Skip to content

Conversation

shvaikalesh
Copy link
Member

@shvaikalesh shvaikalesh commented Dec 7, 2022

64f2b05

[JSC] RegExp.prototype's @@match and @@replace should use "flags" getter only
https://bugs.webkit.org/show_bug.cgi?id=248605

Reviewed by NOBODY (OOPS!).

This change implements recent spec change [1], aligning RegExp.prototype's
@@match / @@replace with @@split / @@matchAll to use only "flags" getter to
check for flags, which is observable.

Ensures that DFG watches and constant-folds all related invoked prototype getters,
which was proven to be neutral on both JetStream2 and Speedometer2.

[1]: tc39/ecma262#2791

* JSTests/test262/expectations.yaml: Mark 12 test cases as passing.
* Source/JavaScriptCore/builtins/BuiltinNames.h:
* Source/JavaScriptCore/builtins/RegExpPrototype.js:
(linkTimeConstant.hasObservableSideEffectsForRegExpMatch):
(linkTimeConstant.matchSlow):
(overriddenName.string_appeared_here.replace):
(linkTimeConstant.hasObservableSideEffectsForRegExpSplit):
* Source/JavaScriptCore/builtins/StringPrototype.js:
(linkTimeConstant.hasObservableSideEffectsForStringReplace):
* Source/JavaScriptCore/bytecode/LinkTimeConstant.h:
* Source/JavaScriptCore/dfg/DFGAbstractInterpreterInlines.h:
(JSC::DFG::AbstractInterpreter<AbstractStateType>::executeEffects):
* Source/JavaScriptCore/dfg/DFGFixupPhase.cpp:
(JSC::DFG::FixupPhase::addStringReplacePrimordialChecks):
* Source/JavaScriptCore/runtime/JSGlobalObject.cpp:
(JSC::JSGlobalObject::init):
* Source/JavaScriptCore/runtime/JSGlobalObject.h:
* Source/JavaScriptCore/runtime/JSGlobalObjectInlines.h:
(JSC::JSGlobalObject::regExpProtoFlagsGetter const):
(JSC::JSGlobalObject::regExpProtoDotAllGetter const):
(JSC::JSGlobalObject::regExpProtoHasIndicesGetter const):
(JSC::JSGlobalObject::regExpProtoIgnoreCaseGetter const):
(JSC::JSGlobalObject::regExpProtoMultilineGetter const):
(JSC::JSGlobalObject::regExpProtoStickyGetter const):

582aab2

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

@shvaikalesh shvaikalesh requested a review from a team as a code owner December 7, 2022 21:49
@shvaikalesh shvaikalesh self-assigned this Dec 7, 2022
@shvaikalesh shvaikalesh added the JavaScriptCore For bugs in JavaScriptCore, the JS engine used by WebKit, other than kxmlcore issues. label Dec 7, 2022
@shvaikalesh shvaikalesh force-pushed the eng/JSC-RegExp-prototypes-match-and-replace-should-use-flags-getter-only branch from 582aab2 to d5ae907 Compare December 7, 2022 22:08
…ter only

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

Reviewed by NOBODY (OOPS!).

This change implements recent spec change [1], aligning RegExp.prototype's
@@match / @@replace with @@split / @@matchall to use only "flags" getter to
check for flags, which is observable.

Ensures that DFG watches and constant-folds all related invoked prototype getters,
which was proven to be neutral on both JetStream2 and Speedometer2.

[1]: tc39/ecma262#2791

* JSTests/test262/expectations.yaml: Mark 12 test cases as passing.
* Source/JavaScriptCore/builtins/BuiltinNames.h:
* Source/JavaScriptCore/builtins/RegExpPrototype.js:
(linkTimeConstant.hasObservableSideEffectsForRegExpMatch):
(linkTimeConstant.matchSlow):
(overriddenName.string_appeared_here.replace):
(linkTimeConstant.hasObservableSideEffectsForRegExpSplit):
* Source/JavaScriptCore/builtins/StringPrototype.js:
(linkTimeConstant.hasObservableSideEffectsForStringReplace):
* Source/JavaScriptCore/bytecode/LinkTimeConstant.h:
* Source/JavaScriptCore/dfg/DFGAbstractInterpreterInlines.h:
(JSC::DFG::AbstractInterpreter<AbstractStateType>::executeEffects):
* Source/JavaScriptCore/dfg/DFGFixupPhase.cpp:
(JSC::DFG::FixupPhase::addStringReplacePrimordialChecks):
* Source/JavaScriptCore/runtime/JSGlobalObject.cpp:
(JSC::JSGlobalObject::init):
* Source/JavaScriptCore/runtime/JSGlobalObject.h:
* Source/JavaScriptCore/runtime/JSGlobalObjectInlines.h:
(JSC::JSGlobalObject::regExpProtoFlagsGetter const):
(JSC::JSGlobalObject::regExpProtoDotAllGetter const):
(JSC::JSGlobalObject::regExpProtoHasIndicesGetter const):
(JSC::JSGlobalObject::regExpProtoIgnoreCaseGetter const):
(JSC::JSGlobalObject::regExpProtoMultilineGetter const):
(JSC::JSGlobalObject::regExpProtoStickyGetter const):
@shvaikalesh shvaikalesh force-pushed the eng/JSC-RegExp-prototypes-match-and-replace-should-use-flags-getter-only branch from d5ae907 to 64f2b05 Compare December 7, 2022 22:14
@@ -291,11 +314,13 @@ function replace(strArg, replace)
if (!functionalReplace)
replace = @toString(replace);

var global = regexp.global;
var flags = @toString(regexp.flags);
Copy link
Member

Choose a reason for hiding this comment

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

Is it used for the fast path? Or not used and only used for slow path? I think flags generates strings, and it is strictly worse than global's flag (just returning boolean) in terms of performance, so I would like to know that we have optimization for flags, or it is not used in the most places.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's used only for slow path of String.prototype.replace, if @hasObservableSideEffectsForStringReplace returns false.

Copy link
Member

@Constellation Constellation 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

webkit-commit-queue pushed a commit to sosukesuzuki/WebKit that referenced this pull request Feb 21, 2025
…s` getter only

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

Reviewed by Yusuke Suzuki.

This patch implements recent spec change [1], aligning RegExp.prototype's
@@match / @@replace with @@split / @@matchall to use only "flags" getter to
check for flags, which is observable.

This patch is based on the PR by Alexey Shvayka[2]. Also according to
the PR, no performance regressions.

[1]: tc39/ecma262#2791
[2]: WebKit#7281

* JSTests/test262/expectations.yaml:
* Source/JavaScriptCore/builtins/RegExpPrototype.js:
(linkTimeConstant.hasObservableSideEffectsForRegExpMatch):
(linkTimeConstant.matchSlow):
(overriddenName.string_appeared_here.replace):
* Source/JavaScriptCore/builtins/StringPrototype.js:
(linkTimeConstant.hasObservableSideEffectsForStringReplace):

Canonical link: https://commits.webkit.org/290785@main
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.

3 participants