Bug 1545755 - Support (result t) syntax for block and if. r=jseward
authorLars T Hansen <lhansen@mozilla.com>
Tue, 07 May 2019 07:12:52 +0000
changeset 531670 71efb056f9e087b9c9213391a108ee73ca1d9610
parent 531669 65ffa078d3b25af64079af4d0a443389c19f065b
child 531671 1a7c349c2c607bf7d0ed2d9a5851073343705fb9
push id11265
push userffxbld-merge
push dateMon, 13 May 2019 10:53:39 +0000
treeherdermozilla-beta@77e0fe8dbdd3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjseward
bugs1545755
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1545755 - Support (result t) syntax for block and if. r=jseward wasmTextToBinary allows a naked type name, but standard wat syntax requires (result t) for ifs and blocks. Supporting this in wasmTextToBinary makes it easier to share wasm source code among the tools. Differential Revision: https://phabricator.services.mozilla.com/D30098
js/src/jit-test/tests/wasm/control-flow.js
js/src/wasm/WasmTextToBinary.cpp
--- a/js/src/jit-test/tests/wasm/control-flow.js
+++ b/js/src/jit-test/tests/wasm/control-flow.js
@@ -6,37 +6,40 @@ const RuntimeError = WebAssembly.Runtime
 // Condition is an int32
 wasmFailValidateText('(module (func (local f32) (if (local.get 0) (i32.const 1))))', mismatchError("f32", "i32"));
 wasmFailValidateText('(module (func (local f32) (if (local.get 0) (i32.const 1) (i32.const 0))))', mismatchError("f32", "i32"));
 wasmFailValidateText('(module (func (local f64) (if (local.get 0) (i32.const 1) (i32.const 0))))', mismatchError("f64", "i32"));
 wasmEvalText('(module (func (local i32) (if (local.get 0) (nop))) (export "" 0))');
 wasmEvalText('(module (func (local i32) (if (local.get 0) (nop) (nop))) (export "" 0))');
 
 // Expression values types are consistent
+// Also test that we support (result t) for `if`
 wasmFailValidateText('(module (func (result i32) (local f32) (if f32 (i32.const 42) (local.get 0) (i32.const 0))))', mismatchError("i32", "f32"));
 wasmFailValidateText('(module (func (result i32) (local f64) (if i32 (i32.const 42) (i32.const 0) (local.get 0))))', mismatchError("f64", "i32"));
+wasmFailValidateText('(module (func (result i64) (if (result i64) (i32.const 0) (i32.const 1) (i32.const 2))))', mismatchError("i32", "i64"));
 assertEq(wasmEvalText('(module (func (result i32) (if i32 (i32.const 42) (i32.const 1) (i32.const 2))) (export "" 0))').exports[""](), 1);
-assertEq(wasmEvalText('(module (func (result i32) (if i32 (i32.const 0) (i32.const 1) (i32.const 2))) (export "" 0))').exports[""](), 2);
+assertEq(wasmEvalText('(module (func (result i32) (if (result i32) (i32.const 0) (i32.const 1) (i32.const 2))) (export "" 0))').exports[""](), 2);
 
 // Even if we don't yield, sub expressions types still have to match.
 wasmFailValidateText('(module (func (param f32) (if i32 (i32.const 42) (i32.const 1) (local.get 0))) (export "" 0))', mismatchError('f32', 'i32'));
 wasmFailValidateText('(module (func (if i32 (i32.const 42) (i32.const 1) (i32.const 0))) (export "" 0))', /unused values not explicitly dropped by end of block/);
 wasmFullPass('(module (func (drop (if i32 (i32.const 42) (i32.const 1) (i32.const 0)))) (export "run" 0))', undefined);
 wasmFullPass('(module (func (param f32) (if (i32.const 42) (drop (i32.const 1)) (drop (local.get 0)))) (export "run" 0))', undefined, {}, 13.37);
 
 // Sub-expression values are returned
+// Also test that we support (result t) for `block`
 wasmFullPass(`(module
     (func
         (result i32)
         (if i32
             (i32.const 42)
             (block i32
                 (
                     if i32
-                    (block i32
+                    (block (result i32)
                         (drop (i32.const 3))
                         (drop (i32.const 5))
                         (i32.const 0)
                     )
                     (i32.const 1)
                     (i32.const 2)
                 )
             )
--- a/js/src/wasm/WasmTextToBinary.cpp
+++ b/js/src/wasm/WasmTextToBinary.cpp
@@ -2443,18 +2443,34 @@ static bool ParseValType(WasmParseContex
 
   return true;
 }
 
 static bool ParseBlockSignature(WasmParseContext& c, AstExprType* type) {
   WasmToken token;
   AstValType vt;
 
-  if (!MaybeParseValType(c, &vt)) {
-    return false;
+  if (c.ts.getIf(WasmToken::OpenParen, &token)) {
+    if (c.ts.getIf(WasmToken::Result)) {
+      if (!ParseValType(c, &vt)) {
+        return false;
+      }
+      if (!c.ts.match(WasmToken::CloseParen, c.error)) {
+        return false;
+      }
+    } else {
+      c.ts.unget(token);
+      if (!MaybeParseValType(c, &vt)) {
+        return false;
+      }
+    }
+  } else {
+    if (!MaybeParseValType(c, &vt)) {
+      return false;
+    }
   }
 
   if (vt.isValid()) {
     *type = AstExprType(vt);
   } else {
     *type = AstExprType(ExprType::Void);
   }