Skip to content

comp.ts sheds 443 tokens of redundant code - #1395

Merged
Lorenzobattistela merged 30 commits into
bendlang:mainfrom
nicolas-abril:simplify-comp
Oct 8, 2026
Merged

Lorenzobattistela merged 30 commits into
bendlang:mainfrom
nicolas-abril:simplify-comp

Conversation

@nicolas-abril

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

Copy link
Copy Markdown
Collaborator

bend2/comp.ts drops from 63,975 to 63,532 ttok (−443) through simplifications, not minimizations: dead special cases, duplicated logic folded into one place, and helpers reused instead of copied. No identifiers are shortened and no comments are cut to save tokens.

What changed

  • Compiler (A–C): a match's uses fold in the generic kids walk; lay_box is gone (only W32/W64/BOX have no arms, so it was x === BOX); seg_open renames a binding's words in place; compile_book opens defs and foreign defs in one loop and indents a segment with one seg_text; emit_fork picks frame bindings with one filter; a few dead guards confirmed unreachable by instrumenting the corpus.
  • JS backend and runtime: one function emitter for foreign and filled defs; one tag test in js_match; a pure main's show descriptor is one array; show_chr takes the character.
  • C runtime: a host WL_AGAIN is WL_JMP; blk_wcls is the one word-class rule; task_deal picks a ring in one expression; corpus_map loops its hints and falls back through pool_mmap; io_str drops a no-op io_seal; io_loop takes both of its every-64-steps checks under one test; main reads a missing flag value as "", so --threads/--gpu need no NULL checks; show_f32/show_val are simpler; gpu_hash lives in the CUDA branch, its only user.

Output changes

  • The C and JS runtime text changes, so every emitted .c and .js differs in those runtime lines.
  • js_def's shared emitter gives a foreign def the trailing blank line every other def has, so .js/.mjs files with a JS foreign def gain one blank line after it (this also fixes a }export default { run-on).
  • Everything else emits byte-identical output, and every compile-error log is identical to main's.

Verification

  • Output: all 1,074 tests, benches and demos were compiled to C, JS and .mjs and compared with main; the only differences are the ones listed above.
  • Tests: every Base test on the JS and native (clang + Metal) lanes gives the same result as main.
  • Gates: repo 50/50, ping 46/46, test 1587/1587. perf: every cell over 1.15x also fails on main (raytrace's COMPILER TIME sits at 1.15–1.18x on main; PAR-GPU mandelbrot/merkle up to 1.19x).
  • Speed: the C runtime changes keep instruction counts; CPU cycles are within ±0.5% on all 17 benches, Metal within noise. Dropping term_const's fieldless-constructor shortcut slowed raytrace's compile by 3%, so it stays; raytrace now compiles in the same time as on main.
  • Review fixes: ctr_build keeps its has check (a constructor and a def can share a name, and book_fam returns the constructor's own name when its type is no ADT); term_uses still skips DUMMY; io_loop reads the clock only when something is parked.
  • Not tested here: the CUDA build (the CUDA change only moves gpu_hash into its branch and inlines gpu_shape).

Rejected for costing speed: a merged copy loop in ctr_take (5–10% faster on CPU, slower on Metal), WL_ARGS pushing N words (+1% queens), and removing WL_FRAME's wtw temporary (breaks an ldp/stp pairing).

🤖 Generated with Claude Code

nicolas-abril and others added 30 commits October 7, 2026 23:20
… a probe by its own index (no use asks for DUMMY's)
…ever-made n suffix; type_adts and ty_clo use the plain forms
…DUMMY, io_loop reads the clock only with something parked

A constructor and a def can share a name, and book_fam returns the
constructor's own name when its type is no ADT, so ctr_build must not
overwrite an entry that is there.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@nicolas-abril nicolas-abril changed the title comp.ts sheds 477 tokens of redundant code, its compiler output unchanged comp.ts sheds 443 tokens of redundant code Oct 7, 2026
@Lorenzobattistela
Lorenzobattistela merged commit 0592662 into bendlang:main Oct 8, 2026
1 check passed
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