Skip to content

Conversation

@indietyp
Copy link
Member

Add call graph analysis for MIR

🌟 What is the purpose of this PR?

This PR adds a call graph analysis pass for MIR that tracks function call relationships between definitions. The call graph can be used for call site enumeration, reachability analysis, and optimization decisions.

🔍 What does this change?

  • Adds CallGraph to represent function call relationships between DefIds
  • Implements CallGraphAnalysis pass to populate the graph from MIR bodies
  • Adds CallKind enum to distinguish between direct function calls, filter functions, and other references
  • Adds id field to Body struct to track the definition ID of each body
  • Implements Display for Location and GraphReadLocation to improve debugging
  • Includes comprehensive tests with snapshots to verify call graph construction

Pre-Merge Checklist 🚀

🚢 Has this modified a publishable library?

This PR:

  • does not modify any publishable blocks or libraries, or modifications do not need publishing

📜 Does this require a change to the docs?

The changes in this PR:

  • are internal and do not require a docs change

🕸️ Does this require a change to the Turbo Graph?

The changes in this PR:

  • do not affect the execution graph

🛡 What tests cover this?

  • Comprehensive unit tests for various call patterns:
    • Direct function calls
    • Function arguments containing DefIds
    • Multiple calls from the same body
    • Call chains across multiple bodies
    • Recursive calls
    • Indirect calls via locals

@cursor
Copy link

cursor bot commented Dec 23, 2025

PR Summary

Introduces inter-procedural MIR call graph construction and supporting infrastructure.

  • New CallGraph, CallKind (Apply/Filter/Opaque), and CallGraphAnalysis pass to record DefIdDefId edges during MIR visitation
  • Body now carries id: DefId; reify assigns it via push_with, and visitors skip visiting this field
  • Display impls for Location and GraphReadLocation improve readable edge annotations (e.g., bb0:1)
  • Public re-exports in pass/analysis/mod.rs; builder sets placeholder id for constructed bodies
  • Comprehensive snapshot tests covering direct/indirect calls, arguments with DefIds, chains, recursion

Written by Cursor Bugbot for commit 3fcfaaf. This will update automatically on new commits. Configure here.

Copy link
Member Author

indietyp commented Dec 23, 2025

This stack of pull requests is managed by Graphite. Learn more about stacking.

@augmentcode
Copy link

augmentcode bot commented Dec 23, 2025

🤖 Augment PR Summary

Summary: Adds an inter-procedural call graph analysis pass for HashQL MIR to track cross-definition references and call sites.

Changes:

  • Introduce CallGraph (backed by LinkedGraph) keyed by DefId nodes and CallKind-annotated edges.
  • Add CallGraphAnalysis visitor pass that walks MIR bodies and records Apply, graph-read Filter, and Opaque references.
  • Extend Body with id: DefId and plumb assignment through lowering via push_with.
  • Implement Display for Location and GraphReadLocation to improve debugging / snapshots.
  • Expose call graph analysis from pass::analysis.
  • Add snapshot-based unit tests covering direct calls, call chains, recursion, argument references, and indirect calls via locals.

Technical Notes: Direct call edges are only emitted when the callee is syntactically a DefId (indirect calls via locals are treated as Opaque until later lowering/SROA removes most indirections).

🤖 Was this summary useful? React with 👍 or 👎

Copy link

@augmentcode augmentcode bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review completed. 1 suggestions posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

@codecov
Copy link

codecov bot commented Dec 23, 2025

Codecov Report

❌ Patch coverage is 91.42157% with 35 lines in your changes missing coverage. Please review.
✅ Project coverage is 59.37%. Comparing base (86f263f) to head (c70394b).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
...ocal/hashql/mir/src/pass/analysis/callgraph/mod.rs 73.91% 18 Missing ⚠️
libs/@local/hashql/mir/src/pass/mod.rs 23.07% 10 Missing ⚠️
...ibs/@local/hashql/mir/src/body/terminator/graph.rs 0.00% 6 Missing ⚠️
libs/@local/hashql/mir/src/visit/mut.rs 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8214      +/-   ##
==========================================
+ Coverage   59.26%   59.37%   +0.10%     
==========================================
  Files        1191     1195       +4     
  Lines      113436   113796     +360     
  Branches     4982     4986       +4     
==========================================
+ Hits        67232    67570     +338     
- Misses      45428    45450      +22     
  Partials      776      776              
Flag Coverage Δ
rust.hashql-compiletest 46.65% <ø> (ø)
rust.hashql-mir 88.51% <91.42%> (+0.21%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@codspeed-hq
Copy link

codspeed-hq bot commented Dec 23, 2025

CodSpeed Performance Report

Merging this PR will not alter performance

Comparing bm/be-227-hashql-implement-call-graph (3fcfaaf) with main (abd5ba1)1

Summary

✅ 14 untouched benchmarks
🗄️ 3 archived benchmarks run2

Footnotes

  1. No successful run was found on main (3813e7e) during the generation of this report, so abd5ba1 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

  2. 3 benchmarks were run, but are now archived. If they were deleted in another branch, consider rebasing to remove them from the report. Instead if they were added back, click here to restore them.

@vercel
Copy link

vercel bot commented Jan 15, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

2 Skipped Deployments
Project Deployment Review Updated (UTC)
ds-theme Ignored Ignored Preview Jan 16, 2026 10:39am
hashdotdesign Ignored Ignored Preview Jan 16, 2026 10:39am

@graphite-app graphite-app bot changed the base branch from bm/be-258-hashql-implement-transformationpass-changed-detection to graphite-base/8214 January 15, 2026 15:10
@indietyp indietyp force-pushed the bm/be-227-hashql-implement-call-graph branch from 7b009a5 to c70394b Compare January 15, 2026 15:22
@indietyp indietyp changed the base branch from graphite-base/8214 to bm/be-258-hashql-implement-transformationpass-changed-detection January 15, 2026 15:22
Base automatically changed from bm/be-258-hashql-implement-transformationpass-changed-detection to main January 15, 2026 15:27
@indietyp indietyp enabled auto-merge January 16, 2026 10:36
@indietyp indietyp disabled auto-merge January 16, 2026 10:36
@indietyp indietyp force-pushed the bm/be-227-hashql-implement-call-graph branch from c70394b to 3fcfaaf Compare January 16, 2026 10:38
@indietyp indietyp added this pull request to the merge queue Jan 16, 2026
Merged via the queue into main with commit 59d55c1 Jan 16, 2026
47 checks passed
@indietyp indietyp deleted the bm/be-227-hashql-implement-call-graph branch January 16, 2026 10:55
Copy link
Member Author

Merge activity

  • Jan 16, 12:45 PM UTC: A user started a stack merge that includes this pull request via Graphite.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/libs Relates to first-party libraries/crates/packages (area) area/tests New or updated tests type/eng > backend Owned by the @backend team

Development

Successfully merging this pull request may close these issues.

3 participants