Skip to content

Add a WebAssembly back end

A WebAssembly back end has been discussed and attempted before (#14976 (closed), closed; https://github.com/tweag/asterius, incompatible with GHC's run-time system; https://webghc.github.io/, dormant), but one has never been truly incorporated into GHC. We propose to do it by adapting GHC's native code generator and GHC's run-time system.

The attempt we know best is Asterius, but Asterius currently relies on GHC's 8.10 branch, and instead of GHC's run-time system, it uses a custom run-time system hand-written in JavaScript.

Things to do, to be refined as progress is made:

  • WebAssembly native code generator

    • Add wrapper for doing dominator analysis on CmmGraph (related to #20726)
    • Add key graph-algorithm logic from FGL (#21259)
    • Add "node splitter" to convert irreducible control-flow graphs
    • Add representaiton of WebAssembly control flow
    • Add translation from CmmGraph to WebAssembly control flow
    • Add representation of WebAssembly straight-line code
    • Add representation of WebAssembly relocatable object/asm files
    • Add codeOutput function to emit WebAssembly from CmmGraph
    • Add post-HSC pipeline to support assembly and linking
    • Add WebAssembly back end to compiler driver
  • WebAssembly runtime independent of JavaScript:

    • Update build system to add a new platform (Wasi/Wasm32) to the existing POSIX and Win32 platforms
    • Build RTS and all boot libs for Wasi/Wasm32 without POSIX dependencies
  • JavaScript interoperation:

    • Refactor RTS schedule function to simplify future updates (#20968)
    • Add support for GHC/RTS inside JavaScript event loop, as per operational semantics
    • Reach agreement with GHCJS on support for JavaScript FFI
Edited by Norman Ramsey
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information