Repository navigation
for await runs its body one iteration at a time (#498) - #503
Merged
Merged
Conversation
The body of a `for await` loop ran as concurrent tasks: mlirGen (ForStatement) wrapped each iteration's body in an async.execute, added its token to an async.group made before the loop, and waited for the whole group once, with async.await_all, after the loop. The bodies ran together on the async runtime's threads: iterations interleaved (`<7<8><9>`), and writes were lost (`keep.push` from one iteration, `log += ...` from another), under gc, rc and none; one run printed nothing at all. Each iteration now awaits its body's token before going on, as `await` does since #440, so the next value is asked for only once the body is done, as in TypeScript. The group and the await_all are gone. The body stays an async.execute: an `await` in it needs one. 00for_await_sequential.ts checks the bodies' writes and awaits run in order over eight iterations; on main it failed in every variant, three runs out of three. Closes #498 Co-Authored-By: Claude Opus 5.5 <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.
The body of a
for awaitloop ran as concurrent tasks.mlirGen(ForStatement)wrapped each iteration's body in anasync.executeand added its token to anasync.groupcreated before the loop. It then waited for the whole group only once, withasync.await_allafter the loop. So the bodies ran together on the async runtime's threads:<7<8><9>);keep.push,log += ...), under gc, rc and none;Each iteration now awaits its body's token before going on, as
awaitdoes since #440. The next value is requested only once the body is done, as in TypeScript. The group and theawait_allare gone. The body stays anasync.execute, because anawaitinside it needs one.New test
00for_await_sequential.tschecks, over eight iterations, that the bodies' writes happen in order, every push is kept, and awaits inside the body run in order. Onmainit failed in all 6 ctest variants, three runs out of three. With the fix it passes every time, and under own too.tests.ps1 -Model, release + debug, compile + JITweakref_basicskipped (gc only); all "All tests passed"Not part of this change:
break/continuein afor awaitbody, and a nestedfor await, crash the compiler onmainas well. Filed as #502.Closes #498
🤖 Generated with Claude Code