Skip to content

Cleanup ValidationsGenerator for better incrementality#66373

Open
Youssef1313 wants to merge 8 commits intomainfrom
dev/ygerges/cleanup-validations-gen
Open

Cleanup ValidationsGenerator for better incrementality#66373
Youssef1313 wants to merge 8 commits intomainfrom
dev/ygerges/cleanup-validations-gen

Conversation

@Youssef1313
Copy link
Copy Markdown
Member

This PR cleans up ValidationsGenerator.

  • ValidationAttribute calculations were dead code. The properties of it were never used.
  • Lots of generator incrementality issues due to keeping Roslyn symbols in the pipeline. Instead, this PR switches to storing the info that is really needed in the generation step (e.g, FQN instead of the full roslyn symbol).

Copilot AI review requested due to automatic review settings April 20, 2026 06:17
@github-actions github-actions bot added the area-infrastructure Includes: MSBuild projects/targets, build scripts, CI, Installers and shared framework label Apr 20, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 refactors the Microsoft.Extensions.Validation source generator pipeline to improve incrementality by avoiding keeping Roslyn symbols in the incremental pipeline, and removes dead validation-attribute modeling code.

Changes:

  • Replace stored Roslyn symbols in generator models with fully-qualified type name strings (FQNs) to improve incremental caching behavior.
  • Simplify endpoint/type parsing to return only the data needed for emission (validatable types/properties).
  • Remove unused ValidationAttribute model and related extraction logic.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
src/Validation/gen/ValidationsGenerator.cs Updates the incremental pipeline to extract validatable types from endpoints directly.
src/Validation/gen/Parsers/ValidationsGenerator.TypesParser.cs Switches parsing to store FQNs, removes attribute-model extraction, and adjusts helper signatures.
src/Validation/gen/Parsers/ValidationsGenerator.EndpointsParser.cs Returns validatable types from the transform step (instead of Roslyn operations).
src/Validation/gen/Parsers/ValidationsGenerator.AttributeParser.cs Updates syntax-kind checks for attribute-based discovery.
src/Validation/gen/Parsers/ValidationsGenerator.AddValidation.cs Updates invocation detection to use SyntaxKind checks.
src/Validation/gen/Models/ValidationAttribute.cs Deletes the unused ValidationAttribute generator model.
src/Validation/gen/Models/ValidatableTypeComparer.cs Updates equality to compare by type FQN (string) instead of ITypeSymbol.
src/Validation/gen/Models/ValidatableType.cs Changes model to store TypeFQN instead of ITypeSymbol.
src/Validation/gen/Models/ValidatableProperty.cs Changes model to store containing/property type FQNs and removes attribute payload.
src/Validation/gen/Emitters/ValidationsGenerator.Emitter.cs Emits typeof(...) checks using stored FQNs instead of Roslyn symbols.
src/Http/Http.Extensions/gen/.../InvocationOperationExtensions.cs Adds an InvocationExpressionSyntax overload and simplifies member-access pattern matching.

Comment thread src/Validation/gen/Emitters/ValidationsGenerator.Emitter.cs
Comment thread src/Validation/gen/Parsers/ValidationsGenerator.TypesParser.cs Outdated
Comment thread src/Validation/gen/Parsers/ValidationsGenerator.TypesParser.cs Outdated
Comment thread src/Validation/gen/Parsers/ValidationsGenerator.TypesParser.cs
Comment thread src/Validation/gen/Parsers/ValidationsGenerator.TypesParser.cs Outdated
Comment thread src/Validation/gen/Parsers/ValidationsGenerator.TypesParser.cs Outdated
Comment thread src/Validation/gen/ValidationsGenerator.cs
@Youssef1313 Youssef1313 force-pushed the dev/ygerges/cleanup-validations-gen branch from ac20142 to 5178e70 Compare April 20, 2026 06:27
@Youssef1313 Youssef1313 force-pushed the dev/ygerges/cleanup-validations-gen branch from 5178e70 to 6134541 Compare April 20, 2026 06:28
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

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

Comment thread src/Validation/gen/Parsers/ValidationsGenerator.TypesParser.cs
Comment thread src/Validation/gen/Parsers/ValidationsGenerator.AttributeParser.cs
Comment thread src/Validation/gen/Emitters/ValidationsGenerator.Emitter.cs
Comment thread src/Validation/gen/Models/ValidatableType.cs
Comment on lines -10 to +8
ITypeSymbol ContainingType,
ITypeSymbol Type,
string ContainingTypeFQN,
string TypeFQN,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

These changes seem to be just shifting around of operations. I am not sure that replacing ITypeSymbol in ValidatableProperty metadata with the type's string FullyQualifiedName helps with incrementality (because ITypeSymbol already implements IEquatable) and it does not reduce the number of operations (because the name is resolved once per emit, just in a different location).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@oroztocil It should help with incrementality. See discussion in dotnet/roslyn-analyzers#6352 for why it's bad to include ITypeSymbol in generator pipeline (even if it does implement IEquatable)

Comment on lines -16 to +17
if (syntaxNode is InvocationExpressionSyntax
&& syntaxNode.TryGetMapMethodName(out var method)
if (syntaxNode.IsKind(SyntaxKind.InvocationExpression)
&& ((InvocationExpressionSyntax)syntaxNode).TryGetMapMethodName(out var method)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Although I'd agree that from intuition syntaxNode.IsKind(SyntaxKind.InvocationExpression) feels like it should be faster than syntaxNode is InvocationExpressionSyntax, I am not a Roslyn expert and would be interested in empirical backing for it.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The analyzer I linked is actually different. It doesn't consider type checking.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@333fred Was there something about the perf of IsKind + cast vs doing a type check?

Comment thread src/Validation/gen/Parsers/ValidationsGenerator.TypesParser.cs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-infrastructure Includes: MSBuild projects/targets, build scripts, CI, Installers and shared framework

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants