-
Notifications
You must be signed in to change notification settings - Fork 4
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
Convert panics to errors #54
base: main
Are you sure you want to change the base?
Conversation
ce788d8
to
6f2da57
Compare
Signed-off-by: George Cosma <[email protected]>
6f2da57
to
fc974dd
Compare
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.
In general, really good! I'm struggling whether I like having "not yet implemented" as an error variant.
Further on, we might need its own trap error enum, that explicitly handles all reasons for a trap of the interpreter.
GlobalIsConst, | ||
RuntimeError(RuntimeError), | ||
NotYetImplemented(&'static str), |
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.
I'm opposing to introduce this, is there any reason to not just use todo!()
?
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.
While sketching out a runner for the wasm specsuite, I ran into the todo!
s for the sections a lot of times. I wanted to have avoid a catch_unwind
call more due to esthetic reasons.
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.
I'm also against introducing this error variant. IMO it's okay to have catch_unwind
in the test runner. Maybe we could even check if the panic message includes "not yet implemented" and display a simple statistic.
@@ -169,7 +179,12 @@ where | |||
let error = self.function(func_idx, &mut stack); | |||
error?; | |||
|
|||
let func_inst = self.store.funcs.get(func_idx).expect("valid FuncIdx"); | |||
// TODO(george-cosma): Do we want this to be a RuntimeError(FunctionNotFound)? |
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.
My vote is yes!
@@ -263,9 +278,9 @@ where | |||
let address = address as usize; | |||
mem.data.get(address..(address + 4)) | |||
}) | |||
.expect("TODO trap here"); | |||
.expect("TODO trap here"); // ??? |
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.
Should this be an out-of-bounds access to linear memory?
One general note on this: I think we should |
@wucke13 Just a quick note.. That's what we have this for: wasm-interpreter/src/execution/assert_validated.rs Lines 5 to 19 in 6f91fc5
|
Is there a reason we are trying to specify why the traps arise? There is no mention of specific trap codes in the spec, all traps are encoded with the trap instruction https://webassembly.github.io/spec/core/exec/runtime.html#administrative-instructions
Maybe we can simply get away without implementing an error for everything that causes a trap and simply have an error for trap. Otherwise there might always be things we miss, or traps that correspond to more than one error. |
or maybe there might be benefit, other wasm interpreters seem to be doing this. Copying the codes off of them and iterating would be the best I guess |
For me, it's not super clear what a trap ought to be in terms of core wasm. My interpretation of the spec is that a trap is something similar to rust's panic, though I don't know for sure. Perhaps it would be correct to say that our compiler can exit due to 3 reasons at runtime:
@cemonem Could you link some examples, I'm curious now 😄. Also @nerodesu017 with the instant |
While we could get away with simply having a general Error that resembles a Trap (see https://github.com/WebAssembly/wabt/blob/2e23b86f2716877f6e24df0c39ac8f0f0e64c770/src/interp/interp.cc#L1238 for example), it helps with code readability, maintainability and testing (especially this part, I love me the intellisense when asserting for traps) Besides we have more granular control (for example seeing if an error was at runtime or not, etc) |
|
Yhea, imo I think we can do it how wasmi is doing it |
Pull Request Overview
This pull request attempts to convert most panics into errors.
Testing Strategy
This pull request was tested by running
cargo test
TODO or Help Wanted
There are some
.expects()
that I'm unsure HOW to turn to errors, or if we should. I'm also a bit afraid that ourError
type is becoming "too precise" or "over-specific" (i.e. An error variant is ever created only once). I'd like some input on this.Formatting
cargo fmt
cargo check
cargo build
cargo doc
nix fmt
treefmt