Skip to content

mem: one var node per binder, and a call's result takes its regions by call - #80

Merged
vic merged 1 commit into
mainfrom
mem-binders
Nov 12, 2026
Merged

vic merged 1 commit into
mainfrom
mem-binders

Conversation

@vic

@vic vic commented Nov 12, 2026

Copy link
Copy Markdown
Owner

Two precision fixes from the --mem audit (M9.4).

One var node per binder. Polonius has one local per binding; Mem had one node per name in a def, so a shadowed name and the same name in two sibling scopes merged (1,026 vars on s2c). A pre-pass, Mem.unshadow, renames each binder whose name its def already bound to x#n (its nth binder), and gives every use the name of the binder in scope (lexical: a val for the rest of its block, a pattern var for its arm). The name is printed through Console.captureBegin/captureEnd, the way Store.text builds a string. The walks then see one name per binder. On s2c, 3 vars remain with two binders: two handlers' alloc/free share a bare def name (filed).

A call's result by call. The result of every call of a fn took the regions of all its calls (retOf(G, X), rin(X, R), callOf(N, G)), so build{sess}(..) and build{a}(..) both listed sess and a. Now each call node gets:

  • the region the call runs in: M1 records each call's region (callAt(F, line, R) for a handled region, callFreeAt(F, line) for a region its def runs in), and Mem joins it to the escape walk's call node before the solve (ecallIn, ecallFree);
  • what an arg brings when the arg reaches the callee's result: rin(C, R) :- argOf(M, G, I, C), rin(M, R), retP(G, I).

This over-approximates a callee that returns no new box (its call still lists the region it runs in); a first version gated it on snewRet(G) and cost 10.6 G on s2c, because of the atom order of the join.

useAfterFree no longer needs its binds == 1 guard (shadowing is gone); the assigned guard stays (no kill at an assignment yet).

New test tests/s2/mem/binders.srs: BN.mk{s} called in r and in t (p holds r, q holds t), an inner p shadowing the outer one (p#2), BN.wrap{t}(p) (w holds t and r), BN.mk2 with no choice (runs in t). Checked by hand; the program prints 11. In prog/scope_shadow_inner the outer x now holds only sess and the inner x#2 only a.

Checks:

  • The core fields of every mem test (sites, compact, total, frees, fail, reuse verdicts) are unchanged; fail is empty on every prog test.
  • 830-output identity; fixpoint; seed updated.
  • Speed on s2c: normal compile 561,266,654 -> 561,266,643; --mem 2.019 G -> 2.241 G (+11%: the rename pass and more var nodes).

Mutants (each builds):

mutant killed by
no rename (a binder keeps its name) all 14 mem tests
a val binder not in scope for the rest of its block all 14 mem tests
no ecallIn rule binders and 10 more
no ecallFree rule compact, reuse
no arg-to-result rule binders, moves

@vic
vic merged commit 0b13954 into main Nov 12, 2026
3 checks passed
@vic
vic deleted the mem-binders branch November 17, 2026 16:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant