Repository navigation
Conversation
Member
|
Hey, please submit an issue with the description and reproducer first, thank you. |
alfredbez
force-pushed
the
fix/literal-array-memory-2.3
branch
from
October 10, 2026 20:11
9002975 to
2023a6c
Compare
ScalarHandler builds the constant types of the literal scalars eagerly and hands them over precomputed, without a typeCallback closure, like its PHP twin. ArrayHandler stores only each non-scalar item's [type, nativeType] pair, collects the items' dependencies while walking them, and evicts the items' expression results once their callback ran, unless a by-reference item keeps the literal alive; ExpressionResultStorage gains the native removeExpressionResult(). The item-type resolution of the type callback, the absorbed-items walk and the callable-array dependencies re-derive the scalar and TypeExpr types from their nodes, as the twin does. On the PHP side, fix the import order and use the early exit the coding standard asks for.
A [Foo::class, 'method'] array makes its file depend on what calling it returns, so a change of the method's return type re-analyses it; arrays whose first item is not definitely a class-string (a maybe-class-string, an object) add no such dependency.
Configure the target PHP version, not the test runtime, to expose class-string|object callable dependencies and detect the escaped mutant. Amp-Thread-ID: https://ampcode.com/threads/T-01a129b7-7bd7-771c-89da-39bb43f0eed7 Co-authored-by: Amp <amp@ampcode.com>
Amp-Thread-ID: https://ampcode.com/threads/T-01a129b7-7bd7-771c-89da-39bb43f0eed7 Co-authored-by: Amp <amp@ampcode.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes phpstan/phpstan#15452
Reproducer: https://github.com/alfredbez/phpstan-literal-array-memory-reproducer
Avoid retaining expression results and closures for every scalar item in large literal arrays. Keep results needed by by-reference items, and mirror the changes in the Turbo extension.
On a synthetic 30,000-item array, peak worker memory dropped from 229 MB on the base commit to 126 MB with this change. Analysis results were unchanged.
Verified locally: full test suite with and without Turbo, differential checks, strict native build and UBSan. Added callable-array dependency coverage, including a PHP 7.4 analysis target that detects the escaped mutation. The new GitHub CI run is pending.