From 61e34cc73076fa5681987f7fdc3e66efeb8f66e7 Mon Sep 17 00:00:00 2001 From: Thibaud Michaud Date: Wed, 9 Oct 2024 12:41:46 +0200 Subject: [PATCH 1/7] Fix wasm-module-builder.js (#1831) --- test/js-api/wasm-module-builder.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/js-api/wasm-module-builder.js b/test/js-api/wasm-module-builder.js index 04f19b278..1ffb00cba 100644 --- a/test/js-api/wasm-module-builder.js +++ b/test/js-api/wasm-module-builder.js @@ -966,7 +966,7 @@ class WasmModuleBuilder { } let type_index = (typeof type) == "number" ? type : this.addType(type); this.imports.push({module: module, name: name, kind: kExternalFunction, - type: type_index}); + type_index: type_index}); return this.num_imported_funcs++; } From 76bcf86758de93f3b0fa27bbd7b392e667a45ade Mon Sep 17 00:00:00 2001 From: Andreas Rossberg Date: Tue, 15 Oct 2024 17:03:54 +0200 Subject: [PATCH 2/7] Fix a bunch of errors --- document/core/appendix/embedding.rst | 2 +- document/core/exec/instructions.rst | 2 +- document/core/exec/numerics.rst | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/document/core/appendix/embedding.rst b/document/core/appendix/embedding.rst index 737230ef8..8dd8ffe0c 100644 --- a/document/core/appendix/embedding.rst +++ b/document/core/appendix/embedding.rst @@ -164,7 +164,7 @@ Modules .. index:: instantiation, module instance .. _embed-module-instantiate: -:math:`\F{module\_instantiate}(\store, \module, \externval^\ast) : (\store, \moduleinst ~|~ \error)` +:math:`\F{module\_instantiate}(\store, \module, \externval^\ast) : (\store, \moduleinst ~|~ \exception ~|~ \error)` .................................................................................................... 1. Try :ref:`instantiating ` :math:`\module` in :math:`\store` with :ref:`external values ` :math:`\externval^\ast` as imports: diff --git a/document/core/exec/instructions.rst b/document/core/exec/instructions.rst index 24d73e24b..46004f290 100644 --- a/document/core/exec/instructions.rst +++ b/document/core/exec/instructions.rst @@ -2142,7 +2142,7 @@ where :math:`\Large\times \{x^\ast\}^N` transforms a sequence of :math:`N` sets .. math:: \begin{array}{lcl@{\qquad}l} (\V128\K{.}\VCONST~c)~t\K{x}N\K{.}\BITMASK &\stepto& (\I32\K{.}\CONST~i) - & (\iff i = \ibits_{32}^{-1}(\ilts_{|t|}(\lanes_{t\K{x}N}(c), 0^N))) + & (\iff i = \ibits_{32}^{-1}(\ilts_{|t|}(\lanes_{t\K{x}N}(c), (0)^N) (0)^{32-N})) \\ \end{array} diff --git a/document/core/exec/numerics.rst b/document/core/exec/numerics.rst index 44f823eef..5c1d9be04 100644 --- a/document/core/exec/numerics.rst +++ b/document/core/exec/numerics.rst @@ -2271,7 +2271,7 @@ where: \begin{array}{@{}lcll} \irelaxedswizzlelane(i^n, j) &=& i[j] & (\iff j < 16) \\ \irelaxedswizzlelane(i^n, j) &=& 0 & (\iff \signed_8(j) < 0) \\ - \irelaxedswizzlelane(i^n, j) &=& \relaxed(R_{\F{swizzle}})[ 0, i[j \mod n] ] & (\otherwise) \\ + \irelaxedswizzlelane(i^n, j) &=& \relaxed(R_{\F{swizzle}})[ 0, i^n[j \mod n] ] & (\otherwise) \\ \end{array} .. note:: From bef38ba519e0ce2ff9a2c84267f0c62364ecbf30 Mon Sep 17 00:00:00 2001 From: Andreas Rossberg Date: Thu, 17 Oct 2024 15:01:55 +0200 Subject: [PATCH 3/7] Add missing handlers to eval contexts --- document/core/exec/runtime.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/document/core/exec/runtime.rst b/document/core/exec/runtime.rst index 8a91a1f76..3f251c255 100644 --- a/document/core/exec/runtime.rst +++ b/document/core/exec/runtime.rst @@ -897,7 +897,8 @@ Finally, the following definition of *evaluation context* and associated structu \production{evaluation contexts} & E &::=& [\_] ~|~ \val^\ast~E~\instr^\ast ~|~ - \LABEL_n\{\instr^\ast\}~E~\END \\ + \LABEL_n\{\instr^\ast\}~E~\END ~|~ + \HANDLER_n\{\catch^\ast\}~E~\END \\ \end{array} .. math:: From 37f3cad1265a64e53d558ed469056fe92ff473b0 Mon Sep 17 00:00:00 2001 From: Andreas Rossberg Date: Mon, 28 Oct 2024 21:21:14 +0100 Subject: [PATCH 4/7] [interpreter] Fix subtype condition for result patterns --- interpreter/script/js.ml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/interpreter/script/js.ml b/interpreter/script/js.ml index adc072cb1..30bbb796e 100644 --- a/interpreter/script/js.ml +++ b/interpreter/script/js.ml @@ -358,7 +358,12 @@ let rec type_of_result res = let assert_return ress ts at = let rec test (res, t) = - if not (Match.match_val_type [] t (type_of_result res)) then + if + not ( + Match.match_val_type [] t (type_of_result res) || + Match.match_val_type [] (type_of_result res) t + ) + then [ Br (0l @@ at) @@ at ] else match res.it with From 8ce0607ca134d9d520038fb7fc28d500dab74617 Mon Sep 17 00:00:00 2001 From: Andreas Rossberg Date: Tue, 29 Oct 2024 14:08:56 +0100 Subject: [PATCH 5/7] Handle extern refs --- interpreter/script/js.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interpreter/script/js.ml b/interpreter/script/js.ml index 30bbb796e..47640d683 100644 --- a/interpreter/script/js.ml +++ b/interpreter/script/js.ml @@ -436,7 +436,7 @@ let assert_return ress ts at = [ RefIsNull @@ at; Test (Value.I32 I32Op.Eqz) @@ at; BrIf (0l @@ at) @@ at ] - | RefResult (RefPat {it = HostRef n; _}) -> + | RefResult (RefPat {it = (HostRef n | Extern.ExternRef (HostRef n)); _}) -> [ Const (Value.I32 n @@ at) @@ at; Call (hostref_idx @@ at) @@ at; Call (eq_ref_idx @@ at) @@ at; From 76654e28102e37b65503ae744e8767bb2cba7963 Mon Sep 17 00:00:00 2001 From: Andreas Rossberg Date: Tue, 29 Oct 2024 16:23:33 +0100 Subject: [PATCH 6/7] [interpreter] Fix (and sanity-check) JS wrapper modules --- .github/workflows/ci-interpreter.yml | 4 +-- interpreter/script/js.ml | 43 ++++++++++++++++++++++------ 2 files changed, 37 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci-interpreter.yml b/.github/workflows/ci-interpreter.yml index 6c09ffc0f..7ac7513dd 100644 --- a/.github/workflows/ci-interpreter.yml +++ b/.github/workflows/ci-interpreter.yml @@ -2,11 +2,11 @@ name: CI for interpreter & tests on: push: - branches: [ main ] + branches: [ main, wasm-3.0 ] paths: [ .github/**, interpreter/**, test/** ] pull_request: - branches: [ main ] + branches: [ main, wasm-3.0 ] paths: [ .github/**, interpreter/**, test/** ] # Allows you to run this workflow manually from the Actions tab diff --git a/interpreter/script/js.ml b/interpreter/script/js.ml index 47640d683..a9bde9353 100644 --- a/interpreter/script/js.ml +++ b/interpreter/script/js.ml @@ -309,8 +309,15 @@ let value v = | Num n -> [Const (n @@ v.at) @@ v.at] | Vec s -> [VecConst (s @@ v.at) @@ v.at] | Ref (NullRef ht) -> [RefNull (Match.bot_of_heap_type [] ht) @@ v.at] + | Ref (HostRef n) -> + [ Const (I32 n @@ v.at) @@ v.at; + Call (hostref_idx @@ v.at) @@ v.at; + ] | Ref (Extern.ExternRef (HostRef n)) -> - [Const (I32 n @@ v.at) @@ v.at; Call (hostref_idx @@ v.at) @@ v.at] + [ Const (I32 n @@ v.at) @@ v.at; + Call (hostref_idx @@ v.at) @@ v.at; + ExternConvert Externalize @@ v.at; + ] | Ref _ -> assert false let invoke ft vs at = @@ -357,6 +364,7 @@ let rec type_of_result res = ) (List.hd ts) ts let assert_return ress ts at = + let locals = ref [] in let rec test (res, t) = if not ( @@ -436,10 +444,17 @@ let assert_return ress ts at = [ RefIsNull @@ at; Test (Value.I32 I32Op.Eqz) @@ at; BrIf (0l @@ at) @@ at ] - | RefResult (RefPat {it = (HostRef n | Extern.ExternRef (HostRef n)); _}) -> + | RefResult (RefPat {it = HostRef n; _}) -> + [ Const (Value.I32 n @@ at) @@ at; + Call (hostref_idx @@ at) @@ at; + Call (eq_ref_idx @@ at) @@ at; + Test (Value.I32 I32Op.Eqz) @@ at; + BrIf (0l @@ at) @@ at ] + | RefResult (RefPat {it = Extern.ExternRef (HostRef n); _}) -> [ Const (Value.I32 n @@ at) @@ at; Call (hostref_idx @@ at) @@ at; - Call (eq_ref_idx @@ at) @@ at; + ExternConvert Externalize @@ at; + Call (eq_ref_idx @@ at) @@ at; Test (Value.I32 I32Op.Eqz) @@ at; BrIf (0l @@ at) @@ at ] | RefResult (RefPat _) -> @@ -455,9 +470,13 @@ let assert_return ress ts at = Test (I32 I32Op.Eqz) @@ at; BrIf (0l @@ at) @@ at ] | EitherResult ress -> - [ Block (ValBlockType None, + let idx = Lib.List32.length !locals in + locals := !locals @ [{ltype = t} @@ res.at]; + [ LocalSet (idx @@ res.at) @@ res.at; + Block (ValBlockType None, List.map (fun resI -> Block (ValBlockType None, + [LocalGet (idx @@ resI.at) @@ resI.at] @ test (resI, t) @ [Br (1l @@ resI.at) @@ resI.at] ) @@ resI.at @@ -465,7 +484,7 @@ let assert_return ress ts at = [Br (1l @@ at) @@ at] ) @@ at ] - in [], List.flatten (List.rev_map test (List.combine ress ts)) + in !locals, List.flatten (List.rev_map test (List.combine ress ts)) let i32 = NumT I32T let anyref = RefT (Null, AnyHT) @@ -504,12 +523,20 @@ let wrap item_name wrap_action wrap_assertion at = in let funcs = [{ftype = 0l @@ at; locals; body} @@ at] in let m = {empty_module with types; funcs; imports; exports} @@ at in + (try + Valid.check_module m; (* sanity check *) + with Valid.Invalid _ as exn -> + prerr_endline (string_of_region at ^ + ": internal error in JS converter, invalid wrapper module generated:"); + Sexpr.output stderr 80 (Arrange.module_ m); + raise exn + ); Encode.encode m let is_js_num_type = function - | I32T -> true - | I64T | F32T | F64T -> false + | I32T | I64T -> true + | F32T | F64T -> false let is_js_vec_type = function | _ -> false @@ -569,7 +596,7 @@ let of_num n = let open Value in match n with | I32 i -> I32.to_string_s i - | I64 i -> "int64(\"" ^ I64.to_string_s i ^ "\")" + | I64 i -> I64.to_string_s i ^ "n" | F32 z -> of_float (F32.to_float z) | F64 z -> of_float (F64.to_float z) From 1e101024972b647d923da4f6e7cb9a1062f69a1e Mon Sep 17 00:00:00 2001 From: Andreas Rossberg Date: Tue, 29 Oct 2024 16:24:54 +0100 Subject: [PATCH 7/7] Activate CI for wasm-3.0 branch --- .github/workflows/ci-spec.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci-spec.yml b/.github/workflows/ci-spec.yml index c35b394f1..f5918416c 100644 --- a/.github/workflows/ci-spec.yml +++ b/.github/workflows/ci-spec.yml @@ -2,11 +2,11 @@ name: CI for specs on: push: - branches: [ main ] + branches: [ main, wasm-3.0 ] paths: [ .github/**, document/** ] pull_request: - branches: [ main ] + branches: [ main, wasm-3.0 ] paths: [ .github/**, document/** ] # Allows you to run this workflow manually from the Actions tab