-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Fix post init trees parsing when parse options change #61934
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,7 +37,7 @@ internal GeneratorDriver(GeneratorDriverState state) | |
| internal GeneratorDriver(ParseOptions parseOptions, ImmutableArray<ISourceGenerator> generators, AnalyzerConfigOptionsProvider optionsProvider, ImmutableArray<AdditionalText> additionalTexts, GeneratorDriverOptions driverOptions) | ||
| { | ||
| var incrementalGenerators = GetIncrementalGenerators(generators, SourceExtension); | ||
| _state = new GeneratorDriverState(parseOptions, optionsProvider, generators, incrementalGenerators, additionalTexts, ImmutableArray.Create(new GeneratorState[generators.Length]), DriverStateTable.Empty, SyntaxStore.Empty, driverOptions.DisabledOutputs, runtime: TimeSpan.Zero, driverOptions.TrackIncrementalGeneratorSteps); | ||
| _state = new GeneratorDriverState(parseOptions, optionsProvider, generators, incrementalGenerators, additionalTexts, ImmutableArray.Create(new GeneratorState[generators.Length]), DriverStateTable.Empty, SyntaxStore.Empty, driverOptions.DisabledOutputs, runtime: TimeSpan.Zero, driverOptions.TrackIncrementalGeneratorSteps, parseOptionsChanged: true); | ||
| } | ||
|
|
||
| public GeneratorDriver RunGenerators(Compilation compilation, CancellationToken cancellationToken = default) | ||
|
|
@@ -145,7 +145,7 @@ public GeneratorDriver ReplaceAdditionalText(AdditionalText oldText, AdditionalT | |
| public GeneratorDriver ReplaceAdditionalTexts(ImmutableArray<AdditionalText> newTexts) => FromState(_state.With(additionalTexts: newTexts)); | ||
|
|
||
| public GeneratorDriver WithUpdatedParseOptions(ParseOptions newOptions) => newOptions is object | ||
| ? FromState(_state.With(parseOptions: newOptions)) | ||
| ? FromState(_state.With(parseOptions: newOptions, parseOptionsChanged: true)) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I may have to implement equality checking in #62219 to make that approach work there, so if we don't do it here this may not last long. I have new bits to test that PR with so will hopefully know soon enough if it works or needs that change.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could, but re-parsing the init trees is cheap, and doesn't happen often enough that it'll be an issue. I think we should not block on this here, and can always improve it at a later date if we need to. |
||
| : throw new ArgumentNullException(nameof(newOptions)); | ||
|
|
||
| public GeneratorDriver WithUpdatedAnalyzerConfigOptions(AnalyzerConfigOptionsProvider newOptions) => newOptions is object | ||
|
|
@@ -248,6 +248,12 @@ internal GeneratorDriverState RunGeneratorsCore(Compilation compilation, Diagnos | |
| ? new GeneratorState(postInitSources, inputNodes, outputNodes) | ||
| : SetGeneratorException(MessageProvider, GeneratorState.Empty, sourceGenerator, ex, diagnosticsBag, isInit: true); | ||
| } | ||
| else if (state.ParseOptionsChanged && generatorState.PostInitTrees.Length > 0) | ||
| { | ||
| // the generator is initalized, but we need to reparse the post-init trees as the parse options have changed | ||
| var reparsedInitSources = ParseAdditionalSources(sourceGenerator, generatorState.PostInitTrees.SelectAsArray(t => new GeneratedSourceText(t.HintName, t.Text)), cancellationToken); | ||
| generatorState = new GeneratorState(reparsedInitSources, generatorState.InputNodes, generatorState.OutputNodes); | ||
| } | ||
|
|
||
| // if the pipeline registered any syntax input nodes, record them | ||
| if (!generatorState.InputNodes.IsEmpty) | ||
|
|
@@ -298,7 +304,7 @@ internal GeneratorDriverState RunGeneratorsCore(Compilation compilation, Diagnos | |
| } | ||
| } | ||
|
|
||
| state = state.With(stateTable: driverStateBuilder.ToImmutable(), syntaxStore: syntaxStoreBuilder.ToImmutable(), generatorStates: stateBuilder.ToImmutableAndFree(), runTime: timer.Elapsed); | ||
| state = state.With(stateTable: driverStateBuilder.ToImmutable(), syntaxStore: syntaxStoreBuilder.ToImmutable(), generatorStates: stateBuilder.ToImmutableAndFree(), runTime: timer.Elapsed, parseOptionsChanged: false); | ||
| return state; | ||
| } | ||
|
|
||
|
|
||
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.
There should be diagnostics at this stage though because the language version is csharp 1. Believe we should validate these diagonstics show up here, likely by just grabbing the diagnostics off the syntax tree in the compilation.
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.
These are the generator diagnostics. I'll add a check for the compilation.