Repository navigation
v0.1.30
0.1.30
-
Wasm Asyncify: awaits inside control flow (
if/if-else/else if,
while,for), plusreturn await ...andx = await .... The generator
lowers such async functions into a CFG of basic blocks and emits a
program-counter state machine — aloop+br_tabledispatch over a$pc
local, with$pcspilled/restored on the Asyncify frame stack alongside the
locals. Awaits become block boundaries; leaf (host) and internal (module-
async) awaits both work inside loops/branches, composing with multi-frame
unwinding. Functions whose awaits are all top-level keep the linear path.
Awaits nested inside expressions (t = t + await f(),return await f() + 1,
await f() + await g()) are hoisted into temp locals automatically. Remaining
unsupported shapes (for-each, awaits in loop/branch conditions) fall back to
synchronous-collapse. Tested end-to-end throughApolloRunnerWasm. -
async/awaitsupport (real asynchrony) — Dart parse/run/translate and
JavaScript translation:- AST: new
ASTModifiers.isAsync, newASTExpressionAwaitexpression, and a
new abstractgenerateASTExpressionAwaitgenerator hook. Reuses the
existingASTTypeFuture/ASTValueFuture(addedASTTypeFuture.futureValueType). - Runtime: an
asyncfunction returns a first-class future immediately
(a non-awaited call yields anASTValueFuturethat can be stored and
awaited later);awaitsuspends on real DartFutures, including those
returned by external functions declared with aFuture<...>return type.
ASTEntryPointBlock.executeawaits the entry future before tearing down the
entry-point context (external mapper, current context). - Dart grammar: parses the
asyncbody keyword (after the parameter list) and
theawaitprefix expression;Future<T>types parse toASTTypeFuture;
theawait/asynccontextual keywords no longer shadow identifiers
(e.g.awaiter) or get read as a type name. - Code generation: Dart emits
... ) async {andawait; JavaScript emits
async function/async name(andawait. - Wasm: async/await compiles via synchronous collapse — the backend runs
synchronously, soFuture<T>collapses toT(effectiveReturnType) and
awaitis a value pass-through. Compute-style async Dart compiles to Wasm
and matches the AST interpreter. - Wasm real-suspension Asyncify prototype
(test/apollovm_wasm_asyncify_prototype_test.dart): a hand-assembled
two-frame module proves real suspension against the liveWasmRuntime— a
running call unwinds to the host (saving live locals to linear memory), the
host awaits a real DartFuture, then re-invokes the export which rewinds
and resumes. Demonstrates multi-frame state preservation, exactly-once
prologue execution, and two concurrent computations interleaving by host
delay. - Wasm Asyncify code generation: the generator emits the unwind/rewind
state machine for anasyncfunction whoseawaits are statement-level
calls — a low-memory Asyncify control region (WasmModuleContext) with a
LIFO frame stack, live-local spill/restore,br_tableresume dispatch
supporting multipleawaitpoints in one function, and multi-frame
unwinding: anasyncfunction mayawaitanother moduleasyncfunction
(an internal frame) as well as a host import (a leaf). The unwind
propagates up every frame on the call stack to the host and rewinds back
down (an eligibility fixed-point decides which async functions transform;
the rest use synchronous-collapse). Validated against the live runtime in
test/apollovm_wasm_asyncify_codegen_test.dartand the multi-frame /
mixed-await cases intest/apollovm_wasm_asyncify_runner_test.dart. Shapes
that still fall back to synchronous-collapse: awaits nested in control flow,
multiple awaits in one statement, and async recursion. - Wasm Asyncify runner integration:
ApolloRunnerWasm.executeFunction
now detects real-suspensionasyncfunctions (flagged inapollovm_sig)
and drives their unwind/rewind loop, awaiting a real DartFuturefrom a
host function registered via the newApolloRunnerWasm.mapWasmAsyncFunction
API. So real-suspension async/await works end-to-end through the VM
(test/apollovm_wasm_asyncify_runner_test.dart). Abr_table
multi-await/multi-frame transform is the remaining follow-up. - Kotlin async/await translation: an
asyncfunction maps to asuspend fun
(the declaredFuture<T>collapses toT), andawait ebecomes juste
(suspension is implicit when calling asuspendfunction in coroutines). - Tests:
test/apollovm_async_test.dart(parse, real-suspension ordering,
await chains, top-level async, identifier guard, Dart/JS/Kotlin translation)
andtest/apollovm_wasm_async_test.dart(AST-vs-compiled-Wasm parity).
- AST: new