Implement PartialEq for all externals

This commit is contained in:
Syrus Akbary
2023-02-16 20:00:27 -08:00
parent e9a4ba498a
commit c85b2bf62e
9 changed files with 14 additions and 28 deletions

View File

@@ -81,7 +81,7 @@ mod private {
/// with native functions. Attempting to create a native `Function` with one will /// with native functions. Attempting to create a native `Function` with one will
/// result in a panic. /// result in a panic.
/// [Closures as host functions tracking issue](https://github.com/wasmerio/wasmer/issues/1840) /// [Closures as host functions tracking issue](https://github.com/wasmerio/wasmer/issues/1840)
#[derive(Debug, Clone)] #[derive(Debug, Clone, PartialEq)]
pub struct Function(pub(crate) function_impl::Function); pub struct Function(pub(crate) function_impl::Function);
impl Function { impl Function {
@@ -500,6 +500,8 @@ impl Function {
} }
} }
impl std::cmp::Eq for Function {}
impl<'a> Exportable<'a> for Function { impl<'a> Exportable<'a> for Function {
fn get_self_from_extern(_extern: &'a Extern) -> Result<&'a Self, ExportError> { fn get_self_from_extern(_extern: &'a Extern) -> Result<&'a Self, ExportError> {
match _extern { match _extern {

View File

@@ -19,7 +19,7 @@ use crate::sys::externals::global as global_impl;
/// It consists of an individual value and a flag indicating whether it is mutable. /// It consists of an individual value and a flag indicating whether it is mutable.
/// ///
/// Spec: <https://webassembly.github.io/spec/core/exec/runtime.html#global-instances> /// Spec: <https://webassembly.github.io/spec/core/exec/runtime.html#global-instances>
#[derive(Debug, Clone)] #[derive(Debug, Clone, PartialEq)]
pub struct Global(pub(crate) global_impl::Global); pub struct Global(pub(crate) global_impl::Global);
impl Global { impl Global {
@@ -161,12 +161,6 @@ impl Global {
} }
} }
impl std::cmp::PartialEq for Global {
fn eq(&self, other: &Self) -> bool {
self.0 == other.0
}
}
impl std::cmp::Eq for Global {} impl std::cmp::Eq for Global {}
impl<'a> Exportable<'a> for Global { impl<'a> Exportable<'a> for Global {

View File

@@ -27,7 +27,7 @@ use wasmer_types::{MemoryError, Pages};
/// mutable from both host and WebAssembly. /// mutable from both host and WebAssembly.
/// ///
/// Spec: <https://webassembly.github.io/spec/core/exec/runtime.html#memory-instances> /// Spec: <https://webassembly.github.io/spec/core/exec/runtime.html#memory-instances>
#[derive(Debug, Clone)] #[derive(Debug, Clone, PartialEq)]
pub struct Memory(pub(crate) memory_impl::Memory); pub struct Memory(pub(crate) memory_impl::Memory);
impl Memory { impl Memory {
@@ -148,12 +148,6 @@ impl Memory {
} }
} }
impl std::cmp::PartialEq for Memory {
fn eq(&self, other: &Self) -> bool {
self.0 == other.0
}
}
impl std::cmp::Eq for Memory {} impl std::cmp::Eq for Memory {}
impl<'a> Exportable<'a> for Memory { impl<'a> Exportable<'a> for Memory {

View File

@@ -25,7 +25,7 @@ use crate::store::{AsStoreMut, AsStoreRef};
/// can be imported or exported. /// can be imported or exported.
/// ///
/// Spec: <https://webassembly.github.io/spec/core/exec/runtime.html#external-values> /// Spec: <https://webassembly.github.io/spec/core/exec/runtime.html#external-values>
#[derive(Clone)] #[derive(Clone, PartialEq)]
pub enum Extern { pub enum Extern {
/// A external [`Function`]. /// A external [`Function`].
Function(Function), Function(Function),

View File

@@ -20,7 +20,7 @@ use crate::Value;
/// mutable from both host and WebAssembly. /// mutable from both host and WebAssembly.
/// ///
/// Spec: <https://webassembly.github.io/spec/core/exec/runtime.html#table-instances> /// Spec: <https://webassembly.github.io/spec/core/exec/runtime.html#table-instances>
#[derive(Debug, Clone)] #[derive(Debug, Clone, PartialEq)]
pub struct Table(pub(crate) table_impl::Table); pub struct Table(pub(crate) table_impl::Table);
impl Table { impl Table {
@@ -113,12 +113,6 @@ impl Table {
} }
} }
impl std::cmp::PartialEq for Table {
fn eq(&self, other: &Self) -> bool {
self.0 == other.0
}
}
impl std::cmp::Eq for Table {} impl std::cmp::Eq for Table {}
impl<'a> Exportable<'a> for Table { impl<'a> Exportable<'a> for Table {

View File

@@ -304,7 +304,7 @@ macro_rules! import_namespace {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use crate::store::{AsStoreMut, Store}; use crate::store::Store;
use crate::value::Value; use crate::value::Value;
use crate::Extern; use crate::Extern;
use crate::Global; use crate::Global;

View File

@@ -23,7 +23,7 @@ fn get_function(store: &mut impl AsStoreMut, val: Value) -> Result<Function, Run
match val { match val {
Value::FuncRef(Some(ref func)) => Ok(func.0.handle.function.clone().into()), Value::FuncRef(Some(ref func)) => Ok(func.0.handle.function.clone().into()),
// Only funcrefs is supported by the spec atm // Only funcrefs is supported by the spec atm
_ => unimplemented!(), _ => unimplemented!("The {val:?} is not yet supported"),
} }
} }

View File

@@ -14,7 +14,7 @@ use wasmer_vm::{
VMFunction, VMFunctionBody, VMFunctionContext, VMFunctionKind, VMTrampoline, VMFunction, VMFunctionBody, VMFunctionContext, VMFunctionKind, VMTrampoline,
}; };
#[derive(Debug, Clone)] #[derive(Debug, Clone, PartialEq)]
pub struct Function { pub struct Function {
pub(crate) handle: StoreHandle<VMFunction>, pub(crate) handle: StoreHandle<VMFunction>,
} }

View File

@@ -228,7 +228,7 @@ mod tests {
#[test] #[test]
fn check_customtunables() -> Result<(), Box<dyn std::error::Error>> { fn check_customtunables() -> Result<(), Box<dyn std::error::Error>> {
use crate::{imports, wat2wasm, Instance, Memory, Module, Store}; use crate::{imports, wat2wasm, Engine, Instance, Memory, Module, Store};
use wasmer_compiler_cranelift::Cranelift; use wasmer_compiler_cranelift::Cranelift;
let wasm_bytes = wat2wasm( let wasm_bytes = wat2wasm(
@@ -242,7 +242,9 @@ mod tests {
let compiler = Cranelift::default(); let compiler = Cranelift::default();
let tunables = TinyTunables {}; let tunables = TinyTunables {};
let mut store = Store::new_with_tunables(compiler, tunables); let mut engine = Engine::new(compiler.into(), Default::default(), Default::default());
engine.set_tunables(tunables);
let mut store = Store::new(engine);
//let mut store = Store::new(compiler); //let mut store = Store::new(compiler);
let module = Module::new(&store, wasm_bytes)?; let module = Module::new(&store, wasm_bytes)?;
let import_object = imports! {}; let import_object = imports! {};