Repository navigation
A List Cons spare survives val_box over a sum (#970) - #987
Conversation
|
Thank you, the fix is right: with a list built at runtime, main's generated C leaves
Note: this reply was written by an AI after it reported the issue to me and I made the decision. If anything here is wrong, reply and I will review it myself. |
…it from Scalar (bendlang#970) When val_box branches over a sum, each arm now starts with empty spares, flushes leftovers, and restores the outer spares after the chain. This keeps a runtime List Cons spare available for the enclosing rebuild, so the Scalar path no longer orphans it while the Pair arm allocates its own node. Trade-off: arms no longer see outer spares. An arm that reused a same-size spare on main now heap_allocs; the saved spare is recovered only if a same-size build follows, otherwise a later flush frees it. Co-authored-by: Cursor <[email protected]>
d84d540 to
f7acd44
Compare
|
Both points are in f7acd44 (test and commit message amended in place).
// main // this branch
u64 _nd_2 = _sp_0; u64 _nd_2 = heap_alloc(e, cls_fit(2));
u64 _nd_3 = heap_alloc(e, cls_fit(2)); u64 _nd_3 = _sp_0;On main
|
|
Thanks @YidaWeng! The test now reaches val_box, and its emitted C differs from main in exactly the two lines the fix moves. The trade-off is in the log, and across every test and runtime bench no other program's C changes. Merging 🙏 |
Summary
val_boxshared onefl.spareslist across exclusive sum arms, so boxingPaircould splice a parkedListCons cell that theScalararm never saw; rebuildingConthen always allocated and the Scalar path leaked 16 bytes per call (C backend: list reconstruction leaks 16 bytes per call in 2.0.24 #970).Conkeeps the spare;Pairallocates its own node.tests/run/list_rebox_sum.bend(Scalar + Pair rebox).Test plan
bun bend2/main.ts tests/run/list_rebox_sum.bend— prints7/3-o ….js (bun) and native Ctests/run/spare_reuse.bendstill passes (interp + C)heap_allocs; Cons reuses_sp_0bun gates/repo.ts— PASS 46 / 46gates/test.ts(no minis here)Made with Cursor