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

Avoid producing compilations in Add-Import when we can prove there are no results in that project. #65655

Merged
merged 6 commits into from
Nov 29, 2022

Conversation

CyrusNajmabadi
Copy link
Member

No description provided.

symbolsWithName = symbolsWithName.Select(s => s.GetSymbolKey(cancellationToken).Resolve(startingCompilation, cancellationToken: cancellationToken).Symbol)
.WhereNotNull()
.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.

moved this logic to the caller.

list.AddRange(FilterByCriteria(symbolsWithName, filter));
}
}

private static async Task AddMetadataDeclarationsWithNormalQueryAsync(
Project project,
IAssemblySymbol assembly,
PortableExecutableReference? reference,
AsyncLazy<IAssemblySymbol?> lazyAssembly,
Copy link
Member Author

Choose a reason for hiding this comment

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

changed to lazyAssembly. Avoids creation compilation when no results are found.

// get declarations from directly referenced projects and metadata
foreach (var assembly in compilation.GetReferencedAssemblySymbols())
// get declarations from directly referenced projects
foreach (var projectReference in project.ProjectReferences)
Copy link
Member Author

Choose a reason for hiding this comment

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

instead of walking GetReferencedAssemblySymbols (which needs both a compilation, and creates assembly symbols for all references), we can instead just manually walk project-references and metadtareferences, search each (using indices) And only realize the compilation if we find a match.

@@ -206,6 +206,9 @@ public SymbolTreeInfo WithChecksum(Checksum checksum)
if (ignoreCase || StringComparer.Ordinal.Equals(name, node.Name))
{
assemblySymbol ??= await lazyAssembly.GetValueAsync(cancellationToken).ConfigureAwait(false);
if (assemblySymbol is null)
Copy link
Member

Choose a reason for hiding this comment

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

❔ Where's the source of this null value?

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 are delaying getting the IAssemblySymbol for a particular PE reference, but the compiler does'nt guarantee all pe-references will produce an IAssemblySymbol.

using var _ = ArrayBuilder<ISymbol>.GetInstance(out var buffer);

var referencedProject = project.Solution.GetProject(projectReference.ProjectId);
if (referencedProject is null)
Copy link
Member

Choose a reason for hiding this comment

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

is this true when you have a ProjectReference item in the csproj but no project exists on disk for example?

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah, i think jason has said this can occur.

@CyrusNajmabadi CyrusNajmabadi merged commit 2c896d2 into dotnet:main Nov 29, 2022
@ghost ghost added this to the Next milestone Nov 29, 2022
@allisonchou allisonchou modified the milestones: Next, 17.5 P2 Nov 30, 2022
@CyrusNajmabadi CyrusNajmabadi deleted the addUsing branch November 30, 2022 17:29
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.

4 participants