Skip to content

std: ListIter is a view of the list; the list-iterator intrinsics retire (#2220 step 2) - #2526

Merged
ehartford merged 3 commits into
mainfrom
listiter-view
Oct 21, 2026
Merged

ehartford merged 3 commits into
mainfrom
listiter-view

Conversation

@ehartford

@ehartford ehartford commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

#2220 step 2 (Eric's Option 2 ruling): ListIter[T] is std's view of the list — { list: &List[T], idx: isize } with a next() body yielding &T through the element place (D27, bounds-checked by len() and xs[i]), impl Iter[&T], List.iter() as the Iterable impl's one definition (D65: an inherent twin of the same name registered twice). The four list-iterator intrinsics (VECITER_NEXT, LIST_ITER, LIST_ITER_REF, VECITERREF_NEXT), ListIterRef and their layouts leave Sema, MIR, LLVM codegen, emit-C and TypeLayout; the #2145 iter→iter_ref rewrite and the by-value Copy flavor are gone, so a list's adapters are std.traits' bodies. The terminals those bodies lacked are written in std (sum, product via a new One trait, min, max, min_by, max_by, reduce, partition, unzip, flat_map, zip_with, collect into HashSet/BTreeSet), each with a _views twin for an iterator of views (D22 §6.2, D139); Default for f32/f64. for x in xs.iter() keeps the implicit form's counter loop through Sema's for_list_iter_recvs record. lib/std/traits.w one-liners drop their inferable return types (review). behav_1346 renames its own One trait (#2520). Measured: the view iterator is 1.6× faster than the retired intrinsic (1.14 ms vs 1.84 ms, 4M i64, -O3); with #2527 the std pipeline is within 5% of the retired intrinsics. 108 iterator and 60 trait fixtures green; gate green. Layer 1 of stack #2528.

Eric Hartford added 3 commits October 21, 2026 00:05
…ters are With bodies

`ListIter[T]` is `{ list: &List[T], idx: isize }` with a `next()` body
yielding `&T` through the element place (D27, bounds-checked by `len()` and
`xs[i]`), `impl Iter[&T]`, and `List.iter()` / `iter_ref()` as std methods;
Sema's ListIter/ListIterRef intrinsic rows, builtin return types, the
#2145 iter->iter_ref rewrite and the by-value Copy flavor are gone, so a
list's adapters are std.traits' bodies (map, filter, fold, ...). The
terminals those bodies lacked are written: sum, product (trait One), min,
max, min_by, max_by, reduce, partition, unzip, flat_map, zip_with, and
collect into HashSet / BTreeSet, each with a `_views` twin for an iterator
of views (D22 section 6.2, D139); Default for f32/f64. `for x in xs.iter()`
stays the implicit form's counter loop through Sema's for_list_iter_recvs
record (D65). The intrinsics themselves retire in the next commit.
… inferable return types

VECITER_NEXT, LIST_ITER, LIST_ITER_REF and VECITERREF_NEXT leave MirIntrinsic,
the LLVM emitters, the emit-C builtins and every predicate list; ListIterRef
(a Sema-synthesized type) and its layouts in Codegen, TypeLayout and emit-C
go with them; the dead ListIter/ListIterRef branches of the adapter next
emitters too. 108 iterator fixtures and 60 trait fixtures green on stage1.

lib/std/traits.w: `impl Default for i32: fn default(): 0` and the like --
the trait declares the return, so the written type was ceremony (a
reviewer caught it on the new One impls; the neighbours are folded the
same way). behav_1346 renames its own `One` trait to PlusTwo with a
comment: a same-named user trait rebinds std's impls (#2520).
… (D65)

An inherent `List.iter` beside `impl Iterable for List: fn iter` and an
inherent `ListIter.next` beside `impl Iter for ListIter: mut fn next`
registered two declarations under one method symbol; audit:all named
both (method registration missing, impl-mismatch). The trait impls carry
the bodies; `iter_ref` stays an inherent alias.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant