Repository navigation
Commit 0f6d8d8
committed
Do not generalize a union of constant arrays that is no bigger than its largest member in
- `optimizeConstantArrays()` generalized any union whose constant array value
count exceeded `ConstantArrayTypeBuilder::ARRAY_COUNT_LIMIT`, even when the
union reduced to a single shape no bigger than one of its own members. A
declared shape with more than 256 values (nested ones included) is kept
as-is on its own, but after `$r['opt'] ?? null` (or `isset`,
`array_key_exists`, `empty`, `!== null`) the scope merge unions it with its
narrowed variant, and the merged result was degraded to
`non-empty-array<..., ...>&oversized-array`.
- The threshold is now raised to the largest per-member count of the unioned
types (new `getConstantArrayValueTypesLimit()`), computed only once the
total is already over the plain limit. Both callers in
`processArrayTypes()` pass the types being unioned.
- Ported the same change to the native mirror in
`turbo-ext/src/TypeCombinator.cpp`.
- Probed: big list shapes (fixed by the same change, test added); declared
unions of a large shape with another shape (already generalized when they
are declared, which is long-standing behavior and left unchanged); shapes
with more than 256 *keys* (degraded by `ConstantArrayTypeBuilder::createFromConstantArray()`,
an older design decision, left unchanged).TypeCombinator::optimizeConstantArrays()
1 parent acd0511 commit 0f6d8d8
3 files changed
Lines changed: 598 additions & 8 deletions
File tree
- src/Type
- tests/PHPStan/Analyser/nsrt
- turbo-ext/src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
| 47 | + | |
47 | 48 | | |
48 | 49 | | |
49 | 50 | | |
| |||
1221 | 1222 | | |
1222 | 1223 | | |
1223 | 1224 | | |
1224 | | - | |
| 1225 | + | |
1225 | 1226 | | |
1226 | 1227 | | |
1227 | 1228 | | |
| |||
1240 | 1241 | | |
1241 | 1242 | | |
1242 | 1243 | | |
1243 | | - | |
| 1244 | + | |
1244 | 1245 | | |
1245 | 1246 | | |
1246 | 1247 | | |
| |||
1259 | 1260 | | |
1260 | 1261 | | |
1261 | 1262 | | |
| 1263 | + | |
| 1264 | + | |
| 1265 | + | |
| 1266 | + | |
| 1267 | + | |
1262 | 1268 | | |
| 1269 | + | |
| 1270 | + | |
| 1271 | + | |
| 1272 | + | |
| 1273 | + | |
| 1274 | + | |
| 1275 | + | |
| 1276 | + | |
| 1277 | + | |
| 1278 | + | |
| 1279 | + | |
| 1280 | + | |
| 1281 | + | |
| 1282 | + | |
1263 | 1283 | | |
1264 | 1284 | | |
1265 | | - | |
| 1285 | + | |
1266 | 1286 | | |
1267 | 1287 | | |
1268 | 1288 | | |
1269 | 1289 | | |
1270 | 1290 | | |
1271 | 1291 | | |
1272 | 1292 | | |
| 1293 | + | |
| 1294 | + | |
| 1295 | + | |
| 1296 | + | |
| 1297 | + | |
1273 | 1298 | | |
1274 | 1299 | | |
1275 | 1300 | | |
| |||
1311 | 1336 | | |
1312 | 1337 | | |
1313 | 1338 | | |
1314 | | - | |
| 1339 | + | |
1315 | 1340 | | |
1316 | 1341 | | |
1317 | 1342 | | |
| |||
0 commit comments