Repository navigation
fix(go): link a method value passed as an argument as an indirect_call (#1566) - #4868
nothariharan wants to merge 1 commit into
Conversation
Graphify-Labs#1566) A Go handler or callback is registered by passing a method value: `routing.Wrap(s.Health)`, `r.Get("/p", s.Health)`. The call walk looked only at what a call expression invokes, so the method got no edge from its registration and a handler reached only through its route had no caller. walk_calls now records each `x.M` argument (on a plain identifier, not an imported package) as an `indirect` raw member call, typed the way a direct `x.M()` is. _resolve_go_member_calls resolves it through the same receiver type, single-declaration and single-method guards and emits an INFERRED `indirect_call`, as Python and JS do. It is never parked for a merge: a value argument is as often a field as a method. The AST cache schema goes to 30.
|
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 2 changed function(s) (1 sampled, not proven, 1 not verified).
Formal verification. PR-changed functions: 1/2 verified (0 proven, 1 may-equivalent, 0 distinguished) · 1 not verified (1 vacuous).
Not verified on this run: \_resolve\_go\_member\_calls (vacuous: never exercised).
Graphify review — findings
Adds Go method-value tracking: a method passed as an argument (routing.Wrap(s.Handle)) is recorded as a raw member call marked indirect, and _resolve_go_member_calls links it to the method as an indirect_call edge (#1566). The dedup applied to these method-value edges shares its target with direct calls to the same method, so what it collapses decides which edge type survives. Bumps _AST_CACHE_SCHEMA to 30 so cached Go extractions re-run and pick up the new edges.
Worth a look
- Method value dedup suppresses a later direct
callsedge to the same method —graphify/extract.py:7448· Escalate · medium- NOT verified (no proof, no reproducing execution) — needs human review
Analysis details — impact, health, verification
Impact & health
Graphify review
Impact — 3824 functions depend on the 465 functions this change touches.
Health — this change adds coupling hotspots:
- worse:
extract()— 1056 callers, 62 callees
Verification — 3824 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: 3558 function(s) in the blast radius were not formally verified this run
Test selection
Test selection
248 of 470 test file(s) selected (53%) via static blast radius.
tests/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_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_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_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— impacttests/test_duplicate_annotation_edges.py— impacttests/test_ejs_extractor.py— impacttests/test_elixir_defdelegate.py— impacttests/test_elixir_import_resolution.py— impact- … and 198 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.
Formal verification
Could not verify: Could not verify \_resolve\_go\_member\_calls.
The verifier did not have enough to check \_resolve\_go\_member\_calls, 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: no capturable inputs from the test suite; property tier: non-vacuity: domain too small (only 1 distinct inputs exercised, need 3) — 'no divergence' would be near-vacuous
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).
Go (#4867/#4868/#4866) and Python (#4773) extractor changes alter per-file AST output and are AST-cached, so one combined _AST_CACHE_SCHEMA bump 30->31 forces stale caches to re-extract. Install (#4770/#4771) and the skill reword (#4721) need no bump. Folded into the unreleased 0.9.99. Each PR omitted its own bump / carried a stale number; the single combined bump lands here. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Landed in v0.9.99, now on PyPI (pip install graphifyy==0.9.99). A Go method value passed as a function argument is linked as an indirect_call. Thanks for the fix, @nothariharan. |
What does this PR do?
Refs #1566. In Go, a handler or callback is registered by passing a method value:
routing.Wrap(hs.CheckDatasourceHealth),r.Get("/health", s.Health),pool.Submit(w.run). On v8 such a method gets no edge from the registration site. The call walk only looks at what a call expression invokes, not at its arguments. A handler that is reached only through its route registration therefore shows no caller, andaffecteddoes not reach it.Minimal repro on v8 (
0a8cd4e1):On Grafana,
pkg/api/api.go:420registersrouting.Wrap(hs.CheckDatasourceHealth). Withpkg/apiextracted on v8,HTTPServer.CheckDatasourceHealth(pkg/api/datasources.go:829) has no incomingcallsorindirect_calledge.Extracting
pkg/api,pkg/api/routing,pkg/cmd/grafana-cli/commandsandpkg/storage/unified/sql/db/dbimpl(74 non-test files):callsedges, 0indirect_call;HTTPServer.CheckDatasourceHealthhas 0 incoming edges.callsedges (none added or removed), 176indirect_calledges.CheckDatasourceHealthgetsHTTPServer.registerRoutes -> CheckDatasourceHealthatapi.go:420.x.Methodnot followed by(. 175 targets areHTTPServermethods; 151 come fromregisterRoutes(routing.Wrap(hs.X)route registrations); the others are callbacks such ascookies.DeleteCookie(c.Resp, name, hs.CookieOptionsFromCfg)(login.go:125) andauthn.HandleLoginRedirect(..., hs.ValidateRedirectTo, ...)(login_oauth.go:66).Why #1566 is not resolved yet on v8
#1566 tracks
indirect_call(a function passed by name, or listed in a dispatch table, is linked as an INFERREDindirect_callsoaffectedreaches it). The slices that shipped cover Python (call arguments, dispatch tables, assignments and returns,getattr) and JS/TS (callbacks and dispatch tables). Go has none of them:extractors/go.pynever emits anindirectraw call, and_resolve_go_member_callsonly emitscalls.The change
extractors/go.py: inwalk_calls, each argument of a call that is a selectorx.Mon a plain identifier (not an imported package) is recorded as a raw member call withindirect: Trueandcontext: "argument". Its receiver is typed exactly as a directx.M()call is: the method's own receiver, or the enclosing function's parameter/local type.extract.py_resolve_go_member_calls: anindirectraw call resolves through the same path as a direct member call (receiver type, single declaration, single method of that name), and is emitted asindirect_call, INFERRED, 0.85, which matches the Python/JSindirect_call. It is never parked as an unresolved call for a merge:f(x.y)is just as often a field read as a method value, so an unknown type here is not evidence of a missing call.cache.py:_AST_CACHE_SCHEMA29 → 30.The shared cross-file pass skips every
is_member_call, so it does not see these entries. An existing directcallsedge between the same pair still takes precedence, so no pair gets both.This is independent of #4853 (receivers typed from another package). It only adds a second kind of entry to the resolver #4853 also changes. A method value on a receiver typed
*pkg.Tresolves once both are in.Type of change
Verification & Invariants
Invariant: an
indirect_callfrom a Go function to a method is emitted only when the argument names a method of the one type its receiver is declared as. A field passed as an argument, a package function value, or a receiver of unknown type links nothing and parks nothing.test_a_field_passed_as_an_argument_links_nothing_and_parks_nothingtest_a_package_function_value_is_not_read_as_a_method_valueRead 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.
Not covered (unchanged):
Wrap(handler),Wrap(pkg.Handler)): the free-function half of the Go slice of Extend indirect_call to remaining dispatch patterns (dict tables, assignments, other languages) #1566.Wrap(s.svc.Handle)) or a method expression ((*Server).Health).h := s.Health, struct literals, maps).How was this tested?
Run on Windows 11, Python 3.12, in the environment
uv run --all-extrassyncs (.venv; the later runs call.venv/Scripts/python -m pytestdirectly becauseuv runrewritesuv.lockon Windows).Graphify-specific checklist
uv run python -m tools.skillgen --bless) when changing their source fragments.