Repository navigation
-mm=own: kept parameters given back when their method throws (TSLANG 209); moves in try bodies (TSLANG 210) - #1044
Merged
Merged
Conversation
… 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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 ofk.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.throwof the method's own (if (c.n % 3 == 0) throw "no"; this.items.push(c);): if the move can't have run before thethrow, 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.check(c.n);orcheckC(c);, thenthis.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).UnwindReleasePassthen 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 atrybody, 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". Thetry's cleanup releases the local, and it is reached both before and after the move. The local's slot is made in front of thetryand starts as null, so the paths before its store find nothing.clearsOnUnwindnow 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