Skip to content

Conversation

@indietyp
Copy link
Member

@indietyp indietyp commented Jan 1, 2026

🌟 What is the purpose of this PR?

Add a new PreInlining optimization pass that runs a sequence of transformations to prepare MIR bodies for inlining. This pass orchestrates multiple optimizations in a fixpoint loop to ensure code is maximally simplified before inlining occurs.

🔍 What does this change?

  • Add new PreInlining pass that runs a carefully ordered sequence of optimizations:
    1. Administrative reduction - Removes structural clutter and normalizes shape
    2. Instruction simplification - Constant folding and algebraic simplification
    3. Value propagation (FS/CP alternating) - Propagates values through the code
    4. Dead store elimination - Removes stores made dead by propagation
    5. CFG simplification - Cleans up control flow after local changes
  • Add GlobalTransformState to track per-body changes during global transformations
  • Update AdministrativeReduction to use the new state tracking mechanism
  • Add comprehensive test cases demonstrating the pass's effectiveness on various code patterns
  • Add a new compiletest suite for the pre-inlining pass

🛡 What tests cover this?

  • Added 8 new test cases covering various optimization patterns:
    • Constant folding and branch elimination
    • Cascading conditional simplification
    • Closure inlining with dead branch elimination
    • Dead code elimination after value propagation
    • Instruction simplification with value propagation
    • Nested conditional simplification
    • Nested let binding cleanup
    • Thunk inlining with dead code elimination

❓ How to test this?

  1. Run the MIR tests: cargo test -p hashql_mir
  2. Run the compiletest suite: cargo test -p hashql_compiletest -- mir/pass/transform/pre-inlining

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

@vercel vercel bot temporarily deployed to Preview – petrinaut January 1, 2026 15:08 Inactive
@cursor
Copy link

cursor bot commented Jan 1, 2026

PR Summary

Introduces a pre-inlining optimization driver and supporting infrastructure, and wires it into tests and tooling.

  • Adds global pass PreInlining that runs a fixpoint of AdministrativeReductionInstSimplifyForwardSubstitution/CopyPropagation (alternating) → DeadStoreEliminationCfgSimplify, with an initial CP+CFG pre-pass
  • Adds GlobalTransformState and OwnedGlobalTransformState to track per-body Changed during global transforms; updates GlobalTransformPass::run signature and AdministrativeReduction to use it
  • Improves CfgSimplify dispatch to avoid unnecessary work and unreachable paths; minor helpers in AR (e.g., is_empty, state marking)
  • Integrates new pass into compiletest (mir/pass/transform/pre-inlining), rendering (text/D2), and registers in suite/mod.rs
  • Updates benches to run the pipeline via PreInlining; adjusts builders to assign DefId
  • Adds comprehensive UI tests covering constant folding, cascading conditionals, closure/thunk inlining, propagation + DSE, nested lets/ifs

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

Copy link
Member Author

indietyp commented Jan 1, 2026

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

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

@augmentcode
Copy link

augmentcode bot commented Jan 1, 2026

🤖 Augment PR Summary

Summary: Introduces a new MIR optimization driver pass (PreInlining) to aggressively simplify MIR bodies before the inlining stage.

Changes:

  • Add transform::PreInlining, which runs a fixpoint pipeline (AR → InstSimplify → FS/CP alternating → DSE → CfgSimplify) plus an initial CP+CFG pre-pass.
  • Add GlobalTransformState (borrowed) and OwnedGlobalTransformState (owned) for per-body Changed tracking in global MIR transforms.
  • Update GlobalTransformPass::run signature to accept &mut GlobalTransformState and adapt call sites/tests.
  • Update AdministrativeReduction to mark per-body changes via the new state and return early when nothing is reducible.
  • Minor CfgSimplify refactor to avoid unnecessary CFG recomputation for non-branching terminators.
  • Add and register a new compiletest suite (mir/pass/transform/pre-inlining) plus multiple UI test cases exercising the new pipeline.

Technical notes: PreInlining maintains an internal “unstable body” set and iterates (bounded by MAX_ITERATIONS) until no further changes occur.

🤖 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 Jan 1, 2026

Codecov Report

❌ Patch coverage is 92.52874% with 13 lines in your changes missing coverage. Please review.
✅ Project coverage is 59.87%. Comparing base (1c1b05d) to head (85aff24).

Files with missing lines Patch % Lines
libs/@local/hashql/mir/src/pass/mod.rs 61.90% 8 Missing ⚠️
...ocal/hashql/mir/src/pass/transform/pre_inlining.rs 96.92% 2 Missing and 2 partials ⚠️
.../hashql/mir/src/pass/transform/cfg_simplify/mod.rs 83.33% 1 Missing ⚠️
Additional details and impacted files
@@                                     Coverage Diff                                      @@
##           bm/be-265-hashql-track-locals-inside-of-copy-propagation    #8233      +/-   ##
============================================================================================
+ Coverage                                                     59.81%   59.87%   +0.06%     
============================================================================================
  Files                                                          1066     1067       +1     
  Lines                                                        106239   106408     +169     
  Branches                                                       4472     4479       +7     
============================================================================================
+ Hits                                                          63545    63710     +165     
- Misses                                                        41956    41961       +5     
+ Partials                                                        738      737       -1     
Flag Coverage Δ
rust.hashql-compiletest 46.65% <ø> (ø)
rust.hashql-mir 87.58% <92.52%> (+0.19%) ⬆️

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 Jan 1, 2026

CodSpeed Performance Report

Merging #8233 will degrade performance by 47.86%

Comparing bm/be-266-hashql-implement-pre-inlining-fix-point-loop (85aff24) with bm/be-265-hashql-track-locals-inside-of-copy-propagation (1c1b05d)

Summary

❌ 3 (👁 3) regressions
✅ 14 untouched

Benchmarks breakdown

Benchmark BASE HEAD Efficiency
👁 diamond 37.3 µs 71.6 µs -47.86%
👁 linear 33 µs 40.5 µs -18.65%
👁 complex 53.8 µs 103.2 µs -47.86%

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.

2 participants