Skip to content

fix(rust): give each colliding impl block member its own node - #5380

Closed
ayushcodes10 wants to merge 1 commit into
Graphify-Labs:v8from
ayushcodes10:fix-rust-impl-method-collision
Closed

ayushcodes10 wants to merge 1 commit into
Graphify-Labs:v8from
ayushcodes10:fix-rust-impl-method-collision

Conversation

@ayushcodes10

Copy link
Copy Markdown
Contributor

Bug

make_id casefolds and strips underscores. File level Rust items already get collision protection for this (#3302: fn ignore / struct Ignore, fn e / fn E), but a method, associated const or static inside one impl block did not: rust.py's walk built its id as plain _make_id(parent_impl_nid, name) with no check at all. Two members of one type differing only by a leading _ or by case, such as foo and _foo, minted one node; the second declaration overwrote the first, and its own body's calls were credited to the first member instead.

Found this by auditing which of graphify's extractor languages still lack the _name/name/case fold member collision fix already shipped for Solidity, Java, Dart, C++, Swift, Kotlin, Ruby, Go, Elixir, Scala and Lua. Rust had it for file level items but not impl block members. No filed issue; confirmed directly with a repro.

Reproduction

struct Svc;
impl Svc {
    fn foo(&self) { self.helper(); }
    fn _foo(&self) { self.other(); }
    fn helper(&self) {}
    fn other(&self) {}
}

graphify extract --code-only on unmodified v8: 5 nodes, one .foo() node whose edges include a call to .other() that should belong to ._foo(), which never exists.

Fix

  • Extends the existing type level pre scan (_scan_type_items's impl_item branch) to also collect, per impl block, the direct method/const/static member names, grouped by the id each name's own spelling would fold to (the same key shape items_by_id already uses for file level items, one level down).
  • Adds impl_member_nid, mirroring file_item_nid just above it minus the declared type carve out (a member has no type of its own to prefer keeping stable) and the decl_registry hop (impl members are never re declared the way a trait signature plus its impl are). With no privileged member to defer to, every colliding member is salted, matching how file level items with no declared type in their own collision group are handled today.
  • Threads a new parent_impl_pre_nid through walk() alongside the existing parent_impl_type/parent_impl_key, so the lookup key stays correct even on the rare path where the type's own id was itself salted by a file level collision.
  • Several impl blocks of one type share one member set (an id a method in one block would get still collides with a sibling declared in a different block of the same type), covered by a test.
  • Scoped to methods, associated consts and statics inside impl blocks, which is everything that goes through the one _make_id(parent_impl_nid, name) call site this bug lives in. Trait declarations are a separate code path and are not touched.

Tests

New tests/test_rust_impl_method_collisions.py, mirroring the existing test_rust_case_collisions.py precedent:

  • The repro's own shape: colliding methods get separate nodes, each keeps its own call edges, with an explicit check against cross contamination.
  • A non colliding pair is unaffected (same ids as a build with no collision in the block).
  • The same collision split across two separate impl blocks of one type.
  • An associated const colliding with a method name.
  • A pure case collision (no leading underscore), confirming neither member keeps the plain id, matching the existing file level test_case_only_functions_are_both_salted.
  • A deleted colliding method now counts as one real node fewer, not zero.

Verification

  • All 6 new regression tests fail against unmodified upstream/v8 (confirmed via git stash) and pass against the fix; the non colliding control test passes unmodified, as expected.
  • Full suite: 2 failed, 11642 passed, 234 skipped, 1 xfailed — both failures (test_erlang_extractor.py, test_r_extractor.py) confirmed pre existing on unmodified upstream/v8 in this environment, unrelated to this change.
  • python3 -m tools.skillgen --check: check OK: 134 artifact(s) match committed output and expected/.

make_id casefolds and strips underscores, and a method, associated
const or static inside one impl block went straight through
_make_id(parent_impl_nid, name) with no collision check, unlike
file level items which already got this treatment for Graphify-Labs#3302. Two
members of one type differing only by a leading underscore or by
case, such as foo and _foo, minted one node, the second declaration
overwrote the first, and its own body's calls were credited to the
first member instead.

Pre scan each impl block's direct members (methods, consts, statics)
during the existing type level scan, grouped by the id each member's
own name would fold to, the same way file level items are grouped by
_make_id(stem, name). A collision within one type's member set is
then told apart from an unrelated file level collision, and several
impl blocks of one type share the same member set, so a split
between blocks still collides. With no declared type to defer to
inside an impl block, every colliding member is salted, matching
how file level items with no declared type in their own group are
handled today.
@github-actions github-actions Bot added the contributor Pull request from a returning community contributor label Nov 21, 2026
@github-actions

Copy link
Copy Markdown

Thanks for the pull request, @ayushcodes10. 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.

@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 review View in Graphify

Review before merging · Merge confidence 4/5

1 bug · 6 possible issues to check · High impact

The new tests check graph nodes and call edges for Rust impl members whose names normalize to the same ID.

P2  A colliding type can salt another type’s unrelated method · rust.py:459

6 possible issues we couldn't confirm

They don't change the score.

What this review covered
  • Some lookups asked for files or lines that do not exist; the review was told and carried on.
  • 2 of 2 changed files inspected. This is scope, not a correctness guarantee.
Code graph · 99 functions depend on this change
  • 1 function became more coupled. walk() (1 callers).
  • Gate, test list and every flagged function: in the Graphify check.

Reviewed cd977a8 · Full report in the Graphify check

Comment on lines +456 to +459
continue
member_name_node = child.child_by_field_name("name")
if member_name_node is None:
continue

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2  A colliding type can salt another type’s unrelated method

When two type names normalize to the same ID, a collision in one type can change the ID of a method in the other type, even when that method has no colliding sibling.

Key the member collision census in graphify/extractors/rust.py by the resolved parent impl ID.

Evidence · checked against the code

Expected: Only a member with a colliding sibling of its own type receives a salted ID.
Actually: The member census is keyed by the shared normalized pre-disambiguation type ID, so _Foo::foo is salted using Foo’s collision even though _Foo has no colliding sibling.

  • Independent source review: Read the existing Rust impl-member collision test. It checks colliding names within one type and checks non-colliding methods in that same type, but does not cover two type names that normalize to one pre-disambiguation ID; it therefore does not refute this case. The ID normalizer’s documented behavior confirms that leading underscores are stripped.
Prompt to fix with AI
In graphify/extractors/rust.py, impl_member_nid (lines 456-459):
Problem: A colliding type can salt another type’s unrelated method
Expected: Only a member with a colliding sibling of its own type receives a salted ID.
Actually: The member census is keyed by the shared normalized pre-disambiguation type ID, so `_Foo::foo` is salted using `Foo`’s collision even though `_Foo` has no colliding sibling.
Fix it at the cause, and add a test that fails without the fix.

Graphify · Checked against the code · View in Graphify

safishamsi added a commit that referenced this pull request Nov 21, 2026
…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]>
@safishamsi

Copy link
Copy Markdown
Member

Landed in v0.9.115 via an authorship-preserving cherry-pick. Each colliding impl-block member now gets its own salted node id instead of overwriting a sibling. One maintainer tweak on merge: folded the AST cache schema note in (the change needed the schema bump so cached Rust files re-extract). Thanks @ayushcodes10!

@safishamsi safishamsi closed this Nov 21, 2026
safishamsi pushed a commit that referenced this pull request Nov 23, 2026
…n node

make_id casefolds and strips leading and trailing underscores, and a
method inside one @interface, @implementation or @protocol went
straight through _make_id(container, name) with no collision check,
unlike every other object oriented extractor (#3302, #4415, #5058,
#5151, #5380). Two methods of one container differing only by a
leading underscore or by case, such as setup and _setup, a common
convention for a public method and its private helper, minted one
node, the second declaration overwrote the first, and its own body's
calls were credited to the first method instead.

Pre scan each @interface, @implementation and @protocol's direct
method names during a pass over the file, grouped by the id each
name's own spelling would fold to, the same way file level items are
grouped elsewhere in the codebase. A collision within one container's
method set is then told apart from an unrelated collision in a
different container that happens to share a selector name. The
existing shared salting rule applies unchanged: the one public,
non underscore prefixed name keeps the plain id when the group has
exactly one such name, every other spelling is salted.

(cherry picked from commit 6bababc)
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.

2 participants