forked from Floorp-Projects/Floorp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1620197 - Enable multiple results from WebAssembly functions r=lth
This patch enables multi-value calls and returns, adding some tests, and conditionally disabling a couple expect-fail reftests that now pass. It also changes to make calling multi-result WebAssembly functions from JavaScript raise a run-time error, and likewise for calling out to multi-result JS function from wasm. Previously these would abort at stub generation time. Differential Revision: https://phabricator.services.mozilla.com/D65502
- Loading branch information
Showing
17 changed files
with
317 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
|
||
function expectRunFailure(text, pattern, imports) { | ||
let instance = wasmEvalText(text, imports); | ||
assertErrorMessage(() => instance.exports.run(), | ||
TypeError, | ||
pattern); | ||
} | ||
|
||
expectRunFailure(` | ||
(module | ||
(import "env" "f" (func $f (result i32 i32))) | ||
(func (export "run") (result i32) | ||
(call $f) | ||
i32.sub))`, | ||
/calling JavaScript functions with multiple results from WebAssembly not yet implemented/, | ||
{ env: { f: () => [52, 10] } }); | ||
|
||
expectRunFailure(` | ||
(module | ||
(func (export "run") (result i32 i32) | ||
(i32.const 52) | ||
(i32.const 10)))`, | ||
/calling WebAssembly functions with multiple results from JavaScript not yet implemented/); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// |jit-test| skip-if: !wasmReftypesEnabled() | ||
|
||
let counter = 0; | ||
let i = new WebAssembly.Instance( | ||
new WebAssembly.Module(wasmTextToBinary(` | ||
(module | ||
(func $boxNextInt (import "imports" "boxNextInt") | ||
(result anyref)) | ||
(func $unboxInt (import "imports" "unboxInt") | ||
(param anyref) (result i32)) | ||
(func $boxNextTwoInts (result anyref anyref) | ||
call $boxNextInt | ||
call $boxNextInt) | ||
(func $unboxTwoInts (param anyref anyref) (result i32 i32) | ||
local.get 0 | ||
call $unboxInt | ||
local.get 1 | ||
call $unboxInt) | ||
(func $addNextTwoInts (export "addNextTwoInts") (result i32) | ||
call $boxNextTwoInts | ||
call $unboxTwoInts | ||
i32.add))`)), | ||
{imports: {boxNextInt: () => ({val: counter++}), | ||
unboxInt: box => box.val}}); | ||
|
||
for (let n = 0; n < 200000; n += 2) { | ||
assertEq(i.exports.addNextTwoInts(), n * 2 + 1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
wasmFullPass(` | ||
(module | ||
(func (result i32 i32) | ||
(i32.const 52) | ||
(i32.const 10)) | ||
(func (export "run") (result i32) | ||
(call 0) | ||
i32.sub))`, | ||
42); | ||
|
||
wasmFullPass(` | ||
(module | ||
(func (param i32 i32) (result i32 i32) | ||
(local.get 0) | ||
(local.get 1)) | ||
(func (export "run") (result i32) | ||
(i32.const 52) | ||
(i32.const 10) | ||
(call 0) | ||
i32.sub))`, | ||
42); | ||
|
||
wasmFullPass(` | ||
(module | ||
(func (param i32 i32 i32 i32 i32 | ||
i32 i32 i32 i32 i32) | ||
(result i32 i32) | ||
(local.get 8) | ||
(local.get 9)) | ||
(func (export "run") (result i32) | ||
(i32.const 0) | ||
(i32.const 1) | ||
(i32.const 2) | ||
(i32.const 3) | ||
(i32.const 4) | ||
(i32.const 5) | ||
(i32.const 6) | ||
(i32.const 7) | ||
(i32.const 52) | ||
(i32.const 10) | ||
(call 0) | ||
i32.sub))`, | ||
42); | ||
|
||
wasmFullPass(` | ||
(module | ||
(func (param i32 i32 i32 i32 i32 | ||
i32 i32 i32 i32 i32) | ||
(result i32 i32) | ||
(local i32 i32 i32 i32) | ||
(local.get 8) | ||
(local.get 9)) | ||
(func (export "run") (result i32) | ||
(i32.const 0) | ||
(i32.const 1) | ||
(i32.const 2) | ||
(i32.const 3) | ||
(i32.const 4) | ||
(i32.const 5) | ||
(i32.const 6) | ||
(i32.const 7) | ||
(i32.const 52) | ||
(i32.const 10) | ||
(call 0) | ||
i32.sub))`, | ||
42); | ||
|
||
wasmFullPass(` | ||
(module | ||
(func (param i32 i32 i32 i32 i32 | ||
i32 i32 i32 i32 i32) | ||
(result i32 i32 i32) | ||
(local i32 i32 i32 i32) | ||
(local.get 7) | ||
(local.get 8) | ||
(local.get 9)) | ||
(func (export "run") (result i32) | ||
(i32.const 0) | ||
(i32.const 1) | ||
(i32.const 2) | ||
(i32.const 3) | ||
(i32.const 4) | ||
(i32.const 5) | ||
(i32.const 6) | ||
(i32.const 7) | ||
(i32.const 52) | ||
(i32.const 10) | ||
(call 0) | ||
i32.sub | ||
i32.sub))`, | ||
-35); | ||
|
||
wasmFullPass(` | ||
(module | ||
(func (param i32 i64 i32 i64 i32 | ||
i64 i32 i64 i32 i64) | ||
(result i64 i32 i64) | ||
(local i32 i64 i32 i64) | ||
(local.get 7) | ||
(local.get 8) | ||
(local.get 9)) | ||
(func (export "run") (result i32) | ||
(i32.const 0) | ||
(i64.const 1) | ||
(i32.const 2) | ||
(i64.const 3) | ||
(i32.const 4) | ||
(i64.const 5) | ||
(i32.const 6) | ||
(i64.const 7) | ||
(i32.const 52) | ||
(i64.const 10) | ||
(call 0) | ||
i32.wrap_i64 | ||
i32.sub | ||
i64.extend_i32_s | ||
i64.sub | ||
i32.wrap_i64))`, | ||
-35); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
wasmValidateText(` | ||
(module | ||
(func (result i32 i32) | ||
(i32.const 32) | ||
(i32.const 10)))`); | ||
|
||
wasmValidateText(` | ||
(module | ||
(type $t (func (result i32 i32))) | ||
(func (type $t) | ||
(i32.const 32) | ||
(i32.const 10)))`); | ||
|
||
wasmValidateText(` | ||
(module | ||
(func (result i32 i32) | ||
(block (result i32 i32) | ||
(i32.const 32) | ||
(i32.const 10))))`); | ||
|
||
wasmValidateText(` | ||
(module | ||
(func $return-2 (result i32 i32) | ||
(i32.const 32) | ||
(i32.const 10)) | ||
(func $tail-call (result i32 i32) | ||
(call 0)))`); | ||
|
||
wasmValidateText(` | ||
(module | ||
(func $return-2 (result i32 i32) | ||
(i32.const 32) | ||
(i32.const 10)) | ||
(func $add (result i32) | ||
(call 0) | ||
i32.add))`); | ||
|
||
wasmValidateText(` | ||
(module | ||
(func $return-2 (param i32 i32) (result i32 i32) | ||
(local.get 0) | ||
(local.get 1)) | ||
(func (export "run") (result i32) | ||
(i32.const 32) | ||
(i32.const 10) | ||
(call 0) | ||
i32.add))`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.