Commit c0b434e
committed
Skip conditional type search on types without late-resolvable types
`ConditionalReturnTypeRuleHelper::check()` walks every parameter type, out type, closure-this type and the return type with `TypeTraverser::map()` to collect `ConditionalType` and `ConditionalTypeForParameter` instances. Both are late-resolvable types, so a type whose `hasTemplateOrLateResolvableType()` is false can't contain one, and the traversal now gets skipped for those. When it does run, nothing changes: it still collects every occurrence without memoization, so this is independent from #6652, which keeps `map()` here on purpose.
On the symfony/ux-css array shape (847 keys, 144 of them a nested shape alias), this traversal visits the shared nested shape once per offset using it. With #6671, `hasTemplateOrLateResolvableType()` is memoized on `ConstantArrayType`, so the check costs almost nothing there.
For every `Type` whose `traverse()` visits children, `hasTemplateOrLateResolvableType()` checks those children too, except callable/closure parameter default values and `ObjectWithoutClassType`'s subtracted type, neither of which can hold a conditional type in a declared signature. I logged every traversal that found a conditional type while `hasTemplateOrLateResolvableType()` was false; that gave 0 cases over the full test suite and PHPStan's self-analysis.
Measured with the https://github.com/Kocal/sf-ux-css-phpstan-reproducer reproducer, `phpstan-nested.neon`, `--debug`, 6 interleaved runs with the first discarded:
| | before | after |
|---|---|---|
| 2.3.x, no turbo | 12.50-12.61 s | 12.12-12.17 s |
| 2.3.x + #6652 + #6671, no turbo | 2.58-2.65 s | 2.11-2.13 s |
| 2.3.x, turbo | 5.65-5.84 s | 5.46-5.50 s |
`make tests` passes with and without the turbo extension, `make phpstan` and `make cs` pass.
Refs phpstan/phpstan#153481 parent b0e7a99 commit c0b434e
1 file changed
Lines changed: 19 additions & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
37 | 39 | | |
38 | | - | |
39 | | - | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
40 | 43 | | |
41 | | - | |
| 44 | + | |
42 | 45 | | |
43 | 46 | | |
44 | 47 | | |
| |||
48 | 51 | | |
49 | 52 | | |
50 | 53 | | |
51 | | - | |
| 54 | + | |
52 | 55 | | |
53 | 56 | | |
54 | 57 | | |
| |||
61 | 64 | | |
62 | 65 | | |
63 | 66 | | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
68 | 72 | | |
69 | | - | |
70 | | - | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
71 | 76 | | |
72 | 77 | | |
73 | 78 | | |
| |||
0 commit comments