Skip to content

Preserve already resolved types after scope re-creation#4677

Closed
staabm wants to merge 10 commits intophpstan:2.1.xfrom
staabm:preserve
Closed

Preserve already resolved types after scope re-creation#4677
staabm wants to merge 10 commits intophpstan:2.1.xfrom
staabm:preserve

Conversation

@staabm
Copy link
Copy Markdown
Contributor

@staabm staabm commented Dec 28, 2025

implements the idea described in #4648 (comment)

requires #4676

Comment thread src/Analyser/MutatingScope.php Outdated
Comment on lines +4417 to +4418
foreach($preservedTypes as $exprStringToInvalidate => $resolvedType) {
foreach ($expressionTypes as $exprString => $exprTypeHolder) {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

we cannot use similar logic as in invalidateExpression because we don't know the Expr which $this->resolvedTypes was resolved with

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I have a commit that puts ExpressionTypeHolder into resolvedTypes, do you want it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Might help. Sure why not :-).

Will be afk for a few hours now

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I pushed it to 2.1.x. If it doesn't help you in the end, or if this PR does not lead to performance improvements, I'll revert it.

@staabm
Copy link
Copy Markdown
Contributor Author

staabm commented Dec 29, 2025

remaining problem is, that we need to forget resolved type of $a when scope specifies $a['bar'].
I remember we have such logic arround somewhere, but I am not able to find it atm

@staabm
Copy link
Copy Markdown
Contributor Author

staabm commented Jan 3, 2026

tried a few more things but did not find something measurably better than what we have atm

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.

2 participants