diff --git a/crates/wasmi/src/engine/func_types.rs b/crates/wasmi/src/engine/func_types.rs index 1256c18f93..843bb5e0a1 100644 --- a/crates/wasmi/src/engine/func_types.rs +++ b/crates/wasmi/src/engine/func_types.rs @@ -1,7 +1,6 @@ use super::{EngineIdx, Guarded}; -use crate::{FuncType, Store}; +use crate::FuncType; use wasmi_arena::{DedupArena, GuardedEntity, Index}; -use wasmi_core::ValueType; /// A raw index to a function signature entity. #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)] @@ -49,15 +48,6 @@ impl DedupFuncType { pub(super) fn into_inner(self) -> GuardedEntity { self.0 } - - /// Creates a new function signature to the store. - pub fn new(ctx: &mut Store, inputs: I, outputs: O) -> Self - where - I: IntoIterator, - O: IntoIterator, - { - ctx.alloc_func_type(FuncType::new(inputs, outputs)) - } } /// A [`FuncType`] registry that efficiently deduplicate stored function types. diff --git a/crates/wasmi/src/linker.rs b/crates/wasmi/src/linker.rs index 153e9ad930..be7ab6cc5e 100644 --- a/crates/wasmi/src/linker.rs +++ b/crates/wasmi/src/linker.rs @@ -376,11 +376,12 @@ impl Linker { ModuleImportType::Func(expected_func_type) => { let func = resolved.and_then(Extern::into_func).ok_or_else(make_err)?; let actual_func_type = func.signature(&context); + let actual_func_type = context.store.resolve_func_type(actual_func_type); if &actual_func_type != expected_func_type { return Err(LinkerError::FuncTypeMismatch { name: import.name().clone(), - expected: context.store.resolve_func_type(*expected_func_type), - actual: context.store.resolve_func_type(actual_func_type), + expected: expected_func_type.clone(), + actual: actual_func_type, }) .map_err(Into::into); } diff --git a/crates/wasmi/src/module/instantiate/error.rs b/crates/wasmi/src/module/instantiate/error.rs index a17bd61e7f..0666894e10 100644 --- a/crates/wasmi/src/module/instantiate/error.rs +++ b/crates/wasmi/src/module/instantiate/error.rs @@ -1,9 +1,9 @@ use super::ModuleImportType; use crate::{ - engine::DedupFuncType, errors::{MemoryError, TableError}, global::GlobalError, Extern, + FuncType, Table, }; use core::{fmt, fmt::Display}; @@ -25,9 +25,9 @@ pub enum InstantiationError { /// Caused when a function has a mismatching signature. SignatureMismatch { /// The expected function signature for the function import. - expected: DedupFuncType, + expected: FuncType, /// The actual function signature for the function import. - actual: DedupFuncType, + actual: FuncType, }, /// Occurs when an imported table does not satisfy the required table type. Table(TableError), diff --git a/crates/wasmi/src/module/instantiate/mod.rs b/crates/wasmi/src/module/instantiate/mod.rs index cd7fdb5f12..bbf4cd492f 100644 --- a/crates/wasmi/src/module/instantiate/mod.rs +++ b/crates/wasmi/src/module/instantiate/mod.rs @@ -10,6 +10,7 @@ use crate::{ Error, Extern, FuncEntity, + FuncType, Global, Instance, InstanceEntity, @@ -121,6 +122,9 @@ impl Module { match (import.item_type(), external) { (ModuleImportType::Func(expected_signature), Extern::Func(func)) => { let actual_signature = func.signature(context.as_context()); + let actual_signature = self + .engine + .resolve_func_type(actual_signature, FuncType::clone); // Note: We can compare function signatures without resolving them because // we deduplicate them before registering. Therefore two equal instances of // [`SignatureEntity`] will be associated to the same [`Signature`]. @@ -128,7 +132,7 @@ impl Module { // Note: In case of error we could resolve the signatures for better error readability. return Err(InstantiationError::SignatureMismatch { actual: actual_signature, - expected: *expected_signature, + expected: expected_signature.clone(), }); } builder.push_func(func); diff --git a/crates/wasmi/src/module/mod.rs b/crates/wasmi/src/module/mod.rs index efc4e579c0..d4ffd8589e 100644 --- a/crates/wasmi/src/module/mod.rs +++ b/crates/wasmi/src/module/mod.rs @@ -39,6 +39,7 @@ use crate::{ engine::{DedupFuncType, FuncBody}, Engine, Error, + FuncType, GlobalType, MemoryType, TableType, @@ -182,6 +183,7 @@ impl Module { let len_imported_funcs = self.imports.len_funcs; let len_imported_globals = self.imports.len_globals; ModuleImportsIter { + engine: &self.engine, names: self.imports.items.iter(), funcs: self.funcs[..len_imported_funcs].iter(), tables: self.tables.iter(), @@ -228,6 +230,7 @@ impl Module { /// An iterator over the imports of a [`Module`]. #[derive(Debug)] pub struct ModuleImportsIter<'a> { + engine: &'a Engine, names: SliceIter<'a, Imported>, funcs: SliceIter<'a, DedupFuncType>, tables: SliceIter<'a, TableType>, @@ -246,7 +249,8 @@ impl<'a> Iterator for ModuleImportsIter<'a> { let func_type = self.funcs.next().unwrap_or_else(|| { panic!("unexpected missing imported function for {name:?}") }); - ModuleImport::new(name, *func_type) + let func_type = self.engine.resolve_func_type(*func_type, FuncType::clone); + ModuleImport::new(name, func_type) } Imported::Table(name) => { let table_type = self.tables.next().unwrap_or_else(|| { @@ -330,7 +334,7 @@ pub enum ModuleImportType { /// An imported [`Func`]. /// /// [`Func`]: [`crate::Func`] - Func(DedupFuncType), + Func(FuncType), /// An imported [`Table`]. /// /// [`Table`]: [`crate::Table`] @@ -345,8 +349,8 @@ pub enum ModuleImportType { Global(GlobalType), } -impl From for ModuleImportType { - fn from(func_type: DedupFuncType) -> Self { +impl From for ModuleImportType { + fn from(func_type: FuncType) -> Self { Self::Func(func_type) } }