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

Remove async from FindReferencesInDocument #73516

Merged
merged 10 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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 @@ -236,7 +236,7 @@ private static async Task<ImmutableArray<ReferencedSymbol>> FindChangeSignatureR
var engine = new FindReferencesSearchEngine(
solution,
documents: null,
ReferenceFinders.DefaultReferenceFinders.Add(DelegateInvokeMethodReferenceFinder.DelegateInvokeMethod),
[.. ReferenceFinders.DefaultReferenceFinders, DelegateInvokeMethodReferenceFinder.Instance],
streamingProgress,
FindReferencesSearchOptions.Default);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,13 @@ namespace Microsoft.CodeAnalysis.ChangeSignature;
/// <remarks>
/// TODO: Rewrite this to track backward through references instead of binding everything
/// </remarks>
internal class DelegateInvokeMethodReferenceFinder : AbstractReferenceFinder<IMethodSymbol>
internal sealed class DelegateInvokeMethodReferenceFinder : AbstractReferenceFinder<IMethodSymbol>
{
public static readonly IReferenceFinder DelegateInvokeMethod = new DelegateInvokeMethodReferenceFinder();
public static readonly DelegateInvokeMethodReferenceFinder Instance = new();

private DelegateInvokeMethodReferenceFinder()
{
}

protected override bool CanFind(IMethodSymbol symbol)
=> symbol.MethodKind == MethodKind.DelegateInvoke;
Expand Down Expand Up @@ -76,7 +80,7 @@ protected override Task DetermineDocumentsToSearchAsync<TData>(
return Task.CompletedTask;
}

protected override async ValueTask FindReferencesInDocumentAsync<TData>(
protected override void FindReferencesInDocument<TData>(
IMethodSymbol methodSymbol,
FindReferencesDocumentState state,
Action<FinderLocation, TData> processResult,
Expand Down Expand Up @@ -105,8 +109,7 @@ protected override async ValueTask FindReferencesInDocumentAsync<TData>(
var convertedType = (ISymbol?)state.SemanticModel.GetTypeInfo(node, cancellationToken).ConvertedType;
if (convertedType != null)
{
convertedType = await SymbolFinder.FindSourceDefinitionAsync(convertedType, state.Solution, cancellationToken).ConfigureAwait(false)
?? convertedType;
convertedType = SymbolFinder.FindSourceDefinition(convertedType, state.Solution, cancellationToken) ?? convertedType;
}

if (convertedType == methodSymbol.ContainingType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,19 +290,20 @@ private async ValueTask ProcessDocumentAsync(
await RoslynParallel.ForEachAsync(
symbols,
GetParallelOptions(cancellationToken),
async (symbol, cancellationToken) =>
(symbol, cancellationToken) =>
{
// symbolToGlobalAliases is safe to read in parallel. It is created fully before this point and is no
// longer mutated.
var state = new FindReferencesDocumentState(
cache, TryGet(symbolToGlobalAliases, symbol));

await ProcessDocumentAsync(symbol, state, onReferenceFound).ConfigureAwait(false);
ProcessDocument(symbol, state, onReferenceFound);
return ValueTaskFactory.CompletedTask;
}).ConfigureAwait(false);

return;

async Task ProcessDocumentAsync(
void ProcessDocument(
ISymbol symbol, FindReferencesDocumentState state, Action<Reference> onReferenceFound)
{
cancellationToken.ThrowIfCancellationRequested();
Expand All @@ -318,12 +319,12 @@ async Task ProcessDocumentAsync(
// and only do interesting work on the single relevant one.
foreach (var finder in _finders)
{
await finder.FindReferencesInDocumentAsync(
finder.FindReferencesInDocument(
symbol, state,
static (loc, tuple) => tuple.onReferenceFound((tuple.group, tuple.symbol, loc.Location)),
(group, symbol, onReferenceFound),
_options,
cancellationToken).ConfigureAwait(false);
cancellationToken);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ async ValueTask DirectSymbolSearchAsync(ISymbol symbol, FindReferencesDocumentSt
using var _ = ArrayBuilder<FinderLocation>.GetInstance(out var referencesForFinder);
foreach (var finder in _finders)
{
await finder.FindReferencesInDocumentAsync(
symbol, state, StandardCallbacks<FinderLocation>.AddToArrayBuilder, referencesForFinder, _options, cancellationToken).ConfigureAwait(false);
finder.FindReferencesInDocument(
symbol, state, StandardCallbacks<FinderLocation>.AddToArrayBuilder, referencesForFinder, _options, cancellationToken);
}

if (referencesForFinder.Count > 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ protected sealed override Task DetermineDocumentsToSearchAsync<TData>(
return Task.CompletedTask;
}

protected sealed override ValueTask FindReferencesInDocumentAsync<TData>(
protected sealed override void FindReferencesInDocument<TData>(
TSymbol symbol,
FindReferencesDocumentState state,
Action<FinderLocation, TData> processResult,
Expand All @@ -67,8 +67,6 @@ protected sealed override ValueTask FindReferencesInDocumentAsync<TData>(
var tokens = FindMatchingIdentifierTokens(state, symbol.Name, cancellationToken);
FindReferencesInTokens(symbol, state, tokens, processResult, processResultData, cancellationToken);
}

return ValueTaskFactory.CompletedTask;
}

private static ISymbol? GetContainer(ISymbol symbol)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public abstract ValueTask<ImmutableArray<ISymbol>> DetermineCascadedSymbolsAsync
public abstract Task DetermineDocumentsToSearchAsync<TData>(
ISymbol symbol, HashSet<string>? globalAliases, Project project, IImmutableSet<Document>? documents, Action<Document, TData> processResult, TData processResultData, FindReferencesSearchOptions options, CancellationToken cancellationToken);

public abstract ValueTask FindReferencesInDocumentAsync<TData>(
public abstract void FindReferencesInDocument<TData>(
ISymbol symbol, FindReferencesDocumentState state, Action<FinderLocation, TData> processResult, TData processResultData, FindReferencesSearchOptions options, CancellationToken cancellationToken);

private static (bool matched, CandidateReason reason) SymbolsMatch(
Expand Down Expand Up @@ -848,7 +848,7 @@ protected abstract Task DetermineDocumentsToSearchAsync<TData>(
Action<Document, TData> processResult, TData processResultData,
FindReferencesSearchOptions options, CancellationToken cancellationToken);

protected abstract ValueTask FindReferencesInDocumentAsync<TData>(
protected abstract void FindReferencesInDocument<TData>(
TSymbol symbol, FindReferencesDocumentState state,
Action<FinderLocation, TData> processResult, TData processResultData,
FindReferencesSearchOptions options, CancellationToken cancellationToken);
Expand Down Expand Up @@ -878,12 +878,11 @@ public sealed override Task DetermineDocumentsToSearchAsync<TData>(
return Task.CompletedTask;
}

public sealed override ValueTask FindReferencesInDocumentAsync<TData>(
public sealed override void FindReferencesInDocument<TData>(
ISymbol symbol, FindReferencesDocumentState state, Action<FinderLocation, TData> processResult, TData processResultData, FindReferencesSearchOptions options, CancellationToken cancellationToken)
{
return symbol is TSymbol typedSymbol && CanFind(typedSymbol)
? FindReferencesInDocumentAsync(typedSymbol, state, processResult, processResultData, options, cancellationToken)
: ValueTaskFactory.CompletedTask;
if (symbol is TSymbol typedSymbol && CanFind(typedSymbol))
FindReferencesInDocument(typedSymbol, state, processResult, processResultData, options, cancellationToken);
}

public sealed override ValueTask<ImmutableArray<ISymbol>> DetermineCascadedSymbolsAsync(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace Microsoft.CodeAnalysis.FindSymbols.Finders;

internal abstract class AbstractTypeParameterSymbolReferenceFinder : AbstractReferenceFinder<ITypeParameterSymbol>
{
protected sealed override ValueTask FindReferencesInDocumentAsync<TData>(
protected sealed override void FindReferencesInDocument<TData>(
ITypeParameterSymbol symbol,
FindReferencesDocumentState state,
Action<FinderLocation, TData> processResult,
Expand Down Expand Up @@ -43,7 +43,7 @@ protected sealed override ValueTask FindReferencesInDocumentAsync<TData>(
processResult,
processResultData);

return ValueTaskFactory.CompletedTask;
return;

static bool IsObjectCreationToken(SyntaxToken token, FindReferencesDocumentState state)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ protected override Task DetermineDocumentsToSearchAsync<TData>(
}, symbol.ContainingType.Name, processResult, processResultData, cancellationToken);
}

protected sealed override ValueTask FindReferencesInDocumentAsync<TData>(
protected sealed override void FindReferencesInDocument<TData>(
IMethodSymbol methodSymbol,
FindReferencesDocumentState state,
Action<FinderLocation, TData> processResult,
Expand All @@ -68,7 +68,7 @@ protected sealed override ValueTask FindReferencesInDocumentAsync<TData>(
(state, methodSymbol, cancellationToken));

FindReferencesInTokens(methodSymbol, state, totalTokens, processResult, processResultData, cancellationToken);
return ValueTaskFactory.CompletedTask;
return;

// local functions
static bool TokensMatch(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

namespace Microsoft.CodeAnalysis.FindSymbols.Finders;

internal class ConstructorSymbolReferenceFinder : AbstractReferenceFinder<IMethodSymbol>
internal sealed class ConstructorSymbolReferenceFinder : AbstractReferenceFinder<IMethodSymbol>
{
public static readonly ConstructorSymbolReferenceFinder Instance = new();

Expand Down Expand Up @@ -90,7 +90,7 @@ private static bool IsPotentialReference(PredefinedType predefinedType, ISyntaxF
=> syntaxFacts.TryGetPredefinedType(token, out var actualType) &&
predefinedType == actualType;

protected override ValueTask FindReferencesInDocumentAsync<TData>(
protected override void FindReferencesInDocument<TData>(
IMethodSymbol methodSymbol,
FindReferencesDocumentState state,
Action<FinderLocation, TData> processResult,
Expand Down Expand Up @@ -126,8 +126,6 @@ protected override ValueTask FindReferencesInDocumentAsync<TData>(

FindReferencesInDocumentInsideGlobalSuppressions(
methodSymbol, state, processResult, processResultData, cancellationToken);

return ValueTaskFactory.CompletedTask;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,13 @@ protected override Task DetermineDocumentsToSearchAsync<TData>(
return Task.CompletedTask;
}

protected override ValueTask FindReferencesInDocumentAsync<TData>(
protected override void FindReferencesInDocument<TData>(
IMethodSymbol methodSymbol,
FindReferencesDocumentState state,
Action<FinderLocation, TData> processResult,
TData processResultData,
FindReferencesSearchOptions options,
CancellationToken cancellationToken)
{
return ValueTaskFactory.CompletedTask;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace Microsoft.CodeAnalysis.FindSymbols.Finders;

internal class EventSymbolReferenceFinder : AbstractMethodOrPropertyOrEventSymbolReferenceFinder<IEventSymbol>
internal sealed class EventSymbolReferenceFinder : AbstractMethodOrPropertyOrEventSymbolReferenceFinder<IEventSymbol>
{
protected override bool CanFind(IEventSymbol symbol)
=> true;
Expand Down Expand Up @@ -49,7 +49,7 @@ protected sealed override async Task DetermineDocumentsToSearchAsync<TData>(
await FindDocumentsWithGlobalSuppressMessageAttributeAsync(project, documents, processResult, processResultData, cancellationToken).ConfigureAwait(false);
}

protected sealed override ValueTask FindReferencesInDocumentAsync<TData>(
protected sealed override void FindReferencesInDocument<TData>(
IEventSymbol symbol,
FindReferencesDocumentState state,
Action<FinderLocation, TData> processResult,
Expand All @@ -58,6 +58,5 @@ protected sealed override ValueTask FindReferencesInDocumentAsync<TData>(
CancellationToken cancellationToken)
{
FindReferencesInDocumentUsingSymbolName(symbol, state, processResult, processResultData, cancellationToken);
return ValueTaskFactory.CompletedTask;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ protected sealed override async Task DetermineDocumentsToSearchAsync<TData>(
}
}

protected sealed override ValueTask FindReferencesInDocumentAsync<TData>(
protected sealed override void FindReferencesInDocument<TData>(
IMethodSymbol symbol,
FindReferencesDocumentState state,
Action<FinderLocation, TData> processResult,
Expand All @@ -74,7 +74,6 @@ protected sealed override ValueTask FindReferencesInDocumentAsync<TData>(
state);

FindReferencesInTokens(symbol, state, tokens, processResult, processResultData, cancellationToken);
return ValueTaskFactory.CompletedTask;
}

private static bool IsPotentialReference(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ protected sealed override Task DetermineDocumentsToSearchAsync<TData>(
return Task.CompletedTask;
}

protected sealed override ValueTask FindReferencesInDocumentAsync<TData>(
protected sealed override void FindReferencesInDocument<TData>(
IMethodSymbol symbol,
FindReferencesDocumentState state,
Action<FinderLocation, TData> processResult,
Expand All @@ -39,6 +39,5 @@ protected sealed override ValueTask FindReferencesInDocumentAsync<TData>(
CancellationToken cancellationToken)
{
// An explicit method can't be referenced anywhere.
return ValueTaskFactory.CompletedTask;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ protected override async Task DetermineDocumentsToSearchAsync<TData>(
await FindDocumentsWithGlobalSuppressMessageAttributeAsync(project, documents, processResult, processResultData, cancellationToken).ConfigureAwait(false);
}

protected override ValueTask FindReferencesInDocumentAsync<TData>(
protected override void FindReferencesInDocument<TData>(
IFieldSymbol symbol,
FindReferencesDocumentState state,
Action<FinderLocation, TData> processResult,
Expand All @@ -53,6 +53,5 @@ protected override ValueTask FindReferencesInDocumentAsync<TData>(
symbol, state, processResult, processResultData, cancellationToken);
FindReferencesInDocumentInsideGlobalSuppressions(
symbol, state, processResult, processResultData, cancellationToken);
return ValueTaskFactory.CompletedTask;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Task DetermineDocumentsToSearchAsync<TData>(
///
/// Implementations of this method must be thread-safe.
/// </summary>
ValueTask FindReferencesInDocumentAsync<TData>(
void FindReferencesInDocument<TData>(
ISymbol symbol,
FindReferencesDocumentState state,
Action<FinderLocation, TData> processResult,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Threading;

namespace Microsoft.CodeAnalysis.FindSymbols.Finders;

internal sealed class LabelSymbolReferenceFinder : AbstractMemberScopedReferenceFinder<ILabelSymbol>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ private static bool IsPotentialReference(
predefinedType == actualType;
}

protected override ValueTask FindReferencesInDocumentAsync<TData>(
protected override void FindReferencesInDocument<TData>(
INamedTypeSymbol namedType,
FindReferencesDocumentState state,
Action<FinderLocation, TData> processResult,
Expand Down Expand Up @@ -135,8 +135,6 @@ protected override ValueTask FindReferencesInDocumentAsync<TData>(

FindReferencesInDocumentInsideGlobalSuppressions(
namedType, state, processResult, processResultData, cancellationToken);

return ValueTaskFactory.CompletedTask;
}

internal static void AddReferencesToTypeOrGlobalAliasToIt<TData>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

namespace Microsoft.CodeAnalysis.FindSymbols.Finders;

internal class NamespaceSymbolReferenceFinder : AbstractReferenceFinder<INamespaceSymbol>
internal sealed class NamespaceSymbolReferenceFinder : AbstractReferenceFinder<INamespaceSymbol>
{
protected override bool CanFind(INamespaceSymbol symbol)
=> true;
Expand Down Expand Up @@ -51,7 +51,7 @@ await FindDocumentsAsync(
await FindDocumentsWithGlobalSuppressMessageAttributeAsync(project, documents, processResult, processResultData, cancellationToken).ConfigureAwait(false);
}

protected override ValueTask FindReferencesInDocumentAsync<TData>(
protected override void FindReferencesInDocument<TData>(
INamespaceSymbol symbol,
FindReferencesDocumentState state,
Action<FinderLocation, TData> processResult,
Expand Down Expand Up @@ -94,8 +94,6 @@ protected override ValueTask FindReferencesInDocumentAsync<TData>(
FindReferencesInDocumentInsideGlobalSuppressions(
symbol, state, processResult, processResultData, cancellationToken);
}

return ValueTaskFactory.CompletedTask;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ private static Task FindDocumentsAsync<TData>(
project, documents, static (index, op) => index.ContainsPredefinedOperator(op), op, processResult, processResultData, cancellationToken);
}

protected sealed override ValueTask FindReferencesInDocumentAsync<TData>(
protected sealed override void FindReferencesInDocument<TData>(
IMethodSymbol symbol,
FindReferencesDocumentState state,
Action<FinderLocation, TData> processResult,
Expand All @@ -67,7 +67,6 @@ protected sealed override ValueTask FindReferencesInDocumentAsync<TData>(
symbol, state, tokens, processResult, processResultData, cancellationToken);
FindReferencesInDocumentInsideGlobalSuppressions(
symbol, state, processResult, processResultData, cancellationToken);
return ValueTaskFactory.CompletedTask;
}

private static bool IsPotentialReference(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ private static bool IsGetAwaiterMethod(IMethodSymbol methodSymbol)
private static bool IsAddMethod(IMethodSymbol methodSymbol)
=> methodSymbol.Name == WellKnownMemberNames.CollectionInitializerAddMethodName;

protected sealed override ValueTask FindReferencesInDocumentAsync<TData>(
protected sealed override void FindReferencesInDocument<TData>(
IMethodSymbol symbol,
FindReferencesDocumentState state,
Action<FinderLocation, TData> processResult,
Expand All @@ -134,7 +134,5 @@ protected sealed override ValueTask FindReferencesInDocumentAsync<TData>(

if (IsAddMethod(symbol))
FindReferencesInCollectionInitializer(symbol, state, processResult, processResultData, cancellationToken);

return ValueTaskFactory.CompletedTask;
}
}
Loading
Loading