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
16 changes: 11 additions & 5 deletions crates/wasm-mutate/src/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,19 @@ impl<'a> ModuleInfo<'a> {
info.section(SectionId::Type.into(), reader.range(), input_wasm);

// Save function types
for ty in reader {
if let Ok(st) = ty {
if st.is_final || st.supertype_idx.is_some() {
for rec_group in reader {
if let Ok(rg) = rec_group {
if rg.types().len() != 1 {
return Err(Error::unsupported("GC types not supported yet"));
}
let typeinfo = TypeInfo::try_from(st.structural_type).unwrap();
info.types_map.push(typeinfo);
for st in rg.types() {
if st.is_final || st.supertype_idx.is_some() {
return Err(Error::unsupported("GC types not supported yet"));
}
let typeinfo =
TypeInfo::try_from(st.clone().structural_type).unwrap();
info.types_map.push(typeinfo);
}
}
}
}
Expand Down
46 changes: 24 additions & 22 deletions crates/wasm-mutate/src/mutators/add_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,28 +55,30 @@ impl Mutator for AddTypeMutator {
if let Some(old_types) = config.info().get_type_section() {
// Copy the existing types section over into the encoder.
let reader = wasmparser::TypeSectionReader::new(old_types.data, 0)?;
for ty in reader {
match ty?.structural_type {
wasmparser::StructuralType::Func(ty) => {
let params = ty
.params()
.iter()
.copied()
.map(map_type)
.collect::<Result<Vec<_>, _>>()?;
let results = ty
.results()
.iter()
.copied()
.map(map_type)
.collect::<Result<Vec<_>, _>>()?;
types.function(params, results);
}
wasmparser::StructuralType::Array(_) => {
return Err(Error::unsupported("Array types are not supported yet."));
}
wasmparser::StructuralType::Struct(_) => {
return Err(Error::unsupported("Struct types are not supported yet."));
for rec_group in reader {
for ty in rec_group?.types() {
match ty.clone().structural_type {
wasmparser::StructuralType::Func(ty) => {
let params = ty
.params()
.iter()
.copied()
.map(map_type)
.collect::<Result<Vec<_>, _>>()?;
let results = ty
.results()
.iter()
.copied()
.map(map_type)
.collect::<Result<Vec<_>, _>>()?;
types.function(params, results);
}
wasmparser::StructuralType::Array(_) => {
return Err(Error::unsupported("Array types are not supported yet."));
}
wasmparser::StructuralType::Struct(_) => {
return Err(Error::unsupported("Struct types are not supported yet."));
}
}
}
}
Expand Down
7 changes: 6 additions & 1 deletion crates/wasm-mutate/src/mutators/remove_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,12 @@ impl RemoveItem {
0,
TypeSectionReader::new(section.data, 0)?,
Item::Type,
|me, ty, section| me.translate_type_def(ty.structural_type, section),
|me, rec_group, section| {
for ty in rec_group.types() {
me.translate_type_def(ty.clone().structural_type, section)?;
}
Ok(())
},
)?;
},

Expand Down
6 changes: 4 additions & 2 deletions crates/wasm-smith/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -553,8 +553,10 @@ impl Module {
match payload.expect("could not parse the available import payload") {
wasmparser::Payload::TypeSection(type_reader) => {
for ty in type_reader {
let ty = ty.expect("could not parse type section");
available_types.push((ty.structural_type, None));
let rec_group = ty.expect("could not parse type section");
for ty in rec_group.types() {
available_types.push((ty.clone().structural_type, None));
}
}
}
wasmparser::Payload::ImportSection(import_reader) => {
Expand Down
18 changes: 10 additions & 8 deletions crates/wasm-smith/tests/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,16 @@ fn smoke_test_imports_config() {
let payload = payload.unwrap();
if let wasmparser::Payload::TypeSection(rdr) = payload {
// Gather the signature types to later check function types against.
for ty in rdr {
match ty.unwrap().structural_type {
wasmparser::StructuralType::Func(ft) => sig_types.push(ft),
wasmparser::StructuralType::Array(_) => {
unimplemented!("Array types are not supported yet.")
}
wasmparser::StructuralType::Struct(_) => {
unimplemented!("Struct types are not supported yet.")
for rec_group in rdr {
for ty in rec_group.unwrap().types() {
match ty.clone().structural_type {
wasmparser::StructuralType::Func(ft) => sig_types.push(ft),
wasmparser::StructuralType::Array(_) => {
unimplemented!("Array types are not supported yet.")
}
wasmparser::StructuralType::Struct(_) => {
unimplemented!("Struct types are not supported yet.")
}
}
}
}
Expand Down
Loading