Skip to content

Commit 64f3ada

Browse files
lannalexcrichton
andauthored
Remove union types (#1180)
* Fix formatting for Rust 1.72.0 * Remove union types --------- Co-authored-by: Alex Crichton <alex@alexcrichton.com>
1 parent 6d05053 commit 64f3ada

File tree

67 files changed

+318
-773
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+318
-773
lines changed

crates/wasm-compose/src/encoding.rs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,6 @@ impl<'a> TypeEncoder<'a> {
702702
wasmparser::types::ComponentDefinedType::Enum(cases) => {
703703
Self::enum_type(&mut state.cur.encodable, cases)
704704
}
705-
wasmparser::types::ComponentDefinedType::Union(u) => self.union(state, u),
706705
wasmparser::types::ComponentDefinedType::Option(ty) => self.option(state, *ty),
707706
wasmparser::types::ComponentDefinedType::Result { ok, err } => {
708707
self.result(state, *ok, *err)
@@ -789,18 +788,6 @@ impl<'a> TypeEncoder<'a> {
789788
index
790789
}
791790

792-
fn union(&self, state: &mut TypeState<'a>, union: &wasmparser::types::UnionType) -> u32 {
793-
let types = union
794-
.types
795-
.iter()
796-
.map(|ty| self.component_val_type(state, *ty))
797-
.collect::<Vec<_>>();
798-
799-
let index = state.cur.encodable.type_count();
800-
state.cur.encodable.ty().defined_type().union(types);
801-
index
802-
}
803-
804791
fn option(&self, state: &mut TypeState<'a>, ty: wasmparser::types::ComponentValType) -> u32 {
805792
let ty = self.component_val_type(state, ty);
806793

@@ -1297,11 +1284,6 @@ impl DependencyRegistrar<'_, '_> {
12971284
}
12981285
}
12991286
}
1300-
types::ComponentDefinedType::Union(r) => {
1301-
for ty in r.types.iter() {
1302-
self.val_type(*ty);
1303-
}
1304-
}
13051287
types::ComponentDefinedType::Result { ok, err } => {
13061288
if let Some(ok) = ok {
13071289
self.val_type(*ok);

crates/wasm-compose/tests/compositions/complex-import/composed.wat

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@
6363
(export (;24;) "enum1" (type (eq 23)))
6464
(type (;25;) (func (param "x" 24)))
6565
(export (;17;) "r" (func (type 25)))
66-
(type (;26;) (union s8 string 14))
67-
(export (;27;) "union1" (type (eq 26)))
66+
(type (;26;) (option 14))
67+
(export (;27;) "option1" (type (eq 26)))
6868
(type (;28;) (func (param "x" 27)))
6969
(export (;18;) "s" (func (type 28)))
7070
(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)))
@@ -96,8 +96,8 @@
9696
(export (;3;) "flags1" (type (eq 2)))
9797
(type (;4;) (enum "a" "b" "c"))
9898
(export (;5;) "enum1" (type (eq 4)))
99-
(type (;6;) (union s8 string 1))
100-
(export (;7;) "union1" (type (eq 6)))
99+
(type (;6;) (option 1))
100+
(export (;7;) "option1" (type (eq 6)))
101101
(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)))
102102
(export (;9;) "variant1" (type (eq 8)))
103103
(type (;10;) (func))

crates/wasm-compose/tests/compositions/complex/a.wat

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
(type $t21' (enum "a" "b" "c"))
2626
(export $t21 "enum1" (type $t21'))
2727
(type $t22 (func (param "x" $t21)))
28-
(type $t23' (union s8 string $t13))
29-
(export $t23 "union1" (type $t23'))
28+
(type $t23' (option $t13))
29+
(export $t23 "option1" (type $t23'))
3030
(type $t24 (func (param "x" $t23)))
3131
(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)))
3232
(export $t25 "variant1" (type $t25'))

crates/wasm-compose/tests/compositions/complex/b.wat

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@
4545
(export $t5 "enum1" (type (eq $t5')))
4646
(type $f18 (func (param "x" $t5)))
4747
(export "r" (func (type $f18)))
48-
(type $t6' (union s8 string $t1))
49-
(export $t6 "union1" (type (eq $t6')))
48+
(type $t6' (option $t1))
49+
(export $t6 "option1" (type (eq $t6')))
5050
(type $f19 (func (param "x" $t6)))
5151
(export "s" (func (type $f19)))
5252
(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)))

crates/wasm-compose/tests/compositions/complex/composed.wat

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@
6060
(export (;24;) "enum1" (type (eq 23)))
6161
(type (;25;) (func (param "x" 24)))
6262
(export (;17;) "r" (func (type 25)))
63-
(type (;26;) (union s8 string 14))
64-
(export (;27;) "union1" (type (eq 26)))
63+
(type (;26;) (option 14))
64+
(export (;27;) "option1" (type (eq 26)))
6565
(type (;28;) (func (param "x" 27)))
6666
(export (;18;) "s" (func (type 28)))
6767
(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)))
@@ -344,8 +344,8 @@
344344
(type $t21' (;23;) (enum "a" "b" "c"))
345345
(export $t21 (;24;) "enum1" (type $t21'))
346346
(type $t22 (;25;) (func (param "x" $t21)))
347-
(type $t23' (;26;) (union s8 string $t13))
348-
(export $t23 (;27;) "union1" (type $t23'))
347+
(type $t23' (;26;) (option $t13))
348+
(export $t23 (;27;) "option1" (type $t23'))
349349
(type $t24 (;28;) (func (param "x" $t23)))
350350
(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)))
351351
(export $t25 (;30;) "variant1" (type $t25'))

crates/wasm-encoder/src/component/types.rs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -642,21 +642,6 @@ impl ComponentDefinedTypeEncoder<'_> {
642642
}
643643
}
644644

645-
/// Define a union type.
646-
pub fn union<I, T>(self, types: I)
647-
where
648-
I: IntoIterator<Item = T>,
649-
I::IntoIter: ExactSizeIterator,
650-
T: Into<ComponentValType>,
651-
{
652-
let types = types.into_iter();
653-
self.0.push(0x6C);
654-
types.len().encode(self.0);
655-
for ty in types {
656-
ty.into().encode(self.0);
657-
}
658-
}
659-
660645
/// Define an option type.
661646
pub fn option(self, ty: impl Into<ComponentValType>) {
662647
self.0.push(0x6B);

crates/wasm-smith/src/component.rs

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1453,20 +1453,6 @@ impl ComponentBuilder {
14531453
Ok(EnumType { variants })
14541454
}
14551455

1456-
fn arbitrary_union_type(&self, u: &mut Unstructured, type_fuel: &mut u32) -> Result<UnionType> {
1457-
let mut variants = vec![];
1458-
arbitrary_loop(u, 1, 100, |u| {
1459-
*type_fuel = type_fuel.saturating_sub(1);
1460-
if *type_fuel == 0 {
1461-
return Ok(false);
1462-
}
1463-
1464-
variants.push(self.arbitrary_component_val_type(u)?);
1465-
Ok(true)
1466-
})?;
1467-
Ok(UnionType { variants })
1468-
}
1469-
14701456
fn arbitrary_option_type(&self, u: &mut Unstructured) -> Result<OptionType> {
14711457
Ok(OptionType {
14721458
inner_ty: self.arbitrary_component_val_type(u)?,
@@ -1491,7 +1477,7 @@ impl ComponentBuilder {
14911477
u: &mut Unstructured,
14921478
type_fuel: &mut u32,
14931479
) -> Result<DefinedType> {
1494-
match u.int_in_range(0..=9)? {
1480+
match u.int_in_range(0..=8)? {
14951481
0 => Ok(DefinedType::Primitive(
14961482
self.arbitrary_primitive_val_type(u)?,
14971483
)),
@@ -1505,9 +1491,8 @@ impl ComponentBuilder {
15051491
4 => Ok(DefinedType::Tuple(self.arbitrary_tuple_type(u, type_fuel)?)),
15061492
5 => Ok(DefinedType::Flags(self.arbitrary_flags_type(u, type_fuel)?)),
15071493
6 => Ok(DefinedType::Enum(self.arbitrary_enum_type(u, type_fuel)?)),
1508-
7 => Ok(DefinedType::Union(self.arbitrary_union_type(u, type_fuel)?)),
1509-
8 => Ok(DefinedType::Option(self.arbitrary_option_type(u)?)),
1510-
9 => Ok(DefinedType::Result(self.arbitrary_result_type(u)?)),
1494+
7 => Ok(DefinedType::Option(self.arbitrary_option_type(u)?)),
1495+
8 => Ok(DefinedType::Result(self.arbitrary_result_type(u)?)),
15111496
_ => unreachable!(),
15121497
}
15131498
}
@@ -2120,7 +2105,6 @@ enum DefinedType {
21202105
Tuple(TupleType),
21212106
Flags(FlagsType),
21222107
Enum(EnumType),
2123-
Union(UnionType),
21242108
Option(OptionType),
21252109
Result(ResultType),
21262110
}
@@ -2155,11 +2139,6 @@ struct EnumType {
21552139
variants: Vec<KebabString>,
21562140
}
21572141

2158-
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
2159-
struct UnionType {
2160-
variants: Vec<ComponentValType>,
2161-
}
2162-
21632142
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
21642143
struct OptionType {
21652144
inner_ty: ComponentValType,

crates/wasm-smith/src/component/encode.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,9 +251,6 @@ impl DefinedType {
251251
Self::Enum(ty) => {
252252
enc.enum_type(ty.variants.iter().map(|v| v.as_str()));
253253
}
254-
Self::Union(ty) => {
255-
enc.union(ty.variants.iter().copied());
256-
}
257254
Self::Option(ty) => {
258255
enc.option(ty.inner_ty);
259256
}

crates/wasmparser/src/limits.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ pub const MAX_WASM_VARIANT_CASES: usize = 1000;
4747
pub const MAX_WASM_TUPLE_TYPES: usize = 1000;
4848
pub const MAX_WASM_FLAG_NAMES: usize = 1000;
4949
pub const MAX_WASM_ENUM_CASES: usize = 1000;
50-
pub const MAX_WASM_UNION_TYPES: usize = 1000;
5150
pub const MAX_WASM_INSTANTIATION_EXPORTS: usize = 100_000;
5251
pub const MAX_WASM_CANONICAL_OPTIONS: usize = 10;
5352
pub const MAX_WASM_INSTANTIATION_ARGS: usize = 100_000;

crates/wasmparser/src/readers/component/types.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -470,8 +470,6 @@ pub enum ComponentDefinedType<'a> {
470470
Flags(Box<[&'a str]>),
471471
/// The type is an enum with the given tags.
472472
Enum(Box<[&'a str]>),
473-
/// The type is a union of the given value types.
474-
Union(Box<[ComponentValType]>),
475473
/// The type is an option of the given value type.
476474
Option(ComponentValType),
477475
/// The type is a result type.
@@ -516,11 +514,7 @@ impl<'a> ComponentDefinedType<'a> {
516514
.read_iter(MAX_WASM_ENUM_CASES, "enum cases")?
517515
.collect::<Result<_>>()?,
518516
),
519-
0x6c => ComponentDefinedType::Union(
520-
reader
521-
.read_iter(MAX_WASM_UNION_TYPES, "union types")?
522-
.collect::<Result<_>>()?,
523-
),
517+
// NOTE: 0x6c (union) removed
524518
0x6b => ComponentDefinedType::Option(reader.read()?),
525519
0x6a => ComponentDefinedType::Result {
526520
ok: reader.read()?,

0 commit comments

Comments
 (0)