You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Vec index/get element copies of Drop elements are ungated (double free); #607 gate covers for/match only #715
1e9e587 gated consuming for-loops and match-destructures of Vec[Drop]
(#607). The index-binding spelling was never gated:
let entry = state.entries[i] // Entry owns a Vec — element handle copied
Post-#691 this double-frees: the binding's drop and the vec's element drop
both free the element's buffers (issue61_query_state_stress reproduced it:
DOUBLE FREE first_drop=__drop_struct_106 second_drop=__drop_struct_107).
Vec.get(i) -> T by copy is the same class. This is the D23 surface (D22 §2.2
explicitly defers Vec/slice/array/iterator element ownership).
Until D23 lands, the sound spelling is let entry = &state.entries[i] (the
issue61 lib now uses it). A minimal gate matching 1e9e587's rule (non-Copy
needs-drop element, index/get copy into a binding) would close the silent
unsoundness; note it will also flag Vec.get copies inside the compiler and
stdlib, so it needs its own sweep.
Residual: after the borrow fix, issue61_query_state_stress still leaks 9
16-byte allocations (origin unknown) under WITH_DEBUG_ALLOC — likely the same
element/str copy debt; needs its own allocator pass.
Shipped in 61eaf45 + 1b41ef2 (battery green: build, fixpoint, :test, :move-audit, :drop-audit, :test-green, :last-green; seed + installed compiler now v0.15.1-g1b41ef21e).
What landed
Sema gate: a non-Copy, Drop-bearing element reached via vec.get(i) / vec[i] cannot satisfy an owned demand — by-value call argument, assignment into an owned place, or struct-literal field. Pinned by test/compile_errors/err_elem_copy_{call_arg,assign,struct_field}.w. While adding the assignment site I found plain x = vec[i] was never checked (the old reject call sat in the multi-index branch only) — fixed.
A plain let binding is deliberately NOT gated: D22 rules a view materializes an owned T only when an owned demand has already been established, and the issue-64 pins assert let item = inners.get(0); item.tags.push(99) mutates in place. First draft gated let and broke exactly those pins. Scope call recorded as decisions.md D26.
Vec[i32][1, 2] collection literals: gate consults index_expr_is_type_level (same predicate as check_index) so a type-level base is never misread as an element read.
Compiler + stdlib migrated off the copy-out pattern: ~45 sites across Mir, MirLower, MirSuspendCheck, AsyncMir, Zcu, CodegenUnits, Analysis, Lsp, BuildGraph*, main, and lib/std/build.w now borrow the element. CCodegen gained mir_body_at, the same frozen-module raw element handle Codegen uses (raw pointer hoisted into a local — deriving the reference straight from self.mir_mod.bodies.ptr still pins self in the view checker).
For Eric — two connected design points surfaced by this work
The real cure is D22 plan line 334: Vec element access as uniform view (&T) semantics. The interim gate keys on the get/index expression, so a let-bound element that is consumed later escapes it by design; under uniform view semantics the binding IS a &T and every later owned demand is checked structurally. When that lands, this gate should be subsumed/replaced.
Activity
ehartford commentedon Jul 28, 2026
Shipped in 61eaf45 + 1b41ef2 (battery green: build, fixpoint, :test, :move-audit, :drop-audit, :test-green, :last-green; seed + installed compiler now v0.15.1-g1b41ef21e).
What landed
vec.get(i)/vec[i]cannot satisfy an owned demand — by-value call argument, assignment into an owned place, or struct-literal field. Pinned by test/compile_errors/err_elem_copy_{call_arg,assign,struct_field}.w. While adding the assignment site I found plainx = vec[i]was never checked (the old reject call sat in the multi-index branch only) — fixed.letbinding is deliberately NOT gated: D22 rules a view materializes an owned T only when an owned demand has already been established, and the issue-64 pins assertlet item = inners.get(0); item.tags.push(99)mutates in place. First draft gated let and broke exactly those pins. Scope call recorded as decisions.md D26.Vec[i32][1, 2]collection literals: gate consultsindex_expr_is_type_level(same predicate ascheck_index) so a type-level base is never misread as an element read.mir_body_at, the same frozen-module raw element handle Codegen uses (raw pointer hoisted into a local — deriving the reference straight fromself.mir_mod.bodies.ptrstill pinsselfin the view checker).For Eric — two connected design points surfaced by this work
&T) semantics. The interim gate keys on the get/index expression, so a let-bound element that is consumed later escapes it by design; under uniform view semantics the binding IS a&Tand every later owned demand is checked structurally. When that lands, this gate should be subsumed/replaced.analyze: seam-sites — inventory ownership seams before they detonate
handoff: record the Stage 6 batch — 19 roots, evidence, and open rulings
Eliminate the three copy-elem-drop seams: elements are borrowed, not …
D22 #715: gate non-Copy Drop element copies out of Vec at owned demands
D26 #715: element-copy gate narrows to owned demands; let is not a de…
build/emit_c.w: move exports into the aggregate instead of copying (#715
Handoff: D27 enshrined and E1+E2 landed; stage2 miscompile blocks the…
D27: err_elem_copy_call_arg pin follows the structural diagnostic (#740)
D27: make positional element access observe through views (#740)