Skip to content

Commit

Permalink
review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
fitzgen committed Jan 24, 2024
1 parent 75a95de commit eca01da
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 10 deletions.
27 changes: 27 additions & 0 deletions crates/wasmparser/src/readers/core/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,33 @@ impl RefType {
/// `externref`.
pub const EXTERNREF: Self = RefType::EXTERN.nullable();

/// A nullable reference to any object aka `(ref null any)` aka `anyref`.
pub const ANYREF: Self = RefType::ANY.nullable();

/// A nullable reference to no object aka `(ref null none)` aka `nullref`.
pub const NULLREF: Self = RefType::NONE.nullable();

/// A nullable reference to a noextern object aka `(ref null noextern)` aka
/// `nullexternref`.
pub const NULLEXTERNREF: Self = RefType::NOEXTERN.nullable();

/// A nullable reference to a nofunc object aka `(ref null nofunc)` aka
/// `nullfuncref`.
pub const NULLFUNCREF: Self = RefType::NOFUNC.nullable();

/// A nullable reference to an eq object aka `(ref null eq)` aka `eqref`.
pub const EQREF: Self = RefType::EQ.nullable();

/// A nullable reference to a struct aka `(ref null struct)` aka
/// `structref`.
pub const STRUCTREF: Self = RefType::STRUCT.nullable();

/// A nullable reference to an array aka `(ref null array)` aka `arrayref`.
pub const ARRAYREF: Self = RefType::ARRAY.nullable();

/// A nullable reference to an i31 object aka `(ref null i31)` aka `i31ref`.
pub const I31REF: Self = RefType::I31.nullable();

/// A nullable reference to an exception object aka `(ref null exn)` aka
/// `exnref`.
pub const EXNREF: Self = RefType::EXN.nullable();
Expand Down
19 changes: 9 additions & 10 deletions crates/wasmparser/src/validator/operators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1072,10 +1072,13 @@ where
BinaryReaderError::new("implementation limit: type index too large", self.offset)
})?;

let sup_ty = self
.pop_ref()?
.unwrap_or_else(|| sub_ty.as_reference_type().unwrap());
let sup_ty = RefType::new(true, self.resources.top_type(&sup_ty.heap_type())).unwrap();
let sup_ty = self.pop_ref()?.unwrap_or_else(|| {
sub_ty
.as_reference_type()
.expect("we created this as a reference just above")
});
let sup_ty = RefType::new(true, self.resources.top_type(&sup_ty.heap_type()))
.expect("can't panic with non-concrete heap types");

if !self.resources.is_subtype(sub_ty, sup_ty.into()) {
bail!(
Expand Down Expand Up @@ -3990,15 +3993,11 @@ where
self.push_operand(ValType::Ref(RefType::I31))
}
fn visit_i31_get_s(&mut self) -> Self::Output {
self.pop_operand(Some(ValType::Ref(
RefType::new(true, HeapType::I31).unwrap(),
)))?;
self.pop_operand(Some(ValType::Ref(RefType::I31REF)))?;
self.push_operand(ValType::I32)
}
fn visit_i31_get_u(&mut self) -> Self::Output {
self.pop_operand(Some(ValType::Ref(
RefType::new(true, HeapType::I31).unwrap(),
)))?;
self.pop_operand(Some(ValType::Ref(RefType::I31REF)))?;
self.push_operand(ValType::I32)
}
}
Expand Down

0 comments on commit eca01da

Please sign in to comment.