Repository navigation
-mm=own: a field taken out of an object a const names (spec 64) - #729
Merged
Merged
Conversation
`const r = new Holder(); return r.value`, `c ? initial : r.value` and `initial ?? r.value` were "'this value' borrows a field and cannot be stored, returned or captured". A `const` whose value is `new`'s or a call's own result is folded into that value, so the read is spec 63's shape with a named owner. namedFieldTakeOf moves the read out of the field when nothing sees the object after the read but its releases (no method, move, read of that field, nor a borrow made of it before), the read is not made again on the same object, and rc's retain of it is in its block; the field is emptied right at the read, so a release after a merge frees nothing of a path that did not take it. Under own, consumeConditionalResults retains such a branch yield in the branch when a receiver keeps the merge, so the take sees its retain; a merge only read stays a borrow. findReceiverRetains gets a mode that only asks, without marking a `let` as the acquisition. own_err_container_read_stored reads `h.c` after `h2.c = h.c`: without that read it is now a move. 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.
Summary
-mm=own spec 64: a field can be moved out of an object a
constnames.const r = new Holder(); return r.value,c ? initial : r.valueandinitial ?? r.valueused to fail with "'this value' borrows a field and cannot be stored, returned or captured".A
constholdingnew's (or a call's) own result is folded into that SSA value, sor.valuehas spec 63's shape (a field of a temporary) with a named owner.namedFieldTakeOftreats the read as a move when:new);The field is emptied right at the read, not at the release: after a
?:the release stands on every path, and emptying there would leak the field on a path that did not take it.rc side: under own,
consumeConditionalResultsretains a branch that yields such a field inside the branch, but only when a receiver keeps the merge; a merge that is only read stays a borrow.findReceiverRetainsgets a mode that only asks: itsletpath marks the slot as the acquisition, and calling it early for the gate brokelet x = c ? a : b.Changed test:
own_err_container_read_stored(h2.c = h.c) is now a legal move whenhis not read again, so the test readsh.cafterwards to stay an error.Not covered: a
letof a class type (a slot, not a folded name), or a push into a global array (spec 25).Tests
own_named_field_takeunder own/rc/gc/none, churning between steps: return,?:,??, the read used before it is returned, another field read after, a merge that is only read, a push fromnewin a loop, and a call's result. The ownership verifier is silent and the own build has no counting.own_err_named_field_{read_again,method_after,object_moved,borrow_after}; also checked by hand: a loop around the read only, andlet h = rread afterwards (both rejected).🤖 Generated with Claude Code