binaryen.js: Valid module fails assertions during `mod.optimize()`

I’m working on a compiler that uses binaryen.js to generate Wasm. A problem I’ve run into, however, is that running mod.optimize() on the generated module (which executes fine without optimization) runs into an assertion error. Running binaryen.readBinary(mod.emitBinary()).optimize() works fine, and it passes mod.validate(), so I’m not sure what the problem is. What could I be doing wrong that causes this?

The specific assertion failure is int(_id) == int(T::SpecificId). I can probably make a reproduction if totally necessary, but it’ll take a bit.

About this issue

  • Original URL
  • State: closed
  • Created 9 months ago
  • Comments: 22 (15 by maintainers)

Most upvoted comments

Seems to happen when I use an expression reference twice, which I’m now thinking might be taboo?

Oh, that’s extremely taboo.

Nope.

# make sure emcc and emcmake are available (maybe you need to source emsdk_env.sh)
git clone https://github.com/AssemblyScript/binaryen.js --recursive
cd binaryen.js
emcmake cmake -GNinja -DCMAKE_BUILD_TYPE=Debug -DCMAKE_EXE_LINKER_FLAGS="-sSTACK_SIZE=5242880" -B binaryen/build binaryen
ninja -C binaryen/build
npm i
npm run bundle
npm link # or use your desired package manager

Then, in your project:

npm link binaryen.js # or your desired package manager
NODE_OPTIONS="--enable-source-maps" npm run yourscript # or you can use `node --enable-source-maps` directly