Skip to content

fix(rust): skip generic type parameters when collecting type references - #5680

Open
Max17190 wants to merge 2 commits into
Graphify-Labs:v8from
Max17190:fix/rust-type-parameter-references
Open

Max17190 wants to merge 2 commits into
Graphify-Labs:v8from
Max17190:fix/rust-type-parameter-references

Conversation

@Max17190

@Max17190 Max17190 commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Why

The Rust extractor emitted a references edge for every generic type parameter. R, T and F became phantom nodes, or bound to unrelated nodes such as a blanket impl<T> Trait for T. Fixes #5677.

Summary

_rust_type_params_in_scope collects the type and const parameters of an item, plus those of the enclosing impl or trait for associated items. _rust_collect_type_refs skips those names when they appear bare, so a qualified path such as tree::Node is still referenced. The Go, Kotlin, Swift, Scala and C++ extractors already skip type parameters.

A cold tauri build loses 1268 references edges and 321 sourceless nodes, and gains nothing. A cold Django build matches v8 byte for byte.

Limitations: existing graphs keep the old edges for unchanged Rust files until those files are extracted again, because the AST cache version is unchanged. Open #2963 skips Self in the same function, so whichever lands second needs a small rebase.

Test plan

python -m pytest tests -q -n 4 --dist loadfile   # 12640 passed
python -m pytest tests/test_rust_type_parameter_references.py -q   # 3 passed; all 3 fail on v8
uv run ruff check .                              # passes
uv run pyright --pythonpath .venv/bin/python     # same diagnostics as v8
uv run python -m tools.skillgen --check          # 134 artifacts match
graphify update .   # cold on tauri and Django, compared with v8
  • Read CONTRIBUTING.md
  • AI help disclosed in the commit trailer

_rust_collect_type_refs treated every type_identifier as a referenced
type, so `R` in `fn spawn<R: Runtime>(..) -> App<R>` produced a
references edge to a sourceless `R` stub, or to a real node with that
label such as a blanket `impl<T> Trait for T` or a `struct R` in
another file.

Collect the type and const parameters in scope, which are the item's own
list plus the enclosing impl or trait for associated items, and skip
them at every call site. The Go, Kotlin, Swift, Scala and C++
extractors already do this. Only a bare name is skipped, because a
qualified path such as `tree::Node` cannot name a type parameter.
Parameter lists are read in both the tree-sitter-rust 0.23 and 0.24
node shapes.

Fixes Graphify-Labs#5677

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Max17190
Max17190 requested a review from safishamsi as a code owner December 1, 2026 06:55
@github-actions github-actions Bot added the contributor Pull request from a returning community contributor label Dec 1, 2026
@github-actions

github-actions Bot commented Dec 1, 2026

Copy link
Copy Markdown

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

Looks safe to merge · Merge confidence 5/5

No issues reported · High impact

The Rust extractor now filters generic type and const parameters from collected references across signatures, declared types, trait bounds, and impls.

Code graph · 96 functions depend on this change
  • 7 of 666 test files are affected by this change.
  • Gate, test list and every flagged function: in the Graphify check.

Reviewed f1c4c7d · 1 earlier finding not re-checked

The built graph keeps one edge per node pair, so a leaked bare `Node`
parameter that lands on the same real `Node` struct merged with the
qualified `tree::Node` reference and the test could not see it. Count
the raw extraction edges by role instead.

Refs Graphify-Labs#5677

Co-Authored-By: Claude Opus 5.5 <[email protected]>

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.

Rust generic type parameters become references edges to phantom R, T and F nodes

1 participant