Skip to content

Conversation

@staabm
Copy link
Contributor

@staabm staabm commented Jan 9, 2026

before this PR we read/ast-traversed every stub file only until we found the single symbol we were searching for.
after something was found, traversal stopped and we returned early.

this means we e.g. see the same file beeing read/php-parsed/ast-traversed from the filesystem multiple times, when e.g. multiple constants of the same class are unkown or a mix of constants and methods are unknown.

see a phpstan-doctrine example run:

phar:///Users/staabm/workspace/phpstan-doctrine/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/SignatureMap/../../../vendor/phpstan/php-8-stubs/stubs/ext/pdo/PDO.stub
phar:///Users/staabm/workspace/phpstan-doctrine/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/SignatureMap/../../../vendor/phpstan/php-8-stubs/stubs/ext/pdo/PDO.stub
phar:///Users/staabm/workspace/phpstan-doctrine/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/SignatureMap/../../../vendor/phpstan/php-8-stubs/stubs/ext/pdo/PDO.stub
phar:///Users/staabm/workspace/phpstan-doctrine/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/SignatureMap/../../../vendor/phpstan/php-8-stubs/stubs/ext/pdo/PDO.stub
phar:///Users/staabm/workspace/phpstan-doctrine/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/SignatureMap/../../../vendor/phpstan/php-8-stubs/stubs/ext/pdo/PDO.stub

after this PR we remember all contained symbols within a stub file on the first read/parse/ast-traversal.
when later requested we can easily lookup whether a stub for a given method or constant exists, without the need to read/parse the stub file over and overr again.

@staabm staabm changed the title Find all constant types at once Find all constant/method types at once Jan 9, 2026
…ols not applicable for the current php version
@staabm staabm changed the title Find all constant/method types at once Find all constant/method types per class at once Jan 9, 2026
@staabm staabm marked this pull request as ready for review January 9, 2026 08:05
@phpstan-bot
Copy link
Collaborator

This pull request has been marked as ready for review.

@staabm
Copy link
Contributor Author

staabm commented Jan 9, 2026

hmm maybe this caching should happen in FileNodesFetcher instead, so all consumers will benefit from it.
will give it a try

@ondrejmirtes
Copy link
Member

No, I don't think so. Please wait until I look at the code.


/** @var array<string, array<string, Type|null>> */
/** @var array<lowercase-string, array<lowercase-string, array{ClassMethod, string}>> */
private array $stubbedMethodNodes = [];
Copy link
Member

Choose a reason for hiding this comment

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

I don't follow, what's the difference between methodNodes and stubbedMethodNodes?

I'm probably slower than usual, you know, Friday morning, heavy snowing outside etc. 😊

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had the impression based on the previous implementation that we should only remember the requested types.

but it seems thats not the case. simplified it now

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