126. Library loops are generators; early exit stays in for (2026-11-21)
- Decision. Loop-shaped library facilities (traversals, enumerations,
divisors, submasks, enter/exit walks) are generators consumed with a
plain
for.break,continue,return, labelledbreak 'outerand loopelse(§125) work in that body even when the generator is recursive: the compiler inlines a non-recursive push generator to a jump, and threads a hidden stop path through the frames of a recursive one, only in specializations whose body can exit (cpl explainshows it). Enter/exit walks yield events (Enter(v)/Exit(v)). A body that steers the generator uses a method on the yielded item, read by the generator after theyieldreturns (step.prune()skips a subtree); this is ordinary library code. Lockstep over recursive generators isList(g)(4.2's existing error). Folds and predicates stay closures (t.up(+, finish:),bsearch_first). - Deferred.
return/breakinside a closure literal acting on the enclosing function (Kotlin's inline lambdas, Ruby blocks). Revisit only if ports keep needing early exit from closure-shaped library calls. - Why. Library loops get exactly the control flow of built-in loops
with no per-library protocol (no
ControlFlowvalues, nofoundflags), which is the no-privileged-stdlib test; and no closure ever has two meanings ofreturn. - Reverse. Allow closure-level non-local exit for call-only closure parameters, or require library loops to accept a stop signal.
- Status. Accepted.
breakandreturnout of aforover a recursiveyieldsfn already run identically incpl runand the C++. Not yet done: item-steeredprune,Enter/Exitevents, labelled break and loopelsecoverage over generators, and converting the remaining callback-shaped stdlib traversals.