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

Question about “locals exceed maximum” #2465

Open
SDGGiesbrecht opened this issue Jan 9, 2021 · 6 comments
Open

Question about “locals exceed maximum” #2465

SDGGiesbrecht opened this issue Jan 9, 2021 · 6 comments
Assignees
Labels
bug Something isn't working

Comments

@SDGGiesbrecht
Copy link

carton test fails with the following:

error: failed to run `[...]/.build/wasm32-unknown-wasi/debug/[Package]Tests.wasm`
│   1: module instantiation failed (engine: jit, compiler: cranelift)
╰─> 2: Validation error: locals exceed maximum (at offset 1442120)

I don’t understand what that means or how to go about finding the underlying problem.

@MaxDesiatov
Copy link

Thanks! This is one of the errors we've been chasing for some time, but couldn't find an isolated reproducible test case. Do you have one to share here by any chance? Either an isolated file compilable with swiftc or a SwiftPM project would be much appreciated!

@SDGGiesbrecht
Copy link
Author

Yes, I managed to narrow the problem down to a particular long dictionary literal. Let me clean‐up some of the mess left over from my experiments, and then I’ll post a link.

@MaxDesiatov
Copy link

I don't think it's related to carton directly, so I'm moving it to the toolchain repo in the meantime...

@MaxDesiatov MaxDesiatov transferred this issue from swiftwasm/carton Jan 9, 2021
@MaxDesiatov MaxDesiatov added the bug Something isn't working label Jan 9, 2021
@SDGGiesbrecht
Copy link
Author

This was the offending literal.

git clone https://github.com/SDGGiesbrecht/SDGWeb
cd SDGWeb
git checkout 8bd5066bebc69e8d686a879628363689108d8048

With the empty literal variant applied when compiling for the web platform, everything works. But if you comment out the #if to enable the 2125‐entry literal variant used by the other platforms, then this error occurs.

Note that the error doesn’t surface until you actually attempt to launch the tests (carton test). The compilation phase on its own throws no errors (swift build --triple wasm32-unknown-wasi), even though that is almost certainly where the real problem is.

@SDGGiesbrecht
Copy link
Author

But I still don’t know what the error message means; I only know how to dodge it.

@MaxDesiatov
Copy link

MaxDesiatov commented Jan 9, 2021

WebAssembly hosts have certain limits placed on modules they load, and binaries not satisfying these limits don't pass validation, which hosts are required to do before actual execution. The Swift toolchain and LLVM unfortunately don't run validation during the build, so this error doesn't surface until you actually load the binary in the host (i.e. the browser). This isn't an error in your code, this is a bug in how LLVM or swiftc generate Wasm binary for such literals.

Thanks for isolating this, we'll try to create a test case for it and submit a patch upstream.

CC @kateinoigakukun

@kateinoigakukun kateinoigakukun self-assigned this Jan 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants