Skip to content

fix(rust): drop the Self keyword from type references so it stops minting a god node - #2963

Open
rajatnagda45 wants to merge 1 commit into
Graphify-Labs:v8from
rajatnagda45:fix/rust-self-phantom-node
Open

rajatnagda45 wants to merge 1 commit into
Graphify-Labs:v8from
rajatnagda45:fix/rust-self-phantom-node

Conversation

@rajatnagda45

Copy link
Copy Markdown
Contributor

What

The Rust extractor treats the Self keyword in type position as an ordinary type reference, which manufactures a false god node.

_rust_collect_type_refs matches Self as a plain type_identifier and emits it as a referenced type. Because Self is never declared in any file, ensure_named_node mints a sourceless stub whose id normalises (via ids.normalize_id) to a single global self node. Every fn new() -> Self, builder method returning -> Self, and &Self parameter/field across the whole crate then rewires onto that one stub — so self becomes a hub wired to essentially every constructor in the codebase.

Self is a keyword alias for the enclosing impl/trait type; it is not a referenceable type of its own, so no node should be emitted for it (just like the primitive_type case already returns early).

Reproduce

// shape.rs
pub struct Circle { r: f64 }
impl Circle {
    pub fn new(r: f64) -> Self { Circle { r } }
    pub fn scaled(&self, k: f64) -> Self { Circle { r: self.r * k } }
}

Before this change extract_rust returns a node labelled Self and references edges pointing at the normalised self id. In a real multi-impl crate all of those collapse onto one global node.

Fix

Skip Self in the type_identifier branch of _rust_collect_type_refs, exactly like the primitive types above it. Genuine types are untouched, and associated types such as Self::Item (which arrive as scoped_type_identifier, resolving to Item) keep resolving as before.

Tests

Adds test_rust_self_return_type_does_not_create_phantom_node asserting no Self node and no edge targeting the self stub, while the real type is still extracted. Full suite is green locally (only the pre-existing order-dependent flake in test_label_communities_batches_when_over_batch_size, #2877, is unrelated).

…inting a god node

`_rust_collect_type_refs` treated the `Self` in `-> Self`, `&Self`, and field
positions as an ordinary `type_identifier`. `Self` is a keyword alias for the
enclosing impl/trait type, not a referenceable type, and it is never declared in
any file -- so `ensure_named_node` minted a SOURCELESS stub whose id normalises
to a single global `self` node. Every `fn new() -> Self`, builder `-> Self`, and
`&Self` across the crate then rewired onto that one stub, manufacturing a false
god node wired to every constructor.

Skip `Self` the same way primitive types are already skipped. Real types (and
associated types like `Self::Item`, which arrive as `scoped_type_identifier`)
are unaffected.

Adds a regression test asserting no `Self` node and no edge to the `self` stub.

@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.

Looks safe to merge — no coupling regressions and no blocking issues, checked against the code graph (not a self-assessment).

Formal verification. No changes could be formally verified in this run.


Graphify review — findings

Skips the Self keyword in _rust_collect_type_refs so it no longer mints a SOURCELESS stub that collapses into a single global self node linked to every constructor/builder. Adds test_rust_self_return_type_does_not_create_phantom_node covering -> Self and &self return types.

No blocking issues surfaced. 1 lower-confidence candidate did not survive cross-model review.

Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 104 functions depend on the 104 functions this change touches.

Health — this change adds coupling hotspots:

  • new: extract_rust() — 17 callers, 6 callees
  • new: walk() — 1 callers, 8 callees

Verification — 104 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: 104 function(s) in the blast radius were not formally verified this run

Formal verification

Could not verify: Could not verify \_rust\_collect\_type\_refs.

The verifier did not have enough to check \_rust\_collect\_type\_refs, 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: not verifiable: all 200 sampled inputs raised on both versions — the function never executed, so 'no divergence' would be vacuous (mostly AttributeError — names the real obstacle, not a sampling gap)

· 2 more finding(s) on lines outside this diff (see the check run).

@rajatnagda45

Copy link
Copy Markdown
Contributor Author

Hi @safishamsi — small self-contained extractor fix here. Ran into the phantom self node while mapping a Rust crate (every constructor was wiring into one hub). Fix mirrors the existing primitive_type skip and adds a regression test. Happy to adjust naming or add a fixture if you'd prefer it in sample.rs. Thanks for taking a look!

safishamsi added a commit that referenced this pull request Sep 5, 2026
The #3345 ghost-merge fix cited #2963 (an unrelated Rust Self-keyword bug)
in its comments and test docstrings; the issue it actually resolves is #3344.

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant