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

Wasm64 support #74

Open
theSherwood opened this issue Apr 19, 2024 · 7 comments
Open

Wasm64 support #74

theSherwood opened this issue Apr 19, 2024 · 7 comments
Labels
enhancement New feature or request

Comments

@theSherwood
Copy link

Hi! Thanks for this great library!

Just a heads up that I've run into an issue around BigInts when using 64-bit wasm. I know this is to be expected but figured I'd flag it all the same just to get it on your radar.

TypeError: Cannot mix BigInt and other types, use explicit conversions
    at Ciovec.read_bytes_array (file:///Users/stuff/node_modules/@bjorn3/browser_wasi_shim/dist/wasi_defs.js:1:4249)
    at fd_write (file:///Users/stuff/node_modules/@bjorn3/browser_wasi_shim/dist/wasi.js:1:8534)
    at wasm://wasm/00091766:wasm-function[206]:0x1ccc0
    at wasm://wasm/00091766:wasm-function[198]:0x1c83c
    at wasm://wasm/00091766:wasm-function[150]:0x14cf4
    at wasm://wasm/00091766:wasm-function[53]:0x878a
    at wasm://wasm/00091766:wasm-function[191]:0x196d9
@bjorn3
Copy link
Owner

bjorn3 commented Apr 19, 2024

AFAIK WASI doesn't have a wasm64 version. How did you compile this wasm module?

@theSherwood
Copy link
Author

Emscripten. I didn't realize WASI didn't support wasm64. Are there any alternative standard interfaces?

@bjorn3
Copy link
Owner

bjorn3 commented Apr 19, 2024

Emscripten originally used a fully custom ABI, but moved to a subset of WASI + extra methods for functionality not part of WASI. Wasm64 support for WASI is probably an Emscripten specific extensions. I'm curious why you are trying to use browser_wasi_shim with an Emscripten compiled wasm module though. Emscripten already emits javascript for handling their entire ABI including all those extra methods and extensions.

@theSherwood
Copy link
Author

I've been using the WASI api (using PURE_WASI compiler flag) because I want to use a larger standard than Emscripten's custom ABI. I don't know how Emscripten supports Wasm64. I just set the MEMORY64 compiler flag. I'm using the browser_wasi_shim at the moment while I figure out what capabilities I want to support. Currently, I'm mostly just using it for printing, as I'm not doing a lot of communication between js and wasm yet.

Emscripten's glue code generation creates a lot of stuff I don't necessarily want. I'm using Nim->C->Wasm. So the resulting Emscripten glue code for passing data to and from JS ends up being pretty mismatched with Nim semantics. At the point that I need to pass data to and from JS, I'm just going to write the JS code myself to match the semantics I want in a perf-conscious way. I've experimented with this a bit and I much prefer it to Emscripten's generated stuff.

So I may be heading in an unusual direction and you don't want to support 64-bit memory because it would entail a bunch of extra code for something that may or may not see much use in the near term. That makes sense. I just wanted to flag this as a limitation.

@bjorn3
Copy link
Owner

bjorn3 commented Apr 19, 2024

I see. I've asked on the wasm discord if there is any documentation about the wasm64 extension to WASI of Emscripten. I'm not sure yet if I want to support wasm64. I think I will have to try implementing it once I know what to actually implement to see how much extra code it needs.

@bjorn3 bjorn3 added the enhancement New feature or request label Apr 19, 2024
@bjorn3
Copy link
Owner

bjorn3 commented Apr 19, 2024

Got a reply. Seems like support for the combination of PURE_WASI and MEMORY64 is purely accidental and the resulting ABI is not documented.

@theSherwood
Copy link
Author

Okay. Good to know. Thanks for your time with all this!

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

No branches or pull requests

2 participants