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
names.iter() |> filter(...) double-frees every kept element of a Vec[str] #2145
Same with |> filter(...) |> map(it.len()) |> sum() and |> filter(...) |> collect[Vec](). names.iter() |> count() (no filter) is clean. Any element type that owns something is affected (an enum with a str payload too).
Reading so far (to be confirmed at the line): the filter stage builds its result vector by storing each kept element's bytes and pushing them (with_vec_push in the filter intrinsic of src/CodegenDispatch.w), and that vector is then dropped as if it owned the elements, while names still owns them.
Found while testing #2137; not caused by it (the installed compiler reproduces it).
Located. lib/std/collections.w: pub type VecIter[T] ephemeral { data_ptr, len, idx } with impl[T] Iter[T] for VecIter[T]: mut fn next() -> Option[T], so names.iter() hands each element out by value, and the stage type is FilterIter[VecIter[str], str] with pred: fn(T) -> bool. The predicate receives a byte copy of the element and drops it; names drops it again. names.iter() |> count() is clean only because nothing binds the copies.
The spec already rules it: §9.7's example says .iter() yields &(str, i32), and the stdlib inventory says of VecIter[T] "iteration must preserve element views" (D27/D44: traversal observes). The implementation is non-compliant: Vec.iter() must yield &T, and the adapters carry that view. That is the fix; its reach is every .iter() pipeline, so it gets its own change after #2137.
Status (2026-10-05): the swap itself works and is on the draft #2150 (v.iter() over non-Copy elements is the view iterator, except as a loop's own iterable and where the by-value type is expected; every double-free form is clean under the allocator). It was taken out of the landed stack because six existing tests depend on collecting owned collections straight from .iter() over non-Copy elements, and the conforming spellings hit gaps:
xs.into_iter() |> collect[HashMap[K, V]]() / collect[BTreeMap] / collect[BTreeSet]: "collect[] over a VecIntoIter[…] is not available: an Iter[T] implementor collects into a Vec".
xs.iter() |> map(it.clone()) |> collect[…] over Vec[(str, i32)]: "unknown method 'clone' for type '&(str, i32)'" (a tuple of Clone elements has no clone).
iter_ref().next() on a temporary skipped §15.3's place-receiver rule (fixed on the branch).
Tests to move once 1 and 2 exist: spec_ss13_3_collect_targets (two lines), spec_ss13_3_collection_operations, err_collect_btree_unimplemented, err_iter_next_rvalue_receiver. Order of work: tuple clone, collect targets from a consuming iterator, then this.
Activity
ehartford commentedon Oct 5, 2026
Located.
lib/std/collections.w:pub type VecIter[T] ephemeral { data_ptr, len, idx }withimpl[T] Iter[T] for VecIter[T]: mut fn next() -> Option[T], sonames.iter()hands each element out by value, and the stage type isFilterIter[VecIter[str], str]withpred: fn(T) -> bool. The predicate receives a byte copy of the element and drops it;namesdrops it again.names.iter() |> count()is clean only because nothing binds the copies.The spec already rules it: §9.7's example says
.iter() yields &(str, i32), and the stdlib inventory says ofVecIter[T]"iteration must preserve element views" (D27/D44: traversal observes). The implementation is non-compliant:Vec.iter()must yield&T, and the adapters carry that view. That is the fix; its reach is every.iter()pipeline, so it gets its own change after #2137.sema: v.iter() over elements that own something is the view iterator (#…
fixup #2145: a loop's own iterable and std's Iterable.iter keep the b…
ehartford commentedon Oct 5, 2026
Status (2026-10-05): the swap itself works and is on the draft #2150 (
v.iter()over non-Copy elements is the view iterator, except as a loop's own iterable and where the by-value type is expected; every double-free form is clean under the allocator). It was taken out of the landed stack because six existing tests depend on collecting owned collections straight from.iter()over non-Copy elements, and the conforming spellings hit gaps:xs.into_iter() |> collect[HashMap[K, V]]()/collect[BTreeMap]/collect[BTreeSet]: "collect[]over a VecIntoIter[…] is not available: an Iter[T] implementor collects into a Vec".xs.iter() |> map(it.clone()) |> collect[…]overVec[(str, i32)]: "unknown method 'clone' for type '&(str, i32)'" (a tuple of Clone elements has noclone).iter_ref().next()on a temporary skipped §15.3's place-receiver rule (fixed on the branch).for x in v.iter_ref()and a comprehension over it fail in MIR lowering on main (see for cannot iterate an iterator adapter: §13.5'sfor (i, item) in collection.enumerate()does not compile #2152).Tests to move once 1 and 2 exist: spec_ss13_3_collect_targets (two lines), spec_ss13_3_collection_operations, err_collect_btree_unimplemented, err_iter_next_rvalue_receiver. Order of work: tuple
clone, collect targets from a consuming iterator, then this.WIP #2145: place rule for the view iterator's next; tests that collec…
v.iter() over elements that own something yields views; every iterato…
v.iter() over elements that own something yields views; every iterato…
ehartford commentedon Oct 5, 2026
Fixed on main baa84b2 (#2150); battery green on the stack.
std: ListIter is a view of the list; the list-iterator intrinsics ret…