Towards a WebAssembly Backend for MicroHs
Summary
This thesis presents the design and implementation of a WasmGC backend for MicroHs, a lightweight Haskell compiler. The backend targets modern WebAssembly runtimes with native garbage collection support. Functional languages require a garbage collector; we can either implement our own or reuse the one provided by the host system. Reusing the host's garbage collector reduces the binary size. To this end, we develop a WasmGC encoding of SK combinators, the theoretical foundation of MicroHs, and implement a reduction machine entirely in WasmGC. The runtime system is realized in two ways: as handwritten WasmGC code and through code generation using a Haskell-based DSL. The code generation automates the encoding of SK reduction rules, whereas the handwritten part of the runtime system forms the rest of it. Together, these components form our native WasmGC runtime. Unfortunately, we were unable to port enough of MicroHs' runtime to be able to run any Haskell programs, although the approach demonstrates potential. Using the MicroHs test suite, median binary sizes were measured as 45.3 KB for WasmGC, 161.2 KB for C, and 203 KB for Wasm 1.0.