Repository navigation
fix(php): resolve member calls in remapped files and through inherited methods, keep every call site - #5364
fix(php): resolve member calls in remapped files and through inherited methods, keep every call site#5364livingforelvis wants to merge 2 commits into
Conversation
…d methods, keep every call site - Gate _resolve_php_member_calls on _lang_family, so a .graphifyrc-mapped extension (language.inc=php) is resolved - Bind $this->m() to the enclosing class, like self:: - Look the method up the inherits chain level by level: nearest declaring class wins, a tie binds nothing - Keep one edge per call site in the PHP extractor and resolver, so repeats reach also_seen (Graphify-Labs#4881) - _merge_decl_def_classes keys calls edges by call site, so its dedup keeps repeat call sites - _AST_CACHE_SCHEMA 49 -> 50 Refs Graphify-Labs#5362
|
Thanks for the pull request, @livingforelvis. A maintainer will review it soon. Want to talk it through while it is in review? Come join us on our Discord server. For longer-form discussion there is also GitHub Discussions. A couple of things that speed up review: make sure the test suite passes on Python 3.11 and 3.13, and that the change keeps extraction deterministic. |
…, non-php and $this:: cases
There was a problem hiding this comment.
Graphify code review 
Review finished · 85a59790597b
Warning
Merge confidence: 4/5 · Review before merging · 🟠 High impact
1 P2 bug checked against the code · 4 possible issues not confirmed
Bugs (1)
P2 · Filter inaccessible private methods in declared_from: child $this->secret() and parent::secret() calls can otherwise emit calls edges to a parent method PHP does not allow them to access. Inspect source
Detailed review · checked against the code
Child calls can link to an inaccessible private parent method
A child’s $this->secret() or parent::secret() can be recorded as calling a parent’s private method, even though PHP does not allow that call from the child.
Expected: The graph should not link the call to a method PHP makes inaccessible from the child.
Actually: The resolver can select the parent’s private method by name and emit a calls edge to it.
The resolver indexes method edges by owner and name without filtering visibility, and declared_from walks the inheritance chain until it finds a match. For $this->secret(), the new special case selects the caller’s class and the inherited lookup can then return the parent’s private method; for parent::secret(), the resolver selects the parent and can return that private method directly. It emits a calls edge for either match. PHP does not allow a child to call a parent’s private method through either form, so these edges misrepresent the source. The resolver is registered and run for PHP files through the language resolver registry.
- Independent source review: Checked the inherited-call tests: they cover public parent methods, trait precedence, and lookup ties, but do not check private methods. No visibility check appears in the inspected lookup or call-emission path. The base implementation already directly looked up methods on the
parent::receiver, so that form could link a private parent method before this change; the new inherited lookup adds the same false link for$this->secret()when the child has no matching declaration.
Not confirmed (4 possible issues)
Leads worth a look; we didn't double-check these. They don't change the score.
Not confirmed · Each test extraction leaves a new temporary cache directory behind in the system temp folder Inspect source
Detailed review · not confirmed
The _extract helper passes a fresh tempfile.mkdtemp() directory as cache_root on every call, and nothing removes it, so each test run leaves more directories behind.
Line 38 calls extract(paths, cache_root=Path(tempfile.mkdtemp()), root=tmp_path, parallel=False). mkdtemp creates a directory that persists after the test finishes, and no finally, addfinalizer, or fixture cleans it up. The test already receives pytest's tmp_path fixture, which is cleaned up automatically, so the cache could live under it instead.
-
Whether
extractscans or caches anything underrootwhencache_rootsits insidetmp_pathwas not checked, since the extract source is not in this review. -
Only this test file was reviewed; the behavior of
extractwithcache_rootis unverified. -
Found by the per-file sweep; not double-checked.
Not confirmed · static:: calls are bound to the calling method's own class, so a subclass override is never the resolved target Inspect source
Detailed review · not confirmed
The self/static branch resolves static:: to the class where the caller is defined, but PHP late static binding dispatches static:: to the class actually called at runtime.
At line 7836 both self and static take the same path, type_nid = enclosing_type.get(caller), so static is treated exactly like self. The new docstring at lines 7727-7728 calls self::/static:: exact because the keyword names the class unambiguously, but static:: does not name a fixed class.
-
The subclass that actually receives the call is not visible from the call site, so the resolver cannot tell whether an override exists.
-
Found by the per-file sweep; not double-checked.
Not confirmed · Chosen definition location is compared as text, so L10 can sort before L9 and the reported definition may not be the earliest one Inspect source
Detailed review · not confirmed
The tie-break that picks which implementation file's location becomes definition_location compares source_location as a string. A location like L10 sorts before L9, so the recorded definition site may not be the lowest line the comment promises.
Lines 4162-4163 build the sort key as (str(source_file), str(source_location)). Strings sort lexicographically, so "L10" < "L9". The comment at 4154-4156 says the choice is 'lowest source_file, then location', which only holds if the location is compared numerically. The sort is still deterministic, so the failure is an incorrect choice rather than nondeterminism. The exact format of source_location is not visible in this hunk, so this depends on whether it contains unpadded numbers.
-
The format of
source_locationvalues is not shown in this hunk; the problem only occurs if they hold unpadded line numbers. -
Whether the header node already carries a
definition_locationfrom an earlier pass is not visible here. -
Found by the per-file sweep; not double-checked.
Not confirmed · Repeated calls edges that differ only by source file are no longer merged, so duplicate edges created by the collapse can survive Inspect source
Detailed review · not confirmed
The de-duplication key for calls edges now includes source_file and source_location. Edges that were copied during the merge from a duplicate node may carry a different source file and therefore are no longer recognised as duplicates.
Lines 4193-4196 extend the key k with (source_file, source_location) for calls edges so that real repeat call sites are kept for also_seen. The comment at 4182-4183 says the de-dup step exists to remove edges that become identical after the collapse. A merge copy with a different source_file now has a different key, so it is kept. Whether the merge actually produces such copies is not visible in this hunk.
-
Not shown whether merged duplicate
callsedges can carry a differentsource_filefrom their original. -
The consumer of
also_seenis outside this hunk, so its expectations for duplicate call edges are unverified. -
Found by the per-file sweep; not double-checked.
What this review covered
- This review stopped before it finished; findings are from the part that ran.
- The AI model asked for code in a way the review could not use.
- 4 of 4 changed files inspected. This is scope, not a correctness guarantee.
Code graph and static checks · 5829 functions depend on this change
Impact & health
Impact — 5829 functions depend on the 744 functions this change touches.
Health — this change adds coupling hotspots:
- worse:
_resolve_php_member_calls()— 2 callers, 6 callees
Formal checks — 5829 functions this change can affect weren't formally checked in this review. Formal checks are informational only.
Health delta baseline: last indexed commit dfab9cc (diverged from this PR's base — delta is approximate).
Gate & verification
✅ PASS — objectively clean (no health regressions, tests not run — proofs not run this pass (advisory)). Grounded, not self-assessed.
Advisory (not blocking):
- verification_scope: 5256 function(s) in the blast radius were not formally verified this run
Test selection
390 of 602 test file(s) selected (65%) via static blast radius.
tests/test_4874_jvm_resolution.py— impacttests/test_4909_reference_binding_scale.py— impacttests/test_4978_reconcile_cost.py— impacttests/test_4992_ts_import_types.py— impacttests/test_affected_overrides.py— impacttests/test_alias_folding.py— impacttests/test_analyze.py— impacttests/test_astro_extraction.py— impacttests/test_astro_import_ids.py— impacttests/test_binary_media_words.py— impacttests/test_blade_extractor.py— impacttests/test_build.py— impacttests/test_build_located_semantic_identity.py— impacttests/test_build_merge_dedup_scope.py— impacttests/test_build_merge_ghost_fold_4955.py— impacttests/test_build_merge_hyperedges_and_prune.py— impacttests/test_build_merge_shrink_guard.py— impacttests/test_builtin_global_type_refs.py— impacttests/test_c_include_resolution.py— impacttests/test_cache.py— impacttests/test_cache_long_paths.py— impacttests/test_cache_stale_import_target.py— impacttests/test_cache_windows_case_4925.py— impacttests/test_carried_hyperedge_remap.py— impacttests/test_case_only_decl_ids_4904.py— impacttests/test_case_sensitive_resolution.py— impacttests/test_charmap_encoding.py— impacttests/test_chunking.py— impacttests/test_cjs_module_extension.py— impacttests/test_cli_export.py— impacttests/test_cluster.py— impacttests/test_cobol_extractor.py— impacttests/test_code_only_scope_4923.py— impacttests/test_confidence.py— impacttests/test_confidence_score_output.py— impacttests/test_corrupt_graph_json.py— impacttests/test_cpp_alias_member_resolution.py— impacttests/test_cpp_anonymous_namespace_receivers.py— impacttests/test_cpp_conditional_initializers.py— impacttests/test_cpp_forward_declarations.py— impacttests/test_cpp_forward_receiver_completion.py— impacttests/test_cpp_inherited_member_resolution.py— impacttests/test_cpp_local_callable_shadowing.py— impacttests/test_cpp_member_call_by_receiver_type.py— impacttests/test_cpp_member_declaration_identity.py— impacttests/test_cpp_method_declarations.py— impacttests/test_cpp_nested_and_cli.py— impacttests/test_cpp_objc_cross_file_calls.py— impacttests/test_cpp_receiver_chains.py— impacttests/test_cpp_receiver_parameters.py— impact- … and 340 more
Selection is safe under the controlled-regression assumption; always-run tests + a periodic full run are the backstops. Advisory — it never changes the check verdict.
Every flagged function
_resolve_php_member_calls()ingraphify/extract.py:7708· 2 callers, 6 callees: fans out to 6 callees (efferent coupling)
…batch Fold the Rust (#5380), C# (#5376) and PHP (#5362) AST-output changes into the unreleased _AST_CACHE_SCHEMA = 51 entry (alongside the GHSA-g6c9-j4vm-mwq4 bash change already there), so cached Rust/C#/PHP extractions re-run on the next build. Document the #5229 Python import-binding limitation (plain-module re-exports are left unresolved rather than chased) in ARCHITECTURE.md, and add the 0.9.115 changelog entries for the batch. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Landed in v0.9.115 via an authorship-preserving cherry-pick (both commits). Member calls now resolve in remapped files (e.g. |
What does this PR do?
_resolve_php_member_callsdropped PHP calls whose target is plain from the source.phpsuffix; it now gates on_lang_family, like the extractor registry, solanguage.inc=phpfiles getCls::m()/self::m()/parent::m()edges$this->m()resolves against the enclosing class, exact likeself::inheritschain level by level: nearest class that provides it wins, a tie on that level binds nothing (the Java resolver's rule)used trait's (through traits that use traits), then the parent'sextract_phppassespreserve_call_sites=Trueand the resolver dedups per (caller, target, line), so a second call reaches the build and folds intoalso_seen([Feature]: don't erase weaker-confidence evidence when edges or paths merge #4881)_merge_decl_def_classeskeys acallsedge by its file and line too, so its corpus-wide dedup removes only the twins a header/definition merge creates, never a repeat call (it ran on the whole corpus once one.h/.ccmember merged, so it dropped PHP repeat calls in mixed corpora)_AST_CACHE_SCHEMA49 -> 50, so cached PHP extractions re-runType of change
Verification & Invariants
Invariant: one
callsedge per PHP call site the resolver can bind; the build folds repeats of one pair intoalso_seenInvariant: a method is bound only when exactly one class on the nearest providing level of the
inheritschain provides it$this::m()(dynamic scope) and untyped instance receivers stay unresolved, as beforeLimitation: interfaces are not walked (no method body);
insteadof/astrait conflict rules are not read, so two traits providing one method bind nothingLimitation:
$this->/static::bind the enclosing class's view, not a subclass override (late binding), same asself::Not changed: C++ repeat call sites still collapse earlier, in the cross-file call resolver
Cache schema bump: feat(java): dispatch interface method calls to their implementers (#5319) #5323 also moves 49 -> 50; whichever lands second takes 51
Read the CONTRIBUTING.md guide.
Reproduced the issue and identified the invariant.
Made the smallest fix necessary.
Added a regression test.
Kept the PR description synchronized with the final implementation.
Documented any limitations / unsupported cases explicitly.
How was this tested?
tests/test_php_member_call_gaps.py:.inccorpus withlanguage.inc=php:Cls::m(),self::m(),parent::m()resolve EXTRACTED$this->m()binds the parent's method, with a same-named decoy classparent::m()binds the grandparent's methodinheritscycle ends with no edge; a non-PHP member call is skipped;$this::m()stays unresolved.h/.ccmember merge in the corpusbuild_from_jsoncarries the second line inalso_seencontains/methodedgesuv run pytest tests/test_php_member_call_gaps.py -qorigin/v8(f51d46c)10 failed, 6 passed16 passedFailing on
v8:Repro from #5362 (three
.incfiles,language.inc=php),callsedges fromextract():.run() -> .helper()L4 ($this->, two levels up).run() -> .helper()L5 (repeat).boot() -> .setup()L8 (parent::, two levels up).make() -> .setup()L9 (self::, inherited)uv run --with pytest-xdist pytest tests -n 8(first commit) —8 failed, 11619 passed, 165 skipped, 1 xfailed; the 8 (test_terraform_modulesparallel cases,test_language_override_lifecycle[modify],test_workers_by_work_size::test_extract_honours_env) pass serially:84 passed-k "php or cpp or decl_def or also_seen or cache or merge or trait"—6 failed, 1396 passed; the 6 are the sametest_terraform_modulesparallel cases, serially13 passedclass C extends P { use T; }, both declarem):.run() -> .m()bound toP.phpbefore,T.phpafteruv run ruff checkon changed files —All checks passed!uv run pyright graphify/extract.py graphify/extractors/resolution.py— 192 errors, the same 192 as onv8Graphify-specific checklist