-
Notifications
You must be signed in to change notification settings - Fork 506
Faster processing of array comparisons with constant offsets #3933
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This pull request has been marked as ready for review. |
@@ -4428,6 +4428,10 @@ public function addTypeToExpression(Expr $expr, Type $type): self | |||
|
|||
if ($originalExprType->equals($nativeType)) { | |||
$newType = TypeCombinator::intersect($type, $originalExprType); | |||
if ($newType->isConstantScalarValue()->yes() && $newType->equals($originalExprType)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't get it, why only for $newType->isConstantScalarValue()->yes()
?
And: can we make it faster for the other return
in this method too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't get it, why only for
$newType->isConstantScalarValue()->yes()
?
I went with constant scalars as these matched best the slow case at hand
additionally there are types with weird equals-semantics like ...
$mixed->equals($error)
=>true
(becauseErrorType extends MixedType
)- ObjectType
... for which tests start failing if we take the fast-pass without changing the scope
And: can we make it faster for the other return in this method too?
I can't think of a case where this would help
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These equals
problems should be fixed, they might lead to other bugfixes as well.
Thank you! |
step debugging thru the example made me realize that most of the time we were adding the same constant types to the scope again. This PR detects this situation and does a fast exit to prevent unnecessary scope creations.
before this PR
after this PR
closes phpstan/phpstan#12800