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
Comprehension over a Drop-class Vec: element copied by VEC_GET into a &T-typed local (garbage to &str params) and the receiver is moved out #934
Sibling of #925 (the for form is fixed there). Pre-existing on the current seed.
Repro
fn peek_str(s: &str) -> i64: s.len()
fn main:
var ss: Vec[str] = Vec.new()
ss.push("hello")
let a: Vec[i64] = [peek_str(s) for s in ss] // first = 0
let b: Vec[i64] = [peek_str(s) for s in ss.iter()] // first = 4331063280
Expected 5 and 5.
Evidence (--dump-mir, bare form)
_6 = move _1; <- the source Vec is MOVED into a temp; `ss` is blank afterwards
call const fn sym187(copy _6, copy _8) -> [return: _10, next: bb9]; <- VEC_GET (copy) into _10: ty17 (&str)
_11 = copy _10;
call const fn sym659(copy _11) -> ... <- peek_str(copy s)
lower_comprehension_vec (src/MirLower.w) types the element with infer_for_element_type_frozen (Drop-class → &T, same split as for) but fills it with emit_vec_get_into = the VEC_GET copy intrinsic, and materializes the receiver with materialize_operand (a move). lower_for_iter_ref already does this right for the same case: borrow the receiver place (no header copy — the #607 double-free note) and read elements with VEC_GET_REF into the &T local. The comprehension path should share that lowering rather than re-derive it.
Sema side: after #925, for_loop_element_type also types comprehension bindings over vec.iter() as &T for Drop-class elements, so the types agree; the remaining defect is the MIR read/receiver handling above.
Fixture to add with the fix: comprehension × (bare, .iter()) × (str, Vec[i32], struct, i32) → &T parameter, plus ss still usable after the comprehension.
Stronger evidence: the receiver move blanks the source for every element class, not just Drop-class ones.
let v: Vec[i32] = [1, 2, 3]
let w: Vec[i32] = [x * 2 for x in v]
print(f"{v.len()} {w.len()}") // 0 3 — expected 3 3
and for Vec[str] the source is blanked and the element read is garbage (7955890216726691840), then a later comprehension panics with "Vec index out of bounds" on the now-empty source.
Fix in progress: lower_comprehension_vec reads a place receiver through its place (as lower_for_vec does — no header move) and uses VEC_GET_REF for &T element types (as lower_for_iter_ref does). Fixture behav_comprehension_view_to_fn covers bare/.iter() × str/Vec/struct/i32 → &T parameter plus source-still-usable for Copy- and Drop-class sources.
Fixed in 891fd01. lower_comprehension_vec now reads a place receiver (ident, field, index) through its own place — no header move, exactly as lower_for_vec — and reads Drop-class elements with VEC_GET_REF into the &T local, exactly as lower_for_iter_ref; Copy-class elements keep VEC_GET by value. Only rvalue receivers still materialize an owning temp. MIR for the bare str case: zero moves of the source Vec, one VEC_GET_REF read.
Results: [x * 2 for x in v] leaves v intact; [peek(s) for s in strs] and the .iter() form pass the view intact; the follow-on out-of-bounds panic is gone.
Fixture behav_comprehension_view_to_fn: bare and .iter() comprehensions over str, Vec[i32], a struct, and i32 reach a &T parameter, and Copy- and Drop-class sources remain usable afterwards. Isolated battery: build, fixpoint, move-audit (15 cells, 0 diff), drop-audit (115 cells, 0 regressions), test — all green; reseeded.
Activity
Sema: `for x in vec.iter()` binds the same element type MirLower lowe…
ehartford commentedon Sep 2, 2026
Stronger evidence: the receiver move blanks the source for every element class, not just Drop-class ones.
and for
Vec[str]the source is blanked and the element read is garbage (7955890216726691840), then a later comprehension panics with "Vec index out of bounds" on the now-empty source.Fix in progress:
lower_comprehension_vecreads a place receiver through its place (aslower_for_vecdoes — no header move) and uses VEC_GET_REF for&Telement types (aslower_for_iter_refdoes). Fixturebehav_comprehension_view_to_fncovers bare/.iter()× str/Vec/struct/i32 →&Tparameter plus source-still-usable for Copy- and Drop-class sources.MirLower: comprehensions borrow their source Vec and read element vie…
ehartford commentedon Sep 2, 2026
Fixed in 891fd01.
lower_comprehension_vecnow reads a place receiver (ident, field, index) through its own place — no header move, exactly aslower_for_vec— and reads Drop-class elements with VEC_GET_REF into the&Tlocal, exactly aslower_for_iter_ref; Copy-class elements keep VEC_GET by value. Only rvalue receivers still materialize an owning temp. MIR for the bare str case: zero moves of the source Vec, one VEC_GET_REF read.Results:
[x * 2 for x in v]leavesvintact;[peek(s) for s in strs]and the.iter()form pass the view intact; the follow-on out-of-bounds panic is gone.Fixture
behav_comprehension_view_to_fn: bare and.iter()comprehensions over str, Vec[i32], a struct, and i32 reach a&Tparameter, and Copy- and Drop-class sources remain usable afterwards. Isolated battery: build, fixpoint, move-audit (15 cells, 0 diff), drop-audit (115 cells, 0 regressions), test — all green; reseeded.