Repository navigation
repeat and Sequence foreach run as loop frames, so their bodies can wait - #530
Merged
Merged
Conversation
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>
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.
Second batch after #528.
Number repeatran its body from a C loop, inside a nested eval loop where a coroutine switch can't happen. It now sets up theforframe state (0 to max − 1). That state now accepts a missing counter name, forrepeatwithout an index.foreachsets up theforeachframe state, which gains a Sequence branch next to List and Map.select/selectInPlaceare written withrepeat, 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
sortByfamily,interpolate,lexicalDo,Date cpuSecondsToRun. Parked inPlan.mduntil a real use turns up.Testing
make check280 pass,make check-componentpass,make check-browser-node32 pass (the wait test now covers 14 constructs), Playwright suite 83 / 83 locally.🤖 Generated with Claude Code