Skip to content

comp.ts sheds 266 tokens - #1576

Merged
Lorenzobattistela merged 4 commits into
bendlang:mainfrom
nicolas-abril:comp-shed-921
Oct 15, 2026
Merged

Lorenzobattistela merged 4 commits into
bendlang:mainfrom
nicolas-abril:comp-shed-921

Conversation

@nicolas-abril

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

Copy link
Copy Markdown
Collaborator

comp.ts goes from 63,652 to 63,386 ttok tokens on top of main. These are structural simplifications. The emitted program code is unchanged, and comments, if statements, types, section-prefixed names and every runtime cast stay as on main.

Compiler

  • ty_srcs roots a type's datatypes directly, replacing type_adts.
  • val_arms takes a box flag instead of a condition callback.
  • emit_chain takes [cond, body] pairs.
  • show_main reads main's layout from fun_of.
  • emit_ctr's word and Array branches share their field emission.
  • nat_add and nat_double share one tpl_ops entry.
  • view_root folds into its one caller.
  • emit_clo drops a binding copy.
  • The lend edges come from split("<").reverse().

C runtime

  • WL_CASE opens its own brace.
  • WL_FN and OUTLINE reuse FAR.
  • io_wait uses one fd-set buffer.
  • f32_text NUL-terminates and prints its exponent with %+d.
  • main starts thr at the CPU count.

JS runtime

  • char_new, now in a Char section, is bound from the TS function, as f32_round is. The Chr builder reuses it.
  • f32_show's digit loop covers nan, ±inf and -0.

Same output as main

  • For all 1714 programs under tests/, demos/ and bench/runtime/:
    • the emitted C tables, spins and segments are byte-identical to main's, except for WL_CASE's brace;
    • the emitted JS program text is identical, except that non-scalar Char literals fold into string literals of the same value.
  • Two review rounds reverted everything that was not a pure refactor:
    • term_aux's return type
    • the JS f32 bit views (Node keeps signaling-NaN payloads differently)
    • node_fill's name stems, wpoll and TAB_AT, which could flip INLINE/DFAR
    • task_deliver's loop bound
    • io_wait's running max fd
    • emit_jump's ref
    • WL_LOAD/WL_TAKE
    • emit_task's return
    • #undef WL_X
    • file_book's error order

Verification

  • Gates: test 1634/1634, perf 124/124, ping and repo all pass. comp.ts typechecks clean.
  • Both lanes: all 1710 non-network programs print the same as with main's comp.ts on the JS and C lanes, GPU builds included. The one mismatch was tree-radix's JS timeout under 8-way load. Its program JS is identical, and alone or under synthetic load it times the same: 9.0 s on both.
  • Sanitizers: 745 test builds with -fsanitize=undefined print the same as with main's comp.ts, and report nothing.
  • f32 text: C f32_text and JS f32_show were fuzzed against main's (2^24 and 2M+ bit patterns, plus edge values, under Bun and Node) with no differences.

🤖 Generated with Claude Code

@nicolas-abril nicolas-abril changed the title comp.ts sheds 811 tokens comp.ts sheds 517 tokens Oct 15, 2026
nicolas-abril and others added 3 commits October 15, 2026 15:20
File, Scope, Seg and Val become classes, so their fields are declared
once (Seg takes the Vals of its parameters); src_types roots a type's
datatypes directly; val_arms takes a box flag; emit_chain takes [cond,
body] pairs; emit_task returns the task term; file_book checks each def
once; show_main reads main's layout from fun_of. The C runtime's
term_aux is a u32, WL_LOAD reads through a pointer (WL_TAKE goes),
WL_CASE opens its brace, WL_SPIN declares its poll counter, TAB_AT goes,
and io_wait sizes its sets from a running max, so its one park walk
needs no io_parked. The JS runtime splices char_new and the f32 bit
views from TS, and f32_show lets its digit loop cover nan, inf and -0.
All gates pass; perf matches main within noise.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
File, Scope, Seg and Val are types again, built by file_new, scope_new,
seg_new and val_new, as main has them. src_types becomes ty_srcs, and
char_new gets a Char section, so each name starts with its section's.

The cast changes stay: term_aux yields a u32 of the same value, which
every caller cast to anyway, and io_hand_v widens it before shifting.
310 tests built with -fsanitize=undefined print the same as with main's
comp.ts, with no runtime errors. comp.ts is 63,115 tokens, 517 under main.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
A review against main reverts what was not a pure refactor: term_aux
returns a u64 again (foreign C may shift it), with every cast as on
main; the JS f32 bit views are typed arrays again (Node's DataView keeps
a signaling NaN's payload); node_fill keeps its name stem, emit_native
its wpoll and the runtime TAB_AT, so every spin's text, and with it
every INLINE or DFAR choice, matches main; task_deliver keeps its
WL_RESW loop; file_book reports OWNED names first again; char_new is
bound by name.

Every program under tests/, demos/ and bench/runtime/ emits the same
spins and, past the intended spelling (WL_LOAD's pointer, WL_CASE's
brace, the fork join's term_loc), the same segments and tables as with
main's comp.ts, and prints the same on both lanes.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@nicolas-abril nicolas-abril changed the title comp.ts sheds 517 tokens comp.ts sheds 374 tokens Oct 15, 2026
A second review reverts what changed the emitted program or tied code
together: io_wait walks the parked list again rather than keep the
highest fd ever seen (a burst of fds kept every later wait large);
emit_jump records its target itself; WL_LOAD indexes e.mem and WL_TAKE
returns (WL_LOAD(rv, WL_RESW) had dead reads past rv); emit_task leaves
term_tsk to its callers, so the fork join stores into its node again;
#undef WL_X stays. io_wait keeps one fd-set buffer.

Every program under tests/, demos/ and bench/runtime/ now emits the same
tables, spins and segments as with main's comp.ts but for WL_CASE's
brace, and the same JS but for non-scalar Char literals, which fold to
the same strings. All tests built with -fsanitize=undefined print as
with main's comp.ts, with no reports, and every program prints the same
on both lanes.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@nicolas-abril nicolas-abril changed the title comp.ts sheds 374 tokens comp.ts sheds 266 tokens Oct 15, 2026
@nicolas-abril
nicolas-abril marked this pull request as ready for review October 15, 2026 13:56
@Lorenzobattistela
Lorenzobattistela merged commit 25233fb into bendlang:main Oct 15, 2026
1 check passed
@nicolas-abril
nicolas-abril deleted the comp-shed-921 branch October 15, 2026 15:24
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