Emit calls edges for top-level function calls, with file node as caller#2016
Open
Rishet11 wants to merge 2 commits into
Open
Emit calls edges for top-level function calls, with file node as caller#2016Rishet11 wants to merge 2 commits into
Rishet11 wants to merge 2 commits into
Conversation
… as caller (Graphify-Labs#1972) Calls at a file's top level (or inside a plain DSL block) had no enclosing definition, so they never entered function_bodies and got no caller node or edge. Walk the file root once with the file node as caller after the per-definition walk; walk_calls already returns at every definition boundary, so it cannot double-emit anything the per-body loop covered. During this root walk emit ONLY direct calls: a _toplevel_calls_only flag suppresses indirect_call (already handled by the dedicated module-dispatch pass with correct shadow filtering) and the PHP-family reference emissions. Java is skipped entirely (no top-level statements; field initializers are walked via initializer_nodes with the owning class as caller). Covers Python and JS/TS, which share this extractor. Adds tests for top-level Python/JS calls and an in-context regression guard.
There was a problem hiding this comment.
Pull request overview
This PR fixes a graph-extraction gap where calls made at a file’s top level (outside any function/method body) previously had no caller node and therefore emitted no calls edges. It does so by adding a second walk_calls pass rooted at the file AST root with the file node as caller_nid, while gating that pass to avoid duplicating non-calls relations handled by other module-scope passes.
Changes:
- Add a file-root
walk_callspass (skipping Java) to emitcallsedges for script/top-level call sites (#1972). - Introduce a
_toplevel_calls_onlyguard to suppress indirect-dispatch and other non-callsrelations during the file-root walk. - Add tests covering top-level Python calls, top-level JS calls, and a regression guard ensuring no duplicate/incorrect caller attribution.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| graphify/extractors/engine.py | Adds a guarded file-root call walk to attribute top-level calls to the file node and avoid duplicating non-calls relations. |
| tests/test_extract.py | Adds regression tests ensuring top-level calls now produce calls edges sourced from the file node (and that in-function calls remain unchanged). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+3612
to
+3615
| # #1972: during the top-level root walk, emit ONLY direct `calls` edges. | ||
| # Module-level indirect dispatch already has a dedicated pass below with | ||
| # correct module-scope shadow filtering, so a root-walk emission would be a | ||
| # duplicate carrying wrong (empty) shadow context. |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1972
Problem
Calls made at a file's top level (outside any def) have no caller node, so they emit no
callsedges. 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_callsalready returns at every definition boundary, so nothing already covered gets re-emitted.Two scoping decisions:
_toplevel_calls_onlyflag limits the extra walk to directcalls. Indirect dispatch and PHP-family references have their own passes; emitting them here would duplicate work with empty shadow context.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.