Skip to content

Conversation

@staabm
Copy link
Contributor

@staabm staabm commented Jan 3, 2026

prevents unnecessary work when e.g. assigning variables to non-falsy values.

to my suprise this hardly has an influence on performance, even though I can see if ($truthyType !== $type) { is not always true.

@staabm staabm marked this pull request as ready for review January 3, 2026 20:34
@phpstan-bot
Copy link
Collaborator

This pull request has been marked as ready for review.

$conditionalExpressions = $this->processSureTypesForConditionalExpressionsAfterAssign($scope, $var->name, $conditionalExpressions, $falseySpecifiedTypes, $falseyType);
$conditionalExpressions = $this->processSureNotTypesForConditionalExpressionsAfterAssign($scope, $var->name, $conditionalExpressions, $falseySpecifiedTypes, $falseyType);

if ($truthyType !== $type) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when $truthyType = TypeCombinator::removeFalsey($type); returns $truthyType === $type, this means TypeCombinator::intersect($type, StaticTypeFactory::falsey()) will always be a NeverType.

Copy link
Contributor Author

@staabm staabm Jan 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

blackfire reports 10.000 less invocations of TypeCombinator::intersect with this PR in comparison to 2.1.x@c53546e53a on bin/phpstan analyse src/Analyser/ src/Rules/ -v --debug

@ondrejmirtes ondrejmirtes merged commit fd1ef14 into phpstan:2.1.x Jan 3, 2026
630 of 644 checks passed
@ondrejmirtes
Copy link
Member

Very very nice! Looking forward to what you find next :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants