graphify icon indicating copy to clipboard operation
graphify copied to clipboard

Emit calls edges for top-level function calls, with file node as caller

Open Rishet11 opened this issue 4 months ago • 0 comments

Fixes #1972

Problem

Calls made at a file's top level (outside any def) have no caller node, so they emit no calls edges. A function invoked only from module scope looks dead in the graph.

Fix

In graphify/extractors/engine.py, after the per-definition walk, walk the file root once more with the file node as caller. walk_calls already returns at every definition boundary, so nothing already covered gets re-emitted.

Two scoping decisions:

  • A _toplevel_calls_only flag limits the extra walk to direct calls. Indirect dispatch and PHP-family references have their own passes; emitting them here would duplicate work with empty shadow context.
  • Java is skipped. It has no top-level statements, field initializers are walked elsewhere, and a root walk would re-create the phantom stubs #1744 removed.

Test

3 new tests: top-level Python call, top-level JS call, and an in-function regression guard. Full suite shows no new failures against the v8 baseline.

One known behavior to flag: class-body statements now get attributed to the file (relevant for Swift field initializers). No test covers that yet, so I left it alone for now.

Still fairly new to this codebase, so if I have the approach or the scoping wrong anywhere, tell me and I will fix it up.

Rishet11 avatar Jul 19 '26 00:07 Rishet11