Skip to content

Commit

Permalink
Sync wasmparser/wasm-smith on bulk-memory
Browse files Browse the repository at this point in the history
Historically in bytecodealliance#410 fuzzing for `wasm-tools smith` was updated to
unconditionally enable the bulk-memory proposal if the reference-types
proposal was enabled. This doesn't prevent configuration on the CLI,
however, as exposed in bytecodealliance#1324. This change undoes bytecodealliance#410 effectively and
then syncs the `wasm-smith` crate's understanding of bulk-memory and
reference-types with `wasmparser`'s understanding.

I'm not actually sure if `wasmparser`'s understanding of
bulk-memory-vs-reference-types is correct. It was always a bit murky to
me precisely which instructions where in which proposal, so I've opted
here to take whatever `wasmparser` does today as the source of truth.
Any edits necessary to move items between proposals can be done in
`wasmparser` and then reflected in `wasm-smith`.
  • Loading branch information
alexcrichton committed Dec 11, 2023
1 parent c1e28f3 commit 891130f
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion crates/wasm-smith/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ impl<'a> Arbitrary<'a> for SwarmConfig {
max_tables,
max_memory_pages: u.arbitrary()?,
min_uleb_size: u.int_in_range(0..=5)?,
bulk_memory_enabled: reference_types_enabled || u.arbitrary()?,
bulk_memory_enabled: u.arbitrary()?,
reference_types_enabled,
simd_enabled: u.arbitrary()?,
multi_value_enabled: u.arbitrary()?,
Expand Down
8 changes: 5 additions & 3 deletions crates/wasm-smith/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1149,11 +1149,13 @@ impl Module {

// Reference types allows us to create passive and declared element
// segments.
if self.config.reference_types_enabled() {
if self.config.bulk_memory_enabled() {
funcrefs.push(Box::new(|_| Ok((ElementKind::Passive, None))));
externrefs.push(Box::new(|_| Ok((ElementKind::Passive, None))));
funcrefs.push(Box::new(|_| Ok((ElementKind::Declared, None))));
externrefs.push(Box::new(|_| Ok((ElementKind::Declared, None))));
if self.config.reference_types_enabled() {
externrefs.push(Box::new(|_| Ok((ElementKind::Passive, None))));
externrefs.push(Box::new(|_| Ok((ElementKind::Declared, None))));
}
}

let mut choices = Vec::new();
Expand Down
6 changes: 3 additions & 3 deletions crates/wasm-smith/src/core/code_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4814,7 +4814,7 @@ fn table_grow(

#[inline]
fn table_copy_valid(module: &Module, builder: &mut CodeBuilder) -> bool {
module.config.reference_types_enabled()
module.config.bulk_memory_enabled()
&& !module.config.disallow_traps() // Non-trapping table.copy generation not yet implemented
&& module.tables.len() > 0
&& builder.types_on_stack(&[ValType::I32, ValType::I32, ValType::I32])
Expand All @@ -4838,7 +4838,7 @@ fn table_copy(

#[inline]
fn table_init_valid(module: &Module, builder: &mut CodeBuilder) -> bool {
module.config.reference_types_enabled()
module.config.bulk_memory_enabled()
&& !module.config.disallow_traps() // Non-trapping table.init generation not yet implemented.
&& builder.allocs.table_init_possible
&& builder.types_on_stack(&[ValType::I32, ValType::I32, ValType::I32])
Expand Down Expand Up @@ -4869,7 +4869,7 @@ fn table_init(

#[inline]
fn elem_drop_valid(module: &Module, _builder: &mut CodeBuilder) -> bool {
module.config.reference_types_enabled() && module.elems.len() > 0
module.config.bulk_memory_enabled() && module.elems.len() > 0
}

fn elem_drop(
Expand Down
4 changes: 2 additions & 2 deletions fuzz/src/validate_valid_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ pub fn run(u: &mut Unstructured<'_>) -> Result<()> {
component_model: generate_component,
multi_value: config.multi_value_enabled,
multi_memory: config.max_memories > 1,
bulk_memory: true,
reference_types: true,
bulk_memory: config.bulk_memory_enabled,
reference_types: config.reference_types_enabled,
simd: config.simd_enabled,
relaxed_simd: config.relaxed_simd_enabled,
memory64: config.memory64_enabled,
Expand Down

0 comments on commit 891130f

Please sign in to comment.