Commit 177cd03
committed
Fix phpstan/phpstan#14319: Prevent exponential type growth in array dim fetch narrowing
- Added ARRAY_DIM_FETCH_UNION_TYPE_LIMIT (8) to MutatingScope to cap parent type narrowing
- When array dim fetch narrows a parent variable type that is already a UnionType with
more than 8 members, skip propagating HasOffsetValueType intersections to the parent
- This prevents 2^N exponential growth when N consecutive if-blocks check different array
offsets on an array|object typed variable
- New regression test in tests/PHPStan/Analyser/nsrt/bug-14319.php
- New benchmark test in tests/bench/data/bug-14319.php1 parent 7861fe4 commit 177cd03
3 files changed
Lines changed: 96 additions & 8 deletions
File tree
- src/Analyser
- tests
- PHPStan/Analyser/nsrt
- bench/data
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
139 | 139 | | |
140 | 140 | | |
141 | 141 | | |
| 142 | + | |
| 143 | + | |
142 | 144 | | |
143 | 145 | | |
144 | 146 | | |
| |||
2690 | 2692 | | |
2691 | 2693 | | |
2692 | 2694 | | |
2693 | | - | |
| 2695 | + | |
| 2696 | + | |
2694 | 2697 | | |
2695 | 2698 | | |
2696 | 2699 | | |
2697 | 2700 | | |
2698 | 2701 | | |
2699 | 2702 | | |
2700 | 2703 | | |
2701 | | - | |
| 2704 | + | |
2702 | 2705 | | |
2703 | 2706 | | |
2704 | 2707 | | |
2705 | 2708 | | |
2706 | 2709 | | |
2707 | 2710 | | |
2708 | | - | |
2709 | | - | |
2710 | | - | |
2711 | | - | |
2712 | | - | |
2713 | | - | |
| 2711 | + | |
| 2712 | + | |
| 2713 | + | |
| 2714 | + | |
| 2715 | + | |
| 2716 | + | |
| 2717 | + | |
| 2718 | + | |
2714 | 2719 | | |
2715 | 2720 | | |
2716 | 2721 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
0 commit comments