await of a void async function waits for it (#440) - #497
Merged
Merged
Conversation
`await f()` on an async function that returns nothing never ran `f` before going on, under every memory model, AOT and JIT: the await of the example printed `ran 0`, and `f` did not run at all if the program ended first. mlirGen(AwaitExpression) wraps the awaited expression in an async.execute and checked its result with EXIT_IF_FAILED_OR_NO_VALUE; a call to a void function succeeds with no value, so it left there, before the async.await on the execute's token. It now leaves on a failure only, and a void await awaits its token and gives no value, as it already did with no result slot. Any await of a void call was affected: a function, a method, an arrow function, in a loop or in sequence. 00await_void.ts runs them in order under every model. Closes #440 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.
await f()on an async function that returns nothing never ranfbefore going on, under every memory model, AOT and JIT. The issue's example printedran 0, and if the program ended first,fnever ran at all.mlirGen(AwaitExpression)wraps the awaited expression in anasync.executeand checked the result withEXIT_IF_FAILED_OR_NO_VALUE. A call to a void function succeeds with no value, so the function returned there, before theasync.awaiton the execute's token. The task was never awaited. It now returns early only on a failure (EXIT_IF_FAILED), so a void await waits for its token and gives no value.New test
00await_void.ts: void awaits of a function, a nested async function, a loop, a method and an arrow function, which must run in order (abc012mg). Onmainit fails in all 6 ctest variants (compile/JIT, default, rc and none corpus). With the fix it passes in all 6, and under own too.weakref_basicis gc-only, as onmain)The issue's "Also seen" notes are not part of this change:
for awaitbodies run as concurrent tasks, and a failingassertcan hang the JIT after a dropped task.Closes #440
🤖 Generated with Claude Code