Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Canonical ABI functions with over 16 parameters result in IntoFunc not implemented for Wasmtime #134

Closed
radu-matei opened this issue Jan 24, 2022 · 2 comments

Comments

@radu-matei
Copy link
Member

radu-matei commented Jan 24, 2022

The following WIT file, implemented as an export in Wasmtime, results in a compilation error:

 --> src/lib.rs:1:1
  |
1 | wit_bindgen_wasmtime::export!("test.wit");
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `IntoFunc<T, _, _>` is not implemented for `[closure@src/lib.rs:1:1: 1:43]`

The peculiar aspect of this is that commenting out various fields seems to bypass the issue:

record param1 {
    a: list<u8>,
    b: list<u8>,
    // commenting one list field also makes this compile
    c: list<u8>,
}

record param2 {
    g: bool,
    h: bool,
    // commenting the following field makes this compile
    i: bool,
    j: param1,
}

record ret {
    d: list<u8>,
    e: list<u8>,
    f: list<u8>,
}

enum error {
    fatal
}

testfunc: function(p1: param1, p2: option<param2>) -> expected<ret, error>

The Rust implementation:

wit_bindgen_wasmtime::export!("test.wit");

struct Test {}

impl test::Test for Test {
    fn testfunc(
        &mut self,
        p1: test::Param1<'_>,
        p2: Option<test::Param2<'_>>,
    ) -> Result<test::Ret, test::Error> {
        todo!()
    }
}

Here is the repository with the repro — https://github.com/radu-matei/wit-bindgen-wasmtime-intofunc-repro

Thanks to @flavio for initially raising this in fermyon/wasi-experimental-toolkit#9

@alexcrichton
Copy link
Member

I think that the reason this is happening is that this is hitting the limit of the number of arguments for functions in Wasmtime. The IntoFunc trait is implemented for up to 16-argument functions, and this looks like it's trying to generate a function that has more than 16 arguments.

One thing we could consider is to place a limit on the maximum number of arguments for canonical abi functions to solve this, but then there's the other detail of finding space in linear memory to insert all the other arguments which can be tricky. Overall I don't think that there's a great solution for this right now, and it may mean that the current canonical ABI lowering needs to be improved.

@radu-matei radu-matei changed the title Various combinations of fundamental values and lists result in IntoFunc not implemented for Wasmtime Canonical ABI functions with over 16 parameters result in IntoFunc not implemented for Wasmtime Jan 24, 2022
@alexcrichton
Copy link
Member

This'll get fixed in the new canonical ABI so I'm going to close this in favor of #201

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants