Repository navigation
fix(rust): bind an in-file call to the type it names, not to any same-named function - #4238
rohit-jsfreaky wants to merge 1 commit into
Conversation
…-named function extract_rust bound every in-file call through one bare-name index (last one wins), so `Matcher::new()` reached `Printer::new()` when the file defined both, `Arc::new(x)` reached the file's own `fn new`, `self.go()` another type's `go`, `drop(x)` the `impl Drop` method and `x.total()` a free `fn total`, all EXTRACTED. `Type::f()` / `Self::f()` / `self.f()` now bind only to that type's method in the file (type = last path segment without generics, on the call and on the impl; `i32` and other primitives count as types). With none, `Enum::Variant(x)` still gets its constructor reference and `self.f()` falls through to the cross-file self pass. A bare `f()` binds only to a free function or a type, `x.f()` only to a method. Against rust-analyzer: wrong edges ripgrep 1232 -> 532, bat 138 -> 36, fd 29 -> 9; correct edges 1852 -> 2236, 602 -> 655, 148 -> 154. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01B8gwEpjajiWHVW3c9smuKf
|
Thanks for the pull request, @rohit-jsfreaky. 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.10 and 3.13, and that the change keeps extraction deterministic. |
There was a problem hiding this comment.
Graphify reviewed this change.
Looks safe to merge — no coupling regressions and no blocking issues, checked against the code graph (not a self-assessment).
Formal verification. PR-changed functions: 1/1 verified (0 proven, 1 may-equivalent, 0 distinguished) · 0 not verified.
Graphify review — findings
Fixes Rust in-file call binding to follow the call's shape. Type::f(), Self::f() and self.f() now bind only to that type's method from this file's impl blocks, and draw no in-file edge when the file doesn't define one, so Arc::new(x) no longer lands on a local fn new and unresolved self calls fall to the cross-file pass. Enum::Variant(x) falls back to the variant node, a bare f() reaches only free functions or constructors, and x.f() only methods. _rust_qualifier_type treats lowercase paths as modules, accepts primitives like i32, and strips generics and &/dyn from impl types.
No blocking issues surfaced. 3 lower-confidence candidates did not survive cross-model review.
Analysis details — impact, health, verification
Impact & health
Graphify review
Impact — 65 functions depend on the 32 functions this change touches.
Health — this change adds coupling hotspots:
- new:
extract_rust()— 35 callers, 9 callees - new:
walk()— 1 callers, 10 callees
Verification — 65 functions in the blast radius were not formally verified this run (proofs are advisory here).
Gate & verification
graphify gate
PASS — objectively clean (no health regressions, tests not run — proofs not run this pass (advisory)). Grounded, not self-assessed.
Advisory (not blocking):
- verification_scope: 65 function(s) in the blast radius were not formally verified this run
Test selection
Test selection
4 of 345 test file(s) selected (1%) via static blast radius.
tests/test_multilang.py— impacttests/test_rust_in_file_call_binding.py— impact, changed-testtests/test_rust_macro_rules.py— impacttests/test_rust_self_member_calls.py— impact
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.
Formal verification
No difference found (not proven): No behavior difference found in extract\_rust (not a proof).
The verifier ran both versions of extract\_rust on many inputs and saw identical behavior every time. Strong evidence the change is safe, but evidence, not a proof.
Guarantee: Empirical: differential testing (both versions run on many generated inputs). A divergence on an untested input remains possible, so this is 'no counterexample found', not 'proven equivalent'.
Note: An input the sampler did not try could still differ.
· 1 grounded finding(s) anchored inline below; 1 more finding(s) on lines outside this diff (see the check run).
| return segments[-1] if segments else "" | ||
|
|
||
|
|
||
| def extract_rust(path: Path) -> dict: |
There was a problem hiding this comment.
extract_rust()
fans out to 9 callees (efferent coupling); 35 callers depend on it (afferent coupling).
Grounded coupling-delta finding (deterministic), not an LLM guess.
|
Landed in v0.9.82 via an authorship-preserving cherry-pick, so your commit is on |
What does this PR do?
Fixes #4237.
In
extract_rust(graphify/extractors/rust.py), the in-file call match now follows the call's shape:Type::f()andSelf::f()bind only tofin animpl Typeblock of the same file. The type is the last path segment without generic arguments (crate::a::Matcher,Vec::<u8>,io::Error,i32), on both the call and the impl. With no such method there is no in-file edge, exceptEnum::Variant(x), which still gets itsreferences(constructor) edge to the variant node.self.f()binds only tofon the caller's own impl type. With no such method in the file it now reaches the existing cross-fileselfpass (fix(rust): receiver-method calls (self.method()) are dropped cross-file — Rust has no _resolve_*_member_calls pass #2234) instead of another type'sf.f()binds only to a free function or a type (tuple struct / variant constructor), never to a method.x.f()binds only to a method, never to a free function.Module paths (
fs::read,self::helper) keep the old match.Type of change
Verification & Invariants
Invariant: an in-file
Type::f()/Self::f()/self.f()edge goes to a method of that type; a free call never reaches a method and a method call never reaches a free function.Persisted state it could invalidate: AST cache entries for
.rsfiles. The cache directory is keyed by package version (cache/ast/v{version}-s{schema}), so the next release re-extracts; no schema bump needed (no new persisted field).Against rust-analyzer 1.97.1 (go-to-definition at every call inside every
fn), 0.9.80 vs this branch, coldgraphify update <dir> --no-cluster --force,callsedges with both ends in.rsfiles:"Calls found": (caller, callee) pairs rust-analyzer resolves to a
fnin the repo that the graph also has. Correct edges go up becauseB::new()now reachesB::newinstead of the lastnewin the file.Correct (caller, callee) pairs lost: ripgrep 1, bat 0, fd 0. The one is
Default::default()in a globset test: a trait-qualified call whose target depends on the variable's type (let set: GlobSet), so the old edge was the bare-name guess landing right.New pairs rust-analyzer does not confirm: ripgrep 25, bat 0, fd 0. All are
x.f()calls with an untyped receiver, which this PR leaves as a bare-name guess; with methods and free functions in separate indexes, the guess now lands on a different method in those 25 cases (for examplesearcher.search_path()incrates/core/search.rs, whose target isSearcher::search_pathincrates/searcher, now reaching the localSearchWorker::search_path; before, the name matched the caller itself and the edge was dropped). Over allx.f()/expr.f()/self.field.f()edges in ripgrep: wrong 659 -> 502, correct 560 -> 646.Changed-files rebuild vs full build (
watch._rebuild_code, bat, changingsrc/printer.rs): 1118 / 1118 / 1118callsedges, identical.walk_calls, plus the method index it reads).tests/test_rust_in_file_call_binding.py, 7 tests; 6 fail on 0.9.80,test_enum_variant_constructor_is_still_a_referencepasses on both.Limitations:
x.f()with a receiver that is notselfis still bound by name in-file (a typed-receiver pass is the follow-up). Trait-qualified calls (Default::default(),From::from(x)) and<T as Trait>::f()get no in-file edge.Type::f()whereimpl Typeis in another file still gets no edge, as before.How was this tested?
Project venv (Python 3.12.12, graphify from this branch via PYTHONPATH), Windows 11; rust-analyzer 1.97.1 for the ground truth:
Graphify-specific checklist
🤖 Generated with Claude Code
https://claude.ai/code/session_01B8gwEpjajiWHVW3c9smuKf