Questions about Haskell and Wasm

Hi,

I’m writing a bug-finding tool called Owi. It already works for C/C++/Go/Rust/Zig/LLVM/Wasm, see the Quickstart if you’re curious about it. I’m currently adding Haskell support, and I have a few questions.

The way the tool work is by performing symbolic execution of Wasm code. Because many languages target Wasm, I can easily compile higher-level languages to Wasm and then symbolically execute the produced code.

I was missing the SIMD proposal in my Wasm engine, I added was what required by Haskell programs compiled to Wasm, and now I can run some code, but there are various issues.

Note that I’m not at all familiar with Haskell.

  1. It seems the only way to compile to Wasm is through ghc-wasm-meta ; which is a bit annoying because it is not yet packaged anywhere. Is there some plan to provide something like ghc --target=wasm32-wasi in the future? Or to package ghc-wasm-meta (having it in nixpkgs would already make things much easier)?

  2. I want to be able to import custom Wasm functions, but the only way I found to do it is by going through a C file, for instance, with this simple_symbol.hs:

module Main where

import Data.Int

foreign import ccall unsafe "symbol_i32"
symbol_i32 :: IO Int32

main :: IO ()
main = do
  x <- symbol_i32
  let d = if x == 42 then 0 else 1
  print (1 div d)

And this symbol.c:

#include <stdint.h>

extern int32_t __attribute__((import_module("owi"), import_name("i32_symbol")))
owi_symbol_i32(void);

int32_t symbol_i32(void) { return owi_symbol_i32(); }

I can compile using:

$ wasm32-wasi-ghc simple_symbol.hs symbol.c -o main.wasm 

But this is a bit annoying too, and I’m wondering if there’s a way to do without the C file or if there are plans to provide an alternative in the future?

  1. If I start executing basic programs (for instance something very simple, without any function imported from Wasm and no possible failure), it seems the Wasm Haskell runtime fails to initialize itself (at least, that’s my guess) and exits with a call to proc_exit (with exit code 1) before executing any of my code. My guess for now is that my dummy implementations of some WASI functions might be the issue, in particular, I have a dummy implementation for:
  • environ_sizes_get
  • args_sizes
  • args_get
  • clock_time_get
  • fd_write

Is the Wasm runtime making any assumptions about what is returned by these functions? Does it actually rely on them to initialize properly? If not, does someone have a clue about what could be the issue?

Thanks a lot for any answer!

What’s wrong with ghc-wasm-meta? It has a flake so it is kinda “packaged” in a way.

@TerrorJack is probably the best person to answer these questions.