Skip to content

Lower async functions to backend-neutral resumable state machines #443

Open

Description

@LunaStev

Parent: #439
Depends on: #440 and #442.

Summary

Lower typed async functions into a backend-neutral resumable state-machine representation before LLVM emission.

Required contract

  • Split control flow at await sites and assign deterministic suspension states.
  • Move locals that survive suspension into an explicit frame with target-correct size and alignment.
  • Preserve return, loop, match, branch, and early-completion behavior across suspension.
  • Represent ready, pending, failure, and cancellation according to the agreed semantic contract.
  • Keep raw pointer values unchanged while documenting that pointee validity remains the program's responsibility.
  • Support nested awaits, multiple awaits, generic specializations, and async calls returning variants or structs.
  • Do not use LLVM coroutine intrinsics as the public or frontend contract; LLVM-specific optimization may be added behind the lowered representation.

Completion criteria

  • A backend-neutral async frame/state-machine IR is documented in code and consumed by LLVM.
  • Generated LLVM verifies for x86_64, AArch64, and RV64 layouts.
  • Locals live across exactly the required suspension states.
  • Completed frames cannot resume again, and cancelled frames follow the defined cleanup contract.
  • Regression tests cover branches, loops, match, nested calls, generics, and pointer-bearing frames.
  • No valid async program reaches an unimplemented-node panic in LLVM.

This is a high-difficulty compiler task.

Implementation audit — 2026-09-23

AsyncFrame/AsyncState/Transition are implemented before LLVM lowering, and async_frames_emit_for_enabled_native_targets passes. Runtime control-flow fixtures also pass locally. Retain this issue for exact suspension liveness and the remaining frame/cancellation acceptance audit; existing code currently creates explicit frame slots broadly.

Activity

  1. added
    enhancement
    help wanted
    needs testing
    on Aug 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementhelp wantedneeds testing

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions