Fix all clippy suggestions in ir.rs#8162
Conversation
📝 WalkthroughWalkthroughThis PR updates ChangesCodegen IR control-flow refactor
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
crates/codegen/src/ir.rs (1)
1584-1597: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueConsider consolidating the two identical opposite-direction arms.
The
Some(PseudoOpcode::JumpIfTrue) if opcode_is_falseandSome(PseudoOpcode::JumpIfFalse) if !opcode_is_falsearms 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
📒 Files selected for processing (1)
crates/codegen/src/ir.rs
Summary
Summary by CodeRabbit
Refactor
Bug Fixes
Chores