Repository navigation
fix(c): extract structs and their fields instead of dropping the whole type layer - #2971
rajatnagda45 wants to merge 1 commit into
Conversation
…e type layer The C config set `class_types=frozenset()`, so every `struct` -- the primary data-modeling construct in C -- was dropped from the graph along with its fields. A C codebase therefore lost its entire type layer, while C++ (using the same generic extractor) captured structs and fields fine. - Add `struct_specifier` to the C config's `class_types`, mirroring C++. - Let the shared `field_declaration` branch run for `tree_sitter_c` too, selecting `_c_collect_type_refs` for field type references (the branch was hard-gated to `tree_sitter_cpp`). - Teach `_c_collect_type_refs` to resolve a bare aggregate tag (`struct Point p`, `union U u`) to its name, so struct-typed fields, parameters, and return values reference the struct -- C omits the tag keyword far less often than C++, so these were previously invisible. Enums/unions-as-definitions remain out of scope (enum_specifier is not in C++'s class_types either). Adds a regression test covering struct nodes, field `defines` edges, and a struct-typed field reference.
There was a problem hiding this comment.
Graphify reviewed this change.
Worth a look — the grounded gate found no coupling regressions or blocking issues, but 1 advisory finding(s) below merit a look before merge.
Formal verification. No changes could be formally verified in this run.
Graphify review — findings
Adds C struct_specifier to the C language config's class_types so structs and their fields are emitted as nodes/edges instead of being dropped, restoring the type layer for C codebases. Routes C field declarations through _extract_generic's struct/field path (reusing the C++ grammar) with _c_collect_type_refs, and extends that collector to resolve bare struct/union/enum tag references. Adds test_c_struct_and_fields_are_extracted covering struct nodes, field edges, and struct-typed field references.
Worth a look
- C function-pointer struct fields are skipped as if they were C++ methods —
graphify/extractors/engine.py:3980· Escalate · medium- agreed by 2 of 2 members but NOT verified (no proof, no reproducing execution) — consensus is not a verdict; needs human review
Analysis details — impact, health, verification
Impact & health
Graphify review
Impact — 2063 functions depend on the 920 functions this change touches.
Health — this change adds coupling hotspots:
- new:
extract()— 474 callers, 42 callees - new:
_rebuild_code()— 98 callers, 50 callees - new:
_extract_generic()— 18 callers, 24 callees - new:
extract_xaml()— 19 callers, 17 callees - new:
extract_objc()— 27 callers, 9 callees - new:
extract_js()— 80 callers, 3 callees - new:
dispatch_command()— 2 callers, 119 callees - new:
_get_extractor()— 26 callers, 6 callees - …and 32 more — each is listed as a finding
Verification — 2063 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: 1915 function(s) in the blast radius were not formally verified this run
Formal verification
Could not verify: Could not verify \_c\_collect\_type\_refs.
The verifier did not have enough to check \_c\_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)
Could not verify: Could not verify \_extract\_generic.
The verifier did not have enough to check \_extract\_generic, 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: parameter `path` is annotated `Path` — outside the synthesizable primitive/collection set
· 40 more finding(s) on lines outside this diff (see the check run).
C# was the only language with a class-shaped type layer whose state was missing from the graph. A field or property produced a `references` edge to its type and no node of its own, so nothing could point at a member. C++ has emitted a node per data member with a `defines` edge for a while, Graphify-Labs#2971 is adding the same for C structs, and Graphify-Labs#2220 gave Swift computed properties nodes. This puts C# on that line, using the same relation and `context="field"` as the C++ branch. The member node does not depend on what the member is typed as, so it is emitted before the type checks: a primitive and a generic parameter both leave a member behind even though neither produces a type reference. Properties keep landing on `defines` rather than `method`, since a property is state, not a call target. Cost on a 1457-file .NET service: 9925 -> 15489 nodes and 29547 -> 34989 edges, +56% and +18%. It is a DTO-heavy corpus, which is where that ratio comes from. The added nodes are leaves, so the hub structure is unchanged: the top god nodes are identical except ProductService moving 259 -> 263 edges. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01NCycXc9pjGzovxrZqojPUE
What
The C extractor dropped every
struct— and all their fields — from the graph._C_CONFIGsetclass_types=frozenset(), so structs were never emitted as nodes. In C thestructis the primary data-modeling construct, so this erased the entire type layer of a C codebase: no struct nodes, no field edges, and functions couldn't reference the structs they take or return. C++ — using the same_extract_genericengine — captured structs and fields correctly, so this was a C-only gap.Reproduce
Before: only
area()is emitted.Point,Rect, and every field are absent.Fix
Three small, symmetric changes that reuse the existing C++ path:
struct_specifierto the C config'sclass_types(mirrors C++).field_declarationbranch run fortree_sitter_cas well, selecting_c_collect_type_refsfor field type references (it was hard-gated totree_sitter_cpp)._c_collect_type_refsto resolve a bare aggregate tag (struct Point p,union U u) to its name — C keeps thestruct/unionkeyword in type position far more often than C++, so those references were invisible.After:
PointandRectare nodes;Point defines x/y,Rect defines w, andRect references Point(field), plusarea references Rect(parameter) all resolve — matching C++.enum_specifieris intentionally left out (it isn't in C++'sclass_typeseither), so enum handling stays consistent across the two languages and out of scope here.Tests
Adds
test_c_struct_and_fields_are_extractedcovering struct nodes, fielddefinesedges, and a struct-typed field reference. Full suite green locally except the pre-existing order-dependent flaketest_label_communities_batches_when_over_batch_size(#2877), which passes in isolation and is unrelated.