Skip to content
2 changes: 2 additions & 0 deletions crates/c-api/src/val.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ impl wasm_val_t {
},
Val::AnyRef(_) => crate::abort("creating a wasm_val_t from an anyref"),
Val::ExternRef(_) => crate::abort("creating a wasm_val_t from an externref"),
Val::ExnRef(_) => crate::abort("creating a wasm_val_t from an exnref"),
Val::V128(_) => crate::abort("creating a wasm_val_t from a v128"),
}
}
Expand Down Expand Up @@ -251,6 +252,7 @@ impl wasmtime_val_t {
funcref: func.into(),
},
},
Val::ExnRef(_) => crate::abort("exnrefs not yet supported in C API"),
Val::V128(val) => wasmtime_val_t {
kind: crate::WASMTIME_V128,
of: wasmtime_val_union {
Expand Down
13 changes: 9 additions & 4 deletions crates/cranelift/src/func_environ.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1514,6 +1514,9 @@ impl<'a, 'func, 'module_env> Call<'a, 'func, 'module_env> {
| WasmHeapType::ConcreteArray(_)
| WasmHeapType::Struct
| WasmHeapType::ConcreteStruct(_)
| WasmHeapType::Exn
| WasmHeapType::ConcreteExn(_)
| WasmHeapType::NoExn
| WasmHeapType::None => {
unreachable!()
}
Expand Down Expand Up @@ -1741,7 +1744,7 @@ impl<'module_environment> TargetEnvironment for FuncEnvironment<'module_environm
fn reference_type(&self, wasm_ty: WasmHeapType) -> (ir::Type, bool) {
let ty = crate::reference_type(wasm_ty, self.pointer_type());
let needs_stack_map = match wasm_ty.top() {
WasmHeapTopType::Extern | WasmHeapTopType::Any => true,
WasmHeapTopType::Extern | WasmHeapTopType::Any | WasmHeapTopType::Exn => true,
WasmHeapTopType::Func => false,
WasmHeapTopType::Cont => todo!(), // FIXME: #10248 stack switching support.
};
Expand Down Expand Up @@ -1838,7 +1841,7 @@ impl FuncEnvironment<'_> {
let heap_ty = table.ref_type.heap_type;
match heap_ty.top() {
// GC-managed types.
WasmHeapTopType::Any | WasmHeapTopType::Extern => {
WasmHeapTopType::Any | WasmHeapTopType::Extern | WasmHeapTopType::Exn => {
let (src, flags) = table_data.prepare_table_addr(self, builder, index);
gc::gc_compiler(self)?.translate_read_gc_reference(
self,
Expand Down Expand Up @@ -1872,7 +1875,7 @@ impl FuncEnvironment<'_> {
let heap_ty = table.ref_type.heap_type;
match heap_ty.top() {
// GC-managed types.
WasmHeapTopType::Any | WasmHeapTopType::Extern => {
WasmHeapTopType::Any | WasmHeapTopType::Extern | WasmHeapTopType::Exn => {
let (dst, flags) = table_data.prepare_table_addr(self, builder, index);
gc::gc_compiler(self)?.translate_write_gc_reference(
self,
Expand Down Expand Up @@ -2254,7 +2257,9 @@ impl FuncEnvironment<'_> {
Ok(match ht.top() {
WasmHeapTopType::Func => pos.ins().iconst(self.pointer_type(), 0),
// NB: null GC references don't need to be in stack maps.
WasmHeapTopType::Any | WasmHeapTopType::Extern => pos.ins().iconst(types::I32, 0),
WasmHeapTopType::Any | WasmHeapTopType::Extern | WasmHeapTopType::Exn => {
pos.ins().iconst(types::I32, 0)
}
WasmHeapTopType::Cont => todo!(), // FIXME: #10248 stack switching support.
})
}
Expand Down
14 changes: 11 additions & 3 deletions crates/cranelift/src/func_environ/gc/enabled.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,10 @@ fn read_field_at_addr(
WasmValType::F64 => builder.ins().load(ir::types::F64, flags, addr, 0),
WasmValType::V128 => builder.ins().load(ir::types::I8X16, flags, addr, 0),
WasmValType::Ref(r) => match r.heap_type.top() {
WasmHeapTopType::Any | WasmHeapTopType::Extern => gc_compiler(func_env)?
.translate_read_gc_reference(func_env, builder, r, addr, flags)?,
WasmHeapTopType::Any | WasmHeapTopType::Extern | WasmHeapTopType::Exn => {
gc_compiler(func_env)?
.translate_read_gc_reference(func_env, builder, r, addr, flags)?
}
WasmHeapTopType::Func => {
let expected_ty = match r.heap_type {
WasmHeapType::Func => ModuleInternedTypeIndex::reserved_value(),
Expand Down Expand Up @@ -1042,6 +1044,8 @@ pub fn translate_ref_test(
| WasmHeapType::NoFunc
| WasmHeapType::Cont
| WasmHeapType::NoCont
| WasmHeapType::Exn
| WasmHeapType::NoExn
| WasmHeapType::I31 => unreachable!("handled top, bottom, and i31 types above"),

// For these abstract but non-top and non-bottom types, we check the
Expand All @@ -1057,7 +1061,9 @@ pub fn translate_ref_test(
// TODO: This check should ideally be done inline, but we don't have a
// good way to access the `TypeRegistry`'s supertypes arrays from Wasm
// code at the moment.
WasmHeapType::ConcreteArray(ty) | WasmHeapType::ConcreteStruct(ty) => {
WasmHeapType::ConcreteArray(ty)
| WasmHeapType::ConcreteStruct(ty)
| WasmHeapType::ConcreteExn(ty) => {
let expected_interned_ty = ty.unwrap_module_type_index();
let expected_shared_ty =
func_env.module_interned_to_shared_ty(&mut builder.cursor(), expected_interned_ty);
Expand Down Expand Up @@ -1417,6 +1423,8 @@ impl FuncEnvironment<'_> {
// Can only ever be `null`.
WasmHeapType::NoExtern => false,

WasmHeapType::Exn | WasmHeapType::ConcreteExn(_) | WasmHeapType::NoExn => false,

// Wrong type hierarchy, and also funcrefs are not GC-managed
// types. Should have been caught by the assertion at the start of
// the function.
Expand Down
2 changes: 1 addition & 1 deletion crates/cranelift/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ fn wasm_call_signature(
fn reference_type(wasm_ht: WasmHeapType, pointer_type: ir::Type) -> ir::Type {
match wasm_ht.top() {
WasmHeapTopType::Func => pointer_type,
WasmHeapTopType::Any | WasmHeapTopType::Extern => ir::types::I32,
WasmHeapTopType::Any | WasmHeapTopType::Extern | WasmHeapTopType::Exn => ir::types::I32,
WasmHeapTopType::Cont =>
// TODO(10248) This is added in a follow-up PR
{
Expand Down
5 changes: 4 additions & 1 deletion crates/environ/src/compile/module_environ.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1220,7 +1220,10 @@ impl ModuleTranslation<'_> {
// initializer won't trap so we could continue processing
// segments, but that's left as a future optimization if
// necessary.
WasmHeapTopType::Any | WasmHeapTopType::Extern | WasmHeapTopType::Cont => break,
WasmHeapTopType::Any
| WasmHeapTopType::Extern
| WasmHeapTopType::Cont
| WasmHeapTopType::Exn => break,
}

// Function indices can be optimized here, but fully general
Expand Down
2 changes: 2 additions & 0 deletions crates/environ/src/compile/module_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@ where
WasmCompositeInnerType::Func(_) => WasmHeapType::ConcreteFunc(index),
WasmCompositeInnerType::Struct(_) => WasmHeapType::ConcreteStruct(index),
WasmCompositeInnerType::Cont(_) => WasmHeapType::ConcreteCont(index),
WasmCompositeInnerType::Exn(_) => WasmHeapType::ConcreteExn(index),
}
} else if let Some((wasmparser_types, _)) = self.rec_group_context.as_ref() {
let wasmparser_ty = &wasmparser_types[id].composite_type;
Expand Down Expand Up @@ -481,6 +482,7 @@ where
WasmCompositeInnerType::Func(_) => WasmHeapType::ConcreteFunc(index),
WasmCompositeInnerType::Struct(_) => WasmHeapType::ConcreteStruct(index),
WasmCompositeInnerType::Cont(_) => WasmHeapType::ConcreteCont(index),
WasmCompositeInnerType::Exn(_) => WasmHeapType::ConcreteExn(index),
}
} else if let Some((parser_types, rec_group)) = self.rec_group_context.as_ref() {
let rec_group_index = interned.index() - self.types.types.len_types();
Expand Down
Loading