wasp icon indicating copy to clipboard operation
wasp copied to clipboard

wasp encodes element sections differently than binaryen [typed function references]

Open dbezhetskov opened this issue 2 years ago • 2 comments

The example func_ref_o.wat:

(module
  (func (export "main") (result i32)
    (call_ref (i32.const 10)
              (ref.func $foo)
    )
  )
  (func $foo (param $x i32) (result i32)
    (i32.add (local.get $x)
             (i32.const 19))
  )
  (elem declare funcref (ref.func $foo))
)

wasp wat2wasm --enable-function-references:

Contents of section element:
0000025: 0107 7001 d201 0b                        ..p....

binaryen wasm-as --enable-reference-types:

Contents of section element:
0000025: 0103 0001 01                             .....

wasp encodes element section as vec(expr) and binaryen encodes it as vec(func_idx), according to the https://github.com/WebAssembly/function-references/blob/master/proposals/function-references/Overview.md there is no any evidence that vec(expr) should be used.

Is it a bug?

dbezhetskov avatar Jul 09 '21 11:07 dbezhetskov

If someone can confirm, I can make a fix.

dbezhetskov avatar Jul 09 '21 11:07 dbezhetskov

IIRC, they are both allowed and equivalent. Has that changed recently? I suppose it would be best for tools to choose the smaller size, where possible.

binji avatar Aug 02 '21 18:08 binji