-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Move source-generators out of ProjectState and entirely into SolutinoCompilationState #72834
Conversation
} | ||
} | ||
|
||
public IEnumerable<ISourceGenerator> SourceGenerators |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this was too broad a surface area. we def did not want to expose inside the workspace that you could get to ISourceGenerator instances.
@@ -422,7 +422,7 @@ async Task<InProgressState> CollapseInProgressStateAsync(InProgressState initial | |||
// Also transform the compilation that has generated files; we won't do that though if the transformation either would cause problems with | |||
// the generated documents, or if don't have any source generators in the first place. | |||
if (translationAction.CanUpdateCompilationWithStaleGeneratedTreesIfGeneratorsGiveSameOutput && | |||
translationAction.OldProjectState.SourceGenerators.Any()) | |||
GetSourceGenerators(translationAction.OldProjectState).Any()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: this needs to not instantiate generators, but instead call into OOP to determine this info.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Considering that the SDK delivers source generators that are enabled by default, it might make sense to just assume the .Any()
is true and focus on optimizing the specific case where none of the source generators adds any documents to the compilation.
@@ -774,7 +774,7 @@ public ICompilationTracker FreezePartialState(CancellationToken cancellationToke | |||
SolutionCompilationState compilationState, CancellationToken cancellationToken) | |||
{ | |||
// If we don't have any generators, then we know we have no generated files, so we can skip the computation entirely. | |||
if (!this.ProjectState.SourceGenerators.Any()) | |||
if (!GetSourceGenerators(this.ProjectState).Any()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same.
@@ -787,7 +787,7 @@ public ICompilationTracker FreezePartialState(CancellationToken cancellationToke | |||
public async ValueTask<ImmutableArray<Diagnostic>> GetSourceGeneratorDiagnosticsAsync( | |||
SolutionCompilationState compilationState, CancellationToken cancellationToken) | |||
{ | |||
if (!this.ProjectState.SourceGenerators.Any()) | |||
if (!GetSourceGenerators(this.ProjectState).Any()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
@@ -816,7 +816,7 @@ public ICompilationTracker FreezePartialState(CancellationToken cancellationToke | |||
|
|||
public async ValueTask<GeneratorDriverRunResult?> GetSourceGeneratorRunResultAsync(SolutionCompilationState compilationState, CancellationToken cancellationToken) | |||
{ | |||
if (!this.ProjectState.SourceGenerators.Any()) | |||
if (!GetSourceGenerators(this.ProjectState).Any()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same.
@@ -233,7 +233,7 @@ private partial class CompilationTracker : ICompilationTracker | |||
// the "InCurrentProcess" call so that it will normally run only in the OOP process, thus ensuring that we | |||
// get accurate information about what SourceGenerators we actually have (say, in case they they are rebuilt | |||
// by the user while VS is running). | |||
if (!this.ProjectState.SourceGenerators.Any()) | |||
if (!GetSourceGenerators(this.ProjectState).Any()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this call is fine. We're already in OOP.
@@ -293,7 +295,7 @@ private partial class CompilationTracker : ICompilationTracker | |||
if (IsGeneratorRunResultToIgnore(generatorResult)) | |||
continue; | |||
|
|||
var generatorAnalyzerReference = this.ProjectState.GetAnalyzerReferenceForGenerator(generatorResult.Generator); | |||
var generatorAnalyzerReference = GetAnalyzerReference(this.ProjectState, generatorResult.Generator); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this call is fine. We're already in OOP.
@@ -394,7 +396,7 @@ static GeneratorDriver CreateGeneratorDriver(ProjectState projectState) | |||
|
|||
return compilationFactory.CreateGeneratorDriver( | |||
projectState.ParseOptions!, | |||
projectState.SourceGenerators.ToImmutableArray(), | |||
GetSourceGenerators(projectState), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this call is fine. We're already in OOP.
@@ -355,7 +355,7 @@ public override GeneratorDriver TransformGeneratorDriver(GeneratorDriver _) | |||
.ReplaceAdditionalTexts(this.NewProjectState.AdditionalDocumentStates.SelectAsArray(static documentState => documentState.AdditionalText)) | |||
.WithUpdatedParseOptions(this.NewProjectState.ParseOptions!) | |||
.WithUpdatedAnalyzerConfigOptions(this.NewProjectState.AnalyzerOptions.AnalyzerConfigOptionsProvider) | |||
.ReplaceGenerators(this.NewProjectState.SourceGenerators.ToImmutableArray()); | |||
.ReplaceGenerators(GetSourceGenerators(this.NewProjectState)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this need to not happen on the VS side.
@ToddGrun ptal :-) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall seems acceptable. Would like the perf question answered before proceeding.
src/Workspaces/Core/Portable/Workspace/Solution/SolutionCompilationState_SourceGenerators.cs
Show resolved
Hide resolved
src/Workspaces/Core/Portable/Workspace/Solution/SolutionCompilationState_SourceGenerators.cs
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jasonmalinowski For review when you get back. |
This will help us control the lifetimes of these objects. The goal here is to only instantiate them on the OOP side. That way we don't have any issues where we create and cache the generators once on the VS side. In VS we can't reload them as we're netfx. Isolating the places where we access the generators means we can always defer to OOP to do anything we need in this regard.
This PR is just about isolating. Next will be actually moving the in proc calls to not instantiate the generators.