Bug 1716869 - Part 1, move test imports before definitions r=rhunt

The Wasm spec for the text format specifies that imports should come
before definitions:

  The second condition enforces that all imports must occur before any
  regular definition of a function, table, memory, or global, thereby
  maintaining the ordering of the respective index spaces.

  https://webassembly.github.io/spec/core/text/modules.html#text-module

However, this was not enforced for the test parser until recently.

Differential Revision: https://phabricator.services.mozilla.com/D118082
This commit is contained in:
Asumu Takikawa 2021-06-21 19:19:12 +00:00
Родитель d5a7547bd7
Коммит 2647ce5160
6 изменённых файлов: 19 добавлений и 20 удалений

Просмотреть файл

@ -4,6 +4,9 @@ var conf = getBuildConfiguration();
var bin = wasmTextToBinary(
`(module
(func $x1 (import "m" "x1") (type $f1))
(func $x2 (import "m" "x2") (type $f2))
(table 2 funcref)
(elem (i32.const 0) $doit $doitagain)
@ -38,9 +41,6 @@ var bin = wasmTextToBinary(
;; Various ways to reference a type in the middle of the
;; type array, make sure we get the right one
(func $x1 (import "m" "x1") (type $f1))
(func $x2 (import "m" "x2") (type $f2))
(func (export "hello") (param f64) (param i32) (result f64)
(call_indirect (type $f2) (local.get 0) (local.get 1)))

Просмотреть файл

@ -33,6 +33,12 @@ function gen_tab_impmod_t(insn)
`(module
;; -------- Types --------
(type (func (result i32))) ;; type #0
;; -------- Imports --------
(import "a" "if0" (func (result i32))) ;; index 0
(import "a" "if1" (func (result i32)))
(import "a" "if2" (func (result i32)))
(import "a" "if3" (func (result i32)))
(import "a" "if4" (func (result i32))) ;; index 4
;; -------- Tables --------
(table 30 30 funcref)
;; -------- Table initialisers --------
@ -40,12 +46,6 @@ function gen_tab_impmod_t(insn)
(elem func 2 7 1 8)
(elem (i32.const 12) 7 5 2 3 6)
(elem func 5 9 2 7 6)
;; -------- Imports --------
(import "a" "if0" (func (result i32))) ;; index 0
(import "a" "if1" (func (result i32)))
(import "a" "if2" (func (result i32)))
(import "a" "if3" (func (result i32)))
(import "a" "if4" (func (result i32))) ;; index 4
;; -------- Functions --------
(func (result i32) (i32.const 5)) ;; index 5
(func (result i32) (i32.const 6))

Просмотреть файл

@ -16,14 +16,13 @@ const {Module,Instance} = WebAssembly;
let t =
`(module
(import "" "check3" (func $check3 (param externref) (param externref) (param externref)))
(import "" "alloc" (func $alloc (result externref)))
(type $typeOfFn0
(func (param i32) (param externref) (param i32)
(param externref) (param externref) (param i32) (result i32)))
(table 1 1 funcref)
(elem (i32.const 0) $fn0)
(import "" "alloc" (func $alloc (result externref)))
;; -- fn 0
(func $fn0 (export "fn0")
(param $arg1 i32) (param $arg2 externref) (param $arg3 i32)

Просмотреть файл

@ -29,13 +29,14 @@ let t =
(type $typeOfFn0
(func (param i32) (param externref) (param i32)
(param externref) (param externref) (param i32) (result i32)))
(table 1 1 funcref)
(elem (i32.const 0) $fn0)
(import "" "alloc" (func $alloc (result externref)))
(import "" "quitp" (func $quitp (result i32)))
(import "" "check3" (func $check3 (param externref) (param externref) (param externref)))
(table 1 1 funcref)
(elem (i32.const 0) $fn0)
;; -- fn 0
(func $fn0 (export "fn0")
(param $arg1 i32) (param $arg2 externref) (param $arg3 i32)

Просмотреть файл

@ -61,19 +61,18 @@ var exp = {m:{t0: new WebAssembly.Table({element:"funcref", initial:2}),
var ins = wasmEvalText(
`(module
(table $t0 (import "m" "t0") 2 funcref)
(table $t1 (import "m" "t1") 3 externref)
(table $t2 (import "m" "t2") 4 funcref)
(table $t3 (import "m" "t3") 5 externref)
(type $id_i32_t (func (param i32) (result i32)))
(func $id_i32 (param i32) (result i32) (local.get 0))
(elem (table $t0) (i32.const 1) func $id_i32)
(table $t1 (import "m" "t1") 3 externref)
(table $t2 (import "m" "t2") 4 funcref)
(type $id_f64_t (func (param f64) (result f64)))
(func $id_f64 (param f64) (result f64) (local.get 0))
(elem (table $t2) (i32.const 3) func $id_f64)
(table $t3 (import "m" "t3") 5 externref)
(func (export "f0") (param i32) (result i32)
(call_indirect $t0 (type $id_i32_t) (local.get 0) (i32.const 1)))

Просмотреть файл

@ -5,10 +5,10 @@
let mt = `
(module
(memory 1 1)
(data (i32.const 0) "\\01\\00\\00\\00\\01\\00\\00\\00\\01\\00\\00\\00")
(import "m" "g" (global (mut i32)))
(import "m" "h" (global (mut i32)))
(memory 1 1)
(data (i32.const 0) "\\01\\00\\00\\00\\01\\00\\00\\00\\01\\00\\00\\00")
(func (export "f") (result i32)
(local i32)
(local i32)