Don't reuse cleaned ASTs for analysed files - #6310
Conversation
|
Please reproduce the problem as well with e2e test. With what kind of extension this happens? |
The parser route for a file can change after the analysed file list is installed. Track whether source-keyed entries contain the richest file representation so a cleaned entry is reparsed when the route changes, while preserving cached node identity for repeated simple parses. Add unit coverage for both early cache paths and an end-to-end fixture where an eagerly created extension reflects an analysed class.
1a0db04 to
1cd9747
Compare
|
This can happen with extensions from the collections PHPStan loads while creating I've added a minimal e2e case using a |
|
Doing work in constructor is a bad idea for many reasons. Did you personally encounter or find an extension that does this on GitHub? |
|
You’re right - the extension was Hypervel’s |
|
Please show how the fix look like.. maybe we can improve some phpstan rules to raise awareness |
|
Sure. Here you go: https://github.com/hypervel/components/pull/546/changes The pin to 2.2.9 is unrelated to this PR. I'm having issues with 2.2.10 stopping early when analysing with multiple forked workers. Some jobs never finish. I've pinned to 2.2.9 because the same analysis completes reliably there. Will dig into that more when I have time. |
Likely fixed in todays 2.2.11 |
PathRoutingParsercan't choose the parser for analysed files until the analysed file list is set. If an eagerly created extension usesReflectionProviderin its constructor,CachedParsercan store a cleaned AST and return it later during analysis. The affected extension types are property and method class reflection extensions, dynamic function, method, and static method return type extensions, and function, method, and static method type-specifying extensions. Rules and collectors are created after the analysed file list is set, so they can't trigger it.This PR tracks whether cached ASTs contain the full file representation and upgrades cleaned entries when an analysed file needs one. It adds unit coverage for both cache entry paths and an e2e case for early reflection. In a cold Hypervel analysis, the new per-process route memo reached at most 1,787 entries.