fitzgen edited issue #9848:
I'm getting this error:
types incompatible: expected type `(func (param (ref array (engine 5))))`, found type `(func (param (ref array)))`
The wasm looks like this:
(type $String (;3;) (array i8)) (type $debug.type (;4;) (func (param (ref $String)))) (import "host" "debug" (func $debug (;0;) (type $debug.type)))
And I'm registering the function like this:
let engine = wasmtime::Engine::new(&config).unwrap(); let store = wasmtime::Store::<StoreData>::new(&engine, ()); let mut linker = wasmtime::Linker::new(&engine); linker .func_wrap( "host", "debug", |caller: Caller<'_, StoreData>, param: Rooted<ArrayRef>| { // ... }, ) .unwrap();
Test Case
(module $hello.saga (type $hello.type (;0;) (func (result i32))) (type $add.type (;1;) (func (param i32) (result i32))) (type $name.type (;2;) (func)) (type $String (;3;) (array (mut i8))) (type $debug.type (;4;) (func (param (ref $String)))) (import "host" "debug" (func $debug (;0;) (type $debug.type))) (export "hello" (func $hello)) (func $hello (;1;) (type $hello.type) (result i32) i32.const 1 call $add i32.const 2 i32.add f32.const 0x1.8p+1 (;=3;) i32.trunc_f32_s i32.add return ) (func $add (;2;) (type $add.type) (param i32) (result i32) (local i32) i32.const 1 local.set 1 local.get 0 local.get 1 i32.add return ) (func $name (;3;) (type $name.type) i32.const 0 i32.const 15 array.new_data $String 0 call $debug ) (data (;0;) "Hello from SAGA") )
Steps to Reproduce
Create an Engine and Linker.
Bind a function which accepts an ArrayRef as a parameter.
Attempt to load the script.Expected Results
Script should load without error (it loads if I delete the code that calls the host func).
Actual Results
Error when I attempt to instantiate the script.
Versions and Environment
Wasmtime version or commit:
{ version = "27.0.0", features = ["gc", "gc-drc"] }
Operating system: OS X
Architecture: M2
fitzgen edited issue #9848:
Edit by @fitzgen: The OP described behavior is subtle but expected. To allow
Func::wrap
-style APIs to be used with specific function type subtypes, we should add aFunc::wrap_with_type
constructor. See this comment for some more details.
<details>
<summary>original issue report </summary>
I'm getting this error:
types incompatible: expected type `(func (param (ref array (engine 5))))`, found type `(func (param (ref array)))`
The wasm looks like this:
(type $String (;3;) (array i8)) (type $debug.type (;4;) (func (param (ref $String)))) (import "host" "debug" (func $debug (;0;) (type $debug.type)))
And I'm registering the function like this:
let engine = wasmtime::Engine::new(&config).unwrap(); let store = wasmtime::Store::<StoreData>::new(&engine, ()); let mut linker = wasmtime::Linker::new(&engine); linker .func_wrap( "host", "debug", |caller: Caller<'_, StoreData>, param: Rooted<ArrayRef>| { // ... }, ) .unwrap();
Test Case
(module $hello.saga (type $hello.type (;0;) (func (result i32))) (type $add.type (;1;) (func (param i32) (result i32))) (type $name.type (;2;) (func)) (type $String (;3;) (array (mut i8))) (type $debug.type (;4;) (func (param (ref $String)))) (import "host" "debug" (func $debug (;0;) (type $debug.type))) (export "hello" (func $hello)) (func $hello (;1;) (type $hello.type) (result i32) i32.const 1 call $add i32.const 2 i32.add f32.const 0x1.8p+1 (;=3;) i32.trunc_f32_s i32.add return ) (func $add (;2;) (type $add.type) (param i32) (result i32) (local i32) i32.const 1 local.set 1 local.get 0 local.get 1 i32.add return ) (func $name (;3;) (type $name.type) i32.const 0 i32.const 15 array.new_data $String 0 call $debug ) (data (;0;) "Hello from SAGA") )
Steps to Reproduce
Create an Engine and Linker.
Bind a function which accepts an ArrayRef as a parameter.
Attempt to load the script.Expected Results
Script should load without error (it loads if I delete the code that calls the host func).
Actual Results
Error when I attempt to instantiate the script.
Versions and Environment
Wasmtime version or commit:
{ version = "27.0.0", features = ["gc", "gc-drc"] }
Operating system: OS X
Architecture: M2
</details>
Last updated: Apr 17 2025 at 01:31 UTC