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
10 changes: 7 additions & 3 deletions ci/generate-spec-tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@ fn copy_test(src: &Path, dst: &Path) {
return;
}

let mut contents = format!(";; RUN: wast \\\n");
let directive = match dst.file_name().and_then(|s| s.to_str()) {
Some("exact-func-import.wast") => "FAIL",
Some(_) | None => "RUN",
};

let mut contents = format!(";; {directive}: wast \\\n");
contents.push_str(";; --assert default \\\n");

// Allow certain assert_malformed tests to be interpreted as assert_invalid
Expand Down Expand Up @@ -73,8 +78,7 @@ fn copy_test(src: &Path, dst: &Path) {
Some("threads") => "wasm1,threads",
Some("custom-page-sizes") => "wasm3,custom-page-sizes",
Some("wide-arithmetic") => "wasm3,wide-arithmetic",
// not implemented yet
Some("custom-descriptors") => return,
Some("custom-descriptors") => "wasm3,custom-descriptors",
Some(proposal) => panic!("unsupported proposal: {}", proposal),
};
contents.push_str(&format!(";; --features={features} \\\n"));
Expand Down
27 changes: 27 additions & 0 deletions crates/wasm-encoder/src/core/code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1316,6 +1316,20 @@ pub enum Instruction<'a> {
I64Sub128,
I64MulWideS,
I64MulWideU,

RefGetDesc(u32),
RefCastDescNonNull(HeapType),
RefCastDescNullable(HeapType),
BrOnCastDesc {
relative_depth: u32,
from_ref_type: RefType,
to_ref_type: RefType,
},
BrOnCastDescFail {
relative_depth: u32,
from_ref_type: RefType,
to_ref_type: RefType,
},
}

impl Encode for Instruction<'_> {
Expand Down Expand Up @@ -2144,6 +2158,19 @@ impl Encode for Instruction<'_> {
Instruction::I64Sub128 => sink.i64_sub128(),
Instruction::I64MulWideS => sink.i64_mul_wide_s(),
Instruction::I64MulWideU => sink.i64_mul_wide_u(),
Instruction::RefGetDesc(type_index) => sink.ref_get_desc(type_index),
Instruction::RefCastDescNonNull(hty) => sink.ref_cast_desc_non_null(hty),
Instruction::RefCastDescNullable(hty) => sink.ref_cast_desc_nullable(hty),
Instruction::BrOnCastDesc {
relative_depth,
from_ref_type,
to_ref_type,
} => sink.br_on_cast_desc(relative_depth, from_ref_type, to_ref_type),
Instruction::BrOnCastDescFail {
relative_depth,
from_ref_type,
to_ref_type,
} => sink.br_on_cast_desc_fail(relative_depth, from_ref_type, to_ref_type),
};
}
}
Expand Down
58 changes: 58 additions & 0 deletions crates/wasm-encoder/src/core/instructions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4609,4 +4609,62 @@ impl<'a> InstructionSink<'a> {
22u32.encode(self.sink);
self
}

/// Encode [`Instruction::RefGetDesc`].
pub fn ref_get_desc(&mut self, type_index: u32) -> &mut Self {
self.sink.push(0xFB);
34u32.encode(self.sink);
type_index.encode(self.sink);
self
}

/// Encode [`Instruction::RefCastDescNonNull`].
Comment thread
yurydelendik marked this conversation as resolved.
pub fn ref_cast_desc_non_null(&mut self, ht: HeapType) -> &mut Self {
self.sink.push(0xFB);
35u32.encode(self.sink);
ht.encode(self.sink);
self
}

/// Encode [`Instruction::RefCastDescNullable`].
pub fn ref_cast_desc_nullable(&mut self, ht: HeapType) -> &mut Self {
self.sink.push(0xFB);
36u32.encode(self.sink);
ht.encode(self.sink);
self
}

/// Encode [`Instruction::BrOnCastDesc`].
pub fn br_on_cast_desc(
&mut self,
relative_depth: u32,
from_ref_type: RefType,
to_ref_type: RefType,
) -> &mut Self {
self.sink.push(0xFB);
37u32.encode(self.sink);
let cast_flags = (from_ref_type.nullable as u8) | ((to_ref_type.nullable as u8) << 1);
self.sink.push(cast_flags);
relative_depth.encode(self.sink);
from_ref_type.heap_type.encode(self.sink);
to_ref_type.heap_type.encode(self.sink);
self
}

/// Encode [`Instruction::BrOnCastDescFail`].
pub fn br_on_cast_desc_fail(
&mut self,
relative_depth: u32,
from_ref_type: RefType,
to_ref_type: RefType,
) -> &mut Self {
self.sink.push(0xFB);
38u32.encode(self.sink);
let cast_flags = (from_ref_type.nullable as u8) | ((to_ref_type.nullable as u8) << 1);
self.sink.push(cast_flags);
relative_depth.encode(self.sink);
from_ref_type.heap_type.encode(self.sink);
to_ref_type.heap_type.encode(self.sink);
self
}
}
21 changes: 21 additions & 0 deletions crates/wasm-encoder/src/core/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ pub struct CompositeType {
/// Whether the type is shared. This is part of the
/// shared-everything-threads proposal.
pub shared: bool,
/// Optional descriptor attribute.
pub descriptor: Option<u32>,
/// Optional describes attribute.
pub describes: Option<u32>,
}

/// A [`CompositeType`] can contain one of these types.
Expand Down Expand Up @@ -362,6 +366,8 @@ pub enum HeapType {

/// A concrete Wasm-defined type at the given index.
Concrete(u32),
/// An exact type.
Exact(u32),
}

impl HeapType {
Expand Down Expand Up @@ -402,6 +408,11 @@ impl Encode for HeapType {
// Note that this is encoded as a signed type rather than unsigned
// as it's decoded as an s33
HeapType::Concrete(i) => i64::from(*i).encode(sink),
// Exact type is u32
HeapType::Exact(i) => {
sink.push(0x62);
u32::from(*i).encode(sink)
}
}
}
}
Expand Down Expand Up @@ -669,6 +680,14 @@ impl<'a> CoreTypeEncoder<'a> {
if ty.composite_type.shared {
self.bytes.push(0x65);
}
if let Some(index) = ty.composite_type.describes {
self.bytes.push(0x4c);
index.encode(self.bytes);
}
if let Some(index) = ty.composite_type.descriptor {
self.bytes.push(0x4d);
index.encode(self.bytes);
}
match &ty.composite_type.inner {
CompositeInnerType::Func(ty) => {
self.encode_function(ty.params().iter().copied(), ty.results().iter().copied())
Expand Down Expand Up @@ -715,6 +734,8 @@ mod tests {
composite_type: CompositeType {
inner: CompositeInnerType::Func(FuncType::new([], [])),
shared: false,
descriptor: None,
describes: None,
},
});

Expand Down
11 changes: 11 additions & 0 deletions crates/wasm-encoder/src/reencode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1170,6 +1170,14 @@ pub mod utils {
Ok(crate::CompositeType {
inner,
shared: composite_ty.shared,
descriptor: composite_ty
.descriptor_idx
.map(|i| reencoder.type_index_unpacked(i.unpack()))
.transpose()?,
describes: composite_ty
.describes_idx
.map(|i| reencoder.type_index_unpacked(i.unpack()))
.transpose()?,
})
}

Expand Down Expand Up @@ -1269,6 +1277,9 @@ pub mod utils {
wasmparser::HeapType::Concrete(i) => {
crate::HeapType::Concrete(reencoder.type_index_unpacked(i)?)
}
wasmparser::HeapType::Exact(i) => {
crate::HeapType::Exact(reencoder.type_index_unpacked(i)?)
}
wasmparser::HeapType::Abstract { shared, ty } => crate::HeapType::Abstract {
shared,
ty: reencoder.abstract_heap_type(ty)?,
Expand Down
1 change: 1 addition & 0 deletions crates/wasm-mutate/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ pub fn map_ref_type(ref_ty: wasmparser::RefType) -> Result<RefType> {
nullable: ref_ty.is_nullable(),
heap_type: match ref_ty.heap_type() {
wasmparser::HeapType::Concrete(i) => HeapType::Concrete(i.as_module_index().unwrap()),
wasmparser::HeapType::Exact(i) => HeapType::Exact(i.as_module_index().unwrap()),
wasmparser::HeapType::Abstract { shared, ty } => {
let ty = ty.into();
HeapType::Abstract { shared, ty }
Expand Down
12 changes: 12 additions & 0 deletions crates/wasm-smith/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,12 @@ define_config! {
/// Defaults to `true`.
pub gc_enabled: bool = true,

/// Determines whether the custom descriptors proposal is enabled when
/// generating a Wasm module.
///
/// Defaults to `true`.
pub custom_descriptors_enabled: bool = false,

/// Determines whether the custom-page-sizes proposal is enabled when
/// generating a Wasm module.
///
Expand Down Expand Up @@ -876,6 +882,7 @@ impl<'a> Arbitrary<'a> for Config {
custom_page_sizes_enabled: false,
wide_arithmetic_enabled: false,
shared_everything_threads_enabled: false,
custom_descriptors_enabled: false,
};
config.sanitize();
Ok(config)
Expand Down Expand Up @@ -908,6 +915,7 @@ impl Config {
// also disable shared-everything-threads.
if !self.gc_enabled {
self.shared_everything_threads_enabled = false;
self.custom_descriptors_enabled = false;
}

// If simd is disabled then disable all relaxed simd instructions as
Expand Down Expand Up @@ -972,6 +980,10 @@ impl Config {
);
features.set(WasmFeatures::EXTENDED_CONST, self.extended_const_enabled);
features.set(WasmFeatures::WIDE_ARITHMETIC, self.wide_arithmetic_enabled);
features.set(
WasmFeatures::CUSTOM_DESCRIPTORS,
self.custom_descriptors_enabled,
);

features
}
Expand Down
Loading