You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
await of a void async function never runs it: the async.execute token is not awaited #440
await f() on an async function that returns nothing never runs f, under every memory model, AOT and JIT. The awaiting function continues straight past the await, and if the program ends first, f never runs at all.
letran=0;asyncfunctionf(){ran=1;}asyncfunctionmain(){awaitf();assert(ran==1,"f did not run");// fails under gc, rc, none, ownprint("done.");}
With a value it works: async function f() { return 1; } and const v = await f(); run f and give 1.
Cause
MLIRGenImpl::mlirGen(AwaitExpression) (lib/TypeScript/MLIRGenExpressions.cpp) wraps the awaited expression in an async.execute, then checks the result with
EXIT_IF_FAILED_OR_NO_VALUE(result)
A call to a void function succeeds with no value, so the function returns there, before
The token is dropped, and nothing waits for the task. The MLIR for the example has the async.execute with the call, and no async.await after it.
Fix
Exit on failure only, EXIT_IF_FAILED(result), so a void await still awaits its token. The function already returns mlir::success() with no value when there is no result slot. Any await of a void call is affected, including await sleep(100).
Also seen
A failing assert hangs under the JIT after such a dropped task (gc and none): the run never exits. Two of these runs were left as tslang.exe processes that taskkill /F reports as "no running instance".
for await bodies run as concurrent tasks. Each body is its own async.execute, added to a group and awaited with async.await_all after the loop, so iterations are not sequential. In one run of
the output was body 7, body 8, after loop 1: one push was lost. A version with three yields and an assert passed in all six model/mode runs, so it is intermittent. In TypeScript, the body of a for await runs one iteration at a time, in order.
Activity
-mm=own phase 7b: a generator over a parameter's block borrows it; .m…
for await runs its body one iteration at a time (#498) (#503)