Skip to content

mem: --mem lists each region's frees (manual and at block end), its def and the defs that fill it - #74

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

vic merged 1 commit into
mainfrom
mem-frees

Conversation

@vic

@vic vic commented Nov 12, 2026

Copy link
Copy Markdown
Owner

--mem now says how each region is freed and who fills it.

  • frees: each x.free() on a handled region (kind: manual, at), then the drop the protocol runs at the end of the handle's block (kind: auto, when: blockEnd, ifLive: true: Emit.drops calls the drop op only when the region is still live). A free() on a {} Region param has region: null, its def and param (the caller passes the region).
  • regions[] gain def (the def that handles it) and defs (the defs whose sites fill it, in order of first site): region sharing.
  • sites[] gain def.

Mem finds the frees with a walk over the fn bodies (Mem.manualFrees); a free belongs to the region of its def handled as the same name on an earlier line, else it is a param free.

New test tests/s2/mem/frees.srs: a region freed by hand then dropped, a region filled by two defs, a region with no sites, a param free. Checked by hand against the source; the program runs and prints 10.

Checks:

  • The old fields of every tests/s2/mem/*.out are unchanged (jq drops the new fields and compares).
  • Every prog test gives valid JSON. The C of 830 outputs is identical; fixpoint; seed updated.
  • Speed on s2c: normal compile 528,032,551 -> 528,032,546; --mem 1,405,420,910 -> 1,409,850,176 (+0.32%).

Mutants (each builds):

mutant killed by
a manual free must come before its handle (l < line) mem/frees
a param free is kept when a region frees it, dropped when none does mem/frees
the walk looks for freex mem/frees
defs keeps duplicates mem/death, mem/reasons, mem/reuse

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