Skip to content

Commit

Permalink
Do not wait for all members to be completed to emit an event for a type.
Browse files Browse the repository at this point in the history
  • Loading branch information
gafter committed Dec 15, 2015
1 parent cbe906c commit 836e78e
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,7 @@ internal override void ForceComplete(SourceLocation locationOpt, CancellationTok
var diagnostics = DiagnosticBag.GetInstance();
AfterMembersChecks(diagnostics);
AddDeclarationDiagnostics(diagnostics);
DeclaringCompilation.SymbolDeclaredEvent(this);
var thisThreadCompleted = state.NotePartComplete(CompletionPart.FinishMemberChecks);
Debug.Assert(thisThreadCompleted);
diagnostics.Free();
Expand Down Expand Up @@ -510,10 +511,7 @@ internal override void ForceComplete(SourceLocation locationOpt, CancellationTok

// We've completed all members, so we're ready for the PointedAtManagedTypeChecks;
// proceed to the next iteration.
if (state.NotePartComplete(CompletionPart.MembersCompleted))
{
DeclaringCompilation.SymbolDeclaredEvent(this);
}
state.NotePartComplete(CompletionPart.MembersCompleted);
break;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,10 +390,14 @@ protected sealed override void LazyAsyncMethodChecks(CancellationToken cancellat

if (!this.IsAsync)
{
state.NotePartComplete(CompletionPart.StartAsyncMethodChecks);
if (state.NotePartComplete(CompletionPart.FinishAsyncMethodChecks) && IsPartialDefinition)
if (state.NotePartComplete(CompletionPart.StartAsyncMethodChecks))
{
DeclaringCompilation.SymbolDeclaredEvent(this);
if (IsPartialDefinition) DeclaringCompilation.SymbolDeclaredEvent(this);
state.NotePartComplete(CompletionPart.FinishAsyncMethodChecks);
}
else
{
state.SpinWaitComplete(CompletionPart.FinishAsyncMethodChecks, cancellationToken);
}

return;
Expand Down Expand Up @@ -431,10 +435,8 @@ protected sealed override void LazyAsyncMethodChecks(CancellationToken cancellat
if (state.NotePartComplete(CompletionPart.StartAsyncMethodChecks))
{
AddDeclarationDiagnostics(diagnostics);
if (state.NotePartComplete(CompletionPart.FinishAsyncMethodChecks) && IsPartialDefinition)
{
DeclaringCompilation.SymbolDeclaredEvent(this);
}
if (IsPartialDefinition) DeclaringCompilation.SymbolDeclaredEvent(this);
state.NotePartComplete(CompletionPart.FinishAsyncMethodChecks);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,8 @@ private Dictionary<string, ImmutableArray<NamespaceOrTypeSymbol>> GetNameToMembe
// NOTE: the following is not cancellable. Once we've set the
// members, we *must* do the following to make sure we're in a consistent state.
this.DeclaringCompilation.DeclarationDiagnostics.AddRange(diagnostics);

RegisterDeclaredCorTypes();
DeclaringCompilation.SymbolDeclaredEvent(this);
_state.NotePartComplete(CompletionPart.NameToMembersMap);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,7 @@ internal override void ForceComplete(SourceLocation locationOpt, CancellationTok

if (allCompleted)
{
if (_state.NotePartComplete(CompletionPart.MembersCompleted))
{
DeclaringCompilation.SymbolDeclaredEvent(this);
}
_state.NotePartComplete(CompletionPart.MembersCompleted);
break;
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public void Foo()
Assert.Equal(4, info.WarningLevel);
}

[Fact(Skip ="7446"), WorkItem(7446, "https://github.com/dotnet/roslyn/issues/7446")]
[Fact, WorkItem(7446, "https://github.com/dotnet/roslyn/issues/7446")]
public void TestCompilationEventQueueWithSemanticModelGetDiagnostics()
{
var source1 = @"
Expand Down Expand Up @@ -155,10 +155,8 @@ private void NonPartialMethod2() { }
var compilation = CreateCompilationWithMscorlib45(new[] { tree1, tree2 }).WithEventQueue(eventQueue);

// Invoke SemanticModel.GetDiagnostics to force populate the event queue for symbols in the first source file.
var tree = compilation.SyntaxTrees.Single(t => t == tree1);
var root = tree.GetRoot();
var model = compilation.GetSemanticModel(tree);
model.GetDiagnostics(root.FullSpan);
var model = compilation.GetSemanticModel(tree1);
model.GetDiagnostics(tree1.GetRoot().FullSpan);

Assert.True(eventQueue.Count > 0);
bool compilationStartedFired;
Expand All @@ -171,10 +169,10 @@ private void NonPartialMethod2() { }
Assert.True(declaredSymbolNames.Contains("N1"));
Assert.True(declaredSymbolNames.Contains("Class"));
Assert.True(declaredSymbolNames.Contains("NonPartialMethod1"));
Assert.True(completedCompilationUnits.Contains(tree.FilePath));
Assert.True(completedCompilationUnits.Contains(tree1.FilePath));
}

[Fact(Skip = "7446"), WorkItem(7446, "https://github.com/dotnet/roslyn/issues/7446")]
[Fact(Skip = "https://github.com/dotnet/roslyn/issues/7477"), WorkItem(7477, "https://github.com/dotnet/roslyn/issues/7477")]
public void TestCompilationEventsForPartialMethod()
{
var source1 = @"
Expand Down Expand Up @@ -204,10 +202,8 @@ partial void PartialMethod() { }
var compilation = CreateCompilationWithMscorlib45(new[] { tree1, tree2 }).WithEventQueue(eventQueue);

// Invoke SemanticModel.GetDiagnostics to force populate the event queue for symbols in the first source file.
var tree = compilation.SyntaxTrees.Single(t => t == tree1);
var root = tree.GetRoot();
var model = compilation.GetSemanticModel(tree);
model.GetDiagnostics(root.FullSpan);
var model = compilation.GetSemanticModel(tree1);
model.GetDiagnostics(tree1.GetRoot().FullSpan);

Assert.True(eventQueue.Count > 0);
bool compilationStartedFired;
Expand All @@ -221,7 +217,7 @@ partial void PartialMethod() { }
Assert.True(declaredSymbolNames.Contains("Class"));
Assert.True(declaredSymbolNames.Contains("NonPartialMethod1"));
Assert.True(declaredSymbolNames.Contains("PartialMethod"));
Assert.True(completedCompilationUnits.Contains(tree.FilePath));
Assert.True(completedCompilationUnits.Contains(tree1.FilePath));
}

private static bool DequeueCompilationEvents(AsyncQueue<CompilationEvent> eventQueue, out bool compilationStartedFired, out HashSet<string> declaredSymbolNames, out HashSet<string> completedCompilationUnits)
Expand All @@ -247,7 +243,8 @@ private static bool DequeueCompilationEvents(AsyncQueue<CompilationEvent> eventQ
var symbolDeclaredEvent = compEvent as SymbolDeclaredCompilationEvent;
if (symbolDeclaredEvent != null)
{
Assert.True(declaredSymbolNames.Add(symbolDeclaredEvent.Symbol.Name), "Unexpected multiple symbol declared events for same symbol");
var added = declaredSymbolNames.Add(symbolDeclaredEvent.Symbol.Name);
Assert.True(added, "Unexpected multiple symbol declared events for symbol " + symbolDeclaredEvent.Symbol);
}
else
{
Expand Down

0 comments on commit 836e78e

Please sign in to comment.