Repository navigation
comp.ts simplifications: helpers reused, dead code and redundant casts gone (-447 ttok) - #1563
Merged
Merged
Conversation
…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
force-pushed
the
simplify-comp-cuts
branch
from
October 14, 2026 16:58
d183787 to
b69e48f
Compare
- emit_clo sets a captured binding's count directly again: bind_set could sink it and leave bind_pop reading a deleted binding. - Tag lists test exact membership through ty_tag, not a substring. - The IO_EMIT and CLO_APPLY entries take plain words (W64) again. - js_expr captures each outer variable once. - Metal keeps its own ulong/uint/uchar typedefs. - WL_POPN, WL_ARGS and the term bit macros parenthesize again. - term_rfc tests RFC_BIT; io_again, io_wait and io_late say "no deadline" plainly instead of through unsigned wraparound. - show_val writes fixed text with fputs, not a format string. - io_addr names its byte test; io_push adds a number. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
With err_post a macro, err_fail inlines at every call site, and together with the WL_ARGS rewrite clang lays the hot loop out worse: editdist went from 1.90 s to 2.38 s on SEQ-CPU (1.24x, over the gate's 1.15x) and to 1.11x on PAR-CPU. Either change alone is neutral. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This makes room under comp.ts's 64,000 ttok cap for #1438, which adds about 810 ttok. comp.ts goes from 63,968 to 63,521 ttok. It also absorbs #1562. Every change is a plain simplification: no code moves out of the file, and no
ifis rewritten as an expression.Compiler (TypeScript)
bind_set,ty_adtandck.tldare used where the code repeated what they do.quant_liveandty_clofold into their callers (from comp.ts sheds 65 tokens with the same output #1562).seg_newtakes its parameters' values instead of words and kinds flattened at each call site.emit_matchnames its tag test once, asjs_matchalready does.js_call'stailandjs_expr'sty0default to the value most callers pass.VIEW, and tag lists are a single string, as one site already did.C runtime
ERR_*is an enum.term_buffolds intoterm_blk.WL_ARGStakes the count directly and pushes withWL_PUSHN;WL_FRAMEandFID_EXITreuseWL_PUSHNandWL_POPN.show_valprototype, redundant casts and single-use temporaries are gone.IO layer
io_wait's two walks over the parked ring share oneio_parkedloop.fcntl.his included once, andIoWorkis declared once.JS runtime
f32_showlets its shortest-text loop reach infinity and fixes only the spelling.io_strerrorfolds intoio_fail, andio_addrchecks a byte with one test.cmp_newis one line (from comp.ts sheds 65 tokens with the same output #1562).Review fixes (second commit, +135 ttok)
emit_closets a captured binding's count directly again.bind_setcould sink the value and leavebind_popreading a deleted binding.ty_taginstead of a substring test.IO_EMITandCLO_APPLYentries take plain words (W64) again.js_exprcaptures each outer variable once.ulong/uint/uchartypedefs.WL_POPN,WL_ARGSand the term bit macros parenthesize their arguments.term_rfctestsRFC_BIT.io_again,io_waitandio_latesay "no deadline" plainly instead of through unsigned wraparound.show_valwrites fixed text withfputs, not a format string (-Wformat-zero-lengthon Linux GCC).io_addrnames its byte test, andio_pushadds a number.The fixes change no emitted code on the compiler side. The emitted C and JS differ from the first commit only in the runtime lines above, identically across all 772 compiled tests. Building and running every compiled test (C and JS, 5 s each) gives the same pass set on both commits: C 756/772, JS 758/772. The failures are expected-error IO tests that the local harness doesn't model. A
!test's Metal shader builds with--gpu-build, andtscreports no errors in comp.ts.Perf fix (third commit, +20 ttok)
err_postis a function again. As a macro, combined with theWL_ARGSrewrite, it pushed editdist's SEQ-CPU time from 1.90 s to 2.38 s (1.24x, over the gate's 1.15x limit) and its PAR-CPU time to 1.11x. Neither change slows editdist alone, so this looks like clang laying out the hot loop differently. Bisected locally by applying groups of runtime hunks to main's emitted C.Gates (minis, at the third commit): repo 54/54, ping 57/57, test 1631/1631, perf 124/124. editdist reads 0.99x on SEQ-CPU and 0.96x on PAR-CPU.
Verification (macOS, M-series)
cmp_new's line join, the same in all 802 JS outputs.tests/*/*.bendwherever only the compiler side changed. Where the runtime text changed, the diffs are exactly the runtime edits.!programs built and ran on Metal.tscreports no new errors in comp.ts.-Wformat-zero-lengthconcern from the review doesn't reproduce: GCC warns aboutprintf("")but not about the conditionalprintf(i > 0 ? ", " : ""), so thefputsrevert is cleanup only.🤖 Generated with Claude Code