Skip to content

Commit

Permalink
added eq, partial_eq traits for many wasmparser types (bytecodeallian…
Browse files Browse the repository at this point in the history
…ce#1690)

* added eq, partial_eq traits for many wasmparser types

* impl eq, partialeq for ConstExpr

* removed from wast
  • Loading branch information
thesuhas authored Aug 9, 2024
1 parent 3e14e8e commit d19cf14
Show file tree
Hide file tree
Showing 12 changed files with 34 additions and 23 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ publish
*.wat
test.config

.DS_Store
.idea
.vscode
2 changes: 1 addition & 1 deletion crates/wasmparser/src/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ macro_rules! define_wasm_features {

define_wasm_features! {
/// Flags for features that are enabled for validation.
#[derive(Hash, Debug, Copy, Clone)]
#[derive(Hash, Debug, Copy, Clone, Eq, PartialEq)]
pub struct WasmFeatures: u32 {
/// The WebAssembly `mutable-global` proposal.
pub mutable_global: MUTABLE_GLOBAL(1) = true;
Expand Down
2 changes: 1 addition & 1 deletion crates/wasmparser/src/readers/component/aliases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub enum ComponentOuterAliasKind {
}

/// Represents an alias in a WebAssembly component.
#[derive(Debug, Clone)]
#[derive(Debug, Clone, Eq, PartialEq)]
pub enum ComponentAlias<'a> {
/// The alias is to an export of a component instance.
InstanceExport {
Expand Down
2 changes: 1 addition & 1 deletion crates/wasmparser/src/readers/component/canonicals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub enum CanonicalOption {
}

/// Represents a canonical function in a WebAssembly component.
#[derive(Debug, Clone)]
#[derive(Debug, Clone, Eq, PartialEq)]
pub enum CanonicalFunction {
/// The function lifts a core WebAssembly function to the canonical ABI.
Lift {
Expand Down
4 changes: 2 additions & 2 deletions crates/wasmparser/src/readers/component/exports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl ComponentExternalKind {
}

/// Represents an export in a WebAssembly component.
#[derive(Debug, Clone)]
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct ComponentExport<'a> {
/// The name of the exported item.
pub name: ComponentExportName<'a>,
Expand Down Expand Up @@ -115,7 +115,7 @@ impl<'a> FromReader<'a> for ComponentExternalKind {
}

/// Represents the name of a component export.
#[derive(Debug, Copy, Clone)]
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
#[allow(missing_docs)]
pub struct ComponentExportName<'a>(pub &'a str);

Expand Down
4 changes: 2 additions & 2 deletions crates/wasmparser/src/readers/component/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ impl<'a> FromReader<'a> for ComponentTypeRef {
}

/// Represents an import in a WebAssembly component
#[derive(Debug, Copy, Clone)]
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub struct ComponentImport<'a> {
/// The name of the imported item.
pub name: ComponentImportName<'a>,
Expand Down Expand Up @@ -110,7 +110,7 @@ impl<'a> FromReader<'a> for ComponentImport<'a> {
pub type ComponentImportSectionReader<'a> = SectionLimited<'a, ComponentImport<'a>>;

/// Represents the name of a component import.
#[derive(Debug, Copy, Clone)]
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
#[allow(missing_docs)]
pub struct ComponentImportName<'a>(pub &'a str);

Expand Down
8 changes: 4 additions & 4 deletions crates/wasmparser/src/readers/component/instances.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub enum InstantiationArgKind {
}

/// Represents an argument to instantiating a WebAssembly module.
#[derive(Debug, Clone)]
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct InstantiationArg<'a> {
/// The name of the module argument.
pub name: &'a str,
Expand All @@ -24,7 +24,7 @@ pub struct InstantiationArg<'a> {
}

/// Represents an instance of a WebAssembly module.
#[derive(Debug, Clone)]
#[derive(Debug, Clone, Eq, PartialEq)]
pub enum Instance<'a> {
/// The instance is from instantiating a WebAssembly module.
Instantiate {
Expand Down Expand Up @@ -91,7 +91,7 @@ impl<'a> FromReader<'a> for InstantiationArgKind {
}

/// Represents an argument to instantiating a WebAssembly component.
#[derive(Debug, Clone)]
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct ComponentInstantiationArg<'a> {
/// The name of the component argument.
pub name: &'a str,
Expand All @@ -102,7 +102,7 @@ pub struct ComponentInstantiationArg<'a> {
}

/// Represents an instance in a WebAssembly component.
#[derive(Debug, Clone)]
#[derive(Debug, Clone, Eq, PartialEq)]
pub enum ComponentInstance<'a> {
/// The instance is from instantiating a WebAssembly component.
Instantiate {
Expand Down
14 changes: 7 additions & 7 deletions crates/wasmparser/src/readers/component/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub enum OuterAliasKind {
}

/// Represents a core type in a WebAssembly component.
#[derive(Debug, Clone)]
#[derive(Debug, Clone, Eq, PartialEq)]
pub enum CoreType<'a> {
/// The type is for a core subtype.
Sub(SubType),
Expand Down Expand Up @@ -44,7 +44,7 @@ impl<'a> FromReader<'a> for CoreType<'a> {
}

/// Represents a module type declaration in a WebAssembly component.
#[derive(Debug, Clone)]
#[derive(Debug, Clone, Eq, PartialEq)]
pub enum ModuleTypeDeclaration<'a> {
/// The module type definition is for a type.
Type(SubType),
Expand Down Expand Up @@ -235,7 +235,7 @@ impl fmt::Display for PrimitiveValType {
}

/// Represents a type in a WebAssembly component.
#[derive(Debug, Clone)]
#[derive(Debug, Clone, Eq, PartialEq)]
pub enum ComponentType<'a> {
/// The type is a component defined type.
Defined(ComponentDefinedType<'a>),
Expand Down Expand Up @@ -295,7 +295,7 @@ impl<'a> FromReader<'a> for ComponentType<'a> {
}

/// Represents part of a component type declaration in a WebAssembly component.
#[derive(Debug, Clone)]
#[derive(Debug, Clone, Eq, PartialEq)]
pub enum ComponentTypeDeclaration<'a> {
/// The component type declaration is for a core type.
CoreType(CoreType<'a>),
Expand Down Expand Up @@ -336,7 +336,7 @@ impl<'a> FromReader<'a> for ComponentTypeDeclaration<'a> {
}

/// Represents an instance type declaration in a WebAssembly component.
#[derive(Debug, Clone)]
#[derive(Debug, Clone, Eq, PartialEq)]
pub enum InstanceTypeDeclaration<'a> {
/// The component type declaration is for a core type.
CoreType(CoreType<'a>),
Expand Down Expand Up @@ -369,7 +369,7 @@ impl<'a> FromReader<'a> for InstanceTypeDeclaration<'a> {
}

/// Represents the result type of a component function.
#[derive(Debug, Clone)]
#[derive(Debug, Clone, Eq, PartialEq)]
pub enum ComponentFuncResult<'a> {
/// The function returns a singular, unnamed type.
Unnamed(ComponentValType),
Expand Down Expand Up @@ -430,7 +430,7 @@ impl ComponentFuncResult<'_> {
}

/// Represents a type of a function in a WebAssembly component.
#[derive(Debug, Clone)]
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct ComponentFuncType<'a> {
/// The function parameters.
pub params: Box<[(&'a str, ComponentValType)]>,
Expand Down
2 changes: 1 addition & 1 deletion crates/wasmparser/src/readers/core/exports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub enum ExternalKind {
}

/// Represents an export in a WebAssembly module.
#[derive(Debug, Copy, Clone)]
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub struct Export<'a> {
/// The name of the exported item.
pub name: &'a str,
Expand Down
4 changes: 2 additions & 2 deletions crates/wasmparser/src/readers/core/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::{
};

/// Represents a reference to a type definition in a WebAssembly module.
#[derive(Debug, Clone, Copy)]
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
pub enum TypeRef {
/// The type is a function.
///
Expand All @@ -40,7 +40,7 @@ pub enum TypeRef {
}

/// Represents an import in a WebAssembly module.
#[derive(Debug, Copy, Clone)]
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub struct Import<'a> {
/// The module being imported from.
pub module: &'a str,
Expand Down
8 changes: 8 additions & 0 deletions crates/wasmparser/src/readers/core/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ pub struct ConstExpr<'a> {
reader: BinaryReader<'a>,
}

impl PartialEq for ConstExpr<'_> {
fn eq(&self, other: &Self) -> bool {
self.reader.remaining_buffer() == other.reader.remaining_buffer()
}
}

impl Eq for ConstExpr<'_> {}

impl<'a> ConstExpr<'a> {
/// Constructs a new `ConstExpr` from the given data and offset.
pub fn new(reader: BinaryReader<'a>) -> ConstExpr {
Expand Down
4 changes: 2 additions & 2 deletions crates/wasmparser/src/readers/core/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1780,14 +1780,14 @@ pub struct GlobalType {
}

/// Represents a tag kind.
#[derive(Clone, Copy, Debug)]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum TagKind {
/// The tag is an exception type.
Exception,
}

/// A tag's type.
#[derive(Clone, Copy, Debug)]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct TagType {
/// The kind of tag
pub kind: TagKind,
Expand Down

0 comments on commit d19cf14

Please sign in to comment.