@@ -44,31 +44,14 @@ public override int GetHashCode()
44
44
}
45
45
}
46
46
47
- public class IncrementalityTracker
47
+ public static class StepNames
48
48
{
49
- public enum StepName
50
- {
51
- CalculateStubInformation ,
52
- GenerateSingleStub ,
53
- NormalizeWhitespace ,
54
- ConcatenateStubs ,
55
- OutputSourceFile
56
- }
57
-
58
- public record ExecutedStepInfo ( StepName Step , object Input ) ;
59
-
60
- private readonly List < ExecutedStepInfo > _executedSteps = new ( ) ;
61
- public IEnumerable < ExecutedStepInfo > ExecutedSteps => _executedSteps ;
62
-
63
- internal void RecordExecutedStep ( ExecutedStepInfo step ) => _executedSteps . Add ( step ) ;
49
+ public const string CalculateStubInformation = nameof ( CalculateStubInformation ) ;
50
+ public const string GenerateSingleStub = nameof ( GenerateSingleStub ) ;
51
+ public const string NormalizeWhitespace = nameof ( NormalizeWhitespace ) ;
52
+ public const string ConcatenateStubs = nameof ( ConcatenateStubs ) ;
64
53
}
65
54
66
- /// <summary>
67
- /// This property provides a test-only hook to enable testing the incrementality of the source generator.
68
- /// This will be removed when https://github.com/dotnet/roslyn/issues/54832 is implemented and can be consumed.
69
- /// </summary>
70
- public IncrementalityTracker ? IncrementalTracker { get ; set ; }
71
-
72
55
public void Initialize ( IncrementalGeneratorInitializationContext context )
73
56
{
74
57
var attributedMethods = context . SyntaxProvider
@@ -128,7 +111,7 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
128
111
} ) ;
129
112
130
113
IncrementalValueProvider < DllImportGeneratorOptions > stubOptions = context . AnalyzerConfigOptionsProvider
131
- . Select ( ( options , ct ) => new DllImportGeneratorOptions ( options . GlobalOptions ) ) ;
114
+ . Select ( static ( options , ct ) => new DllImportGeneratorOptions ( options . GlobalOptions ) ) ;
132
115
133
116
IncrementalValueProvider < StubEnvironment > stubEnvironment = compilationAndTargetFramework
134
117
. Combine ( stubOptions )
@@ -151,34 +134,24 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
151
134
Environment = data . Right
152
135
} )
153
136
. Select (
154
- ( data , ct ) =>
155
- {
156
- IncrementalTracker ? . RecordExecutedStep ( new IncrementalityTracker . ExecutedStepInfo ( IncrementalityTracker . StepName . CalculateStubInformation , data ) ) ;
157
- return ( data . Syntax , StubContext : CalculateStubInformation ( data . Symbol , data . Environment , ct ) ) ;
158
- }
137
+ static ( data , ct ) => ( data . Syntax , StubContext : CalculateStubInformation ( data . Symbol , data . Environment , ct ) )
159
138
)
160
139
. WithComparer ( Comparers . CalculatedContextWithSyntax )
140
+ . WithTrackingName ( StepNames . CalculateStubInformation )
161
141
. Combine ( stubOptions )
162
142
. Select (
163
- ( data , ct ) =>
164
- {
165
- IncrementalTracker ? . RecordExecutedStep ( new IncrementalityTracker . ExecutedStepInfo ( IncrementalityTracker . StepName . GenerateSingleStub , data ) ) ;
166
- return GenerateSource ( data . Left . StubContext , data . Left . Syntax , data . Right ) ;
167
- }
143
+ static ( data , ct ) => GenerateSource ( data . Left . StubContext , data . Left . Syntax , data . Right )
168
144
)
169
145
. WithComparer ( Comparers . GeneratedSyntax )
146
+ . WithTrackingName ( StepNames . GenerateSingleStub )
170
147
// Handle NormalizeWhitespace as a separate stage for incremental runs since it is an expensive operation.
171
148
. Select (
172
- ( data , ct ) =>
173
- {
174
- IncrementalTracker ? . RecordExecutedStep ( new IncrementalityTracker . ExecutedStepInfo ( IncrementalityTracker . StepName . NormalizeWhitespace , data ) ) ;
175
- return ( data . Item1 . NormalizeWhitespace ( ) . ToFullString ( ) , data . Item2 ) ;
176
- } )
149
+ static ( data , ct ) => ( data . Item1 . NormalizeWhitespace ( ) . ToFullString ( ) , data . Item2 ) )
150
+ . WithTrackingName ( StepNames . NormalizeWhitespace )
177
151
. Collect ( )
178
152
. WithComparer ( Comparers . GeneratedSourceSet )
179
- . Select ( ( generatedSources , ct ) =>
153
+ . Select ( static ( generatedSources , ct ) =>
180
154
{
181
- IncrementalTracker ? . RecordExecutedStep ( new IncrementalityTracker . ExecutedStepInfo ( IncrementalityTracker . StepName . ConcatenateStubs , generatedSources ) ) ;
182
155
StringBuilder source = new ( ) ;
183
156
// Mark in source that the file is auto-generated.
184
157
source . AppendLine ( "// <auto-generated/>" ) ;
@@ -190,12 +163,12 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
190
163
}
191
164
return ( source : source . ToString ( ) , diagnostics : diagnostics . ToImmutable ( ) ) ;
192
165
} )
193
- . WithComparer ( Comparers . GeneratedSource ) ;
166
+ . WithComparer ( Comparers . GeneratedSource )
167
+ . WithTrackingName ( StepNames . ConcatenateStubs ) ;
194
168
195
169
context . RegisterSourceOutput ( methodSourceAndDiagnostics ,
196
- ( context , data ) =>
170
+ static ( context , data ) =>
197
171
{
198
- IncrementalTracker ? . RecordExecutedStep ( new IncrementalityTracker . ExecutedStepInfo ( IncrementalityTracker . StepName . OutputSourceFile , data ) ) ;
199
172
foreach ( Diagnostic diagnostic in data . Item2 )
200
173
{
201
174
context . ReportDiagnostic ( diagnostic ) ;
@@ -510,7 +483,7 @@ private static IncrementalStubGenerationContext CalculateStubInformation(IMethod
510
483
return new IncrementalStubGenerationContext ( environment , dllImportStub , additionalAttributes . ToImmutableArray ( ) , stubDllImportData , generatorDiagnostics . Diagnostics . ToImmutableArray ( ) ) ;
511
484
}
512
485
513
- private ( MemberDeclarationSyntax , ImmutableArray < Diagnostic > ) GenerateSource (
486
+ private static ( MemberDeclarationSyntax , ImmutableArray < Diagnostic > ) GenerateSource (
514
487
IncrementalStubGenerationContext dllImportStub ,
515
488
MethodDeclarationSyntax originalSyntax ,
516
489
DllImportGeneratorOptions options )
@@ -567,7 +540,7 @@ private static IncrementalStubGenerationContext CalculateStubInformation(IMethod
567
540
return ( PrintGeneratedSource ( originalSyntax , dllImportStub . StubContext , code ) , dllImportStub . Diagnostics . AddRange ( diagnostics . Diagnostics ) ) ;
568
541
}
569
542
570
- private MemberDeclarationSyntax PrintForwarderStub ( MethodDeclarationSyntax userDeclaredMethod , IncrementalStubGenerationContext stub , GeneratorDiagnostics diagnostics )
543
+ private static MemberDeclarationSyntax PrintForwarderStub ( MethodDeclarationSyntax userDeclaredMethod , IncrementalStubGenerationContext stub , GeneratorDiagnostics diagnostics )
571
544
{
572
545
GeneratedDllImportData targetDllImportData = GetTargetDllImportDataFromStubData (
573
546
stub . DllImportData ,
0 commit comments