Skip to content

feat: add BITSTATE_BYTECODE strategy for prefix-guarded scan patterns - #99

Merged
jbachorik merged 4 commits into
mainfrom
feat/bitstate-bytecode-generator
Jul 8, 2026
Merged

jbachorik merged 4 commits into
mainfrom
feat/bitstate-bytecode-generator

Conversation

@jbachorik

@jbachorik jbachorik commented Jul 8, 2026 •

Copy link
Copy Markdown
Collaborator

What does this PR do?

Adds a new BITSTATE_BYTECODE matching strategy: PatternAnalyzer.detectPrefixGuardedScan
recognizes the ^(?:leadingWs(kw1|kw2|...)separatorWs)?mandatoryCharSet+trailingWs*(tail)
AST shape and BitStateBytecodeGenerator compiles it to straight-line, non-backtracking JVM
bytecode instead of routing through the general BitState interpreter. Wired into both the
runtime (RuntimeCompiler) and compile-time (ReggieMatcherBytecodeGenerator) dispatch paths.

Motivation

This pattern shape (an optional prefix keyword + separator, then a mandatory greedy scan and a
.* tail) is common enough in practice to warrant a dedicated fast path over the general
BitState interpreter.

Related Issue(s)

Change Type

  • Bug fix
  • New feature
  • Performance improvement
  • Refactoring (no functional change)
  • Documentation
  • Test improvement
  • Build/CI change

Checklist

  • I have read the CONTRIBUTING.md guidelines
  • All existing tests pass (./gradlew build)
  • I have added tests for my changes
  • I have updated documentation (if applicable)
  • My commits are signed

Performance Impact

Not benchmarked in this PR.

Additional Notes

Detector-side hardening applied during review: decline when the leading-whitespace or separator
charset overlaps the mandatory charset (no give-back is possible without discarding the whole
prefix), require unbounded max and greedy quantifiers throughout the recognized shape, corrected
extractDisjointKeywords' javadoc to match the generator's actual sequential-comparison
implementation, and guard against an empty keyword list.

@jbachorik jbachorik added the AI Generated or assisted by AI label Jul 8, 2026
@codecov-commenter

codecov-commenter commented Jul 8, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.97863% with 47 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.4%. Comparing base (5db1866) to head (2f142d6).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
...doghq/reggie/codegen/analysis/PatternAnalyzer.java 75.6% 7 Missing and 30 partials ⚠️
...gie/codegen/codegen/BitStateBytecodeGenerator.java 98.6% 4 Missing and 6 partials ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##              main     #99     +/-   ##
=========================================
+ Coverage     83.1%   83.4%   +0.2%     
  Complexity       1       1             
=========================================
  Files          134     135      +1     
  Lines        41223   42147    +924     
  Branches      5548    5605     +57     
=========================================
+ Hits         34288   35166    +878     
- Misses        5217    5227     +10     
- Partials      1718    1754     +36     
Files with missing lines Coverage Δ
...ggie/processor/ReggieMatcherBytecodeGenerator.java 74.1% <100.0%> (+0.5%) ⬆️
.../com/datadoghq/reggie/runtime/BitStateMatcher.java 100.0% <100.0%> (ø)
.../com/datadoghq/reggie/runtime/RuntimeCompiler.java 87.9% <100.0%> (+<0.1%) ⬆️
...gie/codegen/codegen/BitStateBytecodeGenerator.java 98.6% <98.6%> (ø)
...doghq/reggie/codegen/analysis/PatternAnalyzer.java 76.0% <75.6%> (-0.1%) ⬇️

Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5db1866...2f142d6. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Detects the ^(?:leadingWs(kw1|kw2|...)separatorWs)?mandatoryCharSet+(tail)
AST shape and compiles it to straight-line bytecode instead of routing
through the general BitState interpreter.

Review fixes: decline when leadingWs/separator charsets overlap the
mandatory charset (no give-back possible), require unbounded+greedy
quantifiers throughout, correct extractDisjointKeywords javadoc, and
guard against an empty keyword list.
@jbachorik
jbachorik force-pushed the feat/bitstate-bytecode-generator branch from 515c482 to 7db5913 Compare July 8, 2026 10:19
jbachorik added 2 commits July 8, 2026 12:29
…d branches

Adds a compile-time ReggieMatcherBytecodeGenerator test for the case
BITSTATE_BYTECODE dispatch arm (previously 0% patch coverage — only the
runtime dispatch path was tested), plus PatternAnalyzer detector negative
tests for each quantifier's greedy/max guard and the leadingWs-overlap
branch, per the codecov coverage regression on PR #99.
@jbachorik
jbachorik marked this pull request as ready for review July 8, 2026 10:44

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0c69a83e02

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

skipSeparator only stores separatorMin and emits an unbounded greedy
scan, so a bounded separator quantifier (e.g. \s{1,3}) let the
generated matcher over-consume past JDK's upper bound, diverging on
inputs where the separator run exceeds the bound.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@jbachorik
jbachorik merged commit b9cf582 into main Jul 8, 2026
9 checks passed
@jbachorik
jbachorik deleted the feat/bitstate-bytecode-generator branch July 8, 2026 12:07
@jbachorik jbachorik added this to the 0.4.0 milestone Sep 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI Generated or assisted by AI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants