Skip to content
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

Improve expression resolving of superglobals #2012

Merged

Conversation

herndlm
Copy link
Contributor

@herndlm herndlm commented Nov 19, 2022

Handles superglobals as any other expressions, which fixes narrowing them.

Closes phpstan/phpstan#5805 (which I was totally not expecting, most likely unlocked also by recent changes from @rajyan) nope, not anymore, this was fixed in #2030, I do understand that this change then is only improving things if people use superglobal expressions to narrow types, which might not be the case often in modern apps. Therefore I also get it if this is not wanted in the scope :)

The superglobals creation is most likely also a good integration point for phpstan/phpstan#8037

@herndlm herndlm marked this pull request as draft November 19, 2022 20:40
@herndlm herndlm force-pushed the improve-superglobal-expression-resolving branch 4 times, most recently from c3dd5c1 to b54aeb7 Compare November 20, 2022 01:00
@herndlm
Copy link
Contributor Author

herndlm commented Nov 20, 2022

Still not a 100% happy with how the superglobals are created and set, but at least it seems to be working fine now.

@herndlm herndlm force-pushed the improve-superglobal-expression-resolving branch from b54aeb7 to 98f40eb Compare November 20, 2022 01:39
@herndlm herndlm marked this pull request as ready for review November 20, 2022 02:04
@phpstan-bot
Copy link
Collaborator

This pull request has been marked as ready for review.

@herndlm herndlm force-pushed the improve-superglobal-expression-resolving branch from 98f40eb to d784b9b Compare November 20, 2022 08:07
@herndlm herndlm force-pushed the improve-superglobal-expression-resolving branch 4 times, most recently from ac80adc to 8ba50ff Compare November 20, 2022 20:19
@herndlm herndlm marked this pull request as draft November 20, 2022 20:29
@herndlm herndlm force-pushed the improve-superglobal-expression-resolving branch 2 times, most recently from 8c5fe5c to 77f6465 Compare November 20, 2022 20:42
@herndlm herndlm marked this pull request as ready for review November 20, 2022 20:42
@phpstan-bot
Copy link
Collaborator

This pull request has been marked as ready for review.

@herndlm herndlm force-pushed the improve-superglobal-expression-resolving branch from 77f6465 to e3a8fcb Compare November 20, 2022 21:10
@herndlm herndlm marked this pull request as draft November 21, 2022 08:31
@herndlm herndlm force-pushed the improve-superglobal-expression-resolving branch from e3a8fcb to 51ddfcc Compare November 24, 2022 16:36
@herndlm herndlm marked this pull request as ready for review November 24, 2022 16:45
@phpstan-bot
Copy link
Collaborator

This pull request has been marked as ready for review.

@herndlm herndlm force-pushed the improve-superglobal-expression-resolving branch from 51ddfcc to 5c856d7 Compare December 2, 2022 10:18
@herndlm
Copy link
Contributor Author

herndlm commented Dec 2, 2022

rector error again WHY? I only rebased on 1.9.x and removed a commit that added a test which is not needed anymore... :/
update: looks like I could "fix" it by removing phpdoc from the scope factory classes that is already on the interface. very weird

@herndlm herndlm force-pushed the improve-superglobal-expression-resolving branch 5 times, most recently from 3562d82 to cb75108 Compare December 8, 2022 09:13
@herndlm herndlm force-pushed the improve-superglobal-expression-resolving branch from cb75108 to e541807 Compare December 11, 2022 21:26
@ondrejmirtes ondrejmirtes merged commit 6dcbf38 into phpstan:1.9.x Jan 8, 2023
@ondrejmirtes
Copy link
Member

Thank you!

@herndlm
Copy link
Contributor Author

herndlm commented Jan 8, 2023

On, tbh I didn't expect that this one would be merged without changes 😊 I think I duplicated the list of superglobals somewhere. Are you fine with that or should I put it somewhere central? Maybe I didn't because it would have needed a public static method or so and felt weird 🤔

@ondrejmirtes
Copy link
Member

When you open a pull request, there's always a risk I'm gonna merge it :) Feel free to improve your code in follow-up PRs.

@herndlm
Copy link
Contributor Author

herndlm commented Jan 8, 2023

Saw that it was in MutatingScope, but I believe that it's fine to not deduplicate it. So, nevermind and sorry for the noise

@herndlm herndlm deleted the improve-superglobal-expression-resolving branch January 8, 2023 20:34
@ondrejmirtes
Copy link
Member

Sadly I have to revert this because of performance reasons. Blackfire comparison on top of 1.10.x-dev: https://blackfire.io/profiles/compare/21309b29-d2de-4f60-b6fe-1873b47e31b4/graph

@herndlm
Copy link
Contributor Author

herndlm commented Jan 13, 2023

oh that's unfortunate. just for my understanding - how did you find out that it was this commit that caused it in the performance graph? or was it just a lucky guess?

@ondrejmirtes
Copy link
Member

Yesterday I saw a million calls to ArrayType::equals() which looked weird to me. Today I looked at recent releases and started git bisect, and the results made my suspicion obvious 😊

@staabm
Copy link
Contributor

staabm commented Jan 14, 2023

Blackfire comparison on top of 1.10.x-dev

is this a blackfire run over php bin/phpstan -vvv --debug - or some other script ?
I want to reproduce and fiddle a bit with this PRs impl

@ondrejmirtes
Copy link
Member

Yes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants