Repository navigation
Add optional-producing call iteration #123
Description
Activity
- addedenhancementNew feature or requestNew feature or requestlanguage-modelPeeper language model, ownership, pointer, optional, array/slice workPeeper language model, ownership, pointer, optional, array/slice work
on Aug 31, 2026 Architecture planning update (no implementation): traced canonical method calls, optional extraction, CFG/effects, ownership and HIR/MIR. Proposed topology is once-only source initialization -> header checked advancement/result binding -> optional presence branch -> payload binding/body -> latch back to header. Generated operations must have indexed nodes/scopes and real CFG analysis sites before ownership; current loop segments lack those sites. HIR/MIR must consume the same operations without double execution. Reuse existing call adaptation, payload proofs, return origins and cleanup. Include nested optional items in coverage.
Item-only custom binding is working default pending final review; builtin index,value unchanged.
New design question: lowercase next is private under current uppercase export convention, and declared method lookup searches current module method table. Cross-module method visibility must be resolved centrally. Exported Next is a recommendation for review, not yet an approved spelling change. No private-method visibility bypass for iteration.
Implementation started on feature/structural-iterators. First slice: local concrete cursors, scalar items, one binding, exported Next() -> ?Item, static calls through central guards. No runtime interface iteration. Generated checked operations will enter CFG/flow/effects/ownership before lowering. Temporary sources, resource-bearing payloads and cross-module method availability remain follow-up scope; no implementation validation claimed yet.
Review refinement: user-facing iterator errors now describe source-level problems and actionable remedies instead of structural/concrete-cursor/scalar terminology. Added Next declaration/return-type labels, optional item/none guidance, argument/default explanations, index advice, local-variable workaround, explicit-loop alternative for unsupported item types, and interface-specific guidance. Recognition and ownership behavior unchanged. Diagnostic tests and negative fixture assert hints and exclude internal wording/hidden names. Validation passed: full Go suite, refreshed bundle, full bundled x_test suite, gofmt and git diff --check. Still uncommitted; first slice remains under user review.
- changed the title
[-]Add user-defined iterator protocol[/-][+]Add optional-producing call iteration[/+]on Sep 11, 2026 Documentation correction for the current implementation and PR #135: the feature is optional-producing call iteration, not a
Next()protocol.Current contract is
for item in producerCall()where any ordinary free-function, method, or pipe call returning?Tis valid. The complete call evaluates once per attempt, including the terminating attempt.Next()has no special language meaning; it is valid only as an explicitly written ordinary method call.The issue body and PR description now reflect this model. Earlier comments describe superseded design exploration and remain historical.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Goal
Add concise custom iteration syntax for ordinary calls that return optional values, while preserving built-in range, array, and slice loops.
Contract
for item in producerCall().producerCall()is an ordinary free-function, method, or pipe call.?T; a present result binds one item of typeT, andnoneends iteration.continuestarts another producer-call attempt;breakandreturndo not advance again.index, valuesequence behavior remains unchanged.Nextmethod are not producers unless the method call is written explicitly.Nextprotocol, source capture, iterator interface, vtable, boxing, generic constraint, or tuple prerequisite is added.Architecture
The typechecker expands valid optional-producing call loops into ordinary checked call, optional-test, payload-binding, and loop-control statements before CFG, flow, effects, definite-init, ownership, cleanup, HIR, and MIR. Downstream phases consume the checked expansion and do not rediscover producer calls.
The expansion intentionally keeps the complete producer call inside the loop because ordinary call evaluation occurs once per attempt. Existing call checking owns receiver adaptation, default arguments, move/borrow behavior, reference provenance, effects, and cleanup.
Coverage
Validation
go test ./...go test -race ./...go run ./scripts/bundle.goPEEPER_BIN=$PWD/build/bin/peeper go test -count=1 ./x_testgofmtandgit diff --checkCloses #123