@@ -90,88 +90,85 @@ public async Task RunAsync()
90
90
{
91
91
Stopwatch swRun = Stopwatch . StartNew ( ) ;
92
92
93
- List < Task > mainForLoopTasks = [ ] ;
93
+ // Needs to block so the _afterAssemblySymbols dictionary gets updated.
94
+ await ProcessBeforeAndAfterAssembliesAsync ( ) . ConfigureAwait ( false ) ;
94
95
96
+ // Needs to happen after processing the before and after assemblies and filtering out the existing ones.
97
+ await ProcessNewAssembliesAsync ( ) . ConfigureAwait ( false ) ;
98
+
99
+ _log . LogMessage ( $ "FINAL TOTAL TIME: { swRun . Elapsed . TotalMilliseconds / 1000.0 / 60.0 : F2} mins.") ;
100
+ swRun . Stop ( ) ;
101
+ }
102
+
103
+ private async Task ProcessBeforeAndAfterAssembliesAsync ( )
104
+ {
95
105
foreach ( ( string beforeAssemblyName , IAssemblySymbol beforeAssemblySymbol ) in _beforeAssemblySymbols )
96
106
{
97
- mainForLoopTasks . Add ( Task . Run ( async ( ) =>
98
- {
99
- StringBuilder sb = new ( ) ;
107
+ StringBuilder sb = new ( ) ;
100
108
101
- _log . LogMessage ( $ "Visiting assembly { beforeAssemblySymbol . Name } (before vs after)...") ;
109
+ _log . LogMessage ( $ "Visiting assembly { beforeAssemblySymbol . Name } (before vs after)...") ;
102
110
103
- Stopwatch swAssembly = Stopwatch . StartNew ( ) ;
104
- ( SyntaxNode beforeAssemblyNode , SemanticModel beforeModel ) = await GetAssemblyRootNodeAndModelAsync ( _beforeLoader , beforeAssemblySymbol ) . ConfigureAwait ( false ) ;
105
- string finalMessage = $ "Finished visiting { beforeAssemblySymbol . Name } (before) in { swAssembly . Elapsed . TotalMilliseconds / 1000.0 : F2} s{ Environment . NewLine } ";
111
+ Stopwatch swAssembly = Stopwatch . StartNew ( ) ;
112
+ ( SyntaxNode beforeAssemblyNode , SemanticModel beforeModel ) = await GetAssemblyRootNodeAndModelAsync ( _beforeLoader , beforeAssemblySymbol ) . ConfigureAwait ( false ) ;
113
+ string finalMessage = $ "Finished visiting { beforeAssemblySymbol . Name } (before) in { swAssembly . Elapsed . TotalMilliseconds / 1000.0 : F2} s{ Environment . NewLine } ";
106
114
107
- // See if an assembly with the same name can be found in the diff folder.
108
- if ( _afterAssemblySymbols . TryGetValue ( beforeAssemblyName , out IAssemblySymbol ? afterAssemblySymbol ) )
109
- {
110
- swAssembly = Stopwatch . StartNew ( ) ;
111
- ( SyntaxNode afterAssemblyNode , SemanticModel afterModel ) = await GetAssemblyRootNodeAndModelAsync ( _afterLoader , afterAssemblySymbol ) . ConfigureAwait ( false ) ;
112
- finalMessage += $ "Finished visiting { afterAssemblySymbol . Name } (after) in { swAssembly . Elapsed . TotalMilliseconds / 1000.0 : F2} s{ Environment . NewLine } ";
115
+ // See if an assembly with the same name can be found in the diff folder.
116
+ if ( _afterAssemblySymbols . TryGetValue ( beforeAssemblyName , out IAssemblySymbol ? afterAssemblySymbol ) )
117
+ {
118
+ swAssembly = Stopwatch . StartNew ( ) ;
119
+ ( SyntaxNode afterAssemblyNode , SemanticModel afterModel ) = await GetAssemblyRootNodeAndModelAsync ( _afterLoader , afterAssemblySymbol ) . ConfigureAwait ( false ) ;
120
+ finalMessage += $ "Finished visiting { afterAssemblySymbol . Name } (after) in { swAssembly . Elapsed . TotalMilliseconds / 1000.0 : F2} s{ Environment . NewLine } ";
113
121
114
- // We don't care about changed assembly attributes (for now).
115
- swAssembly = Stopwatch . StartNew ( ) ;
116
- sb . Append ( VisitChildren ( beforeAssemblyNode , afterAssemblyNode , beforeModel , afterModel , ChangeType . Unchanged , wereParentAttributesChanged : false ) ) ;
117
- finalMessage += $ "Finished generating diff for { afterAssemblySymbol . Name } (before vs after) in { swAssembly . Elapsed . TotalMilliseconds / 1000.0 : F2} s{ Environment . NewLine } ";
122
+ // We don't care about changed assembly attributes (for now).
123
+ swAssembly = Stopwatch . StartNew ( ) ;
124
+ sb . Append ( VisitChildren ( beforeAssemblyNode , afterAssemblyNode , beforeModel , afterModel , ChangeType . Unchanged , wereParentAttributesChanged : false ) ) ;
125
+ finalMessage += $ "Finished generating diff for { afterAssemblySymbol . Name } (before vs after) in { swAssembly . Elapsed . TotalMilliseconds / 1000.0 : F2} s{ Environment . NewLine } ";
118
126
119
- _log . LogMessage ( finalMessage ) ;
120
- swAssembly . Stop ( ) ;
127
+ _log . LogMessage ( finalMessage ) ;
128
+ swAssembly . Stop ( ) ;
121
129
122
- // Remove the found ones. The remaining ones will be processed at the end because they're new.
123
- _afterAssemblySymbols . Remove ( beforeAssemblyName , out _ ) ;
124
- }
125
- else
126
- {
127
- // The assembly was removed in the diff.
128
- //sb.Append(GenerateDeletedDiff(beforeAssemblyNode));
129
- sb . Append ( VisitChildren ( beforeAssemblyNode , afterParentNode : null , beforeModel , afterModel : null , ChangeType . Deleted , wereParentAttributesChanged : false ) ) ;
130
- }
130
+ // Remove the found ones. The remaining ones will be processed at the end because they're new.
131
+ _afterAssemblySymbols . Remove ( beforeAssemblyName , out _ ) ;
132
+ }
133
+ else
134
+ {
135
+ // The assembly was removed in the diff.
136
+ //sb.Append(GenerateDeletedDiff(beforeAssemblyNode));
137
+ sb . Append ( VisitChildren ( beforeAssemblyNode , afterParentNode : null , beforeModel , afterModel : null , ChangeType . Deleted , wereParentAttributesChanged : false ) ) ;
138
+ }
131
139
132
- if ( sb . Length > 0 )
133
- {
134
- _results . TryAdd ( beforeAssemblyName , GetFinalAssemblyDiff ( beforeAssemblyName , sb . ToString ( ) ) ) ;
135
- }
136
- } ) ) ;
140
+ if ( sb . Length > 0 )
141
+ {
142
+ _results . TryAdd ( beforeAssemblyName , GetFinalAssemblyDiff ( beforeAssemblyName , sb . ToString ( ) ) ) ;
143
+ }
137
144
}
145
+ }
138
146
139
- // This needs to block, because the tasks remove items from _afterAssemblySymbols, processed in the forloop below
140
- await Task . WhenAll ( mainForLoopTasks ) . ConfigureAwait ( false ) ;
141
-
142
- List < Task > rightSideForLoopTasks = [ ] ;
143
-
147
+ private async Task ProcessNewAssembliesAsync ( )
148
+ {
144
149
// Process the remaining assemblies in the diff folder.
145
150
foreach ( ( string afterAssemblyName , IAssemblySymbol afterAssemblySymbol ) in _afterAssemblySymbols )
146
151
{
147
- rightSideForLoopTasks . Add ( Task . Run ( async ( ) =>
148
- {
149
- StringBuilder sb = new ( ) ;
150
- _log . LogMessage ( $ "Visiting *new* assembly { afterAssemblySymbol . Name } ...") ;
152
+ StringBuilder sb = new ( ) ;
153
+ _log . LogMessage ( $ "Visiting *new* assembly { afterAssemblySymbol . Name } ...") ;
151
154
152
- var swNew = Stopwatch . StartNew ( ) ;
153
- ( SyntaxNode afterAssemblyNode , SemanticModel afterModel ) = await GetAssemblyRootNodeAndModelAsync ( _afterLoader , afterAssemblySymbol ) . ConfigureAwait ( false ) ;
154
- string finalMessage = $ "Finished visiting *new* { afterAssemblySymbol . Name } in { swNew . Elapsed . TotalMilliseconds / 1000.0 : F2} s{ Environment . NewLine } ";
155
+ var swNew = Stopwatch . StartNew ( ) ;
156
+ ( SyntaxNode afterAssemblyNode , SemanticModel afterModel ) = await GetAssemblyRootNodeAndModelAsync ( _afterLoader , afterAssemblySymbol ) . ConfigureAwait ( false ) ;
157
+ string finalMessage = $ "Finished visiting *new* { afterAssemblySymbol . Name } in { swNew . Elapsed . TotalMilliseconds / 1000.0 : F2} s{ Environment . NewLine } ";
155
158
156
- // We don't care about changed assembly attributes (for now).
157
- swNew = Stopwatch . StartNew ( ) ;
158
- sb . Append ( VisitChildren ( beforeParentNode : null , afterAssemblyNode , beforeModel : null , afterModel , ChangeType . Inserted , wereParentAttributesChanged : false ) ) ;
159
- finalMessage += $ "Finished generating diff for *new* assembly { afterAssemblySymbol . Name } in { swNew . Elapsed . TotalMilliseconds / 1000.0 : F2} s{ Environment . NewLine } ";
159
+ // We don't care about changed assembly attributes (for now).
160
+ swNew = Stopwatch . StartNew ( ) ;
161
+ sb . Append ( VisitChildren ( beforeParentNode : null , afterAssemblyNode , beforeModel : null , afterModel , ChangeType . Inserted , wereParentAttributesChanged : false ) ) ;
162
+ finalMessage += $ "Finished generating diff for *new* assembly { afterAssemblySymbol . Name } in { swNew . Elapsed . TotalMilliseconds / 1000.0 : F2} s{ Environment . NewLine } ";
160
163
161
- _log . LogMessage ( finalMessage ) ;
162
- swNew . Stop ( ) ;
164
+ _log . LogMessage ( finalMessage ) ;
165
+ swNew . Stop ( ) ;
163
166
164
- if ( sb . Length > 0 )
165
- {
166
- _results . TryAdd ( afterAssemblyName , GetFinalAssemblyDiff ( afterAssemblyName , sb . ToString ( ) ) ) ;
167
- }
168
- } ) ) ;
167
+ if ( sb . Length > 0 )
168
+ {
169
+ _results . TryAdd ( afterAssemblyName , GetFinalAssemblyDiff ( afterAssemblyName , sb . ToString ( ) ) ) ;
170
+ }
169
171
}
170
-
171
- await Task . WhenAll ( rightSideForLoopTasks ) . ConfigureAwait ( false ) ;
172
-
173
- _log . LogMessage ( $ "FINAL TOTAL: { swRun . Elapsed . TotalMilliseconds / 1000.0 / 60.0 : F2} mins.") ;
174
- swRun . Stop ( ) ;
175
172
}
176
173
177
174
private async Task < ( SyntaxNode rootNode , SemanticModel model ) > GetAssemblyRootNodeAndModelAsync ( IAssemblySymbolLoader loader , IAssemblySymbol assemblySymbol )
0 commit comments