Skip to content

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 into
fix-1403-comprehension-refutablefrom
fix-1409-1408-field-join-view
Sep 24, 2026
Merged

ehartford merged 1 commit into
fix-1403-comprehension-refutablefrom
fix-1409-1408-field-join-view

Conversation

@ehartford

Copy link
Copy Markdown
Contributor

Draft: layer 5 of 7 in the ownership/leaks stack (batch battery pending; iterate tier + :drop-audit/:move-audit on 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 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
ehartford added this pull request to stack #1556 September 23, 2026 19:42
…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
ehartford force-pushed the fix-1409-1408-field-join-view branch from 9c88efb to 4c609a7 Compare September 23, 2026 21:39
@ehartford
ehartford marked this pull request as ready for review September 23, 2026 22:32
@ehartford
ehartford merged commit c8cce31 into main Sep 24, 2026
@ehartford
ehartford deleted the fix-1409-1408-field-join-view branch September 24, 2026 16:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant