New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Wasm-GC] Add extern.internalize/externalize #11666
[Wasm-GC] Add extern.internalize/externalize #11666
Conversation
EWS run on previous version of this PR (hash 3010140) |
3010140
to
4c3a5fc
Compare
EWS run on previous version of this PR (hash 4c3a5fc) |
4c3a5fc
to
6a4ea67
Compare
EWS run on previous version of this PR (hash 6a4ea67) |
6a4ea67
to
e379d0d
Compare
EWS run on previous version of this PR (hash e379d0d) |
e379d0d
to
60ff12d
Compare
EWS run on previous version of this PR (hash 60ff12d) |
Should be ready for review now. I forgot to update the commit message, but I plan to add an explanation about eqrefs like the following:
|
Notes for extern conversions:
|
The |
@@ -3604,6 +3604,21 @@ class BBQJIT { | |||
PartialResult WARN_UNUSED_RETURN addRefCast(ExpressionType, bool, int32_t, ExpressionType&) BBQ_STUB | |||
PartialResult WARN_UNUSED_RETURN addRefTest(ExpressionType, bool, int32_t, ExpressionType&) BBQ_STUB | |||
|
|||
PartialResult WARN_UNUSED_RETURN addExternInternalize(ExpressionType reference, ExpressionType& result) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: due to Wasm GC disabling BBQJIT, this isn't really testable right now. If it's better to stub it out, I can change this to stub code.
@@ -904,6 +904,7 @@ class TypeInformation { | |||
RefPtr<TypeDefinition> m_I32_RefI32I32; | |||
RefPtr<TypeDefinition> m_Ref_RefI32I32; | |||
RefPtr<TypeDefinition> m_Ref_I32I32I32I32; | |||
RefPtr<TypeDefinition> m_Anyref_Externref; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: The style CI failure is due to this member variable naming, which is named like this for consistency with the others.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
r=me
@@ -127,6 +127,7 @@ enum JSType : uint8_t { | |||
JSWeakSetType, | |||
WebAssemblyModuleType, | |||
WebAssemblyInstanceType, | |||
WebAssemblyGCObjectType, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wish we could avoid adding a new type here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah unfortunately I'm not aware of a way to avoid it. The C++ code can just use jsDynamicCast
(https://github.com/WebKit/WebKit/blob/60ff12d314ad2127a1ff211c05636ff630f29582/Source/JavaScriptCore/wasm/WasmOperationsInlines.h#L300) but I don't think it's easy to use this generic dispatch from JIT since it involves calling JSCell::inherits
IIUC.
60ff12d
to
3ac125e
Compare
EWS run on current version of this PR (hash 3ac125e) |
https://bugs.webkit.org/show_bug.cgi?id=251039 Reviewed by Justin Michaud. Adds extern conversion instructions to convert between anyref (internal references) and externref. The any to extern direction is currently a no-op. The extern to any direction requires checking for Numbers in the i31 range and converting them to i31ref representation. The any to extern is a no-op because JSC's value representation allows i31s to just be JSC 32-bit exact integers, and structs and arrays are represented as objects. This would need to change if the representation were to change, so that, e.g., structs and arrays have an optimized non-object wasm representation and a wrapper object is used to interop with JS. The addition of internalize means non-Wasm values (JS objects, strings, etc) can be converted into an internal reference as "host references" that are opaque to Wasm. These need to be distinguishable from true Wasm values, including in JIT code, which requires adding a WasmGCObjectType JSType. * JSTests/wasm/gc/extern.js: Added. (testInternalize): (testRoundtrip): (testTable): * JSTests/wasm/wasm.json: * Source/JavaScriptCore/bytecode/BytecodeList.rb: * Source/JavaScriptCore/llint/WebAssembly32_64.asm: * Source/JavaScriptCore/llint/WebAssembly64.asm: * Source/JavaScriptCore/runtime/JSType.cpp: (WTF::printInternal): * Source/JavaScriptCore/runtime/JSType.h: * Source/JavaScriptCore/wasm/WasmAirIRGeneratorBase.h: (JSC::Wasm::ExpressionType>::emitRefTestOrCast): (JSC::Wasm::ExpressionType>::makeBranchNotWasmGCObject): (JSC::Wasm::ExpressionType>::addExternInternalize): (JSC::Wasm::ExpressionType>::addExternExternalize): * Source/JavaScriptCore/wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::emitRefTestOrCast): (JSC::Wasm::B3IRGenerator::addExternInternalize): (JSC::Wasm::B3IRGenerator::addExternExternalize): * Source/JavaScriptCore/wasm/WasmBBQJIT.cpp: (JSC::Wasm::BBQJIT::addExternInternalize): (JSC::Wasm::BBQJIT::addExternExternalize): * Source/JavaScriptCore/wasm/WasmFormat.h: (JSC::Wasm::externrefType): (JSC::Wasm::anyrefType): * Source/JavaScriptCore/wasm/WasmFunctionParser.h: (JSC::Wasm::FunctionParser<Context>::parseExpression): * Source/JavaScriptCore/wasm/WasmLLIntBuiltin.h: * Source/JavaScriptCore/wasm/WasmLLIntGenerator.cpp: (JSC::Wasm::LLIntGenerator::addExternInternalize): (JSC::Wasm::LLIntGenerator::addExternExternalize): * Source/JavaScriptCore/wasm/WasmOperations.cpp: (JSC::Wasm::JSC_DEFINE_JIT_OPERATION): * Source/JavaScriptCore/wasm/WasmOperations.h: * Source/JavaScriptCore/wasm/WasmOperationsInlines.h: (JSC::Wasm::refCast): (JSC::Wasm::externInternalize): * Source/JavaScriptCore/wasm/WasmSlowPaths.cpp: (JSC::LLInt::WASM_SLOW_PATH_DECL): * Source/JavaScriptCore/wasm/WasmTypeDefinition.cpp: (JSC::Wasm::TypeInformation::signatureForLLIntBuiltin): (JSC::Wasm::TypeInformation::TypeInformation): * Source/JavaScriptCore/wasm/WasmTypeDefinition.h: * Source/JavaScriptCore/wasm/js/JSWebAssemblyArray.h: * Source/JavaScriptCore/wasm/js/JSWebAssemblyStruct.h: * Source/JavaScriptCore/wasm/wasm.json: Canonical link: https://commits.webkit.org/262282@main
3ac125e
to
e537d9e
Compare
Committed 262282@main (e537d9e): https://commits.webkit.org/262282@main Reviewed commits have been landed. Closing PR #11666 and removing active labels. |
e537d9e
3ac125e