Skip to content

Commit

Permalink
Re-land [Wasm-GC] Implement packed types in arrays
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=247576

Reviewed by Justin Michaud.

This patch implements support for packed types (i8, i16) in Wasm GC
arrays. Packed types are represented with new entries in wasm.json and
are only allowed for use in StorageTypes, which are a new kind of type
used for struct and array type definition fields.

Packed structs are not yet allowed with this patch.

Relanded patch fixes an invalid move in the Air generator for non-x86
platforms. It also refactors StorageType use slightly and also
eliminates redundant LLInt opcodes.

* JSTests/wasm/gc/arrays.js:
(testArrayDeclaration):
* JSTests/wasm/gc/packed-arrays.js: Added.
(module):
(check):
(testArrayGetPacked):
(testArrayGetUWithNewCanonPacked):
(testArrayGetSWithNewCanonPacked):
(testTypeMismatch64):
(testTypeMismatchArrayGet):
(testPackedTypeOutOfContext):
(testSetGetTruncate):
(testArraySet):
(testArrayGetUnreachable):
* JSTests/wasm/wasm.json:
* Source/JavaScriptCore/bytecode/BytecodeList.rb:
* Source/JavaScriptCore/wasm/WasmAirIRGeneratorBase.h:
(JSC::Wasm::ExpressionType>::addArrayNewDefault):
(JSC::Wasm::ExpressionType>::addArrayGet):
(JSC::Wasm::ExpressionType>::addStructGet):
(JSC::Wasm::ExpressionType>::addStructSet):
* Source/JavaScriptCore/wasm/WasmB3IRGenerator.cpp:
(JSC::Wasm::B3IRGenerator::emitStructSet):
(JSC::Wasm::B3IRGenerator::pushArrayNew):
(JSC::Wasm::B3IRGenerator::addArrayNew):
(JSC::Wasm::B3IRGenerator::addArrayNewDefault):
(JSC::Wasm::B3IRGenerator::addArrayGet):
(JSC::Wasm::B3IRGenerator::addStructGet):
* Source/JavaScriptCore/wasm/WasmFormat.h:
(JSC::Wasm::isRefType):
(JSC::Wasm::isRefWithRecursiveReference):
(JSC::Wasm::isSubtype):
(JSC::Wasm::isDefaultableType):
* Source/JavaScriptCore/wasm/WasmFunctionParser.h:
(JSC::Wasm::FunctionParser<Context>::parseExpression):
(JSC::Wasm::FunctionParser<Context>::parseUnreachableExpression):
* Source/JavaScriptCore/wasm/WasmLLIntGenerator.cpp:
(JSC::Wasm::LLIntGenerator::addArrayGet):
* Source/JavaScriptCore/wasm/WasmOperations.cpp:
(JSC::Wasm::JSC_DEFINE_JIT_OPERATION):
* Source/JavaScriptCore/wasm/WasmSectionParser.cpp:
(JSC::Wasm::SectionParser::parsePackedType):
(JSC::Wasm::SectionParser::parseStorageType):
(JSC::Wasm::SectionParser::parseStructType):
(JSC::Wasm::SectionParser::parseArrayType):
* Source/JavaScriptCore/wasm/WasmSectionParser.h:
* Source/JavaScriptCore/wasm/WasmSlowPaths.cpp:
(JSC::LLInt::WASM_SLOW_PATH_DECL):
* Source/JavaScriptCore/wasm/WasmTypeDefinition.cpp:
(JSC::Wasm::StructType::dump const):
(JSC::Wasm::StructType::StructType):
(JSC::Wasm::ArrayType::dump const):
(JSC::Wasm::StorageType::dump const):
(JSC::Wasm::computeStructTypeHash):
(JSC::Wasm::computeArrayTypeHash):
(JSC::Wasm::TypeDefinition::replacePlaceholders const):
* Source/JavaScriptCore/wasm/WasmTypeDefinition.h:
(JSC::Wasm::StorageType::is const):
(JSC::Wasm::StorageType::as const):
(JSC::Wasm::StorageType::StorageType):
(JSC::Wasm::StorageType::unpacked const):
(JSC::Wasm::StorageType::elementSize const):
(JSC::Wasm::StorageType::operator== const):
(JSC::Wasm::StorageType::operator!= const):
(JSC::Wasm::StorageType::typeCode const):
(JSC::Wasm::StorageType::index const):
(JSC::Wasm::makeString):
(JSC::Wasm::typeSizeInBytes):
* Source/JavaScriptCore/wasm/generateWasm.py:
(Wasm.__init__):
* Source/JavaScriptCore/wasm/generateWasmOpsHeader.py:
(cppMacro):
(cppMacroPacked):
(packedTypeMacroizer):
* Source/JavaScriptCore/wasm/js/JSWebAssemblyArray.cpp:
(JSC::JSWebAssemblyArray::JSWebAssemblyArray):
(JSC::JSWebAssemblyArray::~JSWebAssemblyArray):
(JSC::JSWebAssemblyArray::visitChildrenImpl):
* Source/JavaScriptCore/wasm/js/JSWebAssemblyArray.h:
* Source/JavaScriptCore/wasm/js/JSWebAssemblyStruct.cpp:
(JSC::JSWebAssemblyStruct::get const):
(JSC::JSWebAssemblyStruct::set):
* Source/JavaScriptCore/wasm/wasm.json:

Canonical link: https://commits.webkit.org/258463@main
  • Loading branch information
catamorphism authored and takikawa committed Jan 5, 2023
1 parent d9e61bb commit 24d6d56
Show file tree
Hide file tree
Showing 21 changed files with 998 additions and 108 deletions.
2 changes: 1 addition & 1 deletion JSTests/wasm/gc/arrays.js
Expand Up @@ -34,7 +34,7 @@ function testArrayDeclaration() {
assert.throws(
() => new WebAssembly.Instance(module("\x00\x61\x73\x6d\x01\x00\x00\x00\x01\x84\x80\x80\x80\x00\x01\x5e\xff\x02")),
WebAssembly.CompileError,
"Module doesn't parse at byte 17: can't get array's element Type"
"Module doesn't parse at byte 16: can't get array's element Type"
)

/*
Expand Down

0 comments on commit 24d6d56

Please sign in to comment.