Skip to content

test: differential replacement/split parity suite; fix DFA_UNROLLED findBoundsFrom match truncation - #145

Merged
jbachorik merged 2 commits into
mainfrom
test/replacement-ops-parity
Oct 5, 2026
Merged

jbachorik merged 2 commits into
mainfrom
test/replacement-ops-parity

Conversation

@jbachorik

Copy link
Copy Markdown
Collaborator

What does this PR do?

Adds a differential parity suite pinning the replacement/collection ops of ReggieMatcher — replaceAll(String,String), replaceFirst, functional replaceAll, split(String,int) — against java.util.regex as the oracle (curated + 400-case seeded randomized inputs), and fixes a real bug the suite caught: the DFA_UNROLLED generated findBoundsFrom greedy scan skipped its lastAcceptingPos record at "skippable" accepting states, which truncated matches and corrupted split/replaceAll results (e.g. cbb|b{0,2}b on "bb" reported [0,1) instead of [0,2)).

The optimization was statically unsound — any accepting state can be the scan's terminal state, and a terminal skippable state never records — so it is removed entirely: every accepting state records unconditionally. The scan now also delegates to the anchor-aware findLongestMatchEnd path when any state carries acceptance anchor conditions, and the unreachable assertion-handling path (dead since delegation already covers all assertion-bearing DFAs) is deleted.

Six intentional divergences from the JDK are documented in the suite and pinned on both engines (JDK drift fails the test too): no backslash-escape processing in replacement strings, $$ accepted as literal $, out-of-range/trailing $ group references appended literally instead of throwing, and functional replaceAll using the replacer result verbatim.

Motivation

The profiling-backend wave-3 migration relies on these ops per operation; the engine-level semantic contract had no differential coverage (only backend per-site parity), which is why the findBoundsFrom truncation survived.

Related Issue(s)

Draft source: .issue-drafts/2-replacement-ops-parity.md. Note the draft's premise that reggie treats $ literally in replaceAll was wrong (verified empirically) — reggie expands $n; the real divergences are the ones documented in the suite.

Change Type

  • Bug fix
  • Test improvement

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

JMH A/B (pre 967e525 vs post, 3 interleaved runs, medians): replaceAll(b{0,2}b) −31%, replaceAll(b{0,4}bc?) −16%, split(b{0,2}b) −35%; control pattern within noise. The pre-fix truncation caused more, shorter match scans; the unconditional 2-instruction record is free.

Additional Notes

Full in-depth review already performed by independent fresh-context reviewers (bytecode-trace verified removal, no sibling generator carries the pattern, all 6 divergences confirmed against JDK 26). Reviewer-flagged follow-up: none open in this diff. Gate evidence: :reggie-runtime:test + :reggie-integration-tests:test = 3281 tests, 0 failures; spotlessCheck green.

…dsFrom

The skippable-accepting-state optimization was statically unsound: any
accepting state can be the greedy scan's terminal state, and a terminal
skippable state never recorded, truncating matches (b{0,2}b on "bb" gave
[0,1) instead of [0,2)), corrupting split/replaceAll. Also delegate
anchor-conditioned acceptance to findLongestMatchEnd and drop the dead
assertion path (unreachable since delegation covers all assertion-bearing
DFAs). JMH A/B: the fix is faster on affected patterns (16-35%).
@jbachorik jbachorik added the AI Generated or assisted by AI label Oct 5, 2026
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.1%. Comparing base (967e525) to head (9c1c849).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main    #145     +/-   ##
=========================================
+ Coverage     84.9%   85.1%   +0.2%     
  Complexity       1       1             
=========================================
  Files          163     163             
  Lines        48981   48847    -134     
  Branches      7000    6970     -30     
=========================================
- Hits         41594   41588      -6     
+ Misses        5378    5258    -120     
+ Partials      2009    2001      -8     
Files with missing lines Coverage Δ
.../codegen/codegen/DFAUnrolledBytecodeGenerator.java 95.6% <100.0%> (+5.2%) ⬆️

... and 7 files with indirect coverage changes


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 967e525...9c1c849. Read the comment docs.

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

@jbachorik
jbachorik marked this pull request as ready for review October 5, 2026 10:00
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-05T10:05:52.551944Z 9c1c849 Draft marked ready
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@datadog-datadog-prod-us1 datadog-datadog-prod-us1 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.

Bits Code Review: PASS

More details

Unconditional accepting-state recording and delegation of assertion/anchor-bearing DFAs to the existing longest-end path address the truncation without a reportable regression.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit 9c1c849 · @DataDog review to ask questions

@jbachorik
jbachorik merged commit 584dfca into main Oct 5, 2026
9 checks passed
@jbachorik
jbachorik deleted the test/replacement-ops-parity branch October 5, 2026 10:31
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