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

Add MIR call graph analysis

  • New CallGraph with CallKind (Apply, Filter, Opaque) and CallGraphAnalysis pass to record DefIdDefId references across bodies; human-readable output via Display
  • Integrates stable definition IDs by adding id: DefId to Body; reify now assigns IDs (push_with), builder.finish initializes, and visitors skip traversing id
  • Improves debuggability: Display for Location and GraphReadLocation
  • Wires exports in pass/analysis/mod.rs; adds comprehensive snapshot tests for direct/indirect calls, arguments carrying DefIds, multiple calls, chains, and recursion

Written by Cursor Bugbot for commit c70394b. 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 1 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 improve performance by ×2.7

Comparing bm/be-227-hashql-implement-call-graph (c70394b) with main (86f263f)

Summary

⚡ 7 improved benchmarks
✅ 7 untouched benchmarks
🗄️ 3 archived benchmarks run1

Performance Changes

Benchmark BASE HEAD Efficiency
diamond 20.8 µs 7.8 µs ×2.7
complex 68.1 µs 55.5 µs +22.71%
complex 25.4 µs 11.8 µs ×2.1
diamond 50.1 µs 38.2 µs +31.25%
diamond 15.5 µs 7.5 µs ×2.1
complex 18.8 µs 8.2 µs ×2.3
linear 11.9 µs 7.1 µs +68.14%

Footnotes

  1. 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 15, 2026 3:23pm
hashdotdesign Ignored Ignored Preview Jan 15, 2026 3:23pm

@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
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