Path: blob/main/crates/fuzzing/src/generators/gc_ops/limits.rs
3068 views
//! Limits for the `gc` operations.12use serde::{Deserialize, Serialize};3use std::ops::RangeInclusive;45/// Range for the number of parameters.6pub const NUM_PARAMS_RANGE: RangeInclusive<u32> = 0..=10;7/// Range for the maximum number of types.8pub const MAX_TYPES_RANGE: RangeInclusive<u32> = 0..=32;9/// Range for the number of globals.10pub const NUM_GLOBALS_RANGE: RangeInclusive<u32> = 0..=10;11/// Range for the table size.12pub const TABLE_SIZE_RANGE: RangeInclusive<u32> = 0..=100;13/// Range for the maximum number of rec groups.14pub const MAX_REC_GROUPS_RANGE: RangeInclusive<u32> = 0..=10;15/// Maximum number of operations.16pub const MAX_OPS: usize = 100;1718/// Limits controlling the structure of a generated Wasm module.19#[derive(Debug, Default, Serialize, Deserialize)]20pub struct GcOpsLimits {21pub(crate) num_params: u32,22pub(crate) num_globals: u32,23pub(crate) table_size: u32,24pub(crate) max_rec_groups: u32,25pub(crate) max_types: u32,26}27impl GcOpsLimits {28/// Fixup the limits to ensure they are within the valid range.29pub(crate) fn fixup(&mut self) {30// NB: Exhaustively match so that we remember to fixup any other new31// limits we add in the future.32let Self {33num_params,34num_globals,35table_size,36max_rec_groups,37max_types,38} = self;3940let clamp = |limit: &mut u32, range: RangeInclusive<u32>| {41*limit = (*limit).clamp(*range.start(), *range.end())42};43clamp(table_size, TABLE_SIZE_RANGE);44clamp(num_params, NUM_PARAMS_RANGE);45clamp(num_globals, NUM_GLOBALS_RANGE);46clamp(max_rec_groups, MAX_REC_GROUPS_RANGE);47clamp(max_types, MAX_TYPES_RANGE);48}49}505152