Repository navigation
-mm=own: an object literal capturing an object, given to an interface, borrows it (spec 68) - #739
Merged
Merged
Conversation
…n interface, borrows it (spec 68)
`use({ greet: () => "hi" + b.n }); b.n` for `use(g: Greeter)` was "used after its value was
moved": the interface's release freed the literal's `.captured` box with every copy in it.
- The signature pass marks `.captured` as a field a borrowing record (spec 32) borrows when each
copy in the box has an owner of its own and nothing keeps or returns the interfaces.
- That record's release frees such a box alone (tsfrecb_).
- Inference bounds the copies by the record's uses (walkRecord) in place of walkBorrowed.
- checkBoundedResults skips results that own no block (a number bounded by a state-shaped literal).
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, an object literal whose arrows capture an object, passed to an interface parameter, moved the object into the literal:The interface is a view of the literal's box (
ts.NewInterface). When the interface is released, it frees the.capturedbox and every copy in it, so spec 67's borrow could not apply.Spec 68
capturedBoxBorrows):.capturedbecomes one more field a borrowing record (spec 32) borrows. This happens only when:releaseFields): a borrowed capture-box field is freed withtsfrecb_, which frees the box but not what it holds.classifyLiteralCaptures): the copies are bounded by the record's uses (walkRecord).classifyRecordsleaves the.capturedstore alone.checkBoundedResultsnow skips results that own no block. Before, a literal capturing a parameter boundedviaParam's number result, andprint(viaParam(c))was an error.Test
New test
own_literal_interface_captures, run under own, rc, gc and none, with churn between steps:Not covered (unchanged)
let.return applyO({ w: (x) => x + item.n })with an object-type parameter.Results
ctest: 6345/6345.
DefaultLib release jit:
This ran against DefaultLib before Ts support #59, which needs Object literal into an interface union; fewer-parameter callback fixes; design notes #738.
🤖 Generated with Claude Code