Memory issues with WASM backend
Summary
I'm trying to run Fourmolu built with the new WASM backend in GHC, where I malloc an input string in JS, send the pointer to Haskell, malloc the output string in Haskell, send the pointer back to JS, and free everything. It works as expected initially, then I run into two problems:
- At start up, sending a really large input will show
Data.Binary.Get.runGet at position 32: not enough bytes
. - When sending multiple small inputs, I eventually get
RuntimeError: memory access out of bounds
. I see this happening in thehs.free()
JS call, thehs.malloc()
JS call, or themalloc
Haskell call
Printing out the pointers shows that the input pointer uses the same memory address every time, and the result pointer isn't continually increasing, so it doesn't seem like a memory leak. Regardless, the pointers + length are well below the size of hs.memory.buffer
.
- How do I go about debugging this? I've never worked this low-level before, and I'm not really sure how to start
- I've attached the relevant files below; am I doing anything obviously wrong?
Steps to reproduce
See repo above, follow quickstart.
Expected behavior
Environment
- GHC version used:
Optional:
- Operating System:
- System Architecture: