Repository navigation
-mm=own: a thrown parameter is kept; an awaited borrowed string is copied - #768
Merged
Merged
Conversation
…pied
A function that throws its parameter (`function reject(reason: E) { throw reason; }`) failed under
own both ways: without `@keeps` the throw's retain was "a parameter, kept here, but -mm=own cannot
make the callers give it up", and with `@keeps("reason")` the signature pass said "its body keeps
nothing". OwnershipSignaturePass::keeps now counts a throw of the value as keeping it: the
exception takes it, and releaseKeptParamsAtExits already places no release at such a throw. The
callers move the argument in, and a use of it afterwards is a use after move.
`await identity(greet("you"))`, a string result that borrows its argument, was "borrows the
result of 'identity' and cannot be stored". The async lowering outlines the await's region into a
func.func that stores the value through a reference to the caller's local; its temporaries are
released when it ends. Such a store of a copyable string now takes a copy, as a store into a place
does (spec 50). An object result that borrows its argument is still the error.
Found adding Promise to the DefaultLib (TypeScriptCompilerDefaultLib#65).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The Linux CI failed the new test under rc and own: "operand #0 does not dominate this use". The await's result slot, released by the scope, was declared in the body of a TryOp while the TryOp's cleanup region released it. On Itanium a block with a typed `catch` is wrapped in such a TryOp, which is why only Linux saw it; an await in any `try` body failed the same way on Windows too. The slot is now declared in front of the TryOp, as an owned local is (allocateScopeOwnedVarsOutsideOfOperation). Under own the value is then moved out of the slot into a hoisted local, which is declared with no value and filled by a store right before rc's RetainSlot. takerOf named the declaration as the move, which ran before the value was made, so the move looked like one inside a loop; the store is the move now. Still open under own on Itanium: a value moved out of an await's slot at the top level of a block wrapped for a typed `catch` is "moved on some paths only" (the wrapper's cleanup releases the slot too). The test's awaits are in functions of their own. 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.
Two
-mm=owngaps found while addingPromiseto the default library (ASDAlexander77/TypeScriptCompilerDefaultLib#65).A thrown parameter is kept (
OwnershipSignaturePass.cpp)function reject<T, R>(reason: R): T { throw reason; }didn't compile under own either way:@keeps, the throw's retain gave "'reason' is a parameter, kept here, but -mm=own cannot make the callers of 'reject' give it up".@keeps("reason"), it gave "'@keeps' of 'reject' names 'reason', but its body keeps nothing".OwnershipSignaturePass::keepshad no case for a throw. It now counts a throw of the value (ts.Throw,ts.ThrowCall,ts.ThrowUnwind) as keeping it, since the exception takes it. Inference already treats that as a move:releaseKeptParamsAtExitsdoesn't release a parameter at a throw that takes it. So callers move the argument in, a use of the argument afterwards is a use-after-move error, and a function that throws on one path and returns on the other releases the parameter on the return path.An awaited string that borrows its argument is copied (
OwnershipInferencePlaceReads.cpp)const s = await identity(greet("you"))gave "borrows the result of 'identity' and cannot be stored, returned or captured". The same line withoutawaitcompiled.The async lowering moves the await's region into its own
func.func, which stores the value through a reference to the caller's local. That function's temporaries (greet("you")) are released when it ends, so a borrow of them can't be handed back. A store of a copyable string (or a handle) through that reference now takes a copy, as a store into a place already does (spec 50,storesCopyOf). An object result that borrows its argument (await identity(new B(3))) still gets the error.Test
tests/00own_throw_param_await_borrow.ts:It's registered for compile and JIT under the default model and own, and runs under rc and none through
TSLANG_CORPUS. It also passes with--verify-ownership.Verification
ctest -C Release: 6637 tests, all passed (3 disabled as before).tests.ps1release compile + jit: gc 186/186; rc, none and own 185/186 (the gc-only skip). Under own this includespromise_reject.ts, which more no default opts finished #65 no longer skips there.🤖 Generated with Claude Code