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

Investigate wasm3 stack overflow during function compilation #3708

Closed
ayazhafiz opened this issue Aug 5, 2022 · 7 comments · Fixed by #3735
Closed

Investigate wasm3 stack overflow during function compilation #3708

ayazhafiz opened this issue Aug 5, 2022 · 7 comments · Fixed by #3735
Labels
testing Relates to `roc test` wasm Specific to WASM

Comments

@ayazhafiz
Copy link
Member

This test currently hits a stack memory limit while compiling a function inside wasm3:

https://github.com/rtfeldman/roc/blob/d4e81ccbd2f2c94725eb21af58cb948b33247898/crates/compiler/test_gen/src/gen_abilities.rs#L920-L940

I think the only way to resolve this, as far as I found, is to compile wasm3 from source ourselves. See wasm3/wasm3-rs#22

@ayazhafiz ayazhafiz added wasm Specific to WASM testing Relates to `roc test` labels Aug 5, 2022
@brian-carroll
Copy link
Contributor

brian-carroll commented Aug 6, 2022

This test currently hits a stack memory limit while compiling a function inside wasm3:

I'm not 100% sure this is the right interpretation of the error message you got!

wasm3's error messages are sometimes a bit misleading. I got a very similar error message while working on the dev backend. The real issue was that I hadn't pushed enough values onto the Wasm stack machine but it was reported as an underflow in the "compiling function stack". To me that sounds like an issue inside wasm3 but in fact it was in the app.
So before we go building wasm3 from source I think it's worth doing a bit more investigation to confirm what the problem is.

@brian-carroll
Copy link
Contributor

Also I'm confused about the code comment saying it fails on gen-wasm. I thought you had mentioned before that it was working there. Did that change?

@brian-carroll
Copy link
Contributor

This test passed for me just now on trunk for both gen-wasm and gen-llvm-wasm. I'm on an M1 Mac, which shouldn't matter but maybe does? I can try on x86 WSL Ubuntu tomorrow.

@folkertdev
Copy link
Contributor

the test also passes for me with gen-llvm-wasm on x86-64 linux mint (effectively ubuntu)

@brian-carroll
Copy link
Contributor

Cool. Also works for me on x86-64 WSL Ubuntu with both gen-wasm and gen-llvm-wasm.

@ayazhafiz
Copy link
Member Author

ayazhafiz commented Aug 9, 2022

It looks like the error only happens when built in release (cargo test-gen-llvm-wasm --release). In non-release it builds fine. I'm happy to debug this but don't know much about wasm or our infrastructure around it (for dev or llvm); any tips on where to start?

@brian-carroll
Copy link
Contributor

Aha! OK well I thought this issue had gone away but apparently not!

I can look into it, so you don't need to worry about it unless you're interested in learning about it!

My approaches to investigate things like this are

  • Load up the test .wasm file in Chrome and see if it gives any errors. We have a webpage for this at crates/compiler/test_gen/src/helpers/debug-wasm-test.html with instructions in the HTML itself. You need to serve that page from localhost.
  • Try it out with a different CLI runtime like Wasmer and see if that gives any errors
  • Run some analysis tools on it like wasm-validate and wasm-objdump

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
testing Relates to `roc test` wasm Specific to WASM
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants