From ef01de5ef4e7d5cc772110af2e30cc4fb722784a Mon Sep 17 00:00:00 2001 From: Andreas Rossberg Date: Mon, 12 Dec 2022 23:37:45 +0100 Subject: [PATCH 01/31] [interpreter] Refactor parser to handle select & call_indirect correctly (#1567) --- interpreter/text/parser.mly | 100 +++++++++++------------------------ test/core/call_indirect.wast | 20 +++++++ test/core/select.wast | 17 ++++++ 3 files changed, 67 insertions(+), 70 deletions(-) diff --git a/interpreter/text/parser.mly b/interpreter/text/parser.mly index 535a05d5..7489acf7 100644 --- a/interpreter/text/parser.mly +++ b/interpreter/text/parser.mly @@ -366,12 +366,16 @@ align_opt : /* Instructions & Expressions */ -instr : +instr_list : + | /* empty */ { fun c -> [] } + | instr1 instr_list { fun c -> $1 c @ $2 c } + | select_instr_instr_list { $1 } + | call_instr_instr_list { $1 } + +instr1 : | plain_instr { let at = at () in fun c -> [$1 c @@ at] } - | select_instr_instr { fun c -> let e, es = $1 c in e :: es } - | call_instr_instr { fun c -> let e, es = $1 c in e :: es } | block_instr { let at = at () in fun c -> [$1 c @@ at] } - | expr { $1 } /* Sugar */ + | expr { $1 } /* Sugar */ plain_instr : | UNREACHABLE { fun c -> unreachable } @@ -442,89 +446,51 @@ plain_instr : | VEC_REPLACE NAT { let at = at () in fun c -> $1 (vec_lane_index $2 at) } -select_instr : - | SELECT select_instr_results - { let at = at () in fun c -> let b, ts = $2 in - select (if b then (Some ts) else None) @@ at } - -select_instr_results : - | LPAR RESULT value_type_list RPAR select_instr_results - { let _, ts = $5 in true, $3 @ ts } - | /* empty */ - { false, [] } - -select_instr_instr : - | SELECT select_instr_results_instr +select_instr_instr_list : + | SELECT select_instr_results_instr_list { let at1 = ati 1 in fun c -> let b, ts, es = $2 c in - select (if b then (Some ts) else None) @@ at1, es } + (select (if b then (Some ts) else None) @@ at1) :: es } -select_instr_results_instr : - | LPAR RESULT value_type_list RPAR select_instr_results_instr +select_instr_results_instr_list : + | LPAR RESULT value_type_list RPAR select_instr_results_instr_list { fun c -> let _, ts, es = $5 c in true, $3 @ ts, es } - | instr + | instr_list { fun c -> false, [], $1 c } -call_instr : - | CALL_INDIRECT var call_instr_type - { let at = at () in fun c -> call_indirect ($2 c table) ($3 c) @@ at } - | CALL_INDIRECT call_instr_type /* Sugar */ - { let at = at () in fun c -> call_indirect (0l @@ at) ($2 c) @@ at } - -call_instr_type : - | type_use call_instr_params - { let at1 = ati 1 in - fun c -> - match $2 c with - | FuncType ([], []) -> $1 c type_ - | ft -> inline_type_explicit c ($1 c type_) ft at1 } - | call_instr_params - { let at = at () in fun c -> inline_type c ($1 c) at } - -call_instr_params : - | LPAR PARAM value_type_list RPAR call_instr_params - { fun c -> let FuncType (ts1, ts2) = $5 c in FuncType ($3 @ ts1, ts2) } - | call_instr_results - { fun c -> FuncType ([], $1 c) } - -call_instr_results : - | LPAR RESULT value_type_list RPAR call_instr_results - { fun c -> $3 @ $5 c } - | /* empty */ - { fun c -> [] } - - -call_instr_instr : - | CALL_INDIRECT var call_instr_type_instr +call_instr_instr_list : + | CALL_INDIRECT var call_instr_type_instr_list { let at1 = ati 1 in - fun c -> let x, es = $3 c in call_indirect ($2 c table) x @@ at1, es } - | CALL_INDIRECT call_instr_type_instr /* Sugar */ + fun c -> let x, es = $3 c in + (call_indirect ($2 c table) x @@ at1) :: es } + | CALL_INDIRECT call_instr_type_instr_list /* Sugar */ { let at1 = ati 1 in - fun c -> let x, es = $2 c in call_indirect (0l @@ at1) x @@ at1, es } + fun c -> let x, es = $2 c in + (call_indirect (0l @@ at1) x @@ at1) :: es } -call_instr_type_instr : - | type_use call_instr_params_instr +call_instr_type_instr_list : + | type_use call_instr_params_instr_list { let at1 = ati 1 in fun c -> match $2 c with | FuncType ([], []), es -> $1 c type_, es | ft, es -> inline_type_explicit c ($1 c type_) ft at1, es } - | call_instr_params_instr + | call_instr_params_instr_list { let at = at () in fun c -> let ft, es = $1 c in inline_type c ft at, es } -call_instr_params_instr : - | LPAR PARAM value_type_list RPAR call_instr_params_instr +call_instr_params_instr_list : + | LPAR PARAM value_type_list RPAR call_instr_params_instr_list { fun c -> let FuncType (ts1, ts2), es = $5 c in FuncType ($3 @ ts1, ts2), es } - | call_instr_results_instr + | call_instr_results_instr_list { fun c -> let ts, es = $1 c in FuncType ([], ts), es } -call_instr_results_instr : - | LPAR RESULT value_type_list RPAR call_instr_results_instr +call_instr_results_instr_list : + | LPAR RESULT value_type_list RPAR call_instr_results_instr_list { fun c -> let ts, es = $5 c in $3 @ ts, es } - | instr + | instr_list { fun c -> [], $1 c } @@ -657,12 +623,6 @@ if_ : | LPAR THEN instr_list RPAR /* Sugar */ { fun c c' -> [], $3 c', [] } -instr_list : - | /* empty */ { fun c -> [] } - | select_instr { fun c -> [$1 c] } - | call_instr { fun c -> [$1 c] } - | instr instr_list { fun c -> $1 c @ $2 c } - expr_list : | /* empty */ { fun c -> [] } | expr expr_list { fun c -> $1 c @ $2 c } diff --git a/test/core/call_indirect.wast b/test/core/call_indirect.wast index 1ecd9b7b..79b8dc39 100644 --- a/test/core/call_indirect.wast +++ b/test/core/call_indirect.wast @@ -1015,3 +1015,23 @@ (module (table funcref (elem 0 0))) "unknown function" ) + + + + +;; Flat syntax + +(module + (table 1 funcref) + (func unreachable call_indirect) + (func unreachable call_indirect nop) + (func unreachable call_indirect call_indirect) + (func unreachable call_indirect (call_indirect)) + (func unreachable call_indirect call_indirect call_indirect) + (func unreachable call_indirect (result)) + (func unreachable call_indirect (result) (result)) + (func unreachable call_indirect (result) (result) call_indirect) + (func unreachable call_indirect (result) (result) call_indirect (result)) + (func (result i32) unreachable call_indirect select) + (func (result i32) unreachable call_indirect select call_indirect) +) diff --git a/test/core/select.wast b/test/core/select.wast index 046e6fe2..673dcf47 100644 --- a/test/core/select.wast +++ b/test/core/select.wast @@ -512,3 +512,20 @@ "type mismatch" ) + +;; Flat syntax + +(module + (table 1 funcref) + (func (result i32) unreachable select) + (func (result i32) unreachable select nop) + (func (result i32) unreachable select (select)) + (func (result i32) unreachable select select) + (func (result i32) unreachable select select select) + (func (result i32) unreachable select (result i32)) + (func (result i32) unreachable select (result i32) (result)) + (func (result i32) unreachable select (result i32) (result) select) + (func (result i32) unreachable select (result) (result i32) select (result i32)) + (func (result i32) unreachable select call_indirect) + (func (result i32) unreachable select call_indirect select) +) From a54a1d85400db3cf243717a0ab1cc2fb6098170f Mon Sep 17 00:00:00 2001 From: Andreas Rossberg Date: Thu, 15 Dec 2022 16:23:26 +0100 Subject: [PATCH 02/31] [spec] Remove dead piece of grammar --- document/core/exec/runtime.rst | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/document/core/exec/runtime.rst b/document/core/exec/runtime.rst index 9ee7eccc..6c53a4e9 100644 --- a/document/core/exec/runtime.rst +++ b/document/core/exec/runtime.rst @@ -476,8 +476,8 @@ Intuitively, :math:`\instr^\ast` is the *continuation* to execute when the branc When branching, the empty continuation ends the targeted block, such that execution can proceed with consecutive instructions. -Activations and Frames -...................... +Activation Frames +................. Activation frames carry the return arity :math:`n` of the respective function, hold the values of its :ref:`locals ` (including arguments) in the order corresponding to their static :ref:`local indices `, @@ -485,8 +485,6 @@ and a reference to the function's own :ref:`module instance ` .. math:: \begin{array}{llll} - \production{activation} & \X{activation} &::=& - \FRAME_n\{\frame\} \\ \production{frame} & \frame &::=& \{ \ALOCALS~\val^\ast, \AMODULE~\moduleinst \} \\ \end{array} From 1782235239ddebaf2cb079b00fdaa2d2c4dedba3 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Fri, 16 Dec 2022 00:24:54 +0900 Subject: [PATCH 03/31] [test] elem.wast: force to use exprs in a element (#1561) --- test/core/elem.wast | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test/core/elem.wast b/test/core/elem.wast index 8dc04e6e..5857ae8b 100644 --- a/test/core/elem.wast +++ b/test/core/elem.wast @@ -148,6 +148,25 @@ (assert_return (invoke "call-7") (i32.const 65)) (assert_return (invoke "call-9") (i32.const 66)) +;; Same as the above, but use ref.null to ensure the elements use exprs. +;; Note: some tools like wast2json avoid using exprs when possible. +(module + (type $out-i32 (func (result i32))) + (table 11 funcref) + (elem (i32.const 6) funcref (ref.null func) (ref.func $const-i32-a)) + (elem (i32.const 9) funcref (ref.func $const-i32-b) (ref.null func)) + (func $const-i32-a (type $out-i32) (i32.const 65)) + (func $const-i32-b (type $out-i32) (i32.const 66)) + (func (export "call-7") (type $out-i32) + (call_indirect (type $out-i32) (i32.const 7)) + ) + (func (export "call-9") (type $out-i32) + (call_indirect (type $out-i32) (i32.const 9)) + ) +) +(assert_return (invoke "call-7") (i32.const 65)) +(assert_return (invoke "call-9") (i32.const 66)) + (assert_invalid (module (table 1 funcref) (global i32 (i32.const 0)) (elem (global.get 0) $f) (func $f)) "unknown global" From ca1d792430e353a7de0f2f4948fbb02bb0b83a65 Mon Sep 17 00:00:00 2001 From: Ng Zhi An Date: Tue, 17 Jan 2023 23:47:06 +0000 Subject: [PATCH 04/31] Fix typos in SIMD exec/instructions --- document/core/exec/instructions.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/document/core/exec/instructions.rst b/document/core/exec/instructions.rst index 6b028060..72893d64 100644 --- a/document/core/exec/instructions.rst +++ b/document/core/exec/instructions.rst @@ -394,7 +394,7 @@ Most vector instructions are defined in terms of generic numeric operators appli .. math:: \begin{array}{l} \begin{array}{lcl@{\qquad}l} - (\V128\K{.}\VCONST~c_1)~(\V128\K{.}\VCONST~c_2)~\V128\K{.}\SWIZZLE &\stepto& (\V128\K{.}\VCONST~c') + (\V128\K{.}\VCONST~c_1)~(\V128\K{.}\VCONST~c_2)~\I8X16\K{.}\SWIZZLE &\stepto& (\V128\K{.}\VCONST~c') \end{array} \\ \qquad \begin{array}[t]{@{}r@{~}l@{}} @@ -431,7 +431,7 @@ Most vector instructions are defined in terms of generic numeric operators appli .. math:: \begin{array}{l} \begin{array}{lcl@{\qquad}l} - (\V128\K{.}\VCONST~c_1)~(\V128\K{.}\VCONST~c_2)~\V128\K{.}\SHUFFLE~x^\ast &\stepto& (\V128\K{.}\VCONST~c) + (\V128\K{.}\VCONST~c_1)~(\V128\K{.}\VCONST~c_2)~\I8X16\K{.}\SHUFFLE~x^\ast &\stepto& (\V128\K{.}\VCONST~c) \end{array} \\ \qquad \begin{array}[t]{@{}r@{~}l@{}} From 4c249c5a575e2b0e252e747af261bbb82f448dd4 Mon Sep 17 00:00:00 2001 From: Thomas Lively Date: Wed, 18 Jan 2023 16:34:13 -0600 Subject: [PATCH 05/31] Update interpreter README (#1571) It previously stated that the formal spec did not exist, but the spec has existed for years now. --- interpreter/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interpreter/README.md b/interpreter/README.md index 418b8450..18aa36c0 100644 --- a/interpreter/README.md +++ b/interpreter/README.md @@ -1,6 +1,6 @@ # WebAssembly Reference Interpreter -This repository implements a interpreter for WebAssembly. It is written for clarity and simplicity, _not_ speed. It is intended as a playground for trying out ideas and a device for nailing down the exact semantics, and as a proxy for the (yet to be produced) formal specification of WebAssembly. For that purpose, the code is written in a fairly declarative, "speccy" way. +This repository implements an interpreter for WebAssembly. It is written for clarity and simplicity, _not_ speed. It is intended as a playground for trying out ideas and a device for nailing down their exact semantics. For that purpose, the code is written in a fairly declarative, "speccy" way. The interpreter can From f54b5b81a3649461b4c8be0363844301983868ab Mon Sep 17 00:00:00 2001 From: Andreas Rossberg Date: Tue, 24 Jan 2023 12:22:06 +0100 Subject: [PATCH 06/31] [spec] Remove an obsolete exec step (#1580) --- document/core/exec/instructions.rst | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/document/core/exec/instructions.rst b/document/core/exec/instructions.rst index 72893d64..cc66dbf2 100644 --- a/document/core/exec/instructions.rst +++ b/document/core/exec/instructions.rst @@ -2912,15 +2912,13 @@ Invocation of :ref:`function address ` :math:`a` 7. Pop the values :math:`\val^n` from the stack. -8. Let :math:`\val_0^\ast` be the list of zero values of types :math:`t^\ast`. +8. Let :math:`F` be the :ref:`frame ` :math:`\{ \AMODULE~f.\FIMODULE, \ALOCALS~\val^n~(\default_t)^\ast \}`. -9. Let :math:`F` be the :ref:`frame ` :math:`\{ \AMODULE~f.\FIMODULE, \ALOCALS~\val^n~(\default_t)^\ast \}`. +9. Push the activation of :math:`F` with arity :math:`m` to the stack. -10. Push the activation of :math:`F` with arity :math:`m` to the stack. +10. Let :math:`L` be the :ref:`label ` whose arity is :math:`m` and whose continuation is the end of the function. -11. Let :math:`L` be the :ref:`label ` whose arity is :math:`m` and whose continuation is the end of the function. - -12. :ref:`Enter ` the instruction sequence :math:`\instr^\ast` with label :math:`L`. +11. :ref:`Enter ` the instruction sequence :math:`\instr^\ast` with label :math:`L`. .. math:: ~\\[-1ex] From 6798f054ad1b0493919f0b5244fa46682ccd3e69 Mon Sep 17 00:00:00 2001 From: Keith Winstein Date: Tue, 24 Jan 2023 04:32:02 -0800 Subject: [PATCH 07/31] [test] Optional tableidx for table.{get,set,size,grow,fill} (#1582) --- test/core/table_fill.wast | 6 +++++- test/core/table_get.wast | 2 +- test/core/table_grow.wast | 5 ++++- test/core/table_set.wast | 2 +- test/core/table_size.wast | 2 +- 5 files changed, 12 insertions(+), 5 deletions(-) diff --git a/test/core/table_fill.wast b/test/core/table_fill.wast index 3df64da1..a8e22255 100644 --- a/test/core/table_fill.wast +++ b/test/core/table_fill.wast @@ -5,6 +5,10 @@ (table.fill $t (local.get $i) (local.get $r) (local.get $n)) ) + (func (export "fill-abbrev") (param $i i32) (param $r externref) (param $n i32) + (table.fill (local.get $i) (local.get $r) (local.get $n)) + ) + (func (export "get") (param $i i32) (result externref) (table.get $t (local.get $i)) ) @@ -39,7 +43,7 @@ (assert_return (invoke "get" (i32.const 8)) (ref.extern 4)) (assert_return (invoke "get" (i32.const 9)) (ref.extern 4)) -(assert_return (invoke "fill" (i32.const 9) (ref.null extern) (i32.const 1))) +(assert_return (invoke "fill-abbrev" (i32.const 9) (ref.null extern) (i32.const 1))) (assert_return (invoke "get" (i32.const 8)) (ref.extern 4)) (assert_return (invoke "get" (i32.const 9)) (ref.null extern)) diff --git a/test/core/table_get.wast b/test/core/table_get.wast index 5d57c319..0dedb19f 100644 --- a/test/core/table_get.wast +++ b/test/core/table_get.wast @@ -10,7 +10,7 @@ ) (func (export "get-externref") (param $i i32) (result externref) - (table.get $t2 (local.get $i)) + (table.get (local.get $i)) ) (func $f3 (export "get-funcref") (param $i i32) (result funcref) (table.get $t3 (local.get $i)) diff --git a/test/core/table_grow.wast b/test/core/table_grow.wast index 7d5b5630..9a931a7f 100644 --- a/test/core/table_grow.wast +++ b/test/core/table_grow.wast @@ -7,6 +7,9 @@ (func (export "grow") (param $sz i32) (param $init externref) (result i32) (table.grow $t (local.get $init) (local.get $sz)) ) + (func (export "grow-abbrev") (param $sz i32) (param $init externref) (result i32) + (table.grow (local.get $init) (local.get $sz)) + ) (func (export "size") (result i32) (table.size $t)) ) @@ -22,7 +25,7 @@ (assert_trap (invoke "set" (i32.const 1) (ref.extern 2)) "out of bounds table access") (assert_trap (invoke "get" (i32.const 1)) "out of bounds table access") -(assert_return (invoke "grow" (i32.const 4) (ref.extern 3)) (i32.const 1)) +(assert_return (invoke "grow-abbrev" (i32.const 4) (ref.extern 3)) (i32.const 1)) (assert_return (invoke "size") (i32.const 5)) (assert_return (invoke "get" (i32.const 0)) (ref.extern 2)) (assert_return (invoke "set" (i32.const 0) (ref.extern 2))) diff --git a/test/core/table_set.wast b/test/core/table_set.wast index 5a9cfa37..3362f956 100644 --- a/test/core/table_set.wast +++ b/test/core/table_set.wast @@ -12,7 +12,7 @@ ) (func (export "set-externref") (param $i i32) (param $r externref) - (table.set $t2 (local.get $i) (local.get $r)) + (table.set (local.get $i) (local.get $r)) ) (func (export "set-funcref") (param $i i32) (param $r funcref) (table.set $t3 (local.get $i) (local.get $r)) diff --git a/test/core/table_size.wast b/test/core/table_size.wast index ad293b5e..83fef02b 100644 --- a/test/core/table_size.wast +++ b/test/core/table_size.wast @@ -4,7 +4,7 @@ (table $t2 0 2 externref) (table $t3 3 8 externref) - (func (export "size-t0") (result i32) (table.size $t0)) + (func (export "size-t0") (result i32) table.size) (func (export "size-t1") (result i32) (table.size $t1)) (func (export "size-t2") (result i32) (table.size $t2)) (func (export "size-t3") (result i32) (table.size $t3)) From 7d905dfa61b25ad58b71490eacfb13e70290b5ef Mon Sep 17 00:00:00 2001 From: Andreas Rossberg Date: Thu, 26 Jan 2023 17:03:14 +0100 Subject: [PATCH 08/31] [spec] Fix abstract grammar for const immediate (#1577) --- document/core/syntax/instructions.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/document/core/syntax/instructions.rst b/document/core/syntax/instructions.rst index eae802cb..9c48736b 100644 --- a/document/core/syntax/instructions.rst +++ b/document/core/syntax/instructions.rst @@ -45,7 +45,7 @@ These operations closely match respective operations available in hardware. \production{signedness} & \sx &::=& \K{u} ~|~ \K{s} \\ \production{instruction} & \instr &::=& - \K{i}\X{nn}\K{.}\CONST~\xref{syntax/values}{syntax-int}{\iX{\X{nn}}} ~|~ + \K{i}\X{nn}\K{.}\CONST~\xref{syntax/values}{syntax-int}{\uX{\X{nn}}} ~|~ \K{f}\X{nn}\K{.}\CONST~\xref{syntax/values}{syntax-float}{\fX{\X{nn}}} \\&&|& \K{i}\X{nn}\K{.}\iunop ~|~ \K{f}\X{nn}\K{.}\funop \\&&|& From 0031ea49613c72522eeff11e0511d423cb64645f Mon Sep 17 00:00:00 2001 From: Andreas Rossberg Date: Thu, 26 Jan 2023 17:03:48 +0100 Subject: [PATCH 09/31] [spec] Fix context composition in text format (#1578) --- document/core/text/modules.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/document/core/text/modules.rst b/document/core/text/modules.rst index fde59878..c3407732 100644 --- a/document/core/text/modules.rst +++ b/document/core/text/modules.rst @@ -108,7 +108,7 @@ If inline declarations are given, then their types must match the referenced :re \end{array} \\ \end{array} -The synthesized attribute of a |Ttypeuse| is a pair consisting of both the used :ref:`type index ` and the updated :ref:`identifier context ` including possible parameter identifiers. +The synthesized attribute of a |Ttypeuse| is a pair consisting of both the used :ref:`type index ` and the local :ref:`identifier context ` containing possible parameter identifiers. The following auxiliary function extracts optional identifiers from parameters: .. math:: @@ -200,7 +200,7 @@ Function definitions can bind a symbolic :ref:`function identifier `, a \text{(}~\text{func}~~\Tid^?~~x,I'{:}\Ttypeuse_I~~ (t{:}\Tlocal)^\ast~~(\X{in}{:}\Tinstr_{I''})^\ast~\text{)} \\ &&& \qquad \Rightarrow\quad \{ \FTYPE~x, \FLOCALS~t^\ast, \FBODY~\X{in}^\ast~\END \} \\ &&& \qquad\qquad\qquad - (\iff I'' = I' \compose \{\ILOCALS~\F{id}(\Tlocal)^\ast\} \idcwellformed) \\[1ex] + (\iff I'' = I \compose I' \compose \{\ILOCALS~\F{id}(\Tlocal)^\ast\} \idcwellformed) \\[1ex] \production{local} & \Tlocal &::=& \text{(}~\text{local}~~\Tid^?~~t{:}\Tvaltype~\text{)} \quad\Rightarrow\quad t \\ From dcf4eaa08fe1b3f98e855e0581389bc29f5d496b Mon Sep 17 00:00:00 2001 From: Andreas Rossberg Date: Thu, 26 Jan 2023 17:04:44 +0100 Subject: [PATCH 10/31] [spec] Fix label shadowing (#1579) --- document/core/text/instructions.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/document/core/text/instructions.rst b/document/core/text/instructions.rst index 348aa773..e846ccb5 100644 --- a/document/core/text/instructions.rst +++ b/document/core/text/instructions.rst @@ -34,6 +34,8 @@ The following grammar handles the corresponding update to the :ref:`identifier c \production{label} & \Tlabel_I &::=& v{:}\Tid &\Rightarrow& \{\ILABELS~v\} \compose I & (\iff v \notin I.\ILABELS) \\ &&|& + v{:}\Tid &\Rightarrow& \{\ILABELS~v\} \compose (I \with \ILABELS[i] = \epsilon) + & (\iff I.\ILABELS[i] = v) \\ &&|& \epsilon &\Rightarrow& \{\ILABELS~(\epsilon)\} \compose I \\ \end{array} @@ -42,6 +44,9 @@ The following grammar handles the corresponding update to the :ref:`identifier c This effectively shifts all existing labels up by one, mirroring the fact that control instructions are indexed relatively not absolutely. + If a label with the same name already exists, + then it is shadowed and the earlier label becomes inaccessible. + .. index:: control instructions, structured control, label, block, branch, result type, label index, function index, type index, vector, polymorphism pair: text format; instruction From 45f9845d4ecb92984dd573c93b7143ad42726bf8 Mon Sep 17 00:00:00 2001 From: candymate <31069474+candymate@users.noreply.github.com> Date: Tue, 31 Jan 2023 18:31:53 +0900 Subject: [PATCH 11/31] [spec] Fix typos in instruction index (#1584) --- document/core/appendix/gen-index-instructions.py | 8 ++++---- document/core/appendix/index-instructions.rst | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/document/core/appendix/gen-index-instructions.py b/document/core/appendix/gen-index-instructions.py index 65a97171..fffa2b32 100755 --- a/document/core/appendix/gen-index-instructions.py +++ b/document/core/appendix/gen-index-instructions.py @@ -427,10 +427,10 @@ def Instruction(name, opcode, type=None, validation=None, execution=None, operat Instruction(r'\V128.\LOAD\K{16\_lane}~\memarg~\laneidx', r'\hex{FD}~~\hex{55}', r'[\I32~\V128] \to [\V128]', r'valid-load-lane', r'exec-load-lane'), Instruction(r'\V128.\LOAD\K{32\_lane}~\memarg~\laneidx', r'\hex{FD}~~\hex{56}', r'[\I32~\V128] \to [\V128]', r'valid-load-lane', r'exec-load-lane'), Instruction(r'\V128.\LOAD\K{64\_lane}~\memarg~\laneidx', r'\hex{FD}~~\hex{57}', r'[\I32~\V128] \to [\V128]', r'valid-load-lane', r'exec-load-lane'), - Instruction(r'\V128.\STORE\K{8\_lane}~\memarg~\laneidx', r'\hex{FD}~~\hex{58}', r'[\I32~\V128] \to [\V128]', r'valid-store-lane', r'exec-store-lane'), - Instruction(r'\V128.\STORE\K{16\_lane}~\memarg~\laneidx', r'\hex{FD}~~\hex{59}', r'[\I32~\V128] \to [\V128]', r'valid-store-lane', r'exec-store-lane'), - Instruction(r'\V128.\STORE\K{32\_lane}~\memarg~\laneidx', r'\hex{FD}~~\hex{5A}', r'[\I32~\V128] \to [\V128]', r'valid-store-lane', r'exec-store-lane'), - Instruction(r'\V128.\STORE\K{64\_lane}~\memarg~\laneidx', r'\hex{FD}~~\hex{5B}', r'[\I32~\V128] \to [\V128]', r'valid-store-lane', r'exec-store-lane'), + Instruction(r'\V128.\STORE\K{8\_lane}~\memarg~\laneidx', r'\hex{FD}~~\hex{58}', r'[\I32~\V128] \to []', r'valid-store-lane', r'exec-store-lane'), + Instruction(r'\V128.\STORE\K{16\_lane}~\memarg~\laneidx', r'\hex{FD}~~\hex{59}', r'[\I32~\V128] \to []', r'valid-store-lane', r'exec-store-lane'), + Instruction(r'\V128.\STORE\K{32\_lane}~\memarg~\laneidx', r'\hex{FD}~~\hex{5A}', r'[\I32~\V128] \to []', r'valid-store-lane', r'exec-store-lane'), + Instruction(r'\V128.\STORE\K{64\_lane}~\memarg~\laneidx', r'\hex{FD}~~\hex{5B}', r'[\I32~\V128] \to []', r'valid-store-lane', r'exec-store-lane'), Instruction(r'\V128.\LOAD\K{32\_zero}~\memarg~\laneidx', r'\hex{FD}~~\hex{5C}', r'[\I32] \to [\V128]', r'valid-load-zero', r'exec-load-zero'), Instruction(r'\V128.\LOAD\K{64\_zero}~\memarg~\laneidx', r'\hex{FD}~~\hex{5D}', r'[\I32] \to [\V128]', r'valid-load-zero', r'exec-load-zero'), Instruction(r'\F32X4.\VDEMOTE\K{\_f64x2\_zero}', r'\hex{FD}~~\hex{5E}', r'[\V128] \to [\V128]', r'valid-vcvtop', r'exec-vcvtop', r'op-demote'), diff --git a/document/core/appendix/index-instructions.rst b/document/core/appendix/index-instructions.rst index 84055a9f..977c21fb 100644 --- a/document/core/appendix/index-instructions.rst +++ b/document/core/appendix/index-instructions.rst @@ -367,10 +367,10 @@ Instruction Binary Opcode :math:`\V128.\LOAD\K{16\_lane}~\memarg~\laneidx` :math:`\hex{FD}~~\hex{55}` :math:`[\I32~\V128] \to [\V128]` :ref:`validation ` :ref:`execution ` :math:`\V128.\LOAD\K{32\_lane}~\memarg~\laneidx` :math:`\hex{FD}~~\hex{56}` :math:`[\I32~\V128] \to [\V128]` :ref:`validation ` :ref:`execution ` :math:`\V128.\LOAD\K{64\_lane}~\memarg~\laneidx` :math:`\hex{FD}~~\hex{57}` :math:`[\I32~\V128] \to [\V128]` :ref:`validation ` :ref:`execution ` -:math:`\V128.\STORE\K{8\_lane}~\memarg~\laneidx` :math:`\hex{FD}~~\hex{58}` :math:`[\I32~\V128] \to [\V128]` :ref:`validation ` :ref:`execution ` -:math:`\V128.\STORE\K{16\_lane}~\memarg~\laneidx` :math:`\hex{FD}~~\hex{59}` :math:`[\I32~\V128] \to [\V128]` :ref:`validation ` :ref:`execution ` -:math:`\V128.\STORE\K{32\_lane}~\memarg~\laneidx` :math:`\hex{FD}~~\hex{5A}` :math:`[\I32~\V128] \to [\V128]` :ref:`validation ` :ref:`execution ` -:math:`\V128.\STORE\K{64\_lane}~\memarg~\laneidx` :math:`\hex{FD}~~\hex{5B}` :math:`[\I32~\V128] \to [\V128]` :ref:`validation ` :ref:`execution ` +:math:`\V128.\STORE\K{8\_lane}~\memarg~\laneidx` :math:`\hex{FD}~~\hex{58}` :math:`[\I32~\V128] \to []` :ref:`validation ` :ref:`execution ` +:math:`\V128.\STORE\K{16\_lane}~\memarg~\laneidx` :math:`\hex{FD}~~\hex{59}` :math:`[\I32~\V128] \to []` :ref:`validation ` :ref:`execution ` +:math:`\V128.\STORE\K{32\_lane}~\memarg~\laneidx` :math:`\hex{FD}~~\hex{5A}` :math:`[\I32~\V128] \to []` :ref:`validation ` :ref:`execution ` +:math:`\V128.\STORE\K{64\_lane}~\memarg~\laneidx` :math:`\hex{FD}~~\hex{5B}` :math:`[\I32~\V128] \to []` :ref:`validation ` :ref:`execution ` :math:`\V128.\LOAD\K{32\_zero}~\memarg~\laneidx` :math:`\hex{FD}~~\hex{5C}` :math:`[\I32] \to [\V128]` :ref:`validation ` :ref:`execution ` :math:`\V128.\LOAD\K{64\_zero}~\memarg~\laneidx` :math:`\hex{FD}~~\hex{5D}` :math:`[\I32] \to [\V128]` :ref:`validation ` :ref:`execution ` :math:`\F32X4.\VDEMOTE\K{\_f64x2\_zero}` :math:`\hex{FD}~~\hex{5E}` :math:`[\V128] \to [\V128]` :ref:`validation ` :ref:`execution `, :ref:`operator ` From 947badf48a7e2b27aeec7a0eaad6b3053032d9f1 Mon Sep 17 00:00:00 2001 From: Bongjun Jang Date: Tue, 7 Feb 2023 17:00:10 +0900 Subject: [PATCH 12/31] [spec] Fix typo (#1587) --- document/core/text/instructions.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/document/core/text/instructions.rst b/document/core/text/instructions.rst index e846ccb5..0e8c577d 100644 --- a/document/core/text/instructions.rst +++ b/document/core/text/instructions.rst @@ -165,7 +165,7 @@ Reference Instructions \production{instruction} & \Tplaininstr_I &::=& \dots \\ &&|& \text{ref.null}~~t{:}\Theaptype &\Rightarrow& \REFNULL~t \\ &&|& \text{ref.is\_null} &\Rightarrow& \REFISNULL \\ &&|& - \text{ref.func}~~x{:}\Tfuncidx &\Rightarrow& \REFFUNC~x \\ &&|& + \text{ref.func}~~x{:}\Tfuncidx &\Rightarrow& \REFFUNC~x \\ \end{array} @@ -891,7 +891,7 @@ Vector constant instructions have a mandatory :ref:`shape ` de \text{f64x2.convert\_low\_i32x4\_s} &\Rightarrow& \F64X2.\VCONVERT\K{\_low\_i32x4\_s}\\ &&|& \text{f64x2.convert\_low\_i32x4\_u} &\Rightarrow& \F64X2.\VCONVERT\K{\_low\_i32x4\_u}\\ &&|& \text{f32x4.demote\_f64x2\_zero} &\Rightarrow& \F32X4.\VDEMOTE\K{\_f64x2\_zero}\\ &&|& - \text{f64x2.promote\_low\_f32x4} &\Rightarrow& \F64X2.\VPROMOTE\K{\_low\_f32x4}\\ &&|& + \text{f64x2.promote\_low\_f32x4} &\Rightarrow& \F64X2.\VPROMOTE\K{\_low\_f32x4}\\ \end{array} From b1fbe1a89a812a031f556392185cb8d9c65beeb8 Mon Sep 17 00:00:00 2001 From: ShinWonho <50018375+ShinWonho@users.noreply.github.com> Date: Wed, 8 Feb 2023 18:07:52 +0900 Subject: [PATCH 13/31] [spec] Remove inconsistent newline (#1589) --- document/core/exec/modules.rst | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/document/core/exec/modules.rst b/document/core/exec/modules.rst index 4dfdb973..578acfa2 100644 --- a/document/core/exec/modules.rst +++ b/document/core/exec/modules.rst @@ -449,8 +449,7 @@ and list of :ref:`reference ` vectors for the module's :ref:`element a. Let :math:`\limits_i~t_i` be the :ref:`table type ` :math:`\table_i.\TTYPE`. - b. Let :math:`\tableaddr_i` be the :ref:`table address ` resulting from :ref:`allocating ` :math:`\table_i.\TTYPE` - with initialization value :math:`\REFNULL~t_i`. + b. Let :math:`\tableaddr_i` be the :ref:`table address ` resulting from :ref:`allocating ` :math:`\table_i.\TTYPE` with initialization value :math:`\REFNULL~t_i`. 4. For each :ref:`memory ` :math:`\mem_i` in :math:`\module.\MMEMS`, do: From 2b4222d04d33d7d69bdf7a54e018ce3a486d89b1 Mon Sep 17 00:00:00 2001 From: Andreas Rossberg Date: Thu, 9 Feb 2023 10:24:19 +0100 Subject: [PATCH 14/31] [interpreter] Remove legacy bigarray linking (#1593) --- interpreter/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interpreter/Makefile b/interpreter/Makefile index 7820e642..499b3a63 100644 --- a/interpreter/Makefile +++ b/interpreter/Makefile @@ -18,7 +18,7 @@ JSLIB = wast WINMAKE = winmake.bat DIRS = util syntax binary text valid runtime exec script host main tests -LIBS = bigarray +LIBS = FLAGS = -lexflags -ml -cflags '-w +a-4-27-42-44-45-70 -warn-error +a-3' OCBA = ocamlbuild $(FLAGS) $(DIRS:%=-I %) OCB = $(OCBA) $(LIBS:%=-libs %) From aa15776984dc41c5f07463297c02fc3f84185437 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=84=9C=EB=8F=99=ED=9C=98?= Date: Fri, 10 Feb 2023 00:25:08 +0900 Subject: [PATCH 15/31] [spec] Show scrolls for overflow math blocks (#1594) --- document/core/static/custom.css | 2 ++ 1 file changed, 2 insertions(+) diff --git a/document/core/static/custom.css b/document/core/static/custom.css index 45838c1e..33bb863d 100644 --- a/document/core/static/custom.css +++ b/document/core/static/custom.css @@ -44,6 +44,8 @@ div.admonition p.admonition-title { div.math { background-color: #F0F0F0; padding: 3px 0 3px 0; + overflow-x: auto; + overflow-y: hidden; } div.relations { From 31cabf87f8e605d71933d724430831a841d2d298 Mon Sep 17 00:00:00 2001 From: Andreas Rossberg Date: Thu, 9 Feb 2023 18:02:34 +0100 Subject: [PATCH 16/31] [interpreter] Run JS tests via node.js (#1595) --- .github/workflows/main.yml | 4 ++++ interpreter/Makefile | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 00b70e8f..2e43f200 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -19,6 +19,10 @@ jobs: with: ocaml-compiler: 4.12.x - run: opam install --yes ocamlbuild.0.14.0 + - name: Setup Node.js + uses: actions/setup-node@v1 + with: + node-version: 18.x - run: cd interpreter && opam exec make all ref-interpreter-js-library: diff --git a/interpreter/Makefile b/interpreter/Makefile index 499b3a63..78cbea55 100644 --- a/interpreter/Makefile +++ b/interpreter/Makefile @@ -23,7 +23,7 @@ FLAGS = -lexflags -ml -cflags '-w +a-4-27-42-44-45-70 -warn-error +a-3' OCBA = ocamlbuild $(FLAGS) $(DIRS:%=-I %) OCB = $(OCBA) $(LIBS:%=-libs %) JSO = js_of_ocaml -q --opt 3 -JS = # set to JS shell command to run JS tests +JS = node # set to JS shell command to run JS tests, empty to skip # Main targets From e7f6e1c45acc396281e31df78d8ad531ab65a2ee Mon Sep 17 00:00:00 2001 From: Jim Blandy Date: Fri, 10 Feb 2023 17:46:52 -0800 Subject: [PATCH 17/31] [spec] Remove stray `x` indices (#1598) --- document/core/exec/instructions.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/document/core/exec/instructions.rst b/document/core/exec/instructions.rst index cc66dbf2..bf5acdfe 100644 --- a/document/core/exec/instructions.rst +++ b/document/core/exec/instructions.rst @@ -2244,7 +2244,7 @@ Memory Instructions S; F; (\I32.\CONST~d)~\val~(\I32.\CONST~n)~\MEMORYFILL \quad\stepto\quad S; F; \TRAP \\ \qquad - (\iff d + n > |S.\SMEMS[F.\AMODULE.\MIMEMS[x]].\MIDATA|) + (\iff d + n > |S.\SMEMS[F.\AMODULE.\MIMEMS[0]].\MIDATA|) \\[1ex] S; F; (\I32.\CONST~d)~\val~(\I32.\CONST~0)~\MEMORYFILL \quad\stepto\quad S; F; \epsilon @@ -2451,7 +2451,7 @@ Memory Instructions \\ \qquad \begin{array}[t]{@{}r@{~}l@{}} (\iff & s + n > |S.\SDATAS[F.\AMODULE.\MIDATAS[x]].\DIDATA| \\ - \vee & d + n > |S.\SMEMS[F.\AMODULE.\MIMEMS[x]].\MIDATA|) \\[1ex] + \vee & d + n > |S.\SMEMS[F.\AMODULE.\MIMEMS[0]].\MIDATA|) \\[1ex] \end{array} \\[1ex] S; F; (\I32.\CONST~d)~(\I32.\CONST~s)~(\I32.\CONST~0)~(\MEMORYINIT~x) From f8ae6b2443a0f1e6ebc62e2fdbe49e2a98008a17 Mon Sep 17 00:00:00 2001 From: Andreas Rossberg Date: Mon, 13 Feb 2023 12:43:34 +0100 Subject: [PATCH 18/31] [spec] Style tweak for cross-refs --- document/core/conf.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/document/core/conf.py b/document/core/conf.py index 22a578a2..3952701b 100644 --- a/document/core/conf.py +++ b/document/core/conf.py @@ -297,7 +297,8 @@ 'pointsize': '10pt', # Additional stuff for the LaTeX preamble. - 'preamble': '', + # Don't type-set cross references with emphasis. + 'preamble': '\\renewcommand\\sphinxcrossref[1]{#1}\n', # Latex figure (float) alignment 'figure_align': 'htbp', From 0f068801d6bcd0219e5ede2a71fcde1d130e3853 Mon Sep 17 00:00:00 2001 From: Bongjun Jang Date: Mon, 13 Feb 2023 21:16:43 +0900 Subject: [PATCH 19/31] [spec] Style eps (#1601) --- document/core/text/lexical.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/document/core/text/lexical.rst b/document/core/text/lexical.rst index f4664666..1dd34c86 100644 --- a/document/core/text/lexical.rst +++ b/document/core/text/lexical.rst @@ -48,7 +48,7 @@ The character stream in the source text is divided, from left to right, into a s \text{(} ~|~ \text{)} ~|~ \Treserved \\ \production{keyword} & \Tkeyword &::=& (\text{a} ~|~ \dots ~|~ \text{z})~\Tidchar^\ast - \qquad (\mbox{if occurring as a literal terminal in the grammar}) \\ + \qquad (\iff~\mbox{occurring as a literal terminal in the grammar}) \\ \production{reserved} & \Treserved &::=& (\Tidchar ~|~ \Tstring)^+ \\ \end{array} From 328e425226dad03539ec0a3891fe0ba6426cc62c Mon Sep 17 00:00:00 2001 From: Andreas Rossberg Date: Thu, 16 Feb 2023 07:00:49 +0100 Subject: [PATCH 20/31] [spec] Clarify that atoms can be symbolic (#1602) --- document/core/syntax/conventions.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/document/core/syntax/conventions.rst b/document/core/syntax/conventions.rst index 9e5dca18..5eeff48c 100644 --- a/document/core/syntax/conventions.rst +++ b/document/core/syntax/conventions.rst @@ -20,7 +20,7 @@ Grammar Notation The following conventions are adopted in defining grammar rules for abstract syntax. -* Terminal symbols (atoms) are written in sans-serif font: :math:`\K{i32}, \K{end}`. +* Terminal symbols (atoms) are written in sans-serif font or in symbolic form: :math:`\K{i32}, \K{end}, {\to}, [, ]`. * Nonterminal symbols are written in italic font: :math:`\X{valtype}, \X{instr}`. From deeb164186d17bdb8a5234c3639e143a8cf71700 Mon Sep 17 00:00:00 2001 From: Andreas Rossberg Date: Thu, 16 Feb 2023 11:46:44 +0100 Subject: [PATCH 21/31] [test] Import v128 global (#1597) --- .github/workflows/main.yml | 2 +- interpreter/Makefile | 2 +- test/core/linking.wast | 14 ++++++++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 2e43f200..0ff1bd5f 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -23,7 +23,7 @@ jobs: uses: actions/setup-node@v1 with: node-version: 18.x - - run: cd interpreter && opam exec make all + - run: cd interpreter && opam exec make JS=node all ref-interpreter-js-library: runs-on: ubuntu-latest diff --git a/interpreter/Makefile b/interpreter/Makefile index 78cbea55..97e6e17c 100644 --- a/interpreter/Makefile +++ b/interpreter/Makefile @@ -23,7 +23,7 @@ FLAGS = -lexflags -ml -cflags '-w +a-4-27-42-44-45-70 -warn-error +a-3' OCBA = ocamlbuild $(FLAGS) $(DIRS:%=-I %) OCB = $(OCBA) $(LIBS:%=-libs %) JSO = js_of_ocaml -q --opt 3 -JS = node # set to JS shell command to run JS tests, empty to skip +JS = # set to JS shell command to run JS tests, empty to skip # Main targets diff --git a/test/core/linking.wast b/test/core/linking.wast index 994e0f49..578a8c18 100644 --- a/test/core/linking.wast +++ b/test/core/linking.wast @@ -129,6 +129,20 @@ ) +(module + (global (export "g-v128") v128 (v128.const i64x2 0 0)) + (global (export "mg-v128") (mut v128) (v128.const i64x2 0 0)) +) +(register "Mv128") + +(module + ;; TODO: Reactivate once the fix for https://bugs.chromium.org/p/v8/issues/detail?id=13732 + ;; has made it to the downstream node.js that we use on CI. + ;; (import "Mv128" "g-v128" (global v128)) + (import "Mv128" "mg-v128" (global (mut v128))) +) + + ;; Tables (module $Mt From 19b1243cea1d8c3898ea56e9b193fa9fba9f4583 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Wed, 12 Oct 2022 15:39:40 +0200 Subject: [PATCH 22/31] [js-api] Expose everywhere --- document/js-api/index.bs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/document/js-api/index.bs b/document/js-api/index.bs index b22e825c..1f703401 100644 --- a/document/js-api/index.bs +++ b/document/js-api/index.bs @@ -282,7 +282,7 @@ dictionary WebAssemblyInstantiatedSource { required Instance instance; }; -[Exposed=(Window,Worker,Worklet)] +[Exposed=*] namespace WebAssembly { boolean validate(BufferSource bytes); Promise<Module> compile(BufferSource bytes); @@ -537,7 +537,7 @@ dictionary ModuleImportDescriptor { required ImportExportKind kind; }; -[LegacyNamespace=WebAssembly, Exposed=(Window,Worker,Worklet)] +[LegacyNamespace=WebAssembly, Exposed=*] interface Module { constructor(BufferSource bytes); static sequence<ModuleExportDescriptor> exports(Module moduleObject); @@ -601,7 +601,7 @@ interface Module {

Instances

-[LegacyNamespace=WebAssembly, Exposed=(Window,Worker,Worklet)]
+[LegacyNamespace=WebAssembly, Exposed=*]
 interface Instance {
   constructor(Module module, optional object importObject);
   readonly attribute object exports;
@@ -628,7 +628,7 @@ dictionary MemoryDescriptor {
   [EnforceRange] unsigned long maximum;
 };
 
-[LegacyNamespace=WebAssembly, Exposed=(Window,Worker,Worklet)]
+[LegacyNamespace=WebAssembly, Exposed=*]
 interface Memory {
   constructor(MemoryDescriptor descriptor);
   unsigned long grow([EnforceRange] unsigned long delta);
@@ -738,7 +738,7 @@ dictionary TableDescriptor {
   [EnforceRange] unsigned long maximum;
 };
 
-[LegacyNamespace=WebAssembly, Exposed=(Window,Worker,Worklet)]
+[LegacyNamespace=WebAssembly, Exposed=*]
 interface Table {
   constructor(TableDescriptor descriptor, optional any value);
   unsigned long grow([EnforceRange] unsigned long delta, optional any value);
@@ -860,7 +860,7 @@ dictionary GlobalDescriptor {
   boolean mutable = false;
 };
 
-[LegacyNamespace=WebAssembly, Exposed=(Window,Worker,Worklet)]
+[LegacyNamespace=WebAssembly, Exposed=*]
 interface Global {
   constructor(GlobalDescriptor descriptor, optional any v);
   any valueOf();

From 4feb91964f8e5e80d416abd6e9f62cc626c7c600 Mon Sep 17 00:00:00 2001
From: Ms2ger 
Date: Thu, 16 Feb 2023 15:58:14 +0100
Subject: [PATCH 23/31] [js-api] Try to clarify NaN/infinity handling. (#1535)

---
 document/js-api/index.bs | 36 ++++++++++++++++++++++++++++++------
 1 file changed, 30 insertions(+), 6 deletions(-)

diff --git a/document/js-api/index.bs b/document/js-api/index.bs
index 1f703401..961918ea 100644
--- a/document/js-api/index.bs
+++ b/document/js-api/index.bs
@@ -93,6 +93,8 @@ urlPrefix: https://tc39.github.io/ecma262/; spec: ECMASCRIPT
         text: IterableToList; url: sec-iterabletolist
         text: ToBigInt64; url: #sec-tobigint64
         text: BigInt; url: #sec-ecmascript-language-types-bigint-type
+        text: ๐”ฝ; url: #๐”ฝ
+        text: โ„ค; url: #โ„ค
     type: abstract-op
         text: CreateMethodProperty; url: sec-createmethodproperty
 urlPrefix: https://webassembly.github.io/spec/core/; spec: WebAssembly; type: dfn
@@ -163,6 +165,12 @@ urlPrefix: https://webassembly.github.io/spec/core/; spec: WebAssembly; type: df
         text: reftype
         text: funcref
         text: externref
+    url: syntax/values.html#syntax-float
+        text: +โˆž
+        text: โˆ’โˆž
+        text: nan
+        text: canon
+        text: signif
     text: function element; url: exec/runtime.html#syntax-funcelem
     text: import component; url: syntax/modules.html#imports
     text: external value; url: exec/runtime.html#syntax-externval
@@ -1087,10 +1095,16 @@ The algorithm ToJSValue(|w|) coerces a [=WebAssembly value=] to a Jav
 1. Assert: |w| is not of  the form [=v128.const=] v128.
 1. If |w| is of the form [=i64.const=] |i64|,
     1. Let |v| be [=signed_64=](|i64|).
-    1. Return a [=BigInt=] representing the mathematical value |v|.
-1. If |w| is of the form [=i32.const=] |i32|, return [=the Number value=] for [=signed_32=](|i32|).
-1. If |w| is of the form [=f32.const=] |f32|, return [=the Number value=] for |f32|.
-1. If |w| is of the form [=f64.const=] |f64|, return [=the Number value=] for |f64|.
+    1. Return [=โ„ค=](|v| interpreted as a mathematical value).
+1. If |w| is of the form [=i32.const=] |i32|, return [=๐”ฝ=]([=signed_32=](|i32| interpreted as a mathematical value)).
+1. If |w| is of the form [=f32.const=] |f32|,
+    1. If |f32| is [=+โˆž=] or [=โˆ’โˆž=], return **+โˆž**๐”ฝ or **-โˆž**๐”ฝ, respectively.
+    1. If |f32| is [=nan=], return **NaN**.
+    1. Return [=๐”ฝ=](|f32| interpreted as a mathematical value).
+1. If |w| is of the form [=f64.const=] |f64|,
+    1. If |f64| is [=+โˆž=] or [=โˆ’โˆž=], return **+โˆž**๐”ฝ or **-โˆž**๐”ฝ, respectively.
+    1. If |f64| is [=nan=], return **NaN**.
+    1. Return [=๐”ฝ=](|f64| interpreted as a mathematical value).
 1. If |w| is of the form [=ref.null=] t, return null.
 1. If |w| is of the form [=ref.func=] |funcaddr|, return the result of creating [=a new Exported Function=] from |funcaddr|.
 1. If |w| is of the form [=ref.extern=] |externaddr|, return the result of [=retrieving an extern value=] from |externaddr|.
@@ -1119,10 +1133,20 @@ The algorithm ToWebAssemblyValue(|v|, |type|) coerces a JavaScript va
     1. Let |i32| be [=?=] [=ToInt32=](|v|).
     1. Return [=i32.const=] |i32|.
 1. If |type| is [=f32=],
-    1. Let |f32| be [=?=] [=ToNumber=](|v|) rounded to the nearest representable value using IEEE 754-2008 round to nearest, ties to even mode.
+    1. Let |number| be [=?=] [=ToNumber=](|v|).
+    1. If |number| is **NaN**,
+        1. Let |n| be an implementation-defined integer such that [=canon=]32 โ‰ค |n| < 2[=signif=](32).
+        1. Let |f32| be [=nan=](n).
+    1. Otherwise,
+        1. Let |f32| be |number| rounded to the nearest representable value using IEEE 754-2008 round to nearest, ties to even mode. [[IEEE-754]]
     1. Return [=f32.const=] |f32|.
 1. If |type| is [=f64=],
-    1. Let |f64| be [=?=] [=ToNumber=](|v|).
+    1. Let |number| be [=?=] [=ToNumber=](|v|).
+    1. If |number| is **NaN**,
+        1. Let |n| be an implementation-defined integer such that [=canon=]64 โ‰ค |n| < 2[=signif=](64).
+        1. Let |f64| be [=nan=](n).
+    1. Otherwise,
+        1. Let |f64| be |number|.
     1. Return [=f64.const=] |f64|.
 1. If |type| is [=funcref=],
     1. If |v| is null,

From 51ff50a1f4f580e8d3bc185fd83479fdbb62ca7a Mon Sep 17 00:00:00 2001
From: Ms2ger 
Date: Fri, 17 Feb 2023 12:26:24 +0100
Subject: [PATCH 24/31] [web-api] Correct MIME type check. (#1537)

Fixes #1138.
---
 document/web-api/index.bs | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/document/web-api/index.bs b/document/web-api/index.bs
index 1e74e094..64c8ecf3 100644
--- a/document/web-api/index.bs
+++ b/document/web-api/index.bs
@@ -69,6 +69,7 @@ url:https://fetch.spec.whatwg.org/#concept-body-consume-body;text:consume body;t
 
 
 
@@ -111,8 +112,10 @@ Note: This algorithm accepts a {{Response}} object, or a
     1. Let |returnValue| be [=a new promise=]
     1. [=Upon fulfillment=] of |source| with value |unwrappedSource|:
         1. Let |response| be |unwrappedSource|'s [=Response/response=].
-        1. Let |mimeType| be the result of [=extracting a MIME type=] from |response|'s [=response/header list=].
-        1. If |mimeType| is not `` `application/wasm` ``, reject |returnValue| with a {{TypeError}} and abort these substeps.
+        1. Let |mimeType| be the result of [=header list/getting=] `` `Content-Type` `` from |response|'s [=response/header list=].
+        1. If |mimeType| is null, reject |returnValue| with a {{TypeError}} and abort these substeps.
+        1. Remove all [=HTTP tab or space byte=] from the start and end of |mimeType|.
+        1. If |mimeType| is not a [=byte-case-insensitive=] match for `` `application/wasm` ``, reject |returnValue| with a {{TypeError}} and abort these substeps.
 
             Note: extra parameters are not allowed, including the empty `` `application/wasm;` ``.
 

From e8a83b22635281a62731df2dcd0488445f71744f Mon Sep 17 00:00:00 2001
From: Heejin Ahn 
Date: Tue, 21 Feb 2023 02:53:49 -0800
Subject: [PATCH 25/31] [ci] Pin nodejs version to avoid fetching failures
 (#1603)

The issues appears to be related to https://github.com/actions/runner-images/issues/7002.

Co-authored-by: Ms2ger 
---
 .github/workflows/main.yml | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index 0ff1bd5f..b64d31bb 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -64,6 +64,9 @@ jobs:
       - uses: actions/checkout@v2
         with:
           submodules: "recursive"
+      - uses: actions/setup-node@v3
+        with:
+          node-version: 16
       - run: pip install bikeshed && bikeshed update
       - run: pip install six
       - run: sudo apt-get update -y && sudo apt-get install -y latexmk texlive-latex-recommended texlive-latex-extra texlive-fonts-recommended

From 3545ad06f20d7cd4068aeb470f5c8050b5a44e09 Mon Sep 17 00:00:00 2001
From: Tom Stuart 
Date: Tue, 21 Feb 2023 11:03:02 +0000
Subject: [PATCH 26/31] [spec] Add missing value to table.grow reduction rule
 (#1607)

---
 document/core/exec/instructions.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/document/core/exec/instructions.rst b/document/core/exec/instructions.rst
index bf5acdfe..8bc05499 100644
--- a/document/core/exec/instructions.rst
+++ b/document/core/exec/instructions.rst
@@ -1312,7 +1312,7 @@ Table Instructions
      \end{array}
    \\[1ex]
    \begin{array}{lcl@{\qquad}l}
-   S; F; (\I32.\CONST~n)~(\TABLEGROW~x) &\stepto& S; F; (\I32.\CONST~\signed_{32}^{-1}(-1))
+   S; F; \val~(\I32.\CONST~n)~(\TABLEGROW~x) &\stepto& S; F; (\I32.\CONST~\signed_{32}^{-1}(-1))
    \end{array}
    \end{array}
 

From 585bfa7e08ca1ef2556781707f0668731a0ab63d Mon Sep 17 00:00:00 2001
From: Andreas Rossberg 
Date: Tue, 21 Feb 2023 12:28:29 +0100
Subject: [PATCH 27/31] [test] Move SIMD linking test to simd dir (#1610)

---
 test/core/linking.wast           | 14 --------------
 test/core/simd/simd_linking.wast | 12 ++++++++++++
 2 files changed, 12 insertions(+), 14 deletions(-)
 create mode 100644 test/core/simd/simd_linking.wast

diff --git a/test/core/linking.wast b/test/core/linking.wast
index 578a8c18..994e0f49 100644
--- a/test/core/linking.wast
+++ b/test/core/linking.wast
@@ -129,20 +129,6 @@
 )
 
 
-(module
-  (global (export "g-v128") v128 (v128.const i64x2 0 0))
-  (global (export "mg-v128") (mut v128) (v128.const i64x2 0 0))
-)
-(register "Mv128")
-
-(module
-  ;; TODO: Reactivate once the fix for https://bugs.chromium.org/p/v8/issues/detail?id=13732
-  ;; has made it to the downstream node.js that we use on CI.
-  ;; (import "Mv128" "g-v128" (global v128))
-  (import "Mv128" "mg-v128" (global (mut v128)))
-)
-
-
 ;; Tables
 
 (module $Mt
diff --git a/test/core/simd/simd_linking.wast b/test/core/simd/simd_linking.wast
new file mode 100644
index 00000000..1a1d1635
--- /dev/null
+++ b/test/core/simd/simd_linking.wast
@@ -0,0 +1,12 @@
+(module
+  (global (export "g-v128") v128 (v128.const i64x2 0 0))
+  (global (export "mg-v128") (mut v128) (v128.const i64x2 0 0))
+)
+(register "Mv128")
+
+(module
+  ;; TODO: Reactivate once the fix for https://bugs.chromium.org/p/v8/issues/detail?id=13732
+  ;; has made it to the downstream node.js that we use on CI.
+  ;; (import "Mv128" "g-v128" (global v128))
+  (import "Mv128" "mg-v128" (global (mut v128)))
+)

From f9a726780deb99b3c87cb2f0bad56b90580c60fb Mon Sep 17 00:00:00 2001
From: Daniel Ehrenberg 
Date: Mon, 18 Mar 2019 10:46:12 +0100
Subject: [PATCH 28/31] Editorial: Clarify the name of the instantiate
 algorithm.

---
 document/js-api/index.bs | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/document/js-api/index.bs b/document/js-api/index.bs
index 961918ea..df23c7a7 100644
--- a/document/js-api/index.bs
+++ b/document/js-api/index.bs
@@ -485,7 +485,7 @@ The verification of WebAssembly type requirements is deferred to the
 
 
 
- To instantiate a WebAssembly module from a {{Module}} |moduleObject| and imports |importObject|, perform the following steps: + To synchronously instantiate a WebAssembly module from a {{Module}} |moduleObject| and imports |importObject|, perform the following steps: 1. Let |module| be |moduleObject|.\[[Module]]. 1. [=Read the imports=] of |module| with imports |importObject|, and let |imports| be the result. 1. [=Instantiate the core of a WebAssembly module=] |module| with |imports|, and let |instance| be the result. @@ -499,7 +499,7 @@ The verification of WebAssembly type requirements is deferred to the 1. Let |promise| be [=a new promise=]. 1. [=Upon fulfillment=] of |promiseOfModule| with value |module|: - 1. [=instantiate a WebAssembly module|Instantiate the WebAssembly module=] |module| importing |importObject|, and let |instance| be the result. If this throws an exception, catch it, [=reject=] |promise| with the exception, and abort these substeps. + 1. [=synchronously instantiate a WebAssembly module|Synchronously instantiate the WebAssembly module=] |module| importing |importObject|, and let |instance| be the result. If this throws an exception, catch it, [=reject=] |promise| with the exception, and abort these substeps. 1. Let |result| be the {{WebAssemblyInstantiatedSource}} value ยซ[ "{{WebAssemblyInstantiatedSource/module}}" โ†’ |module|, "{{WebAssemblyInstantiatedSource/instance}}" โ†’ |instance| ]ยป. 1. [=Resolve=] |promise| with |result|. 1. [=Upon rejection=] of |promiseOfModule| with reason |reason|: From a114f7a06bb0e867f1a66570dedcf2ebebe95f3c Mon Sep 17 00:00:00 2001 From: Daniel Ehrenberg Date: Mon, 18 Mar 2019 10:51:53 +0100 Subject: [PATCH 29/31] Add notes to discourage using synchronous APIs. --- document/js-api/index.bs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/document/js-api/index.bs b/document/js-api/index.bs index df23c7a7..19600b85 100644 --- a/document/js-api/index.bs +++ b/document/js-api/index.bs @@ -604,6 +604,8 @@ interface Module { 1. If |module| is [=error=], throw a {{CompileError}} exception. 1. Set **this**.\[[Module]] to |module|. 1. Set **this**.\[[Bytes]] to |stableBytes|. + +Note: Some implementations enforce a size limitation on |bytes|. Use of this API is discouraged, in favor of asynchronous APIs.

Instances

@@ -622,6 +624,8 @@ interface Instance { 1. [=Read the imports=] of |module| with imports |importObject|, and let |imports| be the result. 1. [=Instantiate the core of a WebAssembly module=] |module| with |imports|, and let |instance| be the result. 1. [=initialize an instance object|Initialize=] **this** from |module| and |instance|. + +Note: The use of this synchronous API is discouraged, as some implementations sometimes do long-running compilation work when instantiating.
From 25b3df3e21324465fefd9aed2cf3901cfd76a7c1 Mon Sep 17 00:00:00 2001 From: Daniel Ehrenberg Date: Mon, 18 Mar 2019 10:52:13 +0100 Subject: [PATCH 30/31] [jsapi] Normative: Always queue a task during asynchronous instantiation JSC will have to do asynchronous compilation work during some instantiations. To be consistent, this PR always queues a task to complete instantiation, except through the synchronous Instance(module) API, to ensure consistency across platforms. This patch also cleans up the specification in various surrounding ways: - Include notes about APIs whose use is discouraged/may be limited Closes #741 See also https://github.com/webpack/webpack/issues/6433 --- document/js-api/index.bs | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/document/js-api/index.bs b/document/js-api/index.bs index 19600b85..19faf7ed 100644 --- a/document/js-api/index.bs +++ b/document/js-api/index.bs @@ -474,13 +474,15 @@ The verification of WebAssembly type requirements is deferred to the 1. Let |module| be |moduleObject|.\[[Module]]. 1. [=Read the imports=] of |module| with imports |importObject|, and let |imports| be the result. If this operation throws an exception, catch it, [=reject=] |promise| with the exception, and return |promise|. - 1. [=Queue a task=] to perform the following steps: - 1. [=Instantiate the core of a WebAssembly module=] |module| with |imports|, and let |instance| be the result. - If this throws an exception, catch it, [=reject=] |promise| with the exception, and terminate these substeps. - 1. Let |instanceObject| be a [=/new=] {{Instance}}. - 1. [=initialize an instance object|Initialize=] |instanceObject| from |module| and |instance|. - If this throws an exception, catch it, [=reject=] |promise| with the exception, and terminate these substeps. - 1. [=Resolve=] |promise| with |instanceObject|. + 1. Run the following steps [=in parallel=]: + 1. [=Queue a task=] to perform the following steps: + Note: Implementation-specific work may be performed here. + 1. [=Instantiate the core of a WebAssembly module=] |module| with |imports|, and let |instance| be the result. + If this throws an exception, catch it, [=reject=] |promise| with the exception, and terminate these substeps. + 1. Let |instanceObject| be a [=/new=] {{Instance}}. + 1. [=initialize an instance object|Initialize=] |instanceObject| from |module| and |instance|. + If this throws an exception, catch it, [=reject=] |promise| with the exception, and terminate these substeps. + 1. [=Resolve=] |promise| with |instanceObject|. 1. Return |promise|.
@@ -499,14 +501,15 @@ The verification of WebAssembly type requirements is deferred to the 1. Let |promise| be [=a new promise=]. 1. [=Upon fulfillment=] of |promiseOfModule| with value |module|: - 1. [=synchronously instantiate a WebAssembly module|Synchronously instantiate the WebAssembly module=] |module| importing |importObject|, and let |instance| be the result. If this throws an exception, catch it, [=reject=] |promise| with the exception, and abort these substeps. - 1. Let |result| be the {{WebAssemblyInstantiatedSource}} value ยซ[ "{{WebAssemblyInstantiatedSource/module}}" โ†’ |module|, "{{WebAssemblyInstantiatedSource/instance}}" โ†’ |instance| ]ยป. - 1. [=Resolve=] |promise| with |result|. + 1. [=asynchronously instantiate a WebAssembly module|Instantiate the WebAssembly module=] |module| importing |importObject|, and let |innerPromise| be the result. + 1. [=Upon fulfillment=] of |innerPromise| with value |instance|. + 1. Let |result| be the {{WebAssemblyInstantiatedSource}} value ยซ[ "{{WebAssemblyInstantiatedSource/module}}" โ†’ |module|, "{{WebAssemblyInstantiatedSource/instance}}" โ†’ |instance| ]ยป. + 1. [=Resolve=] |promise| with |result|. + 1. [=Upon rejection=] of |innerPromise| with reason |reason|: + 1. [=Reject=] |promise| with |reason|. 1. [=Upon rejection=] of |promiseOfModule| with reason |reason|: 1. [=Reject=] |promise| with |reason|. 1. Return |promise|. - - Note: It would be valid to perform certain parts of the instantiation [=in parallel=], but several parts need to happen in the event loop, including JavaScript operations to access the |importObject| and execution of the start function.
From 036365a10e47ac1bec0151c148d0b334b3b2ef2b Mon Sep 17 00:00:00 2001 From: Heejin Ahn Date: Fri, 17 Feb 2023 17:12:31 -0800 Subject: [PATCH 31/31] [test] Exception -> Tag in wasm-module-builder.js The section name has changed to the tag section a few years ago. This adds the corresponding changes added in WebAssembly/exception-handling#252 and WebAssembly/exception-handling#256. --- test/js-api/wasm-module-builder.js | 46 +++++++++++++++--------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/test/js-api/wasm-module-builder.js b/test/js-api/wasm-module-builder.js index 7be72f86..d0f9e78b 100644 --- a/test/js-api/wasm-module-builder.js +++ b/test/js-api/wasm-module-builder.js @@ -65,7 +65,7 @@ let kElementSectionCode = 9; // Elements section let kCodeSectionCode = 10; // Function code let kDataSectionCode = 11; // Data segments let kDataCountSectionCode = 12; // Data segment count (between Element & Code) -let kExceptionSectionCode = 13; // Exception section (between Global & Export) +let kTagSectionCode = 13; // Tag section (between Memory & Global) // Name section types let kModuleNameCode = 0; @@ -104,13 +104,13 @@ let kExternalFunction = 0; let kExternalTable = 1; let kExternalMemory = 2; let kExternalGlobal = 3; -let kExternalException = 4; +let kExternalTag = 4; let kTableZero = 0; let kMemoryZero = 0; let kSegmentZero = 0; -let kExceptionAttribute = 0; +let kTagAttribute = 0; // Useful signatures let kSig_i_i = makeSig([kWasmI32], [kWasmI32]); @@ -681,7 +681,7 @@ class WasmModuleBuilder { this.exports = []; this.globals = []; this.tables = []; - this.exceptions = []; + this.tags = []; this.functions = []; this.element_segments = []; this.data_segments = []; @@ -689,7 +689,7 @@ class WasmModuleBuilder { this.num_imported_funcs = 0; this.num_imported_globals = 0; this.num_imported_tables = 0; - this.num_imported_exceptions = 0; + this.num_imported_tags = 0; return this; } @@ -752,11 +752,11 @@ class WasmModuleBuilder { return table; } - addException(type) { + addTag(type) { let type_index = (typeof type) == "number" ? type : this.addType(type); - let except_index = this.exceptions.length + this.num_imported_exceptions; - this.exceptions.push(type_index); - return except_index; + let tag_index = this.tags.length + this.num_imported_tags; + this.tags.push(type_index); + return tag_index; } addFunction(name, type) { @@ -804,14 +804,14 @@ class WasmModuleBuilder { return this.num_imported_tables++; } - addImportedException(module, name, type) { - if (this.exceptions.length != 0) { - throw new Error('Imported exceptions must be declared before local ones'); + addImportedTag(module, name, type) { + if (this.tags.length != 0) { + throw new Error('Imported tags must be declared before local ones'); } let type_index = (typeof type) == "number" ? type : this.addType(type); - let o = {module: module, name: name, kind: kExternalException, type: type_index}; + let o = {module: module, name: name, kind: kExternalTag, type: type_index}; this.imports.push(o); - return this.num_imported_exceptions++; + return this.num_imported_tags++; } addExport(name, index) { @@ -938,8 +938,8 @@ class WasmModuleBuilder { section.emit_u8(has_max ? 1 : 0); // flags section.emit_u32v(imp.initial); // initial if (has_max) section.emit_u32v(imp.maximum); // maximum - } else if (imp.kind == kExternalException) { - section.emit_u32v(kExceptionAttribute); + } else if (imp.kind == kExternalTag) { + section.emit_u32v(kTagAttribute); section.emit_u32v(imp.type); } else { throw new Error("unknown/unsupported import kind " + imp.kind); @@ -1036,13 +1036,13 @@ class WasmModuleBuilder { }); } - // Add exceptions. - if (wasm.exceptions.length > 0) { - if (debug) print("emitting exceptions @ " + binary.length); - binary.emit_section(kExceptionSectionCode, section => { - section.emit_u32v(wasm.exceptions.length); - for (let type of wasm.exceptions) { - section.emit_u32v(kExceptionAttribute); + // Add tags. + if (wasm.tags.length > 0) { + if (debug) print("emitting tags @ " + binary.length); + binary.emit_section(kTagSectionCode, section => { + section.emit_u32v(wasm.tags.length); + for (let type of wasm.tags) { + section.emit_u32v(kTagAttribute); section.emit_u32v(type); } });