A lightweight WebAssembly runtime that is fast, secure, and standards-compliant
Remove `HeapType::ConcreteExn` from the public API (#15099)
Alex Crichton458eead5366a
diff --git a/crates/c-api/include/wasmtime/types/val.h b/crates/c-api/include/wasmtime/types/val.hindex 595da01c50..9b455d9411 100644--- a/crates/c-api/include/wasmtime/types/val.h+++ b/crates/c-api/include/wasmtime/types/val.h@@ -55,10 +55,8 @@ typedef uint8_t wasmtime_heaptype_kind_t;#define WASMTIME_HEAPTYPE_KIND_CONCRETE_STRUCT 12/// \brief Heap type for the abstract `exn` type.#define WASMTIME_HEAPTYPE_KIND_EXN 13-/// \brief Heap type for a concrete exception type.-#define WASMTIME_HEAPTYPE_KIND_CONCRETE_EXN 14/// \brief Heap type for the abstract `noexn` type.-#define WASMTIME_HEAPTYPE_KIND_NOEXN 15+#define WASMTIME_HEAPTYPE_KIND_NOEXN 14/// \brief Payload of the `wasmtime_heaptype_t` union.typedef union wasmtime_heaptype_union {@@ -68,8 +66,6 @@ typedef union wasmtime_heaptype_union {wasmtime_array_type_t *concrete_array;/// \brief Used with `WASMTIME_HEAPTYPE_KIND_CONCRETE_STRUCT`.wasmtime_struct_type_t *concrete_struct;- /// \brief Used with `WASMTIME_HEAPTYPE_KIND_CONCRETE_EXN`.- wasmtime_exn_type_t *concrete_exn;} wasmtime_heaptype_union_t;/// \brief A WebAssembly heap type.diff --git a/crates/c-api/include/wasmtime/types/val.hh b/crates/c-api/include/wasmtime/types/val.hhindex 42ec8d684f..f89d2df8d1 100644--- a/crates/c-api/include/wasmtime/types/val.hh+++ b/crates/c-api/include/wasmtime/types/val.hh@@ -104,12 +104,6 @@ public:/// \brief Constructor for the `exn` heap typestatic HeapType exn() { return HeapType(WASMTIME_HEAPTYPE_KIND_EXN); }- /// \brief Constructor for a concrete exception heap type.- HeapType(const ExnType &ty) {- this->ty.kind = WASMTIME_HEAPTYPE_KIND_CONCRETE_EXN;- this->ty.of.concrete_exn = ExnType(ty).capi_release();- }-/// \brief Constructor for the `noexn` heap typestatic HeapType noexn() { return HeapType(WASMTIME_HEAPTYPE_KIND_NOEXN); }@@ -119,7 +113,6 @@ public:case WASMTIME_HEAPTYPE_KIND_CONCRETE_FUNC:case WASMTIME_HEAPTYPE_KIND_CONCRETE_ARRAY:case WASMTIME_HEAPTYPE_KIND_CONCRETE_STRUCT:- case WASMTIME_HEAPTYPE_KIND_CONCRETE_EXN:return true;default:return false;@@ -190,16 +183,6 @@ public:/// \brief Is this the abstract `exn` heap type?bool is_exn() const { return ty.kind == WASMTIME_HEAPTYPE_KIND_EXN; }- /// \brief If this is a concrete exception type, returns the underlying- /// exception type.- const ExnType *as_concrete_exn() const {- static_assert(sizeof(ExnType) == sizeof(wasmtime_exn_type_t *));- if (ty.kind == WASMTIME_HEAPTYPE_KIND_CONCRETE_EXN) {- return reinterpret_cast<const ExnType *>(&ty.of.concrete_exn);- }- return nullptr;- }-/// \brief Is this the abstract `noexn` heap type?bool is_noexn() const { return ty.kind == WASMTIME_HEAPTYPE_KIND_NOEXN; }diff --git a/crates/c-api/src/types/val.rs b/crates/c-api/src/types/val.rsindex e6fe7e6071..57a37d999c 100644--- a/crates/c-api/src/types/val.rs+++ b/crates/c-api/src/types/val.rs@@ -1,7 +1,4 @@-use crate::{- wasm_engine_t, wasm_functype_t, wasmtime_array_type_t, wasmtime_exn_type_t,- wasmtime_struct_type_t,-};+use crate::{wasm_engine_t, wasm_functype_t, wasmtime_array_type_t, wasmtime_struct_type_t};use std::mem::{ManuallyDrop, MaybeUninit};use wasmtime::{HeapType, RefType, ValType};@@ -133,7 +130,6 @@ pub unsafe extern "C" fn wasmtime_valtype_to_wasm(wasmtime_heaptype_t::Struct => HeapType::Struct,wasmtime_heaptype_t::ConcreteStruct(s) => HeapType::ConcreteStruct(s.ty.clone()),wasmtime_heaptype_t::Exn => HeapType::Exn,- wasmtime_heaptype_t::ConcreteExn(e) => HeapType::ConcreteExn(e.ty.clone()),wasmtime_heaptype_t::NoExn => HeapType::NoExn,};Box::new(ValType::Ref(RefType::new(r.nullable, heap_type)))@@ -156,7 +152,6 @@ pub enum wasmtime_heaptype_t {Struct,ConcreteStruct(Box<wasmtime_struct_type_t>),Exn,- ConcreteExn(Box<wasmtime_exn_type_t>),NoExn,}@@ -181,7 +176,6 @@ impl From<HeapType> for wasmtime_heaptype_t {Self::ConcreteStruct(Box::new(wasmtime_struct_type_t { ty: s }))}HeapType::Exn => Self::Exn,- HeapType::ConcreteExn(e) => Self::ConcreteExn(Box::new(wasmtime_exn_type_t { ty: e })),HeapType::NoExn => Self::NoExn,HeapType::Cont | HeapType::ConcreteCont(_) | HeapType::NoCont => {crate::abort("missing support for contref")diff --git a/crates/c-api/tests/val_type.cc b/crates/c-api/tests/val_type.ccindex 2ce4bc35fa..3bc373967e 100644--- a/crates/c-api/tests/val_type.cc+++ b/crates/c-api/tests/val_type.cc@@ -79,27 +79,15 @@ TEST(ExnType, Smoke) {Engine engine;ExnType ety =ExnType::create(engine, {ValType::i32(), ValType::i64()}).unwrap();- HeapType hty(ety);- auto exn_ty = hty.as_concrete_exn();- ASSERT_NE(exn_ty, nullptr);- EXPECT_TRUE(hty.is_concrete());EXPECT_FALSE(HeapType::exn().is_concrete());- TagType tt = exn_ty->tag_type();+ TagType tt = ety.tag_type();auto ft = tt->functype();EXPECT_EQ(ft->params().size(), 2);EXPECT_EQ(*ft->params().begin(), ValType::i32());- RefType rty(true, hty);- rty = RefType(false, hty);- rty = RefType(false, ety);- ValType vty(engine, rty);-ety = ExnType::create(engine, {}).unwrap();- HeapType hty2(ety);- auto exn_ty2 = hty2.as_concrete_exn();- ASSERT_NE(exn_ty2, nullptr);- EXPECT_EQ(exn_ty2->tag_type()->functype()->params().size(), 0);+ EXPECT_EQ(ety.tag_type()->functype()->params().size(), 0);}TEST(StructType, Smoke) {diff --git a/crates/wasmtime/src/runtime/externals/global.rs b/crates/wasmtime/src/runtime/externals/global.rsindex 91e887f3a0..3457ce4e47 100644--- a/crates/wasmtime/src/runtime/externals/global.rs+++ b/crates/wasmtime/src/runtime/externals/global.rs@@ -208,7 +208,7 @@ impl Global {HeapType::NoExtern => Ref::Extern(None),- HeapType::Exn | HeapType::ConcreteExn(_) => definition+ HeapType::Exn => definition.as_gc_ref().map(|r| {let r = store.clone_gc_ref(r);diff --git a/crates/wasmtime/src/runtime/gc/enabled/arrayref.rs b/crates/wasmtime/src/runtime/gc/enabled/arrayref.rsindex 0fbdd06149..c860e678d2 100644--- a/crates/wasmtime/src/runtime/gc/enabled/arrayref.rs+++ b/crates/wasmtime/src/runtime/gc/enabled/arrayref.rs@@ -1084,7 +1084,6 @@ unsafe impl WasmTy for Rooted<ArrayRef> {| HeapType::ConcreteCont(_)| HeapType::Exn| HeapType::NoExn- | HeapType::ConcreteExn(_)| HeapType::None => bail!("type mismatch: expected `(ref {ty})`, got `(ref {})`",self._ty(store)?,@@ -1184,7 +1183,6 @@ unsafe impl WasmTy for OwnedRooted<ArrayRef> {| HeapType::ConcreteCont(_)| HeapType::Exn| HeapType::NoExn- | HeapType::ConcreteExn(_)| HeapType::None => bail!("type mismatch: expected `(ref {ty})`, got `(ref {})`",self._ty(store)?,diff --git a/crates/wasmtime/src/runtime/gc/enabled/exnref.rs b/crates/wasmtime/src/runtime/gc/enabled/exnref.rsindex 502fe8f7d0..676be039f8 100644--- a/crates/wasmtime/src/runtime/gc/enabled/exnref.rs+++ b/crates/wasmtime/src/runtime/gc/enabled/exnref.rs@@ -466,7 +466,8 @@ impl ExnRef {pub(crate) fn _matches_ty(&self, store: &StoreOpaque, ty: &HeapType) -> Result<bool> {assert!(self.comes_from_same_store(store));- Ok(HeapType::from(self._ty(store)?).matches(ty))+ self.inner.try_gc_ref(store)?;+ Ok(HeapType::Exn.matches(ty))}pub(crate) fn ensure_matches_ty(&self, store: &StoreOpaque, ty: &HeapType) -> Result<()> {@@ -649,13 +650,11 @@ unsafe impl WasmTy for Rooted<ExnRef> {#[inline]fn dynamic_concrete_type_check(&self,- _store: &StoreOpaque,+ store: &StoreOpaque,_nullable: bool,- _ty: &HeapType,+ ty: &HeapType,) -> Result<()> {- // Wasm can't specify a concrete exn type, so there are no- // dynamic checks.- Ok(())+ self.ensure_matches_ty(store, ty)}fn store(self, store: &mut AutoAssertNoGc<'_>, ptr: &mut MaybeUninit<ValRaw>) -> Result<()> {diff --git a/crates/wasmtime/src/runtime/gc/enabled/structref.rs b/crates/wasmtime/src/runtime/gc/enabled/structref.rsindex 15a946232c..7d1800d951 100644--- a/crates/wasmtime/src/runtime/gc/enabled/structref.rs+++ b/crates/wasmtime/src/runtime/gc/enabled/structref.rs@@ -680,8 +680,7 @@ unsafe impl WasmTy for Rooted<StructRef> {| HeapType::Cont| HeapType::ConcreteCont(_)| HeapType::NoExn- | HeapType::Exn- | HeapType::ConcreteExn(_) => bail!(+ | HeapType::Exn => bail!("type mismatch: expected `(ref {ty})`, got `(ref {})`",self._ty(store)?,),@@ -780,8 +779,7 @@ unsafe impl WasmTy for OwnedRooted<StructRef> {| HeapType::Cont| HeapType::ConcreteCont(_)| HeapType::NoExn- | HeapType::Exn- | HeapType::ConcreteExn(_) => bail!(+ | HeapType::Exn => bail!("type mismatch: expected `(ref {ty})`, got `(ref {})`",self._ty(store)?,),diff --git a/crates/wasmtime/src/runtime/types.rs b/crates/wasmtime/src/runtime/types.rsindex cbf296289b..8c3472024a 100644--- a/crates/wasmtime/src/runtime/types.rs+++ b/crates/wasmtime/src/runtime/types.rs@@ -798,17 +798,9 @@ pub enum HeapType {/// The abstract `exn` heap type represents a reference to any/// kind of exception.///- /// This is a supertype of the internal concrete exception heap- /// types and the `noexn` heap type.+ /// This is a supertype of the `noexn` heap type.Exn,- /// A concrete exception object with a specific tag.- ///- /// These are internal, not exposed at the Wasm level, but useful- /// in our implementation and host API. These are subtypes of- /// `exn` and supertypes of `noexn`.- ConcreteExn(ExnType),-/// A reference to a continuation of a specific, concrete type.////// These are subtypes of `cont` and supertypes of `nocont`.@@ -909,7 +901,6 @@ impl Display for HeapType {HeapType::ConcreteArray(ty) => write!(f, "(concrete array {:?})", ty.type_index()),HeapType::ConcreteStruct(ty) => write!(f, "(concrete struct {:?})", ty.type_index()),HeapType::ConcreteCont(ty) => write!(f, "(concrete cont {:?})", ty.type_index()),- HeapType::ConcreteExn(ty) => write!(f, "(concrete exn {:?})", ty.type_index()),HeapType::Cont => write!(f, "cont"),HeapType::NoCont => write!(f, "nocont"),HeapType::Exn => write!(f, "exn"),@@ -946,13 +937,6 @@ impl From<ContType> for HeapType {}}-impl From<ExnType> for HeapType {- #[inline]- fn from(e: ExnType) -> Self {- HeapType::ConcreteExn(e)- }-}-impl HeapType {/// Is this the abstract `extern` heap type?pub fn is_extern(&self) -> bool {@@ -1017,7 +1001,6 @@ impl HeapType {| HeapType::ConcreteArray(_)| HeapType::ConcreteStruct(_)| HeapType::ConcreteCont(_)- | HeapType::ConcreteExn(_))}@@ -1105,21 +1088,6 @@ impl HeapType {self.as_concrete_struct().unwrap()}- /// Is this a concrete, user-defined exception type?- pub fn is_concrete_exn(&self) -> bool {- matches!(self, HeapType::ConcreteExn(_))- }-- /// Get the underlying concrete, user-defined exception type, if any.- ///- /// Returns `None` if this is not a concrete exception type.- pub fn as_concrete_exn(&self) -> Option<&ExnType> {- match self {- HeapType::ConcreteExn(e) => Some(e),- _ => None,- }- }-/// Get the top type of this heap type's type hierarchy.////// The returned type represents a supertype of all types in this heap@@ -1142,7 +1110,7 @@ impl HeapType {HeapType::Cont | HeapType::ConcreteCont(_) | HeapType::NoCont => HeapTopType::Cont,- HeapType::Exn | HeapType::ConcreteExn(_) | HeapType::NoExn => HeapTopType::Exn,+ HeapType::Exn | HeapType::NoExn => HeapTopType::Exn,}}@@ -1179,7 +1147,7 @@ impl HeapType {HeapType::Cont | HeapType::ConcreteCont(_) | HeapType::NoCont => HeapBottomType::NoCont,- HeapType::Exn | HeapType::ConcreteExn(_) | HeapType::NoExn => HeapBottomType::NoExn,+ HeapType::Exn | HeapType::NoExn => HeapBottomType::NoExn,}}@@ -1287,13 +1255,9 @@ impl HeapType {(HeapType::Any, HeapType::Any) => true,(HeapType::Any, _) => false,- (HeapType::NoExn, HeapType::Exn | HeapType::ConcreteExn(_) | HeapType::NoExn) => true,+ (HeapType::NoExn, HeapType::Exn | HeapType::NoExn) => true,(HeapType::NoExn, _) => false,- (HeapType::ConcreteExn(_), HeapType::Exn) => true,- (HeapType::ConcreteExn(a), HeapType::ConcreteExn(b)) => a.matches(b),- (HeapType::ConcreteExn(_), _) => false,-(HeapType::Exn, HeapType::Exn) => true,(HeapType::Exn, _) => false,}@@ -1343,7 +1307,6 @@ impl HeapType {HeapType::ConcreteArray(ty) => ty.comes_from_same_engine(engine),HeapType::ConcreteStruct(ty) => ty.comes_from_same_engine(engine),HeapType::ConcreteCont(ty) => ty.comes_from_same_engine(engine),- HeapType::ConcreteExn(ty) => ty.comes_from_same_engine(engine),}}@@ -1375,9 +1338,6 @@ impl HeapType {}HeapType::Exn => WasmHeapType::Exn,HeapType::NoExn => WasmHeapType::NoExn,- HeapType::ConcreteExn(e) => {- WasmHeapType::ConcreteExn(EngineOrModuleTypeIndex::Engine(e.type_index()))- }}}@@ -1420,11 +1380,12 @@ impl HeapType {WasmHeapType::ConcreteCont(EngineOrModuleTypeIndex::Engine(idx)) => {HeapType::ConcreteCont(ContType::from_shared_type_index(engine, *idx).unwrap())}- WasmHeapType::Exn => HeapType::Exn,- WasmHeapType::NoExn => HeapType::NoExn,- WasmHeapType::ConcreteExn(EngineOrModuleTypeIndex::Engine(idx)) => {- HeapType::ConcreteExn(ExnType::from_shared_type_index(engine, *idx).unwrap())+ // Concrete exception types are an implementation detail of+ // Wasmtime that Wasm can't name, so they're only `exn` here.+ WasmHeapType::Exn | WasmHeapType::ConcreteExn(EngineOrModuleTypeIndex::Engine(_)) => {+ HeapType::Exn}+ WasmHeapType::NoExn => HeapType::NoExn,}}@@ -1434,7 +1395,6 @@ impl HeapType {HeapType::ConcreteFunc(f) => Some(&f.registered_type),HeapType::ConcreteArray(a) => Some(&a.registered_type),HeapType::ConcreteStruct(a) => Some(&a.registered_type),- HeapType::ConcreteExn(e) => Some(&e.registered_type),HeapType::Extern| HeapType::NoExtern@@ -1479,7 +1439,6 @@ impl HeapType {ConcreteArray(ty) => Some(ty.registered_type),ConcreteStruct(ty) => Some(ty.registered_type),ConcreteCont(ty) => Some(ty.registered_type),- ConcreteExn(ty) => Some(ty.registered_type),Extern | NoExtern | Func | NoFunc | Any | Eq | I31 | Array | Struct | Cont | NoCont| Exn | NoExn | None => Option::None,}@@ -3029,6 +2988,7 @@ impl ExnType {////// Returns `None` if `index` does not name a registered type of this/// shape, since indices may come from the untrusted GC heap.+ #[cfg(feature = "gc")]pub(crate) fn from_shared_type_index(engine: &Engine,index: VMSharedTypeIndex,diff --git a/crates/wasmtime/src/runtime/values.rs b/crates/wasmtime/src/runtime/values.rsindex ddab81ebcd..6839863a5c 100644--- a/crates/wasmtime/src/runtime/values.rs+++ b/crates/wasmtime/src/runtime/values.rs@@ -178,7 +178,10 @@ impl Val {Val::AnyRef(None) => ValType::NULLREF,Val::AnyRef(Some(a)) => ValType::Ref(RefType::new(false, a._ty(store)?)),Val::ExnRef(None) => ValType::NULLEXNREF,- Val::ExnRef(Some(e)) => ValType::Ref(RefType::new(false, e._ty(store)?.into())),+ Val::ExnRef(Some(e)) => {+ e.try_gc_ref(store)?;+ ValType::Ref(RefType::new(false, HeapType::Exn))+ }Val::ContRef(_) => {// TODO(#10248): Return proper continuation reference type when availablereturn Err(crate::format_err!(@@ -345,9 +348,7 @@ impl Val {AnyRef::_from_raw(store, raw.get_anyref()).into()}- HeapType::Exn | HeapType::ConcreteExn(_) => {- ExnRef::_from_raw(store, raw.get_exnref()).into()- }+ HeapType::Exn => ExnRef::_from_raw(store, raw.get_exnref()).into(),HeapType::NoExn => Ref::Exn(None),HeapType::None => Ref::Any(None),@@ -1051,7 +1052,10 @@ impl Ref {Ref::Any(Some(a)) => a._ty(store)?,Ref::Exn(None) => HeapType::NoExn,- Ref::Exn(Some(e)) => e._ty(store)?.into(),+ Ref::Exn(Some(e)) => {+ e.try_gc_ref(store)?;+ HeapType::Exn+ }},))}@@ -1121,10 +1125,7 @@ impl Ref {true}(Ref::Exn(None), HeapType::Exn) => true,- (Ref::Exn(None), HeapType::NoExn | HeapType::ConcreteExn(_)) => true,- (Ref::Exn(Some(e)), HeapType::ConcreteExn(_)) => {- e._matches_ty(store, &ty.heap_type())?- }+ (Ref::Exn(None), HeapType::NoExn) => true,(Ref::Exn(_), _) => false,})}