summaryrefslogtreecommitdiffstats
path: root/third_party/rust/wasm-smith/src/component.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-15 03:34:50 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-15 03:34:50 +0000
commitdef92d1b8e9d373e2f6f27c366d578d97d8960c6 (patch)
tree2ef34b9ad8bb9a9220e05d60352558b15f513894 /third_party/rust/wasm-smith/src/component.rs
parentAdding debian version 125.0.3-1. (diff)
downloadfirefox-def92d1b8e9d373e2f6f27c366d578d97d8960c6.tar.xz
firefox-def92d1b8e9d373e2f6f27c366d578d97d8960c6.zip
Merging upstream version 126.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/wasm-smith/src/component.rs')
-rw-r--r--third_party/rust/wasm-smith/src/component.rs53
1 files changed, 48 insertions, 5 deletions
diff --git a/third_party/rust/wasm-smith/src/component.rs b/third_party/rust/wasm-smith/src/component.rs
index e18373b4f4..7a85b2bf10 100644
--- a/third_party/rust/wasm-smith/src/component.rs
+++ b/third_party/rust/wasm-smith/src/component.rs
@@ -7,12 +7,13 @@
use crate::{arbitrary_loop, Config};
use arbitrary::{Arbitrary, Result, Unstructured};
use std::collections::BTreeMap;
-use std::convert::TryFrom;
use std::{
collections::{HashMap, HashSet},
rc::Rc,
};
-use wasm_encoder::{ComponentTypeRef, ComponentValType, PrimitiveValType, TypeBounds, ValType};
+use wasm_encoder::{
+ ComponentTypeRef, ComponentValType, HeapType, PrimitiveValType, RefType, TypeBounds, ValType,
+};
mod encode;
@@ -540,7 +541,7 @@ impl ComponentBuilder {
}
let ty = match u.int_in_range::<u8>(0..=1)? {
- 0 => CoreType::Func(crate::core::arbitrary_func_type(
+ 0 => CoreType::Func(arbitrary_func_type(
u,
&self.config,
&self.core_valtypes,
@@ -819,7 +820,7 @@ impl ComponentBuilder {
// Type definition.
2 => {
- let ty = crate::core::arbitrary_func_type(
+ let ty = arbitrary_func_type(
u,
&self.config,
&self.core_valtypes,
@@ -955,7 +956,7 @@ impl ComponentBuilder {
}
fn arbitrary_core_table_type(&self, u: &mut Unstructured) -> Result<crate::core::TableType> {
- crate::core::arbitrary_table_type(u, &self.config)
+ crate::core::arbitrary_table_type(u, &self.config, None)
}
fn arbitrary_core_memory_type(&self, u: &mut Unstructured) -> Result<crate::core::MemoryType> {
@@ -2176,3 +2177,45 @@ struct CoreInstanceSection {}
struct CoreTypeSection {
types: Vec<Rc<CoreType>>,
}
+
+fn arbitrary_func_type(
+ u: &mut Unstructured,
+ config: &Config,
+ valtypes: &[ValType],
+ max_results: Option<usize>,
+ type_ref_limit: u32,
+) -> Result<Rc<crate::core::FuncType>> {
+ let mut params = vec![];
+ let mut results = vec![];
+ arbitrary_loop(u, 0, 20, |u| {
+ params.push(arbitrary_valtype(u, config, valtypes, type_ref_limit)?);
+ Ok(true)
+ })?;
+ arbitrary_loop(u, 0, max_results.unwrap_or(20), |u| {
+ results.push(arbitrary_valtype(u, config, valtypes, type_ref_limit)?);
+ Ok(true)
+ })?;
+ Ok(Rc::new(crate::core::FuncType { params, results }))
+}
+
+fn arbitrary_valtype(
+ u: &mut Unstructured,
+ config: &Config,
+ valtypes: &[ValType],
+ type_ref_limit: u32,
+) -> Result<ValType> {
+ if config.gc_enabled && type_ref_limit > 0 && u.ratio(1, 20)? {
+ Ok(ValType::Ref(RefType {
+ // TODO: For now, only create allow nullable reference
+ // types. Eventually we should support non-nullable reference types,
+ // but this means that we will also need to recognize when it is
+ // impossible to create an instance of the reference (eg `(ref
+ // nofunc)` has no instances, and self-referential types that
+ // contain a non-null self-reference are also impossible to create).
+ nullable: true,
+ heap_type: HeapType::Concrete(u.int_in_range(0..=type_ref_limit - 1)?),
+ }))
+ } else {
+ Ok(*u.choose(valtypes)?)
+ }
+}