Source generators/fix exception latching#59930
Conversation
- Remove unsused info - Ensure we don't drop init info between results + errors - Don't run if we have no output nodes
|
@dotnet/roslyn-compiler for review please :) |
| } | ||
| } | ||
|
|
||
| internal class CallbackHolder |
There was a problem hiding this comment.
The struct get passed to ISourceGenerator.Initialize where the generator then calls the set methods. Previously we had a builder type that held onto them, but given that that's no longer used I just moved them here. Its ugly but its just for back compat.
src/Compilers/Core/Portable/SourceGeneration/GeneratorContexts.cs
Outdated
Show resolved
Hide resolved
| ? new GeneratorState(generatorState.Info, postInitSources, inputNodes, outputNodes) | ||
| : SetGeneratorException(MessageProvider, generatorState, sourceGenerator, ex, diagnosticsBag, isInit: true); | ||
| ? new GeneratorState(postInitSources, inputNodes, outputNodes) | ||
| : SetGeneratorException(MessageProvider, GeneratorState.Empty, sourceGenerator, ex, diagnosticsBag, isInit: true); |
There was a problem hiding this comment.
Yes. If the initialization fails there is no state, and we don't want to try and do anything with it in the future.
| { | ||
| var generatorState = stateBuilder[i]; | ||
| if (generatorState.Exception is object) | ||
| if (generatorState.OutputNodes.Length == 0) |
There was a problem hiding this comment.
Yes. That then led me to discover we were throwing away initialization state when we set the exception. It didn't matter before because we never recovered, but we now need to handle it correctly.
|
@dotnet/roslyn-compiler for reviews please :) |
|
ping @dotnet/roslyn-compiler for a second review. |
Fixes #58625
We were incorrectly skipping generators when they had an assigned exception, meaning they would never recover once one occurred. After switching the logic it became clear that we were incorrectly losing initialization state (that wasn't exposed because we never recovered), which is fixed by altering the way we store state. I also cleaned up the unused
GeneratorInfothat was left over from V1.