Skip to content

Revert "Support Notones in alternation reductions that merge sets (#118109)" - #121775

Merged
stephentoub merged 2 commits into
dotnet:mainfrom
stephentoub:revertnotone
Nov 19, 2025
Merged

stephentoub merged 2 commits into
dotnet:mainfrom
stephentoub:revertnotone

Conversation

@stephentoub

Copy link
Copy Markdown
Member

Clean automatic revert of #118109, plus adding a few additional tests. The logic of the optimization was not complete. You could end up with a negative set and then attempt to add values to it when merging in subsequent alternation branches, and those branches would be interpreted erroneously as negative rather than positive.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/area-system-text-regularexpressions
See info in area-owners.md if you want to be subscribed.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull Request Overview

This PR cleanly reverts the optimization introduced in #118109 that attempted to support Notone nodes in alternation reductions. The revert is necessary because the optimization logic was incomplete and could cause negative sets to be interpreted erroneously when merging subsequent alternation branches.

Key changes:

  • Removes Notone handling from alternation reduction optimization in RegexNode.cs
  • Removes the AddNotChar helper method from RegexCharClass.cs
  • Adds regression tests to validate correct matching behavior for dot-newline alternations

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
RegexCharClass.cs Removes the AddNotChar method that was introduced to support the reverted optimization
RegexNode.cs Removes Notone node handling from alternation reduction logic and updates related comments
RegexReductionTests.cs Removes test cases that validated the reverted optimization (e.g., `a
Regex.Match.Tests.cs Adds regression tests for patterns like `.

@stephentoub
stephentoub merged commit 01b11cd into dotnet:main Nov 19, 2025
@stephentoub
stephentoub deleted the revertnotone branch November 19, 2025 12:06
@stephentoub

Copy link
Copy Markdown
Member Author

/backport to release/10.0

@github-actions

Copy link
Copy Markdown
Contributor

Started backporting to release/10.0 (link to workflow run)

@github-actions

Copy link
Copy Markdown
Contributor

@stephentoub backporting to release/10.0 failed, the patch most likely resulted in conflicts. Please backport manually!

git am output
$ git am --3way --empty=keep --ignore-whitespace --keep-non-patch changes.patch

Patch format detection failed.
Error: The process '/usr/bin/git' failed with exit code 128

Link to workflow output

stephentoub added a commit to stephentoub/runtime that referenced this pull request Nov 19, 2025
…tnet#118109)" (dotnet#121775)

Clean automatic revert of dotnet#118109, plus adding a few additional tests.
The logic of the optimization was not complete. You could end up with a
negative set and then attempt to add values to it when merging in
subsequent alternation branches, and those branches would be interpreted
erroneously as negative rather than positive.
steveisok pushed a commit that referenced this pull request Nov 21, 2025
… merge sets (#118109)" (#121775) (#121822)

Clean automatic revert of #118109, plus adding a few additional tests.
The logic of the optimization was not complete. You could end up with a
negative set and then attempt to add values to it when merging in
subsequent alternation branches, and those branches would be interpreted
erroneously as negative rather than positive.

**Customer Impact**
 
A customer hit this as part of their .NET 10 upgrade. It results in
incorrect regex matches in some cases. In their case, they had an
alternation like `.|\r|\n` (which is a non-idiomatic way of writing
“match anything”) and it was incorrectly being merged into the
equivalent of `[^\n]` (which is “match anything other than newline”).
 
**Regression**
 
Yes, in .NET 10. It was caused by an incomplete performance
optimization. Rather than try to patch the optimization, this just
reverts it, and we can see whether it’s practical to redo the
optimization correctly for .NET 11.
 
**Workarounds**
 
There are workarounds, all of which involve changing the regex pattern
to another way of expressing the same concept. The customer is changing
their code to avoid the problematic case.
 
**Testing**
 
Passing all functional and unit tests, including new ones added for the
regression.
 
**Risk**
 
Low. The optimization was done relatively late in .NET 10, so few folks
are likely to be depending on the performance gains, and the change
itself was very isolated. The revert is a clean automatic revert.
@github-actions github-actions Bot locked and limited conversation to collaborators Dec 20, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants