Repository navigation
Sema/MIR: a join whose arms are all non-Copy field places is a view of those places (§3.8 join rule 3) (#1408, #1409) - #1553
Merged
ehartford merged 1 commit intoSep 24, 2026
Conversation
…f those places (§3.8 join rule 3) (#1408, #1409) Spec, §3.8 (Contextual Copy materialization): "A binding names what's there; an annotation demands what it says: an unannotated `let` binds the view unchanged, while a typed binding is an owned-value demand (D22 §6.2, D27). This is uniform across field projections and collection element access." and its join rules: "2. If an enclosing expected type or any reaching expression independently establishes an owned result type `J`, the join result is `J`. … 3. If all reaching expressions are compatible shared references, the result remains a shared reference and carries the union of their possible origins. 4. An owned temporary is never implicitly borrowed merely to force a reference result. 5. A reference to a non-`Copy` value cannot satisfy an owned demand …" §2.2 (D32): "A field never moves out implicitly — anywhere, in any context." D22 §5.1 lists field projection among exact-type preservation; D27 ruling 3: "uniformly for field projections and element access". An element arm is a view already (check_index types `v[i]` as `&T`, so `if c: v[0] else: v[1]` binds `&str`). A field arm was typed by its declared, owned type, so `if c: self.p else: self.q` saw two owned arms: since #1395 the D32 funnel rejects both arms (#1408); before it, lower_if moved the field into the join temp and the queued reset blanked the owner's field, so a second read saw "" (#1409, `[xy] [] []`). #1409's two acceptable outcomes were the view join or the D32 error; main has the error, and this delivers the view, so one change closes both. Sema: join_field_arms_as_views (check_if_expr and the match join, before resolve_contextual_join). When the expected type is absent or a reference, and every reaching arm is a reference or a place projection of a non-Copy, drop-bearing field (through groupings and block tails) whose storage root outlives the join, each field arm is typed `&F` and recorded in join_field_view_arms; the join is then all references and resolves to a view by rule 3. An owned arm or an owned expectation leaves the field arms owned — the D32 error stands (rule 2/5). A field of a call's result is no place (rule 4). collect_expr_view_deps gives a recorded field arm its place's storage root as an origin, as `&place.f` has, so the union of origins reaches the binding (rule 3; the #1406 element rule). MIR, the exact lines of #1409's mechanism: lower_expr lowered the arm as a value read (OK_MOVE of `_x.f0`) and consume_moved_operand queued the reset; for a block-tail arm, lower_block_mode's tail call to cancel_scheduled_value_drop_for_receiver_expr marked the field moved and queued the reset (`_1.s = const zst(ty16)` in the arm block, seen in --dump-mir and WITH_TRACE_RESETS `[reset-q] field place=22`). A recorded arm now lowers as `ref(shared, place)` (lower_join_field_view) and the receiver-drop cancel skips it. Matrix (32 cells, base = origin/main ba2d5d1 stage1 -> fixed): view now (all D32-rejected on base, leak count 0 fixed, owners intact): let-if, let-match, print(if), `peek(&str)(if)`, f-string hole, `.len()` on the join, typed `&str` binding, field + `&y.s` arm, nested `o.inner.s`/`o.t`, else-if chain, block-tail arm, `-> &str` return of `a.s`/`b.s` through `&S` params, 3-arm match with a nested if, mut fn receiver (the #1408 program: `a`, then `s.p` = `a`), read fn receiver, Vec field, `&S` params, loop then mutate after the loop, the #1409 program `[xy] [xy] [xy]`. still rejected: owned demand `take(if …)` and `let p: str = if …` (D32), field + owned `"lit".clone()` arm (D32), field of `mk()` (D32, rule 4), mutation of `x.s` / `self.p` while the view lives ("cannot mutate `x` while `p` is a live view into it"), `take(p)` of the view (wrong type). unchanged: `&x.s` arms, `.clone()` arms, Copy field join (`i32` value). --validate-all ok and `analyze audit:all` violations=0 on the #1408 program, the block-tail cell and the match cell. Every existing D32, join and §3.8 fixture passes on the fixed stage1. Fixtures: behav_field_join_view.w (exact stdout; base: D32 errors), da_field_join_view.w (leak count=0; base rejects), err_field_join_ {view_mutated,view_mut_recv_mutated,owned_demand,temporary_base}.w. Audits: move_audit gains field_{ifview,matchview,blockview}/{base}/{shape} (OK) and field_viewarg (FIELD-ERR); drop_audit gains field_join_view_ {if,match,block,recv} (sum 1; base COMPILE-FAIL). Scope kept, filed: #1531 — a Copy field binding copies while a Copy element binding views; Copy field joins stay values here to match the plain Copy field binding. #1530 — an explicit `move x.s` while a view of `x.s` is live is accepted (plain `let p = x.s` has the same hole).
ehartford
force-pushed
the
fix-1409-1408-field-join-view
branch
from
September 23, 2026 21:39
9c88efb to
4c609a7
Compare
ehartford
marked this pull request as ready for review
September 23, 2026 22:32
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.
Draft: layer 5 of 7 in the ownership/leaks stack (batch battery pending; iterate tier +
:drop-audit/:move-auditon the layer's stage1 done locally). Closes #1408, closes #1409. Filed on the way: #1530, #1531.Audits (tools/drop_audit.w + tools/move_audit.w, candidate = this layer's stage1, baseline = the pinned seed): drop-audit 197 cells, 0 non-PASS, 0 regressions; move-audit 105 cells, 0 vs-expected FAIL (12 new view-join cells).
Sema/MIR: a join whose arms are all non-Copy field places is a view of those places (§3.8 join rule 3) (#1408, #1409)
Spec, §3.8 (Contextual Copy materialization):
"A binding names what's there; an annotation demands what it says: an
unannotated
letbinds the view unchanged, while a typed binding is anowned-value demand (D22 §6.2, D27). This is uniform across field
projections and collection element access."
and its join rules:
"2. If an enclosing expected type or any reaching expression
independently establishes an owned result type
J, the join result isJ. …3. If all reaching expressions are compatible shared references, the
result remains a shared reference and carries the union of their
possible origins.
4. An owned temporary is never implicitly borrowed merely to force a
reference result.
5. A reference to a non-
Copyvalue cannot satisfy an owned demand …"§2.2 (D32): "A field never moves out implicitly — anywhere, in any
context." D22 §5.1 lists field projection among exact-type preservation;
D27 ruling 3: "uniformly for field projections and element access".
An element arm is a view already (check_index types
v[i]as&T, soif c: v[0] else: v[1]binds&str). A field arm was typed by itsdeclared, owned type, so
if c: self.p else: self.qsaw two owned arms:since #1395 the D32 funnel rejects both arms (#1408); before it, lower_if
moved the field into the join temp and the queued reset blanked the
owner's field, so a second read saw "" (#1409,
[xy] [] []). #1409's twoacceptable outcomes were the view join or the D32 error; main has the
error, and this delivers the view, so one change closes both.
Sema: join_field_arms_as_views (check_if_expr and the match join, before
resolve_contextual_join). When the expected type is absent or a
reference, and every reaching arm is a reference or a place projection of
a non-Copy, drop-bearing field (through groupings and block tails) whose
storage root outlives the join, each field arm is typed
&Fand recordedin join_field_view_arms; the join is then all references and resolves to a
view by rule 3. An owned arm or an owned expectation leaves the field arms
owned — the D32 error stands (rule 2/5). A field of a call's result is no
place (rule 4). collect_expr_view_deps gives a recorded field arm its
place's storage root as an origin, as
&place.fhas, so the union oforigins reaches the binding (rule 3; the #1406 element rule).
MIR, the exact lines of #1409's mechanism: lower_expr lowered the arm as a
value read (OK_MOVE of
_x.f0) and consume_moved_operand queued the reset;for a block-tail arm, lower_block_mode's tail call to
cancel_scheduled_value_drop_for_receiver_expr marked the field moved and
queued the reset (
_1.s = const zst(ty16)in the arm block, seen in--dump-mir and WITH_TRACE_RESETS
[reset-q] field place=22). A recordedarm now lowers as
ref(shared, place)(lower_join_field_view) and thereceiver-drop cancel skips it.
Matrix (32 cells, base = origin/main ba2d5d1 stage1 -> fixed):
view now (all D32-rejected on base, leak count 0 fixed, owners intact):
let-if, let-match, print(if),
peek(&str)(if), f-string hole,.len()on the join, typed
&strbinding, field +&y.sarm, nestedo.inner.s/o.t, else-if chain, block-tail arm,-> &strreturn ofa.s/b.sthrough&Sparams, 3-arm match with a nested if, mut fnreceiver (the #1408 program:
a, thens.p=a), read fn receiver,Vec field,
&Sparams, loop then mutate after the loop, the #1409program
[xy] [xy] [xy].still rejected: owned demand
take(if …)andlet p: str = if …(D32),field + owned
"lit".clone()arm (D32), field ofmk()(D32, rule 4),mutation of
x.s/self.pwhile the view lives ("cannot mutatexwhile
pis a live view into it"),take(p)of the view (wrong type).unchanged:
&x.sarms,.clone()arms, Copy field join (i32value).--validate-all ok and
analyze audit:allviolations=0 on the #1408program, the block-tail cell and the match cell. Every existing D32,
join and §3.8 fixture passes on the fixed stage1.
Fixtures: behav_field_join_view.w (exact stdout; base: D32 errors),
da_field_join_view.w (leak count=0; base rejects), err_field_join_
{view_mutated,view_mut_recv_mutated,owned_demand,temporary_base}.w.
Audits: move_audit gains field_{ifview,matchview,blockview}/{base}/{shape}
(OK) and field_viewarg (FIELD-ERR); drop_audit gains field_join_view_
{if,match,block,recv} (sum 1; base COMPILE-FAIL).
Scope kept, filed: #1531 — a Copy field binding copies while a Copy
element binding views; Copy field joins stay values here to match the
plain Copy field binding. #1530 — an explicit
move x.swhile a view ofx.sis live is accepted (plainlet p = x.shas the same hole).