Repository navigation
Keep a merged call whose uninformative check leads back to itself - #7088
Merged
Merged
Conversation
Since bcca2b0, a merge drops a remembered call whose merged type is what the call resolves to on its own. Resolving the call processes its arguments again, and a ternary among them merges its own branches. When conditional expressions tie the call's type to the ternary's condition, as after `$s = strlen($s ?: '') ?: 0;`, that merge finds the same call differing between the branches and resolves it again, without end, until the memory limit is hit. A check that leads back to a call whose check is in progress now keeps the merged entry, as every merge did before bcca2b0. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
staabm
approved these changes
Nov 16, 2026
Contributor
|
//cc @SanderMuller |
VincentLanglet
approved these changes
Nov 16, 2026
SanderMuller
approved these changes
Nov 16, 2026
SanderMuller
left a comment
Contributor
There was a problem hiding this comment.
I checked this locally against the merge base 02480d8, with and without the Turbo extension.
- The snippet from phpstan/phpstan#15754 runs out of a 1 GB memory limit after 53 seconds on the base. On this PR it finishes in 3 seconds, without errors at level max. With the extension loaded, it also finishes.
- The new test hangs when I take
MutatingScope.phpfrom the base (killed after 180 seconds). With the extension loaded, it also hangs when onlyMutatingScope.cppand its generated header come from the base (killed after 120 seconds). So both guards are needed. - I tried 9 variants of the pattern. They cover
count(),trim()andpreg_split()in the call, a nested?:, a narrowedcount()like in bug-13750, and the assignment twice. The dumped types are the same as on the 2.3.5 PHAR, and the same as on the base where the base finishes. Only the assignment twice hangs on the base. - With the assignment repeated 1 to 16 times in one function, analysis takes 0.86 to 0.96 seconds on this PR. The base does not finish any of them within 30 seconds.
tests/PHPStan/Analyserpasses, with and without the extension (3,430 tests). The Turbo smoke test,bin/side-by-side.phpand the signature parity check pass on a local build.- Performance: I counted
AnalysisBenchand theMutatingScope*Benchcases (145) with Tally, base against this PR. The instruction count does not change by more than 0.084 % in any case (median 0), and memory changes by at most 0.001 %.
The two red jobs (phpstan-dba and phpstan-laravel tests) also fail on #7090 and #7093. They come from the type changes in 2.3.6: see staabm/phpstan-dba#830 and calebdw/phpstan-laravel#55.
I did not run the full make tests, make phpstan or the walk trace locally. CI covers the first two, and they are green.
Contributor
|
thank you! |
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.
Closes phpstan/phpstan#15754
Since bcca2b0 (#6953), merging two scopes checks whether a remembered call's merged type is what the call resolves to on its own (
findUninformativeMergedCalls()). Resolving the call processes its arguments again. After$s = strlen($s ?: '') ?: 0;, conditional expressions tiestrlen($s ?: '')to$s, so merging the branches of the inner$s ?: ''finds the same call differing between them and resolves it again. That repeats until the memory limit is hit.This happens both in the regular walk (when the assignment is repeated) and when a rule asks for the statement's type at execution end, as
ParameterOutExecutionEndTypeRuledoes for the single assignment in the issue.Now, when a check leads back to a call whose own check is still in progress, it keeps the merged entry instead, as every merge did before bcca2b0. The C++ twin uses the same static property as the guard.
Without the fix, the regression test runs out of memory. That's true without the extension, and with the extension built with only the C++ change reverted.
Verified with:
tests/PHPStan/Analyserwith the extension activeMutatingScope.phpturbo-ext/bin/side-by-side.php