From 065bedd2f52de2d3966510bf0f788984fde3a88b Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Tue, 29 Oct 2024 11:58:22 -0700 Subject: [PATCH 01/11] threads: add `WasmCompositeInnerType` layer As in `wasm-tools`, push the type down a layer so that `WasmCompositeType` can be marked shared. This leaves several holes to be filled in by future commits (all marked with `TODO: handle shared`); in effect, this change allows `WasmCompositeType` to be marked shared but mostly does not wire up the sharedness during translation. --- crates/cranelift/src/func_environ.rs | 6 +- crates/cranelift/src/gc/enabled.rs | 28 ++++--- crates/cranelift/src/gc/enabled/drc.rs | 7 +- crates/environ/src/compile/module_types.rs | 27 +++--- crates/environ/src/gc.rs | 13 +-- crates/environ/src/types.rs | 87 +++++++++++++------- crates/wasmtime/src/runtime/type_registry.rs | 17 ++-- crates/wasmtime/src/runtime/types.rs | 22 +++-- crates/wasmtime/src/runtime/vm/const_expr.rs | 14 ++-- 9 files changed, 139 insertions(+), 82 deletions(-) diff --git a/crates/cranelift/src/func_environ.rs b/crates/cranelift/src/func_environ.rs index 8821dfc287d3..e5030030fa8f 100644 --- a/crates/cranelift/src/func_environ.rs +++ b/crates/cranelift/src/func_environ.rs @@ -22,7 +22,7 @@ use wasmtime_environ::{ BuiltinFunctionIndex, DataIndex, ElemIndex, EngineOrModuleTypeIndex, FuncIndex, GlobalIndex, IndexType, Memory, MemoryIndex, MemoryPlan, MemoryStyle, Module, ModuleInternedTypeIndex, ModuleTranslation, ModuleTypesBuilder, PtrSize, Table, TableIndex, TableStyle, Tunables, - TypeConvert, TypeIndex, VMOffsets, WasmCompositeType, WasmFuncType, WasmHeapTopType, + TypeConvert, TypeIndex, VMOffsets, WasmCompositeInnerType, WasmFuncType, WasmHeapTopType, WasmHeapType, WasmRefType, WasmResult, WasmValType, }; use wasmtime_environ::{FUNCREF_INIT_BIT, FUNCREF_MASK}; @@ -1932,8 +1932,8 @@ impl<'module_environment> crate::translate::FuncEnvironment fn struct_fields_len(&mut self, struct_type_index: TypeIndex) -> WasmResult { let ty = self.module.types[struct_type_index]; - match &self.types[ty].composite_type { - WasmCompositeType::Struct(s) => Ok(s.fields.len()), + match &self.types[ty].composite_type.inner { + WasmCompositeInnerType::Struct(s) => Ok(s.fields.len()), _ => unreachable!(), } } diff --git a/crates/cranelift/src/gc/enabled.rs b/crates/cranelift/src/gc/enabled.rs index 80b603a9d784..7aa34a017326 100644 --- a/crates/cranelift/src/gc/enabled.rs +++ b/crates/cranelift/src/gc/enabled.rs @@ -11,8 +11,8 @@ use cranelift_entity::packed_option::ReservedValue; use cranelift_frontend::FunctionBuilder; use wasmtime_environ::{ GcArrayLayout, GcLayout, GcStructLayout, ModuleInternedTypeIndex, PtrSize, TypeIndex, VMGcKind, - WasmCompositeType, WasmHeapTopType, WasmHeapType, WasmRefType, WasmResult, WasmStorageType, - WasmValType, I31_DISCRIMINANT, NON_NULL_NON_I31_MASK, + WasmCompositeInnerType, WasmHeapTopType, WasmHeapType, WasmRefType, WasmResult, + WasmStorageType, WasmValType, I31_DISCRIMINANT, NON_NULL_NON_I31_MASK, }; mod drc; @@ -252,8 +252,8 @@ pub fn translate_struct_new_default( struct_type_index: TypeIndex, ) -> WasmResult { let interned_ty = func_env.module.types[struct_type_index]; - let struct_ty = match &func_env.types[interned_ty].composite_type { - WasmCompositeType::Struct(s) => s, + let struct_ty = match &func_env.types[interned_ty].composite_type.inner { + WasmCompositeInnerType::Struct(s) => s, _ => unreachable!(), }; let fields = struct_ty @@ -285,8 +285,8 @@ pub fn translate_struct_get( let field_offset = struct_layout.fields[field_index]; - let field_ty = match &func_env.types[interned_type_index].composite_type { - WasmCompositeType::Struct(s) => &s.fields[field_index], + let field_ty = match &func_env.types[interned_type_index].composite_type.inner { + WasmCompositeInnerType::Struct(s) => &s.fields[field_index], _ => unreachable!(), }; @@ -323,8 +323,8 @@ fn translate_struct_get_and_extend( let field_offset = struct_layout.fields[field_index]; - let field_ty = match &func_env.types[interned_type_index].composite_type { - WasmCompositeType::Struct(s) => &s.fields[field_index], + let field_ty = match &func_env.types[interned_type_index].composite_type.inner { + WasmCompositeInnerType::Struct(s) => &s.fields[field_index], _ => unreachable!(), }; @@ -401,8 +401,8 @@ pub fn translate_struct_set( let field_offset = struct_layout.fields[field_index]; - let field_ty = match &func_env.types[interned_type_index].composite_type { - WasmCompositeType::Struct(s) => &s.fields[field_index], + let field_ty = match &func_env.types[interned_type_index].composite_type.inner { + WasmCompositeInnerType::Struct(s) => &s.fields[field_index], _ => unreachable!(), }; @@ -447,7 +447,8 @@ pub fn translate_array_new_default( len: ir::Value, ) -> WasmResult { let interned_ty = func_env.module.types[array_type_index]; - let WasmCompositeType::Array(array_ty) = &func_env.types[interned_ty].composite_type else { + let WasmCompositeInnerType::Array(array_ty) = &func_env.types[interned_ty].composite_type.inner + else { unreachable!() }; let elem = default_value(&mut builder.cursor(), func_env, &array_ty.0.element_type); @@ -598,6 +599,7 @@ pub fn translate_array_fill( |func_env, builder, elem_addr| { let elem_ty = func_env.types[interned_type_index] .composite_type + .inner .unwrap_array() .0 .element_type; @@ -765,6 +767,7 @@ pub fn translate_array_get( let array_ty = func_env.types[array_type_index] .composite_type + .inner .unwrap_array(); let elem_ty = array_ty.0.element_type; @@ -783,6 +786,7 @@ pub fn translate_array_get_s( let array_ty = func_env.types[array_type_index] .composite_type + .inner .unwrap_array(); let elem_ty = array_ty.0.element_type; @@ -801,6 +805,7 @@ pub fn translate_array_get_u( let array_ty = func_env.types[array_type_index] .composite_type + .inner .unwrap_array(); let elem_ty = array_ty.0.element_type; @@ -820,6 +825,7 @@ pub fn translate_array_set( let array_ty = func_env.types[array_type_index] .composite_type + .inner .unwrap_array(); let elem_ty = array_ty.0.element_type; diff --git a/crates/cranelift/src/gc/enabled/drc.rs b/crates/cranelift/src/gc/enabled/drc.rs index e86068da7f7a..db53da6f1dd4 100644 --- a/crates/cranelift/src/gc/enabled/drc.rs +++ b/crates/cranelift/src/gc/enabled/drc.rs @@ -14,7 +14,7 @@ use cranelift_frontend::FunctionBuilder; use smallvec::SmallVec; use wasmtime_environ::{ drc::DrcTypeLayouts, GcArrayLayout, GcTypeLayouts, ModuleInternedTypeIndex, PtrSize, TypeIndex, - VMGcKind, WasmCompositeType, WasmHeapTopType, WasmHeapType, WasmRefType, WasmResult, + VMGcKind, WasmCompositeInnerType, WasmHeapTopType, WasmHeapType, WasmRefType, WasmResult, WasmStorageType, WasmValType, }; @@ -415,6 +415,7 @@ impl GcCompiler for DrcCompiler { let array_ty = func_env.types[interned_type_index] .composite_type + .inner .unwrap_array(); let elem_ty = array_ty.0.element_type; @@ -493,8 +494,8 @@ impl GcCompiler for DrcCompiler { uextend_i32_to_pointer_type(builder, func_env.pointer_type(), struct_ref); let struct_addr = builder.ins().iadd(base, extended_struct_ref); - let struct_ty = match &func_env.types[interned_type_index].composite_type { - WasmCompositeType::Struct(s) => s, + let struct_ty = match &func_env.types[interned_type_index].composite_type.inner { + WasmCompositeInnerType::Struct(s) => s, _ => unreachable!(), }; let field_types: SmallVec<[_; 8]> = struct_ty.fields.iter().cloned().collect(); diff --git a/crates/environ/src/compile/module_types.rs b/crates/environ/src/compile/module_types.rs index e25c7c6de57e..45aa2c5b6a69 100644 --- a/crates/environ/src/compile/module_types.rs +++ b/crates/environ/src/compile/module_types.rs @@ -1,7 +1,7 @@ use crate::{ EngineOrModuleTypeIndex, EntityRef, ModuleInternedRecGroupIndex, ModuleInternedTypeIndex, - ModuleTypes, TypeConvert, TypeIndex, WasmCompositeType, WasmFuncType, WasmHeapType, WasmResult, - WasmSubType, + ModuleTypes, TypeConvert, TypeIndex, WasmCompositeInnerType, WasmCompositeType, WasmFuncType, + WasmHeapType, WasmResult, WasmSubType, }; use std::{borrow::Cow, collections::HashMap, ops::Index}; use wasmparser::{UnpackedIndex, Validator, ValidatorId}; @@ -163,7 +163,10 @@ impl ModuleTypesBuilder { let idx = self.types.push(WasmSubType { is_final: true, supertype: None, - composite_type: WasmCompositeType::Func(f.clone()), + composite_type: WasmCompositeType { + inner: WasmCompositeInnerType::Func(f.clone()), + shared: false, // TODO: handle shared + }, }); // The trampoline type is its own trampoline type. @@ -388,14 +391,13 @@ where // array vs struct vs func reference. In this case, we can use // the validator's type context. if let Some(ty) = self.types.types.get(interned) { - match &ty.composite_type { - WasmCompositeType::Array(_) => WasmHeapType::ConcreteArray(index), - WasmCompositeType::Func(_) => WasmHeapType::ConcreteFunc(index), - WasmCompositeType::Struct(_) => WasmHeapType::ConcreteStruct(index), + match &ty.composite_type.inner { + WasmCompositeInnerType::Array(_) => WasmHeapType::ConcreteArray(index), + WasmCompositeInnerType::Func(_) => WasmHeapType::ConcreteFunc(index), + WasmCompositeInnerType::Struct(_) => WasmHeapType::ConcreteStruct(index), } } else if let Some((wasmparser_types, _)) = self.rec_group_context.as_ref() { let wasmparser_ty = &wasmparser_types[id].composite_type; - assert!(!wasmparser_ty.shared); match &wasmparser_ty.inner { wasmparser::CompositeInnerType::Array(_) => { WasmHeapType::ConcreteArray(index) @@ -426,10 +428,10 @@ where // indirectly get one by looking it up inside the current rec // group. if let Some(ty) = self.types.types.get(interned) { - match &ty.composite_type { - WasmCompositeType::Array(_) => WasmHeapType::ConcreteArray(index), - WasmCompositeType::Func(_) => WasmHeapType::ConcreteFunc(index), - WasmCompositeType::Struct(_) => WasmHeapType::ConcreteStruct(index), + match &ty.composite_type.inner { + WasmCompositeInnerType::Array(_) => WasmHeapType::ConcreteArray(index), + WasmCompositeInnerType::Func(_) => WasmHeapType::ConcreteFunc(index), + WasmCompositeInnerType::Struct(_) => WasmHeapType::ConcreteStruct(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(); @@ -438,7 +440,6 @@ where .nth(rec_group_index) .unwrap(); let wasmparser_ty = &parser_types[id].composite_type; - assert!(!wasmparser_ty.shared); match &wasmparser_ty.inner { wasmparser::CompositeInnerType::Array(_) => { WasmHeapType::ConcreteArray(index) diff --git a/crates/environ/src/gc.rs b/crates/environ/src/gc.rs index 167b3517b928..52f6258b16fc 100644 --- a/crates/environ/src/gc.rs +++ b/crates/environ/src/gc.rs @@ -13,7 +13,10 @@ pub mod drc; use crate::prelude::*; -use crate::{WasmArrayType, WasmCompositeType, WasmStorageType, WasmStructType, WasmValType}; +use crate::{ + WasmArrayType, WasmCompositeInnerType, WasmCompositeType, WasmStorageType, WasmStructType, + WasmValType, +}; use core::alloc::Layout; /// Discriminant to check whether GC reference is an `i31ref` or not. @@ -63,10 +66,10 @@ pub trait GcTypeLayouts { /// Returns `None` if the type is a function type, as functions are not /// managed by the GC. fn gc_layout(&self, ty: &WasmCompositeType) -> Option { - match ty { - WasmCompositeType::Array(ty) => Some(self.array_layout(ty).into()), - WasmCompositeType::Struct(ty) => Some(self.struct_layout(ty).into()), - WasmCompositeType::Func(_) => None, + match &ty.inner { + WasmCompositeInnerType::Array(ty) => Some(self.array_layout(ty).into()), + WasmCompositeInnerType::Struct(ty) => Some(self.struct_layout(ty).into()), + WasmCompositeInnerType::Func(_) => None, } } diff --git a/crates/environ/src/types.rs b/crates/environ/src/types.rs index 0b7d64a350a1..26aba46caeb2 100644 --- a/crates/environ/src/types.rs +++ b/crates/environ/src/types.rs @@ -885,27 +885,50 @@ impl TypeTrace for WasmStructType { } } +#[derive(Debug, Clone, Eq, PartialEq, Hash, Serialize, Deserialize)] +#[allow(missing_docs)] +pub struct WasmCompositeType { + /// The type defined inside the composite type. + pub inner: WasmCompositeInnerType, + /// Is the composite type shared? This is part of the + /// shared-everything-threads proposal. + pub shared: bool, +} + +impl fmt::Display for WasmCompositeType { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + if self.shared { + write!(f, "(shared ")?; + } + fmt::Display::fmt(&self.inner, f)?; + if self.shared { + write!(f, ")")?; + } + Ok(()) + } +} + /// A function, array, or struct type. #[derive(Debug, Clone, Eq, PartialEq, Hash, Serialize, Deserialize)] #[allow(missing_docs)] -pub enum WasmCompositeType { +pub enum WasmCompositeInnerType { Array(WasmArrayType), Func(WasmFuncType), Struct(WasmStructType), } -impl fmt::Display for WasmCompositeType { +impl fmt::Display for WasmCompositeInnerType { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { - WasmCompositeType::Array(ty) => fmt::Display::fmt(ty, f), - WasmCompositeType::Func(ty) => fmt::Display::fmt(ty, f), - WasmCompositeType::Struct(ty) => fmt::Display::fmt(ty, f), + Self::Array(ty) => fmt::Display::fmt(ty, f), + Self::Func(ty) => fmt::Display::fmt(ty, f), + Self::Struct(ty) => fmt::Display::fmt(ty, f), } } } #[allow(missing_docs)] -impl WasmCompositeType { +impl WasmCompositeInnerType { #[inline] pub fn is_array(&self) -> bool { matches!(self, Self::Array(_)) @@ -914,7 +937,7 @@ impl WasmCompositeType { #[inline] pub fn as_array(&self) -> Option<&WasmArrayType> { match self { - WasmCompositeType::Array(f) => Some(f), + Self::Array(f) => Some(f), _ => None, } } @@ -932,7 +955,7 @@ impl WasmCompositeType { #[inline] pub fn as_func(&self) -> Option<&WasmFuncType> { match self { - WasmCompositeType::Func(f) => Some(f), + Self::Func(f) => Some(f), _ => None, } } @@ -950,7 +973,7 @@ impl WasmCompositeType { #[inline] pub fn as_struct(&self) -> Option<&WasmStructType> { match self { - WasmCompositeType::Struct(f) => Some(f), + Self::Struct(f) => Some(f), _ => None, } } @@ -966,10 +989,10 @@ impl TypeTrace for WasmCompositeType { where F: FnMut(EngineOrModuleTypeIndex) -> Result<(), E>, { - match self { - WasmCompositeType::Array(a) => a.trace(func), - WasmCompositeType::Func(f) => f.trace(func), - WasmCompositeType::Struct(a) => a.trace(func), + match &self.inner { + WasmCompositeInnerType::Array(a) => a.trace(func), + WasmCompositeInnerType::Func(f) => f.trace(func), + WasmCompositeInnerType::Struct(a) => a.trace(func), } } @@ -977,10 +1000,10 @@ impl TypeTrace for WasmCompositeType { where F: FnMut(&mut EngineOrModuleTypeIndex) -> Result<(), E>, { - match self { - WasmCompositeType::Array(a) => a.trace_mut(func), - WasmCompositeType::Func(f) => f.trace_mut(func), - WasmCompositeType::Struct(a) => a.trace_mut(func), + match &mut self.inner { + WasmCompositeInnerType::Array(a) => a.trace_mut(func), + WasmCompositeInnerType::Func(f) => f.trace_mut(func), + WasmCompositeInnerType::Struct(a) => a.trace_mut(func), } } } @@ -1020,47 +1043,47 @@ impl fmt::Display for WasmSubType { impl WasmSubType { #[inline] pub fn is_func(&self) -> bool { - self.composite_type.is_func() + self.composite_type.inner.is_func() } #[inline] pub fn as_func(&self) -> Option<&WasmFuncType> { - self.composite_type.as_func() + self.composite_type.inner.as_func() } #[inline] pub fn unwrap_func(&self) -> &WasmFuncType { - self.composite_type.unwrap_func() + self.composite_type.inner.unwrap_func() } #[inline] pub fn is_array(&self) -> bool { - self.composite_type.is_array() + self.composite_type.inner.is_array() } #[inline] pub fn as_array(&self) -> Option<&WasmArrayType> { - self.composite_type.as_array() + self.composite_type.inner.as_array() } #[inline] pub fn unwrap_array(&self) -> &WasmArrayType { - self.composite_type.unwrap_array() + self.composite_type.inner.unwrap_array() } #[inline] pub fn is_struct(&self) -> bool { - self.composite_type.is_struct() + self.composite_type.inner.is_struct() } #[inline] pub fn as_struct(&self) -> Option<&WasmStructType> { - self.composite_type.as_struct() + self.composite_type.inner.as_struct() } #[inline] pub fn unwrap_struct(&self) -> &WasmStructType { - self.composite_type.unwrap_struct() + self.composite_type.inner.unwrap_struct() } } @@ -1850,19 +1873,23 @@ pub trait TypeConvert { fn convert_composite_type(&self, ty: &wasmparser::CompositeType) -> WasmCompositeType { assert!(!ty.shared); - match &ty.inner { + let inner = match &ty.inner { wasmparser::CompositeInnerType::Func(f) => { - WasmCompositeType::Func(self.convert_func_type(f)) + WasmCompositeInnerType::Func(self.convert_func_type(f)) } wasmparser::CompositeInnerType::Array(a) => { - WasmCompositeType::Array(self.convert_array_type(a)) + WasmCompositeInnerType::Array(self.convert_array_type(a)) } wasmparser::CompositeInnerType::Struct(s) => { - WasmCompositeType::Struct(self.convert_struct_type(s)) + WasmCompositeInnerType::Struct(self.convert_struct_type(s)) } wasmparser::CompositeInnerType::Cont(_) => { unimplemented!("continuation types") } + }; + WasmCompositeType { + inner, + shared: ty.shared, } } diff --git a/crates/wasmtime/src/runtime/type_registry.rs b/crates/wasmtime/src/runtime/type_registry.rs index d23e31607421..4e13f76c9130 100644 --- a/crates/wasmtime/src/runtime/type_registry.rs +++ b/crates/wasmtime/src/runtime/type_registry.rs @@ -737,9 +737,12 @@ impl TypeRegistryInner { WasmSubType { is_final: true, supertype: None, - composite_type: wasmtime_environ::WasmCompositeType::Func( - trampoline.into_owned(), - ), + composite_type: wasmtime_environ::WasmCompositeType { + shared: false, // TODO: handle shared + inner: wasmtime_environ::WasmCompositeInnerType::Func( + trampoline.into_owned(), + ), + }, }, ); let trampoline_index = trampoline_entry.0.shared_type_indices[0]; @@ -806,12 +809,12 @@ impl TypeRegistryInner { "type is not canonicalized for runtime usage: {ty:?}" ); - let gc_layout = match &ty.composite_type { - wasmtime_environ::WasmCompositeType::Func(_) => None, - wasmtime_environ::WasmCompositeType::Array(a) => { + let gc_layout = match &ty.composite_type.inner { + wasmtime_environ::WasmCompositeInnerType::Func(_) => None, + wasmtime_environ::WasmCompositeInnerType::Array(a) => { Some(gc_runtime.layouts().array_layout(a).into()) } - wasmtime_environ::WasmCompositeType::Struct(s) => { + wasmtime_environ::WasmCompositeInnerType::Struct(s) => { Some(gc_runtime.layouts().struct_layout(s).into()) } }; diff --git a/crates/wasmtime/src/runtime/types.rs b/crates/wasmtime/src/runtime/types.rs index 348ca968c277..fa5feef8e4d5 100644 --- a/crates/wasmtime/src/runtime/types.rs +++ b/crates/wasmtime/src/runtime/types.rs @@ -2,8 +2,9 @@ use crate::prelude::*; use core::fmt::{self, Display, Write}; use wasmtime_environ::{ EngineOrModuleTypeIndex, EntityType, Global, IndexType, Limits, Memory, ModuleTypes, Table, - TypeTrace, VMSharedTypeIndex, WasmArrayType, WasmCompositeType, WasmFieldType, WasmFuncType, - WasmHeapType, WasmRefType, WasmStorageType, WasmStructType, WasmSubType, WasmValType, + TypeTrace, VMSharedTypeIndex, WasmArrayType, WasmCompositeInnerType, WasmCompositeType, + WasmFieldType, WasmFuncType, WasmHeapType, WasmRefType, WasmStorageType, WasmStructType, + WasmSubType, WasmValType, }; use crate::{type_registry::RegisteredType, Engine}; @@ -1617,6 +1618,7 @@ impl StructType { Self::from_wasm_struct_type( engine, finality.is_final(), + false, // TODO: handle shared supertype.map(|ty| ty.type_index().into()), WasmStructType { fields }, ) @@ -1733,6 +1735,7 @@ impl StructType { pub(crate) fn from_wasm_struct_type( engine: &Engine, is_final: bool, + is_shared: bool, supertype: Option, ty: WasmStructType, ) -> Result { @@ -1750,7 +1753,10 @@ impl StructType { WasmSubType { is_final, supertype, - composite_type: WasmCompositeType::Struct(ty), + composite_type: WasmCompositeType { + shared: is_shared, + inner: WasmCompositeInnerType::Struct(ty), + }, }, ); Ok(Self { @@ -1994,7 +2000,10 @@ impl ArrayType { WasmSubType { is_final, supertype, - composite_type: WasmCompositeType::Array(ty), + composite_type: WasmCompositeType { + shared: false, // TODO: handle shared + inner: WasmCompositeInnerType::Array(ty), + }, }, ); Self { @@ -2350,7 +2359,10 @@ impl FuncType { WasmSubType { is_final, supertype, - composite_type: WasmCompositeType::Func(ty), + composite_type: WasmCompositeType { + shared: false, // TODO: handle shared + inner: WasmCompositeInnerType::Func(ty), + }, }, ); Self { diff --git a/crates/wasmtime/src/runtime/vm/const_expr.rs b/crates/wasmtime/src/runtime/vm/const_expr.rs index 0ffab2720e37..e2a48e0a9dd2 100644 --- a/crates/wasmtime/src/runtime/vm/const_expr.rs +++ b/crates/wasmtime/src/runtime/vm/const_expr.rs @@ -7,8 +7,8 @@ use crate::{ }; use smallvec::SmallVec; use wasmtime_environ::{ - ConstExpr, ConstOp, FuncIndex, GlobalIndex, ModuleInternedTypeIndex, WasmCompositeType, - WasmSubType, + ConstExpr, ConstOp, FuncIndex, GlobalIndex, ModuleInternedTypeIndex, WasmCompositeInnerType, + WasmCompositeType, WasmSubType, }; /// An interpreter for const expressions. @@ -55,8 +55,8 @@ impl<'a> ConstEvalContext<'a> { .runtime_module() .expect("should never be allocating a struct type defined in a dummy module"); - let struct_ty = match &module.types()[struct_type_index].composite_type { - WasmCompositeType::Struct(s) => s, + let struct_ty = match &module.types()[struct_type_index].composite_type.inner { + WasmCompositeInnerType::Struct(s) => s, _ => unreachable!(), }; @@ -118,7 +118,11 @@ impl<'a> ConstEvalContext<'a> { .borrow(shared_ty) .expect("should have a registered type for struct"); let WasmSubType { - composite_type: WasmCompositeType::Struct(struct_ty), + composite_type: + WasmCompositeType { + shared: false, // TODO: handle shared + inner: WasmCompositeInnerType::Struct(struct_ty), + }, .. } = &*borrowed else { From 6328709cab9b22309b87e25f85520fbffb9cbb9c Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Wed, 30 Oct 2024 11:16:10 -0700 Subject: [PATCH 02/11] review: remove TODOs --- crates/wasmtime/src/runtime/types.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/wasmtime/src/runtime/types.rs b/crates/wasmtime/src/runtime/types.rs index fa5feef8e4d5..398182c9cf1b 100644 --- a/crates/wasmtime/src/runtime/types.rs +++ b/crates/wasmtime/src/runtime/types.rs @@ -1618,7 +1618,7 @@ impl StructType { Self::from_wasm_struct_type( engine, finality.is_final(), - false, // TODO: handle shared + false, supertype.map(|ty| ty.type_index().into()), WasmStructType { fields }, ) @@ -2001,7 +2001,7 @@ impl ArrayType { is_final, supertype, composite_type: WasmCompositeType { - shared: false, // TODO: handle shared + shared: false, inner: WasmCompositeInnerType::Array(ty), }, }, @@ -2360,7 +2360,7 @@ impl FuncType { is_final, supertype, composite_type: WasmCompositeType { - shared: false, // TODO: handle shared + shared: false, inner: WasmCompositeInnerType::Func(ty), }, }, From ef0731e123a86c36d95f8b87f8e852fa09abf261 Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Wed, 30 Oct 2024 11:16:55 -0700 Subject: [PATCH 03/11] review: remove more TODOs --- crates/wasmtime/src/runtime/vm/const_expr.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/wasmtime/src/runtime/vm/const_expr.rs b/crates/wasmtime/src/runtime/vm/const_expr.rs index e2a48e0a9dd2..55b4a2c63081 100644 --- a/crates/wasmtime/src/runtime/vm/const_expr.rs +++ b/crates/wasmtime/src/runtime/vm/const_expr.rs @@ -120,7 +120,7 @@ impl<'a> ConstEvalContext<'a> { let WasmSubType { composite_type: WasmCompositeType { - shared: false, // TODO: handle shared + shared: false, inner: WasmCompositeInnerType::Struct(struct_ty), }, .. From 844548142595fc6287419694fce1799d1a10823b Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Wed, 30 Oct 2024 11:28:35 -0700 Subject: [PATCH 04/11] review: refactor to use `GcTypeLayouts::gc_layout` --- crates/wasmtime/src/runtime/type_registry.rs | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/crates/wasmtime/src/runtime/type_registry.rs b/crates/wasmtime/src/runtime/type_registry.rs index 4e13f76c9130..cc5d9b2bbc55 100644 --- a/crates/wasmtime/src/runtime/type_registry.rs +++ b/crates/wasmtime/src/runtime/type_registry.rs @@ -809,15 +809,7 @@ impl TypeRegistryInner { "type is not canonicalized for runtime usage: {ty:?}" ); - let gc_layout = match &ty.composite_type.inner { - wasmtime_environ::WasmCompositeInnerType::Func(_) => None, - wasmtime_environ::WasmCompositeInnerType::Array(a) => { - Some(gc_runtime.layouts().array_layout(a).into()) - } - wasmtime_environ::WasmCompositeInnerType::Struct(s) => { - Some(gc_runtime.layouts().struct_layout(s).into()) - } - }; + let gc_layout = gc_runtime.layouts().gc_layout(&ty.composite_type); // Add the type to our slab. let id = self.types.alloc(Arc::new(ty)); From c76df0cb7d13ef1c8f710defd3b04063b6d90965 Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Wed, 30 Oct 2024 11:30:49 -0700 Subject: [PATCH 05/11] review: propagate sharedness --- crates/wasmtime/src/runtime/type_registry.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/wasmtime/src/runtime/type_registry.rs b/crates/wasmtime/src/runtime/type_registry.rs index cc5d9b2bbc55..1c53b7ade03c 100644 --- a/crates/wasmtime/src/runtime/type_registry.rs +++ b/crates/wasmtime/src/runtime/type_registry.rs @@ -738,7 +738,7 @@ impl TypeRegistryInner { is_final: true, supertype: None, composite_type: wasmtime_environ::WasmCompositeType { - shared: false, // TODO: handle shared + shared: sub_ty.composite_type.shared, inner: wasmtime_environ::WasmCompositeInnerType::Func( trampoline.into_owned(), ), From ba799572b9825115d58e97d607e4e67dffcc88c9 Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Wed, 30 Oct 2024 11:53:41 -0700 Subject: [PATCH 06/11] review: fail if an unwrapped type is shared --- crates/cranelift/src/gc/enabled.rs | 62 +++++----------------- crates/cranelift/src/gc/enabled/drc.rs | 13 ++--- crates/environ/src/compile/module_types.rs | 47 ++++++++++++++-- 3 files changed, 61 insertions(+), 61 deletions(-) diff --git a/crates/cranelift/src/gc/enabled.rs b/crates/cranelift/src/gc/enabled.rs index 7aa34a017326..e2865e6593f3 100644 --- a/crates/cranelift/src/gc/enabled.rs +++ b/crates/cranelift/src/gc/enabled.rs @@ -11,8 +11,8 @@ use cranelift_entity::packed_option::ReservedValue; use cranelift_frontend::FunctionBuilder; use wasmtime_environ::{ GcArrayLayout, GcLayout, GcStructLayout, ModuleInternedTypeIndex, PtrSize, TypeIndex, VMGcKind, - WasmCompositeInnerType, WasmHeapTopType, WasmHeapType, WasmRefType, WasmResult, - WasmStorageType, WasmValType, I31_DISCRIMINANT, NON_NULL_NON_I31_MASK, + WasmHeapTopType, WasmHeapType, WasmRefType, WasmResult, WasmStorageType, WasmValType, + I31_DISCRIMINANT, NON_NULL_NON_I31_MASK, }; mod drc; @@ -252,10 +252,7 @@ pub fn translate_struct_new_default( struct_type_index: TypeIndex, ) -> WasmResult { let interned_ty = func_env.module.types[struct_type_index]; - let struct_ty = match &func_env.types[interned_ty].composite_type.inner { - WasmCompositeInnerType::Struct(s) => s, - _ => unreachable!(), - }; + let struct_ty = func_env.types.unwrap_struct(interned_ty)?; let fields = struct_ty .fields .iter() @@ -284,12 +281,7 @@ pub fn translate_struct_get( let struct_size_val = builder.ins().iconst(ir::types::I32, i64::from(struct_size)); let field_offset = struct_layout.fields[field_index]; - - let field_ty = match &func_env.types[interned_type_index].composite_type.inner { - WasmCompositeInnerType::Struct(s) => &s.fields[field_index], - _ => unreachable!(), - }; - + let field_ty = &func_env.types.unwrap_struct(interned_type_index)?.fields[field_index]; let field_size = wasmtime_environ::byte_size_of_wasm_ty_in_gc_heap(&field_ty.element_type); assert!(field_offset + field_size <= struct_size); @@ -322,12 +314,7 @@ fn translate_struct_get_and_extend( let struct_size_val = builder.ins().iconst(ir::types::I32, i64::from(struct_size)); let field_offset = struct_layout.fields[field_index]; - - let field_ty = match &func_env.types[interned_type_index].composite_type.inner { - WasmCompositeInnerType::Struct(s) => &s.fields[field_index], - _ => unreachable!(), - }; - + let field_ty = &func_env.types.unwrap_struct(interned_type_index)?.fields[field_index]; let field_size = wasmtime_environ::byte_size_of_wasm_ty_in_gc_heap(&field_ty.element_type); assert!(field_offset + field_size <= struct_size); @@ -400,12 +387,7 @@ pub fn translate_struct_set( let struct_size_val = builder.ins().iconst(ir::types::I32, i64::from(struct_size)); let field_offset = struct_layout.fields[field_index]; - - let field_ty = match &func_env.types[interned_type_index].composite_type.inner { - WasmCompositeInnerType::Struct(s) => &s.fields[field_index], - _ => unreachable!(), - }; - + let field_ty = &func_env.types.unwrap_struct(interned_type_index)?.fields[field_index]; let field_size = wasmtime_environ::byte_size_of_wasm_ty_in_gc_heap(&field_ty.element_type); assert!(field_offset + field_size <= struct_size); @@ -447,10 +429,7 @@ pub fn translate_array_new_default( len: ir::Value, ) -> WasmResult { let interned_ty = func_env.module.types[array_type_index]; - let WasmCompositeInnerType::Array(array_ty) = &func_env.types[interned_ty].composite_type.inner - else { - unreachable!() - }; + let array_ty = func_env.types.unwrap_array(interned_ty)?; let elem = default_value(&mut builder.cursor(), func_env, &array_ty.0.element_type); gc_compiler(func_env)?.alloc_array( func_env, @@ -597,10 +576,9 @@ pub fn translate_array_fill( one_elem_size, fill_end, |func_env, builder, elem_addr| { - let elem_ty = func_env.types[interned_type_index] - .composite_type - .inner - .unwrap_array() + let elem_ty = func_env + .types + .unwrap_array(interned_type_index)? .0 .element_type; write_field_at_addr(func_env, builder, elem_ty, elem_addr, value) @@ -765,10 +743,7 @@ pub fn translate_array_get( let array_type_index = func_env.module.types[array_type_index]; let elem_addr = array_elem_addr(func_env, builder, array_type_index, array_ref, index); - let array_ty = func_env.types[array_type_index] - .composite_type - .inner - .unwrap_array(); + let array_ty = func_env.types.unwrap_array(array_type_index)?; let elem_ty = array_ty.0.element_type; read_field_at_addr(func_env, builder, elem_ty, elem_addr, None) @@ -784,10 +759,7 @@ pub fn translate_array_get_s( let array_type_index = func_env.module.types[array_type_index]; let elem_addr = array_elem_addr(func_env, builder, array_type_index, array_ref, index); - let array_ty = func_env.types[array_type_index] - .composite_type - .inner - .unwrap_array(); + let array_ty = func_env.types.unwrap_array(array_type_index)?; let elem_ty = array_ty.0.element_type; read_field_at_addr(func_env, builder, elem_ty, elem_addr, Some(Extension::Sign)) @@ -803,10 +775,7 @@ pub fn translate_array_get_u( let array_type_index = func_env.module.types[array_type_index]; let elem_addr = array_elem_addr(func_env, builder, array_type_index, array_ref, index); - let array_ty = func_env.types[array_type_index] - .composite_type - .inner - .unwrap_array(); + let array_ty = func_env.types.unwrap_array(array_type_index)?; let elem_ty = array_ty.0.element_type; read_field_at_addr(func_env, builder, elem_ty, elem_addr, Some(Extension::Zero)) @@ -823,10 +792,7 @@ pub fn translate_array_set( let array_type_index = func_env.module.types[array_type_index]; let elem_addr = array_elem_addr(func_env, builder, array_type_index, array_ref, index); - let array_ty = func_env.types[array_type_index] - .composite_type - .inner - .unwrap_array(); + let array_ty = func_env.types.unwrap_array(array_type_index)?; let elem_ty = array_ty.0.element_type; write_field_at_addr(func_env, builder, elem_ty, elem_addr, value) diff --git a/crates/cranelift/src/gc/enabled/drc.rs b/crates/cranelift/src/gc/enabled/drc.rs index db53da6f1dd4..9a45d781a3ee 100644 --- a/crates/cranelift/src/gc/enabled/drc.rs +++ b/crates/cranelift/src/gc/enabled/drc.rs @@ -14,8 +14,7 @@ use cranelift_frontend::FunctionBuilder; use smallvec::SmallVec; use wasmtime_environ::{ drc::DrcTypeLayouts, GcArrayLayout, GcTypeLayouts, ModuleInternedTypeIndex, PtrSize, TypeIndex, - VMGcKind, WasmCompositeInnerType, WasmHeapTopType, WasmHeapType, WasmRefType, WasmResult, - WasmStorageType, WasmValType, + VMGcKind, WasmHeapTopType, WasmHeapType, WasmRefType, WasmResult, WasmStorageType, WasmValType, }; #[derive(Default)] @@ -413,10 +412,7 @@ impl GcCompiler for DrcCompiler { // Finally, initialize each of the newly-allocated array's elements. - let array_ty = func_env.types[interned_type_index] - .composite_type - .inner - .unwrap_array(); + let array_ty = func_env.types.unwrap_array(interned_type_index)?; let elem_ty = array_ty.0.element_type; let pointer_type = func_env.pointer_type(); @@ -494,10 +490,7 @@ impl GcCompiler for DrcCompiler { uextend_i32_to_pointer_type(builder, func_env.pointer_type(), struct_ref); let struct_addr = builder.ins().iadd(base, extended_struct_ref); - let struct_ty = match &func_env.types[interned_type_index].composite_type.inner { - WasmCompositeInnerType::Struct(s) => s, - _ => unreachable!(), - }; + let struct_ty = func_env.types.unwrap_struct(interned_type_index)?; let field_types: SmallVec<[_; 8]> = struct_ty.fields.iter().cloned().collect(); assert_eq!(field_vals.len(), field_types.len()); diff --git a/crates/environ/src/compile/module_types.rs b/crates/environ/src/compile/module_types.rs index 45aa2c5b6a69..508fafffd63b 100644 --- a/crates/environ/src/compile/module_types.rs +++ b/crates/environ/src/compile/module_types.rs @@ -1,7 +1,8 @@ use crate::{ - EngineOrModuleTypeIndex, EntityRef, ModuleInternedRecGroupIndex, ModuleInternedTypeIndex, - ModuleTypes, TypeConvert, TypeIndex, WasmCompositeInnerType, WasmCompositeType, WasmFuncType, - WasmHeapType, WasmResult, WasmSubType, + wasm_unsupported, EngineOrModuleTypeIndex, EntityRef, ModuleInternedRecGroupIndex, + ModuleInternedTypeIndex, ModuleTypes, TypeConvert, TypeIndex, WasmArrayType, + WasmCompositeInnerType, WasmCompositeType, WasmFuncType, WasmHeapType, WasmResult, + WasmStructType, WasmSubType, }; use std::{borrow::Cow, collections::HashMap, ops::Index}; use wasmparser::{UnpackedIndex, Validator, ValidatorId}; @@ -328,6 +329,46 @@ impl ModuleTypesBuilder { pub fn trampoline_type(&self, ty: ModuleInternedTypeIndex) -> ModuleInternedTypeIndex { self.types.trampoline_type(ty) } + + /// Get and unwrap a [`WasmStructType`] for the given struct index. + /// + /// # Panics + /// + /// Panics if the unwrapped type is not a struct. + /// + /// # Errors + /// + /// For now, fails with an unsupported error if the type is shared. + pub fn unwrap_struct(&self, ty: ModuleInternedTypeIndex) -> WasmResult<&WasmStructType> { + let composite_type = &self.types[ty].composite_type; + if composite_type.shared { + return Err(wasm_unsupported!("shared structs are not yet implemented")); + } + match &composite_type.inner { + WasmCompositeInnerType::Struct(s) => Ok(s), + _ => unreachable!(), + } + } + + /// Get and unwrap a [`WasmArrayType`] for the given array index. + /// + /// # Panics + /// + /// Panics if the unwrapped type is not an array. + /// + /// # Errors + /// + /// For now, fails with an unsupported error if the type is shared. + pub fn unwrap_array(&self, interned_ty: ModuleInternedTypeIndex) -> WasmResult<&WasmArrayType> { + let composite_type = &self.types[interned_ty].composite_type; + if composite_type.shared { + return Err(wasm_unsupported!("shared arrays are not yet implemented")); + } + match &composite_type.inner { + WasmCompositeInnerType::Array(a) => Ok(a), + _ => unreachable!(), + } + } } // Forward the indexing impl to the internal `ModuleTypes` From 057a4a57ae150120e4f1849ed70b436b776e8ac3 Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Wed, 30 Oct 2024 11:56:28 -0700 Subject: [PATCH 07/11] review: propagate sharedness more --- crates/environ/src/compile/module_types.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/crates/environ/src/compile/module_types.rs b/crates/environ/src/compile/module_types.rs index 508fafffd63b..8120c88bc4cf 100644 --- a/crates/environ/src/compile/module_types.rs +++ b/crates/environ/src/compile/module_types.rs @@ -141,7 +141,8 @@ impl ModuleTypesBuilder { &mut self, for_func_ty: ModuleInternedTypeIndex, ) -> ModuleInternedTypeIndex { - let trampoline = self.types[for_func_ty].unwrap_func().trampoline_type(); + let sub_ty = &self.types[for_func_ty]; + let trampoline = sub_ty.unwrap_func().trampoline_type(); if let Some(idx) = self.trampoline_types.get(&trampoline) { // We've already interned this trampoline type; reuse it. @@ -166,7 +167,7 @@ impl ModuleTypesBuilder { supertype: None, composite_type: WasmCompositeType { inner: WasmCompositeInnerType::Func(f.clone()), - shared: false, // TODO: handle shared + shared: sub_ty.composite_type.shared, }, }); From db6a977bff6ddc343884158b6018be435fe77d54 Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Wed, 30 Oct 2024 14:22:24 -0700 Subject: [PATCH 08/11] review: redefine accessors as unshared --- crates/environ/src/types.rs | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/crates/environ/src/types.rs b/crates/environ/src/types.rs index 26aba46caeb2..cd3a7155e8d7 100644 --- a/crates/environ/src/types.rs +++ b/crates/environ/src/types.rs @@ -1039,50 +1039,68 @@ impl fmt::Display for WasmSubType { } } +/// Implicitly define all of these helper functions to handle only unshared +/// types; essentially, these act like `is_unshared_*` functions until shared +/// support is implemented. #[allow(missing_docs)] impl WasmSubType { #[inline] pub fn is_func(&self) -> bool { - self.composite_type.inner.is_func() + self.composite_type.inner.is_func() && !self.composite_type.shared } #[inline] pub fn as_func(&self) -> Option<&WasmFuncType> { - self.composite_type.inner.as_func() + if self.composite_type.shared { + None + } else { + self.composite_type.inner.as_func() + } } #[inline] pub fn unwrap_func(&self) -> &WasmFuncType { + assert!(!self.composite_type.shared); self.composite_type.inner.unwrap_func() } #[inline] pub fn is_array(&self) -> bool { - self.composite_type.inner.is_array() + self.composite_type.inner.is_array() && !self.composite_type.shared } #[inline] pub fn as_array(&self) -> Option<&WasmArrayType> { - self.composite_type.inner.as_array() + if self.composite_type.shared { + None + } else { + self.composite_type.inner.as_array() + } } #[inline] pub fn unwrap_array(&self) -> &WasmArrayType { + assert!(!self.composite_type.shared); self.composite_type.inner.unwrap_array() } #[inline] pub fn is_struct(&self) -> bool { - self.composite_type.inner.is_struct() + self.composite_type.inner.is_struct() && !self.composite_type.shared } #[inline] pub fn as_struct(&self) -> Option<&WasmStructType> { - self.composite_type.inner.as_struct() + if self.composite_type.shared { + None + } else { + self.composite_type.inner.as_struct() + } } #[inline] pub fn unwrap_struct(&self) -> &WasmStructType { + assert!(!self.composite_type.shared); self.composite_type.inner.unwrap_struct() } } From bbce5951370310b55d32222f857791ca1881926a Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Wed, 30 Oct 2024 14:29:36 -0700 Subject: [PATCH 09/11] fix: add `DisabledLayouts` to satisfy `GcRuntime::layouts()` --- crates/wasmtime/src/runtime/vm/gc/disabled.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/crates/wasmtime/src/runtime/vm/gc/disabled.rs b/crates/wasmtime/src/runtime/vm/gc/disabled.rs index 245631605f0f..2afd7d6e1d38 100644 --- a/crates/wasmtime/src/runtime/vm/gc/disabled.rs +++ b/crates/wasmtime/src/runtime/vm/gc/disabled.rs @@ -23,6 +23,21 @@ unsafe impl GcRuntime for DisabledCollector { } fn layouts(&self) -> &dyn GcTypeLayouts { + &DisabledLayouts + } +} + +struct DisabledLayouts; +impl GcTypeLayouts for DisabledLayouts { + fn array_length_field_offset(&self) -> u32 { + unreachable!() + } + + fn array_layout(&self, _: &WasmArrayType) -> GcArrayLayout { + unreachable!() + } + + fn struct_layout(&self, _: &WasmStructType) -> GcStructLayout { unreachable!() } } From fbc4c24d7be1b6959fe7266d2f9149bb8420458e Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Wed, 30 Oct 2024 14:31:39 -0700 Subject: [PATCH 10/11] review: panic on shared --- crates/environ/src/compile/module_types.rs | 4 ++++ crates/environ/src/gc.rs | 1 + 2 files changed, 5 insertions(+) diff --git a/crates/environ/src/compile/module_types.rs b/crates/environ/src/compile/module_types.rs index 8120c88bc4cf..b8c32f7fe8c7 100644 --- a/crates/environ/src/compile/module_types.rs +++ b/crates/environ/src/compile/module_types.rs @@ -433,6 +433,7 @@ where // array vs struct vs func reference. In this case, we can use // the validator's type context. if let Some(ty) = self.types.types.get(interned) { + assert!(!ty.composite_type.shared); match &ty.composite_type.inner { WasmCompositeInnerType::Array(_) => WasmHeapType::ConcreteArray(index), WasmCompositeInnerType::Func(_) => WasmHeapType::ConcreteFunc(index), @@ -440,6 +441,7 @@ where } } else if let Some((wasmparser_types, _)) = self.rec_group_context.as_ref() { let wasmparser_ty = &wasmparser_types[id].composite_type; + assert!(!wasmparser_ty.shared); match &wasmparser_ty.inner { wasmparser::CompositeInnerType::Array(_) => { WasmHeapType::ConcreteArray(index) @@ -470,6 +472,7 @@ where // indirectly get one by looking it up inside the current rec // group. if let Some(ty) = self.types.types.get(interned) { + assert!(!ty.composite_type.shared); match &ty.composite_type.inner { WasmCompositeInnerType::Array(_) => WasmHeapType::ConcreteArray(index), WasmCompositeInnerType::Func(_) => WasmHeapType::ConcreteFunc(index), @@ -482,6 +485,7 @@ where .nth(rec_group_index) .unwrap(); let wasmparser_ty = &parser_types[id].composite_type; + assert!(!wasmparser_ty.shared); match &wasmparser_ty.inner { wasmparser::CompositeInnerType::Array(_) => { WasmHeapType::ConcreteArray(index) diff --git a/crates/environ/src/gc.rs b/crates/environ/src/gc.rs index 52f6258b16fc..40faa3076056 100644 --- a/crates/environ/src/gc.rs +++ b/crates/environ/src/gc.rs @@ -66,6 +66,7 @@ pub trait GcTypeLayouts { /// Returns `None` if the type is a function type, as functions are not /// managed by the GC. fn gc_layout(&self, ty: &WasmCompositeType) -> Option { + assert!(!ty.shared); match &ty.inner { WasmCompositeInnerType::Array(ty) => Some(self.array_layout(ty).into()), WasmCompositeInnerType::Struct(ty) => Some(self.struct_layout(ty).into()), From 7ef7722f7a01383e14ba9e6756af679ebb7d1842 Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Fri, 1 Nov 2024 17:09:40 -0700 Subject: [PATCH 11/11] review: remove unnecessary assert --- crates/environ/src/types.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/environ/src/types.rs b/crates/environ/src/types.rs index cd3a7155e8d7..677ee0d2224e 100644 --- a/crates/environ/src/types.rs +++ b/crates/environ/src/types.rs @@ -1890,7 +1890,6 @@ pub trait TypeConvert { } fn convert_composite_type(&self, ty: &wasmparser::CompositeType) -> WasmCompositeType { - assert!(!ty.shared); let inner = match &ty.inner { wasmparser::CompositeInnerType::Func(f) => { WasmCompositeInnerType::Func(self.convert_func_type(f))