Repository navigation
Substitute call arguments into emit_unfold let type annotations - #2288
Merged
nicolas-abril merged 1 commit intoNov 24, 2026
Merged
Conversation
nicolas-abril
added a commit
to EpsilonPhoenix/bend
that referenced
this pull request
Nov 24, 2026
The spin call stays a braced block and its Term o is declared before the arguments' aliases, as on main, so a spin's text keeps its length and SPIN_FAR picks the same INLINE or FAR it did. Only the spins that lose their h/q cache now differ in the generated C. The tokens that costs, and 9 more for bendlang#2288 to land beside this, come from merged declarations and one braceless early return in nearby TypeScript, none of which changes output. Co-Authored-By: Claude Opus 5.5 <[email protected]>
nicolas-abril
added a commit
to nicolas-abril/bend
that referenced
this pull request
Nov 24, 2026
, bendlang#2224-bendlang#2226, bendlang#2231, bendlang#2285, bendlang#2286, bendlang#2288 and others) One conflict, in emit_unfold: bendlang#2288 annotates an unfolded call's lets with the argument types instantiated by the earlier arguments; bendlang#2162's deep unfold keeps its arguments unannotated there and annotates them the same way after folding (its type walk renamed D, beside bendlang#2288's T). Both kept. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.
User-visible failure
Pure, safe Bend programs (passing
bend --verdict) can crash withSIGSEGV(bend: memory fault) when compiled to native C if a function with an erased type parameter (e.g.def caller(-A: Type, ...)) calls a flat polymorphic function whose erased type parameter shares the same name and index (e.g.def dup(-A: Data, b: Bool, +x: A)).Even without a colliding caller parameter name, unfolding a polymorphic flat function leaks raw callee type variables into caller
Annnodes, causingfacts_hotto fall back tofact_add("open")and degrading unboxed layouts.Root cause
In
bend2/comp.ts,emit_unfoldpreviously annotated unfoldedlet-bound arguments usingtele_unbind(m.tld!.T).doms:tele_unbindleaves the callee's telescope variables unsubstituted (e.g.Var("A", 0)). When the caller binds the resultingletand later shares it (bind_pop),facts_hot(sc.def, b.A, true)looks upVar("A", 0)in the caller's telescope (tele_unbind(tld_of(def).T).doms[w.i]). If the caller also has an erased-Aat index0(e.g.Unit),facts_hotmarks the caller's-Aargument hot instead of the actual instantiated type (Node):Node's constructors (Leaf,Bin) remain cold (CID_T[CID_Bin].hot == 0), skippingrfc_sealon constructor children and emittingterm_loc(...)instead ofctr_take(...)when matching.Node(term_keep), it becomes RFC-wrapped, so subsequent matching reads the RFC redirect word + adjacent heap memory as constructor fields and faults (SIGSEGV).Minimal change
bend2/comp.ts(emit_unfold): walkm.tld!.Tstep-by-step viaty_all(T)and substitute each folded argumentT = f.B(a)before annotatingBend.Ann(a, f.A).tests/reg/unfold_poly_hot.bend: regression test (passing--verdict) covering colliding caller-Aat index0, forwarding a caller's own erased type parameter at index1with a non-Varexpression, and a dependent parameter type instantiated by a folded argument.Before / after evidence
On
tests/reg/unfold_poly_hot.bend(mainat966bbb74):CID_Unithot ({ 0, 1, 0 }),CID_Leaf/CID_Bincold ({ 1, 0, 0 },{ 2, 0, 0 }), and unsealedBinchildren.bend: memory fault (machine stack overflow?)/Segmentation fault (core dumped)(exit code139).CID_Unitcold ({ 0, 0, 0 }),CID_Leaf/CID_Binhot ({ 1, 1, 0 },{ 2, 1, 0 }), andrfc_sealonBinchildren.bun bend2/main.ts tests/reg/unfold_poly_hot.bend --verdict->ALL PROOFS CHECK.-O3and-O3 -DBEND_POISON,--threads 1and--threads 4) all output94(exit0).Validation & limits
bun 1.3.12,node v24.14.1,clang 23.1.5, Leanv4.34.0):bun gates/repo.ts:PASS: 56 / 56(bend2/comp.ts:65,989 / 66,000ttok, +9 tokens).tests/reg/unfold_poly_hot.bend:--verdict, JS (Bun & Node), C (-O3and-DBEND_POISON,--threads 1&--threads 4).tests/reg/*.bendandtests/rfc/*.bendsweep (JS + native C):126passed,0failed (7skipped for platform/foreign requirements).gates/test.ts,gates/perf.ts), Metal, and CUDA device lanes.