Skip to content

Add optional-producing call iteration - #135

Merged
itsfuad merged 5 commits into
mainfrom
feature/structural-iterators
Sep 11, 2026
Merged

Add optional-producing call iteration#135
itsfuad merged 5 commits into
mainfrom
feature/structural-iterators

Conversation

@itsfuad

@itsfuad itsfuad commented Sep 8, 2026

Copy link
Copy Markdown
Member

Summary

  • add concise for item in producerCall() syntax for ordinary calls returning ?Item
  • expand valid calls into checked call, optional test, payload binding, and loop control before CFG and ownership analysis
  • preserve ordinary call evaluation on every attempt, including callee, receiver, arguments, and the terminating call
  • support free-function, method, and pipe producers with existing default-argument, borrow, move, effect, provenance, and cleanup rules
  • keep built-in range, array, and slice iteration unchanged
  • add source-facing diagnostics, language-spec coverage, LSP hover coverage, semantic regressions, lifecycle checks, and bundled runtime fixtures

Contract

  • one custom item binding: for item in producerCall()
  • producer call must return ?T; none ends iteration and a present result binds one T
  • continue performs another complete producer-call attempt; break and return do not advance again
  • no implicit index for custom calls; built-in index, value behavior remains unchanged
  • free functions, methods of any name, and pipe calls use canonical ordinary call checking
  • no implicit Next protocol, source capture, iterator interface, vtable, boxing, generic constraint, or tuple prerequisite

Architecture

Generated operations are stored as checked semantic expansion and consumed by CFG, flow, effects, definite-init, ownership, cleanup, HIR, and MIR. Lowering does not rediscover calls or synthesize hidden producer behavior. The complete producer call intentionally remains inside the loop because it evaluates once per attempt under ordinary call semantics.

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 test -race ./...
  • go run ./scripts/bundle.go
  • PEEPER_BIN=$PWD/build/bin/peeper go test -count=1 ./x_test
  • gofmt and git diff --check

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
@itsfuad itsfuad self-assigned this Sep 11, 2026
@itsfuad itsfuad changed the title Add structural custom iteration Add optional-producing call iteration Sep 11, 2026
@itsfuad

itsfuad commented Sep 11, 2026

Copy link
Copy Markdown
Member Author

PR description correction: this change implements optional-producing call iteration, not an implicit Next() protocol.

Valid form is for item in producerCall() for any ordinary free-function, method, or pipe call returning ?T. The complete call evaluates once per attempt, including the terminating attempt. Next() is not special; explicit cursor.Next() works only through ordinary method-call semantics.

Earlier issue/PR comments describe superseded design exploration and remain historical.

@itsfuad
itsfuad merged commit 0a6a7e1 into main Sep 11, 2026
14 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in Peeper Roadmap Sep 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Add optional-producing call iteration

2 participants