Do not make php-parser and phpdoc-parser properties public when inlining getters in the phar build - #6410
Merged
Merged
Conversation
…ing getters in the phar build The phar ships both packages under their own, unprefixed namespaces, and projects install them on their own too, so the copy loaded at run time may be one whose properties are still non-public. The collector skips a call site whenever the inlined body would need such a property made public, and the applier refuses such a target instead of stamping it. better-reflection is PHPStan's own fork and keeps being inlined; call sites inside the two packages and their getters reading public members are still inlined. Inlined call sites 9,005 -> 8,426, properties made public 851 -> 823 (the 28 php-parser and phpdoc-parser ones gone), rewritten files 1,039 -> 976. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MenQLNmxZKVgpFuzRRTBGW
ondrejmirtes
force-pushed
the
inliner-no-vendor-publicize
branch
from
September 10, 2026 12:36
5a17d2b to
0710158
Compare
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.
Follow-up to #6406. The phar build's getter inliner made properties of the three vendor packages public (stamped with
#[PrivateProperty]/#[ProtectedProperty]) so that their single-return getters could be inlined. For php-parser and phpdoc-parser that is unsafe: the phar ships both under their own, unprefixed namespaces (PhpParser,PHPStan\PhpDocParserare in scoper'sexclude-namespaces), and projects install them on their own too, so the copy loaded at run time may be one whose properties are still non-public. Their properties are no longer touched. better-reflection is PHPStan's own fork and keeps being inlined.What changed
InlineCallCollectorskips a call site whenever the inlined body would need a property declared undervendor/nikic/php-parserorvendor/phpstan/phpdoc-parsermade public (PROTECTED_PACKAGE_DIRECTORIES). The check runs against every publicize target (declaring class, trait file, subclass redeclarations). Getters of the two packages that only read public properties or call public methods are still inlined, and call sites inside them are still rewritten.InlineEditsApplierrefuses such a target with an exception instead of applying it, so a collector regression fails the build loudly. The protected directories are a constructor argument defaulting to the same two, covered by a new test.Before vs. after
Collector output replayed with the applier's outermost-wins logic, then confirmed by a full
compiler/bin/preparerun in a copy of the tree.The 587 dropped sites are exactly the ones that needed a php-parser (407) or phpdoc-parser (180) property; nothing else is lost. 336 of them were calls from
src/into those getters, 251 were calls inside the two packages. Eight nestedsrc/edits previously shadowed by an outer edit now apply on their own. Largest individual losses:NodeAbstract::getStartLine(203 sites),NodeAbstract::getAttributes(104),TokenIterator::currentTokenValue(53),Comment::getText(49),TokenIterator::currentTokenLine(46),TokenIterator::currentTokenIndex(34). Nosrc/getter reads a property inherited from a php-parser parent, so no PHPStan-declared callee is affected.The level-0 collection analysis reports the same findings before and after; the compiler test suite, its level-8 analysis and phpcs pass. The CPU cost of the dropped sites was not benchmarked; at the 28–40 ns/frame figure from #6406 it is well under half a percent.
🤖 Generated with Claude Code
https://claude.ai/code/session_01MenQLNmxZKVgpFuzRRTBGW