Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 0 additions & 18 deletions crates/wasm-compose/src/encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,6 @@ impl<'a> TypeEncoder<'a> {
wasmparser::types::ComponentDefinedType::Enum(cases) => {
Self::enum_type(&mut state.cur.encodable, cases)
}
wasmparser::types::ComponentDefinedType::Union(u) => self.union(state, u),
wasmparser::types::ComponentDefinedType::Option(ty) => self.option(state, *ty),
wasmparser::types::ComponentDefinedType::Result { ok, err } => {
self.result(state, *ok, *err)
Expand Down Expand Up @@ -789,18 +788,6 @@ impl<'a> TypeEncoder<'a> {
index
}

fn union(&self, state: &mut TypeState<'a>, union: &wasmparser::types::UnionType) -> u32 {
let types = union
.types
.iter()
.map(|ty| self.component_val_type(state, *ty))
.collect::<Vec<_>>();

let index = state.cur.encodable.type_count();
state.cur.encodable.ty().defined_type().union(types);
index
}

fn option(&self, state: &mut TypeState<'a>, ty: wasmparser::types::ComponentValType) -> u32 {
let ty = self.component_val_type(state, ty);

Expand Down Expand Up @@ -1297,11 +1284,6 @@ impl DependencyRegistrar<'_, '_> {
}
}
}
types::ComponentDefinedType::Union(r) => {
for ty in r.types.iter() {
self.val_type(*ty);
}
}
types::ComponentDefinedType::Result { ok, err } => {
if let Some(ok) = ok {
self.val_type(*ok);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@
(export (;24;) "enum1" (type (eq 23)))
(type (;25;) (func (param "x" 24)))
(export (;17;) "r" (func (type 25)))
(type (;26;) (union s8 string 14))
(export (;27;) "union1" (type (eq 26)))
(type (;26;) (option 14))
(export (;27;) "option1" (type (eq 26)))
(type (;28;) (func (param "x" 27)))
(export (;18;) "s" (func (type 28)))
(type (;29;) (variant (case "a" s8) (case "b" u8) (case "c" s16) (case "d" u16) (case "e" s32) (case "f" u32) (case "g" s64) (case "h" u64) (case "i" float32) (case "j" float64) (case "k" bool) (case "l" string) (case "m" 14)))
Expand Down Expand Up @@ -96,8 +96,8 @@
(export (;3;) "flags1" (type (eq 2)))
(type (;4;) (enum "a" "b" "c"))
(export (;5;) "enum1" (type (eq 4)))
(type (;6;) (union s8 string 1))
(export (;7;) "union1" (type (eq 6)))
(type (;6;) (option 1))
(export (;7;) "option1" (type (eq 6)))
(type (;8;) (variant (case "a" s8) (case "b" u8) (case "c" s16) (case "d" u16) (case "e" s32) (case "f" u32) (case "g" s64) (case "h" u64) (case "i" float32) (case "j" float64) (case "k" bool) (case "l" string) (case "m" 1)))
(export (;9;) "variant1" (type (eq 8)))
(type (;10;) (func))
Expand Down
4 changes: 2 additions & 2 deletions crates/wasm-compose/tests/compositions/complex/a.wat
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
(type $t21' (enum "a" "b" "c"))
(export $t21 "enum1" (type $t21'))
(type $t22 (func (param "x" $t21)))
(type $t23' (union s8 string $t13))
(export $t23 "union1" (type $t23'))
(type $t23' (option $t13))
(export $t23 "option1" (type $t23'))
(type $t24 (func (param "x" $t23)))
(type $t25' (variant (case "a" s8) (case "b" u8) (case "c" s16) (case "d" u16) (case "e" s32) (case "f" u32) (case "g" s64) (case "h" u64) (case "i" float32) (case "j" float64) (case "k" bool) (case "l" string) (case "m" $t13)))
(export $t25 "variant1" (type $t25'))
Expand Down
4 changes: 2 additions & 2 deletions crates/wasm-compose/tests/compositions/complex/b.wat
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
(export $t5 "enum1" (type (eq $t5')))
(type $f18 (func (param "x" $t5)))
(export "r" (func (type $f18)))
(type $t6' (union s8 string $t1))
(export $t6 "union1" (type (eq $t6')))
(type $t6' (option $t1))
(export $t6 "option1" (type (eq $t6')))
(type $f19 (func (param "x" $t6)))
(export "s" (func (type $f19)))
(type $t7' (variant (case "a" s8) (case "b" u8) (case "c" s16) (case "d" u16) (case "e" s32) (case "f" u32) (case "g" s64) (case "h" u64) (case "i" float32) (case "j" float64) (case "k" bool) (case "l" string) (case "m" $t1)))
Expand Down
8 changes: 4 additions & 4 deletions crates/wasm-compose/tests/compositions/complex/composed.wat
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@
(export (;24;) "enum1" (type (eq 23)))
(type (;25;) (func (param "x" 24)))
(export (;17;) "r" (func (type 25)))
(type (;26;) (union s8 string 14))
(export (;27;) "union1" (type (eq 26)))
(type (;26;) (option 14))
(export (;27;) "option1" (type (eq 26)))
(type (;28;) (func (param "x" 27)))
(export (;18;) "s" (func (type 28)))
(type (;29;) (variant (case "a" s8) (case "b" u8) (case "c" s16) (case "d" u16) (case "e" s32) (case "f" u32) (case "g" s64) (case "h" u64) (case "i" float32) (case "j" float64) (case "k" bool) (case "l" string) (case "m" 14)))
Expand Down Expand Up @@ -344,8 +344,8 @@
(type $t21' (;23;) (enum "a" "b" "c"))
(export $t21 (;24;) "enum1" (type $t21'))
(type $t22 (;25;) (func (param "x" $t21)))
(type $t23' (;26;) (union s8 string $t13))
(export $t23 (;27;) "union1" (type $t23'))
(type $t23' (;26;) (option $t13))
(export $t23 (;27;) "option1" (type $t23'))
(type $t24 (;28;) (func (param "x" $t23)))
(type $t25' (;29;) (variant (case "a" s8) (case "b" u8) (case "c" s16) (case "d" u16) (case "e" s32) (case "f" u32) (case "g" s64) (case "h" u64) (case "i" float32) (case "j" float64) (case "k" bool) (case "l" string) (case "m" $t13)))
(export $t25 (;30;) "variant1" (type $t25'))
Expand Down
15 changes: 0 additions & 15 deletions crates/wasm-encoder/src/component/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -642,21 +642,6 @@ impl ComponentDefinedTypeEncoder<'_> {
}
}

/// Define a union type.
pub fn union<I, T>(self, types: I)
where
I: IntoIterator<Item = T>,
I::IntoIter: ExactSizeIterator,
T: Into<ComponentValType>,
{
let types = types.into_iter();
self.0.push(0x6C);
types.len().encode(self.0);
for ty in types {
ty.into().encode(self.0);
}
}

/// Define an option type.
pub fn option(self, ty: impl Into<ComponentValType>) {
self.0.push(0x6B);
Expand Down
27 changes: 3 additions & 24 deletions crates/wasm-smith/src/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1453,20 +1453,6 @@ impl ComponentBuilder {
Ok(EnumType { variants })
}

fn arbitrary_union_type(&self, u: &mut Unstructured, type_fuel: &mut u32) -> Result<UnionType> {
let mut variants = vec![];
arbitrary_loop(u, 1, 100, |u| {
*type_fuel = type_fuel.saturating_sub(1);
if *type_fuel == 0 {
return Ok(false);
}

variants.push(self.arbitrary_component_val_type(u)?);
Ok(true)
})?;
Ok(UnionType { variants })
}

fn arbitrary_option_type(&self, u: &mut Unstructured) -> Result<OptionType> {
Ok(OptionType {
inner_ty: self.arbitrary_component_val_type(u)?,
Expand All @@ -1491,7 +1477,7 @@ impl ComponentBuilder {
u: &mut Unstructured,
type_fuel: &mut u32,
) -> Result<DefinedType> {
match u.int_in_range(0..=9)? {
match u.int_in_range(0..=8)? {
0 => Ok(DefinedType::Primitive(
self.arbitrary_primitive_val_type(u)?,
)),
Expand All @@ -1505,9 +1491,8 @@ impl ComponentBuilder {
4 => Ok(DefinedType::Tuple(self.arbitrary_tuple_type(u, type_fuel)?)),
5 => Ok(DefinedType::Flags(self.arbitrary_flags_type(u, type_fuel)?)),
6 => Ok(DefinedType::Enum(self.arbitrary_enum_type(u, type_fuel)?)),
7 => Ok(DefinedType::Union(self.arbitrary_union_type(u, type_fuel)?)),
8 => Ok(DefinedType::Option(self.arbitrary_option_type(u)?)),
9 => Ok(DefinedType::Result(self.arbitrary_result_type(u)?)),
7 => Ok(DefinedType::Option(self.arbitrary_option_type(u)?)),
8 => Ok(DefinedType::Result(self.arbitrary_result_type(u)?)),
_ => unreachable!(),
}
}
Expand Down Expand Up @@ -2120,7 +2105,6 @@ enum DefinedType {
Tuple(TupleType),
Flags(FlagsType),
Enum(EnumType),
Union(UnionType),
Option(OptionType),
Result(ResultType),
}
Expand Down Expand Up @@ -2155,11 +2139,6 @@ struct EnumType {
variants: Vec<KebabString>,
}

#[derive(Clone, Debug, PartialEq, Eq, Hash)]
struct UnionType {
variants: Vec<ComponentValType>,
}

#[derive(Clone, Debug, PartialEq, Eq, Hash)]
struct OptionType {
inner_ty: ComponentValType,
Expand Down
3 changes: 0 additions & 3 deletions crates/wasm-smith/src/component/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,6 @@ impl DefinedType {
Self::Enum(ty) => {
enc.enum_type(ty.variants.iter().map(|v| v.as_str()));
}
Self::Union(ty) => {
enc.union(ty.variants.iter().copied());
}
Self::Option(ty) => {
enc.option(ty.inner_ty);
}
Expand Down
1 change: 0 additions & 1 deletion crates/wasmparser/src/limits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ pub const MAX_WASM_VARIANT_CASES: usize = 1000;
pub const MAX_WASM_TUPLE_TYPES: usize = 1000;
pub const MAX_WASM_FLAG_NAMES: usize = 1000;
pub const MAX_WASM_ENUM_CASES: usize = 1000;
pub const MAX_WASM_UNION_TYPES: usize = 1000;
pub const MAX_WASM_INSTANTIATION_EXPORTS: usize = 100_000;
pub const MAX_WASM_CANONICAL_OPTIONS: usize = 10;
pub const MAX_WASM_INSTANTIATION_ARGS: usize = 100_000;
Expand Down
8 changes: 1 addition & 7 deletions crates/wasmparser/src/readers/component/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -470,8 +470,6 @@ pub enum ComponentDefinedType<'a> {
Flags(Box<[&'a str]>),
/// The type is an enum with the given tags.
Enum(Box<[&'a str]>),
/// The type is a union of the given value types.
Union(Box<[ComponentValType]>),
/// The type is an option of the given value type.
Option(ComponentValType),
/// The type is a result type.
Expand Down Expand Up @@ -516,11 +514,7 @@ impl<'a> ComponentDefinedType<'a> {
.read_iter(MAX_WASM_ENUM_CASES, "enum cases")?
.collect::<Result<_>>()?,
),
0x6c => ComponentDefinedType::Union(
reader
.read_iter(MAX_WASM_UNION_TYPES, "union types")?
.collect::<Result<_>>()?,
),
// NOTE: 0x6c (union) removed
0x6b => ComponentDefinedType::Option(reader.read()?),
0x6a => ComponentDefinedType::Result {
ok: reader.read()?,
Expand Down
30 changes: 1 addition & 29 deletions crates/wasmparser/src/validator/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::{
limits::*,
types::{
ComponentDefinedType, ComponentEntityType, Context, InstanceTypeKind, LoweringInfo, Remap,
SubtypeCx, TupleType, TypeInfo, UnionType, VariantType,
SubtypeCx, TupleType, TypeInfo, VariantType,
},
BinaryReaderError, CanonicalOption, ComponentExternName, ComponentExternalKind,
ComponentOuterAliasKind, ComponentTypeRef, ExternalKind, FuncType, GlobalType,
Expand Down Expand Up @@ -662,9 +662,6 @@ impl ComponentState {
ComponentDefinedType::Tuple(r) => {
r.types.iter().all(|t| types.type_named_valtype(t, set))
}
ComponentDefinedType::Union(r) => {
r.types.iter().all(|t| types.type_named_valtype(t, set))
}
ComponentDefinedType::Variant(r) => r
.cases
.values()
Expand Down Expand Up @@ -2456,9 +2453,6 @@ impl ComponentState {
crate::ComponentDefinedType::Enum(cases) => {
self.create_enum_type(cases.as_ref(), offset)
}
crate::ComponentDefinedType::Union(tys) => {
self.create_union_type(tys.as_ref(), types, offset)
}
crate::ComponentDefinedType::Option(ty) => Ok(ComponentDefinedType::Option(
self.create_component_val_type(ty, types, offset)?,
)),
Expand Down Expand Up @@ -2653,28 +2647,6 @@ impl ComponentState {
Ok(ComponentDefinedType::Enum(tags))
}

fn create_union_type(
&self,
tys: &[crate::ComponentValType],
types: &TypeList,
offset: usize,
) -> Result<ComponentDefinedType> {
let mut info = TypeInfo::new();
if tys.is_empty() {
bail!(offset, "union type must have at least one case");
}
let types = tys
.iter()
.map(|ty| {
let ty = self.create_component_val_type(*ty, types, offset)?;
info.combine(ty.info(), offset)?;
Ok(ty)
})
.collect::<Result<_>>()?;

Ok(ComponentDefinedType::Union(UnionType { info, types }))
}

fn create_component_val_type(
&self,
ty: crate::ComponentValType,
Expand Down
Loading