Skip to content

mem: --mem gives each var node the regions whose boxes it can hold, and whether and why it is shared - #75

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

vic merged 1 commit into
mainfrom
mem-regions

Conversation

@vic

@vic vic commented Nov 12, 2026

Copy link
Copy Markdown
Owner

--mem now says, for every var node, which regions its boxes can come from, and whether and why it is shared.

  • New relation rin(N, R): node N can hold a box of handled region R. A site node gets the regions of its site (esm joins the escape walk's site to the M1 walk's site by def, line and ctor; fills gives the regions). Then it spreads over the same edges as shared: flow, arg into param, a callee's result into its call.
  • New fact callOf(C, G) for every call to a def whose result can hold a box. The result rules (shared r5 and rin) read it. Before, they found the call only through argOf, so a call whose args are all scalars (RG.make(2)) never got its callee's result: its regions were lost, and its sharing too. That was a soundness gap in the M7a sharing pass: on s2c it removes 2 reuse candidates that were wrong to report (s2/flow.srs:1815, s2/names.srs:417).
  • JSON: vars[] = {id, def, name, regions, shared: false | "multi" | "unknown" | "flow"}. Region ids are now Mem's own region ids, so vars[].regions, sites[].region and frees[].region agree (a region that is not live is skipped, so ids can have gaps: mem/inner).

New test tests/s2/mem/regions.srs: a box (seed), a val of it (flow), the result of a scalar-arg call (ret, through callOf), a param (arg), arg then ret; a param given boxes of two regions. Checked by hand.

Checks:

  • All old fields of the mem tests are unchanged, apart from region ids and the reuse change above.
  • 830-output identity; fixpoint; seed updated.
  • Speed on s2c: normal compile unchanged (534,595,254 -> 534,595,308). --mem 1.42 G -> 1.70 G (+19.5%): the rin rules cost 193 M (ablation without them: 1.506 G), and callOf, vars and the wider r5 cost 84 M. A first version cost 7.8 G: in the seed rule, D probes in written order and esiteNode came first, so each new fills row scanned every site node. Order esm, fills, esiteNode gives every delta a bound column.

Mutants (each builds):

mutant killed by
no seed rule all 11 mem tests (regions included)
no flow rule all 11 mem tests
no arg rule all 11 mem tests
no ret rule mem/regions and 6 more
r5 back to argOf only the s2c --mem output (2 reuses): survives the mem tests

Open: the last mutant survives the tests. Three small programs with that shape did not catch it (another edge already makes the var shared in each). Like the var-map mutant of #70, the M7b run-time oracle has to cover it. Scalar pattern vars (an I64 field) list regions too, because flow is untyped.

@vic
vic merged commit c4df0fc into main Nov 12, 2026
3 checks passed
@vic
vic deleted the mem-regions 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