Skip to content

Merge degraded members into one oversized array only when each is an array - #7217

Merged
ondrejmirtes merged 1 commit into
2.3.xfrom
oversized-widening-non-array-member
Nov 27, 2026
Merged

ondrejmirtes merged 1 commit into
2.3.xfrom
oversized-widening-non-array-member

Conversation

@ondrejmirtes

@ondrejmirtes ondrejmirtes commented Nov 27, 2026 •

Copy link
Copy Markdown
Member

OversizedArrayWidening merged its results into one general array when each member held a shape it degraded. A member such as bool|int|list{...}|string (the values of shapes merged by ArrayUnion::mergeIntoGeneralArray()) holds shapes without being an array, so its iterable key and value types are *ERROR* and the merged array became non-empty-array<*ERROR*, *ERROR*>&oversized-array. Such members now stay apart.

Regression from 4268fd0, found in openemr/openemr by the phpstan/phpstan integration tests.

Closes phpstan/phpstan#15861

The benchmark bug-6948.php took the same path and always measured a broken type (non-empty-list<non-empty-array<*ERROR*>&oversized-array>, also before 4268fd0). It now infers the nested non-empty-list<int|non-empty-list<int|...>>, which costs 692.1M instead of 211.9M instructions; the new numbers are accepted in this PR. The other failing benchmark shards (bug-7214, ConstantArrayTypeBench, TypeCombinatorBench) fail the same way on 2.3.x.

…array

OversizedArrayWidening merged its results into one general array when
each member held a shape it degraded. A member such as
bool|int|list{...}|string holds shapes without being an array, and its
iterable key and value types are *ERROR*, so the merged array was
non-empty-array<*ERROR*, *ERROR*>&oversized-array. Such a member now
gives its arrays to the merged array and keeps the rest beside it.

bug-6948.php (`$row[] = $row` fifteen times) took the same path: $row
was non-empty-list<non-empty-array<*ERROR*>&oversized-array>, and is now
the nested non-empty-list<int|non-empty-list<int|...>> its values are.
Computing with those nested lists is the price of the new numbers.

Amp-Thread-ID: https://ampcode.com/threads/T-01a21c4a-f4aa-73fb-ab5d-2ac321ba792a
@ondrejmirtes
ondrejmirtes force-pushed the oversized-widening-non-array-member branch from 95764e5 to bc52dd7 Compare November 27, 2026 13:35
@ondrejmirtes
ondrejmirtes merged commit 6be3066 into 2.3.x Nov 27, 2026
878 of 917 checks passed
@ondrejmirtes
ondrejmirtes deleted the oversized-widening-non-array-member branch November 27, 2026 14:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

foreach over a large constant array of shapes gives *ERROR* values (since phpstan-src 4268fd0b3, #7195)

1 participant