Skip to content

Fix all clippy suggestions in ir.rs#8162

Merged
youknowone merged 4 commits into
RustPython:mainfrom
ShaharNaveh:ir-cleanup-clippy
Jun 30, 2026
Merged

Fix all clippy suggestions in ir.rs#8162
youknowone merged 4 commits into
RustPython:mainfrom
ShaharNaveh:ir-cleanup-clippy

Conversation

@ShaharNaveh

@ShaharNaveh ShaharNaveh commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Summary

Summary by CodeRabbit

  • Refactor

    • Made control-flow and instruction-sequence transformations more direct and consistent.
    • Simplified CFG cleanup and related processing to use deterministic, non-failing steps.
  • Bug Fixes

    • Improved reliability of jump/label resolution and exception-target labeling during code generation.
    • Strengthened exception-stack handling by removing unnecessary failure paths.
  • Chores

    • Updated debug output and tests to align with the revised internal processing behavior.

@coderabbitai

coderabbitai Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This PR updates crates/codegen/src/ir.rs so several CFG and instruction-sequence helpers become infallible, adjusts the corresponding callers, and refactors some label, block-indexing, and loop-based updates across codegen and exception-stack handling.

Changes

Codegen IR control-flow refactor

Layer / File(s) Summary
Label map remapping
crates/codegen/src/ir.rs
instruction_sequence_use_label(), instruction_sequence_insert_instruction(), cfg_to_instruction_sequence(), and cfg_from_instruction_sequence() remap labels without InternalResult and clear label-map state after application.
Jump and NOP cleanup
crates/codegen/src/ir.rs
resolve_unconditional_jumps(), resolve_jump_offsets(), and the redundant-NOP passes drop Result wrappers, and finalize_code() calls the updated helpers directly.
Exception handling and pipeline wiring
crates/codegen/src/ir.rs
mark_except_handlers(), insert_superinstructions(), take_recorded_instr_sequence(), prepare_cfg_from_codegen(), and debug tracing use the new infallible pipeline flow.
Indexing and loop simplifications
crates/codegen/src/ir.rs
Several helpers switch to direct Blocks[...] access or iterator-based updates, including constant removal, stack-effect scans, pseudo-op conversion, cell-offset fixes, and location-info assembly.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

Poem

I hopped through labels, neat and small,
and nops went poof along the wall. 🐇
The stacks held steady, jumps fell in line,
while CFG moons kept shining fine.
Thump-thump—bytecode sings tonight!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 74.51% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title matches the PR’s main goal of applying Clippy-driven cleanup in ir.rs.
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.
✨ 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
crates/codegen/src/ir.rs (1)

1584-1597: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Consider consolidating the two identical opposite-direction arms.

The Some(PseudoOpcode::JumpIfTrue) if opcode_is_false and Some(PseudoOpcode::JumpIfFalse) if !opcode_is_false arms have byte-for-byte identical bodies; only the pattern/guard pair differs. They can be folded into a single arm (e.g. guarding on a precomputed "target is opposite-direction" bool) to avoid the duplicated block.

The current behavior matches CPython and the new tests, so this is purely a dedup nit.

As per coding guidelines: "When branches differ only in a value but share common logic, extract the differing value first, then call the common logic once to avoid duplicate code."

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@crates/codegen/src/ir.rs` around lines 1584 - 1597, Consolidate the
duplicated JumpIfTrue/JumpIfFalse handling in the instruction rewrite logic
inside the relevant match in ir.rs: both arms in the opcode adjustment path have
identical bodies, so factor the shared target-updating logic into one branch and
guard it with a precomputed “opposite direction” condition. Use the existing
symbols PseudoOpcode, opcode_is_false, inst.target, and
self[block_idx].instructions[i].target to locate the code, and keep the same
behavior while removing the repeated block.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@crates/codegen/src/ir.rs`:
- Around line 1584-1597: Consolidate the duplicated JumpIfTrue/JumpIfFalse
handling in the instruction rewrite logic inside the relevant match in ir.rs:
both arms in the opcode adjustment path have identical bodies, so factor the
shared target-updating logic into one branch and guard it with a precomputed
“opposite direction” condition. Use the existing symbols PseudoOpcode,
opcode_is_false, inst.target, and self[block_idx].instructions[i].target to
locate the code, and keep the same behavior while removing the repeated block.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: 18ca81c0-cb29-4f03-8d1f-1e10a5442574

📥 Commits

Reviewing files that changed from the base of the PR and between 4db90b2 and 86a6360.

📒 Files selected for processing (1)
  • crates/codegen/src/ir.rs

@youknowone youknowone merged commit 19a17d1 into RustPython:main Jun 30, 2026
26 checks passed
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.

2 participants