未验证 提交 0276b9b7 编写于 作者: M msftbot[bot] 提交者: GitHub

Merge pull request #46922 from dotnet/merges/release/dev16.8-to-release/dev16.8-vs-deps

Merge release/dev16.8 to release/dev16.8-vs-deps
......@@ -611,5 +611,58 @@ void M2()
await Task.WhenAll(tasks);
}
[Theory, WorkItem(46874, "https://github.com/dotnet/roslyn/pull/46874")]
[InlineData(2)]
[InlineData(50)]
public async Task TestConcurrentGetAnalyzerDiagnostics_SymbolStartAnalyzer(int partialDeclarationCount)
{
var sources = new string[partialDeclarationCount + 1];
for (var i = 0; i < partialDeclarationCount; i++)
{
sources[i] = $@"
partial class C
{{
void M{i}()
{{
// warning CS0168: The variable 'x' is declared but never used.
int x;
}}
}}
";
}
sources[partialDeclarationCount] = @"
class C3
{
void M2()
{
// warning CS0168: The variable 'x' is declared but never used.
int x;
}
}
";
var compilation = CreateCompilation(sources);
compilation = compilation.WithOptions(compilation.Options.WithConcurrentBuild(true));
var analyzers = ImmutableArray.Create<DiagnosticAnalyzer>(new SymbolStartAnalyzer(topLevelAction: false, SymbolKind.NamedType, OperationKind.VariableDeclaration));
var compilationWithAnalyzers = compilation.WithAnalyzers(analyzers,
new CompilationWithAnalyzersOptions(
new AnalyzerOptions(ImmutableArray<AdditionalText>.Empty),
onAnalyzerException: null,
concurrentAnalysis: true,
logAnalyzerExecutionTime: false));
var tree = compilation.SyntaxTrees.First();
var model = compilation.GetSemanticModel(tree, true);
var tasks = new Task[10];
for (var i = 0; i < 10; i++)
{
tasks[i] = Task.Run(() => compilationWithAnalyzers.GetAnalyzerSemanticDiagnosticsAsync(model, null, CancellationToken.None));
}
await Task.WhenAll(tasks);
}
}
}
......@@ -687,23 +687,15 @@ private async Task ComputeAnalyzerSemanticDiagnosticsAsync(SemanticModel model,
Func<ImmutableArray<CompilationEvent>> getPendingEvents = () => _analysisState.GetPendingEvents(analysisScope.Analyzers, model.SyntaxTree, cancellationToken);
// Compute the analyzer diagnostics for the given analysis scope.
// We need to loop till symbol analysis is complete for any partial symbols being processed for other tree diagnostic requests.
do
{
cancellationToken.ThrowIfCancellationRequested();
cancellationToken.ThrowIfCancellationRequested();
(ImmutableArray<CompilationEvent> compilationEvents, bool hasSymbolStartActions) = await ComputeAnalyzerDiagnosticsAsync(pendingAnalysisScope, getPendingEvents, taskToken, cancellationToken).ConfigureAwait(false);
if (hasSymbolStartActions && forceCompletePartialTrees)
{
await processPartialSymbolLocationsAsync(compilationEvents, analysisScope).ConfigureAwait(false);
}
} while (_analysisOptions.ConcurrentAnalysis && _analysisState.HasPendingSymbolAnalysis(pendingAnalysisScope, cancellationToken));
// Compute the analyzer diagnostics for the given analysis scope.
(ImmutableArray<CompilationEvent> compilationEvents, bool hasSymbolStartActions) = await ComputeAnalyzerDiagnosticsAsync(pendingAnalysisScope, getPendingEvents, taskToken, cancellationToken).ConfigureAwait(false);
if (_analysisOptions.ConcurrentAnalysis)
// If required, force compute diagnostics for partial symbol locations.
if (hasSymbolStartActions && forceCompletePartialTrees)
{
// Wait for all active tree tasks as they might still be reporting diagnostics for partial symbols defined in this tree.
await WaitForActiveAnalysisTasksAsync(waitForTreeTasks: true, waitForCompilationOrNonConcurrentTask: false, cancellationToken: cancellationToken).ConfigureAwait(false);
await processPartialSymbolLocationsAsync(compilationEvents, analysisScope).ConfigureAwait(false);
}
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册