Skip to content

Analyzer suggestion: Improper incremental pipeline #6352

Open

Description

Describe the problem you are trying to solve

Incremental source generators are sometimes designed in a non-cache-friendly way. This happens when pipeline contains types that are not equatable across different compilations. These types can be ISymbols, or Compilations. Maybe also SyntaxNode? Not sure.

Describe suggestions on how to achieve the rule

The analyzer will look for incremental generator pipelines that are not cache-friendly, and issue a diagnostic.

More detailed, the analyzer will look for Register[Implementation]SourceOutput<T> invocations where T violates incrementality. Violation is defined as follows:

  • Type T doesn't implement IEquatable<T> (this includes Compilation)
  • Type T is ISymbol.
  • Type T isn't ImmutableArray<T>
  • Type T is a tuple where one of the tuple elements violates incrementality.
  • Type T is a user-defined model where one of the members violates incrementality.

Alternatively, and more strongly, we can detect any part of the pipeline that violates incrementality, not only Register[Implementation]SourceOutput. This should exclude the root context.CompilationProvider, etc.

Additional context

I have seen this a lot, and in the dotnet organization. e.g, dotnet/runtime#76119 and https://github.com/dotnet/winforms/blob/117451b053c2fbda2f9caf9e1ef280f412b5aad1/src/System.Windows.Forms.Analyzers.CSharp/src/System/Windows/Forms/Generators/ApplicationConfigurationGenerator.cs#L74-L81

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions