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 ISymbol
s, or Compilation
s. 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 implementIEquatable<T>
(this includesCompilation
) - Type
T
isISymbol
. - Type
T
isn'tImmutableArray<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