Skip to content

break and continue in a for await body, and nested for await (#502) - #505

Merged
ASDAlexander77 merged 1 commit into
mainfrom
fix-for-await-break
Oct 5, 2026
Merged

ASDAlexander77 merged 1 commit into
mainfrom
fix-for-await-break

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

break or continue in the body of a for await, and a for await nested in another, crashed the compiler (0xC0000005, no message), under every memory model.

mlirGen(ForStatement) generated a for await body inside an async.execute region of its own, awaited once per iteration since #498. That broke two things:

  • a ts.Break / ts.Continue in the body had no loop inside its region, and lowering crashed on it;
  • a nested loop crashed MLIR generation itself.

The body is now generated directly in the loop, like any other loop body. The region existed only to give an await in the body an async region. But an await creates its own async.execute and waits for it wherever it appears, as in a plain for...of in an async function. So the body still runs one iteration at a time, in order (00for_await_sequential.ts, #498, still passes). The ForAwait flag no longer changes the loop's code.

New test 00for_await_control.ts covers break, continue, a nested for await, and awaits with continue and break in one body. It passes under every model; on main each of these crashed the compiler. A for await at module level runs as well.

Gate Result
Windows full suite (Release) 3852/3852
Linux (WSL) full suite 3837/3837
DefaultLib build + its own tests.ps1 -Model, release + debug, compile + JIT gc 159/159; rc, none 158 passed + weakref_basic skipped (gc only); all "All tests passed"
own corpus no flips, no first-error changes (463/621; the new test passes under own)
existing async / await / generator / yield tests 146/146

Closes #502

🤖 Generated with Claude Code

`break` or `continue` in the body of a `for await`, and a `for await`
nested in another, crashed the compiler (0xC0000005, no message), under
every memory model. mlirGen(ForStatement) generated a `for await` body
inside an async.execute region of its own (awaited per iteration since
#498): a ts.Break / ts.Continue in it had no loop in its region, which
the lowering crashed on, and the nested loop crashed MLIR generation.

The body is now generated in the loop as any other loop's is. The
region was there only so that an `await` in the body had an async
region, and an `await` makes its own async.execute and waits for it
wherever it is (as in a plain for...of in an async function), so the
body still runs one iteration at a time, in order. The ForAwait flag
no longer changes the loop's code.

00for_await_control.ts: break, continue, a nested for await, and
awaits with continue and break in one body, under every model; on main
each crashed the compiler. A for await at module level runs as well.

Closes #502

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ASDAlexander77
ASDAlexander77 merged commit efffdc0 into main Oct 5, 2026
2 checks passed
@ASDAlexander77
ASDAlexander77 deleted the fix-for-await-break branch October 5, 2026 08:45
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.

break / continue in a for await body, and nested for await, crash the compiler

1 participant