Skip to content

The compiler says the same in fewer tokens, with the same output - #1230

Merged
Lorenzobattistela merged 7 commits into
bendlang:mainfrom
wakamex:comp-cleanups2
Oct 2, 2026
Merged

Lorenzobattistela merged 7 commits into
bendlang:mainfrom
wakamex:comp-cleanups2

Conversation

@wakamex

@wakamex wakamex commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

comp.ts goes from 64302 to 64192 ttok (-110 ttok, +19 -39 lines) in 7 independent simplifications, one per commit, each with its ttok change in the body, so any of them can be dropped on its own:

  • emit_fold spends its fold fuel per node, so the single-use term_nodes goes
  • emit_chain pushes each branch header with one call
  • lay_pack keeps the old kind unless the new one is wider
  • tpl_ops builds its record with Object.fromEntries
  • memo hands its key to the builder, so lay_of needs no word or key binding
  • emit_tab maps its cells once, null or not
  • js_func takes a lambda's argument and the rest in one destructuring

The other 8 commits of the first version are gone: #1235 made the same or a competing change to that code, and the js_marshal findLast commit needs es2023 where bend2/pack targets es2022. Thanks to Lorenzo for the rebase and check.

@Lorenzobattistela Lorenzobattistela self-assigned this Oct 2, 2026
@Lorenzobattistela

Copy link
Copy Markdown
Collaborator

Thanks for the contribution. I rebased it onto current main (43efc78) and checked it. #1235 landed after you branched and changed the same code, so 7 of the 15 commits conflict, and there's nothing left to save in them:

  • Same as main already: facts_fam with done_live, and js_call's exprs.push.
  • Main changed it a different way: val_arms and mat_arms.
  • Main already inlined it into compile_book: both compile_tables commits and the segs commit.

The other 8 still apply. Seven are clean; memo/lay_of needed a small manual fix-up because of the lines around it. On top of main they hold up:

  • Same output: I compiled all 1,606 .bend files under tests/, bench/runtime/ and demos/ to .c, .js and .mjs. A7,330 files are byte-identical to main'sit codes and error messages.
  • Gates on the cluster: repo 49/49, ping 46/46, test 1529/1529, and perf 117/117 then 116/117. Main gives the same counts, and no bench is over 1.15x
  • Equivalence by hand: lay_pack gives the same result for every pair of w32, w64 and box. emit_fold still
    charges fuel once per node. No other calt now passes. WORDS values are never null,so ?? behaves like the old check. The js_func destructuring gives the same values, including when args is
    empty.

There's one issue:

  • findLast breaks the typecheck. bend2/pac2022, and findLast only exists from es2023.bunx tsc -p bend2/pack goes from 0 comp.ts errors to 2 at the js_marshal line: TS2550, and TS7031 because f becomes an implicit any. It runs fine unte catches it. It saves 1 token, so I'd keep filter(...).pop() there.

Could you rebase onto main, keep the other 7 surviving commits, and update the ttok figure in the description?

… goes

comp.ts 64302 -> 64267 ttok, with the same output.
comp.ts 64267 -> 64254 ttok, with the same output.
comp.ts 64254 -> 64231 ttok, with the same output.
comp.ts 64231 -> 64219 ttok, with the same output.
…ding

comp.ts 64219 -> 64209 ttok, with the same output.
comp.ts 64209 -> 64200 ttok, with the same output.
comp.ts 64200 -> 64192 ttok, with the same output.
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.

2 participants