Repository navigation
safe.ts and comp.ts stop reducing types they never read or already reduced, and safe_pass dedups book.order in one pass - #1362
Conversation
…s dedups book.order in one pass - safe_pass found each root with book.order.lastIndexOf, O(n²) on a book's ~50k order entries: now one Map of last indices. - safe.ts skips a whnf whose result is never used: arg_term and tree at a term bend2 never types as a function (NOT_FN), ctr_term for a family with no parameters, root_cols past the last parameter, and arm's template map for a def with no ~ parameters. - comp.ts: term_spine skips tele_unbind on a node with no applications, and ty_wnf memoizes a call-headed type by its structural key, so a computed type in live code is reduced once, not once per annotation. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
… so a bound X never shares a key with a free X ty_wnf keyed a call-headed type by term_lower at depth 0, so a binder at depth i keyed the same as a free variable at level or probe i with its name: pick(X => b => X) and pick(X => b => Y) at Y := X shared one whnf. A Data let in a generic def then read U32, a word, kept no count for the boxed value it shared, and the native run read freed cells. tests/reg/wnf_memo_bound_key.bend is the witness. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
@nicolas-abril I pushed ffd5bc3 to this branch: a fix for a key collision in the new The key lowered the type from depth 0, so a binder at depth i keyed the same as a free variable at level i with the same name. Main's closed
On this branch merged onto main af6a54f, every gate passes: repo 50 / 50, ping 47 / 47, test 1575 / 1575, perf 124 / 124, and safe 1016 agree with the same single false reject as main (agree_32). The description has the details, and it now gives the |
…memoizing ty_wnf Drops the structural ty_wnf memo (an implicit sharing layer that changed literal_readback's print descriptor). Instead: - tele_unbind stores a def's domains reduced, so fun_of's layouts and file_book's datatype scan read one reduced object per domain. - fun_of takes a fully applied def's return type from that telescope. - file_book reads the datatypes of a def's own λs and body, and of a call's head, off the signature's reduced telescope (tele_adts), in the order type_adts walks it, so constructor ids keep their numbering. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
… added code #1362 merged before this pass. Drops what no program in the repo needed: comp.ts's signature-once machinery (the reduced telescope, tele_adts, fun_of's return type, file_book's spine map), which only sped up a synthetic live def with a computed type; NOT_FN and the tree leaf skip, since a constructor argument alone gives app_win's saving; and the order dedup's Map, now one line. Output is byte-identical to main's. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
--verdict's elaborator spent most of its time on big books in two places it didn't need to. The compiler reduced a computed type once per annotation that mentions it, instead of once per def signature.safe.tssafe_passfound each root withbook.order.lastIndexOf(k) === i, which is O(n²). On the checker benchesbook.orderholds 42–54k entries, and this one line was 55–80% of elaboration. It now builds oneMapof last indices.arg_termandtreeskipall_offor a term bend2 never types as a function (NOT_FN: types, quantities, constructors, literals,{==}).ctr_termskips the goal's whnf for a family with no parameters.root_colsno longer reduces the return type past the last parameter.armbuilds its template map only for a def with~parameters.comp.tsterm_spineskipstele_unbindon a node with no applications. It was reducing a leaf's annotation type it never reads.term_wnfhas no per-object result cache (sharing lives in argument cells, built fresh per call), so every fresh copy ofT(ev(…))was reduced again.tele_unbind, already memoized per def inFL.teles, now stores each domain reduced.fun_oftakes a fully applied def's return type from it.file_bookreads the datatypes of a def's own λs and body, and of a call's head, off that reduced telescope (tele_adts), instead of reducing each annotation's copy of the signature. They come out in the ordertype_adtswalks a ∀ (domains, then return type), so constructor ids keep their numbering.App's or aCtr's per-site type, are scanned as before.ty_wnfby structural key instead. That was unsound: @Lorenzobattistela'stests/reg/wnf_memo_bound_key.bendshows a boundXsharing a key with a freeX, so a count was lost and memory freed early. The memo is gone; the test stays as a regression guard and passes natively, in JS, and in the interpreter.Timings (median of 3, Apple M4):
--check-only-o .bendttmain → branch--verdictmain → branchMost of what's left in
--verdicton the benches is the kernel:Book.indexis a linear scan, run once per def and once per live call. That fix needs the proofs updated and will come as a separate PR.Where
comp.tsspeeds up: nothing in the corpus has a computed type in live code, so its compile times don't move (.c98.6 → 98.4 s,.js91.5 → 91.4 s over the whole corpus). On a program built for it, livep(x: Nat) -> T(ev(200000n))andq(x: Nat, u: T(ev(200000n)))called frommain, with a 0.35 s check,-o .cgoes 1.55 → 0.84 s and-o .js1.59 → 0.75 s. Insafe.ts, the same kind of return type takes-o .bendttfrom 0.78 → 0.36 s.Checked:
.bendfiles intests/,demos/andbench/, the output is byte-identical to main's:-o .bendttfor all 1,154 files that emit it,-o .cfor all 762 that build, and-o .jsfor all 786.tscreports no new errors..bendtt, 764.cand 788.js. The new test is the only extra file.safe.ts22,019 → 22,117 ttok,comp.ts63,553 → 63,838.🤖 Generated with Claude Code