Sort transitive tips instead of ksorting a list - #426
Merged
janedbal merged 1 commit intoAug 28, 2026
Conversation
$tips is built with $tips[] = ..., so its keys are already 0..n-1 in ascending order and ksort() does nothing. The tip order therefore followed the insertion order of $usageGraph, which follows the order PHPStan hands over collected data - and that varies between parallel runs. On a large project two runs of the same code produced different tip order for the same error. The two grouping expectations that encoded the old order contained the same three members in two different orders, which is the same symptom. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01G7xhBWRXCTYyc336QVj13s
Member
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.
buildError()collects transitive tips into a list:Since
$tipsis appended to with$tips[], its keys are already0..n-1in ascending order, soksort()is a no-op. The tips are emitted in insertion order, which is the order ofgetTransitiveDeadCalls()→ the insertion order of$usageGraph→ the order PHPStan hands over collected data. That last one is not stable across parallel runs.I noticed this while profiling the extension on a ~16k-file codebase: two runs of identical code produced different tip order for the same error, so diffing analysis output between runs showed spurious changes.
The existing test expectations show the same thing —
Grouping\Example::booandGrouping\Example::foohave the same three transitively dead members, but the fixture encoded them in two different orders:sort($tips)gives the deterministic order theksort()call was clearly reaching for. I updated the three affected expectations; the full suite passes (858 tests), as dophpstanandphpcs.I also opened phpstan/phpstan#15126 asking for a rule that reports
ksort()on a list, since PHPStan already reports the analogousarray_values()on a list and would have caught this.