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

Confusion about table with anyref #42

Closed
jpopesculian opened this issue Feb 6, 2020 · 6 comments
Closed

Confusion about table with anyref #42

jpopesculian opened this issue Feb 6, 2020 · 6 comments

Comments

@jpopesculian
Copy link

I'm trying to use cargo wasi in conjunction with wasmtime and I'm having difficulties, because I'd like to use the wasm interface types. For example I have a simple rust lib:

use wasm_bindgen::prelude::*;

#[wasm_bindgen]
pub fn add(a: i32, b: i32) -> i32 {
    a + b
}

When I compile it with cargo wasi build --release, I get the Webassembly module (printed with wasmprinter):

(module
  (type (;0;) (func (param i32 i32) (result i32)))
  (func $add (type 0) (param i32 i32) (result i32)
    local.get 1
    local.get 0
    i32.add)
  (table (;0;) 32 anyref)
  (memory (;0;) 17)
  (global (;0;) (mut i32) (i32.const 1048576))
  (export "memory" (memory 0))
  (export "add" (func $add))
  (data (;0;) (i32.const 1048576) "\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"))

However, the table with anyref generated always seems to throw an error. Specifically with wasmtime::Config.wasm_reference_types enabled:

thread 'main' panicked at 'not implemented: tables of types other than anyfunc (r64)'

I don't know if this is expected behavior, and I'm also confused on why the table is generated in the first place. Any help and explanation would be greatly appreciated

@jpopesculian
Copy link
Author

Version Information:

cargo-wasi 0.1.20 (698008a73d 2020-02-04)
wasm_bindgen 0.2.58
wasmtime / wastime_interface_types 0.9.0 (c9dce98ba21)

@fitzgen
Copy link
Member

fitzgen commented Feb 6, 2020

Wasmtime doesn't have full anyref support yet, notably it is currently missing support for anyref tables. These are coming soon tho!

@alexcrichton
Copy link
Member

Yes it looks like wasm-bindgen will unconditionally emit the anyref table, even though it doesn't use it. This is arguably a bug though!

Like @fitzgen said though the wasmtime crate nor CLI implement the full reference types proposal yet, so that's still very much a work in progress. Until that's implemented the demos with wasm-bindgen unfortunately may not work for a bit.

@alexcrichton
Copy link
Member

In the meantime though I think this is otherwise working as expected, so I'm going to close in favor of bytecodealliance/wasmtime#285

@alexcrichton
Copy link
Member

I've also opened up rustwasm/wasm-bindgen#1992 to track wasm-bindgen's removal of the table if it's not needed.

@Drakulix
Copy link

Drakulix commented Feb 7, 2020

Version Information:

cargo-wasi 0.1.20 (698008a73d 2020-02-04)
wasm_bindgen 0.2.58
wasmtime / wastime_interface_types 0.9.0 (c9dce98ba21)

If you still want to play around with it wasm-bindgen = "=0.2.54" seems to generate wasm files that can be loaded by wasmtime.

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

4 participants