Skip to content

comp.ts sheds 65 tokens with the same output - #1562

Closed
nicolas-abril wants to merge 2 commits into
bendlang:mainfrom
nicolas-abril:comp-shed-312
Closed

nicolas-abril wants to merge 2 commits into
bendlang:mainfrom
nicolas-abril:comp-shed-312

Conversation

@nicolas-abril

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

Copy link
Copy Markdown
Collaborator

comp.ts goes from 63,968 to 63,903 ttok, against its 64k cap. The emitted C is unchanged, and the emitted JS changes only in two line joins.

Every cut keeps the output the same:

  • Folded helpers: quant_live (4 callers) and ty_clo (1 caller) inline into their callers.
  • OPTIMIZED.F32.F32.intr: reads group 2 of VIEW (its f32_bits arm) instead of repeating that regex.
  • bind_pop, emit_args: recount through bind_set. n is at least 1 at both sites, so bind_set always takes its set branch.
  • Line joins: the wrapped ternaries in the emitted JS runtime's cmp_new and f32_show go on one line each, as do two wrapped TS lines (ctr_adt, js_expr).

An earlier version also cut comments and turned if/return pairs into conditionals. Those are reverted: the comments carried information the code doesn't, and the if statements read better.

Verification

  • Emitted output: generated compile_book, js_book and js_lib for all 1,705 .bend files under tests/, demos/ and bench/runtime/ with the old and new comp.ts. Outputs are byte-identical apart from the two JS line joins. This ran on the larger cut, of which this PR is a subset.
  • Runs: for 64 sampled tests, the build output, interpreter, native C and Bun runs match current main exactly (stdout, stderr and exit code).
  • Gates: repo gate 54/54.

macOS only; the cluster test gate hasn't been run.

🤖 Generated with Claude Code

nicolas-abril and others added 2 commits October 14, 2026 18:31
quant_live and ty_clo fold into their callers, F32's intr reads VIEW's
f32_bits group, bind_pop and emit_args recount through bind_set, a few
if/return pairs in the C runtime become one conditional, and comments
that restate their code go. The emitted C and JS for every .bend under
tests/, demos/ and bench/runtime/ is byte-identical apart from those
rewritten runtime lines.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
The cut comments carried what the code does not say (a segment's entry,
what crosses to a host, an effect source's single read, show_f32's
shortest round trip), and the if/return pairs read better than the
conditionals that replaced them. 65 of the 312 tokens stay shed.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@nicolas-abril nicolas-abril changed the title comp.ts sheds 312 tokens with the same output comp.ts sheds 65 tokens with the same output Oct 14, 2026
nicolas-abril added a commit that referenced this pull request Oct 14, 2026
…s gone (-602 ttok)

- The compiler: bind_set, ty_adt and ck.tld are reused where the code
  repeated them; quant_live and ty_clo fold into their callers; seg_new
  takes its parameters' values; emit_match names its tag test once;
  js_call and js_expr default their usual arguments; F32's intrinsic
  reuses VIEW; tag lists are one string.
- The C runtime: ERR_* is an enum; err_post is a macro on both sides;
  term_buf folds into term_blk; WL_ARGS takes its count directly and
  pushes with WL_PUSHN; Metal uses the stdint typedefs; redundant casts,
  a dead show_val prototype and single-use temporaries go.
- The IO layer: one io_parked walk for io_wait's two loops; fcntl.h is
  included once; IoWork is declared once; strcmp tests read !strcmp.
- The JS runtime: f32_show lets its loop reach inf; io_strerror folds
  into io_fail; io_addr checks a byte with one test; cmp_new is one line.

Absorbs #1562. Emitted C and JS stay byte-identical for every test
where only the compiler changed; the C and JS test runs match main.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@nicolas-abril

Copy link
Copy Markdown
Collaborator Author

Closing in favor of #1563, which includes these simplifications (quant_live and ty_clo inlined, F32 reusing VIEW, bind_set in bind_pop and emit_args, the line joins) in one commit with the other comp.ts cuts. The f32_show join is gone because #1563 rewrites that function.

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