Skip to content

Conversation

takikawa
Copy link
Contributor

@takikawa takikawa commented Dec 11, 2023

7e71e72

[Wasm-GC] Update element segments to account for typed funcrefs and GC types
https://bugs.webkit.org/show_bug.cgi?id=251874

Reviewed by Justin Michaud.

Fix element segment parsing to allow more kinds of ref types (this is actually
a requirement of the reference types proposal, predating both typed funcref and
GC).

Also add support for general const expr initialization for elements.

For now, initialization steps for element segments are done each time on table
init or array.new_elem. This could be done earlier in module init instead (to
avoid duplciated work for shared elements), but that requires a larger change
to create a runtime representation of elements that can strongly hold
references.

Add missing spec tests and re-enable tests that now succeed as well. A small
validation fix was needed for the br_table test.

* JSTests/wasm/function-references-spec-tests/br_table.wast.js: Added.
* JSTests/wasm/function-references-spec-tests/ref.wast.js: Added.
* JSTests/wasm/function-references-spec-tests/ref_is_null.wast.js: Added.
* JSTests/wasm/function-references-spec-tests/table-sub.wast.js: Added.
* JSTests/wasm/function-references-spec-tests/unreached-valid.wast.js: Added.
* JSTests/wasm/gc-spec-tests/array.wast.js:
* JSTests/wasm/gc-spec-tests/binary-gc.wast.js: Added.
* JSTests/wasm/gc-spec-tests/ref_eq.wast.js: Added.
* JSTests/wasm/gc-spec-tests/ref_test.wast.js: Added.
* JSTests/wasm/gc/array_new_elem.js:
(testTypeMismatch):
(testAllElementSegmentKinds):
(testNullFunctionIndex):
* JSTests/wasm/gc/const-exprs.js:
(async testElementConstExprs):
* JSTests/wasm/gc/wast-wrapper.js:
* JSTests/wasm/references/element_active_mod.js:
(refNullExternInElemsSection):
* JSTests/wasm/v8/regress/regress-1046472.js:
* Source/JavaScriptCore/wasm/WasmConstExprGenerator.cpp:
(JSC::Wasm::evaluateExtendedConstExpr):
* Source/JavaScriptCore/wasm/WasmConstExprGenerator.h:
* Source/JavaScriptCore/wasm/WasmEntryPlan.cpp:
(JSC::Wasm::EntryPlan::prepare):
* Source/JavaScriptCore/wasm/WasmFormat.h:
(JSC::Wasm::Element::Element):
(JSC::Wasm::Element::length const):
(JSC::Wasm::Element::isNullFuncIndex): Deleted.
* Source/JavaScriptCore/wasm/WasmFunctionParser.h:
(JSC::Wasm::FunctionParser<Context>::addReferencedFunctions):
(JSC::Wasm::FunctionParser<Context>::parseExpression):
* Source/JavaScriptCore/wasm/WasmInstance.cpp:
(JSC::Wasm::Instance::initElementSegment):
(JSC::Wasm::Instance::copyElementSegment):
(JSC::Wasm::Instance::evaluateConstantExpression):
* Source/JavaScriptCore/wasm/WasmInstance.h:
* Source/JavaScriptCore/wasm/WasmSectionParser.cpp:
(JSC::Wasm::SectionParser::parseTableHelper):
(JSC::Wasm::SectionParser::parseElement):
(JSC::Wasm::SectionParser::validateElementTableIdx):
(JSC::Wasm::SectionParser::parseElementSegmentVectorOfExpressions):
(JSC::Wasm::SectionParser::parseElementSegmentVectorOfIndexes):
* Source/JavaScriptCore/wasm/WasmSectionParser.h:
* Source/JavaScriptCore/wasm/js/WebAssemblyModuleRecord.cpp:
(JSC::WebAssemblyModuleRecord::evaluateConstantExpression):
(JSC::WebAssemblyModuleRecord::evaluate):

Canonical link: https://commits.webkit.org/271952@main

a032f5e

Misc iOS, tvOS & watchOS macOS Linux Windows
✅ 🧪 style ✅ 🛠 ios ✅ 🛠 mac ✅ 🛠 wpe ✅ 🛠 wincairo
✅ 🛠 ios-sim ✅ 🛠 mac-AS-debug ✅ 🧪 wpe-wk2
✅ 🧪 webkitperl ✅ 🧪 ios-wk2 ✅ 🧪 api-mac ✅ 🧪 api-wpe
✅ 🧪 ios-wk2-wpt ✅ 🧪 mac-wk1 ✅ 🛠 gtk
🛠 🧪 jsc ✅ 🧪 api-ios ✅ 🧪 mac-wk2 🧪 gtk-wk2
🛠 🧪 jsc-arm64 ✅ 🛠 tv ✅ 🧪 mac-AS-debug-wk2 ✅ 🧪 api-gtk
✅ 🛠 tv-sim ✅ 🛠 jsc-armv7
✅ 🛠 🧪 merge ✅ 🛠 watch ✅ 🧪 jsc-armv7-tests
✅ 🛠 watch-sim

@takikawa takikawa self-assigned this Dec 11, 2023
@takikawa takikawa added the WebAssembly For bugs in JavaScript WebAssembly label Dec 11, 2023
@takikawa takikawa requested a review from a team as a code owner December 11, 2023 20:49
@takikawa
Copy link
Contributor Author

This will also close https://bugs.webkit.org/show_bug.cgi?id=260542

@takikawa takikawa force-pushed the eng/Wasm-GC-Update-element-segments-to-account-for-typed-funcrefs-and-GC-types branch from cefa447 to 8570de3 Compare December 11, 2023 20:56
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be fixed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh whoops, thanks for catching this. Currently it's not expected that this should ever fail, so I'll put in a RELEASE_ASSERT but once I fix https://bugs.webkit.org/show_bug.cgi?id=264454 it will change to throw an exception in rare cases (ditto for the other call of evaluateConstantExpression).

@takikawa
Copy link
Contributor Author

BTW there is a test failure in armv7, which just looks to be the result of error message mismatch (test still fails correctly). I'll update the expected message when I push in a bit.

@takikawa takikawa force-pushed the eng/Wasm-GC-Update-element-segments-to-account-for-typed-funcrefs-and-GC-types branch from 8570de3 to 818914a Compare December 11, 2023 22:17
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Dec 12, 2023
Copy link
Contributor

@justinmichaud justinmichaud left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r=me

@takikawa takikawa added merge-queue Applied to send a pull request to merge-queue and removed merging-blocked Applied to prevent a change from being merged labels Dec 12, 2023
@webkit-commit-queue
Copy link
Collaborator

No reviewer information in commit message, blocking PR #21647

@webkit-commit-queue webkit-commit-queue added merging-blocked Applied to prevent a change from being merged and removed merge-queue Applied to send a pull request to merge-queue labels Dec 12, 2023
@takikawa takikawa removed the merging-blocked Applied to prevent a change from being merged label Dec 12, 2023
@takikawa takikawa force-pushed the eng/Wasm-GC-Update-element-segments-to-account-for-typed-funcrefs-and-GC-types branch from 818914a to a032f5e Compare December 12, 2023 19:55
@takikawa takikawa added the merge-queue Applied to send a pull request to merge-queue label Dec 12, 2023
…C types

https://bugs.webkit.org/show_bug.cgi?id=251874

Reviewed by Justin Michaud.

Fix element segment parsing to allow more kinds of ref types (this is actually
a requirement of the reference types proposal, predating both typed funcref and
GC).

Also add support for general const expr initialization for elements.

For now, initialization steps for element segments are done each time on table
init or array.new_elem. This could be done earlier in module init instead (to
avoid duplciated work for shared elements), but that requires a larger change
to create a runtime representation of elements that can strongly hold
references.

Add missing spec tests and re-enable tests that now succeed as well. A small
validation fix was needed for the br_table test.

* JSTests/wasm/function-references-spec-tests/br_table.wast.js: Added.
* JSTests/wasm/function-references-spec-tests/ref.wast.js: Added.
* JSTests/wasm/function-references-spec-tests/ref_is_null.wast.js: Added.
* JSTests/wasm/function-references-spec-tests/table-sub.wast.js: Added.
* JSTests/wasm/function-references-spec-tests/unreached-valid.wast.js: Added.
* JSTests/wasm/gc-spec-tests/array.wast.js:
* JSTests/wasm/gc-spec-tests/binary-gc.wast.js: Added.
* JSTests/wasm/gc-spec-tests/ref_eq.wast.js: Added.
* JSTests/wasm/gc-spec-tests/ref_test.wast.js: Added.
* JSTests/wasm/gc/array_new_elem.js:
(testTypeMismatch):
(testAllElementSegmentKinds):
(testNullFunctionIndex):
* JSTests/wasm/gc/const-exprs.js:
(async testElementConstExprs):
* JSTests/wasm/gc/wast-wrapper.js:
* JSTests/wasm/references/element_active_mod.js:
(refNullExternInElemsSection):
* JSTests/wasm/v8/regress/regress-1046472.js:
* Source/JavaScriptCore/wasm/WasmConstExprGenerator.cpp:
(JSC::Wasm::evaluateExtendedConstExpr):
* Source/JavaScriptCore/wasm/WasmConstExprGenerator.h:
* Source/JavaScriptCore/wasm/WasmEntryPlan.cpp:
(JSC::Wasm::EntryPlan::prepare):
* Source/JavaScriptCore/wasm/WasmFormat.h:
(JSC::Wasm::Element::Element):
(JSC::Wasm::Element::length const):
(JSC::Wasm::Element::isNullFuncIndex): Deleted.
* Source/JavaScriptCore/wasm/WasmFunctionParser.h:
(JSC::Wasm::FunctionParser<Context>::addReferencedFunctions):
(JSC::Wasm::FunctionParser<Context>::parseExpression):
* Source/JavaScriptCore/wasm/WasmInstance.cpp:
(JSC::Wasm::Instance::initElementSegment):
(JSC::Wasm::Instance::copyElementSegment):
(JSC::Wasm::Instance::evaluateConstantExpression):
* Source/JavaScriptCore/wasm/WasmInstance.h:
* Source/JavaScriptCore/wasm/WasmSectionParser.cpp:
(JSC::Wasm::SectionParser::parseTableHelper):
(JSC::Wasm::SectionParser::parseElement):
(JSC::Wasm::SectionParser::validateElementTableIdx):
(JSC::Wasm::SectionParser::parseElementSegmentVectorOfExpressions):
(JSC::Wasm::SectionParser::parseElementSegmentVectorOfIndexes):
* Source/JavaScriptCore/wasm/WasmSectionParser.h:
* Source/JavaScriptCore/wasm/js/WebAssemblyModuleRecord.cpp:
(JSC::WebAssemblyModuleRecord::evaluateConstantExpression):
(JSC::WebAssemblyModuleRecord::evaluate):

Canonical link: https://commits.webkit.org/271952@main
@webkit-commit-queue webkit-commit-queue force-pushed the eng/Wasm-GC-Update-element-segments-to-account-for-typed-funcrefs-and-GC-types branch from a032f5e to 7e71e72 Compare December 12, 2023 22:16
@webkit-commit-queue
Copy link
Collaborator

Committed 271952@main (7e71e72): https://commits.webkit.org/271952@main

Reviewed commits have been landed. Closing PR #21647 and removing active labels.

@webkit-commit-queue webkit-commit-queue merged commit 7e71e72 into WebKit:main Dec 12, 2023
@webkit-commit-queue webkit-commit-queue removed the merge-queue Applied to send a pull request to merge-queue label Dec 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

WebAssembly For bugs in JavaScript WebAssembly

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants