Repository navigation
-mm=own: an object literal whose arrows capture an object borrows it (spec 67) - #736
Merged
Merged
Conversation
…(spec 67)
`const b = new Box(5); const q = { w: (x: number) => x * b.n }; q.w(1);
b.n` was "'this value' is used here after its value was moved": the
literal's `.captured` box took `b`, where a closure that does not escape
only borrows what it captures. The literal has no release, and rc no
reference of the box's own it gives back: the box only ever borrowed.
classifyLiteralCaptures: a capture box filled field by field and stored
once into the `.captured` field of the local a literal is built in, read
once into the object ts.New made. When walkBorrowed from that object
finds nothing that keeps it, each copy with an owner of its own is a
borrowing store (OWN_CAPTURE_BORROW_ATTR_NAME), rc's retain before it is
erased, and the literal's uses are the borrowed value's.
Test: own_literal_object_captures (own, rc, gc, none). A literal given to
an interface still moves the object (the cast copies the 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.
-mm=own: an object literal whose arrows capture an object borrows it (spec 67).
const b = new Box(5); const q = { w: (x: number) => x * b.n }; q.w(1); print(b.n)failed under own with "'this value' is used here after its value was moved". The literal's.capturedbox took ownership ofb, while a plain arrow function capturingbonly borrows it.In every model, MLIRGen gives the literal no release, and rc gives the box no reference it later gives back. So the box only ever borrowed; own now says so:
classifyLiteralCapturespicks out a capture box that is filled field by field and stored into the.capturedfield of the local the literal is built in, where that local is read once into the objectts.Newmade.walkBorrowedfrom that object must find nothing that keeps it; calling its members and passing it to an object-type parameter (spec 66) are fine.Test:
own_literal_object_captures, under own, rc, gc and none. It captures a local object and a parameter, calls members, passes the literal to an object-type parameter, reads the objects afterwards, and churns memory between steps.Not covered: a literal passed to an interface. The cast copies the literal into the interface's object, so the captured object stays moved into the box.
Validation: ctest 6324/6324. DefaultLib release JIT: gc 181/181, rc and none 180 (1 skipped), own 170 (11 skipped).
🤖 Generated with Claude Code