Make ReusesCachedOutputOnRerun detect a non-incremental generator - #22
Merged
matt-edmondson merged 1 commit intoSep 26, 2026
Merged
Conversation
The check reran the driver against the same Compilation instance. Roslyn compares incremental inputs by reference, so every step came back Cached and the check passed for any generator, including one that recomputes on every keystroke. The second run now gets a new but equivalent compilation, which is what an edit hands a generator. A generator with no tracked output steps now reports false instead of passing by default. Downstream tests that call this check may now fail. Each such failure is a generator that really was not incremental. Fixes #19 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019StKk4VdpfAZ5cdW5X685e
|
matt-edmondson
deleted the
fix/incremental-check-uses-fresh-compilation
branch
September 26, 2026 11:49
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Fixes #19
What was wrong
GeneratorHarness.ReusesCachedOutputOnRerunran the driver twice against the sameCSharpCompilationinstance. Roslyn compares incremental inputs by reference, so every step,CompilationProviderincluded, came backCached/Unchanged, and the check returnedtruefor any generator. A generator that recomputes on every keystroke passed. That also meantTheGeneratorReusesItsOutputWhenNothingChangedproved nothing.Change
compilation.AddSyntaxTrees(CSharpSyntaxTree.ParseText(string.Empty)). That is a new, semantically equivalentCompilation, which is what an edit hands a generator.falseinstead of passing by default.Design note: the
AdditionalTextinstances are kept, not rebuilt. The issue listed rebuilding them as optional. On a keystroke the IDE keeps the same instances for unchanged additional files, so reusing them models the scenario the check is for. Rebuilding them would be stricter than the IDE. It would also failGeneratorBaseitself, becauseMetadataFilehas reference equality, and that is a separate question from this bug.Release note: downstream tests that call this check may now fail. Each such failure is a generator that really was not incremental, as the triage comment anticipated.
Tests
TheRerunCheckCatchesAGeneratorThatRecomputesOnEveryEdit: theCompilationProvider.Select(_ => new object())generator from the issue must fail the check.TheRerunCheckDoesNotPassAGeneratorWithNoOutputStepsThingsGenerator) still passes under the stricter check, so it now proves something.This PR is independent of #21 (duplicate diagnostic numbers); the two merge cleanly in either order.
🤖 Generated with Claude Code
https://claude.ai/code/session_019StKk4VdpfAZ5cdW5X685e
Generated by Claude Code