WebAssembly / gc

Branch of the spec repo scoped to discussion of GC integration in WebAssembly
https://webassembly.github.io/gc/
Other
997 stars 72 forks source link

Section ordering issue in global.wast test #433

Closed eqrion closed 1 year ago

eqrion commented 1 year ago

See https://github.com/WebAssembly/gc/blob/main/test/core/global.wast#L622.

(module
  ...
  (global $gn funcref (ref.null func))
  ...
  (table $t 10 funcref (global.get $gn))
)

This module is supposed to be valid, and has a table with a default value expression referencing a global. However the global section comes after the table section, so when validating the global.get in the table, $gn has not been decoded yet.

Also, it looks like the text format for table default value initializers is not written yet.

titzer commented 1 year ago

I hit this exact case a couple days ago too. AFAICT this was introduced in the function-references proposal but only the GC repo has a test for it. I had asked @rossberg offline about how this is handled in the reference interpreter.

Was the global reference intended behavior? Because that implies initializer expressions cannot be checked until after the global section, because it cannot get the type of the global otherwise. Also, that implies a parser needs to be able to parse instructions (to compute init expr length) without actually typechecking them.

rossberg commented 1 year ago

Indeed, this was an oversight in #420, thanks for pointing out. PTAL at #434.