Repository navigation
[Caching] Fix cross-file cache false negative - invalidate on ancestor change (#8493) - #8783
Closed
TomasVotruba wants to merge 2 commits into
Closed
TomasVotruba wants to merge 2 commits into
TomasVotruba wants to merge 2 commits into
Conversation
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 #8493.
A child class's refactoring result can depend on its parent/interface/trait (e.g.
AddReturnTypeDeclarationBasedOnParentClassMethodRector,ReturnTypeFromStrictTypedCallRector,AddOverrideAttributeToOverriddenMethodsRector). The cache keyed each file only by its own contents, so when an ancestor changed and the child did not, the child's entry still looked valid - it was skipped and the transformation it now needed was silently missed.Fix
FileDependencyResolverresolves the ancestry files (parents, interfaces, traits) a file relies on, via reflection. Best-effort: resolving ancestors can throw on malformed/unresolvable classes, and a miss there only skips a cache optimisation, so it is caught and ignored.ChangedFilesDetectoralso stores the content hash of each ancestry file under a separate key.hasFileChanged()reports the file as changed when its own hash matches but any stored ancestor hash no longer does (or the ancestor file disappeared).Scope
Covers class-ancestry dependencies, which are the cases reported in the issue. It does not track arbitrary cross-file dependencies (a called function's file, a referenced constant); that would need a full dependency graph and is out of scope here.
Tests
CacheFileDependencyTest- end-to-end: a cached child is reconsidered after its parent gains a return type.FileDependencyResolverTest- unit: the resolver returns the parent file, and nothing for an ancestor-less class.Note
Extra reflection + ancestor-hash work runs per clean cached file, so warm runs do slightly more work. Correctness-first; happy to run a full warm-run A/B against main if wanted before merge.