Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: d328c270769037f111e31474429e19999c446382
      
https://github.com/WebKit/WebKit/commit/d328c270769037f111e31474429e19999c446382
  Author: Yusuke Suzuki <[email protected]>
  Date:   2026-07-23 (Thu, 23 Jul 2026)

  Changed paths:
    A JSTests/stress/regexp-exec-anchored-first-char-filter.js
    A JSTests/stress/regexp-exec-sticky-first-char-filter.js
    A JSTests/stress/regexp-test-anchored-first-char-filter.js
    M Source/JavaScriptCore/dfg/DFGCommonData.h
    M Source/JavaScriptCore/dfg/DFGSpeculativeJIT.cpp
    M Source/JavaScriptCore/dfg/DFGSpeculativeJIT.h
    M Source/JavaScriptCore/dfg/DFGSpeculativeJIT64.cpp
    M Source/JavaScriptCore/ftl/FTLLowerDFGToB3.cpp
    M Source/JavaScriptCore/yarr/YarrPattern.cpp
    M Source/JavaScriptCore/yarr/YarrPattern.h

  Log Message:
  -----------
  [JSC] DFG / FTL should have fast-fail filter for RegExp with BOL assertions
https://bugs.webkit.org/show_bug.cgi?id=320128
rdar://183067008

Reviewed by Yijia Huang.

/^regexp/ or sticky bit (y) is used for testing frequently, and the
purpose of this is typically accepting or rejecting a subject. In
particular, sticky bit is introduced mainly for tokenizing pattern, and
it should extremely quickly reject a subject when it does not match and
this pattern is expected use case.

>From this perspective, this patch introduces fast-fail filter. This is
similar to YarrJIT boyermoore lookahead, but the purpose is more
specific: it is quickly rejecting a subject which never matches. On the
other hand, boyermoore lookahead's purpose is finding the false-positive
matching index. We run FirstCharacterBitmapBuilder to collect BitSet for
latin-1 range which quickly answers rejection to avoid actual costly
matching operations. Currently we are only accepting latin-1 (8-bit),
but we should extend it for 16-bit cases as well.

When sticky bit is used, RegExp will work as if it is having BOL
assertion with the current lastIndex offset of a subject. So we do not
need to check BOL, and instead, we need to extract a character from
lastIndex place. Otherwise, we can just extract a character from index 0
and do this filtering only when the pattern is having
one-character-size-prefix and the subject is 8-bit. We do not do this
filtering for global bit case as it is extracting a character from lastIndex.

Tests: JSTests/stress/regexp-exec-anchored-first-char-filter.js
       JSTests/stress/regexp-exec-sticky-first-char-filter.js
       JSTests/stress/regexp-test-anchored-first-char-filter.js

* JSTests/stress/regexp-exec-anchored-first-char-filter.js: Added.
(shouldBe):
(execStr):
(step):
* JSTests/stress/regexp-exec-sticky-first-char-filter.js: Added.
(shouldBe):
(shouldThrow):
(step):
* JSTests/stress/regexp-test-anchored-first-char-filter.js: Added.
(shouldBe):
(step):
(check):
* Source/JavaScriptCore/dfg/DFGCommonData.h:
* Source/JavaScriptCore/dfg/DFGSpeculativeJIT.cpp:
* Source/JavaScriptCore/dfg/DFGSpeculativeJIT.h:
* Source/JavaScriptCore/dfg/DFGSpeculativeJIT64.cpp:
(JSC::DFG::SpeculativeJIT::emitFirstCharacterBitmapMatch):
* Source/JavaScriptCore/ftl/FTLLowerDFGToB3.cpp:
(JSC::FTL::DFG::LowerDFGToB3::compileCompareStrictEq):
* Source/JavaScriptCore/yarr/YarrPattern.cpp:
(JSC::Yarr::FirstCharacterBitmapBuilder::FirstCharacterBitmapBuilder):
(JSC::Yarr::FirstCharacterBitmapBuilder::build):
(JSC::Yarr::FirstCharacterBitmapBuilder::setBit):
(JSC::Yarr::FirstCharacterBitmapBuilder::addCharacterClass):
(JSC::Yarr::FirstCharacterBitmapBuilder::addTerm):
(JSC::Yarr::FirstCharacterBitmapBuilder::addAlternative):
(JSC::Yarr::FirstCharacterBitmapBuilder::addDisjunction):
(JSC::Yarr::computeStickyFirstCharacterBitmap):
(JSC::Yarr::computeAnchoredFirstCharacterBitmap):
* Source/JavaScriptCore/yarr/YarrPattern.h:

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



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications

Reply via email to