Repository navigation
Revert "Support Notones in alternation reductions that merge sets (#118109)" - #121775
Conversation
|
Tagging subscribers to this area: @dotnet/area-system-text-regularexpressions |
There was a problem hiding this comment.
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
AddNotCharhelper 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 `. |
|
/backport to release/10.0 |
|
Started backporting to |
|
@stephentoub backporting to 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 |
…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.
… 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.
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.