rustwasm / wasm-pack

📦✨ your favorite rust -> wasm workflow tool!
https://rustwasm.github.io/wasm-pack/
Apache License 2.0
6.34k stars 411 forks source link

Fails to parse code section: type mismatch expected i32 found i64 #1010

Open Anderssorby opened 3 years ago

Anderssorby commented 3 years ago

🐛 Bug description

When I run wasm-pack build on my project I get this error: failed to parse input file as wasm. Which I suspect is due to some incorrect handling of pointers. I have narrowed the code section down to parts where I manipulate Arc<Mutex<...>> pointers, which can be summarized like this: Inside a closure exposed to js as a callback and which also moves the repl struct which contains some Mutex and Rc pointers which are used for reading and mutating the state of some objects. The struct is itself borrowed as &mut self.

    let callback = Closure::wrap(Box::new(move |e: OnKeyEvent| {
      repl.handle_event(e);
    }) as Box<dyn FnMut(_)>);
let mutex_defs = self.get_defs();
let mut defs = mutex_defs.lock().unwrap();
...
*defs = ...;

🤔 Expected Behavior

Wasm-pack should parse the wasm file correctly, but this could also be a bug in the rustc compiler.

👟 Steps to reproduce

I don't know the minimal code to reproduce, but I suspect it will happen if you do Mutex manipulations inside a Closure exposed to js.

The error message is as follows:

[INFO]: Installing wasm-bindgen...
 INFO 2021-05-31T13:28:36Z: wasm_pack::command::build: Installing wasm-bindgen-cli was successful.
 INFO 2021-05-31T13:28:36Z: wasm_pack::command::build: Building the wasm bindings...
 INFO 2021-05-31T13:28:36Z: wasm_pack::child: Running "/home/anderscs/.cache/.wasm-pack/wasm-bindgen-faffffc23613dc35/wasm-bindgen" "--version"
 INFO 2021-05-31T13:28:36Z: wasm_pack::child: Running "/home/anderscs/.cache/.wasm-pack/wasm-bindgen-faffffc23613dc35/wasm-bindgen" "--version"
 INFO 2021-05-31T13:28:36Z: wasm_pack::child: Running "/home/anderscs/.cache/.wasm-pack/wasm-bindgen-faffffc23613dc35/wasm-bindgen" "/home/anderscs/src/yatima/target/wasm32-unknown-unknown/release/yatima_web.wasm" "--out-dir" "/home/anderscs/src/yatima/web/pkg" "--typescript" "--target" "bundler"
[2021-05-31T13:28:36Z DEBUG walrus::module::types] parsing type section
[2021-05-31T13:28:36Z DEBUG walrus::module::imports] parse import section
[2021-05-31T13:28:36Z DEBUG walrus::module::functions] parse function section
[2021-05-31T13:28:36Z DEBUG walrus::module::tables] parse table section
[2021-05-31T13:28:36Z DEBUG walrus::module::memories] parse memory section
[2021-05-31T13:28:36Z DEBUG walrus::module::globals] parse global section
[2021-05-31T13:28:36Z DEBUG walrus::module::exports] parse export section
[2021-05-31T13:28:36Z DEBUG walrus::module::elements] parse element section
[2021-05-31T13:28:36Z DEBUG walrus::module::data] parse data section
[2021-05-31T13:28:36Z DEBUG walrus::module] parsing custom section `.debug_info`
[2021-05-31T13:28:36Z DEBUG walrus::module] parsing custom section `.debug_pubtypes`
[2021-05-31T13:28:36Z DEBUG walrus::module] parsing custom section `.debug_ranges`
[2021-05-31T13:28:36Z DEBUG walrus::module] parsing custom section `.debug_aranges`
[2021-05-31T13:28:36Z DEBUG walrus::module] parsing custom section `.debug_abbrev`
[2021-05-31T13:28:36Z DEBUG walrus::module] parsing custom section `__wasm_bindgen_unstable`
[2021-05-31T13:28:36Z DEBUG walrus::module] parsing custom section `.debug_line`
[2021-05-31T13:28:36Z DEBUG walrus::module] parsing custom section `.debug_str`
[2021-05-31T13:28:36Z DEBUG walrus::module] parsing custom section `.debug_pubnames`
[2021-05-31T13:28:36Z DEBUG walrus::module] parse name section
[2021-05-31T13:28:36Z WARN  walrus::module] failed to parse `name` custom section Invalid name type (at offset 4330294)
[2021-05-31T13:28:36Z DEBUG walrus::module::producers] parse producers section
[2021-05-31T13:28:36Z DEBUG walrus::module::functions] parse code section
error: failed to parse input file as wasm

Caused by:
    0: failed to parse code section
    1: type mismatch: expected i32, found i64 (at offset 1023445)
Error: Running the wasm-bindgen CLI
Caused by: failed to execute `wasm-bindgen`: exited with exit code: 1
  full command: "/home/anderscs/.cache/.wasm-pack/wasm-bindgen-faffffc23613dc35/wasm-bindgen" "/home/anderscs/src/yatima/target/wasm32-unknown-unknown/release/yatima_web.wasm" "--out-dir" "/home/anderscs/src/yatima/web/pkg" "--typescript" "--target" "bundler"

🌍 Your environment

Include the relevant details of your environment. wasm-pack version: 0.8.1 and 0.9.1 rustc version: 1.53.0-nightly (9d9c2c92b 2021-04-19)

Anderssorby commented 3 years ago

Update: We tracked the bug further down to a line where u128 and i128 rotate_left or rotate_right where used. If those are removed the error does not appear.