Repository navigation
refactor(comp): shed tokens and compile large programs faster - #1968
Merged
Merged
Conversation
comp.ts goes from 66,010 to 65894 ttok, back under its cap. Emitted programs are unchanged; the C runtime's text changes without changing what it does. Compile time: c_ids scans only the runtime, not the emitted C; JS builds skip ty_srcs, which only ever fed the C lane; term_const is memoized; and js_lib drops FL after a module. FL.ty_opens goes, as ty_holds caches the same answer. Simplification: NATIVE and CLI_HELP are inlined where they are read, term_aux returns u32, turn_take and tld_of name repeats, and brw_of loses an Array case the general rule already covers. ty_holds takes its predicate as data rather than keying its cache on a closure's source. Skipping ty_srcs also fixes a stack overflow: js_lib on a module with a recursive type (tests/check/eta_recursive_type) now builds. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
comp.ts is at 65,906 ttok, still under the cap. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Dropping FL.ty_opens made pure_hvm5_mini compile about 3% slower, so it stays. The two locals that were inlined into loops come back, and the ty_holds comment no longer describes the closure-keyed cache. tests/run/array_lent pins Array parameters lent under the general borrow rule. A compiler that keeps every Array parameter borrowed prints a wrong value for it. comp.ts is at 65,928 ttok. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Without the Array case every Array parameter starts borrowed, so small Array programs paid about 15% more compile time for a gain only @unsafe code could see, and a def called through FID(k) could leak an Array. The array_lent test stays as a plain behaviour test: it passes either way. val_box's slot goes back to emit_hold, which always makes a fresh local, and the JS skip of ty_srcs becomes a plain if with its reason. comp.ts is at 65,970 ttok. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Oct 30, 2026
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.
comp.ts drops 40 ttok (
ttok -m gpt-3.5-turbo, asgates/repo.tspins it), and large programs compile faster. It merges cleanly withmain, taking comp.ts from 66,000 to 65,960, which leaves room under the 66,000 cap.Compile time (C and JS together, median of 7 alternating runs):
demos/app_slash_boss_3ddemos/pure_hvm5_miniWhat changes
Compile time
c_idsscans only the runtime. The emitted C names no ids, and it was most of the text being scanned.ty_srcs. It only adds ADT names toFL.srcs, and JS reads only the defs from that map.term_constis memoized. It re-walked the same constructor trees.js_libdropsFLafter building a module, so the loader's host doesn't keep the book alive. After a module build and a GC, the heap goes from 87 MB to 5.4 MB on boss and from 33 MB to 5 MB on hvm5.Simplification
NATIVEis inlined where it is read, andIO_EMITwhere it is used.term_auxreturnsu32, which removes the(u32)term_auxcasts.io_hand_vis the one place that needs the width, and it now casts itself.turn_takeandtld_ofname repeated expressions.ty_holdstakes its predicate as data, where its cache was keyed on a closure's source text.lay_arrreturnsarras a number, and a few one-use locals and inferred annotations go.Behavior
js_lib(book, true)overflowed the stack inty_srcsontests/check/eta_recursive_type, and that module now builds. Only JS is fixed:ty_srcsstill overflows on a recursive type in a C build, as it does onmain.term_auxandturn_takeedits.Verification
tests/run/array_lentis new. It covers Array parameters that are shared and passed to defs that ignore them, on every lane. It passes onmaintoo, so it guards behaviour and is not a test of this PR's changes.gates/_run.tson a clean checkout: repo 54/54, test 1786/1786, perf 124/124. Ping was skipped because that checkout has no site repo next to it.mainfor all 1,875.bendfiles undertests,demosandbench; 1,378 of them load, and the rest fail before reaching the compiler.term_auxchange is untested there. Metal is covered by the test gate.🤖 Generated with Claude Code