Skip to content

Add first-class Flow → MLIR → WebAssembly target #528

Closed

Description

@godofecht

Goal

Make WebAssembly a first-class output of the MLIR backend, without routing through generated C/Emscripten.

Target pipeline:

Flow → typed AST → MLIR → LLVM dialect → LLVM IR → wasm32 WebAssembly

Existing foundation

  • flow.transpiler --wasm32 already selects a 32-bit ABI for MLIR generation.
  • flow.transpiler --llvm already lowers MLIR through mlir-opt/mlir-translate to LLVM IR.
  • The missing stage is a supported LLVM IR → .wasm linker/compiler target and browser-oriented export/runtime conventions.

Execution plan

  1. Add an LLVM-IR-to-wasm compiler utility using the LLVM/Clang wasm32 target, with deterministic export/memory/link flags and toolchain discovery.
  2. Add a Flow-file entry point that internally invokes the existing MLIR/LLVM pipeline; no C generation is permitted in this path.
  3. Add tests that assert the pipeline uses --wasm32 --llvm and the wasm32 LLVM target.
  4. Add browser ABI/export support for stable Flow function symbols and linear-memory marshalling.
  5. Define the minimal freestanding browser runtime required by allocation-heavy Flow programs.
  6. Port flow-scikit browser demos from the C/Emscripten artifact to this backend, beginning with allocation-free kernels and then full training pipelines.
  7. Add CI that builds a .flow fixture to .wasm, instantiates it, and checks exported numerical results.

Acceptance criteria

  • A .flow source file can be compiled to .wasm without generating C.
  • The resulting module is valid WebAssembly and exposes requested computational entry points.
  • Browser-compatible numerical kernels execute with parity to native MLIR/JIT results.
  • flow-scikit can build its browser runtime through this target.

Activity

  1. added
    enhancement
    on Aug 17, 2026
  2. godofecht commented on Aug 17, 2026

    @godofecht
    ContributorAuthor

    Reopening: #529 landed the compiler utility foundation, but the issue's acceptance criteria are not yet complete. The active #530 work is still proving a real Flow-exported function can survive Flow → MLIR → LLVM IR → wasm32 and execute under WebAssembly; linear-memory marshalling, allocation-heavy browser runtime support, numerical parity against native MLIR/JIT, and the flow-scikit migration remain outstanding.

  3. godofecht commented on Aug 17, 2026

    @godofecht
    ContributorAuthor

    Scalar named-export execution milestone landed in #530 (3b92bfa). CI now proves a real export function answer() -> i32 compiles Flow → MLIR → LLVM IR → wasm32 and executes under Node's native WebAssembly runtime with answer() == 42. The shared CI toolchain was also corrected from MLIR 14 to MLIR 18, requested wasm exports are validated against generated LLVM IR, and empty LLVM lowering can no longer masquerade as success. Keeping this issue open for linear-memory marshalling, allocation-heavy freestanding runtime support, numerical parity against native MLIR/JIT, and migration of flow-scikit browser demos.

  4. godofecht commented on Aug 17, 2026

    @godofecht
    ContributorAuthor

    Progress update after #529/#530/#532:

    • Direct Flow → MLIR → LLVM IR → wasm32 compilation is implemented; no generated C/Emscripten path is used.
    • CI now instantiates a real exported Flow function under Node and verifies answer() == 42.
    • The shared toolchain is aligned on MLIR 18 and exposes mlir-translate.
    • wasm compilation now rejects empty LLVM IR and requested exports that do not exist.
    • Linear-memory ABI is proven end-to-end: JavaScript writes two Float32 values into exported wasm memory, passes their byte address to ptr<f32>, and exported Flow returns the correct numerical result.

    Remaining acceptance work is now narrower: define the minimal allocation/runtime contract for memref.alloc/allocation-heavy Flow, prove an allocation-backed numerical kernel, then add native-MLIR parity and migrate flow-scikit browser builds to this backend.

  5. godofecht commented on Aug 17, 2026

    @godofecht
    ContributorAuthor

    Allocation/runtime milestone landed in #534 (d1bc667). Dynamic array<f32> now lowers correctly through MLIR after fixing parser-normalized array_T constructor dispatch, the resulting wasm imports exactly env.malloc, and runtime/wasm/flow_runtime.mjs provides that minimal contract with a growing bump allocator. CI executes the allocation-backed Flow function 32 consecutive times under Node and verifies memory growth. Remaining acceptance work: explicit native-MLIR vs wasm numerical parity for the same source, then migrate flow-scikit's published browser bundle off its legacy Emscripten runtime/artifacts.

  6. godofecht commented on Aug 17, 2026

    @godofecht
    ContributorAuthor

    All acceptance criteria are now met.

    The direct backend is CI- and deployment-proven end-to-end:

    Closing this issue as completed. Further browser demos are now ordinary downstream flow-scikit work rather than missing core wasm backend capability.

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

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions