I have 2 crates,
ffi crates depends on the
interpreter crate exposes an
Interpreter type, which is used by the
Interpreter type, when instantiated, creates a stack which is backed by a
Vec<T> with a capacity of
I need to compile the 2 crates to WASM. Now the compilation itself is successful (the command used is
wasm-pack build --dev --out-dir pkg --target nodejs), but when I try to load the output into the NodeJS repl, it gives an error:
> var x = require('./pkg'); undefined > let i = new x.Interpreter() Thrown: RuntimeError: unreachable at rust_oom (wasm-function:25) at __rg_oom (wasm-function:5) at __rust_alloc_error_handler (wasm-function:5) at alloc::alloc::handle_alloc_error::h67f29d7cba135f71 (wasm-function:5) at <interpreter::eval::memory::Memory as core::default::Default>::default::h87cb4434eda26c4d (wasm-function:233) at interpreter::eval::interpreter::Interpreter::new::h6d6ae62e010770cf (wasm-function:1176) at ffi::Interpreter::new::he342356666d86919 (wasm-function:66) at interpreter_new (wasm-function:15) at new Interpreter (/home/j/dev/accept/ffi/pkg/ffi.js:165:24)
Here's the strangest part:
- This used to work fine (albeit before a refactoring of the
interpretercrate, but even then the Vec-backed stack of capacity 16MB was present)
- When I reduce the size of the stack to < 11 MB, I can instantiate an
Interpreterobject and call its main method
.eval(). However, even then if I call
.eval()on it again, or try to create a 2nd
Interpreterinstance, I still get an OOM error.
Why is this the case? From my perspective I should be able to create a
Vec<T> of capacity
3.2 GB and it should still succeed.
Also, what can I do about this? As-is this code can't go into production, I can't allow spurious OOM errors in there.