Skip to content

Remove duplicated code in compile.rs#8141

Merged
youknowone merged 1 commit into
RustPython:mainfrom
ShaharNaveh:codegen-remove-is-const-dup-code
Jun 22, 2026
Merged

Remove duplicated code in compile.rs#8141
youknowone merged 1 commit into
RustPython:mainfrom
ShaharNaveh:codegen-remove-is-const-dup-code

Conversation

@ShaharNaveh

@ShaharNaveh ShaharNaveh commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Summary

Summary by CodeRabbit

  • Refactor
    • Refactored constant expression detection logic to improve code organization and maintainability without affecting user-facing functionality.

@coderabbitai

coderabbitai Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: 7104264e-6bb8-4440-9a4f-b66b0a1f8b98

📥 Commits

Reviewing files that changed from the base of the PR and between 55b96f9 and 3bcfd74.

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

📝 Walkthrough

Walkthrough

In compile.rs, the standalone is_const_expression helper function is removed. A new ExprExt trait method is_constant takes over constant-literal detection. The interactive-mode branch that guards Instruction::Nop emission is updated to call value.is_constant() instead of the removed helper.

Changes

Constant detection refactor in compile.rs

Layer / File(s) Summary
ExprExt contract, call site update, and helper removal
crates/codegen/src/compile.rs
Adds ExprExt::is_constant method contract, replaces Self::is_const_expression(value) with value.is_constant() in the interactive-mode Nop-guard branch, and removes the now-redundant is_const_expression(expr: &ast::Expr) -> bool helper function.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Possibly related PRs

  • RustPython/RustPython#7541: Directly related — both PRs touch the ExprExt::is_constant method in crates/codegen/src/compile.rs, with that PR extending the semantics that this PR's call site now relies on.

Poem

🐇 A helper once lived in a function so plain,
Matching literals again and again.
Now the trait takes the wheel with is_constant in tow,
The old code deleted, the logic aglow.
Less is more, little bunny, hop hop away! 🌿

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: removing a duplicated is_const_expression function and consolidating constant-checking logic into an ExprExt extension trait method.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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 and usage tips.

@youknowone youknowone merged commit 73b0c9f into RustPython:main Jun 22, 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