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? |
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.