Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

failed wasm compilaiton because of locals exceed maximum #3451

Closed
funlennysub opened this issue May 24, 2023 · 2 comments
Closed

failed wasm compilaiton because of locals exceed maximum #3451

funlennysub opened this issue May 24, 2023 · 2 comments
Labels

Comments

@funlennysub
Copy link

Describe the Bug

I have a crate that works with game's save file, i parse everything in SaveFile struct that holds a few fields, one of them is forge, this struct has a method that uses a large hashmap that contains "definitions" for specific IDs that save file can have, SCHEMATICS is said hashmap:

image

Calling a function that uses that hashmap causes locals exceed maximum error when trying to build a wasm file.

Steps to Reproduce

  1. Clone this repo (wasm_issue branch)
  2. Uncomment this line
  3. Change this line to forge: Forge::from_gvas(gvas)?,
  4. Run cargo build in main directory
  5. Build editor_ui with trunk build or wasm-bindgen

Expected Behavior

Wasm generating with no errors

Actual Behavior

throws an error:

error: failed getting Wasm module for 'drg-save-editor\target\wasm32-unknown-unknown\debug\editor_ui.wasm'

Caused by:
    0: failed to parse input as wasm
    1: failed to parse code section
    2: locals exceed maximum (at offset 1931704)
2023-05-24T16:54:38.126342Z ERROR ❌ error
error from HTML pipeline

Caused by:
    0: error from asset pipeline
    1: wasm-bindgen call returned a bad status

Additional Context

More info in original issue on trunk repo

@daxpedda
Copy link
Collaborator

This is an issue with wasmparser:
https://github.com/bytecodealliance/wasm-tools/blob/wasmparser-0.78.2/crates/wasmparser/src/operators_validator.rs#L157-L159

There isn't much that can be done about this in wasm-bindgen, as far as I understand it the parser doesn't allow for more then 50000 local variables, which somehow you have hit:
https://github.com/bytecodealliance/wasm-tools/blob/wasmparser-0.78.2/crates/wasmparser/src/limits.rs#L29

You can see how you can figure out which function it is here: bytecodealliance/wasm-tools#665. You then have to split it into multiple functions to avoid hitting that limit.

@funlennysub
Copy link
Author

one much simpler solution i found is it to use opt-level = "s" for debug builds since apparently this problem disappears in release mode

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants