-
Notifications
You must be signed in to change notification settings - Fork 414
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
feat: reference types argument #888
Conversation
dbb3a2c
to
2ec80a0
Compare
Hello @Tarnadas 👋🏽 The patch looks great :) You should be able to make |
I tried this out, and found this bug. Not sure if its related to this particular commit, or due to wasm-bindgen. |
This shouldn’t be related to this particular commit. It rather sounds like a memory allocation issue, which might be totally normal. I’m not sure if there is an option for wasm-bindgen to increase the initial memory size, but you could do it manually in the generated JS glue code file and see if that fixes your problem: Also I don’t quite get why this shouldn’t happen without reference types enabled. Btw today I will be fixing the wasm-opt stuff. Thanks for the hint @Urhengulas |
Excuse my ignorance on javascript/wasm. I cant seem to find in the glue code where to memory is allocated -- I can find a buffer with ref-types disabled, as there is a "heap", but I can't see anything of the like here. Strangely, even if I'm just missing that, I preallocated using |
Apparently the JS glue code does not instantiate a WebAssembly memory, which would result in the default values being used. You should see a line in your JS glue code which looks somewhat like this: const wasmModule = new WebAssembly.Module(bytes);
const wasmInstance = new WebAssembly.Instance(wasmModule, imports); Here you can instantiate a WebAssembly Memory with a larger initial size: const wasmModule = new WebAssembly.Module(bytes);
const wasmInstance = new WebAssembly.Instance(wasmModule, {
js: {
mem: new WebAssembly.Memory({ initial: /* large number */, maximum: /* large number */ })
},
...imports
}); |
Unfortunately adding the Should we still accept the PR as is and add a tracking issue until this has been fixed by either wasm-bindgen or wasm-opt? |
The corresponding flag for wasm-bindgen is called |
That sounds definitely like a good idea. I’ll update my PR, but I’m a little worried about the maintenance of this repository |
2ec80a0
to
474af03
Compare
@Tarnadas heya, I'm simply a fellow contributor; that said the changes look good ✌️ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changes look good to me.
Hey, I haven’t looked into this for a very long time. Maybe we no longer need to disable wasm-opt. Has it been updated in the meantime? |
@@ -378,6 +387,9 @@ impl Build { | |||
} | |||
|
|||
fn step_run_wasm_opt(&mut self) -> Result<(), Error> { | |||
if self.reference_types { | |||
return Ok(()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should generate at least a debug message to notify the user that wasm-opt had been disabled.
This PR adds a new argument
--reference-types
, which enables reftype compilation for wasm-bindgen.This feature is hoped to enable more efficient communication between the host (JS) and the wasm module, but not yet all browsers support it.
For more information about reference types, you should read the wasm-bindgen Guide.
This argument will automatically disable
wasm-opt
.Otherwise compilation would crash with the following error: