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

Fix find refs doing too much work lookign for types that had an alias to them in one file. #74015

Merged
merged 5 commits into from
Jun 16, 2024

Conversation

CyrusNajmabadi
Copy link
Member

A silly bug was making it so that if there was a regular (non-global) using alias to a symbol anywhere in a project, that we would think there wa sa global alias to it. We'd then search for that global alias in all files to see if it was a hit for the original symbol, doing lots of unnecessary work.

@CyrusNajmabadi CyrusNajmabadi requested a review from a team as a code owner June 15, 2024 01:26
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Jun 15, 2024
ref HashSet<(string alias, string name, int arity)>? globalAliasInfo,
SyntaxNode node)
{
if (!syntaxFacts.IsUsingAliasDirective(node))
return;

syntaxFacts.GetPartsOfUsingAliasDirective(node, out var globalToken, out var alias, out var usingTarget);
if (globalToken.IsMissing)
return;
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 was the bug. IsMissing is for when the parser thinks a token must be there but doesn't see it. e.g. if x == y) will have a 'missing' open paren token. but if you just have using x = u; there is no missing 'global' token there as that's just a legal using statement with a default global token.

this bug was making it so that every alias in the project was being treated as a global alias. We'd still only look for that alias if the name it bound to was hte name of hte symbol we were looking for. but this was still unnecessary work.

AddReferencesInDocumentWorker(
methodSymbol, name, state, processResult, processResultData, cancellationToken);
methodSymbol, containingTypeName, state, processResult, processResultData, cancellationToken);

// Next, look for constructor references through a global alias to our containing type.
foreach (var globalAlias in state.GlobalAliases)
Copy link
Member Author

Choose a reason for hiding this comment

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

we both want to search for references to global aliases anywhere that might be to our symbol, and...

methodSymbol, globalAlias, state, processResult, processResultData, cancellationToken);
}
foreach (var localAlias in state.Cache.SyntaxTreeIndex.GetAliases(containingTypeName, containingType.Arity))
FindReferenceToAlias(methodSymbol, state, processResult, processResultData, containingTypeName, localAlias, cancellationToken);
Copy link
Member Author

@CyrusNajmabadi CyrusNajmabadi Jun 15, 2024

Choose a reason for hiding this comment

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

... we want to search for local aliases in this file alone to our symbol.

@@ -14,20 +14,20 @@ internal sealed partial class SyntaxTreeIndex : AbstractSyntaxIndex<SyntaxTreeIn
private readonly LiteralInfo _literalInfo;
private readonly IdentifierInfo _identifierInfo;
private readonly ContextInfo _contextInfo;
private readonly HashSet<(string alias, string name, int arity)>? _globalAliasInfo;
private readonly HashSet<(string alias, string name, int arity, bool isGlobal)>? _aliasInfo;
Copy link
Member Author

Choose a reason for hiding this comment

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

both the global and local alias info is useful to store per file. So we keep them both, with a flag saying which type it is.

{
globalAliasInfo = [];
aliasInfo = [];
Copy link
Contributor

Choose a reason for hiding this comment

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

[];

nit: could specify size

Copy link
Contributor

@ToddGrun ToddGrun left a comment

Choose a reason for hiding this comment

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

:shipit:

@CyrusNajmabadi CyrusNajmabadi merged commit 9d5e375 into dotnet:main Jun 16, 2024
25 checks passed
@CyrusNajmabadi CyrusNajmabadi deleted the indices branch June 16, 2024 02:56
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Jun 16, 2024
@jjonescz jjonescz modified the milestones: Next, 17.11 P3 Jun 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants