Skip to content

-mm=own: a field taken out of an object a const names (spec 64) - #729

Merged
ASDAlexander77 merged 1 commit into
mainfrom
own-class-field-take
Oct 29, 2026
Merged

ASDAlexander77 merged 1 commit into
mainfrom
own-class-field-take

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

Summary

-mm=own spec 64: a field can be moved out of an object a const names. const r = new Holder(); return r.value, c ? initial : r.value and initial ?? r.value used to fail with "'this value' borrows a field and cannot be stored, returned or captured".

A const holding new's (or a call's) own result is folded into that SSA value, so r.value has spec 63's shape (a field of a temporary) with a named owner. namedFieldTakeOf treats the read as a move when:

  1. nothing sees the object after the read but its releases: no method, no move of it, no read of that field, and no borrow made of it earlier (followed transitively) used afterwards. Other fields stay readable;
  2. the read cannot run again on the same object (a loop around the read but not around new);
  3. rc's retain of the read is in the read's block.

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, consumeConditionalResults retains 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. findReceiverRetains gets a mode that only asks: its let path marks the slot as the acquisition, and calling it early for the gate broke let x = c ? a : b.

Changed test: own_err_container_read_stored (h2.c = h.c) is now a legal move when h is not read again, so the test reads h.c afterwards to stay an error.

Not covered: a let of a class type (a slot, not a folded name), or a push into a global array (spec 25).

Tests

  • own_named_field_take under 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 from new in 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, and let h = r read afterwards (both rejected).
  • Windows: ctest 6248/6248; DefaultLib gc 178, rc/none 177 (+1 skipped), own 167 (+11 skipped)

🤖 Generated with Claude Code

`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>
@ASDAlexander77
ASDAlexander77 merged commit 645b063 into main Oct 29, 2026
2 checks passed
@ASDAlexander77
ASDAlexander77 deleted the own-class-field-take branch October 29, 2026 08:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant