Skip to content

fix(grit): backtrack into contains when later conditions fail - #12063

Merged
dyc3 merged 1 commit into
mainfrom
dyc3/grit-contains-backtracking
Oct 1, 2026
Merged

dyc3 merged 1 commit into
mainfrom
dyc3/grit-contains-backtracking

Conversation

@dyc3

@dyc3 dyc3 commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This fixes a bug where grit checks only the first string in X ? "foo" : "bar" instead of both for queries that look like this:

JsConditionalExpression() as $conditionalExp where {
  $conditionalExp <: contains JsStringLiteralExpression() as $stringExp,
  $stringExp = trim($stringExp, trim_chars=`'"`),
  $stringExp <: `orange`
}

see #9749

Note that this deviates from the reference implementation's behavior, which is intentional, because its a bug in the reference implementation too.

fixed by opus 5.5

fixes #9749

Test Plan

Docs

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@changeset-bot

changeset-bot Bot commented Oct 1, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: b9bee8a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 13 packages
Name Type
@biomejs/biome Patch
@biomejs/cli-darwin-arm64 Patch
@biomejs/cli-darwin-x64 Patch
@biomejs/cli-linux-arm64-musl Patch
@biomejs/cli-linux-arm64 Patch
@biomejs/cli-linux-x64-musl Patch
@biomejs/cli-linux-x64 Patch
@biomejs/cli-win32-arm64 Patch
@biomejs/cli-win32-x64 Patch
@biomejs/wasm-bundler Patch
@biomejs/wasm-nodejs Patch
@biomejs/wasm-web Patch
@biomejs/backend-jsonrpc Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions Bot added the L-Grit Language: GritQL label Oct 1, 2026
@dyc3
dyc3 marked this pull request as ready for review October 1, 2026 17:19
@codspeed

codspeed Bot commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

⚠️ 3 benchmarks measured no execution time

Nothing ran under measurement, usually because the compiler removed the code under test. These results are not comparable, so they count as unchanged.

Preventing compiler optimizations

✅ 49 untouched benchmarks
⏩ 364 skipped benchmarks1

Performance Changes

Benchmark BASE HEAD Efficiency
⚠️ grit_query_anchor_kinds[code_snippet] < 1 ns < 1 ns N/A
⚠️ grit_query_anchor_kinds[metavariable] < 1 ns < 1 ns N/A
⚠️ grit_query_anchor_kinds[or_pattern] < 1 ns < 1 ns N/A

Comparing dyc3/grit-contains-backtracking (b9bee8a) with main (0b4c11f)2

Open in CodSpeed

Footnotes

  1. 364 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

  2. No successful run was found on main (f5af193) during the generation of this report, so 0b4c11f was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@coderabbitai

coderabbitai Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: biomejs/biome/.coderabbit.yaml

Review profile: CHILL

Plan: Essentials

Run ID: ef383057-1733-42da-986a-965d3a9c7948

📥 Commits

Reviewing files that changed from the base of the PR and between f5af193 and b9bee8a.

⛔ Files ignored due to path filters (2)
  • crates/biome_grit_patterns/tests/specs/ts/containsBacktracking.snap is excluded by !**/*.snap and included by **
  • crates/biome_grit_patterns/tests/specs/ts/containsBacktrackingRewrite.snap is excluded by !**/*.snap and included by **
📒 Files selected for processing (6)
  • .changeset/light-needles-study.md
  • crates/biome_grit_patterns/src/pattern_compiler/and_compiler.rs
  • crates/biome_grit_patterns/tests/specs/ts/containsBacktracking.grit
  • crates/biome_grit_patterns/tests/specs/ts/containsBacktracking.ts
  • crates/biome_grit_patterns/tests/specs/ts/containsBacktrackingRewrite.grit
  • crates/biome_grit_patterns/tests/specs/ts/containsBacktrackingRewrite.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.


Walkthrough

The conjunction compiler now evaluates predicates after a contains match for each candidate, rather than stopping when the first candidate fails those predicates. New fixtures cover matching and rewriting string literals inside conditional expressions. A patch changeset records the fix for GritQL plugins and biome search.

Priority: ⬇️ Low

Change: Bug fix · Severity of issue fixed: Low

Merge Risk: ⚪ Minimal · up to b9bee

The change retries contained candidates when subsequent conditions fail while preserving first-success rewrite behavior. No actionable merge blocker remains, subject to normal build and test checks.

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The PR addresses the coding requirement in [#9749]. and_compiler.rs changes contains handling so later predicates are checked against each candidate instead of stopping at the first failed candida…
Out of Scope Changes check ✅ Passed The changed compiler code, focused Grit fixtures, rewrite fixture, and package changeset all support the backtracking fix for [#9749]. The function-definition guard is part of the matcher change and i…
Title check ✅ Passed The title clearly and concisely describes the main change: enabling backtracking into contains when later conditions fail.
Description check ✅ Passed The description explains the Grit matching bug, the intended fix, the linked issue, and the reference implementation difference. It is related to the changeset.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


Comment @coderabbitai help to get the list of available commands.

@dyc3
dyc3 merged commit 8724a5d into main Oct 1, 2026
34 checks passed
@dyc3
dyc3 deleted the dyc3/grit-contains-backtracking branch October 1, 2026 17:26
@github-actions github-actions Bot mentioned this pull request Oct 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

L-Grit Language: GritQL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🐛 GritQL JsConditionalExpression only evaluates first JsStringLiteralExpression

2 participants