Skip to content

Commit 8d2eded

Browse files
committed
implement Alex' suggetions, part one
1 parent a8cdee7 commit 8d2eded

File tree

19 files changed

+38
-38
lines changed

19 files changed

+38
-38
lines changed

crates/wasm-compose/src/encoding.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,7 @@ impl<'a> TypeEncoder<'a> {
731731
&self,
732732
state: &mut TypeState<'a>,
733733
ty: ct::ComponentValType,
734-
elements: usize,
734+
elements: u32,
735735
) -> u32 {
736736
let ty = self.component_val_type(state, ty);
737737
let index = state.cur.encodable.type_count();

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -606,10 +606,10 @@ impl ComponentDefinedTypeEncoder<'_> {
606606
}
607607

608608
/// Define a fixed size list type.
609-
pub fn fixed_size_list(self, ty: impl Into<ComponentValType>, elements: usize) {
609+
pub fn fixed_size_list(self, ty: impl Into<ComponentValType>, elements: u32) {
610610
self.0.push(0x67);
611611
ty.into().encode(self.0);
612-
(elements as u32).encode(self.0);
612+
elements.encode(self.0);
613613
}
614614

615615
/// Define a tuple type.

crates/wasm-wave/src/value/ty.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub struct Type(pub(super) TypeEnum);
1010
pub(super) enum TypeEnum {
1111
Simple(SimpleType),
1212
List(Arc<ListType>),
13-
FixedSizeList(Arc<ListType>, usize),
13+
FixedSizeList(Arc<ListType>, u32),
1414
Record(Arc<RecordType>),
1515
Tuple(Arc<TupleType>),
1616
Variant(Arc<VariantType>),
@@ -57,7 +57,7 @@ impl Type {
5757
}
5858

5959
/// Returns a list type with the given element type.
60-
pub fn fixed_size_list(element_type: impl Into<Self>, elements: usize) -> Self {
60+
pub fn fixed_size_list(element_type: impl Into<Self>, elements: u32) -> Self {
6161
let element = element_type.into();
6262
Self(TypeEnum::FixedSizeList(
6363
Arc::new(ListType { element }),

crates/wasm-wave/src/value/wit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ impl<'a> TypeResolver<'a> {
149149
Ok(value::Type::list(element_type))
150150
}
151151

152-
fn resolve_fixed_size_list(&self, element_type: &Type, elements: usize) -> ValueResult {
152+
fn resolve_fixed_size_list(&self, element_type: &Type, elements: u32) -> ValueResult {
153153
let element_type = self.resolve_type(*element_type)?;
154154
Ok(value::Type::fixed_size_list(element_type, elements))
155155
}

crates/wasmparser/src/features.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,8 @@ define_wasm_features! {
231231
pub wide_arithmetic: WIDE_ARITHMETIC(1 << 28) = false;
232232
/// Support for component model async lift/lower ABI, as well as streams, futures, and errors.
233233
pub component_model_async: COMPONENT_MODEL_ASYNC(1 << 29) = false;
234+
/// Support for fixed size lists
235+
pub component_model_fixed_size_list: COMPONENT_MODEL_FIXED_SIZE_LIST(1 << 30) = false;
234236
}
235237
}
236238

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ pub enum ComponentDefinedType<'a> {
487487
/// The type is a list of the given value type.
488488
List(ComponentValType),
489489
/// The type is a fixed size list of the given value type.
490-
FixedSizeList(ComponentValType, usize),
490+
FixedSizeList(ComponentValType, u32),
491491
/// The type is a tuple of the given value types.
492492
Tuple(Box<[ComponentValType]>),
493493
/// The type is flags with the given names.
@@ -529,9 +529,6 @@ impl<'a> ComponentDefinedType<'a> {
529529
.collect::<Result<_>>()?,
530530
),
531531
0x70 => ComponentDefinedType::List(reader.read()?),
532-
0x67 => {
533-
ComponentDefinedType::FixedSizeList(reader.read()?, reader.read_var_u32()? as usize)
534-
}
535532
0x6f => ComponentDefinedType::Tuple(
536533
reader
537534
.read_iter(MAX_WASM_TUPLE_TYPES, "tuple types")?
@@ -555,8 +552,9 @@ impl<'a> ComponentDefinedType<'a> {
555552
},
556553
0x69 => ComponentDefinedType::Own(reader.read()?),
557554
0x68 => ComponentDefinedType::Borrow(reader.read()?),
558-
0x65 => ComponentDefinedType::Future(reader.read()?),
555+
0x67 => ComponentDefinedType::FixedSizeList(reader.read()?, reader.read_var_u32()?),
559556
0x66 => ComponentDefinedType::Stream(reader.read()?),
557+
0x65 => ComponentDefinedType::Future(reader.read()?),
560558
0x64 => ComponentDefinedType::ErrorContext,
561559
x => return reader.invalid_leading_byte(x, "component defined type"),
562560
})

crates/wasmparser/src/validator/component.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3278,6 +3278,12 @@ impl ComponentState {
32783278
self.create_component_val_type(ty, offset)?,
32793279
)),
32803280
crate::ComponentDefinedType::FixedSizeList(ty, elements) => {
3281+
if !features.component_model_fixed_size_list() {
3282+
bail!(
3283+
offset,
3284+
"Fixed size lists require the component model fixed size list feature"
3285+
)
3286+
}
32813287
Ok(ComponentDefinedType::FixedSizeList(
32823288
self.create_component_val_type(ty, offset)?,
32833289
elements,

crates/wasmparser/src/validator/component_types.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,7 +1041,7 @@ pub enum ComponentDefinedType {
10411041
/// The type is a list.
10421042
List(ComponentValType),
10431043
/// The type is a fixed size list.
1044-
FixedSizeList(ComponentValType, usize),
1044+
FixedSizeList(ComponentValType, u32),
10451045
/// The type is a tuple.
10461046
Tuple(TupleType),
10471047
/// The type is a set of flags.
@@ -1215,7 +1215,8 @@ impl ComponentDefinedType {
12151215
ComponentDefinedType::Enum(_) => "enum",
12161216
ComponentDefinedType::Flags(_) => "flags",
12171217
ComponentDefinedType::Option(_) => "option",
1218-
ComponentDefinedType::List(_) | ComponentDefinedType::FixedSizeList(_, _) => "list",
1218+
ComponentDefinedType::List(_) => "list",
1219+
ComponentDefinedType::FixedSizeList(_, _) => "fixed size list",
12191220
ComponentDefinedType::Result { .. } => "result",
12201221
ComponentDefinedType::Own(_) => "own",
12211222
ComponentDefinedType::Borrow(_) => "borrow",

crates/wasmprinter/src/component.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ impl Printer<'_, '_> {
171171
&mut self,
172172
state: &State,
173173
element_ty: &ComponentValType,
174-
elements: usize,
174+
elements: u32,
175175
) -> Result<()> {
176176
self.start_group("list ")?;
177177
self.print_component_val_type(state, element_ty)?;

crates/wast/src/component/types.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -580,18 +580,14 @@ pub struct List<'a> {
580580
/// The element type of the array.
581581
pub element: Box<ComponentValType<'a>>,
582582
/// Optional fixed size
583-
pub elements: Option<usize>,
583+
pub elements: Option<u32>,
584584
}
585585

586586
impl<'a> Parse<'a> for List<'a> {
587587
fn parse(parser: Parser<'a>) -> Result<Self> {
588588
parser.parse::<kw::list>()?;
589589
let tp = parser.parse()?;
590-
let elements = if !parser.is_empty() {
591-
Some(parser.parse::<u32>()? as usize)
592-
} else {
593-
None
594-
};
590+
let elements = parser.parse()?;
595591
Ok(Self {
596592
element: Box::new(tp),
597593
elements,

0 commit comments

Comments
 (0)