Rust: `const _` gets its file's node ID, so the file node is relabelled `_` and gains a self-loop
Maintainers usually reply within 1 day
Nobody has claimed this yet.
- #4108 by @xiehuanyi — closed without merging
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 78/100
Research direction
Start in extractors/rust.py at the static_item / const_item branch, then read _make_id, make_id, normalize_id, and _file_node_id to trace the collision. Reproduce with the supplied src/codec.rs and the extract() and build_from_json() entry points. Done means the file keeps its own node identity and label, anonymous constants do not create a file-node collision, and no self-loop is produced.
Written by the indexing model from the issue text.
Description
Version: graphifyy 0.9.69
An anonymous Rust constant (const _: () = assert!(...);, the usual compile-time assertion) gets the same node ID as the file that declares it. When the graph is built, the constant's label and location replace the file node's, and the file's contains edge to the constant becomes a self-loop.
Repro, src/codec.rs:
use core::fmt;
pub const WIDTH: usize = 8;
const _: () = assert!(WIDTH == 1 << 3);
pub fn encode() {}
from pathlib import Path
from graphify.extract import extract
from graphify.build import build_from_json
r = extract([Path("src/codec.rs")], cache_root=Path("."))
G = build_from_json(r, root=".", directed=False)
extract() emits two nodes with the ID src_codec:
N src_codec 'codec.rs' L1
N src_codec '_' L5
E src_codec contains src_codec L5
After build_from_json, G.nodes["src_codec"] has label _ and source_location L5, and (src_codec, src_codec) is a self-loop.
Cause: extractors/rust.py (the static_item / const_item branch) builds the ID with _make_id(stem, item_name). make_id strips _ from each part, so the name _ becomes empty, the join gives src_codec_, and normalize_id strips the trailing underscore. The result is the bare stem, which is also what _file_node_id returns for the file.
Effect on a real project: the file node is shown as _. Every import and contains edge of the file is attached to it, so a module with a few imports ranks as a god node and a cross-community bridge in GRAPH_REPORT.md, and the graph health check reports a self-loop.
Possible fix: skip const _ / static _ in the Rust extractor, since an anonymous constant can't be referenced. Alternatively, have make_id refuse a part that strips to empty, so no symbol can collapse onto its file's ID.
- Dominant language
- Python
- Stars
- 124k
- Forks
- 11.9k
- PR merge metrics
- No merged PRs in 30d
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from Graphify-Labs/graphify
-
[Bug]: changed-files rebuild (hook/watch) evicts placeholder nodes for files that were never scannedPossibly taken @rohit-jsfreaky claimed this today. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
Graphify-Labs/graphify#4160 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
Graphify-Labs/graphify#3763 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Graphify-Labs/graphify#3638 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Graphify-Labs/graphify#3611 · 1 comment ·
Maintainers usually reply within 1 day
-
Nix supportOpen
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
Graphify-Labs/graphify#3193 · 2 reactions ·
Maintainers usually reply within 1 day
All issues in Graphify-Labs/graphify
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
Maintainers usually reply within 1 day
-
area:docs
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
RailtownAI/railtracks#1633 ·
Maintainers usually reply within 2 days
-
review-panel severity:low
Difficulty 1/5 Under an hour Newbie friendliness 85/100
kristovatlas/coin-accounting#152 ·
Maintainers usually reply within 1 day
-
documentation :blue_book:
Difficulty 1/5 Under an hour Newbie friendliness 88/100
PennyLaneAI/pennylane#10280 ·
Maintainers usually reply within 2 days
-
`pipx reinstall` prints a Python traceback when the reinstall failsPossibly taken @ParamTanna claimed this today. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day