Skip to content

Add structural custom iteration - #135

Open
itsfuad wants to merge 4 commits into
mainfrom
feature/structural-iterators
Open

Add structural custom iteration#135
itsfuad wants to merge 4 commits into
mainfrom
feature/structural-iterators

Conversation

@itsfuad

@itsfuad itsfuad commented Sep 8, 2026

Copy link
Copy Markdown
Member

Summary

  • recognize statically resolved Next() -> ?Item methods for custom for item in source loops
  • expand custom iteration into ordinary checked calls, optional tests, payload binding, and loop control before CFG and ownership analysis
  • evaluate sources once while preserving existing place identity and canonical borrow, move, provenance, and cleanup behavior
  • support local, parameter, field, reference, dynamic-index, factory, and literal sources
  • support scalar, aggregate, owned-pointer, nested-optional, and legal reference items
  • add source-facing diagnostics, language specification, LSP hover coverage, differential tests, lifecycle checks, and bundled runtime fixtures

Protocol

  • method-only Next; exactly receiver, no extra/defaulted parameters
  • optional return where outer none ends iteration
  • one custom item binding; no synthesized index
  • concrete static dispatch only
  • no Iterator interface, vtable, boxing, generic constraint, free-function fallback, or tuple prerequisite

Architecture

Generated operations are stored as checked semantic expansion and consumed by CFG, flow, effects, definite-init, ownership, HIR, and MIR. Lowering does not rediscover methods or synthesize hidden calls. Exact payload-depth evidence removes one outer optional layer without flattening optional Item.

Dynamic indexed places capture one reference according to receiver mutability, preserving one-time index evaluation without moving or copying cursor storage.

Validation

  • go test ./internal/semantics/typechecker ./internal/semantics/ownership ./internal/semantics/effect ./internal/semantics/definiteinit ./internal/ir/cfg ./internal/ir/hir/lower ./internal/ir/mir ./internal/lsp
  • go test ./...
  • go run ./scripts/bundle.go
  • PEEPER_BIN=/home/itsfuad/Dev/Peeper/compiler/build/bin/peeper go test -count=1 ./x_test
  • gofmt on touched Go files
  • git diff --check

Separate follow-up boundaries

Cross-module method discovery and broader reference-storage/provenance capabilities remain owned by ordinary lookup and ownership systems. This change adds no iterator-specific workaround; future central improvements flow through the same checked expansion.

Closes #123

Recognize Next() returning an optional scalar item with one loop binding. Expand into checked calls, optional guards and scoped bindings before CFG, effects and ownership analysis; preserve built-in loops and central receiver guards.

Keep temporary sources, complex places, richer items and cross-module method discovery outside this first slice. Add actionable diagnostics, phase regressions and runnable positive/negative fixtures.

Share synthetic node IDs with default expansion, preserve lexical scope identity through InsertParent, centralize structural recognition and reuse generated-node indexing. These helpers protect semantic invariants and avoid duplicated phase logic.

Validated with go test ./..., go run ./scripts/bundle.go, the full bundled x_test suite, gofmt and git diff --check. Refs #123.
Evaluate struct factories and literals once in an ordinary scoped binding. Generalize checked iteration evidence to a block so central cleanup handles source lifetime on exhaustion, break and return without affecting existing local cursor storage.

Migrate CFG, typed-node indexing and HIR consumers. Add counted runtime factory coverage and cleanup-plan assertions; preserve canonical move checks and helpful diagnostics. No new production helpers or ownership policy.

Validated with go test ./..., go run ./scripts/bundle.go, full bundled x_test suite, gofmt and git diff --check. Richer item binding and general place capture remain tracked in #123.
Preserve existing place identity, capture dynamic indexed places once, and materialize produced sources through ordinary bindings.

Carry exact one-layer optional payload evidence so aggregate, owned, nested-optional, and reference items use canonical flow and ownership machinery.
@itsfuad itsfuad moved this from Todo to In Progress in Peeper Roadmap Sep 8, 2026
@itsfuad
itsfuad requested a lite review from Copilot September 9, 2026 14:57

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Order type declarations by completion dependencies and refresh legal recursive generic instances in place. Reuse checked producer-call evidence and keep redundant optional syntax diagnostics in parser.

Shared typeInstanceUnderlying helper keeps initial and completion construction identical while preserving cached type identity.

Tests: go test ./... -count=1
Tests: CCACHE_DISABLE=1 go run ./scripts/bundle.go
Tests: bundled peeper x_test suite
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

Add user-defined iterator protocol

2 participants