WebAssembly / reference-types

Proposal for adding basic reference types (anyref)
https://webassembly.github.io/reference-types/
Other
162 stars 40 forks source link

Bug in reference core test #114

Closed q82419 closed 4 years ago

q82419 commented 4 years ago

If I'm correct, the test case in core/ref_func.wast should not pass. https://github.com/WebAssembly/reference-types/blob/master/test/core/ref_func.wast#L80-L106

The following test case got an expected invalid result:

(assert_invalid
  (module (func $f (drop (ref.func $f))))
  "undeclared function reference"
)

Because the $f is not declared in elem.

I think it needs to add (elem declare func $f1 $f2) or (elem declare funcref (ref.func $f1) (ref.func $f2)) into the module in the above mentioned test case? That is:


(module
  (func $f1)
  (func $f2)
  (func $f3)
  (func $f4)
  (func $f5)
  (func $f6)

  (table $t 1 funcref)

  (global funcref (ref.func $f1))
  (export "f" (func $f2))
  (elem declare funcref (ref.func $f1) (ref.func $f2))
  (elem (table $t) (i32.const 0) func $f3)
  (elem (table $t) (i32.const 0) funcref (ref.func $f4))
  (elem func $f5)
  (elem funcref (ref.func $f6))

  (func
    (ref.func $f1)
    (ref.func $f2)
    (ref.func $f3)
    (ref.func $f4)
    (ref.func $f5)
    (ref.func $f6)
    (return)
  )
)
gahaas commented 4 years ago

The point of this test is that this is no longer needed, per the resolution of https://github.com/WebAssembly/reference-types/issues/76. The occurrences in the other declarations are sufficient.

This was the reply to the same question in https://github.com/WebAssembly/reference-types/pull/95

q82419 commented 4 years ago

Got it, thanks. All ocurrences of ref.func in the module environment are treated as declaring a valid ref.func target for the code section. In the above module, the export and global section reference to $f1 and $f2, so the (elem declare func $f1 $f2) is not needed. Right?

gahaas commented 4 years ago

As far as I understand, it's not needed.

binji commented 4 years ago

Yes, that's correct.