Skip to content

Remove oparg builders#7537

Merged
youknowone merged 1 commit intoRustPython:mainfrom
ShaharNaveh:oparg-no-builders
Mar 30, 2026
Merged

Remove oparg builders#7537
youknowone merged 1 commit intoRustPython:mainfrom
ShaharNaveh:oparg-no-builders

Conversation

@ShaharNaveh
Copy link
Copy Markdown
Contributor

@ShaharNaveh ShaharNaveh commented Mar 30, 2026

Replace builder structs with a simpler X::new(...) method

Summary by CodeRabbit

  • Chores
    • Internal code refactoring to improve maintainability and simplify bytecode argument construction patterns.

Note: This release contains no user-facing changes.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 30, 2026

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: 0d6d7117-cced-4dab-9361-3cb8fd8f38d6

📥 Commits

Reviewing files that changed from the base of the PR and between 3706c53 and 95eca59.

📒 Files selected for processing (2)
  • crates/codegen/src/compile.rs
  • crates/compiler-core/src/bytecode/oparg.rs

📝 Walkthrough

Walkthrough

Replaced the builder-pattern API for LoadAttr and LoadSuperAttr bytecode argument types with direct const fn new(...) constructors. The changes remove builder structs and methods from the type definitions and update all call sites in the bytecode emission code to use the new constructors instead.

Changes

Cohort / File(s) Summary
Bytecode Oparg Type Definitions
crates/compiler-core/src/bytecode/oparg.rs
Removed LoadAttrBuilder and LoadSuperAttrBuilder structs along with their builder methods. Added LoadAttr::new(name_idx, is_method) and LoadSuperAttr::new(name_idx, is_load_method, has_class) as const fn constructors that perform field packing inline.
Bytecode Emission Call Sites
crates/codegen/src/compile.rs
Updated six private helper methods (emit_load_attr, emit_load_attr_method, emit_load_super_attr, emit_load_super_method, emit_load_zero_super_attr, emit_load_zero_super_method) to call the new constructors directly instead of using builder methods.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • youknowone

Poem

🐰 Builders once nested, now constructors shine,
const fn packing, fields align,
No more patterns, just direct and clean,
The fastest bytecode ever seen! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Remove oparg builders' directly and accurately reflects the main change: replacing builder-pattern APIs with direct constructors in the oparg module, affecting LoadAttr and LoadSuperAttr types.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ 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 959b088 into RustPython:main Mar 30, 2026
15 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