-
Notifications
You must be signed in to change notification settings - Fork 1.5k
WebAssembly exception-handling support. #11326
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
Conversation
|
Logistical note: I'm posting this as a draft now to get early feedback and because I know folks are waiting to see how it is shaping up. I'm on vacation for two weeks starting now (back Mon Aug 11) and will plan to polish then. I'm hoping to actually get host-boundary integration built as well, if I can, in this PR, to enable spec-tests, but if that turns out to be too much then it will come right after. Following that, fuzzing is the only piece that remains, I think. |
88e7b7f to
033989a
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.
I've left some high-level thoughts here and there, but definitely feel free to defer anything to issues as you feel appropriate.
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.
Shaping up nicely!
We had talked elsewhere about removing the exception composite type variant and having tags refer to just their function type (but we would now optionally have a GC struct layout for a function type's parameters for use with exceptions). This would better align us with the Wasm spec and make it so that there are less new additions to the types registry code and also fewer interactions at runtime with its locking and tables and all that. Are you still planning on pursuing this?
Ah, sorry, I hadn't made a note in the PR message here, but: I tried and abandoned that path. (Or more precisely, having exception layouts hang off of the function type;
The current implementation performs no locking or accesses to the type registry at runtime; it uses the dynamic context mechanism in Cranelift to get straight to the instance, then look up tags ( (Still on PTO but will respond occasionally to keep review moving) |
44283d9 to
d592c51
Compare
Subscribe to Label Actioncc @fitzgen
This issue or pull request has been labeled: "cranelift", "cranelift:area:aarch64", "fuzzing"
Thus the following users have been cc'd because of the following labels:
To subscribe or unsubscribe from this label, edit the |
92db516 to
1f9f65a
Compare
|
@alexcrichton @fitzgen I've now done the refactor we discussed and also added support for Wasm-to-host, host-to-Wasm, and host-to-host (via |
This commit does some preparatory refactoring for bytecodealliance#11326 to ensure that a store is available when trap information is being processed. Currently this doesn't leverage the new parameter but it should be leverage-able in bytecodealliance#11326.
05725e5 to
6275df6
Compare
|
I've refactored on top of #11441 and this is indeed much nicer; I've removed the The current challenge is dealing with rooting: the factor has placed the point at which we capture the |
|
Oh good point! I think it'd be reasonable to move this management into the trap-handling bits (or around the |
|
Actually, I think there are deeper issues with rooting, exceptions, and The basic question is: if we return an exception as a GC object boxed in a The most basic example is a host function that allocates an But in the general case, with user host code creating nested This will typecheck fine ( More generally, Should we use a It's somewhat tempting to say "don't do that" to all of this -- it's no different than returning any GC ref type at all. If we take this option, we just fix the exact extent of the root scope when calling out to the host, we root any returned exception when it comes back (concretely: put the One alternative is to have an explicit The last option does differ from what we agreed to in the RFC (but the RFC is underspecified with respect to rooting behavior in general, on the other hand) -- so I'd want some consensus here, at least, before building that. Any thoughts? |
|
Good points!
To some degree this is inherently true of
I like this approach personally. What I might recommend is something like |
Indeed, that was my thought as well. I suppose one could actually also have a signature |
|
Ah, sorry about that! Bad habit trying to keep a clean commit history. Last diff was |
* Add a check to `supports_host` for the generated test and assert failure also when that is false. * Remove `pulley_unsupported` test as it falls out of `#[wasmtime_test]` * Remove `exceptions_store` helper as it falls out of `#[wasmtime_test]` * Remove miri annotations as they fall out of `#[wasmtime_test]`
If the selected compiler doesn't support the host at all then there's no need to run it. Actually running it could misinterpret `CraneliftNative` as "run with pulley" otherwise, so avoid such false negatives.
|
While there may be more than one segfaulting test I can reproduce Given that it's s390x-only though it's probably an endianness issue, perhaps something with a little-endian load needs to be native-endian? Or vice versa? Or maybe a store on the host needs to be little instead of native endian? |
|
Yep, it's almost certainly endianness -- taking a look! |
|
Actually, it's an issue with dynamic context reads during the stack-walk, it seems -- s390x ABI is a bit different (stackchains rather than FP-chains) so I suspect this is the issue. |
|
s390x turned out to expose a mismatch in the definition of "spillslot offset" for the dynamic context -- the accessor I had exposed returns offset from the fixed storage area, which is ordinarily at |
3218039 to
42eb847
Compare
Label Messager: wasmtime:configIt looks like you are changing Wasmtime's configuration options. Make sure to
To modify this label's message, edit the To add new label messages or remove existing label messages, edit the |
…1441) * Require a store in `catch_unwind_and_record_trap` This commit does some preparatory refactoring for bytecodealliance#11326 to ensure that a store is available when trap information is being processed. Currently this doesn't leverage the new parameter but it should be leverage-able in bytecodealliance#11326. * Review comments
* WebAssembly exception-handling support. This PR introduces support for the [Wasm exception-handling proposal], which introduces a conventional try/catch mechanism to WebAssembly. The PR supports modules that use `try_table` to register handlers for a lexical scope; and provides `throw` and `throw_ref` that allocate (in the first case) and throw exception objects. This PR builds on top of the work in bytecodealliance#10510 for Cranelift-level exception support, bytecodealliance#10919 for an unwinder, and bytecodealliance#11230 for exception objects built on top of GC, in addition a bunch of smaller fix and enabling PRs around those. [Wasm exception-handling proposal]: https://github.com/WebAssembly/exception-handling/ prtest:full * Permit UnwindToWasm to have unused fields in Pulley builds (for now). * Resolve miri-caught reborrowing issue. * Ignore exceptions tests in miri for now (Pulley not supported). * Use wasmtime_test on exceptions tests. * Get tests passing on pulley platforms * Add a check to `supports_host` for the generated test and assert failure also when that is false. * Remove `pulley_unsupported` test as it falls out of `#[wasmtime_test]` * Remove `exceptions_store` helper as it falls out of `#[wasmtime_test]` * Remove miri annotations as they fall out of `#[wasmtime_test]` * Remove dead import * Skip some unsupported tests entirely in `#[wasmtime_test]` If the selected compiler doesn't support the host at all then there's no need to run it. Actually running it could misinterpret `CraneliftNative` as "run with pulley" otherwise, so avoid such false negatives. * Cranelift: dynamic contexts: account for outgoing-args area. --------- Co-authored-by: Alex Crichton <[email protected]>
This PR introduces support for the Wasm exception-handling proposal, which introduces a conventional try/catch mechanism to WebAssembly. The PR supports modules that use
try_tableto register handlers for a dynamic scope; and providesthrowandthrow_refthat allocate (in the first case) and throw exception objects.This PR builds on top of the work in #10510 for Cranelift-level exception support, #10919 for an unwinder, and #11230 for exception objects built on top of GC, in addition a bunch of smaller fix and enabling PRs around those.