Stream: general

Topic: Passing arrayref to a host function?


view this post on Zulip Talin (Dec 17 2024 at 23:28):

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();

Also: what's the best way to access the bytes of the array as a string?

view this post on Zulip Alex Crichton (Dec 17 2024 at 23:49):

I think that might be a bug because that looks like it's expected to work, mind filing an issue?

For getting the array as a string we need to add APIs to do that, they're not currently present on ArrayRef so you'd have to access it byte-by-byte (which probably isn't the speediest)

view this post on Zulip Alex Crichton (Dec 17 2024 at 23:51):

hm so my guess is that it's (array mut i8) vs (array i8), we might not have anything in the API to match that

view this post on Zulip Alex Crichton (Dec 17 2024 at 23:51):

but if you try changing the type to (array mut i8) it may work for now?

view this post on Zulip Alex Crichton (Dec 17 2024 at 23:52):

(I could also be totally off)

view this post on Zulip Talin (Dec 18 2024 at 01:01):

Changing from types.ty().array(&StorageType::I8, false) to types.ty().array(&StorageType::I8, true)didn't seem to make any difference. Even the error message was the same.

view this post on Zulip Alex Crichton (Dec 18 2024 at 01:04):

Ah ok I'm just barking up the wrong tree then, we can properly investigate this in an issue

view this post on Zulip Talin (Dec 18 2024 at 01:08):

Bug filed: https://github.com/bytecodealliance/wasmtime/issues/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)) ...

view this post on Zulip Alex Crichton (Dec 18 2024 at 01:09):

Thanks!


Last updated: Dec 23 2024 at 13:07 UTC