Repository navigation
Refactor regex source generator to follow best practices. - #135079
Open
teo-tsirpanis wants to merge 3 commits into
Open
teo-tsirpanis wants to merge 3 commits into
teo-tsirpanis wants to merge 3 commits into
Conversation
|
Azure Pipelines: Successfully started running 3 pipeline(s). 13 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
teo-tsirpanis
temporarily deployed
to
copilot-pat-pool
October 2, 2026 03:16 — with
GitHub Actions
Inactive
Contributor
|
Tagging subscribers to this area: @dotnet/area-system-text-regularexpressions |
teo-tsirpanis
temporarily deployed
to
copilot-pat-pool
October 2, 2026 03:17 — with
GitHub Actions
Inactive
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Ambiguous attribute lookup can silently disable regex diagnostics, and incremental caching needs regression coverage.
2 open findings
What changed in this PR
Refactors the regex source generator to separate diagnostics from generation and improve incremental caching, addressing #125409.
Changes:
- Moves diagnostics into an analyzer using shared parsing helpers.
- Introduces strongly typed pipeline models with value-based equality.
- Updates test helpers and diagnostic suppression coverage.
Validation was limited to source inspection; builds and tests were not run.
| File | Description |
|---|---|
| src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/RegexGeneratorParserTests.cs | Updates pragma suppression expectations. |
| src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/RegexGeneratorHelper.netcoreapp.cs | Runs the analyzer after generation. |
| src/libraries/System.Text.RegularExpressions/gen/System.Text.RegularExpressions.Generator.csproj | Enables Roslyn component checks. |
| src/libraries/System.Text.RegularExpressions/gen/RegexGenerator.Parser.cs | Shares validation and defines model equality. |
| src/libraries/System.Text.RegularExpressions/gen/RegexGenerator.Emitter.cs | Reads emission settings from the model. |
| src/libraries/System.Text.RegularExpressions/gen/RegexGenerator.cs | Simplifies the typed incremental pipeline. |
| src/libraries/System.Text.RegularExpressions/gen/RegexGenerator.Analyzer.cs | Adds dedicated regex diagnostics analysis. |
🧠 Review effort: Balanced
|
|
||
| context.RegisterCompilationStartAction(context => | ||
| { | ||
| var generatedRegexAttributeSymbol = context.Compilation.GetTypeByMetadataName(GeneratedRegexAttributeName); |
Comment on lines
+320
to
+321
| public override bool Equals(object? obj) => obj is RegexMethod other && PatternAndSyntax.Equals(other.PatternAndSyntax); | ||
| public override int GetHashCode() => PatternAndSyntax.GetHashCode(); |
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Action<Diagnostic>to report diagnostics. The analyzer passes a callback, while the generator passesnull.Locations andDiagnostics from the generator's pipeline.object.RegexTypeAndPatternthey contain. We can do this, because all other properties of the types depend on it.RegexTypeAndPatternis entirely comprised of value-equatable types (no moreLocations and no complex reference types), this restores incrementality in the pipeline, and fixes RegexGenerator source model lacks value equality, preventing effective incremental caching #125409.RegexGeneratorParserTestsare passing locally.