Repository navigation
Description
Summary
For C/C++/ObjC, a symbol declared in Foo.h and defined in the sibling Foo.cpp is deliberately collapsed into one node keyed to the header (_merge_decl_def_classes, #1547/#1556). That merge is correct and I am not asking to change it — downstream resolvers need exactly one definition node.
The problem is that the merge discards the impl node entirely, so nothing in the graph records where the symbol is actually implemented. The surviving node's source_file/source_location name the declaration, and the definition's file and line — the thing a reader asking "where is this implemented?" wants — are lost with the dropped node.
Same class of harm as #2092 (a symbol whose reported source_location isn't where it lives), different cause.
Repro
Two files, no config:
// foo.h
class Foo {
public:
void Alpha();
void Beta();
};// foo.cpp
#include "foo.h"
void Foo::Alpha() { Beta(); }
void Foo::Beta() { }$ graphify update .
[graphify watch] Rebuilt: 5 nodes, 7 edges, 2 communities
graph.json:
| label | source_file | source_location | id |
|---|---|---|---|
Foo |
foo.h | L3 | foo_foo |
Alpha |
foo.h | L4 | foo_foo_alpha |
Beta |
foo.h | L5 | foo_foo_beta |
foo.h |
foo.h | L1 | foo_h_foo |
foo.cpp |
foo.cpp | L1 | foo_cpp_foo |
foo.cpp contributes only its file node. Foo::Alpha() at foo.cpp L2 and Foo::Beta() at L3 are gone, and no attribute anywhere points at them.
Expected: the merged node keeps naming the declaration (that is the design), but the definition site remains reachable from it.
Also: the drop is silent — no note or warning on any verbosity. _report_id_collision in dedup.py would warn about a two-file id collision, but this merge happens earlier, in extract(), so nothing is reported.
Renaming the impl file so the stems differ (fooimpl.cpp) keeps all 4 nodes, which confirms the path: the ids collide only because both stems slugify to foo.
Why it matters
The merge fires for the ordinary C++ layout — declarations in a header, definitions in the sibling .cpp — so it is the common case, not an edge case. On a 1,767-file C++ codebase I measured, 541 of 700 implementation files larger than 3 KB contribute nothing but their file node; one 188 KB .cpp holds 198 method definitions whose lines are all unreachable from the graph.
The practical cost is that get_node answers "where is this implemented?" with a header line number, and the reader then has to scan a very large .cpp by hand. Call edges and symbol coverage are unaffected — the surviving node keeps the id, so edges still land correctly (I verified edge density is identical between a merged class and an unmerged one). This is purely a loss of provenance.
Proposed fix
Record the dropped impl node's provenance on the survivor before discarding it:
definition_file/definition_locationon the merged nodeget_nodeprints aDefined in:line when present
Additive only: id, label, source_file, node count and edges are all unchanged, so no existing graph is re-keyed and the single-definition guarantee the resolvers depend on is untouched. When several impls fold onto one header (ObjC categories) the choice is deterministic — lowest (source_file, source_location) — so it does not depend on node arrival order.
Alternatives I considered and rejected:
- Let the definition win the merge (survivor becomes the
.cppnode). Smallest diff, but the surviving label flips fromAlphatoFoo::Alpha(), which breaks existing bare-name lookups. - Keep both nodes, disambiguate the impl id (the shape used for Go in Go: case-only sibling symbols (
Run/run) collapse to one node id — the unexported half vanishes and its call sites bind to a same-named function in another package #2779, plus adefinesedge). Nothing gets re-keyed, but node counts grow substantially on a header-heavy C++ repo and it needs an edge-resolution policy for which of the two calls should target.
Happy to switch to either if you prefer one — the additive version just seemed like the smallest change that fixes the reported harm.
Environment
- reproduces on
v8@b2cd362(0.9.48, current default branch) and on the released 0.9.46 - Python 3.12.3, tree-sitter 0.25.2, Linux
- AST-only build, no LLM backend configured
PR follows.
Activity
fix(extract): keep the definition site when a decl/def pair is merged (…
chore: bump to 0.9.49
safishamsi commentedon Aug 24, 2026
Fixed in v0.9.49: https://github.com/Graphify-Labs/graphify/releases/tag/v0.9.49. Closing as resolved.
fix(build): keep definition_file repo-relative like source_file (Grap…
fix(build): make definition_file portable, like its sibling source_fi…