Skip to content

The compiler says the same in 658 fewer tokens, with the same output and compile time - #1235

Merged
nicolas-abril merged 2 commits into
bendlang:mainfrom
nicolas-abril:comp-tokens
Oct 1, 2026
Merged

nicolas-abril merged 2 commits into
bendlang:mainfrom
nicolas-abril:comp-tokens

Conversation

@nicolas-abril

@nicolas-abril nicolas-abril commented Oct 1, 2026 •

Copy link
Copy Markdown
Collaborator

Context

gates/repo.ts caps bend2/comp.ts at 64k ttok, and it was at 63,765, leaving 235 tokens of headroom. This PR frees room under the cap without changing what the compiler emits.

Change

comp.ts goes from 63,765 to 63,107 ttok (−658), so it is now 893 under the cap. Only the TypeScript half changed. The embedded C runtime and the runtime text strings are untouched.

The file's style is kept: no if is folded into a conditional expression, OPERATIONS entries with more than one field keep a line per field, every new or renamed function starts with its section's name, no added line passes 80 columns, and tsc reports no new errors.

  • Duplicates said once:
    • js_ctr was ctr_doms without its final map. It is now ctr_live, and ctr_doms is built on it.
    • live_dom is now dom_live, back in its own // Dom section.
    • emit_fold and emit_unfold now share emit_fold_args.
    • The "has a body or is foreign" test is fun_runs. It was written out by hand in four places.
  • Inlined single-caller helpers:
    • compile_tables, compile_reqs and compile_segs now live in compile_book, which grows to about 125 lines. Splitting compile_tables back out would cost about 23 tokens.
    • emit_frame, book_owned and arr_lay are inlined into their callers.
    • js_tail is folded into js_call. A tail call now records its callee in fl.tails up front, without the fl.seg.def !== "" guard. The extra entries are never read, because the callee is never a def with tail calls of its own, and output is unchanged.
  • Less wasted work:
    • io_base overlays IO on book.tlds with Object.create, the way bend.ts does, instead of copying the whole table on each call. The .mjs path calls it once per def. It is also no longer exported.
    • ctr_tail no longer memoizes a telescope it just filled, which never hit and was never freed.
    • file_book iterates its queue instead of calling shift().
  • The rest is tighter expressions, one-line single-field OPERATIONS entries and type declarations, inferred annotations and template literals.

Checks

  • Output: for each of the 1197 tests that import Base, the emitted .js and .c and every error log are byte-identical to main. A 107-test sample of -o x.mjs is also identical.
  • Compile time: whole-command hyperfine timings over the 16 bench/runtime programs, 20 runs each, against main (measured before the style commit, which only restores main's own code or renames functions). C output totals 1401 → 1396 ms (−0.3%) and JS 1116 → 1112 ms (−0.4%). No bench moves outside noise. Two edits I tried had made C builds about 1% slower and were reverted:
    • removing term_const's shortcut for constructors with no fields;
    • computing lay_of's key before its early return for word types.
  • tsc reports no errors in comp.ts.
  • bun gates/repo.ts passes (49/49).
  • The cluster gates (gates/test.ts, gates/perf.ts) weren't run. The runtime is unchanged and the emitted code is byte-identical, so the programs those gates run are the same.

🤖 Generated with Claude Code

nicolas-abril and others added 2 commits October 1, 2026 16:05
…and compile time

comp.ts goes from 63,765 to 62,919 ttok, 1,081 under its 64k cap. Every
JS and C file the 1197 Base tests emit, and every refusal, is byte for
byte the same, and the .mjs path is the same on a 107-test sample.

Duplicates are said once: js_ctr is ctr_live, under ctr_doms; the two
argument folds are fold_args; "a def that runs" is def_runs. Single-caller
helpers are inlined (compile_tables, compile_reqs, compile_segs,
emit_frame, book_owned, arr_lay; js_tail folds into js_call), and the
rest is tighter expressions and inferred annotations.

Three changes also save work: io_base overlays IO on book.tlds instead of
copying the table once per def, ctr_tail no longer memoizes a telescope
it just built (never hit, never freed), and file_book walks its queue
instead of shifting it.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…es keep a line per field, and a function is named for its section

The ifs the pass folded into conditionals are ifs again (term_force,
mat_rows, facts_hot, file_book, emit_args, emit_expr, emit_match,
emit_chain, js_call, js_match), and the OPERATIONS entries with more than
one field are multi-line again. live_dom is dom_live under its own Dom
section, def_runs is fun_runs and fold_args is emit_fold_args. Output is
byte for byte the same; comp.ts is 63,107 ttok.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@nicolas-abril nicolas-abril changed the title The compiler says the same in 846 fewer tokens, with the same output and compile time The compiler says the same in 658 fewer tokens, with the same output and compile time Oct 1, 2026
@nicolas-abril
nicolas-abril merged commit 0070d08 into bendlang:main Oct 1, 2026
nicolas-abril added a commit to costamatheus97/bend that referenced this pull request Oct 1, 2026
…nt rows, the main thread takes rows, and a turn visits only the rows that can hold a task

bendlang#1092's five commits, squashed onto main. The emitter cleanups its last
commit carried are already on main (bendlang#1235); the column grow keeps bendlang#1171's
row per thread, and a column grow still opens every row to the turns.

Co-Authored-By: Nicolas Abril <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant