◐ Shell
reader mode source ↗
Skip to content

Simplify Intruction.deopt()#7615

Merged
youknowone merged 2 commits into
RustPython:mainfrom
ShaharNaveh:deopt-short
Apr 17, 2026
Merged

Simplify Intruction.deopt()#7615
youknowone merged 2 commits into
RustPython:mainfrom
ShaharNaveh:deopt-short

Conversation

@ShaharNaveh

@ShaharNaveh ShaharNaveh commented Apr 16, 2026

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • Refactor
    • Improved internal compiler infrastructure and code organization for better maintainability.

@coderabbitai

coderabbitai Bot commented Apr 16, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

The changes refactor Instruction::deopt to delegate base opcode construction to Opcode::as_instruction() instead of inline argument handling. Correspondingly, the metadata generation script is rewritten to parse deopt match arms via brace-depth scanning and regex, replacing prior line-based filtering logic.

Changes

Cohort / File(s) Summary
Opcode Deoptimization Refactoring
crates/compiler-core/src/bytecode/instruction.rs
Restructured Instruction::deopt to map specialized opcodes (e.g., ResumeCheck, LoadConstMortal, ToBool*, BinaryOp*, StoreSubscr*, etc.) to corresponding base Opcode variants, delegating marker-field construction to Opcode::as_instruction().
Metadata Parsing Update
scripts/generate_opcode_metadata.py
Rewrote build_deopts to parse deopt implementation using brace-depth scanning for match block extraction and regex for arm extraction, replacing line-based filtering heuristics with explicit error handling for missing match self.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 With ops that hop through deopt's door,
We delegate to as_instruction more,
Brace-depths are scanned with careful care,
A refactor crisp floats through the air!
Bytecode now bounds with pattern so fair,

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Simplify Intruction.deopt()' directly matches the main change: refactoring the deopt method to delegate argument construction to Opcode::as_instruction() rather than inlining it.

✏️ 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.

@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.

Hide comment

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@scripts/generate_opcode_metadata.py`:
- Around line 94-109: The current brace-scan can leave block_start or block_end
as None and then silently slice raw_body[block_start:block_end]; update the scan
logic (using variables brace_depth, block_start, block_end, match_start) to
validate after the loop that both block_start and block_end were found and
raise/throw a clear parsing error (including context like match_start or a
snippet of raw_body) if either is None so the script fails fast instead of
producing incomplete match_body/_specializations.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: 9108f4ed-8656-4d4a-b924-04e0a75cd111

📥 Commits

Reviewing files that changed from the base of the PR and between aa12acc and dfaa089.

📒 Files selected for processing (2)
  • crates/compiler-core/src/bytecode/instruction.rs
  • scripts/generate_opcode_metadata.py

Hide details View details @youknowone youknowone merged commit 2827eca into RustPython:main Apr 17, 2026
20 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