Skip to content

repeat and Sequence foreach run as loop frames, so their bodies can wait - #530

Merged
stevedekorte merged 1 commit into
masterfrom
repeat-and-seq-foreach-frames
Nov 20, 2026
Merged

stevedekorte merged 1 commit into
masterfrom
repeat-and-seq-foreach-frames

Conversation

@stevedekorte

Copy link
Copy Markdown
Member

Second batch after #528.

  • Number repeat ran its body from a C loop, inside a nested eval loop where a coroutine switch can't happen. It now sets up the for frame state (0 to max − 1). That state now accepts a missing counter name, for repeat without an index.
  • Sequence foreach sets up the foreach frame state, which gains a Sequence branch next to List and Map.
  • List select / selectInPlace are written with repeat, so they can wait as well.

The C loops remain as the fallback when the primitive isn't called straight from the eval loop.

Behaviour and speed

Compared side by side with the previous build: results, break (with and without a value), continue, return, errors, fractional and negative counts, float and UTF-8 sequences, and sequences that grow or shrink during iteration all give the same output.

Timing is unchanged for bodies that do work (3M iterations: 1380 → 1396 ms; Sequence foreach over 2M bytes: 1254 → 1317 ms). n repeat(literal) takes the for state's literal fast path: 30M iterations went from 1564 to 27 ms.

Still not waitable

sortBy family, interpolate, lexicalDo, Date cpuSecondsToRun. Parked in Plan.md until a real use turns up.

Testing

make check 280 pass, make check-component pass, make check-browser-node 32 pass (the wait test now covers 14 constructs), Playwright suite 83 / 83 locally.

🤖 Generated with Claude Code

Number repeat ran its body from a C loop, in a nested eval loop where a
coroutine switch can't happen. It now sets up the for-loop frame state
(0 to max - 1); that state accepts a missing counter name for repeat
without an index. Sequence foreach sets up the foreach frame state,
which gains a Sequence branch next to List and Map.

List select and selectInPlace are written with repeat, so they can wait
too. Results, break/continue/return and errors match the C loops, which
remain as the fallback when not called from the eval loop.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@stevedekorte
stevedekorte merged commit dcdc4cc into master Nov 20, 2026
1 check passed
@stevedekorte
stevedekorte deleted the repeat-and-seq-foreach-frames branch November 20, 2026 06:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant