Repository navigation
Price op-assigns as binary ops when deriving conditional expressions - #6777
Merged
Merged
Conversation
Propagating conditional expressions through `$var op= value` re-priced the AssignOp itself under every evaluated holder. That walks the write again, which derives conditional expressions again on the evaluation scope - nested, so analysis time grew exponentially with the number of conditionally described variables the right-hand side reads (several int|float accumulators concatenated with .= in a loop). The value the op-assign writes is `$var op value`, so the equivalent BinaryOp is priced instead, without the write. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L1wYnCXeqv8tgY2Eq1UuZA
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#15498
Propagating conditional expressions through
$var op= value(AssignHandler::processDerivedConditionalExpressionsAfterAssign) re-priced the AssignOp itself under every evaluated holder. On 2.3.x that is an on-demand walk of the whole op-assign including its write, which derives conditional expressions again on the evaluation scope — nested, so time grew exponentially with the number of conditionally described variables the right-hand side reads. 2.2.x only asked for the type.The value an op-assign writes is
$var op value, so the equivalent BinaryOp is priced instead. Inferred types are unchanged; the PHP twin and the turbo mirror carry the same change (walk-trace identical).Reproducer from the issue (added as
tests/bench/data/bug-15498.php), user CPU,-l 8 --debug, empty file ≈ 0.8 s:tests/PHPStan/Analyser/nsrt/bug-15498.phppins derived narrowing through.=,+=and??=plus the reproducer's types.🤖 Generated with Claude Code
https://claude.ai/code/session_01L1wYnCXeqv8tgY2Eq1UuZA