Skip to content

Move free standing ir::Block functions to methods#8205

Open
ShaharNaveh wants to merge 3 commits into
RustPython:mainfrom
ShaharNaveh:ir-cleanup-2
Open

Move free standing ir::Block functions to methods#8205
ShaharNaveh wants to merge 3 commits into
RustPython:mainfrom
ShaharNaveh:ir-cleanup-2

Conversation

@ShaharNaveh

@ShaharNaveh ShaharNaveh commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Summary

Summary by CodeRabbit

  • Refactor

    • Streamlined internal block-handling logic in the code generation pipeline.
    • Improved consistency across control-flow handling, optimization passes, and instruction management.
  • Tests

    • Updated unit coverage to match the revised block-handling behavior and helper APIs.

@coderabbitai

coderabbitai Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Basic-block helper free functions in the codegen IR module were converted into methods on the Block type. All call sites in CFG construction, optimization passes (fallthrough checks, static swaps, constant folding, jump normalization), and unit tests were updated to use the new method-based API. No public API signatures changed.

Changes

Block Method Refactor

Layer / File(s) Summary
New Block methods and removal of old free functions
crates/codegen/src/ir.rs
Free functions for basic-block slot management, fallthrough/cold checks, and static-swap optimization are turned into Block methods, replacing the earlier standalone implementations.
CFG builder and Blocks wiring
crates/codegen/src/ir.rs
Blocks CFG passes and CFG builder helpers now call Block methods for clearing blocks, fallthrough checks, and last/raw-first instruction access.
Optimization pass call-site updates
crates/codegen/src/ir.rs
Load-fast threading, line-number propagation, nop/pair removal, stackdepth calculation, warm/cold marking, cold-block pushing, jump insertion/normalization/removal, CodeInfo helpers, prefix instruction insertion, local-unsafe scanning, exception target labeling, and debug dump logic all switch to the new Block methods.
Constant folding path updates
crates/codegen/src/ir.rs
Unary/binary op folding, tuple-of-constants folding, and list/set folding use get_const_loading_instrs and nop_out Block methods.
Unit test updates for new Block APIs
crates/codegen/src/ir.rs
Tests for slot allocation/clearing, static swaps, line-number propagation, and jump threading are updated to call the new Block methods.

Estimated code review effort: 4 (Complex) | ~60 minutes

Possibly related PRs

  • RustPython/RustPython#7541: Both PRs modify the constant/list/set folding paths in the same file that this PR rewires to use the new Block methods.
  • RustPython/RustPython#7578: Both PRs modify CFG block/instruction utilities in the same file, one via jump-threading logic and this one via helper-to-method refactoring.
  • RustPython/RustPython#8142: Both PRs refactor CFG/block handling in the same file at the block/CFG utility layer.

Suggested reviewers: youknowone

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title accurately summarizes the main refactor of moving free-standing Block helpers into methods.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@ShaharNaveh ShaharNaveh changed the title Move free standing Block functions to methods Move free standing ir::Block functions to methods Jul 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant