Conversation
The corofor trampoline stays what it is — a loop inside one state proc,
driven by `advance` — and keeps `.closure` iterators' arrangement:
- A loop in a `.passive` routine did not compile: `trGoto` took the
iterator call for a suspension point of the enclosing routine and put a
state boundary inside the loop. `corofor` is its own case there now, and
the iterator call is not walked as one. `trCoroFor` also runs the call's
arguments through `coroTr`, so `(haddr x)` names the loop variable's
frame field rather than a local that no longer exists.
- The "did it yield?" test was frame identity (`it.env == myEnv`), which a
passive proc the iterator called satisfies by returning into that same
frame: the body ran again with the previous value (`yield 1; step();
yield 2` printed 1 1 2). `yield` sets `CoroutineBase.yielded` and the
loop tests and clears it (`iterYielded`). Costs 8 bytes per frame — the
tpassivespawn valgrind golden moves 360 -> 432 bytes for its 9 frames.
- A park was treated as the iterator's end: the loop stopped and its
`finally` cancelled a frame the I/O ring still owned. The loop cannot
wait for a park — it and the frame are driven from one stack — so
`iterStopped` says so instead of ending quietly.
A body that would need to suspend (a passive call, a `yield`) is refused
with a message for the same reason; a NESTED for loop is not one of those.
Also: a `{.cast(...)}:` block anywhere in a coroutine crashed hexer —
`trGoto` flattened the pragma block's single body into several statements.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
blackmius
reviewed
Sep 23, 2026
|
|
||
| proc step() {.passive.} = discard | ||
|
|
||
| iterator count(n: int): int {.passive.} = |
Contributor
There was a problem hiding this comment.
if it cannot suspend what is difference between simple iterators and passive iterators?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.