Skip to content
Permalink
Browse files
[Wasm-GC] Implement packed types in arrays
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.

* 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/llint/WebAssembly.asm:
* Source/JavaScriptCore/wasm/WasmAirIRGenerator.cpp:
(JSC::Wasm::AirIRGenerator::addArrayNewDefault):
(JSC::Wasm::AirIRGenerator::addArrayGet):
(JSC::Wasm::AirIRGenerator::addStructGet):
(JSC::Wasm::AirIRGenerator::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):
(JSC::LLInt::ArrayGetOperation):
* Source/JavaScriptCore/wasm/WasmSlowPaths.h:
* 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/257597@main
  • Loading branch information
catamorphism authored and takikawa committed Dec 9, 2022
1 parent b6841b9 commit 04de71ca40b4832b65e5c6861c399d91735c309c
Show file tree
Hide file tree
Showing 23 changed files with 1,050 additions and 111 deletions.
@@ -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"
)

/*

0 comments on commit 04de71c

Please sign in to comment.