Skip to content

-mm=own: kept parameters given back when their method throws (TSLANG 209); moves in try bodies (TSLANG 210) - #1044

Merged
ASDAlexander77 merged 2 commits into
mainfrom
own-kept-param-throw
Nov 27, 2026
Merged

ASDAlexander77 merged 2 commits into
mainfrom
own-kept-param-throw

Conversation

@ASDAlexander77

@ASDAlexander77 ASDAlexander77 commented Nov 27, 2026 •

Copy link
Copy Markdown
Owner

Under -mm=own, a method that keeps its parameter on every way it returns (e.g. this.items.push(c)) leaked that parameter when it threw before keeping it. The caller had given the parameter up, and the exception took the method out still holding it. 1M throws of k.keep(new C(i)) grew to about 60 MB. Class instances and tuples leak the same way, so this predates the TSLANG 208 work; I found it while leak-testing that work.

  • A throw of the method's own (if (c.n % 3 == 0) throw "no"; this.items.push(c);): if the move can't have run before the throw, the parameter is released just before it (decideParam). Parameters the body already releases on paths that don't move them were handled this way (releaseKeptParamsAtExits). The release is skipped when the thrown value is made from the parameter.
  • A call that may throw before the move (check(c.n); or checkC(c);, then this.items.push(c);): the inference marks the parameter's slot and the op that moves it (OWN_KEPT_PARAM_ATTR_NAME, OWN_KEPT_PARAM_TAKER_ATTR_NAME). UnwindReleasePass then puts a release of the slot in the call's cleanup pad wherever no move may have run before that call. Two cases are skipped: the call that is itself the move, and a call whose handler in the same function uses the parameter again (try { check(c.n); } catch {} this.items.push(c);, which keeps it). A call given the parameter that isn't the move only borrows it, so it gets the release too.

Probe peaks: about 5 MB on Windows (was 61 MB) and 6 MB on Linux.

TSLANG 210 (same batch). Under -mm=own, a value moved into a keeping call in a try body, with statements before and after it that may throw (try { mayFail(i); const t = ["b" + i, i]; k.keepOne(t); mayFail(i + 1); }, or a literal given straight to the call), was refused: "moved here on some paths only". The try's cleanup releases the local, and it is reached both before and after the move. The local's slot is made in front of the try and starts as null, so the paths before its store find nothing. clearsOnUnwind now also empties the slot right before a keeping call, after the value is read, so the paths after the call find nothing either. A call that keeps its argument has taken it whether it returns or throws; its own unwind gives it back (209). A probe of 3M turns, throwing before, between and after the moves, stays at about 6 MB on Windows and 8 MB on Linux.

Tests: 00tslang_issue_209.ts, 00tslang_issue_210.ts (all models). Windows ctest 9909/9909. 207-210 pass on Linux (WSL) with release and debug programs. DefaultLib, rebuilt with this compiler, passes its release tests in all models.

🤖 Generated with Claude Code

ASDAlexander77 and others added 2 commits November 27, 2026 00:22
… keeping it (TSLANG 209)

`keep(c) { if (c.n % 3 == 0) throw "no"; this.items.push(c); }` and `keep(c) { check(c.n); this.items.push(c); }`:
the caller gave the parameter up, and the exception took the method out holding it. 1M throws grew to about 60 MB
(class instances and tuples alike).
- A `throw` the move cannot have run before releases the parameter first (decideParam), as one the body releases
  on the paths that do not move it already was; not where the thrown value is made of it.
- A call that may throw before the move gives it back on its unwind: the inference marks the parameter's slot and
  its taker (OWN_KEPT_PARAM_ATTR_NAME / OWN_KEPT_PARAM_TAKER_ATTR_NAME), and UnwindReleasePass puts the slot's
  release in the call's cleanup pad where no move may have run before - not for the call that is the move, nor
  where a handler of the same function the call unwinds to uses the parameter again. A call given the parameter
  that is not the move borrows it, and is covered too.
Every probe now stays at about 5 MB.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ements that may throw (TSLANG 210)

`try { mayFail(i); const t = ["b" + i, i]; k.keepOne(t); mayFail(i + 1); }` (and a literal given straight to the
call) was refused: "moved here on some paths only". The try's cleanup releases the local and is reached from
before the move and after it. The local's slot is made in front of the try and starts as null, so the ways before
its store find nothing; clearsOnUnwind now also empties the slot right before a keeping call (the value already
read), so the ways past the call find nothing either. A call that keeps its argument has taken it whether it
returns or throws: its own unwind gives it back (TSLANG 209). 3M turns throwing before, between and after the
moves stay at about 6 MB.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ASDAlexander77 ASDAlexander77 changed the title -mm=own: a kept parameter is given back when its method throws before keeping it (TSLANG 209) -mm=own: kept parameters given back when their method throws (TSLANG 209); moves in try bodies (TSLANG 210) Nov 27, 2026
@ASDAlexander77
ASDAlexander77 merged commit 72d22d7 into main Nov 27, 2026
8 checks passed
@ASDAlexander77
ASDAlexander77 deleted the own-kept-param-throw branch November 27, 2026 01:58
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