Skip to content

v0.1.30

Choose a tag to compare

@gmpassos gmpassos released this 25 Jun 06:25
· 371 commits to master since this release
8f20f9e

0.1.30

  • Wasm Asyncify: awaits inside control flow (if/if-else/else if,
    while, for), plus return await ... and x = await .... The generator
    lowers such async functions into a CFG of basic blocks and emits a
    program-counter state machine — a loop + br_table dispatch over a $pc
    local, with $pc spilled/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 through ApolloRunnerWasm.

  • async/await support (real asynchrony) — Dart parse/run/translate and
    JavaScript translation:

    • AST: new ASTModifiers.isAsync, new ASTExpressionAwait expression, and a
      new abstract generateASTExpressionAwait generator hook. Reuses the
      existing ASTTypeFuture/ASTValueFuture (added ASTTypeFuture.futureValueType).
    • Runtime: an async function returns a first-class future immediately
      (a non-awaited call yields an ASTValueFuture that can be stored and
      awaited later); await suspends on real Dart Futures, including those
      returned by external functions declared with a Future<...> return type.
      ASTEntryPointBlock.execute awaits the entry future before tearing down the
      entry-point context (external mapper, current context).
    • Dart grammar: parses the async body keyword (after the parameter list) and
      the await prefix expression; Future<T> types parse to ASTTypeFuture;
      the await/async contextual keywords no longer shadow identifiers
      (e.g. awaiter) or get read as a type name.
    • Code generation: Dart emits ... ) async { and await ; JavaScript emits
      async function / async name( and await .
    • Wasm: async/await compiles via synchronous collapse — the backend runs
      synchronously, so Future<T> collapses to T (effectiveReturnType) and
      await is 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 live WasmRuntime — a
      running call unwinds to the host (saving live locals to linear memory), the
      host awaits a real Dart Future, 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 an async function whose awaits are statement-level
      calls — a low-memory Asyncify control region (WasmModuleContext) with a
      LIFO frame stack, live-local spill/restore, br_table resume dispatch
      supporting multiple await points in one function, and multi-frame
      unwinding
      : an async function may await another module async function
      (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.dart and the multi-frame /
      mixed-await cases in test/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-suspension async functions (flagged in apollovm_sig)
      and drives their unwind/rewind loop, awaiting a real Dart Future from a
      host function registered via the new ApolloRunnerWasm.mapWasmAsyncFunction
      API. So real-suspension async/await works end-to-end through the VM
      (test/apollovm_wasm_asyncify_runner_test.dart). A br_table
      multi-await/multi-frame transform is the remaining follow-up.
    • Kotlin async/await translation: an async function maps to a suspend fun
      (the declared Future<T> collapses to T), and await e becomes just e
      (suspension is implicit when calling a suspend function in coroutines).
    • Tests: test/apollovm_async_test.dart (parse, real-suspension ordering,
      await chains, top-level async, identifier guard, Dart/JS/Kotlin translation)
      and test/apollovm_wasm_async_test.dart (AST-vs-compiled-Wasm parity).