Visitar URL original
Bytecode pseudo opcodes by ShaharNaveh · Pull Request #6715 · RustPython/RustPython · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
fad76c6
save
ShaharNaveh Jan 11, 2026
af70361
Merge remote-tracking branch 'upstream/main' into bytecode-pseudo-opc…
ShaharNaveh Jan 11, 2026
ea53cec
save
ShaharNaveh Jan 11, 2026
1ca20a9
Merge remote-tracking branch 'upstream/main' into bytecode-pseudo-opc…
ShaharNaveh Jan 12, 2026
6f09ebe
Base compiler-core
ShaharNaveh Jan 12, 2026
6805175
save
ShaharNaveh Jan 12, 2026
046e17a
Codegen compile
ShaharNaveh Jan 12, 2026
d627623
Move LoadCloure back to RealInstruction
ShaharNaveh Jan 12, 2026
697fe41
Fix opcode.rs
ShaharNaveh Jan 12, 2026
11fc63f
Merge remote-tracking branch 'upstream/main' into bytecode-pseudo-opc…
ShaharNaveh Jan 13, 2026
33b4554
Fix `TryFrom<u8>` for RealInstruction
ShaharNaveh Jan 13, 2026
6140186
Fix script
ShaharNaveh Jan 13, 2026
7acdc1a
Fix jit
ShaharNaveh Jan 13, 2026
0fad43f
Fix typo
ShaharNaveh Jan 13, 2026
24f5161
Fix typo
ShaharNaveh Jan 13, 2026
6e91410
Remove popblock
ShaharNaveh Jan 13, 2026
8751953
Fix docs
ShaharNaveh Jan 13, 2026
8b73441
Fix more docs
ShaharNaveh Jan 13, 2026
d6e46f8
ok word `argty`
ShaharNaveh Jan 13, 2026
0872cb6
Revert "ok word `argty`"
ShaharNaveh Jan 13, 2026
0c7880d
Rename argty -> arg_ty
ShaharNaveh Jan 13, 2026
1a5c72b
Merge remote-tracking branch 'upstream/main' into bytecode-pseudo-opc…
ShaharNaveh Jan 13, 2026
761fa4a
Simplify `emit` macro
ShaharNaveh Jan 13, 2026
4eed137
Trigger CI
ShaharNaveh Jan 13, 2026
8f777d2
Trigger CI
ShaharNaveh Jan 13, 2026
bff25eb
Trigger CI
ShaharNaveh Jan 13, 2026
91c01e6
Merge remote-tracking branch 'upstream/main' into bytecode-pseudo-opc…
ShaharNaveh Jan 14, 2026
f6a0b26
Merge remote-tracking branch 'upstream/main' into bytecode-pseudo-opc…
ShaharNaveh Jan 14, 2026
118ecf3
Move docs
ShaharNaveh Jan 14, 2026
c517585
Fix oparg docs
ShaharNaveh Jan 14, 2026
78958aa
Revert "Move docs"
ShaharNaveh Jan 14, 2026
a405cca
Merge remote-tracking branch 'upstream/main' into bytecode-pseudo-opc…
ShaharNaveh Jan 14, 2026
8ae98b2
Remove `Eq` & `ParitalEq` for RealInstruction
ShaharNaveh Jan 14, 2026
1453726
Simplify `match` arms
ShaharNaveh Jan 14, 2026
f207284
Trigger CI
ShaharNaveh Jan 14, 2026
a1555dc
Trigger CI
ShaharNaveh Jan 14, 2026
c443f8e
Remove `repr(u16)` for `Instruction`
ShaharNaveh Jan 14, 2026
453212e
Fix doc
ShaharNaveh Jan 14, 2026
1f8722a
Rename the enums
ShaharNaveh Jan 14, 2026
0096a65
Restore fmt_dis for LoadClousure
ShaharNaveh Jan 14, 2026
045d576
Fix script
ShaharNaveh Jan 14, 2026
b00f81f
Fix commet
ShaharNaveh Jan 14, 2026
4823d17
Merge remote-tracking branch 'upstream/main' into bytecode-pseudo-opc…
ShaharNaveh Jan 14, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Rename the enums
  • Loading branch information
ShaharNaveh committed Jan 14, 2026
commit 1f8722a9ad18bde3dc5b0b54e426b697ce5c5b35
848 changes: 421 additions & 427 deletions crates/codegen/src/compile.rs

Large diffs are not rendered by default.

39 changes: 19 additions & 20 deletions crates/codegen/src/ir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ use crate::{IndexMap, IndexSet, error::InternalError};
use rustpython_compiler_core::{
OneIndexed, SourceLocation,
bytecode::{
Arg, CodeFlags, CodeObject, CodeUnit, CodeUnits, ConstantData, ExceptionTableEntry,
InstrDisplayContext, Instruction, InstructionMetadata, Label, OpArg, PseudoInstruction,
PyCodeLocationInfoKind, RealInstruction, encode_exception_table, encode_load_attr_arg,
AnyInstruction, Arg, CodeFlags, CodeObject, CodeUnit, CodeUnits, ConstantData,
ExceptionTableEntry, InstrDisplayContext, Instruction, InstructionMetadata, Label, OpArg,
PseudoInstruction, PyCodeLocationInfoKind, encode_exception_table, encode_load_attr_arg,
encode_load_super_attr_arg,
},
varint::{write_signed_varint, write_varint},
Expand Down Expand Up @@ -87,7 +87,7 @@ impl ops::IndexMut<BlockIdx> for Vec<Block> {

#[derive(Debug, Clone)]
pub struct InstructionInfo {
pub instr: Instruction,
pub instr: AnyInstruction,
pub arg: OpArg,
pub target: BlockIdx,
pub location: SourceLocation,
Expand Down Expand Up @@ -198,24 +198,23 @@ impl CodeInfo {
{
for info in &mut block.instructions {
// Special case for:
// - `RealInstruction::LoadAttr`
// - `RealInstruction::LoadSuperAttr`
// - `Instruction::LoadAttr`
// - `Instruction::LoadSuperAttr`

if let Some(instr) = info.instr.real() {
match instr {
// LOAD_ATTR → encode with method flag=0
RealInstruction::LoadAttr { idx } => {
Instruction::LoadAttr { idx } => {
let encoded = encode_load_attr_arg(idx.get(info.arg), false);
info.arg = OpArg(encoded);
info.instr = RealInstruction::LoadAttr { idx: Arg::marker() }.into();
info.instr = Instruction::LoadAttr { idx: Arg::marker() }.into();
}
// LOAD_SUPER_ATTR → encode with flags=0b10 (method=0, class=1)
RealInstruction::LoadSuperAttr { arg: idx } => {
Instruction::LoadSuperAttr { arg: idx } => {
let encoded =
encode_load_super_attr_arg(idx.get(info.arg), false, true);
info.arg = OpArg(encoded);
info.instr =
RealInstruction::LoadSuperAttr { arg: Arg::marker() }.into();
info.instr = Instruction::LoadSuperAttr { arg: Arg::marker() }.into();
}
_ => {}
}
Expand All @@ -230,29 +229,29 @@ impl CodeInfo {
PseudoInstruction::LoadAttrMethod { idx } => {
let encoded = encode_load_attr_arg(idx.get(info.arg), true);
info.arg = OpArg(encoded);
info.instr = RealInstruction::LoadAttr { idx: Arg::marker() }.into();
info.instr = Instruction::LoadAttr { idx: Arg::marker() }.into();
}
// POP_BLOCK pseudo → NOP
PseudoInstruction::PopBlock => {
info.instr = RealInstruction::Nop.into();
info.instr = Instruction::Nop.into();
}
// LOAD_SUPER_METHOD pseudo → LOAD_SUPER_ATTR (flags=0b11: method=1, class=1)
PseudoInstruction::LoadSuperMethod { idx } => {
let encoded = encode_load_super_attr_arg(idx.get(info.arg), true, true);
info.arg = OpArg(encoded);
info.instr = RealInstruction::LoadSuperAttr { arg: Arg::marker() }.into();
info.instr = Instruction::LoadSuperAttr { arg: Arg::marker() }.into();
}
// LOAD_ZERO_SUPER_ATTR pseudo → LOAD_SUPER_ATTR (flags=0b00: method=0, class=0)
PseudoInstruction::LoadZeroSuperAttr { idx } => {
let encoded = encode_load_super_attr_arg(idx.get(info.arg), false, false);
info.arg = OpArg(encoded);
info.instr = RealInstruction::LoadSuperAttr { arg: Arg::marker() }.into();
info.instr = Instruction::LoadSuperAttr { arg: Arg::marker() }.into();
}
// LOAD_ZERO_SUPER_METHOD pseudo → LOAD_SUPER_ATTR (flags=0b01: method=1, class=0)
PseudoInstruction::LoadZeroSuperMethod { idx } => {
let encoded = encode_load_super_attr_arg(idx.get(info.arg), true, false);
info.arg = OpArg(encoded);
info.instr = RealInstruction::LoadSuperAttr { arg: Arg::marker() }.into();
info.instr = Instruction::LoadSuperAttr { arg: Arg::marker() }.into();
}
PseudoInstruction::Jump { .. } => {
// PseudoInstruction::Jump instructions are handled later
Expand Down Expand Up @@ -305,16 +304,16 @@ impl CodeInfo {

// Convert JUMP pseudo to real instructions (direction depends on offset)
let op = match info.instr {
Instruction::Pseudo(PseudoInstruction::Jump { .. })
AnyInstruction::Pseudo(PseudoInstruction::Jump { .. })
if target != BlockIdx::NULL =>
{
let target_offset = block_to_offset[target.idx()].0;
if target_offset > current_offset {
RealInstruction::JumpForward {
Instruction::JumpForward {
target: Arg::marker(),
}
} else {
RealInstruction::JumpBackward {
Instruction::JumpBackward {
target: Arg::marker(),
}
}
Expand All @@ -329,7 +328,7 @@ impl CodeInfo {
));
instructions.extend(
extras
.map(|byte| CodeUnit::new(RealInstruction::ExtendedArg, byte))
.map(|byte| CodeUnit::new(Instruction::ExtendedArg, byte))
.chain([CodeUnit { op, arg: lo_arg }]),
);
current_offset += info.arg.instr_size() as u32;
Expand Down
6 changes: 3 additions & 3 deletions crates/compiler-core/src/bytecode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use rustpython_wtf8::{Wtf8, Wtf8Buf};

pub use crate::bytecode::{
instruction::{
Arg, Instruction, InstructionMetadata, PseudoInstruction, RealInstruction,
AnyInstruction, Arg, Instruction, InstructionMetadata, PseudoInstruction,
decode_load_attr_arg, decode_load_super_attr_arg, encode_load_attr_arg,
encode_load_super_attr_arg,
},
Expand Down Expand Up @@ -303,14 +303,14 @@ bitflags! {
#[derive(Copy, Clone)]
#[repr(C)]
pub struct CodeUnit {
pub op: RealInstruction,
pub op: Instruction,
pub arg: OpArgByte,
}

const _: () = assert!(mem::size_of::<CodeUnit>() == 2);

impl CodeUnit {
pub const fn new(op: RealInstruction, arg: OpArgByte) -> Self {
pub const fn new(op: Instruction, arg: OpArgByte) -> Self {
Self { op, arg }
}
}
Expand Down
62 changes: 34 additions & 28 deletions crates/compiler-core/src/bytecode/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,15 @@ use crate::{
marshal::MarshalError,
};

/// A Single bytecode instruction.
/// All instructions above 44 have an argument.
/// A Single bytecode instruction that are executed by the VM.
///
/// Currently aligned with CPython 3.13.
///
/// ## See also
/// - [CPython opcode IDs](https://github.com/python/cpython/blob/627894459a84be3488a1789919679c997056a03c/Include/opcode_ids.h)
#[derive(Clone, Copy, Debug)]
Comment on lines +15 to +21

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.

⚠️ Potential issue | 🟡 Minor

Fix docs grammar (“instruction … is executed”).

“A Single bytecode instruction that are executed…” should be singular (“is executed”). Also consider “single” vs “Single” for style consistency.

🤖 Prompt for AI Agents
In `@crates/compiler-core/src/bytecode/instruction.rs` around lines 15 - 21, The
doc comment for the Instruction type has a grammar/style issue: change "A Single
bytecode instruction that are executed by the VM." to a grammatically correct,
stylistically consistent sentence such as "A single bytecode instruction that is
executed by the VM." Update the comment above the #[derive(Clone, Copy, Debug)]
(the Instruction documentation block) to use lowercase "single" and singular
verb "is executed" while leaving the rest of the doc (CPython reference lines)
intact.

#[repr(u8)]
pub enum RealInstruction {
pub enum Instruction {
// ==================== No-argument instructions (opcode < 44) ====================
Cache = 0, // Placeholder
BeforeAsyncWith = 1,
Expand Down Expand Up @@ -275,20 +279,21 @@ pub enum RealInstruction {
JumpIfNotExcMatch(Arg<Label>) = 131,
SetExcInfo = 134,
Subscript = 135,
// Pseudos (needs to be moved to `PseudoInstruction` enum.
LoadClosure(Arg<NameIdx>) = 253, // TODO: Move to pseudos
}
Comment on lines +282 to 284

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.

⚠️ Potential issue | 🟡 Minor

Comment typo / unfinished paren in “Pseudos … enum.”

Line 282 reads like it’s missing a closing ) and could be tightened since the enum name is already Instruction.

🤖 Prompt for AI Agents
In `@crates/compiler-core/src/bytecode/instruction.rs` around lines 282 - 284, The
comment above the LoadClosure variant has a typo/unfinished parenthesis; update
the comment to a clean, concise note (e.g., "Pseudos — should be moved to
PseudoInstruction enum.") and remove the stray parenthesis so it reads properly,
and keep the existing TODO about moving LoadClosure(Arg<NameIdx>) = 253 into the
PseudoInstruction enum.


const _: () = assert!(mem::size_of::<RealInstruction>() == 1);
const _: () = assert!(mem::size_of::<Instruction>() == 1);

impl From<RealInstruction> for u8 {
impl From<Instruction> for u8 {
#[inline]
fn from(ins: RealInstruction) -> Self {
fn from(ins: Instruction) -> Self {
// SAFETY: there's no padding bits
unsafe { core::mem::transmute::<RealInstruction, Self>(ins) }
unsafe { mem::transmute::<Instruction, Self>(ins) }
}
}

impl TryFrom<u8> for RealInstruction {
impl TryFrom<u8> for Instruction {
type Error = MarshalError;

#[inline]
Expand Down Expand Up @@ -341,14 +346,14 @@ impl TryFrom<u8> for RealInstruction {
|| value == load_closure
|| custom_ops.contains(&value)
{
Ok(unsafe { core::mem::transmute::<u8, Self>(value) })
Ok(unsafe { mem::transmute::<u8, Self>(value) })
} else {
Err(Self::Error::InvalidBytecode)
}
}
}

impl InstructionMetadata for RealInstruction {
impl InstructionMetadata for Instruction {
#[inline]
fn label_arg(&self) -> Option<Arg<Label>> {
match self {
Expand Down Expand Up @@ -783,6 +788,7 @@ impl InstructionMetadata for RealInstruction {
}
}

/// Instructions used by the compiler. They are not executed by the VM.
#[derive(Clone, Copy, Debug)]
#[repr(u16)]
pub enum PseudoInstruction {
Expand Down Expand Up @@ -821,7 +827,7 @@ impl From<PseudoInstruction> for u16 {
#[inline]
fn from(ins: PseudoInstruction) -> Self {
// SAFETY: there's no padding bits
unsafe { core::mem::transmute::<PseudoInstruction, Self>(ins) }
unsafe { mem::transmute::<PseudoInstruction, Self>(ins) }
}
}

Expand All @@ -836,7 +842,7 @@ impl TryFrom<u16> for PseudoInstruction {
let end = u16::from(Self::StoreFastMaybeNull);

if (start..=end).contains(&value) {
Ok(unsafe { core::mem::transmute::<u16, Self>(value) })
Ok(unsafe { mem::transmute::<u16, Self>(value) })
} else {
Err(Self::Error::InvalidBytecode)
}
Expand Down Expand Up @@ -886,32 +892,32 @@ impl InstructionMetadata for PseudoInstruction {
}
Comment on lines +881 to +892

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.

⚠️ Potential issue | 🟡 Minor

fmt_dis for PseudoInstruction panics unconditionally.

This unimplemented!() will panic if Instruction::Pseudo is ever formatted via the InstructionMetadata trait (e.g., during debug/disassembly output). Consider providing a minimal implementation or at least using todo!("PseudoInstruction display not yet implemented") for a clearer error message.

Minimal implementation suggestion
     fn fmt_dis(
         &self,
-        _arg: OpArg,
-        _f: &mut fmt::Formatter<'_>,
-        _ctx: &impl InstrDisplayContext,
+        arg: OpArg,
+        f: &mut fmt::Formatter<'_>,
+        _ctx: &impl InstrDisplayContext,
         _expand_code_objects: bool,
-        _pad: usize,
+        pad: usize,
         _level: usize,
     ) -> fmt::Result {
-        unimplemented!()
+        match self {
+            Self::Jump { target } => write!(f, "{:pad$}({})", "JUMP", target.get(arg)),
+            Self::JumpNoInterrupt { target } => write!(f, "{:pad$}({})", "JUMP_NO_INTERRUPT", target.get(arg)),
+            Self::LoadAttrMethod { idx } => write!(f, "{:pad$}({})", "LOAD_ATTR_METHOD", idx.get(arg)),
+            Self::LoadSuperMethod { idx } => write!(f, "{:pad$}({})", "LOAD_SUPER_METHOD", idx.get(arg)),
+            Self::LoadZeroSuperAttr { idx } => write!(f, "{:pad$}({})", "LOAD_ZERO_SUPER_ATTR", idx.get(arg)),
+            Self::LoadZeroSuperMethod { idx } => write!(f, "{:pad$}({})", "LOAD_ZERO_SUPER_METHOD", idx.get(arg)),
+            Self::PopBlock => write!(f, "POP_BLOCK"),
+            _ => write!(f, "PSEUDO_PLACEHOLDER"),
+        }
     }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
fn fmt_dis(
&self,
_arg: OpArg,
_f: &mut fmt::Formatter<'_>,
_ctx: &impl InstrDisplayContext,
_expand_code_objects: bool,
_pad: usize,
_level: usize,
) -> fmt::Result {
unimplemented!()
}
}
fn fmt_dis(
&self,
arg: OpArg,
f: &mut fmt::Formatter<'_>,
_ctx: &impl InstrDisplayContext,
_expand_code_objects: bool,
pad: usize,
_level: usize,
) -> fmt::Result {
match self {
Self::Jump { target } => write!(f, "{:pad$}({})", "JUMP", target.get(arg)),
Self::JumpNoInterrupt { target } => write!(f, "{:pad$}({})", "JUMP_NO_INTERRUPT", target.get(arg)),
Self::LoadAttrMethod { idx } => write!(f, "{:pad$}({})", "LOAD_ATTR_METHOD", idx.get(arg)),
Self::LoadSuperMethod { idx } => write!(f, "{:pad$}({})", "LOAD_SUPER_METHOD", idx.get(arg)),
Self::LoadZeroSuperAttr { idx } => write!(f, "{:pad$}({})", "LOAD_ZERO_SUPER_ATTR", idx.get(arg)),
Self::LoadZeroSuperMethod { idx } => write!(f, "{:pad$}({})", "LOAD_ZERO_SUPER_METHOD", idx.get(arg)),
Self::PopBlock => write!(f, "POP_BLOCK"),
_ => write!(f, "PSEUDO_PLACEHOLDER"),
}
}
}
🤖 Prompt for AI Agents
In `@crates/compiler-core/src/bytecode/instruction.rs` around lines 893 - 904, The
fmt_dis implementation for PseudoInstruction currently calls unimplemented!()
and will panic if Instruction::Pseudo is ever formatted via InstructionMetadata;
replace the panic with a defensive implementation (or at minimum a clearer
todo!) by updating the fmt_dis method on the
PseudoInstruction/Instruction::Pseudo branch: either call
todo!("PseudoInstruction display not yet implemented") to provide a clearer
error or implement a minimal formatter that writes a placeholder string (e.g.,
the pseudo opcode name and any relevant fields) to the provided fmt::Formatter,
respecting the signature of fmt_dis and using the
_ctx/_expand_code_objects/_pad/_level params as no-ops if not needed. Ensure the
change is made in the fmt_dis function so formatting of Instruction::Pseudo no
longer panics.


#[derive(Clone, Copy, Debug)]
pub enum Instruction {
Real(RealInstruction),
pub enum AnyInstruction {
Real(Instruction),
Pseudo(PseudoInstruction),
}

impl From<RealInstruction> for Instruction {
fn from(value: RealInstruction) -> Self {
impl From<Instruction> for AnyInstruction {
fn from(value: Instruction) -> Self {
Self::Real(value)
}
}

impl From<PseudoInstruction> for Instruction {
impl From<PseudoInstruction> for AnyInstruction {
fn from(value: PseudoInstruction) -> Self {
Self::Pseudo(value)
}
}

impl TryFrom<u8> for Instruction {
impl TryFrom<u8> for AnyInstruction {
type Error = MarshalError;

fn try_from(value: u8) -> Result<Self, Self::Error> {
Ok(RealInstruction::try_from(value)?.into())
Ok(Instruction::try_from(value)?.into())
}
}

impl TryFrom<u16> for Instruction {
impl TryFrom<u16> for AnyInstruction {
type Error = MarshalError;

fn try_from(value: u16) -> Result<Self, Self::Error> {
Expand All @@ -933,7 +939,7 @@ macro_rules! inst_either {
};
}

impl InstructionMetadata for Instruction {
impl InstructionMetadata for AnyInstruction {
inst_either!(fn label_arg(&self) -> Option<Arg<Label>>);

inst_either!(fn unconditional_branch(&self) -> bool);
Expand All @@ -951,9 +957,9 @@ impl InstructionMetadata for Instruction {
) -> fmt::Result);
}

impl Instruction {
impl AnyInstruction {
/// Gets the inner value of [`Self::Real`].
pub const fn real(self) -> Option<RealInstruction> {
pub const fn real(self) -> Option<Instruction> {
match self {
Self::Real(ins) => Some(ins),
_ => None,
Expand All @@ -973,7 +979,7 @@ impl Instruction {
/// # Panics
///
/// If was called on something else other than [`Self::Real`].
pub const fn expect_real(self) -> RealInstruction {
pub const fn expect_real(self) -> Instruction {
self.real()
.expect("Expected Instruction::Real, found Instruction::Pseudo")
}
Expand All @@ -998,8 +1004,8 @@ pub trait InstructionMetadata {
/// # Examples
///
/// ```
/// use rustpython_compiler_core::bytecode::{Arg, RealInstruction, InstructionMetadata};
/// let jump_inst = RealInstruction::JumpForward { target: Arg::marker() };
/// use rustpython_compiler_core::bytecode::{Arg, Instruction, InstructionMetadata};
/// let jump_inst = Instruction::JumpForward { target: Arg::marker() };
/// assert!(jump_inst.unconditional_branch())
/// ```
fn unconditional_branch(&self) -> bool;
Expand All @@ -1009,9 +1015,9 @@ pub trait InstructionMetadata {
/// # Examples
///
/// ```
/// use rustpython_compiler_core::bytecode::{Arg, RealInstruction, Label, InstructionMetadata};
/// use rustpython_compiler_core::bytecode::{Arg, Instruction, Label, InstructionMetadata};
/// let (target, jump_arg) = Arg::new(Label(0xF));
/// let jump_instruction = RealInstruction::JumpForward { target };
/// let jump_instruction = Instruction::JumpForward { target };
/// assert_eq!(jump_instruction.stack_effect(jump_arg, true), 0);
/// ```
fn stack_effect(&self, arg: OpArg, jump: bool) -> i32;
Expand Down
14 changes: 7 additions & 7 deletions crates/compiler-core/src/bytecode/oparg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use bitflags::bitflags;

use core::{fmt, num::NonZeroU8};

use crate::bytecode::{CodeUnit, instruction::RealInstruction};
use crate::bytecode::{CodeUnit, instruction::Instruction};

pub trait OpArgType: Copy {
fn from_op_arg(x: u32) -> Option<Self>;
Expand Down Expand Up @@ -78,9 +78,9 @@ pub struct OpArgState {

impl OpArgState {
#[inline(always)]
pub fn get(&mut self, ins: CodeUnit) -> (RealInstruction, OpArg) {
pub fn get(&mut self, ins: CodeUnit) -> (Instruction, OpArg) {
let arg = self.extend(ins.arg);
if !matches!(ins.op, RealInstruction::ExtendedArg) {
if !matches!(ins.op, Instruction::ExtendedArg) {
self.reset();
}
(ins.op, arg)
Expand All @@ -98,7 +98,7 @@ impl OpArgState {
}
}

/// Oparg values for [`RealInstruction::ConvertValue`].
/// Oparg values for [`Instruction::ConvertValue`].
///
/// ## See also
///
Expand Down Expand Up @@ -142,7 +142,7 @@ impl fmt::Display for ConvertValueOparg {
Self::Str => "1 (str)",
Self::Repr => "2 (repr)",
Self::Ascii => "3 (ascii)",
// We should never reach this. `FVC_NONE` are being handled by `RealInstruction::FormatSimple`
// We should never reach this. `FVC_NONE` are being handled by `Instruction::FormatSimple`
Self::None => "",
};

Expand Down Expand Up @@ -364,9 +364,9 @@ op_arg_enum!(
/// # Examples
///
/// ```rust
/// use rustpython_compiler_core::bytecode::{Arg, BinaryOperator, RealInstruction};
/// use rustpython_compiler_core::bytecode::{Arg, BinaryOperator, Instruction};
/// let (op, _) = Arg::new(BinaryOperator::Add);
/// let instruction = RealInstruction::BinaryOp { op };
/// let instruction = Instruction::BinaryOp { op };
/// ```
///
/// See also:
Expand Down
Loading
Loading