Skip to content

comp.ts is back under its 64k cap: the compiler says the same in fewer tokens, with the same output - #1285

Merged
Lorenzobattistela merged 1 commit into
mainfrom
comp-under-cap
Oct 2, 2026
Merged

Lorenzobattistela merged 1 commit into
mainfrom
comp-under-cap

Conversation

@Lorenzobattistela

Copy link
Copy Markdown
Collaborator

Context

bend2/comp.ts has been over its permanent 64,000 ttok cap since #1269, which took it from 63,536 to 64,250. Four later merges added more and #1230 took 110 back, leaving main at 64,251, so gates/repo.ts fails on main. This went unnoticed until #1283 because the gate read a failed ttok run as 0.

This PR brings comp.ts to 63,883 ttok (−368). That leaves 117 tokens for the PRs waiting on the cap.

Change (bend2/comp.ts only)

These are pure rewrites of the TypeScript compiler, the same kind as #1230. Nothing in the C or JS runtime templates changes.

  • OPERATIONS: entries whose C and JS texts fit on one line are written on one line.
  • Early returns: chains of early returns become ternaries in val_to, emit_args, emit_match, js_match, js_call, term_force, tpl_nat, lay_of, anf's Lam case and emit_unfold's bind.
  • Once-used helpers: facts_fam, facts_lend and mat_nats move into their one call site each.
  • Once-used locals: load, last, ids, tag and the val_hold results are inlined.
  • Loops: the #define id loop becomes a flatMap; graph_close adds while it scans instead of filtering first; the bind_pop loop becomes a single ??=.
  • ERRS: the placeholders are filled with replaceAll before the split.
  • show_main and val_arm: dot access, and Number(bool) instead of ? 1 : 0, as lay_pack already does.

Not taken: rewrites that bypass an abstraction (pushing to seg.lines directly instead of file_push), parameter-default tricks, Set.add used for its truthiness, and turning switch dispatches into long ternary chains. The last would save about 44 more tokens if they are ever needed.

Checks

On 0a1a769, against main ee8a156:

  • Emitted output: I compiled every .bend under tests/, bench/ and demos/ (1,619 files) to .c, .js and .mjs with main and with this branch. All 4,857 results are byte-identical: the 2,528 emitted files and the error text of the 2,329 that fail to build.
  • tsc: the same 12 errors as main; none is in comp.ts.
  • Gates:
    • gates/repo.ts: PASS 49 / 49. Main fails it, on comp.ts.
    • gates/test.ts: PASS 1536 / 1536.
    • gates/ping.ts: PASS 46 / 46.
    • gates/perf.ts, run alone: 124 / 124 here, 123 / 124 on main back to back.
  • No new line is wider than 80 columns.

#1281 also brings comp.ts under the cap, by removing mechanisms. It rewrites much of the same code, so whichever lands second will need a rebase.

🤖 Generated with Claude Code

…r tokens, with the same output

#1269 took comp.ts to 64,250 ttok and later merges to 64,251, past the
permanent 64,000 cap. These cuts are pure rewrites of the TypeScript
compiler: one-line OPERATIONS entries, ternaries for chains of early
returns, the once-used facts_fam, facts_lend and mat_nats inlined at
their call sites, and locals used once inlined. The emitted C, JS and
.mjs of every .bend under tests/, bench/ and demos/ (4,857 outputs,
error texts included) are byte-identical to main's. comp.ts is at
63,883 ttok.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
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