You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Here are a few issues I'm running into when implementing the spec.
During instantiation, what if memory.size is less than the module's declared min size
During instantiation, what if memory.size is greater than the module's declared max size
During instantiation, what if memory.maxSize is greater than the module's declared max size
and related to this:
What if we grow a memory past one of its instances' module's declared maximum.
What if “initial” > “maximum” inside WebAssembly.Memory constructor.
What if a module declares more than 1 memory import
What if a module has no memory import and it declares functions that use loads/stores
Here are a few issues I'm running into when implementing the spec.
The spec interpreter and its test suite answers most details like that. :)
- During instantiation, what if memory.size is less than the module's
declared min size
- During instantiation, what if memory.size is greater than the module's
declared max size
- During instantiation, what if memory.maxSize is greater than the
module's declared max size
On a related note, it seems sketchy to me that spec that is expected to throw JavaScript exceptions calls into some ML code that does the validation (and does some kind of error raising). I think this validation and exception throwing should be explicit in the JavaScript portion of the spec. Specifically, I think the import loop inside Instance creation should do the consistency checks in JS and throw specified JS exceptions.
There are 2 answers, if I'm understanding your question right. First, the JS spec is somewhat separate from the wasm spec proper. The core wasm spec says what conditions should result in validation failure, or runtime trap, etc, but doesn't say how the embedding environment (e.g. JS) should handle those. JS.md says what a JS environment should do, but an embedding of wasm into a non-JS environment should still be able to implement the core spec.
Also spec interpreter is intended to express e.g. the conditions that cause validation failures or traps, but nobody has to call into that particular ML code. Browsers or other wasm engines just implement the same behavior (and additionally implement the JS exceptions as specified in the JS.md text). Eventually (soon, we hope) we will also have a text version of the core wasm spec which will have the same level of detail as the spec interpreter.
@dschuff Ok, thanks for clarifying. This is how I've been approaching the JS/interpreter separation. However, I guess I'm somewhat annoyed many validation errors inside the interpreter have no corresponding exception in the JS API. I think the JS API should be fully specified in which exceptions it throws. Right now, this isn't even close to how the spec is written.
@saambarati, what @dschuff is saying is that there is a factorisation. The core spec defines validation (and other semantics), while JS.md only defines the behaviour specific to the JS embedding. It wouldn't be good to duplicate parts of the specification.
Wrt validation errors, in a JS embedding they all manifest as a CompileError exception during compilation, see the description of the WebAssembly.Module constructor in JS.md.
@rossberg-chromium I'm specifically talking about Instance construction, not Module construction. I believe there needs to be some text saying what happens for validation errors inside Instance construction inside JS.md.
@saambarati, there are no validation errors during instance construction. You only get RuntimeErrors at that point. Those are likewise part of the core semantics.
@rossberg-chromium I think we're talking past each other at this point. Let me be very specific in my question: I'm a JS embedding, when I find a contradiction during Instance creation for when an imported Memory doesn't meet the requirements of the declared import, which JavaScript exception do I throw?
If the answer to this question is look at the ML interpreter, we at the very least need the text to correspond various ML errors with actual JS errors.
@saambarati, I see. I agree that this isn't really specified in JS.md but should be.
@lukewagner, WDYT? Some initialisation failures (e.g. from data sections) are stated to cause a RangeError. Import type mismatches could throw a TypeError. Both seems a bit ad-hoc. Is that okay or should we perhaps introduce a dedicated LinkError exception, to mirror CompileError and RuntimeError, and distinguish from JS level errors?
I think V8 currently raises RuntimeError in the missing cases, but that may not be ideal, since that is intended for traps (but may arise from executing the start function).
We also currently throw both TypeError and RangeError during instantiation. Converting all these to WebAssembly.LinkErrors sgtm. This might also be useful to distinguish instantiation errors from errors thrown by the call to the start function at the end.
Activity
rossberg commentedon Dec 8, 2016
rossberg commentedon Dec 8, 2016
Adding missing tests in WebAssembly/spec#395.
rossberg commentedon Dec 8, 2016
PR #890 should address the omission specific to JS.md.
saambarati commentedon Dec 8, 2016
@rossberg-chromium
Thanks for sharing https://github.com/WebAssembly/spec/blob/master/interpreter/spec/eval.ml#L380, it addresses my concerns.
On a related note, it seems sketchy to me that spec that is expected to throw JavaScript exceptions calls into some ML code that does the validation (and does some kind of error raising). I think this validation and exception throwing should be explicit in the JavaScript portion of the spec. Specifically, I think the import loop inside Instance creation should do the consistency checks in JS and throw specified JS exceptions.
dschuff commentedon Dec 8, 2016
There are 2 answers, if I'm understanding your question right. First, the JS spec is somewhat separate from the wasm spec proper. The core wasm spec says what conditions should result in validation failure, or runtime trap, etc, but doesn't say how the embedding environment (e.g. JS) should handle those. JS.md says what a JS environment should do, but an embedding of wasm into a non-JS environment should still be able to implement the core spec.
Also spec interpreter is intended to express e.g. the conditions that cause validation failures or traps, but nobody has to call into that particular ML code. Browsers or other wasm engines just implement the same behavior (and additionally implement the JS exceptions as specified in the JS.md text). Eventually (soon, we hope) we will also have a text version of the core wasm spec which will have the same level of detail as the spec interpreter.
saambarati commentedon Dec 8, 2016
@dschuff Ok, thanks for clarifying. This is how I've been approaching the JS/interpreter separation. However, I guess I'm somewhat annoyed many validation errors inside the interpreter have no corresponding exception in the JS API. I think the JS API should be fully specified in which exceptions it throws. Right now, this isn't even close to how the spec is written.
rossberg commentedon Dec 9, 2016
@saambarati, what @dschuff is saying is that there is a factorisation. The core spec defines validation (and other semantics), while JS.md only defines the behaviour specific to the JS embedding. It wouldn't be good to duplicate parts of the specification.
Wrt validation errors, in a JS embedding they all manifest as a
CompileErrorexception during compilation, see the description of theWebAssembly.Moduleconstructor in JS.md.saambarati commentedon Dec 9, 2016
@rossberg-chromium I'm specifically talking about Instance construction, not Module construction. I believe there needs to be some text saying what happens for validation errors inside Instance construction inside JS.md.
rossberg commentedon Dec 9, 2016
@saambarati, there are no validation errors during instance construction. You only get RuntimeErrors at that point. Those are likewise part of the core semantics.
saambarati commentedon Dec 9, 2016
@rossberg-chromium I think we're talking past each other at this point. Let me be very specific in my question: I'm a JS embedding, when I find a contradiction during Instance creation for when an imported Memory doesn't meet the requirements of the declared import, which JavaScript exception do I throw?
If the answer to this question is look at the ML interpreter, we at the very least need the text to correspond various ML errors with actual JS errors.
rossberg commentedon Dec 9, 2016
@saambarati, I see. I agree that this isn't really specified in JS.md but should be.
@lukewagner, WDYT? Some initialisation failures (e.g. from data sections) are stated to cause a
RangeError. Import type mismatches could throw aTypeError. Both seems a bit ad-hoc. Is that okay or should we perhaps introduce a dedicatedLinkErrorexception, to mirrorCompileErrorandRuntimeError, and distinguish from JS level errors?I think V8 currently raises
RuntimeErrorin the missing cases, but that may not be ideal, since that is intended for traps (but may arise from executing the start function).saambarati commentedon Dec 9, 2016
My vote is for something like a WebAssembly.LinkError
lukewagner commentedon Dec 9, 2016
We also currently throw both
TypeErrorandRangeErrorduring instantiation. Converting all these toWebAssembly.LinkErrors sgtm. This might also be useful to distinguish instantiation errors from errors thrown by the call to the start function at the end.rossberg commentedon Dec 12, 2016
Okay, cool. See #901 for a PR.
jfbastien commentedon Dec 15, 2016
Is this resolved now that we have WebAssembly.LinkError?
rossberg commentedon Dec 16, 2016
I would think so. @saambarati, anything missing?
saambarati commentedon Jan 3, 2017
LGTM. I'm closing