Skip to content

Stop loading ISourceGenerators within VS entirely.#72835

Merged
CyrusNajmabadi merged 17 commits intodotnet:mainfrom
CyrusNajmabadi:sgOnlyOop3
Apr 2, 2024
Merged

Stop loading ISourceGenerators within VS entirely.#72835
CyrusNajmabadi merged 17 commits intodotnet:mainfrom
CyrusNajmabadi:sgOnlyOop3

Conversation

@CyrusNajmabadi
Copy link
Contributor

No description provided.

@ghost ghost added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Apr 2, 2024
@CyrusNajmabadi CyrusNajmabadi changed the title WIP: SG oop part 3. Stop loading ISourceGenerators within VS entirely. Apr 2, 2024
@CyrusNajmabadi CyrusNajmabadi marked this pull request as ready for review April 2, 2024 20:11
@CyrusNajmabadi CyrusNajmabadi requested a review from a team as a code owner April 2, 2024 20:11
@CyrusNajmabadi CyrusNajmabadi requested a review from ToddGrun April 2, 2024 20:11
{
using var connection = CreateConnection<TService>(callbackTarget: null);
return await connection.TryInvokeAsync(compilationState, projectId, invocation, cancellationToken).ConfigureAwait(false);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

helper overload for the case where we're asking about a particular project in the context of a particular SolutionCompilationState (first time we've needed to do that).

/// Whether or not the specified <paramref name="projectId"/> has source generators or not.
/// </summary>
ValueTask<bool> HasGeneratorsAsync(
Checksum solutionChecksum, ProjectId projectId, CancellationToken cancellationToken);
Copy link
Contributor Author

@CyrusNajmabadi CyrusNajmabadi Apr 2, 2024

Choose a reason for hiding this comment

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

Pretty self-explanatory.

{
using var generators = TemporaryArray<ISourceGenerator>.Empty;
var generatorToAnalyzerReference = ImmutableDictionary.CreateBuilder<ISourceGenerator, AnalyzerReference>();
private static readonly ConditionalWeakTable<ProjectState, SourceGeneratorMap> s_projectStateToSourceGeneratorsMap = new();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this was a simpler way to organize the existing information. ProjectState already has the language and analyzerreferences. It's also what callers already pass in. And it's a green node which rarely changes. Note: if it does change, we'll 'recompute' the SGs, but end up finding the same set, since the AnalyzerRef objects themselves cache and return the same instances.

/// process (if present) and having it make the determination, without the host necessarily loading generators
/// itself.
/// </summary>
private static readonly ConditionalWeakTable<ProjectState, AsyncLazy<bool>> s_hasSourceGeneratorsMap = new();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

new to this PR.

/// process (if present) and having it make the determination, without the host necessarily loading generators
/// itself.
/// </summary>
private static readonly ConditionalWeakTable<ProjectState, AsyncLazy<bool>> s_hasSourceGeneratorsMap = new();
Copy link
Contributor

Choose a reason for hiding this comment

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

ConditionalWeakTable

Would it be possible to only have a single CWT and only access the SourceGeneratorMap part of the tuple when OOP?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

tried, but it started getting very ugly/allocy

@CyrusNajmabadi CyrusNajmabadi requested a review from ToddGrun April 2, 2024 21:32
@CyrusNajmabadi
Copy link
Contributor Author

@jasonmalinowski For review when you get back.

@dibarbet dibarbet modified the milestones: Next, 17.11 P1 Apr 29, 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