Repository navigation
feat(rust): resolve x.method() and self.field.method() through the receiver's declared type - #4299
rohit-jsfreaky wants to merge 3 commits into
Conversation
|
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.
Worth a look — the grounded gate found no coupling regressions or blocking issues, but 2 advisory finding(s) below merit a look before merge.
Not checked: tests were not run; formal verification proved 0 of 3 changed function(s) (1 sampled, not proven, 2 not verified).
Formal verification. PR-changed functions: 1/3 verified (0 proven, 1 may-equivalent, 0 distinguished) · 2 not verified (1 vacuous, 1 unsupported).
Not verified on this run: dispatch\_command (vacuous: never exercised), \_rebuild\_code (unsupported).
Graphify review — findings
Adds a rust_typed_member_calls resolver that binds Rust x.m() and self.field.m() calls to the receiver type's method, emitting INFERRED call edges (0.85) whenever the extractor can name the type from a typed param or let, a struct field, or the return type of a call unwrapped by ?/.unwrap(). Every lookup must resolve uniquely, narrowing duplicate types and free functions to the caller's file and then its crate; ambiguous calls get no edge. Bumps _AST_CACHE_SCHEMA to 8 so cached ASTs re-extract with the new _rust_ret/_rust_ret_ok/_rust_fields facts, which incremental rebuilds now carry onto context nodes and match across mixed absolute and relative paths.
Worth a look
if let/forbindings hide the outer name in their own value expression —graphify/extractors/rust.py· Escalate · medium- agreed by 2 of 2 members but NOT verified (no proof, no reproducing execution) — consensus is not a verdict; needs human review
- _rust_crate_dir picks the innermost src/tests dir, splitting crates with nested
tests/examplesmodules —graphify/extract.py:5878· Escalate · medium- agreed by 2 of 2 members but NOT verified (no proof, no reproducing execution) — consensus is not a verdict; needs human review
Analysis details — impact, health, verification
Impact & health
Graphify review
Impact — 3809 functions depend on the 580 functions this change touches.
Health — this change adds coupling hotspots:
- worse:
extract()— 845 callers, 51 callees - worse:
build_from_json()— 250 callers, 22 callees - worse:
extract_rust()— 35 callers, 10 callees - worse:
save_cached()— 36 callers, 8 callees - worse:
graph_has_legacy_ids()— 10 callers, 9 callees - worse:
_semantic_id_remap()— 10 callers, 9 callees - worse:
_norm_source_file()— 22 callers, 3 callees - worse:
walk()— 1 callers, 13 callees - …and 2 more — each is listed as a finding
Verification — 3809 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: 3597 function(s) in the blast radius were not formally verified this run
Test selection
Test selection
251 of 362 test file(s) selected (69%) via static blast radius.
tests/test_affected_cli.py— impacttests/test_agents_platform.py— impacttests/test_analyze.py— impacttests/test_astro_extraction.py— impacttests/test_astro_import_ids.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_hyperedges_and_prune.py— impacttests/test_build_merge_shrink_guard.py— impacttests/test_builtin_global_type_refs.py— impacttests/test_cache.py— impacttests/test_cache_stale_import_target.py— impacttests/test_carried_hyperedge_remap.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_cloud_cta.py— impacttests/test_cluster.py— impacttests/test_cobol_extractor.py— impacttests/test_codebuddy.py— impacttests/test_confidence.py— impacttests/test_corrupt_graph_json.py— impacttests/test_cpp_method_declarations.py— impacttests/test_cpp_nested_and_cli.py— impacttests/test_cpp_objc_cross_file_calls.py— impacttests/test_cross_extension_reexport_self_cycle.py— impacttests/test_cross_language_call_resolution.py— impacttests/test_cross_repo_external_call_guards.py— impacttests/test_cross_repo_member_calls.py— impacttests/test_csharp_call_site_generic_args.py— impacttests/test_csharp_enum_members.py— impacttests/test_csharp_field_generic_args.py— impacttests/test_csharp_generic_callsites.py— impacttests/test_csharp_interface_dispatch.py— impacttests/test_csharp_member_calls.py— impacttests/test_csharp_member_chain_calls.py— impacttests/test_csharp_member_nodes.py— impacttests/test_csharp_object_creation.py— impacttests/test_csharp_partial_classes.py— impacttests/test_csharp_tuple_type_refs.py— impacttests/test_csharp_type_resolution.py— impacttests/test_dedup.py— impacttests/test_dedup_remaps_hyperedges.py— impacttests/test_dedup_shrink_refuses_force_write.py— impacttests/test_definition_file_portability.py— impacttests/test_detect.py— impact- … and 201 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.
Docs that may be stale (advisory)
CHANGELOG.md§ 0.9.84 (2026-10-10) (lines 5-17): references changed symbols__init__CHANGELOG.md§ 0.9.77 (2026-10-05) (lines 98-117): references changed symbols__init__CHANGELOG.md§ 0.9.58 (2026-09-10) (lines 350-367): references changed symbols__init__CHANGELOG.md§ 0.9.42 (2026-08-13) (lines 569-587): references changed symbols__init__CHANGELOG.md§ 0.9.23 (2026-07-21) (lines 782-791): references changed symbols__init__CHANGELOG.md§ 0.9.22 (2026-07-20) (lines 792-801): references changed symbols__init__README.md§ See it in action (lines 94-124): references changed symbols__init__docs/superpowers/plans/2026-05-04-incremental-updates-dedup.md§ Task 2: Create graphify/dedup.py — entropy gate + MinHash/LSH + Jaro-Winkler (lines 71-468): references changed symbols__init__docs/translations/README.ar-SA.md§ See it in action (lines 94-124): references changed symbols__init__docs/translations/README.cs-CZ.md§ Podívejte se na to v akci (lines 94-124): references changed symbols__init__
…and 10 more.
Formal verification
Could not verify: Could not verify dispatch\_command.
The verifier did not have enough to check dispatch\_command, so it is saying so rather than guessing. No false assurance is the whole point.
Guarantee: No guarantee either way, this is an honest abstention, not a pass.
Note: Reason: no capturable inputs from the test suite; property tier: not verifiable: all 40 sampled inputs raised on both versions — the function never executed, so 'no divergence' would be vacuous (mostly SystemExit — names the real obstacle, not a sampling gap)
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.
Could not verify: Could not verify \_rebuild\_code.
The verifier did not have enough to check \_rebuild\_code, so it is saying so rather than guessing. No false assurance is the whole point.
Guarantee: No guarantee either way, this is an honest abstention, not a pass.
Note: Reason: no capturable inputs from the test suite; property tier: nondeterministic output (both versions disagreed with themselves on the witness) — not a behaviour change; a function whose output is not a function of its inputs (random / time / uuid / os.urandom, or state carried across calls) cannot be soundly distinguished by execution, so this tier abstains for the whole function
· 3 grounded finding(s) anchored inline below; 7 more finding(s) on lines outside this diff (see the check run).
| return "/".join(parts[:-1]) | ||
|
|
||
|
|
||
| def _resolve_rust_typed_member_calls( |
There was a problem hiding this comment.
_resolve_rust_typed_member_calls()
fans out to 7 callees (efferent coupling).
Grounded coupling-delta finding (deterministic), not an LLM guess.
| node = node_by_id.get(fn_nid, {}) | ||
| return _type(node.get("_rust_ret_ok" if want_ok else "_rust_ret"), _file(fn_nid)) | ||
|
|
||
| def _eval(desc, from_file: str, want_ok: bool = False, depth: int = 0) -> tuple[str, str] | None: |
There was a problem hiding this comment.
_eval()
fans out to 6 callees (efferent coupling).
Grounded coupling-delta finding (deterministic), not an LLM guess.
| return None | ||
|
|
||
|
|
||
| def extract_rust(path: Path) -> dict: |
There was a problem hiding this comment.
extract_rust()
fans out to 10 callees (efferent coupling); 35 callers depend on it (afferent coupling).
Grounded coupling-delta finding (deterministic), not an LLM guess.
Both confirmed and fixed in da617cb.
Tests: The three coupling notes ( @Graphify-Labs please re-review. |
da617cb to
77cfdd0
Compare
|
Rebased onto v8 at 0.9.87 (7536dc0), plus a fix for a wrong edge found in review: a parameter typed by a name the module imports from std ( |
39adc1e to
ba0b659
Compare
…e receiver's declared type
Rust member calls on anything but `self` never resolved across files, and in-file
they bound to whichever method of that name the file defined.
extract_rust records fn return types (`_rust_ret`, `_rust_ret_ok` for Result/Option),
struct field types (`_rust_fields`) and, on each `x.m()` raw call, how the receiver's
type is found (`rust_receiver`: typed param or let, `Type { .. }`, a field, the return
of `T::f()` / `f()` / `y.m()`, through `?`, `.unwrap()`, `.clone()`). The new
_resolve_rust_typed_member_calls evaluates it over the corpus (unique names, narrowed
to the caller's file, then crate) and binds the call to the type's method, INFERRED.
Only crate-local type paths count, untyped rebindings hide outer ones, and an untyped
receiver gets no bare-name edge. AST cache schema 7 -> 8; the new node markers are
forwarded on changed-files rebuilds.
Against rust-analyzer, all calls found: ripgrep 48.2% -> 75.5%, bat 71.5% -> 79.8%,
fd 35.8% -> 65.2%; wrong edges 532 -> 30, 36 -> 24, 9 -> 2.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01B8gwEpjajiWHVW3c9smuKf
…file's crate by its deepest root Two review findings on the typed-receiver pass: - `for x in x.iter()`, `if let Some(x) = x.next()` and match arms bound the new `x` from the start of the construct, so the value expression's own `x` lost its type. The new binding now starts after the value (after the pattern for a match arm). - The crate of a file was the path before its innermost src/tests/benches/examples directory, so `crates/core/src/tests/x.rs` (a tests module) was its own crate and a checkout under a folder named `src` merged crates. A file now belongs to the deepest crate root above it, the roots being the directories that hold a `src/` of some `.rs` file in the corpus. Both covered by tests that fail on the previous commit. ripgrep, bat and fd edges are unchanged; changed-files rebuild == full build. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01B8gwEpjajiWHVW3c9smuKf
…same-named local type Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01B8gwEpjajiWHVW3c9smuKf
ba0b659 to
2cb423c
Compare
…3+rustpaths2 Not for upstream. The pin now also carries upstream PR Graphify-Labs#4299 (typed receivers, for Graphify-Labs#4296), so it needs a version the pokegen3-engine scripts can tell from 0.9.93+rustpaths1. The hint-cap comment gives the new size. Co-Authored-By: Claude <[email protected]> Claude-Session: https://claude.ai/code/session_01W9fdXJbk3kBDaSwc3Z2QCk
Not for upstream. The pin now sits on upstream 0.9.94 and carries the four Rust path branches, the guard's hint index, and upstream PRs Graphify-Labs#4299 (typed receivers) and Graphify-Labs#4581 (type aliases and unions as nodes). The version lets the pokegen3-engine scripts tell it from 0.9.93+rustpaths2. Co-Authored-By: Claude <[email protected]> Claude-Session: https://claude.ai/code/session_01W9fdXJbk3kBDaSwc3Z2QCk
Not for upstream. The pin now sits on upstream 0.9.94 and carries the four Rust path branches, the guard's hint index, and upstream PRs Graphify-Labs#4299 (typed receivers) and Graphify-Labs#4581 (type aliases and unions as nodes). The version lets the pokegen3-engine scripts tell it from 0.9.93+rustpaths2. Co-Authored-By: Claude <[email protected]> Claude-Session: https://claude.ai/code/session_01W9fdXJbk3kBDaSwc3Z2QCk
What does this PR do?
Closes #4296.
extract_rust(graphify/extractors/rust.py) now records:fnnode, its return type:_rust_ret(-> Self,-> Foo,-> Box<Foo>/Arc<Foo>/Rc<Foo>) and_rust_ret_ok(theTof-> Result<T, _>/io::Result<T>/Option<T>);_rust_fields;Box/Arc/Rcderef to the inner type);x.m()raw call, how the receiver's type is found (rust_receiver): a typed parameter (closures included) orlet,Type { .. }, a struct field, the return ofT::f()/f()/y.m(), unwrapped by?/.unwrap()/.expect(), through.clone()._resolve_rust_typed_member_calls(graphify/extract.py, registered after theself.pass) evaluates that over the corpus and binds the call to the type's method,INFERRED0.85. Every step must be unique: a type or free function defined more than once is narrowed to the caller's file, then its crate; a method name must match one method across the type's impl blocks in that crate. A file's crate is the deepest crate root above it, the roots being the directories that hold asrc/of some.rsfile in the corpus (so atestsmodule insidesrc/and a crate's owntests//benches//examples/stay with it).Precision rules: a type written with a path only counts when the path is crate-local (
crate::,self::,super::), sincefs::DirEntryorwalkdir::DirEntrymust not reach the crate's ownDirEntry; a type parameter never names a type; a name rebound without a type (an untyped closure parameter,for x in,if let Some(x), a match arm, a tuple pattern) hides the outer binding from after its value on, sofor x in x.iter()still types thexinx.iter(). A non-selfreceiver with no known type no longer binds by bare name in-file.Type of change
Verification & Invariants
Invariant: an
x.m()edge goes to a method of the typexis declared or constructed with, found by unique names in the corpus; anything else gets no edge.Persisted state it could invalidate: AST cache entries for
.rsfiles, which lack the new raw-call and node facts._AST_CACHE_SCHEMA7 -> 8 retires them (test_schema_bump_retires_entries_cached_without_receiver_typesfails with the old schema). The three node markers are forwarded on changed-files rebuilds next to_rust_impl_keyinwatch.pyandcli.py.Against rust-analyzer 1.97.1 (go-to-definition at every call inside every
fn), 0.9.84 vs this branch, coldgraphify update <dir> --no-cluster --force,callsedges with both ends in.rsfiles:x.m()foundself.field.m()foundNew edges: ripgrep 1344 (1325 confirmed by rust-analyzer at the call site, 19 at sites it has no answer for), bat 87 (86 + 1), fd 156 (128 + 28, all
te.*()on fd's testTestEnv, which rust-analyzer does not resolve). None of the new edges contradicts rust-analyzer.Correct (caller, callee) pairs lost: ripgrep 54, bat 10, fd 4. All are in-file bare-name matches of an untyped receiver that happened to land right; the same rule removes 494 / 12 / 7 edges rust-analyzer does not confirm.
Changed-files rebuild vs full build (
watch._rebuild_code): ripgrep changingcrates/core/search.rs(callers) andcrates/searcher/src/searcher/mod.rs(a callee's file): 3715 / 3715 / 3715callsedges each; fd changingsrc/walk.rs: 316 / 316 / 316.Build time (measured on the 0.9.82 base, before rebasing onto 0.9.84): ripgrep, cold, 3 interleaved runs: 0.9.82 4.4-5.4 s (median 5.1), this branch 4.8-6.3 s (median 5.1).
tests/test_rust_typed_member_calls.py, 10 tests; 8 fail on 0.9.84;test_untyped_closure_parameter_hides_the_outer_bindingandtest_self_call_in_a_trait_default_method_still_bindspass on both (guards).test_for_and_if_let_values_still_read_the_outer_bindingandtest_crate_is_the_deepest_root_above_the_filecover the two review findings (they fail on this PR's first commit).Limitations:
Type::f()itself is not resolved across files (only used to type a receiver). Trait-typed receivers (&dyn Trait,impl Trait, generics) get no edge. Types reached through a path that is not crate-local (other_crate::Foo,use-renamed modules) get no edge. Iterator items,Option/Vec/HashMapelement types,if let Some(x),matchbindings and tuple destructuring are untyped. Two impl blocks of a type in one crate that both definemgive no edge.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