Skip to content

feat(rust): resolve x.method() and self.field.method() through the receiver's declared type - #4299

Open
rohit-jsfreaky wants to merge 3 commits into
Graphify-Labs:v8from
rohit-jsfreaky:feat/rust-typed-receiver-calls
Open

rohit-jsfreaky wants to merge 3 commits into
Graphify-Labs:v8from
rohit-jsfreaky:feat/rust-typed-receiver-calls

Conversation

@rohit-jsfreaky

@rohit-jsfreaky rohit-jsfreaky commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

Closes #4296.

extract_rust (graphify/extractors/rust.py) now records:

  • on each fn node, its return type: _rust_ret (-> Self, -> Foo, -> Box<Foo>/Arc<Foo>/Rc<Foo>) and _rust_ret_ok (the T of -> Result<T, _> / io::Result<T> / Option<T>);
  • on each struct node, its field types (_rust_fields; Box/Arc/Rc deref to the inner type);
  • on each x.m() raw call, how the receiver's type is found (rust_receiver): a typed parameter (closures included) or let, Type { .. }, a struct field, the return of T::f() / f() / y.m(), unwrapped by ? / .unwrap() / .expect(), through .clone().

_resolve_rust_typed_member_calls (graphify/extract.py, registered after the self. pass) evaluates that over the corpus and binds the call to the type's method, INFERRED 0.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 a src/ of some .rs file in the corpus (so a tests module inside src/ and a crate's own tests/ / benches/ / examples/ stay with it).

Precision rules: a type written with a path only counts when the path is crate-local (crate::, self::, super::), since fs::DirEntry or walkdir::DirEntry must not reach the crate's own DirEntry; 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, so for x in x.iter() still types the x in x.iter(). A non-self receiver with no known type no longer binds by bare name in-file.

Type of change

  • Bug fix
  • New feature
  • Documentation
  • Tests or CI
  • Refactor
  • Security fix

Verification & Invariants

Invariant: an x.m() edge goes to a method of the type x is 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 .rs files, which lack the new raw-call and node facts. _AST_CACHE_SCHEMA 7 -> 8 retires them (test_schema_bump_retires_entries_cached_without_receiver_types fails with the old schema). The three node markers are forwarded on changed-files rebuilds next to _rust_impl_key in watch.py and cli.py.

Against rust-analyzer 1.97.1 (go-to-definition at every call inside every fn), 0.9.84 vs this branch, cold graphify update <dir> --no-cluster --force, calls edges with both ends in .rs files:

repo all calls found x.m() found self.field.m() found wrong edges
ripgrep 48.2% -> 75.5% 21.9% -> 66.2% 21.2% -> 83.5% 532 (18.9%) -> 30 (0.8%)
bat 71.5% -> 79.8% 34.5% -> 58.3% 9.1% -> 63.6% 36 (5.0%) -> 24 (3.0%)
fd 35.8% -> 65.2% 5.6% -> 75.1% 1/2 -> 2/2 9 (5.4%) -> 2 (0.6%)

New 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 test TestEnv, 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 changing crates/core/search.rs (callers) and crates/searcher/src/searcher/mod.rs (a callee's file): 3715 / 3715 / 3715 calls edges each; fd changing src/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).

  • Read the CONTRIBUTING.md guide.
  • Reproduced the issue and identified the invariant.
  • Made the smallest fix necessary (one extractor, one resolver, the cache schema and the two marker lists).
  • Added a regression test: tests/test_rust_typed_member_calls.py, 10 tests; 8 fail on 0.9.84; test_untyped_closure_parameter_hides_the_outer_binding and test_self_call_in_a_trait_default_method_still_binds pass on both (guards). test_for_and_if_let_values_still_read_the_outer_binding and test_crate_is_the_deepest_root_above_the_file cover the two review findings (they fail on this PR's first commit).
  • Kept the PR description synchronized with the final implementation.
  • Documented any limitations / unsupported cases explicitly.

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 / HashMap element types, if let Some(x), match bindings and tuple destructuring are untyped. Two impl blocks of a type in one crate that both define m give 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:

python -m pytest tests/test_rust_typed_member_calls.py -q     # 10 passed (on 0.9.84: 8 failed, 2 passed)
python -m pytest tests/test_rust_*.py tests/test_cache.py -q    # 132 passed
python -m pytest tests -q                                       # with this PR and my two other open PRs applied together, absolute PYTHONPATH: 1 failed, 7093 passed, 32 skipped; clean 0.9.84: 1 failed, 7072 passed (the same test_3357_minimal_reproduction_no_config_emits_calls_edge), 0 new
python -m ruff check graphify tests/test_rust_typed_member_calls.py   # All checks passed
pyright graphify/extract.py graphify/extractors/rust.py graphify/cache.py graphify/cli.py graphify/watch.py tests/test_rust_typed_member_calls.py   # 161 errors, same 161 as 0.9.84, 0 new
bandit -ll graphify/extract.py graphify/extractors/rust.py graphify/cache.py graphify/cli.py graphify/watch.py   # 5 findings, same 5 as 0.9.84, 0 new

Graphify-specific checklist

  • I updated generated skill artifacts — not needed, no skill fragments touched.
  • I confirmed that AST/structural extraction remains deterministic.
  • I reviewed changes for security implications (no unsafe interpolation into shell/Python).
  • I confirmed that no API keys or local-only graph data are included.
  • I disclosed AI authorship in my commit messages.

🤖 Generated with Claude Code

https://claude.ai/code/session_01B8gwEpjajiWHVW3c9smuKf

@github-actions github-actions Bot added the contributor Pull request from a returning community contributor label Oct 10, 2026
@github-actions

Copy link
Copy Markdown

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.

@graphify-labs graphify-labs Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 / for bindings 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/examples modules — 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 — impact
  • tests/test_agents_platform.py — impact
  • tests/test_analyze.py — impact
  • tests/test_astro_extraction.py — impact
  • tests/test_astro_import_ids.py — impact
  • tests/test_blade_extractor.py — impact
  • tests/test_build.py — impact
  • tests/test_build_located_semantic_identity.py — impact
  • tests/test_build_merge_dedup_scope.py — impact
  • tests/test_build_merge_hyperedges_and_prune.py — impact
  • tests/test_build_merge_shrink_guard.py — impact
  • tests/test_builtin_global_type_refs.py — impact
  • tests/test_cache.py — impact
  • tests/test_cache_stale_import_target.py — impact
  • tests/test_carried_hyperedge_remap.py — impact
  • tests/test_case_sensitive_resolution.py — impact
  • tests/test_charmap_encoding.py — impact
  • tests/test_chunking.py — impact
  • tests/test_cjs_module_extension.py — impact
  • tests/test_cli_export.py — impact
  • tests/test_cloud_cta.py — impact
  • tests/test_cluster.py — impact
  • tests/test_cobol_extractor.py — impact
  • tests/test_codebuddy.py — impact
  • tests/test_confidence.py — impact
  • tests/test_corrupt_graph_json.py — impact
  • tests/test_cpp_method_declarations.py — impact
  • tests/test_cpp_nested_and_cli.py — impact
  • tests/test_cpp_objc_cross_file_calls.py — impact
  • tests/test_cross_extension_reexport_self_cycle.py — impact
  • tests/test_cross_language_call_resolution.py — impact
  • tests/test_cross_repo_external_call_guards.py — impact
  • tests/test_cross_repo_member_calls.py — impact
  • tests/test_csharp_call_site_generic_args.py — impact
  • tests/test_csharp_enum_members.py — impact
  • tests/test_csharp_field_generic_args.py — impact
  • tests/test_csharp_generic_callsites.py — impact
  • tests/test_csharp_interface_dispatch.py — impact
  • tests/test_csharp_member_calls.py — impact
  • tests/test_csharp_member_chain_calls.py — impact
  • tests/test_csharp_member_nodes.py — impact
  • tests/test_csharp_object_creation.py — impact
  • tests/test_csharp_partial_classes.py — impact
  • tests/test_csharp_tuple_type_refs.py — impact
  • tests/test_csharp_type_resolution.py — impact
  • tests/test_dedup.py — impact
  • tests/test_dedup_remaps_hyperedges.py — impact
  • tests/test_dedup_shrink_refuses_force_write.py — impact
  • tests/test_definition_file_portability.py — impact
  • tests/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)

…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).

Comment thread graphify/extract.py
return "/".join(parts[:-1])


def _resolve_rust_typed_member_calls(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Health regression — _resolve_rust_typed_member_calls()

fans out to 7 callees (efferent coupling).

Grounded coupling-delta finding (deterministic), not an LLM guess.

Comment thread graphify/extract.py
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:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Health regression — _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:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Health regression — 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.

@rohit-jsfreaky

Copy link
Copy Markdown
Contributor Author

if let / for bindings hide the outer name in their own value expression
_rust_crate_dir picks the innermost src/tests dir, splitting crates with nested tests/examples modules

Both confirmed and fixed in da617cb.

  1. The new x of for x in x.iter() / if let Some(x) = x.next() / a match arm now starts after its value (after the pattern for a match arm), so the value's own x keeps the outer binding's type.
  2. The crate of a file is now the deepest crate root above it, the roots being the directories that hold a src/ of some .rs file in the corpus. That keeps crates/core/src/tests/x.rs in crates/core, and also fixes a checkout that itself sits under a folder named src, which a "last src" rule would have merged into one crate.

Tests: test_for_and_if_let_values_still_read_the_outer_binding, test_crate_is_the_deepest_root_above_the_file (both fail on 0a40a0e). ripgrep / bat / fd edges unchanged; changed-files rebuild == full build (ripgrep, changing crates/searcher/src/searcher/mod.rs: 3715 / 3715 / 3715).

The three coupling notes (extract_rust, _resolve_rust_typed_member_calls, _eval) are the size of the new pass; the evaluator is one dispatch over the receiver-description kinds, kept in one place on purpose.

@Graphify-Labs please re-review.

@rohit-jsfreaky
rohit-jsfreaky force-pushed the feat/rust-typed-receiver-calls branch from da617cb to 77cfdd0 Compare October 12, 2026 17:45
@rohit-jsfreaky

Copy link
Copy Markdown
Contributor Author

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 (use std::fs::DirEntry;) bound to a same-named local type. Now a type imported from std/core/alloc never binds to a local type, and one imported from another crate binds only when that crate is part of the corpus (dir name or [package]/[lib] name in Cargo.toml). A use applies to its own module only. 4 new tests (test_a_type_imported_from_std_never_binds_to_a_same_named_local_type and three more). bat, fd and ripgrep give the same calls edges as before, checked against rust-analyzer (bat 732, fd 278, ripgrep 3527 correct). Full suite with my other open PRs applied: 4 failed, 7603 passed; the same 4 fail on clean 0.9.87 on my machine.

@rohit-jsfreaky
rohit-jsfreaky force-pushed the feat/rust-typed-receiver-calls branch 3 times, most recently from 39adc1e to ba0b659 Compare October 15, 2026 16:53
rohit-jsfreaky and others added 3 commits October 18, 2026 23:19
…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
@rohit-jsfreaky
rohit-jsfreaky force-pushed the feat/rust-typed-receiver-calls branch from ba0b659 to 2cb423c Compare October 18, 2026 17:56
gabrielcowley pushed a commit to gabrielcowley/graphify-gabe that referenced this pull request Oct 22, 2026
…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
gabrielcowley pushed a commit to gabrielcowley/graphify-gabe that referenced this pull request Oct 22, 2026
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
gabrielcowley pushed a commit to gabrielcowley/graphify-gabe that referenced this pull request Oct 25, 2026
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

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor Pull request from a returning community contributor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Rust: x.method() and self.field.method() get no calls edge across files, and in-file they bind by bare name

1 participant