Skip to content

Commit a92516b

Browse files
authored
Remove support for variant refines (#2432)
* Remove support for variant `refines` This was removed from the component model specification a long time ago and wasm-tools never caught up. Purge the tests and implementation support for it as it's not needed. * More fixes
1 parent 037cce4 commit a92516b

18 files changed

Lines changed: 66 additions & 249 deletions

File tree

crates/wasm-compose/src/encoding.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -702,9 +702,6 @@ impl<'a> TypeEncoder<'a> {
702702
(
703703
n.as_str(),
704704
c.ty.map(|ty| self.component_val_type(state, ty)),
705-
c.refines
706-
.as_deref()
707-
.map(|r| variant.cases.iter().position(|(n, _)| n == r).unwrap() as u32),
708705
)
709706
})
710707
.collect::<Vec<_>>();

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -601,16 +601,16 @@ impl ComponentDefinedTypeEncoder<'_> {
601601
/// Define a variant type.
602602
pub fn variant<'a, C>(self, cases: C)
603603
where
604-
C: IntoIterator<Item = (&'a str, Option<ComponentValType>, Option<u32>)>,
604+
C: IntoIterator<Item = (&'a str, Option<ComponentValType>)>,
605605
C::IntoIter: ExactSizeIterator,
606606
{
607607
let cases = cases.into_iter();
608608
self.0.push(0x71);
609609
cases.len().encode(self.0);
610-
for (name, ty, refines) in cases {
610+
for (name, ty) in cases {
611611
name.encode(self.0);
612612
ty.encode(self.0);
613-
refines.encode(self.0);
613+
self.0.push(0x00);
614614
}
615615
}
616616

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -758,13 +758,10 @@ pub mod component_utils {
758758
);
759759
}
760760
wasmparser::ComponentDefinedType::Variant(v) => {
761-
defined.variant(v.iter().map(|case| {
762-
(
763-
case.name,
764-
case.ty.map(|t| reencoder.component_val_type(t)),
765-
case.refines,
766-
)
767-
}));
761+
defined.variant(
762+
v.iter()
763+
.map(|case| (case.name, case.ty.map(|t| reencoder.component_val_type(t)))),
764+
);
768765
}
769766
wasmparser::ComponentDefinedType::List(t) => {
770767
defined.list(reencoder.component_val_type(t));

crates/wasm-smith/src/component.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1367,14 +1367,7 @@ impl ComponentBuilder {
13671367
.then(|| self.arbitrary_component_val_type(u))
13681368
.transpose()?;
13691369

1370-
let refines = if !cases.is_empty() && u.arbitrary()? {
1371-
let max_cases = u32::try_from(cases.len() - 1).unwrap();
1372-
Some(u.int_in_range(0..=max_cases)?)
1373-
} else {
1374-
None
1375-
};
1376-
1377-
cases.push((name, ty, refines));
1370+
cases.push((name, ty));
13781371
Ok(true)
13791372
})?;
13801373

@@ -2093,7 +2086,7 @@ struct RecordType {
20932086

20942087
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
20952088
struct VariantType {
2096-
cases: Vec<(String, Option<ComponentValType>, Option<u32>)>,
2089+
cases: Vec<(String, Option<ComponentValType>)>,
20972090
}
20982091

20992092
#[derive(Clone, Debug, PartialEq, Eq, Hash)]

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -229,11 +229,7 @@ impl DefinedType {
229229
enc.record(ty.fields.iter().map(|(name, ty)| (name.as_str(), *ty)));
230230
}
231231
Self::Variant(ty) => {
232-
enc.variant(
233-
ty.cases
234-
.iter()
235-
.map(|(name, ty, refines)| (name.as_str(), *ty, *refines)),
236-
);
232+
enc.variant(ty.cases.iter().map(|(name, ty)| (name.as_str(), *ty)));
237233
}
238234
Self::List(ty) => {
239235
enc.list(ty.elem_ty);

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

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -417,21 +417,17 @@ pub struct VariantCase<'a> {
417417
pub name: &'a str,
418418
/// The value type of the variant case.
419419
pub ty: Option<ComponentValType>,
420-
/// The index of the variant case that is refined by this one.
421-
pub refines: Option<u32>,
422420
}
423421

424422
impl<'a> FromReader<'a> for VariantCase<'a> {
425423
fn from_reader(reader: &mut BinaryReader<'a>) -> Result<Self> {
426-
Ok(VariantCase {
427-
name: reader.read()?,
428-
ty: reader.read()?,
429-
refines: match reader.read_u8()? {
430-
0x0 => None,
431-
0x1 => Some(reader.read_var_u32()?),
432-
x => return reader.invalid_leading_byte(x, "variant case refines"),
433-
},
434-
})
424+
let name = reader.read()?;
425+
let ty = reader.read()?;
426+
match reader.read_u8()? {
427+
0x0 => {}
428+
x => return reader.invalid_leading_byte(x, "zero byte required"),
429+
}
430+
Ok(VariantCase { name, ty })
435431
}
436432
}
437433

crates/wasmparser/src/validator/component.rs

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4058,16 +4058,7 @@ impl ComponentState {
40584058
));
40594059
}
40604060

4061-
for (i, case) in cases.iter().enumerate() {
4062-
if let Some(refines) = case.refines {
4063-
if refines >= i as u32 {
4064-
return Err(BinaryReaderError::new(
4065-
"variant case can only refine a previously defined case",
4066-
offset,
4067-
));
4068-
}
4069-
}
4070-
4061+
for case in cases {
40714062
let name = to_kebab_str(case.name, "variant case", offset)?;
40724063

40734064
let ty = case
@@ -4086,15 +4077,7 @@ impl ComponentState {
40864077
if let Some(ty) = ty {
40874078
info.combine(ty.info(types), offset)?;
40884079
}
4089-
4090-
// Safety: the use of `KebabStr::new_unchecked` here is safe because the string
4091-
// was already verified to be kebab case.
4092-
e.insert(VariantCase {
4093-
ty,
4094-
refines: case
4095-
.refines
4096-
.map(|i| KebabStr::new_unchecked(cases[i as usize].name).to_owned()),
4097-
});
4080+
e.insert(VariantCase { ty });
40984081
}
40994082
}
41004083
}

crates/wasmparser/src/validator/component_types.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1346,8 +1346,6 @@ impl ComponentFuncType {
13461346
pub struct VariantCase {
13471347
/// The variant case type.
13481348
pub ty: Option<ComponentValType>,
1349-
/// The name of the variant case refined by this one.
1350-
pub refines: Option<KebabString>,
13511349
}
13521350

13531351
/// Represents a record type.

crates/wasmprinter/src/component.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,6 @@ impl Printer<'_, '_> {
145145
self.print_component_val_type(state, &ty)?;
146146
}
147147

148-
if let Some(refines) = case.refines {
149-
self.result.write_str(" ")?;
150-
self.start_group("refines ")?;
151-
write!(&mut self.result, "{refines}")?;
152-
self.end_group()?;
153-
}
154148
self.end_group()?;
155149
}
156150
self.end_group()?;

crates/wast/src/component/binary.rs

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,11 @@ fn encode_defined_type(encoder: ComponentDefinedTypeEncoder, ty: &ComponentDefin
9898
encoder.record(r.fields.iter().map(|f| (f.name, &f.ty)));
9999
}
100100
ComponentDefinedType::Variant(v) => {
101-
encoder.variant(v.cases.iter().map(|c| {
102-
(
103-
c.name,
104-
c.ty.as_ref().map(Into::into),
105-
c.refines.as_ref().map(Into::into),
106-
)
107-
}));
101+
encoder.variant(
102+
v.cases
103+
.iter()
104+
.map(|c| (c.name, c.ty.as_ref().map(Into::into))),
105+
);
108106
}
109107
ComponentDefinedType::List(l) => {
110108
encoder.list(l.element.as_ref());
@@ -827,15 +825,6 @@ impl From<PrimitiveValType> for wasm_encoder::PrimitiveValType {
827825
}
828826
}
829827

830-
impl From<&Refinement<'_>> for u32 {
831-
fn from(r: &Refinement) -> Self {
832-
match r {
833-
Refinement::Index(..) => unreachable!("should be resolved by now"),
834-
Refinement::Resolved(i) => *i,
835-
}
836-
}
837-
}
838-
839828
impl From<&ItemSigKind<'_>> for wasm_encoder::ComponentTypeRef {
840829
fn from(k: &ItemSigKind) -> Self {
841830
match k {

0 commit comments

Comments
 (0)