wabt icon indicating copy to clipboard operation
wabt copied to clipboard

Typed funcref: handle unbound type names in validation

Open takikawa opened this issue 3 years ago • 2 comments

An example program like the following should fail during validation:

;;; TOOL: wat2wasm
;;; ARGS: --enable-function-references
;;; ERROR: 1
(module
  (func (param $f (ref $x)) (result f32))
  )
(;; STDERR ;;;
;;; STDERR ;;)

Because the ref $x is unbound.

Right now this will trigger an assertion failure:

  +wat2wasm: ../../../src/wast-parser.cc:283: void wabt::(anonymous namespace)::ResolveTypeName(const wabt::Module &, wabt::Type &, wabt::Index, const std::unordered_map<uint32_t, std::string> &): Assertion `type_index != kInvalidIndex' failed.

which is erroring too soon. Instead, the representation of parsed types should probably include a Var so that the name lookup can be done in validation, when the entire module state is built up already.

takikawa avatar Apr 05 '22 02:04 takikawa

I am new here, and may misunderstand something but the IsModuleField(PeekPair()) while loop completes in WastParser::ParseModuleFieldList before calling ResolveFuncTypes(module, errors_), so all types should be available.

https://github.com/WebAssembly/wabt/blob/main/src/wast-parser.cc#L1165

I try to figure out what is happening here.

zherczeg avatar Apr 11 '22 09:04 zherczeg

#1892 eliminates the assert issue

zherczeg avatar Apr 11 '22 09:04 zherczeg