Repository navigation
comp.ts sheds 468 tokens, so the next changes fit under its cap - #1509
Conversation
…ew and scope_new, and four small cuts - `File` and `Scope` were each a record type that repeated, field by field, the object `file_new` and `scope_new` build. They are now `ReturnType<typeof file_new>` and `ReturnType<typeof scope_new>`, and each initializer carries its field's type (`new Map<Name, Fun>()`, `[] as Seg[]`). - `pool_rows`' drain loop drops `!err_seen(e.mem)`: the loop runs only on the host, where `err_seen` is `DEVICE && ...`, always false. - `task_deal` computes its cursor start in one expression. - The f32 `show` and `read` operations use `tpl_ops`, as the table's other families do. - `src_add` uses `memo`. Every test's JS is byte-identical; the C differs only in `task_deal` and `pool_rows`. comp.ts: 63,929 -> 63,679 ttok (ttok 0.3, as CI counts).
…ype from seg_new, and three smaller cuts - `File` spreads its book instead of holding it, so `FL.book.tlds` is now `FL.tlds` (50 lines). The book's mutable parts survive the spread: `tmps` is a record mutated in place, and only the checker bumps `hols`. `io_base` already spreads a book. - `Seg` is `ReturnType<typeof seg_new>`, as `File` and `Scope` are. `spin` and `fork` now start false instead of absent, so `emit_jump`'s `bang` defaults to false. - `ctr_take` copies a node's fields in one loop from `term_peek`, which is `term_loc` for an unshared node, instead of one loop per case. - `term_peek` and `blk_read` each return a ternary. - The TODO(bendlang#1105) comment in `js_marshal` goes: the error string below it says the same and names the issue. Every test's JS is byte-identical; the C differs only in `term_peek`, `ctr_take` and `blk_read`. comp.ts: 63,679 -> 63,498 ttok (ttok 0.3).
|
One issue with the instruction to keep these files under a certain token count is that we're right on the edge for comp.ts but some fixes may take it over. Then agents start looking to do accessory code golfing and muddle PR intent to bring it back under 64k tokens. This is going to be a continual issue, so at the very least making some independent attempts to reduce tokens feels like a worthwhile task |
…d io_lost and a duplicate FL note; the show descriptor names Char's boxed flag
…m ReturnType
File is Bend.Book & {...}, since it spreads its book; Seg's spin and fork
are booleans, since seg_new sets them. file_new, scope_new and seg_new
declare their return types. Transpiled comp.ts is byte-identical.
|
Unsupervised AI review (via Unii, on behalf of @nicolas): may be wrong. Pushed a3367cc on top:
comp.ts: 63,461 → 63,704 ttok (main 63,929, so still −225). Bun's transpile of comp.ts is byte-identical to the PR head, so emitted C/JS and perf are unchanged. |
…peek, blk_read and task_deal keep their ifs
|
Pushed a commit on top:
comp.ts is now 63,787 ttok (main 63,929). Gates: repo 54/54, test 1602/1602. tsc shows the same 12 errors that were already there. Unsupervised AI review. |
comp.ts is at 63,929 of its 64,000 ttok cap with ttok 0.3, which CI pins. With ttok 1.0 it is over the cap, at 64,098. This PR frees 468 tokens without changing what any program prints, so the next fix has room. comp.ts ends at 63,461 with ttok 0.3 and 63,637 with ttok 1.0.
It takes over #1479's token commit, so that all the trimming lives in one PR. Once this merges, #1479 can be the fix alone.
Commits
3b4a864eis fix(cpu): deal a slow grow's forks to idle threads (#1475) #1479'sa7e927ed, cherry-picked onto today's main without conflicts. It saves 250 tokens:FileandScopebecomeReturnType<typeof file_new>andReturnType<typeof scope_new>.pool_rows' drain loop drops!err_seen(e.mem). The loop runs only on the host, where that test is always false.task_dealcomputes its cursor start in one expression.showandreadoperations usetpl_ops.src_addusesmemo.707eba89is new. It saves 181 tokens:Filespreads its book (...book) instead of holding it, soFL.book.tldsbecomesFL.tldsacross 50 lines (−52). The spread is safe:tmpsis a record mutated in place, only the checker bumpshols, andio_basealready spreads a book.SegisReturnType<typeof seg_new>(−40).spinandforknow startfalseinstead of absent, soemit_jump'sbangdefaults tofalse.ctr_takecopies a node's fields in one loop fromterm_peek, which isterm_locfor an unshared node (−38).TODO(#1105)comment injs_marshalis deleted (−37). The error string right below it says the same and names the issue.term_peekandblk_readeach return a ternary (−14).6a663300fixes or cuts five comments. It saves 37 tokens:show_chrescapes "as char_show".bend.tsno longer has achar_show(it is nowchr_show, insideterm_show), and both comments already say the output matchesterm_show, so the clause goes.show_mainwrites and the Cshow_valreads.io_lostrestated its three lines.let FL: Filerepeated the File comment.ReturnTypefor record types is new to comp.ts; #1479 introduced it. If you'd rather keep hand-written types,File,ScopeandSegwould cost back about 235 of the 468 tokens.What I ran
.jsand.mjsmatch main's byte for byte, except for the one runtime comment line6a663300shortens. The build messages are identical.term_peek,ctr_take,blk_read,task_dealandpool_rows, plus6a663300's comment lines.6a663300changes only comments, so I didn't rerun the suite for it. I built one test (show/char_unicode) to C and JS before and after it: only comment lines differ.term_peekandblk_readcompile to identical assembly.ctr_takemerge keeps the same loads and stores, with one more conditional branch per program.--checkup(check and interpret) over all 1,602 test modules prints the same as main.gfx_windowandgfx_clicksfail as on main: they expect "no display", but a window opens on this desktop.tscreports no new errors.gates/repo.tspasses 54/54 with ttok 0.3. With ttok 1.0 it flags onlybendtt.lean(64,192), which this PR doesn't touch.ctr_take.