-
Notifications
You must be signed in to change notification settings - Fork 833
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
Add support for exceptions in LLVM #5347
Open
xdoardo
wants to merge
9
commits into
wasmer-5.1.0
Choose a base branch
from
5201-experimental-add-support-for-exceptions
base: wasmer-5.1.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
0507d02
feat(test): Update `wasmparser` and update spec tests
xdoardo af760f5
feat(api+vm+types+artifacts): Add EH-related types `Tag` and `ExnRef`
xdoardo 4011404
feat(types+vm): Implement EH-related vm libcalls (personality functio…
xdoardo 00898f1
feat(llvm): Split target-config related functions
xdoardo dc22742
feat(llvm): Implement exception handling IR generation
xdoardo 77e21da
feat(compiler): Initial support for GOT-based relocations and `compac…
xdoardo 19d21ff
chore: Make linter happy
xdoardo eb3277a
Merge remote-tracking branch 'origin/wasmer-5.1.0' into 5201-experime…
xdoardo e04612e
fix(tests): Update artifacts
xdoardo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
use std::any::Any; | ||
|
||
use crate::entities::store::{AsStoreMut, AsStoreRef}; | ||
use crate::macros::rt::{gen_rt_ty, match_rt}; | ||
use crate::vm::VMExceptionRef; | ||
use crate::StoreRef; | ||
|
||
gen_rt_ty!(ExceptionRef @derives derive_more::From, Debug, Clone ; @path exception); | ||
|
||
impl RuntimeExceptionRef { | ||
/// Make a new extern reference | ||
pub fn new<T>(store: &mut impl AsStoreMut, value: T) -> Self | ||
where | ||
T: Any + Send + Sync + 'static + Sized, | ||
{ | ||
match &store.as_store_mut().inner.store { | ||
#[cfg(feature = "sys")] | ||
crate::RuntimeStore::Sys(s) => Self::Sys( | ||
crate::rt::sys::entities::exception::ExceptionRef::new(store, value), | ||
), | ||
#[cfg(feature = "wamr")] | ||
crate::RuntimeStore::Wamr(s) => Self::Wamr( | ||
crate::rt::wamr::entities::exception::ExceptionRef::new(store, value), | ||
), | ||
#[cfg(feature = "wasmi")] | ||
crate::RuntimeStore::Wasmi(s) => Self::Wasmi( | ||
crate::rt::wasmi::entities::exception::ExceptionRef::new(store, value), | ||
), | ||
#[cfg(feature = "v8")] | ||
crate::RuntimeStore::V8(s) => Self::V8( | ||
crate::rt::v8::entities::exception::ExceptionRef::new(store, value), | ||
), | ||
#[cfg(feature = "js")] | ||
crate::RuntimeStore::Js(s) => Self::Js( | ||
crate::rt::js::entities::exception::ExceptionRef::new(store, value), | ||
), | ||
#[cfg(feature = "jsc")] | ||
crate::RuntimeStore::Jsc(s) => Self::Jsc( | ||
crate::rt::jsc::entities::exception::ExceptionRef::new(store, value), | ||
), | ||
} | ||
} | ||
|
||
/// Try to downcast to the given value. | ||
pub fn downcast<'a, T>(&self, store: &'a impl AsStoreRef) -> Option<&'a T> | ||
where | ||
T: Any + Send + Sync + 'static + Sized, | ||
{ | ||
match_rt!(on self => r { | ||
r.downcast::<T>(store) | ||
}) | ||
} | ||
|
||
/// Create a [`VMExceptionRef`] from [`Self`]. | ||
pub(crate) fn vm_exceptionref(&self) -> VMExceptionRef { | ||
match self { | ||
#[cfg(feature = "sys")] | ||
Self::Sys(r) => VMExceptionRef::Sys(r.vm_exceptionref()), | ||
#[cfg(feature = "wamr")] | ||
Self::Wamr(r) => VMExceptionRef::Wamr(r.vm_exceptionref()), | ||
#[cfg(feature = "wasmi")] | ||
Self::Wasmi(r) => VMExceptionRef::Wasmi(r.vm_exceptionref()), | ||
#[cfg(feature = "v8")] | ||
Self::V8(r) => VMExceptionRef::V8(r.vm_exceptionref()), | ||
#[cfg(feature = "js")] | ||
Self::Js(r) => VMExceptionRef::Js(r.vm_exceptionref()), | ||
#[cfg(feature = "jsc")] | ||
Self::Jsc(r) => VMExceptionRef::Jsc(r.vm_exceptionref()), | ||
} | ||
} | ||
|
||
/// Create an instance of [`Self`] from a [`VMExceptionRef`]. | ||
pub(crate) unsafe fn from_vm_exceptionref( | ||
store: &mut impl AsStoreMut, | ||
vm_externref: VMExceptionRef, | ||
) -> Self { | ||
match &store.as_store_mut().inner.store { | ||
#[cfg(feature = "sys")] | ||
crate::RuntimeStore::Sys(_) => Self::Sys( | ||
crate::rt::sys::entities::exception::ExceptionRef::from_vm_exceptionref( | ||
store, | ||
vm_externref.into_sys(), | ||
), | ||
), | ||
#[cfg(feature = "wamr")] | ||
crate::RuntimeStore::Wamr(_) => Self::Wamr( | ||
crate::rt::wamr::entities::exception::ExceptionRef::from_vm_exceptionref( | ||
store, | ||
vm_externref.into_wamr(), | ||
), | ||
), | ||
#[cfg(feature = "wasmi")] | ||
crate::RuntimeStore::Wasmi(_) => Self::Wasmi( | ||
crate::rt::wasmi::entities::exception::ExceptionRef::from_vm_exceptionref( | ||
store, | ||
vm_externref.into_wasmi(), | ||
), | ||
), | ||
#[cfg(feature = "v8")] | ||
crate::RuntimeStore::V8(_) => Self::V8( | ||
crate::rt::v8::entities::exception::ExceptionRef::from_vm_exceptionref( | ||
store, | ||
vm_externref.into_v8(), | ||
), | ||
), | ||
#[cfg(feature = "js")] | ||
crate::RuntimeStore::Js(_) => Self::Js( | ||
crate::rt::js::entities::exception::ExceptionRef::from_vm_exceptionref( | ||
store, | ||
vm_externref.into_js(), | ||
), | ||
), | ||
#[cfg(feature = "jsc")] | ||
crate::RuntimeStore::Jsc(_) => Self::Jsc( | ||
crate::rt::jsc::entities::exception::ExceptionRef::from_vm_exceptionref( | ||
store, | ||
vm_externref.into_jsc(), | ||
), | ||
), | ||
} | ||
} | ||
|
||
/// Checks whether this `ExceptionRef` can be used with the given context. | ||
/// | ||
/// Primitive (`i32`, `i64`, etc) and null funcref/externref values are not | ||
/// tied to a context and can be freely shared between contexts. | ||
/// | ||
/// Externref and funcref values are tied to a context and can only be used | ||
/// with that context. | ||
pub fn is_from_store(&self, store: &impl AsStoreRef) -> bool { | ||
match_rt!(on self => r { | ||
r.is_from_store(store) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
use std::any::Any; | ||
|
||
use crate::entities::store::{AsStoreMut, AsStoreRef}; | ||
use crate::vm::{VMExceptionRef, VMExternRef}; | ||
use crate::StoreRef; | ||
|
||
pub(crate) mod inner; | ||
pub(crate) use inner::*; | ||
|
||
#[derive(Debug, Clone, derive_more::From)] | ||
/// An opaque reference to some data. This reference can be passed through Wasm. | ||
pub struct ExceptionRef(pub(crate) RuntimeExceptionRef); | ||
|
||
impl ExceptionRef { | ||
/// Make a new extern reference | ||
pub fn new<T>(store: &mut impl AsStoreMut, value: T) -> Self | ||
where | ||
T: Any + Send + Sync + 'static + Sized, | ||
{ | ||
Self(RuntimeExceptionRef::new(store, value)) | ||
} | ||
|
||
/// Try to downcast to the given value. | ||
pub fn downcast<'a, T>(&self, store: &'a impl AsStoreRef) -> Option<&'a T> | ||
where | ||
T: Any + Send + Sync + 'static + Sized, | ||
{ | ||
self.0.downcast(store) | ||
} | ||
|
||
/// Create a [`VMExceptionRef`] from [`Self`]. | ||
pub(crate) fn vm_exceptionref(&self) -> VMExceptionRef { | ||
self.0.vm_exceptionref() | ||
} | ||
|
||
/// Create an instance of [`Self`] from a [`VMExceptionRef`]. | ||
pub(crate) unsafe fn from_vm_exceptionref( | ||
store: &mut impl AsStoreMut, | ||
vm_externref: VMExceptionRef, | ||
) -> Self { | ||
Self(RuntimeExceptionRef::from_vm_exceptionref( | ||
store, | ||
vm_externref, | ||
)) | ||
} | ||
|
||
/// Checks whether this `ExceptionRef` can be used with the given context. | ||
/// | ||
/// Primitive (`i32`, `i64`, etc) and null funcref/externref values are not | ||
/// tied to a context and can be freely shared between contexts. | ||
/// | ||
/// Externref and funcref values are tied to a context and can only be used | ||
/// with that context. | ||
pub fn is_from_store(&self, store: &impl AsStoreRef) -> bool { | ||
self.0.is_from_store(store) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
use crate::{ | ||
macros::rt::{gen_rt_ty, match_rt}, | ||
vm::{VMExtern, VMExternTag}, | ||
AsStoreMut, AsStoreRef, ExportError, Exportable, Extern, Tag, Value, | ||
}; | ||
|
||
/// A WebAssembly `global` instance. | ||
/// | ||
/// A global instance is the runtime representation of a global variable. | ||
/// It consists of an individual value and a flag indicating whether it is mutable. | ||
/// | ||
/// Spec: <https://webassembly.github.io/spec/core/exec/runtime.html#global-instances> | ||
gen_rt_ty!(Exception | ||
@cfg feature = "artifact-size" => derive(loupe::MemoryUsage) | ||
@derives Debug, Clone, PartialEq, Eq, derive_more::From | ||
); | ||
|
||
impl RuntimeException { | ||
/// Create a new exception with the given tag type and payload. | ||
pub fn new(store: &mut impl AsStoreMut, tag: Tag, payload: &[Value]) -> Self { | ||
match &store.as_store_mut().inner.store { | ||
#[cfg(feature = "sys")] | ||
crate::RuntimeStore::Sys(_) => Self::Sys(crate::rt::sys::exception::Exception::new( | ||
store, tag, payload, | ||
)), | ||
#[cfg(feature = "wamr")] | ||
crate::RuntimeStore::Wamr(_) => Self::Wamr(crate::rt::wamr::exception::Exception::new( | ||
store, tag, payload, | ||
)), | ||
#[cfg(feature = "wasmi")] | ||
crate::RuntimeStore::Wasmi(_) => Self::Wasmi( | ||
crate::rt::wasmi::exception::Exception::new(store, tag, payload), | ||
), | ||
#[cfg(feature = "v8")] | ||
crate::RuntimeStore::V8(_) => Self::V8(crate::rt::v8::exception::Exception::new( | ||
store, tag, payload, | ||
)), | ||
#[cfg(feature = "js")] | ||
crate::RuntimeStore::Js(_) => Self::Js(crate::rt::js::exception::Exception::new( | ||
store, tag, payload, | ||
)), | ||
#[cfg(feature = "jsc")] | ||
crate::RuntimeStore::Jsc(_) => Self::Jsc(crate::rt::jsc::exception::Exception::new( | ||
store, tag, payload, | ||
)), | ||
} | ||
} | ||
|
||
/// Checks whether this `Exception` can be used with the given store. | ||
pub fn is_from_store(&self, store: &impl AsStoreRef) -> bool { | ||
todo!() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
pub(crate) mod exnref; | ||
pub use exnref::*; | ||
|
||
pub(crate) mod inner; | ||
pub(crate) use inner::*; | ||
use wasmer_types::{TagType, Type}; | ||
|
||
use crate::{ | ||
vm::{VMExtern, VMExternTag}, | ||
AsStoreMut, AsStoreRef, ExportError, Exportable, Extern, Tag, Value, | ||
}; | ||
|
||
/// A WebAssembly `exception` instance. | ||
/// | ||
/// An exception is an internal construct in WebAssembly that represents a runtime object that can | ||
/// be thrown. A WebAssembly exception consists of an exception tag and its runtime arguments. | ||
/// | ||
/// Spec: <https://github.com/WebAssembly/exception-handling/blob/main/proposals/exception-handling/Exceptions.md#exceptions> | ||
#[derive(Debug, Clone, PartialEq, Eq, derive_more::From)] | ||
#[cfg_attr(feature = "artifact-size", derive(loupe::MemoryUsage))] | ||
pub struct Exception(pub(crate) RuntimeException); | ||
|
||
impl Exception { | ||
/// Create a new exception with the given tag type and payload. | ||
pub fn new(store: &mut impl AsStoreMut, tag: Tag, payload: &[Value]) -> Self { | ||
Self(RuntimeException::new(store, tag, payload)) | ||
} | ||
|
||
/// Checks whether this `Exception` comes from the given store. | ||
pub fn is_from_store(&self, store: &impl AsStoreRef) -> bool { | ||
self.0.is_from_store(store) | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 be opaque (pub only for the crate)