Repository navigation
Re-resolve ShortNameResolver short names on stmts change - #8697
Merged
Merged
Conversation
TomasVotruba
marked this pull request as ready for review
October 17, 2026 20:15
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.
What
ShortNameResolver::resolveFromFile()cached its short-name-to-FQN map by file path and never invalidated it. Across the file-processing convergence loop the stmts change between iterations, so later iterations read a stale map - a correctness bug - and the map for every processed file was retained for the whole run.Change
resolveFromFile()now caches by file identity +getNewStmtsVersion()and re-resolves when the stmts version bumps - the same patternresolveShortClassLikeNames()already uses in this class. The per-file-path array is dropped, so only the current file's map is held.Proof the bug is real
ShortNameResolverTest::testResolveFromFileAgainAfterStmtsChangeresolves a file, renames its class, bumps the stmts version, and resolves again. It mirrors the existingtestResolveShortClassLikeNamesAgainAfterStmtsChangeguard for the sibling method.Failed asserting that an array does not have the key 'VariousImports'(stale map returned after the change)Tradeoff - correctness + memory, costs some CPU
Measured with
bench/short_name_resolver_bench.php(8 convergence passes, 400 node queries each, 25 repeats):The old cache ignored version bumps, so convergence passes were free; the new one re-resolves per version (~2x cpu on the multi-version pattern). The cost only hits files that actually change across iterations, scaling with iteration count. In return the short-name map is correct on every iteration and only one file's map is held at a time.
Tests
148 import tests green, plus the new regression test. ECS + full PHPStan clean. Benchmark lives in
bench/(not scanned by ECS/PHPStan/Rector).