Skip to content
This repository has been archived by the owner on Jun 24, 2022. It is now read-only.

funcref vs anyfunc #448

Open
tpmccallum opened this issue Dec 29, 2019 · 1 comment
Open

funcref vs anyfunc #448

tpmccallum opened this issue Dec 29, 2019 · 1 comment

Comments

@tpmccallum
Copy link

I compiled a simple Rust library

#[no_mangle]
pub extern fn one_plus_one() -> i32 {
 1 + 1
}

The wat text representation of this code is as follows

(module
  (type (;0;) (func (result i32)))
  (func $one_plus_one (type 0) (result i32)
    i32.const 2)
  (table (;0;) 1 1 funcref)
  (memory (;0;) 16)
  (global (;0;) (mut i32) (i32.const 1048576))
  (global (;1;) i32 (i32.const 1048576))
  (global (;2;) i32 (i32.const 1048576))
  (export "memory" (memory 0))
  (export "__data_end" (global 1))
  (export "__heap_base" (global 2))
  (export "one_plus_one" (func $one_plus_one)))

Please note the line (table (;0;) 1 1 funcref)

Issue

When I build and execute the above wat, I get the following error.

test.wat:5:20: error: unexpected token funcref, expected anyfunc.
  (table (;0;) 1 1 funcref)

Solution

I note that the WebAssembly wat specification has been updated [1], specifically to use funcref instead of anyfunc for table declaration. The Rust compiler and the wasm to wat conversion tool wabt [2], that I am using appear to adhere to the newerfuncref spec.

Of course, if I change funcref back to anyfunc then the WebAssemblyStudio IDE will build and run the code.

Just wanted to let you know my experience and I am wondering if/when WebAssemblyStudio will adopt the wat spec as per the link below.

Thanks
Tim

[1] WebAssembly/spec#884 (comment)
[2] https://github.com/WebAssembly/wabt

@pfandzelter
Copy link

I actually ran into the same issue with funcref vs anyfunc. Link [1] you mention does include some more updates. For example, get_local has officially been replaced with local.get. WebAssemblyStudio uses the old version while my compiler (wasm2wat) uses the newer spec.

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

No branches or pull requests

2 participants