Skip to content

fix(go): extract package-level var/const as nodes (#2360) - #2364

Open
HaoChiBao wants to merge 2 commits into
Graphify-Labs:v8from
HaoChiBao:fix/go-package-level-var-const-2360
Open

HaoChiBao wants to merge 2 commits into
Graphify-Labs:v8from
HaoChiBao:fix/go-package-level-var-const-2360

Conversation

@HaoChiBao

Copy link
Copy Markdown

Summary

  • Emit nodes and contains edges for Go package-level var/const declarations (including parenthesized blocks and multi-name specs), matching how type_declaration is handled.
  • Add in-file references edges when functions use those symbols, and resolve unique-label cross-file uses as references (not calls) via an opt-in relation/context on raw_calls.
  • Fixes Go: package-level var/const declarations are not extracted as nodes (skews query vocabulary in mixed Go/TS repos) #2360 — without this, Go domain constants/policy data are missing from the graph and vocabulary seeding skews toward languages that already index consts.

Test plan

  • pytest tests/test_go_package_level_vars.py (issue repro: nodes, blank _, in-file + cross-file refs)
  • pytest tests/test_go_builtin_call_targets.py tests/test_multilang.py -k go
  • Broader extract/symbol suite still green (92 passed)
  • Maintainer: spot-check a mixed Go/TS repo that affected/query can see package-level consts

Go package-level var/const were skipped by extract_go, so domain
constants and policy data never entered the graph. Emit nodes and
contains edges for those declarations, plus references edges for
in-file and cross-file uses.

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

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

Graphify reviewed this change.

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


Graphify review — findings

This PR adds Go package-level var/const declarations as graph nodes in the Go extractor, emitting them as identifiers contained by the file (including parenthesized blocks and multi-name specs, while skipping blank identifiers). It also introduces references edges from callers to these package-level symbols, both for in-file uses (resolved directly) and cross-file uses (deferred via the raw_calls resolution path). To support non-call relation types, the generic edge-emitting logic in extract.py was generalized to read relation/context from the raw call dict, defaulting to the previous calls/call behavior. A new test file covers node emission and reference edges across these scenarios.

Worth a look

  • Field/selector identifiers on RHS of selector_expression counted as package-level references — graphify/extractors/go.py:456 · Escalate · medium
    • agreed by 2 of 2 members but NOT verified (no proof, no reproducing execution) — consensus is not a verdict; needs human review
  • Package-level identifier reference may collide with local variable of same name — graphify/extractors/go.py:458 · 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 — 1229 functions depend on the 206 functions this change touches.

Health — this change adds coupling hotspots:

  • worse: extract() — 353 callers, 28 callees
  • worse: extract_go() — 20 callers, 3 callees

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

· 1 grounded finding(s) anchored inline below; 1 more finding(s) on lines outside this diff (see the check run).

Comment thread graphify/extractors/go.py
@@ -80,7 +80,7 @@ def _go_collect_type_refs(node, source: bytes, generic: bool, out: list[tuple[st
_go_collect_type_refs(c, source, generic, out)

def extract_go(path: Path) -> dict:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Health regression — extract_go()

20 callers depend on it (afferent coupling).

Grounded coupling-delta finding (deterministic), not an LLM guess.

@HaoChiBao

Copy link
Copy Markdown
Author

Reviewer notes

Happy to adjust anything — writing this up so the change is easy to evaluate.

Why this exists

extract_go only walked function_declaration / method_declaration / type_declaration / import_declaration. Package-level var / const never became nodes, so:

  • Go enums / sentinels / policy constants were invisible to query / vocab seeding
  • Mixed Go+TS repos skewed toward frontend constants (TS already indexes lexical_declaration)

Same bug class as the accepted Kotlin/Java enum-constant fix (#1700), applied to Go. Issue has a minimal 2-file repro.

What changed (3 files)

1. graphify/extractors/go.py (main fix)

  • New var_declaration / const_declaration branch in walk(), mirroring type_declaration → type_spec
  • One node per declared name (var_spec / const_spec, including parenthesized blocks and a, b = 1, 2)
  • IDs use _make_id(pkg_scope, name) like types, so same-package symbols share a stable id across files
  • Skips blank _
  • Function bodies still return early from walk(), so function-local var/const are not indexed (module-level only)
  • In-file uses → references (EXTRACTED) via package_level_nids
  • Cross-file uses → raw_calls with relation: references / context: identifier, resolved by the existing unique-label pass (same god-node guard as calls)

2. graphify/extract.py (tiny, opt-in)

  • Shared cross-file pass used to hardcode relation: calls / context: call
  • Now: rc.get(relation) or calls (same for context)
  • No other extractor sets relation on raw_calls today, so this is a no-op for every other language

3. tests/test_go_package_level_vars.py

Blast radius

Surface Impact
Non-Go languages Unchanged (opt-in relation defaults to calls)
Existing Go calls / builtins Untouched — call path + _GO_PREDECLARED_FUNCS still as before
Nested locals Not emitted (walk never enters function bodies for decls)
Cross-file refs Only unique labels; ambiguous names still skipped

Residual tradeoff (same class as existing cross-file call resolution): a local identifier that uniquely matches a package-level symbol name elsewhere can get an INFERRED references edge. Happy to tighten (e.g. exported-only / same-package heuristic) if you prefer.

Suggested review path

  1. graphify/extractors/go.py — the new var_declaration/const_declaration block (~30 lines), then the identifier arm in walk_calls
  2. graphify/extract.py — the 5-line relation/context default
  3. Skim tests/test_go_package_level_vars.py::test_go_cross_file_const_reference_edge — that's the issue repro
pytest tests/test_go_package_level_vars.py tests/test_go_builtin_call_targets.py -q

Thanks for taking a look.

Keep package-level var/const extraction and main's Go import-path map plus 0.85 inferred scores.

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

Worth a look — the grounded gate found no coupling regressions or blocking issues, but 2 advisory finding(s) below merit a look before merge.

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


Graphify review — findings

Emits Go package-level var/const declarations as nodes contained by their file, handling parenthesized blocks and multi-name specs while skipping blank identifiers. Adds references/identifier edges for in-file uses of those symbols and queues unknown identifiers as cross-file raw_calls, deduped per caller so hot locals like err don't flood. Threads a per-call relation/context through extract's edge builder, defaulting to calls/call so existing emitters are unchanged.

Worth a look

  • Go package-level reference extraction ignores local shadowing — graphify/extractors/go.py:545 · Escalate · medium
    • agreed by 2 of 2 members but NOT verified (no proof, no reproducing execution) — consensus is not a verdict; needs human review
  • Go local variables are exported as unresolved package references — graphify/extractors/go.py:555 · 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 — 1788 functions depend on the 248 functions this change touches.

Health — this change adds coupling hotspots:

  • new: extract() — 522 callers, 43 callees
  • new: _rebuild_code() — 113 callers, 50 callees
  • new: extract_js() — 85 callers, 4 callees
  • new: extract_xaml() — 19 callers, 17 callees
  • new: dispatch_command() — 2 callers, 123 callees
  • new: extract_go() — 23 callers, 7 callees
  • new: _get_extractor() — 26 callers, 6 callees
  • new: run_pipeline() — 8 callers, 13 callees
  • …and 26 more — each is listed as a finding

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

Formal verification

Could not verify: Could not verify extract.

The verifier did not have enough to check extract, 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 `cache_root` is annotated `Path | None` — outside the synthesizable primitive/collection set

Could not verify: Could not verify extract\_go.

The verifier did not have enough to check extract\_go, 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

· 1 grounded finding(s) anchored inline below; 33 more finding(s) on lines outside this diff (see the check run).

Comment thread graphify/extractors/go.py
@@ -83,7 +83,7 @@ def _go_collect_type_refs(node, source: bytes, generic: bool, out: list[tuple[st
_go_collect_type_refs(c, source, generic, out)

def extract_go(path: Path) -> dict:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Health regression — extract_go()

fans out to 7 callees (efferent coupling); 23 callers depend on it (afferent coupling).

Grounded coupling-delta finding (deterministic), not an LLM guess.

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.

Go: package-level var/const declarations are not extracted as nodes (skews query vocabulary in mixed Go/TS repos)

1 participant