◐ Shell
reader mode source ↗
Skip to content

Bytecode instrumented placeholder#6741

Merged
youknowone merged 2 commits into
RustPython:mainfrom
ShaharNaveh:bytecode-instrumented-placeholder
Jan 16, 2026
Merged

Bytecode instrumented placeholder#6741
youknowone merged 2 commits into
RustPython:mainfrom
ShaharNaveh:bytecode-instrumented-placeholder

Conversation

@ShaharNaveh

@ShaharNaveh ShaharNaveh commented Jan 16, 2026

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • New Features

    • Expanded bytecode instruction set with specialized and instrumented opcodes to support enhanced code execution capabilities.
  • Refactor

    • Updated instruction encoding, validation logic, and metadata implementation to accommodate expanded opcode set.
    • Adjusted instruction discriminant values for improved alignment.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai

coderabbitai Bot commented Jan 16, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Expanded the Instruction enum with 70+ specialized and instrumented RustPython-only opcodes ranging from 149–254, including Resume, BinaryOp variants, LoadAttr variants, Call variants, and instrumented operations. Moved SetExcInfo/Subscript to positions 132/133 and LoadClosure to 255. Updated TryFrom converter and InstructionMetadata to handle new opcode ranges.

Changes

Cohort / File(s) Summary
Instruction Enum Expansion
crates/compiler-core/src/bytecode/instruction.rs
Added 70+ new enum variants for specialized opcodes (BinaryOp* at 150–156, BinarySubscr* at 157–161, Call* at 162–181, CompareOp* at 182–184, LoadAttr* at 191–202, etc.) and instrumented opcodes (InstrumentedResume–InstrumentedLine at 236–254). Reintroduced Resume { arg: Arg } at 149. Moved SetExcInfo/Subscript from 134/135 to 132/133; moved LoadClosure pseudo from 253 to 255.
TryFrom Implementation
crates/compiler-core/src/bytecode/instruction.rs
Updated TryFrom conversion logic to compute specialized_start/specialized_end and instrumented_start/instrumented_end boundaries; validation now covers expanded opcode ranges alongside existing CPython and custom_ops sets.
InstructionMetadata & Display
crates/compiler-core/src/bytecode/instruction.rs
Extended stack_effect definitions for all 70+ new variants (most with effect 0, targeted adjustments where needed). Updated fmt-dispatch and AnyInstruction routing to accommodate expanded opcode set; pseudo-instruction conversions and formatting logic updated for consistency.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • youknowone

Poem

🐰 Hop! Hop! Our instructions bloom anew,
Seventy sprites in opcodes true—
Binary ops and loads take flight,
Specialized code shines so bright!
Resume's back, the range expands wide,
RustPython's power flows inside! ✨

🚥 Pre-merge checks | ✅ 1 | ❌ 2
❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title is vague and uses a placeholder-like term ('placeholder') that doesn't clearly convey the substantial changes being made to the bytecode instruction set. Consider a more descriptive title that indicates the core purpose, such as 'Add RustPython-only and instrumented opcodes to Instruction enum' or 'Expand bytecode instruction set with specialized and instrumented variants'.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

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

✨ Finishing touches
  • 📝 Generate docstrings

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

🤖 Fix all issues with AI agents
In `@crates/compiler-core/src/bytecode/instruction.rs`:
- Around line 280-374: Instrumented jump opcodes (InstrumentedJumpForward,
InstrumentedJumpBackward, InstrumentedPopJumpIfTrue, InstrumentedPopJumpIfFalse,
InstrumentedPopJumpIfNone, InstrumentedPopJumpIfNotNone) are currently no-arg
placeholders but should either be real control-flow ops or explicit no-op
instrumentation; update them accordingly: if they represent instrumented
control-flow, change their variants to carry Arg<Label>, update their
stack_effects, and add them to label_arg() and
unconditional_branch()/conditional-branch logic so control-flow analysis
recognizes their targets (refer to these enum variants and the functions
label_arg() and unconditional_branch()); if they are only markers, leave them
no-arg but document that intent and add explicit comments/tests and ensure they
are never used in control-flow analysis (e.g., assert they are ignored) so
behavior is clear and consistent across the codebase.
📜 Review details

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 746e71a and 79df18b.

⛔ Files ignored due to path filters (2)
  • Lib/_opcode_metadata.py is excluded by !Lib/**
  • Lib/test/test__opcode.py is excluded by !Lib/**
📒 Files selected for processing (1)
  • crates/compiler-core/src/bytecode/instruction.rs
🧰 Additional context used
📓 Path-based instructions (1)
**/*.rs

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

**/*.rs: Follow the default rustfmt code style using cargo fmt to format Rust code
Always run clippy to lint code (cargo clippy) before completing tasks and fix any warnings or lints introduced by changes
Follow Rust best practices for error handling and memory management
Use the macro system (pyclass, pymodule, pyfunction, etc.) when implementing Python functionality in Rust

Files:

  • crates/compiler-core/src/bytecode/instruction.rs
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (11)
  • GitHub Check: Run snippets and cpython tests (macos-latest)
  • GitHub Check: Run snippets and cpython tests (ubuntu-latest)
  • GitHub Check: Run rust tests (macos-latest)
  • GitHub Check: Ensure compilation on various targets
  • GitHub Check: Run rust tests (ubuntu-latest)
  • GitHub Check: Run rust tests (windows-2025)
  • GitHub Check: Run snippets and cpython tests (windows-2025)
  • GitHub Check: Run tests under miri
  • GitHub Check: Check Rust code with clippy
  • GitHub Check: Run snippets and cpython tests on wasm-wasi
  • GitHub Check: Check the WASM package and demo
🔇 Additional comments (3)
crates/compiler-core/src/bytecode/instruction.rs (3)

248-279: Custom-opcode range update looks consistent.

Thanks for tightening the RustPython-only block and moving SetExcInfo/Subscript; the enum layout now cleanly documents the custom range.


401-448: Validator range updates look good.

The specialized/instrumented ranges are now explicitly accepted, which keeps TryFrom<u8> aligned with the expanded opcode space.


693-784: These are CPython 3.13 bytecode compatibility placeholders that are never emitted.

All the opcodes marked as "Placeholder" (BinaryOpAddFloat, CallBuiltinFast, LoadGlobalBuiltin, InstrumentedJumpForward, etc.) are included in the instruction enum to support deserializing CPython 3.13 bytecode, but they are never actually generated by the RustPython compiler itself. The stack effect of 0 for these opcodes is correct since they will never execute—the actual bytecode generation always uses the primary (non-specialized) instruction variants. No stack-depth analysis issues will occur because the code paths that emit bytecode never produce these placeholder instructions.

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.

@youknowone youknowone left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hide comment

is the newly introduced ops all the pseudo ops?

@ShaharNaveh

Copy link
Copy Markdown
Contributor Author

is the newly introduced ops all the pseudo ops?

None are. All are either specialized or instrumented opcodes

@youknowone

Copy link
Copy Markdown
Member

Thanks! I didn't know about them.

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