Repository navigation
Commit cd5c22a
Inline single-return getters when building the phar
A getter call costs a call frame for a body that reads one property, and
the engine's optimizer cannot inline it: it compiles callers before
callees. PHPStan's own analysis knows the receiver class at every call
site, so the phar build (compiler PrepareCommand, before the downgrade)
runs a level-0 analysis of src/ and the three vendor packages on the hot
paths with a collector (build/inline.neon, InlineCallCollector) that
records, for every call whose receiver resolves to a single class and
whose callee is a single `return <expr>;`, the textual replacement with
$this and the parameters substituted. Callees are final classes, final or
private methods, or — closed world — methods nothing in that code base
overrides (OverridesScanner). InlineEditsApplier applies the edits
(outermost wins on overlaps) and makes the non-public properties the
moved bodies read public, in the declaring class or trait and in every
subclass redeclaring them. Turbo-shadowed classes are never inlining
sources: their PHP bodies are not what runs.
On this tree: 9,358 call sites in 1,046 files, 851 properties. Analysis
output byte-identical; single-process src/Type self-analysis with the
transformed tree −3.5% user CPU (5/6 alternating pairs; −3.9%, 6/6 on the
earlier prototype tree).
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SRLigetKoiZzYBe4iRQb3J1 parent abc407c commit cd5c22a
7 files changed
Lines changed: 1014 additions & 0 deletions
File tree
- build
- PHPStan/Build
- compiler
- src
- Console
- tests
0 commit comments