Stream: wasmtime

Topic: ✔ Wit Tuple: failed to convert function `...` to given type


view this post on Zulip Ari Seyhun (Nov 28 2023 at 12:58):

I've modified a wit file I'm working with from being just a string to use a tuple<string, string>.
After this change, when I load the wasm component into wasmtime, I get a runtime error:

failed to convert function `[method]agg.apply` to given type

I'm using wasmtime 0.15, and wit-bindgen 0.15.
This code was working fine when using just the string directly.

My entire wit file looks like:

package thalo:aggregate;

world aggregate {
    export aggregate: interface {
        record event {
            event: string,
            payload: string,
        }

        record command {
            command: string,
            payload: string,
        }

        variant error {
            command(string),
            deserialize-command(tuple<string, string>), // This worked when it was just a (string)
            deserialize-context(string),
            deserialize-event(tuple<string, string>), // and this
            serialize-error(string),
            serialize-event(tuple<string, string>), // and this
        }

        resource agg {
            constructor(id: string);
            apply: func(events: list<event>) -> result<_, error>;
            handle: func(command: command) -> result<list<event>, error>;
        }
    }
}

view this post on Zulip Alex Crichton (Nov 28 2023 at 14:47):

I think this is an error message which would result from the embedding code you're using. Can you share the rest of the Wasmtime code? Either that or can you share steps to reproduce?

view this post on Zulip Ari Seyhun (Nov 29 2023 at 12:20):

Well I hope its okay if I just share the link to the Github repo. It's pretty much the same code, but I only changed some of the variants in the error enum from string to tuple<string, string>.

I don't know what I could be doing wrong on my side, as it works before making this change, and the code compiled fine too. Just at runtime it doesn't like it.

Here's where I load the component from file:
https://github.com/thalo-rs/thalo/blob/e64c8f28405a76a38032254ebbc0c7996b2d1e24/crates/thalo_runtime/src/module.rs#L51-L68

Here's the aggregate.wit file:
https://github.com/thalo-rs/thalo/blob/main/crates/thalo_runtime/wit/aggregate.wit

And finally the guest side implementation:
https://github.com/thalo-rs/thalo/blob/e64c8f28405a76a38032254ebbc0c7996b2d1e24/crates/thalo/src/macros.rs#L21-L75

view this post on Zulip Lann Martin (Nov 29 2023 at 13:34):

It looks like you have a copy of the wit inline in the guest code: https://github.com/thalo-rs/thalo/blob/e64c8f28405a76a38032254ebbc0c7996b2d1e24/crates/thalo/src/macros.rs#L22

view this post on Zulip Lann Martin (Nov 29 2023 at 13:34):

If the two copies are out of sync you would get that sort of error.

view this post on Zulip Ari Seyhun (Nov 29 2023 at 13:37):

Though i did copy the changes across so they were identical, i don't believe i did anything wrong

view this post on Zulip Lann Martin (Nov 29 2023 at 13:41):

I have noted odd cache (?) issues with wit-bindgen-rust in the past that have prevented WIT changes from being reflected in generated code. I believe I needed some combination of cargo clean and restarting rust-analyzer to resolve.

view this post on Zulip Ari Seyhun (Nov 29 2023 at 14:08):

Oh okay I'll give it another try in that case, could possibly be the issue

view this post on Zulip Lann Martin (Nov 29 2023 at 14:15):

Let us know if that does resolve it; if there is a latent issue with wit-bindgen-rust we should try to hunt that down.

view this post on Zulip Ari Seyhun (Nov 29 2023 at 23:26):

ah it worked after a cargo clean! I'll have to keep that in mind, thank you!

view this post on Zulip Notification Bot (Nov 29 2023 at 23:26):

Ari Seyhun has marked this topic as resolved.

view this post on Zulip Lann Martin (Nov 30 2023 at 00:09):

https://github.com/bytecodealliance/wit-bindgen/issues/773

There seems to be some issue with wit_bindgen::generate!'s output failing to refresh under some circumstance. This is mostly a placeholder for people to report problems as I haven't seen this repro...

view this post on Zulip Alex Crichton (Nov 30 2023 at 16:50):

@Ari Seyhun would you happen to remember the sequence of steps you did to reproduce this? I'd be interested to dig in further to see if I can reproduce and fix the original issue if there is one in wit-bindgen

view this post on Zulip Lann Martin (Nov 30 2023 at 17:02):

is the let _ = include_bytes!(...); hack still necessary in macros to pick up changes to external files?

view this post on Zulip Alex Crichton (Nov 30 2023 at 17:03):

AFAIK yes

view this post on Zulip Lann Martin (Nov 30 2023 at 17:03):

oh wit-bindgen does include_str :thumbs_up:

view this post on Zulip Ari Seyhun (Dec 01 2023 at 03:44):

I've just tried playing around with the wit types without doing any cargo clean to see if I could replicate it again in my repo, however I can't seem to replicate it now.
I'm doubting myself, if I had done something wrong, but I'm quite sure I didn't since it only worked when I did the cargo clean and without changing any code.

I'll keep playing around some more to see if I can make it happen again and I'll let you know


Last updated: Nov 22 2024 at 17:03 UTC