-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Re-land [WASM-Function-References] Fix block signature parsing for re…
…ftypes https://bugs.webkit.org/show_bug.cgi?id=247383 Reviewed by Justin Michaud. This is a re-land of this patch that removes a perf issue introduced in the previous attempts. Adds a fast path for parsing potentially nested blocks with simple (one byte) type signatures. Also changes BlockSignature definition in order to avoid redundant calls to as<FunctionSignature>(). Also fixes the error case when a block signature refers to a non-function type. * JSTests/wasm/function-references/block_signature.js: Added. (module): (async blockSignatureTest): * JSTests/wasm/gc-spec-tests/type-equivalence.wast.js: * JSTests/wasm/gc-spec-tests/type-subtyping.wast.js: * JSTests/wasm/gc/block.js: Added. (testBlockType): * Source/JavaScriptCore/wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::ControlData::ControlData): (JSC::Wasm::B3IRGenerator::ControlData::hasNonVoidresult const): (JSC::Wasm::B3IRGenerator::ControlData::branchTargetArity const): (JSC::Wasm::B3IRGenerator::ControlData::branchTargetType const): (JSC::Wasm::B3IRGenerator::toB3ResultType): (JSC::Wasm::B3IRGenerator::addLoop): (JSC::Wasm::B3IRGenerator::addElseToUnreachable): (JSC::Wasm::B3IRGenerator::endBlock): (JSC::Wasm::B3IRGenerator::addEndToUnreachable): * Source/JavaScriptCore/wasm/WasmBBQJIT.cpp: (JSC::Wasm::BBQJIT::ControlData::ControlData): (JSC::Wasm::BBQJIT::ControlData::branchTargetArity const): (JSC::Wasm::BBQJIT::ControlData::branchTargetType const): (JSC::Wasm::BBQJIT::ControlData::argumentType const): (JSC::Wasm::BBQJIT::addBlock): (JSC::Wasm::BBQJIT::addLoop): (JSC::Wasm::BBQJIT::addIf): (JSC::Wasm::BBQJIT::addElse): (JSC::Wasm::BBQJIT::addElseToUnreachable): (JSC::Wasm::BBQJIT::addTry): (JSC::Wasm::BBQJIT::addEndToUnreachable): * Source/JavaScriptCore/wasm/WasmCallingConvention.h: (JSC::Wasm::WasmCallingConvention::callInformationFor const): * Source/JavaScriptCore/wasm/WasmFormat.h: (JSC::Wasm::isValueType): * Source/JavaScriptCore/wasm/WasmFunctionParser.h: (JSC::Wasm::splitStack): (JSC::Wasm::FunctionParser<Context>::parseBody): (JSC::Wasm::FunctionParser<Context>::unify): (JSC::Wasm::FunctionParser<Context>::parseNestedBlocksEagerly): (JSC::Wasm::FunctionParser<Context>::parseExpression): (JSC::Wasm::FunctionParser<Context>::switchToBlock): * Source/JavaScriptCore/wasm/WasmIPIntGenerator.cpp: (JSC::Wasm::IPIntControlType::branchTargetType const): (JSC::Wasm::IPIntControlType::branchTargetArity const): (JSC::Wasm::IPIntGenerator::addElse): (JSC::Wasm::IPIntGenerator::addEndToUnreachable): (JSC::Wasm::IPIntGenerator::endTopLevel): * Source/JavaScriptCore/wasm/WasmLLIntGenerator.cpp: (JSC::Wasm::LLIntGenerator::ControlType::loop): (JSC::Wasm::LLIntGenerator::ControlType::block): (JSC::Wasm::LLIntGenerator::ControlType::if_): (JSC::Wasm::LLIntGenerator::ControlType::createTry): (JSC::Wasm::LLIntGenerator::ControlType::branchTargetArity const): (JSC::Wasm::LLIntGenerator::ControlType::branchTargetType const): (JSC::Wasm::LLIntGenerator::addElseToUnreachable): (JSC::Wasm::LLIntGenerator::addReturn): (JSC::Wasm::LLIntGenerator::addEndToUnreachable): (JSC::Wasm::LLIntGenerator::endTopLevel): * Source/JavaScriptCore/wasm/WasmParser.h: (JSC::Wasm::Parser<SuccessType>::parseBlockSignature): (JSC::Wasm::Parser<SuccessType>::parseReftypeSignature): * Source/JavaScriptCore/wasm/WasmTypeDefinition.cpp: (JSC::Wasm::TypeInformation::TypeInformation): * Source/JavaScriptCore/wasm/WasmTypeDefinition.h: (JSC::Wasm::TypeInformation::thunkFor const): Canonical link: https://commits.webkit.org/271262@main
- Loading branch information
Showing
14 changed files
with
321 additions
and
133 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
//@ runWebAssemblySuite("--useWebAssemblyTypedFunctionReferences=true") | ||
import * as assert from '../assert.js'; | ||
|
||
function module(bytes, valid = true) { | ||
let buffer = new ArrayBuffer(bytes.length); | ||
let view = new Uint8Array(buffer); | ||
for (let i = 0; i < bytes.length; ++i) { | ||
view[i] = bytes.charCodeAt(i); | ||
} | ||
return new WebAssembly.Module(buffer); | ||
} | ||
|
||
async function blockSignatureTest() { | ||
/* | ||
(module | ||
(type (func)) | ||
(func (type 0)) | ||
(elem declare funcref (ref.func 0)) | ||
(func (result) | ||
(block (result (ref 0)) | ||
(ref.func 0)) | ||
drop) | ||
) | ||
*/ | ||
new WebAssembly.Instance(module("\x00\x61\x73\x6d\x01\x00\x00\x00\x01\x84\x80\x80\x80\x00\x01\x60\x00\x00\x03\x83\x80\x80\x80\x00\x02\x00\x00\x09\x87\x80\x80\x80\x00\x01\x07\x70\x01\xd2\x00\x0b\x0a\x96\x80\x80\x80\x00\x02\x82\x80\x80\x80\x00\x00\x0b\x89\x80\x80\x80\x00\x00\x02\x64\x00\xd2\x00\x0b\x1a\x0b")); | ||
|
||
/* | ||
(module | ||
(type (func)) | ||
(func (result) | ||
(block (result (ref null 0)) | ||
(ref.null 0)) | ||
drop) | ||
) | ||
*/ | ||
new WebAssembly.Instance(module("\x00\x61\x73\x6d\x01\x00\x00\x00\x01\x84\x80\x80\x80\x00\x01\x60\x00\x00\x03\x82\x80\x80\x80\x00\x01\x00\x0a\x8f\x80\x80\x80\x00\x01\x89\x80\x80\x80\x00\x00\x02\x63\x00\xd0\x00\x0b\x1a\x0b")); | ||
|
||
// Both shorthand and Ref encodings tested below. | ||
/* | ||
(module | ||
(func (result) | ||
(block (result (ref null extern)) | ||
(ref.null extern)) | ||
drop) | ||
) | ||
*/ | ||
new WebAssembly.Instance(module("\x00\x61\x73\x6d\x01\x00\x00\x00\x01\x84\x80\x80\x80\x00\x01\x60\x00\x00\x03\x82\x80\x80\x80\x00\x01\x00\x0a\x8e\x80\x80\x80\x00\x01\x88\x80\x80\x80\x00\x00\x02\x6f\xd0\x6f\x0b\x1a\x0b")); | ||
new WebAssembly.Instance(module("\x00\x61\x73\x6d\x01\x00\x00\x00\x01\x84\x80\x80\x80\x00\x01\x60\x00\x00\x03\x82\x80\x80\x80\x00\x01\x00\x0a\x8f\x80\x80\x80\x00\x01\x89\x80\x80\x80\x00\x00\x02\x63\x6f\xd0\x6f\x0b\x1a\x0b")); | ||
|
||
/* | ||
(module | ||
(func (result) | ||
(block (result (ref null func)) | ||
(ref.null func)) | ||
drop) | ||
) | ||
*/ | ||
new WebAssembly.Instance(module("\x00\x61\x73\x6d\x01\x00\x00\x00\x01\x84\x80\x80\x80\x00\x01\x60\x00\x00\x03\x82\x80\x80\x80\x00\x01\x00\x0a\x8e\x80\x80\x80\x00\x01\x88\x80\x80\x80\x00\x00\x02\x70\xd0\x70\x0b\x1a\x0b")); | ||
new WebAssembly.Instance(module("\x00\x61\x73\x6d\x01\x00\x00\x00\x01\x84\x80\x80\x80\x00\x01\x60\x00\x00\x03\x82\x80\x80\x80\x00\x01\x00\x0a\x8f\x80\x80\x80\x00\x01\x89\x80\x80\x80\x00\x00\x02\x63\x70\xd0\x70\x0b\x1a\x0b")); | ||
} | ||
|
||
assert.asyncTest(blockSignatureTest()); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
//@ runWebAssemblySuite("--useWebAssemblyTypedFunctionReferences=true", "--useWebAssemblyGC=true") | ||
|
||
import * as assert from "../assert.js"; | ||
import { compile, instantiate } from "./wast-wrapper.js"; | ||
|
||
function testBlockType() { | ||
compile(` | ||
(module | ||
(rec (type (func (result (ref null 0))))) | ||
(func (block (type 0) (ref.null 0)) drop)) | ||
`); | ||
|
||
assert.throws( | ||
() => compile(` | ||
(module | ||
(type (array i32)) | ||
(func (block (type 0)))) | ||
`), | ||
WebAssembly.CompileError, | ||
"WebAssembly.Module doesn't parse at byte 3: can't get block's signature, in function at index 0" | ||
); | ||
|
||
assert.throws( | ||
() => compile(` | ||
(module | ||
(type (struct)) | ||
(func (block (type 0)))) | ||
`), | ||
WebAssembly.CompileError, | ||
"WebAssembly.Module doesn't parse at byte 3: can't get block's signature, in function at index 0" | ||
); | ||
|
||
assert.throws( | ||
() => compile(` | ||
(module | ||
(type (array i32)) | ||
(func (type 0))) | ||
`), | ||
WebAssembly.CompileError, | ||
"WebAssembly.Module doesn't parse at byte 0: type signature was not a function signature, in function at index 0" | ||
); | ||
} | ||
|
||
testBlockType(); |
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.