Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Further FAR simplifications #54652

Merged
merged 1 commit into from
Jul 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -251,23 +251,18 @@ protected static async Task<ImmutableArray<SyntaxToken>> GetIdentifierOrGlobalNa
{
return async (node, model) =>
{
var symbolInfoToMatch = FindReferenceCache.GetSymbolInfo(model, node, cancellationToken);
var symbolInfo = FindReferenceCache.GetSymbolInfo(model, node, cancellationToken);

var symbolToMatch = symbolInfoToMatch.Symbol;
var symbolToMatchCompilation = model.Compilation;

if (await SymbolFinder.OriginalSymbolsMatchAsync(solution, searchSymbol, symbolInfoToMatch.Symbol, cancellationToken).ConfigureAwait(false))
{
if (await SymbolFinder.OriginalSymbolsMatchAsync(solution, searchSymbol, symbolInfo.Symbol, cancellationToken).ConfigureAwait(false))
return (matched: true, CandidateReason.None);
}
else if (await symbolInfoToMatch.CandidateSymbols.AnyAsync(static (s, arg) => SymbolFinder.OriginalSymbolsMatchAsync(arg.solution, arg.searchSymbol, s, arg.cancellationToken), (solution, searchSymbol, cancellationToken)).ConfigureAwait(false))
{
return (matched: true, symbolInfoToMatch.CandidateReason);
}
else

foreach (var candidate in symbolInfo.CandidateSymbols)
{
return (matched: false, CandidateReason.None);
if (await SymbolFinder.OriginalSymbolsMatchAsync(solution, searchSymbol, candidate, cancellationToken).ConfigureAwait(false))
return (matched: true, symbolInfo.CandidateReason);
}

return default;
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 logic is the same, just removed unnecessary variables, and inlined a loop.

};
}

Expand Down Expand Up @@ -471,11 +466,11 @@ protected static Task<ImmutableArray<Document>> FindDocumentsWithImplicitObjectC
/// <summary>
/// If the `node` implicitly matches the `symbol`, then it will be added to `locations`.
/// </summary>
protected delegate void CollectMatchingReferences(ISymbol symbol, SyntaxNode node,
ISyntaxFactsService syntaxFacts, ISemanticFactsService semanticFacts, ArrayBuilder<FinderLocation> locations);
protected delegate void CollectMatchingReferences(
SyntaxNode node, ISyntaxFactsService syntaxFacts, ISemanticFactsService semanticFacts, ArrayBuilder<FinderLocation> locations);

protected static async Task<ImmutableArray<FinderLocation>> FindReferencesInDocumentAsync(
ISymbol symbol,
ISymbol _,
Document document,
Func<SyntaxTreeIndex, bool> isRelevantDocument,
CollectMatchingReferences collectMatchingReferences,
Expand All @@ -488,14 +483,12 @@ protected static async Task<ImmutableArray<FinderLocation>> FindReferencesInDocu
var semanticFacts = document.GetRequiredLanguageService<ISemanticFactsService>();
var syntaxRoot = await document.GetRequiredSyntaxRootAsync(cancellationToken).ConfigureAwait(false);

using var _ = ArrayBuilder<FinderLocation>.GetInstance(out var locations);

var originalUnreducedSymbolDefinition = symbol.GetOriginalUnreducedDefinition();
using var _1 = ArrayBuilder<FinderLocation>.GetInstance(out var locations);

foreach (var node in syntaxRoot.DescendantNodesAndSelf())
{
cancellationToken.ThrowIfCancellationRequested();
collectMatchingReferences(originalUnreducedSymbolDefinition, node, syntaxFacts, semanticFacts, locations);
collectMatchingReferences(node, syntaxFacts, semanticFacts, locations);
}

return locations.ToImmutable();
Expand All @@ -515,15 +508,15 @@ protected Task<ImmutableArray<FinderLocation>> FindReferencesInForEachStatements
static bool IsRelevantDocument(SyntaxTreeIndex syntaxTreeInfo)
=> syntaxTreeInfo.ContainsForEachStatement;

void CollectMatchingReferences(ISymbol originalUnreducedSymbolDefinition, SyntaxNode node,
ISyntaxFactsService syntaxFacts, ISemanticFactsService semanticFacts, ArrayBuilder<FinderLocation> locations)
void CollectMatchingReferences(
SyntaxNode node, ISyntaxFactsService syntaxFacts, ISemanticFactsService semanticFacts, ArrayBuilder<FinderLocation> locations)
{
var info = semanticFacts.GetForEachSymbols(semanticModel, node);

if (Matches(info.GetEnumeratorMethod, originalUnreducedSymbolDefinition) ||
Matches(info.MoveNextMethod, originalUnreducedSymbolDefinition) ||
Matches(info.CurrentProperty, originalUnreducedSymbolDefinition) ||
Matches(info.DisposeMethod, originalUnreducedSymbolDefinition))
if (Matches(info.GetEnumeratorMethod, symbol) ||
Matches(info.MoveNextMethod, symbol) ||
Matches(info.CurrentProperty, symbol) ||
Matches(info.DisposeMethod, symbol))
{
var location = node.GetFirstToken().GetLocation();
var symbolUsageInfo = GetSymbolUsageInfo(node, semanticModel, syntaxFacts, semanticFacts, cancellationToken);
Expand Down Expand Up @@ -551,8 +544,8 @@ protected Task<ImmutableArray<FinderLocation>> FindReferencesInDeconstructionAsy
static bool IsRelevantDocument(SyntaxTreeIndex syntaxTreeInfo)
=> syntaxTreeInfo.ContainsDeconstruction;

void CollectMatchingReferences(ISymbol originalUnreducedSymbolDefinition, SyntaxNode node,
ISyntaxFactsService syntaxFacts, ISemanticFactsService semanticFacts, ArrayBuilder<FinderLocation> locations)
void CollectMatchingReferences(
SyntaxNode node, ISyntaxFactsService syntaxFacts, ISemanticFactsService semanticFacts, ArrayBuilder<FinderLocation> locations)
{
var deconstructMethods = semanticFacts.GetDeconstructionAssignmentMethods(semanticModel, node);
if (deconstructMethods.IsEmpty)
Expand All @@ -561,7 +554,7 @@ void CollectMatchingReferences(ISymbol originalUnreducedSymbolDefinition, Syntax
deconstructMethods = semanticFacts.GetDeconstructionForEachMethods(semanticModel, node);
}

if (deconstructMethods.Any(m => Matches(m, originalUnreducedSymbolDefinition)))
if (deconstructMethods.Any(m => Matches(m, symbol)))
{
var location = syntaxFacts.GetDeconstructionReferenceLocation(node);
var symbolUsageInfo = GetSymbolUsageInfo(node, semanticModel, syntaxFacts, semanticFacts, cancellationToken);
Expand All @@ -583,12 +576,12 @@ protected Task<ImmutableArray<FinderLocation>> FindReferencesInAwaitExpressionAs
static bool IsRelevantDocument(SyntaxTreeIndex syntaxTreeInfo)
=> syntaxTreeInfo.ContainsAwait;

void CollectMatchingReferences(ISymbol originalUnreducedSymbolDefinition, SyntaxNode node,
ISyntaxFactsService syntaxFacts, ISemanticFactsService semanticFacts, ArrayBuilder<FinderLocation> locations)
void CollectMatchingReferences(
SyntaxNode node, ISyntaxFactsService syntaxFacts, ISemanticFactsService semanticFacts, ArrayBuilder<FinderLocation> locations)
{
var awaitExpressionMethod = semanticFacts.GetGetAwaiterMethod(semanticModel, node);

if (Matches(awaitExpressionMethod, originalUnreducedSymbolDefinition))
if (Matches(awaitExpressionMethod, symbol))
{
var location = node.GetFirstToken().GetLocation();
var symbolUsageInfo = GetSymbolUsageInfo(node, semanticModel, syntaxFacts, semanticFacts, cancellationToken);
Expand All @@ -610,8 +603,8 @@ protected Task<ImmutableArray<FinderLocation>> FindReferencesInImplicitObjectCre
static bool IsRelevantDocument(SyntaxTreeIndex syntaxTreeInfo)
=> syntaxTreeInfo.ContainsImplicitObjectCreation;

void CollectMatchingReferences(ISymbol originalUnreducedSymbolDefinition, SyntaxNode node,
ISyntaxFactsService syntaxFacts, ISemanticFactsService semanticFacts, ArrayBuilder<FinderLocation> locations)
void CollectMatchingReferences(
SyntaxNode node, ISyntaxFactsService syntaxFacts, ISemanticFactsService semanticFacts, ArrayBuilder<FinderLocation> locations)
{
if (!syntaxFacts.IsImplicitObjectCreation(node))
{
Expand All @@ -621,7 +614,7 @@ void CollectMatchingReferences(ISymbol originalUnreducedSymbolDefinition, Syntax

var constructor = semanticModel.GetSymbolInfo(node, cancellationToken).Symbol;

if (Matches(constructor, originalUnreducedSymbolDefinition))
if (Matches(constructor, symbol))
{
var location = node.GetFirstToken().GetLocation();
var symbolUsageInfo = GetSymbolUsageInfo(node, semanticModel, syntaxFacts, semanticFacts, cancellationToken);
Expand All @@ -632,11 +625,12 @@ void CollectMatchingReferences(ISymbol originalUnreducedSymbolDefinition, Syntax
}
}

protected static bool Matches(ISymbol? symbol1, ISymbol notNulloriginalUnreducedSymbol2)
protected static bool Matches(ISymbol? symbol1, ISymbol notNullOriginalUnreducedSymbol2)
{
Contract.ThrowIfFalse(notNullOriginalUnreducedSymbol2.GetOriginalUnreducedDefinition().Equals(notNullOriginalUnreducedSymbol2));
return symbol1 != null && SymbolEquivalenceComparer.Instance.Equals(
symbol1.GetOriginalUnreducedDefinition(),
notNulloriginalUnreducedSymbol2);
notNullOriginalUnreducedSymbol2);
}

protected static SymbolUsageInfo GetSymbolUsageInfo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,7 @@ static bool IsRelevantDocument(SyntaxTreeIndex syntaxTreeInfo)
=> syntaxTreeInfo.ContainsImplicitObjectCreation;

void CollectMatchingReferences(
ISymbol originalUnreducedSymbolDefinition, SyntaxNode node,
ISyntaxFactsService syntaxFacts, ISemanticFactsService semanticFacts,
ArrayBuilder<FinderLocation> locations)
SyntaxNode node, ISyntaxFactsService syntaxFacts, ISemanticFactsService semanticFacts, ArrayBuilder<FinderLocation> locations)
{
if (!syntaxFacts.IsImplicitObjectCreationExpression(node))
return;
Expand All @@ -190,7 +188,7 @@ void CollectMatchingReferences(
return;

var constructor = semanticModel.GetSymbolInfo(node, cancellationToken).Symbol;
if (Matches(constructor, originalUnreducedSymbolDefinition))
if (Matches(constructor, symbol))
{
var location = node.GetFirstToken().GetLocation();
var symbolUsageInfo = GetSymbolUsageInfo(node, semanticModel, syntaxFacts, semanticFacts, cancellationToken);
Expand Down