Skip to content

Conversation

@Constellation
Copy link
Member

@Constellation Constellation commented Jan 21, 2026

ea11204

[JSC] Introduce B3 WasmRefCast / WasmRefTest values
https://bugs.webkit.org/show_bug.cgi?id=305912
rdar://168566739

Reviewed by Keith Miller.

We introduce WasmRefCast and WasmRefTest B3 values. This is another
high-level B3 nodes for WasmGC. This enables data-flow analysis for wasm
GC operations in B3 finally.
The generated code is literally just moved from OMG IR generator to
B3LowerMacros. We introduce ValueKey Value::key CSE support for these
values.

Based on this high-level semantics, we start using it in ReduceStrength.
We make WasmStructGet, WasmStructSet can remove trapping bits based on
input's WasmRefCast. And WasmRefCast can make convert itself to non-nullable
based on subsequent values in the same basic block.

* Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj:
* Source/JavaScriptCore/Sources.txt:
* Source/JavaScriptCore/b3/B3Kind.h:
(JSC::B3::Kind::hasTraps const):
* Source/JavaScriptCore/b3/B3LowerMacros.cpp:
* Source/JavaScriptCore/b3/B3Opcode.h:
* Source/JavaScriptCore/b3/B3ReduceStrength.cpp:
* Source/JavaScriptCore/b3/B3Validate.cpp:
* Source/JavaScriptCore/b3/B3Value.cpp:
(JSC::B3::Value::effects const):
(JSC::B3::Value::key const):
* Source/JavaScriptCore/b3/B3Value.h:
* Source/JavaScriptCore/b3/B3ValueInlines.h:
* Source/JavaScriptCore/b3/B3ValueKey.cpp:
(JSC::B3::ValueKey::materialize const):
* Source/JavaScriptCore/b3/B3ValueKey.h:
* Source/JavaScriptCore/b3/B3ValueKeyInlines.h:
(JSC::B3::ValueKey::ValueKey):
* Source/JavaScriptCore/b3/B3WasmRefTypeCheckValue.cpp: Added.
* Source/JavaScriptCore/b3/B3WasmRefTypeCheckValue.h: Added.
* Source/JavaScriptCore/wasm/WasmOMGIRGenerator.cpp:
(JSC::Wasm::OMGIRGenerator::emitRefTestOrCast):
(JSC::Wasm::OMGIRGenerator::emitCheckOrBranchForCast): Deleted.
* Source/JavaScriptCore/wasm/WasmTypeDefinition.cpp:
(JSC::Wasm::RTT::RTT):
(JSC::Wasm::RTT::tryCreate):
(JSC::Wasm::TypeInformation::createCanonicalRTTForType):
* Source/JavaScriptCore/wasm/WasmTypeDefinition.h:

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

77bc15b

Misc iOS, visionOS, tvOS & watchOS macOS Linux Windows Apple Internal
✅ 🧪 style ✅ 🛠 ios ✅ 🛠 mac 🛠 wpe 🛠 win ⏳ 🛠 ios-apple
✅ 🛠 ios-sim ✅ 🛠 mac-AS-debug 🧪 wpe-wk2 🧪 win-tests ⏳ 🛠 mac-apple
✅ 🧪 webkitperl 🧪 ios-wk2 🧪 api-mac 🧪 api-wpe ⏳ 🛠 vision-apple
🧪 ios-wk2-wpt 🧪 api-mac-debug ❌ 🛠 wpe-cairo-libwebrtc
✅ 🛠 🧪 jsc 🧪 api-ios 🧪 mac-wk1 ❌ 🛠 gtk
🛠 🧪 jsc-debug-arm64 ✅ 🛠 vision 🧪 mac-wk2 ❌ 🧪 gtk-wk2
✅ 🛠 vision-sim 🧪 mac-AS-debug-wk2 ❌ 🧪 api-gtk
🧪 vision-wk2 🧪 mac-wk2-stress 🛠 playstation
✅ 🛠 🧪 unsafe-merge 🛠 tv 🧪 mac-intel-wk2 🛠 jsc-armv7
✅ 🛠 tv-sim 🛠 mac-safer-cpp 🧪 jsc-armv7-tests
🛠 watch
🛠 watch-sim

@Constellation Constellation self-assigned this Jan 21, 2026
@Constellation Constellation added the JavaScriptCore For bugs in JavaScriptCore, the JS engine used by WebKit, other than kxmlcore issues. label Jan 21, 2026
@Constellation Constellation force-pushed the eng/JSC-Introduce-B3-WasmRefCast-WasmRefTest-values branch from eda956d to d973293 Compare January 21, 2026 08:46
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Jan 21, 2026
@webkit-ews-buildbot
Copy link
Collaborator

Safer C++ Build #75642 (d973293)

❌ Found 1 failing file with 1 issue. Please address these issues before landing. See WebKit Guidelines for Safer C++ Programming.
(cc @rniwa)

@Constellation Constellation removed the merging-blocked Applied to prevent a change from being merged label Jan 22, 2026
@Constellation Constellation force-pushed the eng/JSC-Introduce-B3-WasmRefCast-WasmRefTest-values branch from d973293 to d2d56b4 Compare January 22, 2026 01:14
@Constellation Constellation force-pushed the eng/JSC-Introduce-B3-WasmRefCast-WasmRefTest-values branch from d2d56b4 to 7f80ffb Compare January 22, 2026 01:17
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Jan 22, 2026
@Constellation Constellation removed the merging-blocked Applied to prevent a change from being merged label Jan 22, 2026
@Constellation Constellation force-pushed the eng/JSC-Introduce-B3-WasmRefCast-WasmRefTest-values branch from 7f80ffb to a743328 Compare January 22, 2026 03:34
@Constellation Constellation marked this pull request as ready for review January 22, 2026 03:35
@Constellation Constellation requested a review from a team as a code owner January 22, 2026 03:35
@Constellation Constellation force-pushed the eng/JSC-Introduce-B3-WasmRefCast-WasmRefTest-values branch from a743328 to f7d8aeb Compare January 22, 2026 03:36
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Jan 22, 2026
@Constellation Constellation removed the merging-blocked Applied to prevent a change from being merged label Jan 22, 2026
@Constellation Constellation force-pushed the eng/JSC-Introduce-B3-WasmRefCast-WasmRefTest-values branch from f7d8aeb to 5ff9619 Compare January 22, 2026 04:29
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Jan 22, 2026
@Constellation Constellation removed the merging-blocked Applied to prevent a change from being merged label Jan 22, 2026
@Constellation Constellation force-pushed the eng/JSC-Introduce-B3-WasmRefCast-WasmRefTest-values branch from 5ff9619 to 7056696 Compare January 22, 2026 06:21
@Constellation Constellation force-pushed the eng/JSC-Introduce-B3-WasmRefCast-WasmRefTest-values branch from 7056696 to ea12212 Compare January 22, 2026 17:35
Copy link
Contributor

@kmiller68 kmiller68 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 if you get rid of the extra subclasses for B3::WasmRefTypeCheckValue

Comment on lines +794 to +796
BasicBlock* before = m_blockInsertionSet.splitForward(m_block, m_index, &m_insertionSet);
BasicBlock* continuation = m_block;
m_value->replaceWithIdentity(emitRefTestOrCast(typeCheck, before, continuation));
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems like most of the time for Casts we wouldn't have to create the continuation. Might be worth a FIXME to only split the block if we're actually inserting new control flow.

HasRTT = 1 << 5, // Whether m_targetRTT is non-null (vs using targetHeapType)
};

class WasmRefTypeCheckValue : public Value {
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like we can just have WasmRefCast and WasmRefTest share the same WasmRefTypeCheckValue and get rid of the specialized subclasses. Those subclasses don't have anything interesting in them and I think we mostly use different Values subclasses when we need extra fields, which isn't the case here.

Copy link
Member Author

Choose a reason for hiding this comment

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

That's nice, changed.

};

if (cast->allowNull()) {
// This is really common in J2CL, Java to wasm compiler. When you write a code in Java like,
Copy link
Contributor

Choose a reason for hiding this comment

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

Might be worth mentioning that this comment is from JS3, it's possible future versions of J2CL in JS4+ lower code differently.

Copy link
Member Author

Choose a reason for hiding this comment

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

That's good. Changed.

@Constellation Constellation force-pushed the eng/JSC-Introduce-B3-WasmRefCast-WasmRefTest-values branch from ea12212 to 013402d Compare January 22, 2026 23:09
@Constellation Constellation force-pushed the eng/JSC-Introduce-B3-WasmRefCast-WasmRefTest-values branch from 013402d to b515c3a Compare January 23, 2026 02:49
@Constellation Constellation force-pushed the eng/JSC-Introduce-B3-WasmRefCast-WasmRefTest-values branch from b515c3a to 77bc15b Compare January 23, 2026 07:38
@Constellation Constellation added the unsafe-merge-queue Applied to send a pull request to merge-queue, but skip building and testing label Jan 23, 2026
https://bugs.webkit.org/show_bug.cgi?id=305912
rdar://168566739

Reviewed by Keith Miller.

We introduce WasmRefCast and WasmRefTest B3 values. This is another
high-level B3 nodes for WasmGC. This enables data-flow analysis for wasm
GC operations in B3 finally.
The generated code is literally just moved from OMG IR generator to
B3LowerMacros. We introduce ValueKey Value::key CSE support for these
values.

Based on this high-level semantics, we start using it in ReduceStrength.
We make WasmStructGet, WasmStructSet can remove trapping bits based on
input's WasmRefCast. And WasmRefCast can make convert itself to non-nullable
based on subsequent values in the same basic block.

* Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj:
* Source/JavaScriptCore/Sources.txt:
* Source/JavaScriptCore/b3/B3Kind.h:
(JSC::B3::Kind::hasTraps const):
* Source/JavaScriptCore/b3/B3LowerMacros.cpp:
* Source/JavaScriptCore/b3/B3Opcode.h:
* Source/JavaScriptCore/b3/B3ReduceStrength.cpp:
* Source/JavaScriptCore/b3/B3Validate.cpp:
* Source/JavaScriptCore/b3/B3Value.cpp:
(JSC::B3::Value::effects const):
(JSC::B3::Value::key const):
* Source/JavaScriptCore/b3/B3Value.h:
* Source/JavaScriptCore/b3/B3ValueInlines.h:
* Source/JavaScriptCore/b3/B3ValueKey.cpp:
(JSC::B3::ValueKey::materialize const):
* Source/JavaScriptCore/b3/B3ValueKey.h:
* Source/JavaScriptCore/b3/B3ValueKeyInlines.h:
(JSC::B3::ValueKey::ValueKey):
* Source/JavaScriptCore/b3/B3WasmRefTypeCheckValue.cpp: Added.
* Source/JavaScriptCore/b3/B3WasmRefTypeCheckValue.h: Added.
* Source/JavaScriptCore/wasm/WasmOMGIRGenerator.cpp:
(JSC::Wasm::OMGIRGenerator::emitRefTestOrCast):
(JSC::Wasm::OMGIRGenerator::emitCheckOrBranchForCast): Deleted.
* Source/JavaScriptCore/wasm/WasmTypeDefinition.cpp:
(JSC::Wasm::RTT::RTT):
(JSC::Wasm::RTT::tryCreate):
(JSC::Wasm::TypeInformation::createCanonicalRTTForType):
* Source/JavaScriptCore/wasm/WasmTypeDefinition.h:

Canonical link: https://commits.webkit.org/306061@main
@webkit-commit-queue webkit-commit-queue force-pushed the eng/JSC-Introduce-B3-WasmRefCast-WasmRefTest-values branch from 77bc15b to ea11204 Compare January 23, 2026 07:41
@webkit-commit-queue
Copy link
Collaborator

Committed 306061@main (ea11204): https://commits.webkit.org/306061@main

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

@webkit-commit-queue webkit-commit-queue merged commit ea11204 into WebKit:main Jan 23, 2026
@webkit-commit-queue webkit-commit-queue removed the unsafe-merge-queue Applied to send a pull request to merge-queue, but skip building and testing label Jan 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

JavaScriptCore For bugs in JavaScriptCore, the JS engine used by WebKit, other than kxmlcore issues.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants