Skip to content

Collections: stream fusion over List and Map sources #64

@MelbourneDeveloper

Description

@MelbourneDeveloper

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions