Bug 1608771 - Part 5, BigInt<>I64 conversion for inlined calls r=lth
authorAsumu Takikawa <asumu@igalia.com>
Thu, 07 May 2020 21:11:06 +0000
changeset 528696 648ab7aa47d348fa4abb277d04587a2846b46b1d
parent 528695 f036cb46d18f81e51ed3e7584d2a4eb5b2449447
child 528697 ef99672bd2af952f9af8fde7708a41e64695e1c1
push id37393
push userrmaries@mozilla.com
push dateFri, 08 May 2020 03:38:07 +0000
treeherdermozilla-central@ead8f0367372 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerslth
bugs1608771
milestone78.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 1608771 - Part 5, BigInt<>I64 conversion for inlined calls r=lth This is part 5 of implementing the Wasm BigInt<>I64 conversion proposal for inlined Ion to Wasm calls. This part adds additional Wasm BigInt tests that are aimed specifically to test limits of the inlined calls and to test more conversion cases that should be covered (e.g., to test ToBigInt instruction cases). Differential Revision: https://phabricator.services.mozilla.com/D65238
js/src/jit-test/tests/wasm/bigint/bigint.js
--- a/js/src/jit-test/tests/wasm/bigint/bigint.js
+++ b/js/src/jit-test/tests/wasm/bigint/bigint.js
@@ -32,28 +32,64 @@ function testId() {
   testWithJit(() => {
     assertEq(f(0n, 1n), 0n);
     assertEq(f(-0n, 1n), -0n);
     assertEq(f(123n, 1n), 123n);
     assertEq(f(-123n, 1n), -123n);
     assertEq(f(2n ** 63n, 1n), -(2n ** 63n));
     assertEq(f(2n ** 64n + 123n, 1n), 123n);
     assertEq(f("5", 1n), 5n);
+    assertEq(f(true, 1n), 1n);
+    assertEq(f(false, 1n), 0n);
+    assertEq(f({ toString() { return "5"; }, }, 1n), 5n);
+    assertEq(f({ valueOf() { return 5n; }, }, 1n), 5n);
 
     assertEq(f2(1n, 0n), 0n);
     assertEq(f2(1n, -0n), -0n);
     assertEq(f2(1n, 123n), 123n);
     assertEq(f2(1n, -123n), -123n);
     assertEq(f2(1n, 2n ** 63n), -(2n ** 63n));
     assertEq(f2(1n, 2n ** 64n + 123n), 123n);
     assertEq(f2(1n, "5"), 5n);
+    assertEq(f2(1n, true), 1n);
+    assertEq(f2(1n, false), 0n);
+    assertEq(f2(1n, { toString() { return "5"; }, }), 5n);
+    assertEq(f2(1n, { valueOf() { return 5n; }, }), 5n);
+  });
+}
 
-    assertErrorMessage(() => f(5, 1n), TypeError, "can't convert 5 to BigInt");
-    assertErrorMessage(() => f2(1n, 5), TypeError, "can't convert 5 to BigInt");
-  });
+function testNonBigIntArgs() {
+  var f = wasmEvalText(`(module
+    (func (export "f") (param i64) (result i64)
+      (local.get 0)
+    )
+  )`).exports.f;
+
+  assertErrorMessage(() => f(5), TypeError, "can't convert 5 to BigInt");
+  assertErrorMessage(() => f({ valueOf() { return 5; }, }),
+                     TypeError,
+                     "can't convert 5 to BigInt");
+  assertErrorMessage(() => f(5.3), TypeError, "can't convert 5.3 to BigInt");
+  assertErrorMessage(() => f(), TypeError, "can't convert undefined to BigInt");
+  assertErrorMessage(
+    () => f(undefined),
+    TypeError,
+    "can't convert undefined to BigInt"
+  );
+  assertErrorMessage(() => f(null), TypeError, "can't convert null to BigInt");
+  assertErrorMessage(
+    () => f(Symbol("foo")),
+    TypeError,
+    'can\'t convert Symbol("foo") to BigInt'
+  );
+  assertErrorMessage(() => f({}), SyntaxError, "invalid BigInt syntax");
+  assertErrorMessage(() => f({ valueof() { return "foo"; }, }),
+                     SyntaxError,
+                     "invalid BigInt syntax");
+  assertErrorMessage(() => f("x"), SyntaxError, "invalid BigInt syntax");
 }
 
 function testIdPlus() {
   var f = wasmEvalText(`(module
     (func (export "f") (param i64) (result i64)
       (i64.const 8)
       (get_local 0)
       (i64.add)
@@ -61,19 +97,42 @@ function testIdPlus() {
   )`).exports.f;
 
   testWithJit(() => {
     assertEq(f(0n), 0n + 8n);
     assertEq(f(147n), 147n + 8n);
   });
 }
 
-// Test functions with many parameters to stress ABI cases.
+// Test functions with many parameters to stress ABI cases. We want to test
+// spilled arguments both under and over the Ion call inlining limit.
 function testManyArgs() {
-  var f = wasmEvalText(`(module
+  var f1 = wasmEvalText(`(module
+    (func (export "f")
+      (param i64 i64 i64 i64 i64 i64 i64 i64)
+      (result i64)
+      (get_local 0)
+      (get_local 1)
+      (get_local 2)
+      (get_local 3)
+      (get_local 4)
+      (get_local 5)
+      (get_local 6)
+      (get_local 7)
+      (i64.add)
+      (i64.add)
+      (i64.add)
+      (i64.add)
+      (i64.add)
+      (i64.add)
+      (i64.add)
+    )
+  )`).exports.f;
+
+  var f2 = wasmEvalText(`(module
     (func (export "f")
       (param i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64)
       (result i64)
       (get_local 0)
       (get_local 1)
       (get_local 2)
       (get_local 3)
       (get_local 4)
@@ -98,17 +157,18 @@ function testManyArgs() {
       (i64.add)
       (i64.add)
       (i64.add)
       (i64.add)
     )
   )`).exports.f;
 
   testWithJit(() => {
-    assertEq(f(1n, 1n, 1n, 1n, 1n, 1n, 1n, 1n, 1n, 1n, 1n, 1n, 1n, 1n), 14n);
+    assertEq(f1(1n, 1n, 1n, 1n, 1n, 1n, 1n, 1n), 8n);
+    assertEq(f2(1n, 1n, 1n, 1n, 1n, 1n, 1n, 1n, 1n, 1n, 1n, 1n, 1n, 1n), 14n);
   });
 }
 
 // Test import and re-export.
 function testImportExport() {
   var f1 = wasmEvalText(
     `(module
       (import "i64" "func" (func (param i64)))
@@ -389,16 +449,17 @@ function testGlobalI64SetWrongType() {
     TypeError,
     "can't convert 5 to BigInt"
   );
 }
 
 testRet();
 testId();
 testIdPlus();
+testNonBigIntArgs();
 testManyArgs();
 testImportExport();
 testMixedArgs();
 testGlobalImport();
 testMutableGlobalImport();
 testMutableGlobalImportLiteral();
 testGlobalBadImportLiteral();
 testGlobalBadImportNumber();