Scope
Phase 7 of docs/plans/collections.md. The existing iterator-fusion pass already merges xs |> filter |> map |> fold into a single loop for range(...) sources. Extend that pass to recognise List<T> and Map<K, V> as Iterable sources via osprey_list_iter_init / osprey_map_iter_init.
Phase 7.1 (forEachList) is already done. Remaining: 7.2 (fusion through pipe chains) and 7.3 (benchmarks).
Required work
- Teach
compiler/internal/codegen/iterator_generation.go that List<T> and Map<K, V> count as iterable sources at the pipe entry point.
- Verify the lowered IR for
xs |> filter(p) |> map(f) |> fold(g, 0) has one loop body and no intermediate alloca for the materialised collection.
- Benchmark
filter |> map |> fold over a 10⁶-element list vs. a hand-written C loop; record in compiler/runtime/BENCHMARKS.md (target: within 1.5×).
Acceptance
- The IR test passes (single loop, no intermediates).
- Benchmark within 1.5× of the C loop.
- A tested example in
compiler/examples/tested/basics/lists/ exercises the fused pipeline.
Origin
docs/plans/collections.md Phase 7.2 and 7.3 (deferred).
Scope
Phase 7 of
docs/plans/collections.md. The existing iterator-fusion pass already mergesxs |> filter |> map |> foldinto a single loop forrange(...)sources. Extend that pass to recogniseList<T>andMap<K, V>as Iterable sources viaosprey_list_iter_init/osprey_map_iter_init.Phase 7.1 (
forEachList) is already done. Remaining: 7.2 (fusion through pipe chains) and 7.3 (benchmarks).Required work
compiler/internal/codegen/iterator_generation.gothatList<T>andMap<K, V>count as iterable sources at the pipe entry point.xs |> filter(p) |> map(f) |> fold(g, 0)has one loop body and no intermediate alloca for the materialised collection.filter |> map |> foldover a 10⁶-element list vs. a hand-written C loop; record incompiler/runtime/BENCHMARKS.md(target: within 1.5×).Acceptance
compiler/examples/tested/basics/lists/exercises the fused pipeline.Origin
docs/plans/collections.mdPhase 7.2 and 7.3 (deferred).