Skip to content

fix(go): drop generic type parameters from signature type references - #4388

Closed
rajatnagda45 wants to merge 1 commit into
Graphify-Labs:v8from
rajatnagda45:fix/go-generic-type-param-phantom
Closed

rajatnagda45 wants to merge 1 commit into
Graphify-Labs:v8from
rajatnagda45:fix/go-generic-type-param-phantom

Conversation

@rajatnagda45

Copy link
Copy Markdown
Contributor

Fixes #4383.

Problem

_go_collect_type_refs appends the bare T/R identifiers used in a generic signature, struct field, or interface method as type references and runs them through the sourceless-stub path. Every generic function/type then collapses its T onto one bare t node — a god node that pollutes god-node rankings (single-letter type params are not in the analyzer's builtin-noise filter). TypeScript, C#, and Java already exclude their type parameters.

Implementation

A new _go_type_param_names helper collects the names a declaration binds — its own [T, R] list and, for a method, the receiver's Box[T] arguments (Go methods reuse the receiver's parameters). _go_collect_type_refs takes a skip set and drops those names at the type_identifier leaf. The set is computed per declaration and threaded through the function/method signature, struct-field, and interface-method paths. Genuine user types and the generic container head (the Box in a Box[T] return) still reference.

Verification

New tests/test_go_generic_type_params.py (generic function, generic struct+method, generic interface, and a user-type/container guard). All four fail on pre-fix v8 and pass with the fix.

Commands run:

  • uv run pytest tests/ (7519 passed, 15 skipped; security/wheel excluded)
  • uv run ruff check . (clean)
  • uv run pyright graphify/extractors/go.py (0 errors)

Limitations

Scoped to generic type parameters; qualified types (testing.T) keep their qualifier and are unaffected. Receiver-type node keying (Box[T]) is unchanged.

A `[T any]` type parameter is a local binding, not a corpus symbol, but
`_go_collect_type_refs` appended the bare `T`/`R` identifiers used in a
function signature, struct field, or interface method as type references and
ran them through the sourceless-stub path. Every generic function/type in the
corpus then collapsed its `T` onto one bare `t` node — a god node that
pollutes god-node rankings, since single-letter type parameters are not in the
analyzer's builtin-noise filter. TS, C#, and Java already exclude their type
parameters.

A new `_go_type_param_names` helper collects the names a declaration binds
(its own `[T, R]` list and, for a method, the receiver's `Box[T]` arguments —
Go methods reuse the receiver's parameters), and `_go_collect_type_refs` skips
them. Genuine user types and the generic container head (the `Box` in a
`Box[T]` return) still reference.
@github-actions github-actions Bot added the contributor Pull request from a returning community contributor label Oct 12, 2026
@github-actions

Copy link
Copy Markdown

Thanks for the pull request, @rajatnagda45. 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.

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

No issues found by static checks — no coupling regressions or blocking issues in the code graph. That is not the same as safe to merge: see what was not checked.

Not checked: tests were not run; no formal proof of the changed code.


Graphify review — findings

Stops the Go extractor from treating generic type parameters as type references, so a [T any] in a function, struct field, or interface method no longer mints a sourceless T stub that every generic declaration collapses onto as a god node. _go_type_param_names collects the names bound by a declaration's own type-parameter list, plus a method receiver's type arguments. _go_collect_type_refs now drops those names via a skip set, while real user types and the generic container head (e.g. Box in Box[T]) are still referenced.

No blocking issues surfaced. 1 lower-confidence candidate did not survive cross-model review.

Analysis details — impact, health, verification

Impact & health

Graphify review

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

Health — this change adds coupling hotspots:

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

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

Test selection

Test selection

3 of 391 test file(s) selected (1%) via static blast radius.

  • tests/test_go_generic_type_params.py — impact, changed-test
  • 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.

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

safishamsi added a commit that referenced this pull request Oct 12, 2026
Python property-accessor decorators and `Self` (#4385, #4386), Swift
`Self` (#4387), Go generic type params (#4388), the Python forward
type-hint file-node fix (#4343), PowerShell dot-source paths (#4369),
and the C# verbatim-interpolated-string recovery (#3612) all change AST
extraction output, so warm caches must re-extract.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@safishamsi

Copy link
Copy Markdown
Member

Shipped in v0.9.88, just released to PyPI as graphifyy 0.9.88. Landed via an authorship-preserving cherry-pick (your commit keeps your name and counts on your contributor graph), which is why GitHub marks this closed rather than merged. Thanks @rajatnagda45!

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.

Go: generic type parameters ([T any]) leak as a sourceless god node t

2 participants