pub struct Config {Show 64 fields
pub available_imports: Option<Vec<u8>>,
pub exports: Option<Vec<u8>>,
pub module_shape: Option<Vec<u8>>,
pub allow_start_export: bool,
pub allowed_instructions: InstructionKinds,
pub allow_floats: bool,
pub bulk_memory_enabled: bool,
pub canonicalize_nans: bool,
pub disallow_traps: bool,
pub exceptions_enabled: bool,
pub export_everything: bool,
pub gc_enabled: bool,
pub custom_page_sizes_enabled: bool,
pub generate_custom_sections: bool,
pub max_aliases: usize,
pub max_components: usize,
pub max_data_segments: usize,
pub max_element_segments: usize,
pub max_elements: usize,
pub max_exports: usize,
pub max_funcs: usize,
pub max_globals: usize,
pub max_imports: usize,
pub max_instances: usize,
pub max_instructions: usize,
pub max_memories: usize,
pub max_memory32_bytes: u64,
pub max_memory64_bytes: u128,
pub max_modules: usize,
pub max_nesting_depth: usize,
pub max_table_elements: u64,
pub max_tables: usize,
pub max_tags: usize,
pub max_type_size: u32,
pub max_types: usize,
pub max_values: usize,
pub memory64_enabled: bool,
pub memory_max_size_required: bool,
pub memory_offset_choices: MemoryOffsetChoices,
pub min_data_segments: usize,
pub min_element_segments: usize,
pub min_elements: usize,
pub min_exports: usize,
pub min_funcs: usize,
pub min_globals: usize,
pub min_imports: usize,
pub min_memories: u32,
pub min_tables: u32,
pub min_tags: usize,
pub min_types: usize,
pub min_uleb_size: u8,
pub multi_value_enabled: bool,
pub reference_types_enabled: bool,
pub relaxed_simd_enabled: bool,
pub saturating_float_to_int_enabled: bool,
pub sign_extension_ops_enabled: bool,
pub shared_everything_threads_enabled: bool,
pub simd_enabled: bool,
pub tail_call_enabled: bool,
pub table_max_size_required: bool,
pub threads_enabled: bool,
pub allow_invalid_funcs: bool,
pub wide_arithmetic_enabled: bool,
pub extended_const_enabled: bool,
}Expand description
Configuration for a generated module.
Don’t care to configure your generated modules? Just use
Module::arbitrary, which internally uses the default
configuration.
Want control over the shape of the module that gets generated? Create a
Config and then pass it to Module::new.
§Swarm Testing
You can use the Arbitrary for Config implementation for swarm
testing. This will dynamically – but still deterministically – choose
configuration options for you.
Note that we pick only maximums, not minimums, here because it is more
complex to describe the domain of valid configs when minima are involved
(min <= max for each variable) and minima are mostly used to ensure
certain elements are present, but do not widen the range of generated
Wasm modules.
Fields§
§available_imports: Option<Vec<u8>>The imports that may be used when generating the module.
Defaults to None which means that any arbitrary import can be
generated.
To only allow specific imports, set this field to a WebAssembly module which describes the imports allowed.
Note that Self::min_imports is ignored when
available_imports are enabled.
The provided value must be a valid binary encoding of a
WebAssembly module. wasm-smith will panic if the module cannot
be parsed.
§Example
An implementation of this method could use the wat crate to
provide a human-readable and maintainable description:
Some(wat::parse_str(r#"
(module
(import "env" "ping" (func (param i32)))
(import "env" "pong" (func (result i32)))
(import "env" "memory" (memory 1))
(import "env" "table" (table 1))
(import "env" "tag" (tag (param i32)))
)
"#))exports: Option<Vec<u8>>If provided, the generated module will have exports with exactly the same names and types as those in the provided WebAssembly module. The implementation (e.g. function bodies, global initializers) of each export in the generated module will be random and unrelated to the implementation in the provided module.
Defaults to None which means arbitrary exports will be
generated.
To specify which exports the generated modules should have, set this field to a WebAssembly module which describes the desired exports. To generate modules with varying exports that meet some constraints, consider randomly generating the value for this field.
The provided value must be a valid binary encoding of a
WebAssembly module. wasm-smith will panic if the module cannot
be parsed.
§Module Limits
All types, functions, globals, memories, tables, tags, and exports
that are needed to provide the required exports will be generated,
even if it causes the resulting module to exceed the limits defined
in Self::max_type_size, Self::max_types,
Self::max_funcs, Self::max_globals,
Self::max_memories, Self::max_tables,
Self::max_tags, or Self::max_exports.
§Example
As for Self::available_imports, the wat crate can be used
to provide an human-readable description of the desired exports:
Some(wat::parse_str(r#"
(module
(func (export "foo") (param i32) (result i64) unreachable)
(global (export "bar") f32 f32.const 0)
(memory (export "baz") 1 10)
(table (export "qux") 5 10 (ref null extern))
(tag (export "quux") (param f32))
)
"#));module_shape: Option<Vec<u8>>If provided, the generated module will have imports and exports with exactly the same names and types as those in the provided WebAssembly module.
Defaults to None which means arbitrary imports and exports will be
generated.
Note that Self::available_imports and Self::exports are
ignored when module_shape is enabled.
The provided value must be a valid binary encoding of a
WebAssembly module. wasm-smith will panic if the module cannot
be parsed.
§Module Limits
All types, functions, globals, memories, tables, tags, imports, and exports
that are needed to provide the required imports and exports will be generated,
even if it causes the resulting module to exceed the limits defined in
Self::max_type_size, Self::max_types, Self::max_funcs,
Self::max_globals, Self::max_memories, Self::max_tables,
Self::max_tags, Self::max_imports, or Self::max_exports.
§Example
As for Self::available_imports and Self::exports, the
wat crate can be used to provide a human-readable description of the
module shape:
Some(wat::parse_str(r#"
(module
(import "env" "ping" (func (param i32)))
(import "env" "memory" (memory 1))
(func (export "foo") (param anyref) (result structref) unreachable)
(global (export "bar") arrayref (ref.null array))
)
"#));allow_start_export: boolDetermines whether a start export may be included. Defaults to true.
allowed_instructions: InstructionKindsThe kinds of instructions allowed in the generated wasm programs. Defaults to all.
The categories of instructions match the categories used by the WebAssembly specification; e.g., numeric, vector, control, memory, etc.
Additionally, we include finer-grained categories which exclude floating point
instructions, e.g. InstructionKind::NumericInt is a subset of
InstructionKind::Numeric consisting of all numeric instructions which
don’t involve floats.
Note that modifying this setting is separate from the proposal
flags; that is, if simd_enabled() == true but
allowed_instruction() does not include vector instructions, the
generated programs will not include these instructions but could
contain vector types.
allow_floats: boolDetermines whether we generate floating point instructions and types.
Defaults to true.
bulk_memory_enabled: boolDetermines whether the bulk memory proposal is enabled for generating instructions.
Defaults to true.
canonicalize_nans: boolReturns whether NaN values are canonicalized after all f32/f64 operation. Defaults to false.
This can be useful when a generated wasm module is executed in multiple runtimes which may produce different NaN values. This ensures that the generated module will always use the same NaN representation for all instructions which have visible side effects, for example writing floats to memory or float-to-int bitcast instructions.
disallow_traps: boolReturns whether we should avoid generating code that will possibly trap.
For some trapping instructions, this will emit extra instructions to ensure they don’t trap, while some instructions will simply be excluded. In cases where we would run into a trap, we instead choose some arbitrary non-trapping behavior. For example, if we detect that a Load instruction would attempt to access out-of-bounds memory, we instead pretend the load succeeded and push 0 onto the stack.
One type of trap that we can’t currently avoid is
StackOverflow. Even when disallow_traps is set to true, wasm-smith
will eventually generate a program that infinitely recurses, causing
the call stack to be exhausted.
Defaults to false.
exceptions_enabled: boolDetermines whether the exception-handling proposal is enabled for generating instructions.
Defaults to true.
export_everything: boolExport all WebAssembly objects in the module. Defaults to false.
This overrides Config::min_exports and Config::max_exports.
gc_enabled: boolDetermines whether the GC proposal is enabled when generating a Wasm module.
Defaults to true.
custom_page_sizes_enabled: boolDetermines whether the custom-page-sizes proposal is enabled when generating a Wasm module.
Defaults to false.
generate_custom_sections: boolReturns whether we should generate custom sections or not. Defaults to false.
max_aliases: usizeReturns the maximal size of the alias section. Defaults to 1000.
max_components: usizeThe maximum number of components to use. Defaults to 10.
This includes imported components.
Note that this is only relevant for components.
max_data_segments: usizeThe maximum number of data segments to generate. Defaults to 100.
max_element_segments: usizeThe maximum number of element segments to generate. Defaults to 100.
max_elements: usizeThe maximum number of elements within a segment to generate. Defaults to 100.
max_exports: usizeThe maximum number of exports to generate. Defaults to 100.
max_funcs: usizeThe maximum number of functions to generate. Defaults to 100. This includes imported functions.
max_globals: usizeThe maximum number of globals to generate. Defaults to 100. This includes imported globals.
max_imports: usizeThe maximum number of imports to generate. Defaults to 100.
max_instances: usizeThe maximum number of instances to use. Defaults to 10.
This includes imported instances.
Note that this is only relevant for components.
max_instructions: usizeThe maximum number of instructions to generate in a function body. Defaults to 100.
Note that some additional ends, elses, and unreachables may be
appended to the function body to finish block scopes.
max_memories: usizeThe maximum number of memories to use. Defaults to 1.
This includes imported memories.
Note that more than one memory is in the realm of the multi-memory wasm proposal.
max_memory32_bytes: u64The maximum, in bytes, of any 32-bit memory’s initial or maximum size.
May not be larger than 2**32.
Defaults to 2**32.
max_memory64_bytes: u128The maximum, in bytes, of any 64-bit memory’s initial or maximum size.
May not be larger than 2**64.
Defaults to 2**64.
max_modules: usizeThe maximum number of modules to use. Defaults to 10.
This includes imported modules.
Note that this is only relevant for components.
max_nesting_depth: usizeReturns the maximal nesting depth of modules with the component model proposal. Defaults to 10.
max_table_elements: u64The maximum, elements, of any table’s initial or maximum size. Defaults to 1 million.
max_tables: usizeThe maximum number of tables to use. Defaults to 1.
This includes imported tables.
Note that more than one table is in the realm of the reference types proposal.
The maximum number of tags to generate. Defaults to 100.
max_type_size: u32Returns the maximal effective size of any type generated by wasm-smith.
Note that this number is roughly in units of “how many types would be needed to represent the recursive type”. A function with 8 parameters and 2 results would take 11 types (one for the type, 10 for params/results). A module type with 2 imports and 3 exports would take 6 (module + imports + exports) plus the size of each import/export type. This is a somewhat rough measurement that is not intended to be very precise.
Defaults to 1000.
max_types: usizeThe maximum number of types to generate. Defaults to 100.
max_values: usizeThe maximum number of values to use. Defaults to 10.
This includes imported values.
Note that this is irrelevant unless value model support is enabled.
memory64_enabled: boolReturns whether 64-bit memories are allowed. Defaults to true.
Note that this is the gate for the memory64 proposal to WebAssembly.
memory_max_size_required: boolWhether every Wasm memory must have a maximum size
specified. Defaults to false.
memory_offset_choices: MemoryOffsetChoicesControl the probability of generating memory offsets that are in bounds vs. potentially out of bounds.
See the MemoryOffsetChoices struct for details.
min_data_segments: usizeThe minimum number of data segments to generate. Defaults to 0.
min_element_segments: usizeThe minimum number of element segments to generate. Defaults to 0.
min_elements: usizeThe minimum number of elements within a segment to generate. Defaults to 0.
min_exports: usizeThe minimum number of exports to generate. Defaults to 0.
min_funcs: usizeThe minimum number of functions to generate. Defaults to 0.
This includes imported functions.
min_globals: usizeThe minimum number of globals to generate. Defaults to 0.
This includes imported globals.
min_imports: usizeThe minimum number of imports to generate. Defaults to 0.
Note that if the sum of the maximum function1, table, global and memory counts is less than the minimum number of imports, then it will not be possible to satisfy all constraints (because imports count against the limits for those element kinds). In that case, we strictly follow the max-constraints, and can fail to satisfy this minimum number.
the maximum number of functions is also limited by the number of function types arbitrarily chosen; strictly speaking, then, the maximum number of imports that can be created due to max-constraints is
sum(min(num_func_types, max_funcs), max_tables, max_globals, max_memories). ↩
min_memories: u32The minimum number of memories to use. Defaults to 0.
This includes imported memories.
min_tables: u32The minimum number of tables to use. Defaults to 0.
This includes imported tables.
The minimum number of tags to generate. Defaults to 0.
min_types: usizeThe minimum number of types to generate. Defaults to 0.
min_uleb_size: u8The minimum size, in bytes, of all leb-encoded integers. Defaults to 1.
This is useful for ensuring that all leb-encoded integers are decoded as such rather than as simply one byte. This will forcibly extend leb integers with an over-long encoding in some locations if the size would otherwise be smaller than number returned here.
multi_value_enabled: boolDetermines whether the multi-value results are enabled.
Defaults to true.
reference_types_enabled: boolDetermines whether the reference types proposal is enabled for generating instructions.
Defaults to true.
relaxed_simd_enabled: boolDetermines whether the Relaxed SIMD proposal is enabled for generating instructions.
Defaults to true.
saturating_float_to_int_enabled: boolDetermines whether the non-trapping float-to-int conversions proposal is enabled.
Defaults to true.
sign_extension_ops_enabled: boolDetermines whether the sign-extension-ops proposal is enabled.
Defaults to true.
Determines whether the shared-everything-threads proposal is enabled.
The shared-everything-threads proposal, among other things,
extends shared attributes to all WebAssembly objects; it builds on
the threads proposal.
Defaults to false.
simd_enabled: boolDetermines whether the SIMD proposal is enabled for generating instructions.
Defaults to true.
tail_call_enabled: boolDetermines whether the tail calls proposal is enabled for generating instructions.
Defaults to true.
table_max_size_required: boolWhether every Wasm table must have a maximum size
specified. Defaults to false.
threads_enabled: boolDetermines whether the threads proposal is enabled.
The threads proposal involves shared linear memory, new atomic
instructions, and new wait and notify instructions.
Defaults to true.
allow_invalid_funcs: boolIndicates whether wasm-smith is allowed to generate invalid function bodies.
When enabled this option will enable taking raw bytes from the input byte stream and using them as a wasm function body. This means that the output module is not guaranteed to be valid but can help tickle various parts of validation/compilation in some circumstances as well.
Defaults to false.
wide_arithmetic_enabled: boolDetermines whether the wide-arithmetic proposal is enabled.
Defaults to false.
extended_const_enabled: boolDetermines whether the extended-const proposal is enabled.
Defaults to true.
Implementations§
Trait Implementations§
Source§impl<'a> Arbitrary<'a> for Config
impl<'a> Arbitrary<'a> for Config
Source§fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self>
fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self>
Self from the given unstructured data. Read moreSource§fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>
fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>
Self from the entirety of the given
unstructured data. Read moreSource§fn size_hint(depth: usize) -> (usize, Option<usize>)
fn size_hint(depth: usize) -> (usize, Option<usize>)
Unstructured this type
needs to construct itself. Read moreSource§fn try_size_hint(
depth: usize,
) -> Result<(usize, Option<usize>), MaxRecursionReached>
fn try_size_hint( depth: usize, ) -> Result<(usize, Option<usize>), MaxRecursionReached>
Unstructured this type
needs to construct itself. Read moreSource§impl<'de> Deserialize<'de> for Config
Available on crate feature serde only.
impl<'de> Deserialize<'de> for Config
serde only.