Repository navigation
fix(go): drop generic type parameters from signature type references - #4388
rajatnagda45 wants to merge 1 commit into
Conversation
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.
|
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. |
There was a problem hiding this comment.
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-testtests/test_languages.py— impacttests/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).
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]>
|
Shipped in v0.9.88, just released to PyPI as |
Fixes #4383.
Problem
_go_collect_type_refsappends the bareT/Ridentifiers 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 itsTonto one baretnode — 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_nameshelper collects the names a declaration binds — its own[T, R]list and, for a method, the receiver'sBox[T]arguments (Go methods reuse the receiver's parameters)._go_collect_type_refstakes askipset and drops those names at thetype_identifierleaf. 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 (theBoxin aBox[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.