Skip to content

Fix Union to match the semantics of GetApplicableAnalyzers#64484

Merged
davidwengier merged 4 commits intodotnet:release/dev17.4from
davidwengier:SolutionCrawler
Oct 6, 2022
Merged

Fix Union to match the semantics of GetApplicableAnalyzers#64484
davidwengier merged 4 commits intodotnet:release/dev17.4from
davidwengier:SolutionCrawler

Conversation

@davidwengier
Copy link
Member

No description provided.

@ghost ghost added the Area-IDE label Oct 4, 2022
@davidwengier davidwengier changed the base branch from main to release/dev17.4 October 4, 2022 21:22
}

[Fact]
public async Task SpecificAnalyzers_SpecificThenAll()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test fails without the changeso the Union method

asyncToken);
}

public WorkItem With(ImmutableHashSet<IIncrementalAnalyzer> specificAnalyzers, IAsyncToken asyncToken)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method was unused, and didn't call Union at all, so I thought it best to remove before someone calls it and does who-knows-what

@davidwengier davidwengier marked this pull request as ready for review October 5, 2022 02:06
@davidwengier davidwengier requested a review from a team as a code owner October 5, 2022 02:06
@davidwengier
Copy link
Member Author

Sadly, this assert is failing,
https://github.com/dotnet/roslyn/blob/main/src/Features/Core/Portable/SolutionCrawler/WorkCoordinator.NormalPriorityProcessor.cs#L446

Not sure if thats a problem though, or just validating an old assumption. @mavasani any context you could help with?

I've validated on my machine that SymbolTreeInfoIncrementalAnalyzer.AnalyzeProjectAsync is never called if I turn off the "Load projects faster" Preview Feature in Tools > Options, but with this fix, it is called. Thats essentially the same thing as I'm seeing on VS Mac, which doesn't have operation progress (which taht preview feature controls)

@mavasani
Copy link
Contributor

mavasani commented Oct 5, 2022

Sadly, this assert is failing, https://github.com/dotnet/roslyn/blob/main/src/Features/Core/Portable/SolutionCrawler/WorkCoordinator.NormalPriorityProcessor.cs#L446

Not sure if thats a problem though, or just validating an old assumption. @mavasani any context you could help with?

I've validated on my machine that SymbolTreeInfoIncrementalAnalyzer.AnalyzeProjectAsync is never called if I turn off the "Load projects faster" Preview Feature in Tools > Options, but with this fix, it is called. Thats essentially the same thing as I'm seeing on VS Mac, which doesn't have operation progress (which taht preview feature controls)

So, the assert seems to be still valid, and the subsequent code in this method is actually relying on it. If you look at the below line:

var reanalyzers = workItem.SpecificAnalyzers.ToImmutableArray();

For your case, this will be empty set of analyzers, so the entire method ProcessReanalyzeDocumentAsync essentially becomes a no-op. I think you should remove the assert you mentioned but also change the above line to:

var reanalyzers = workItem.GetApplicableAnalyzers(analyzers).ToImmutableArray(); 

This would require you to thread in the analyzers parameter into ProcessReanalyzeDocumentAsync from its callsite.

@davidwengier
Copy link
Member Author

Looks like the first thing that RunAnalyzersAsync does with the reanalyzers is to call GetApplicableAnalyzers anyway, so I think just threading through the parameter should be enough.

}

// First reset the document state in analyzers.
var reanalyzers = workItem.SpecificAnalyzers.ToImmutableArray();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just from looking at the code, and having no other context, I'm wondering if perhaps this method was intended to run only when there are specific analyzers on a work item.. in which case perhaps rather than removing the assert, it would make more sense to simply add || workItem.SpecificAnalyzers.Count > 0 to the early-return guard above?

But at the same time, what I have here also makes sense. All of the tests pass too, so I really don't know what exactly to go on, to try to work out what this method is intended to do.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the core issue seems to be "Reanalyze" was designed only for a single/subset of specific analyzers. I think your change is fine to unblock us, and lets pray that @CyrusNajmabadi kills the solution crawler before this change uncovers more bugs :-)

Copy link
Member Author

@davidwengier davidwengier Oct 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I shouldn't point out the bit of code I found, where if you call item.With(..., ..., item.AsyncToken) the first thing the With method does is dispose the async token that you're trying to re-use? :D

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't it dispose the old one and re-use the new one?

// dispose old one
AsyncToken.Dispose();
// create new work item
return new WorkItem(
DocumentId, ProjectId, Language,
InvocationReasons.With(invocationReasons),
IsLowPriority,
ActiveMember == currentMember ? currentMember : null,
Union(analyzers), IsRetry || retry,
asyncToken);

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, bit there are spots where the old one is passed in, to be the new one, presumably assuming it will just be reused.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably add a guard that AsyncToken != asyncToken around the above Dispose call?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if I want to touch it.. this is going into 17.4 under QB and I don't understand the implications

@davidwengier
Copy link
Member Author

Bug for QB: https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1639039

@arkalyanms for approval

@build-analysis build-analysis bot mentioned this pull request Oct 6, 2022
2 tasks
@davidwengier davidwengier merged commit 53c4590 into dotnet:release/dev17.4 Oct 6, 2022
@davidwengier davidwengier deleted the SolutionCrawler branch October 6, 2022 02:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants