andyherbert opened issue #3661:
Feature
Currently wasmtime panics if too many imports are provided to an instance, however in a warm module imports may be optimised away (for example with AssemblyScript), if calls to these imports are unreachable or not present.
Benefit
My particular use case is that I am embedding wasmtime in a Rust application and providing hooks to the host application, in the very likely event that someone writing the wasm module decides not to use one or more of the hooks then my application fails as I would be providing too many imports.
Implementation
Alternatives
alexcrichton commented on issue #3661:
Can you provide example code and/or an example module that triggers this? Excessive imports can theoretically reach a validation error if there's too many but that shouldn't result in a panic, that's definitely a bug in Wasmtime.
andyherbert commented on issue #3661:
The problem isn't because of an excessive amount of imports, it's due to the import being optimised away by (in this case) binaryen.
declare namespace env { export function foo(): void export function bar(): void } env.foo(); // env.bar();
let foo = Func::wrap(&mut store, |_: Caller<'_, u32>| {}); let bar = Func::wrap(&mut store, |_: Caller<'_, u32>| {}); let instance = Instance::new(&mut store, &module, &[foo.into(), bar.into()]).expect("instance");
thread 'main' panicked at 'instance: expected 1 imports, found 2'
alexcrichton commented on issue #3661:
Ah ok, thanks for the clarification. This is not a panic in Wasmtime but rather a panic in your code (the
expect
). This is also due to the low-level nature ofInstance::new
. For your use case I'd recommend usingLinker
to instantiate modules which does name-based resolution which is probably what you want.
alexcrichton closed issue #3661:
Feature
Currently wasmtime panics if too many imports are provided to an instance, however in a warm module imports may be optimised away (for example with AssemblyScript), if calls to these imports are unreachable or not present.
Benefit
My particular use case is that I am embedding wasmtime in a Rust application and providing hooks to the host application, in the very likely event that someone writing the wasm module decides not to use one or more of the hooks then my application fails as I would be providing too many imports.
Implementation
Alternatives
andyherbert commented on issue #3661:
Ah okay, I must have missed the Linker, many thanks.
Last updated: Dec 23 2024 at 12:05 UTC