Repository navigation
feat(go): dispatch interface method calls to implicit implementers - #4934
nothariharan wants to merge 1 commit into
Conversation
A call through an interface-typed field lands on the interface's method
node, and nothing joins it to the concrete method, because Go types
satisfy interfaces implicitly and the shared interface_dispatch pass
only reads `implements` edges. So the concrete method loses every caller
that goes through the interface.
The Go extractor now stamps interface type nodes with
metadata {"language": "go", "kind": "interface"}, and a new
graphify.go_dispatch pass infers implementers from method sets (every
method name the interface requires, own and embedded) and feeds those
pairs to resolve_interface_dispatch. Empty interfaces, type-set
constraints, interfaces embedding an interface outside the corpus, and
interfaces with more than ten structural implementers are skipped; an
unexported requirement only matches types in the same package. The AST
cache schema is bumped so cached Go extractions pick up the stamp.
|
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. |
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.
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 Go interface dispatch: calls through an interface now reach the types that implicitly implement it, and resolve_go_interface_dispatch leaves non-Go interfaces untouched. Go interface type nodes now carry metadata.kind == "interface" so the resolver can identify them, and the _AST_CACHE_SCHEMA bump to 34 forces cached Go extractions to re-run and pick up that tag. Which types count as implementers depends on the interface's method set, so how methods gained through embedded interfaces are counted decides which interfaces get dispatched at all.
Worth a look
- Interfaces whose methods all come from embedded interfaces are never dispatched —
graphify/go_dispatch.py:107· Escalate · medium- NOT verified (no proof, no reproducing execution) — needs human review
Analysis details — impact, health, verification
Impact & health
Graphify review
Impact — 3967 functions depend on the 488 functions this change touches.
Health — this change adds coupling hotspots:
- worse:
extract()— 1091 callers, 64 callees - new:
resolve_go_interface_dispatch()— 3 callers, 5 callees
Verification — 3967 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: 3694 function(s) in the blast radius were not formally verified this run
Test selection
Test selection
261 of 488 test file(s) selected (53%) via static blast radius.
tests/test_4874_jvm_resolution.py— impacttests/test_affected_overrides.py— impacttests/test_astro_extraction.py— impacttests/test_astro_import_ids.py— impacttests/test_binary_media_words.py— impacttests/test_blade_extractor.py— impacttests/test_build.py— impacttests/test_builtin_global_type_refs.py— impacttests/test_c_include_resolution.py— impacttests/test_cache.py— impacttests/test_cache_long_paths.py— impacttests/test_cache_stale_import_target.py— impacttests/test_case_only_decl_ids_4904.py— impacttests/test_case_sensitive_resolution.py— impacttests/test_charmap_encoding.py— impacttests/test_chunking.py— impacttests/test_cjs_module_extension.py— impacttests/test_cobol_extractor.py— impacttests/test_confidence_score_output.py— impacttests/test_cpp_method_declarations.py— impacttests/test_cpp_nested_and_cli.py— impacttests/test_cpp_objc_cross_file_calls.py— impacttests/test_cpp_template_type_params.py— impacttests/test_cpp_type_alias.py— impacttests/test_cross_extension_reexport_self_cycle.py— impacttests/test_cross_language_call_resolution.py— impacttests/test_cross_repo_external_call_guards.py— impacttests/test_cross_repo_member_calls.py— impacttests/test_csharp_call_site_generic_args.py— impacttests/test_csharp_delegate_declarations.py— impacttests/test_csharp_enum_members.py— impacttests/test_csharp_field_generic_args.py— impacttests/test_csharp_foreach_loop_variable.py— impacttests/test_csharp_generic_callsites.py— impacttests/test_csharp_interface_dispatch.py— impacttests/test_csharp_member_calls.py— impacttests/test_csharp_member_chain_calls.py— impacttests/test_csharp_member_nodes.py— impacttests/test_csharp_method_owner_labels.py— impacttests/test_csharp_object_creation.py— impacttests/test_csharp_overloads.py— impacttests/test_csharp_partial_classes.py— impacttests/test_csharp_tuple_type_refs.py— impacttests/test_csharp_type_resolution.py— impacttests/test_csharp_underscore_collisions.py— impacttests/test_csharp_var_call_return_type.py— impacttests/test_csharp_verbatim_interpolation.py— impacttests/test_definition_file_portability.py— impacttests/test_detect.py— impacttests/test_dotnet.py— impact- … and 211 more
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.
Docs that may be stale (advisory)
docs/superpowers/specs/2026-05-04-incremental-updates-dedup-design.md§ New dependencies (lines 106-110): references changed symbolsrequired
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 grounded finding(s) anchored inline below; 1 more finding(s) on lines outside this diff (see the check run).
| return isinstance(meta, dict) and meta.get("language") == "go" and meta.get("kind") == "interface" | ||
|
|
||
|
|
||
| def resolve_go_interface_dispatch( |
There was a problem hiding this comment.
resolve_go_interface_dispatch()
high coupling complexity (Ca·Ce = 15).
Grounded coupling-delta finding (deterministic), not an LLM guess.
|
Landed in 0.9.102 (published to PyPI), cherry-picked with your authorship preserved. Thanks @nothariharan. |
…aphify-Labs#5319) A call through an interface-typed field (`this.worker.run()` where `worker` is a `Worker`) lands on the interface's method node, and nothing joins it to `EmailWorker.run()`, so a directed walk stops at the interface. C# (Graphify-Labs#3003), Swift (Graphify-Labs#4035) and Go (Graphify-Labs#4934) already close this gap with `dispatches_to`; no pass was registered for `.java`. The Java extractor already emits `implements` and the interface's `method` edges, so graphify.java_dispatch is a thin `.java` gate over resolve_interface_dispatch, registered after the Go pass. Same rules as the other languages: additive INFERRED edges at 0.85 / 0.75 / 0.65 by implementer count, both ends declared in `.java`. Each Java overload is its own node, so the shared pairing links overloads by signature, then arity. No extractor change, so no AST cache schema bump (as for Swift). Known limits, pinned by tests: `extends` (abstract classes) is not read, interface hierarchies are not walked, an unoverridden `default` method gets no edge, a lone same-named method pairs without a signature check, and a fully qualified `implements a.Worker` with no import binds to a sourceless stub and gets no edge (the imported form links). Two C# tests asserted that a Java corpus gains no dispatch edge; they now call the C# pass directly, and the mixed-corpus test expects each pair within its own language. Co-Authored-By: Claude <[email protected]>
What does this PR do?
A Go call through an interface-typed field lands on the interface's method node, which is correct. But nothing links that interface method to the concrete types that implement it. So the concrete method loses every caller that goes through the interface, and a directed walk stops at the interface.
Repro on v8 (
f5155bad, 0.9.100).go.modismodule example.com/app.v8 emits
calls .Execute() -> expr_plugincontextprovider_getwithdatasource(the interface method). Nothing reachesplugincontext_provider_getwithdatasource, before or afterbuild_from_json. Grafana has the same shape:pkg/expr/nodes.gocallsGetWithDataSourcethroughpkg/expr's localpluginContextProvider, andplugincontext.Provider.GetWithDataSourceloses those callers.Why.
graphify.interface_dispatch(#3003, shared with the Swift pass) already linksinterface_method --dispatches_to--> implementing_method. It is driven byimplementsedges. Go satisfies interfaces implicitly, so the Go extractor emits noimplementsedges and the mechanism never runs.Change.
graphify/extractors/go.pystamps each interface type node withmetadata: {"language": "go", "kind": "interface"}. Without it the output cannot tell an interface's method requirements from a struct's methods, because both hang off their owner by amethodedge.languageandkindare already among the metadata keys that the incrementalupdate/watchcontext forwards for unchanged nodes, so the stamp survives an incremental rebuild.graphify/go_dispatch.py, registered next to the C# and Swift passes. It infers implementers from method sets: named type T implements interface I when T's methods include every method name I requires, counting I's own methods and the methods of interfaces it embeds. T can be a struct or any other named type with methods. Value and pointer receivers both count, because the extractor hangs both off T's node. The pass hands those pairs toresolve_interface_dispatchand keeps only thedispatches_toedges that come back. The inferredimplementspairs are not added to the graph._AST_CACHE_SCHEMA33 -> 34, so cached Go extractions re-run and pick up the stamp.The C# and Swift edges keep their shape and tiers:
INFERRED,context: "call", 0.85 for one implementer, 0.75 for two, 0.65 floor, and the per-implementer single-owner guard. The edge is additive, so thecallsedge to the interface method stays.Matching rule and guards
.gofile. This is the same suffix gate as the C# and Swift passes.interface{},any) is skipped. Every type satisfies it.~int | ~string, which the extractor marks as atype_constraintreference) is skipped. It is a generics constraint, not something a call goes through.io.Reader), the method set is unknown, so the interface is skipped. Matching on part of the method set would admit types that do not implement it.run()) can only be implemented in the interface's own package. When the interface requires one, only types in the same directory count.implementscannot explode. Name-only structural matching can. An interface matched by more than 10 types (_MAX_IMPLICIT_IMPLEMENTERS) is skipped entirely. It is not truncated, because which ten to keep would be arbitrary. On Grafanapkg/(5715 Go files, 1056 interfaces), 160 interfaces go over the cap. The largest areRunnable/BackgroundService/Elector-style interfaces, with 436 matching types each, andValidator-style ones, with 333 each. Without the cap they would add thousands of 0.65 edges that say little.Error,String). These get no special case. The builtinerrorandfmt.Stringerare not corpus nodes, so they never match. A local redeclaration (type stringer interface{ String() string }) is a real interface that calls go through. It gets edges like any other interface, and the cap covers the case where the name is everywhere.Effect on Grafana
pkg/: 6637dispatches_toedges (680 at 0.85, 1502 at 0.75, 4455 at 0.65).expr.pluginContextProvider.GetWithDataSourcenow dispatches toplugincontext.Provider.GetWithDataSourceand to the in-package test fake, at 0.75. The pass took about 3 s on that corpus with the cap disabled.Limitations
Type of change
Verification & Invariants
Invariant: a
dispatches_toedge joins a Go interface method only to a same-named method of a Go type that has every method the interface requires. The edge is additive (thecallsedge to the interface stays), carries anINFERREDtier, and is never emitted for an interface whose method set is unknown or empty.Persisted state: the AST cache schema is bumped, so stale Go cache entries without the stamp re-extract. The only other change to graph output is the new
metadataon Go interface nodes.How was this tested?
New
tests/test_go_interface_dispatch.pyhas 10 tests:callsedge kept, chain reachable into the concrete method's callee, noimplementsleaked)Each guard was also turned off one at a time, and its test failed.
Graphify-specific checklist
uv run python -m tools.skillgen --bless) when changing their source fragments. (Not applicable: no skill fragments changed;--checkpasses.)