Skip to content

Conversation

@indietyp
Copy link
Member

@indietyp indietyp commented Jan 2, 2026

🌟 What is the purpose of this PR?

Implements a function inlining pass for HashQL's MIR (Mid-level Intermediate Representation). The pass reduces function call overhead and enables further optimizations by replacing call sites with the callee's body. It uses a two-phase approach: heuristic-based normal inlining followed by aggressive inlining for filter closures in graph read pipelines.

🔍 What does this change?

  • Adds libs/@local/hashql/mir/src/pass/transform/inline/ module with:
    • mod.rs: Main pass implementation with two-phase inlining (normal + aggressive)
    • analysis.rs: Cost estimation and body analysis (loop detection, caller counting)
    • heuristics.rs: Scoring algorithm with configurable bonuses (leaf, single-caller, unique-callsite, loop)
    • find.rs: Callsite discovery for aggressive filter closure inlining
    • rename.rs: Reference renaming for inlined code (locals, blocks, places)
    • tests.rs: Comprehensive unit tests and snapshot tests
  • Processes SCCs in dependency order to ensure callees are optimized before inlining
  • Never inlines recursive calls (same SCC) to prevent infinite expansion
  • Respects per-caller budget (default: 120) to avoid code bloat
  • Aggressive phase runs until fixpoint or cutoff (default: 16 iterations

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

"lint:clippy": "just clippy",
"test:codspeed": "cargo codspeed run -p hashql-core",
"test:miri": "cargo miri nextest run -- co_sort try_scan heap::transfer stable_empty_slice",
"test:miri": "cargo miri nextest run -- co_sort try_scan heap::transfer stable_empty_slice id::slice tarjan::tests::members",
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we just generally run Miri on all tests

Copy link
Member Author

Choose a reason for hiding this comment

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

i can give it a try next time, I didnt because of the time it takes to run, but let me check if that is still true

@indietyp indietyp force-pushed the bm/be-197-hashql-implement-inlining branch from 20c52d2 to c3200c0 Compare January 17, 2026 16:17
@indietyp indietyp force-pushed the bm/be-267-hashql-do-not-reset-the-scratch-space-but-instead-use-scopes branch from f088349 to 427eda4 Compare January 17, 2026 16:17
@graphite-app graphite-app bot changed the base branch from bm/be-267-hashql-do-not-reset-the-scratch-space-but-instead-use-scopes to graphite-base/8236 January 17, 2026 17:22
@indietyp indietyp force-pushed the bm/be-197-hashql-implement-inlining branch from c3200c0 to 7e32c71 Compare January 17, 2026 17:55
@indietyp indietyp changed the base branch from graphite-base/8236 to bm/be-267-hashql-do-not-reset-the-scratch-space-but-instead-use-scopes January 17, 2026 17:56
Base automatically changed from bm/be-267-hashql-do-not-reset-the-scratch-space-but-instead-use-scopes to main January 17, 2026 18:03
@indietyp indietyp added this pull request to the merge queue Jan 17, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jan 17, 2026
@indietyp indietyp added this pull request to the merge queue Jan 19, 2026
Merged via the queue into main with commit 4655bbd Jan 19, 2026
98 of 118 checks passed
@indietyp indietyp deleted the bm/be-197-hashql-implement-inlining branch January 19, 2026 09:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/infra Relates to version control, CI, CD or IaC (area) 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