Skip to content

fix(go): reference the types a package-level var initialiser names (#2360) - #4932

Merged
safishamsi merged 1 commit into
Graphify-Labs:v8from
nothariharan:fix/go-package-var-type-references
Nov 1, 2026
Merged

safishamsi merged 1 commit into
Graphify-Labs:v8from
nothariharan:fix/go-package-var-type-references

Conversation

@nothariharan

Copy link
Copy Markdown
Contributor

What does this PR do?

Follow-up to #2360 (commit 1c4c3f2), which credits calls in a Go package-level var initialiser to the file. The types named in the same place were still dropped, so a file that only holds a google/wire set referenced nothing.

Minimal repro (go.mod: module example.com/app):

// validator/validator.go
package validator

type DataSourceRequestValidator interface{ Validate() error }
type OSSDataSourceRequestValidator struct{}
func (v *OSSDataSourceRequestValidator) Validate() error { return nil }
func ProvideValidator() *OSSDataSourceRequestValidator { return &OSSDataSourceRequestValidator{} }
// server/wire.go
package server

import (
	"github.com/google/wire"
	"example.com/app/validator"
)

var wireSet = wire.NewSet(
	validator.ProvideValidator,
	wire.Bind(new(validator.DataSourceRequestValidator), new(*validator.OSSDataSourceRequestValidator)),
)

On v8 (f5155ba), extract(...) warns 1 code file(s) yielded no symbols ... server/wire.go, and wire.go has only its two imports_from edges: nothing to DataSourceRequestValidator or OSSDataSourceRequestValidator. The same shape is Grafana's pkg/server/wire.go.

Root cause: in extract_go, walk hands a package-level var_declaration to walk_calls (#2360), which only looks at call_expressions. Type references are emitted only for struct fields, interface elements and signatures (emit_go_method_refs). Nothing reads the types in a var declaration's declared type, a composite literal, or a new/make type argument.

The change: a new emit_go_package_var_type_refs, called from the same var_declaration branch, walks the declaration and collects:

  • the var_spec declared type (var x pkg.T, var _ Iface = ...),
  • a composite_literal type (pkg.T{}, &T{}, []*T{{}}),
  • an argument_list child that parses as a type node (new(T), new(*pkg.T), make(map[string]pkg.T)).

Each type goes through the same _go_collect_type_refs + ensure_named_node path a struct field uses. The file node gets a references edge with context variable_type, or generic_arg for a generic instantiation's type argument (pkg.List[T]{}), as on a field. That file node is the owner #2360 already gives these calls. Because the path is shared, pkg.T resolves through the file's import in _resolve_go_type_references. An external type such as http.Client is parked on its import path (net/http.Client), the same as an external field type, and is never bound to a same-named local type. wire.NewSet / wire.Bind are unchanged and add no nodes or edges. With the patch, the repro gives wire.go -references-> DataSourceRequestValidator and wire.go -references-> OSSDataSourceRequestValidator, both on the nodes declared in validator/validator.go, and the "no symbols" warning goes away.

Type of change

  • Bug fix
  • New feature
  • Documentation
  • Tests or CI
  • Refactor
  • Security fix

Verification & Invariants

Invariant: a type named in Go source gets a references edge from its owner, and that edge goes to the declaration the import names, or to a parked external stub. It never goes to a same-named local type. Struct fields already worked this way. A package-level initialiser's owner is the file (#2360).

Scope limits, stated explicitly:

  • A closure body inside the initialiser (var f = func() { _ = &T{} }) is function code. It emits no body type references, like any other function body; a test locks this in.

  • A package-qualified function value passed as an argument (validator.ProvideValidator above) is still not linked. The Extend indirect_call to remaining dispatch patterns (dict tables, assignments, other languages) #1566 method-value path covers only non-package receivers, and test_a_package_function_value_is_not_read_as_a_method_value keeps a package function value from becoming an indirect_call. Changing that would also affect function bodies, so it is left out here.

  • A conversion such as var _ Iface = (*Impl)(nil) links Iface (the declared type) but not Impl, because the grammar parses (*Impl) as an expression.

  • _AST_CACHE_SCHEMA is not bumped. Cached Go extractions keep the old output until the next schema bump. I left that for the release batch, the way the recent schema bumps were done.

  • Read the CONTRIBUTING.md guide.

  • Reproduced the issue and identified the invariant.

  • Made the smallest fix necessary.

  • Added a regression test (if bug fix) or isolated boundary test.

  • Kept the PR description synchronized with the final implementation.

  • Documented any limitations / unsupported cases explicitly.

How was this tested?

New file tests/test_go_package_var_type_refs.py, using tmp_path and extract(..., root=tmp_path, parallel=False):

  • the wire repro: new(pkg.Iface) and new(*pkg.Impl) reach the declarations in validator.go;
  • a composite literal pkg.T{}, a bare new(Registry), []*Entry{{}} and a declared var x pkg.Iface in a var (...) group;
  • negative: new(http.Doer) / new(*http.Client) park as net/http.* and never bind to the local type Client; no NewSet/Bind nodes and no calls/indirect_call edges from wire.go;
  • boundary: a type inside a var closure body is not credited to the file.
# with the fix
uv run --frozen pytest -q tests/test_go_package_var_type_refs.py -p no:cacheprovider
4 passed

# go.py change stashed (test file kept)
uv run --frozen pytest -q tests/test_go_package_var_type_refs.py -p no:cacheprovider
3 failed, 1 passed   (the closure-body boundary test passes either way)

uv run --frozen pytest -q tests/ -k "go_" -p no:cacheprovider
157 passed, 10 skipped, 9113 deselected

uv run --frozen python -m tools.skillgen --check
check OK: 134 artifact(s) match committed output and expected/.

# Linux (WSL kali), full suite, isolated HOME and AWS config
HOME=$(mktemp -d) uv run --frozen pytest tests/ -q --tb=short -p no:cacheprovider
9366 passed, 28 skipped, 1 xfailed in 1116.73s

Graphify-specific checklist

  • I updated generated skill artifacts (uv run python -m tools.skillgen --bless) when changing their source fragments. (No skill sources touched; --check passes.)
  • I confirmed that AST/structural extraction remains deterministic (no ambient state dependencies like ENV variables).
  • I reviewed changes for security implications (no unsafe interpolation into shell/Python).
  • I confirmed no API keys or local-only graph data are included.
  • (If applicable) I disclosed AI authorship in my commit messages.

…raphify-Labs#2360)

Graphify-Labs#2360 walks a package-level `var` initialiser for calls owned by the file,
but the types named there were still dropped: `new(T)`, `new(*pkg.T)`, a
composite literal `pkg.T{}` / `&T{}`, and the declared `var x pkg.T`. A file
holding only a google/wire set, `wire.Bind(new(Iface), new(*Impl))`, then
referenced nothing and was reported as yielding no symbols.

The file now gets a `references` edge (context `variable_type`) to each such
type, collected with the same _go_collect_type_refs and ensure_named_node a
struct field uses, so `pkg.T` resolves through the import and an external
type is parked on its import path exactly as a field type is. A closure body
inside the initialiser is function code and is left alone.
@github-actions

github-actions Bot commented Nov 1, 2026

Copy link
Copy Markdown

Thanks for the pull request, @nothariharan. 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.10 and 3.13, and that the change keeps extraction deterministic.

@github-actions github-actions Bot added the contributor Pull request from a returning community contributor label Nov 1, 2026

@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 1 advisory finding(s) below merit a look before merge.

Not checked: tests were not run; formal verification proved 0 of 1 changed function(s) (1 sampled, not proven).

Formal verification. PR-changed functions: 1/1 verified (0 proven, 1 may-equivalent, 0 distinguished) · 0 not verified.


Graphify review — findings

Adds file-level references edges for the types a package-level Go var names, whether in its declared type, a composite literal, or a new(...)/make(...) type argument. A file holding only a wire set like wire.Bind(new(Iface), new(*Impl)) now references both types instead of yielding nothing. External types stay parked on their import path rather than binding to a same-named local type, and the external wire calls mint no call nodes. The walk in emit_go_package_var_type_refs skips func_literal nodes entirely, leaving closure bodies to the existing call walk. That also skips the closure's own signature, so parameter and return types there are never credited to the file.

Worth a look

  • Skipping whole func literals drops signature type references — graphify/extractors/go.py:435 · Escalate · medium
    • NOT verified (no proof, no reproducing execution) — needs human review
Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 68 functions depend on the 42 functions this change touches.

Health — this change adds coupling hotspots:

  • worse: walk() — 1 callers, 14 callees

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

Test selection

Test selection

4 of 488 test file(s) selected (1%) via static blast radius.

  • tests/test_go_package_var_type_refs.py — impact, changed-test
  • tests/test_go_type_alias.py — impact
  • tests/test_languages.py — impact
  • tests/test_multilang.py — impact

Selection is safe under the controlled-regression assumption; always-run tests + a periodic full run are the backstops. Advisory — it never changes the check verdict.

Formal verification

No difference found (not proven): No behavior difference found in extract\_go (not a proof).

The verifier ran both versions of extract\_go on many inputs and saw identical behavior every time. Strong evidence the change is safe, but evidence, not a proof.

Guarantee: Empirical: differential testing (both versions run on many generated inputs). A divergence on an untested input remains possible, so this is 'no counterexample found', not 'proven equivalent'.

Note: An input the sampler did not try could still differ.

· 1 more finding(s) on lines outside this diff (see the check run).

@safishamsi
safishamsi merged commit 96fa042 into Graphify-Labs:v8 Nov 1, 2026
12 checks passed
safishamsi added a commit that referenced this pull request Nov 1, 2026
… fixes

#4933 (python bare-call), #4931 (go method-value via field) and #4932 (go
var-init type refs) were merged on GitHub but each changes AST-cached
output and deferred its schema bump; one combined 33->34 bump so cached
Python/Go extractions re-run. #4929 (namespace packages) is a post-cache
pass and needs none. Opens the unreleased 0.9.101 changelog.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
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.

2 participants