Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Next Next commit
Remove ReturnConst
  • Loading branch information
youknowone committed Jan 20, 2026
commit 1de86789c25deb5a7d90c94f58bc38f937131816
1 change: 0 additions & 1 deletion Lib/_opcode_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,6 @@
'BREAK': 216,
'CONTINUE': 217,
'JUMP_IF_NOT_EXC_MATCH': 220,
'RETURN_CONST': 222,
'SET_EXC_INFO': 223,
'INSTRUMENTED_END_FOR': 234,
'INSTRUMENTED_POP_ITER': 235,
Expand Down
1 change: 0 additions & 1 deletion Lib/dis.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@

ENTER_EXECUTOR = opmap['ENTER_EXECUTOR']
LOAD_CONST = opmap['LOAD_CONST']
RETURN_CONST = opmap['RETURN_CONST']
LOAD_GLOBAL = opmap['LOAD_GLOBAL']
BINARY_OP = opmap['BINARY_OP']
JUMP_BACKWARD = opmap['JUMP_BACKWARD']
Expand Down
3 changes: 2 additions & 1 deletion Lib/test/test_dis.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,8 @@ def bug42562():

dis_bug42562 = """\
RESUME 0
RETURN_CONST 0 (None)
LOAD_CONST 0 (None)
RETURN_VALUE
"""

# Extended arg followed by NOP
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_peepholer.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def f():
return None

self.assertNotInBytecode(f, 'LOAD_GLOBAL')
self.assertInBytecode(f, 'RETURN_CONST', None)
self.assertInBytecode(f, 'LOAD_CONST', None)
self.check_lnotab(f)

@unittest.expectedFailure # TODO: RUSTPYTHON
Expand Down
10 changes: 2 additions & 8 deletions crates/codegen/src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7688,17 +7688,11 @@ impl Compiler {
}

fn emit_return_const(&mut self, constant: ConstantData) {
let idx = self.arg_constant(constant);
self.emit_arg(idx, |idx| Instruction::ReturnConst { idx })
self.emit_load_const(constant);
emit!(self, Instruction::ReturnValue)
}

fn emit_return_value(&mut self) {
if let Some(inst) = self.current_block().instructions.last_mut()
&& let AnyInstruction::Real(Instruction::LoadConst { idx }) = inst.instr
{
inst.instr = Instruction::ReturnConst { idx }.into();
return;
}
emit!(self, Instruction::ReturnValue)
}

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 0 additions & 7 deletions crates/compiler-core/src/bytecode/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,9 +273,6 @@ pub enum Instruction {
target: Arg<Label>,
} = 217,
JumpIfNotExcMatch(Arg<Label>) = 220,
ReturnConst {
idx: Arg<u32>,
} = 222,
SetExcInfo = 223,
// CPython 3.14 RESUME (128)
Resume {
Expand Down Expand Up @@ -434,7 +431,6 @@ impl TryFrom<u8> for Instruction {
target: Arg::marker(),
}),
u8::from(Self::JumpIfNotExcMatch(Arg::marker())),
u8::from(Self::ReturnConst { idx: Arg::marker() }),
u8::from(Self::SetExcInfo),
];

Expand Down Expand Up @@ -479,7 +475,6 @@ impl InstructionMetadata for Instruction {
| Self::Continue { .. }
| Self::Break { .. }
| Self::ReturnValue
| Self::ReturnConst { .. }
| Self::RaiseVarargs { .. }
| Self::Reraise { .. }
)
Expand Down Expand Up @@ -559,7 +554,6 @@ impl InstructionMetadata for Instruction {
Self::ContainsOp(_) => -1,
Self::JumpIfNotExcMatch(_) => -2,
Self::ReturnValue => -1,
Self::ReturnConst { .. } => 0,
Self::Resume { .. } => 0,
Self::YieldValue { .. } => 0,
// SEND: (receiver, val) -> (receiver, retval) - no change, both paths keep same depth
Expand Down Expand Up @@ -935,7 +929,6 @@ impl InstructionMetadata for Instruction {
Self::RaiseVarargs { kind } => w!(RAISE_VARARGS, ?kind),
Self::Reraise { depth } => w!(RERAISE, depth),
Self::Resume { arg } => w!(RESUME, arg),
Self::ReturnConst { idx } => fmt_const("RETURN_CONST", arg, f, idx),
Self::ReturnValue => w!(RETURN_VALUE),
Self::Send { target } => w!(SEND, target),
Self::SetAdd { i } => w!(SET_ADD, i),
Expand Down
6 changes: 0 additions & 6 deletions crates/jit/src/instructions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@ impl<'a, 'b> FunctionCompiler<'a, 'b> {
// If that was an unconditional branch or return, mark future instructions unreachable
match instruction {
Instruction::ReturnValue
| Instruction::ReturnConst { .. }
| Instruction::JumpBackward { .. }
| Instruction::JumpBackwardNoInterrupt { .. }
| Instruction::JumpForward { .. } => {
Expand Down Expand Up @@ -628,11 +627,6 @@ impl<'a, 'b> FunctionCompiler<'a, 'b> {
// TODO: Implement the resume instruction
Ok(())
}
Instruction::ReturnConst { idx } => {
let val = self
.prepare_const(bytecode.constants[idx.get(arg) as usize].borrow_constant())?;
self.return_value(val)
}
Instruction::ReturnValue => {
let val = self.stack.pop().ok_or(JitCompileError::BadBytecode)?;
self.return_value(val)
Expand Down
7 changes: 1 addition & 6 deletions crates/jit/tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ fn extract_annotations_from_annotate_code(code: &CodeObject) -> HashMap<Wtf8Buf,
| Instruction::ExtendedArg => {
// Ignore these instructions for annotation extraction
}
Instruction::ReturnValue | Instruction::ReturnConst { .. } => {
Instruction::ReturnValue => {
// End of function - return what we have
return annotations;
}
Expand Down Expand Up @@ -276,11 +276,6 @@ impl StackMachine {
self.stack.push(StackValue::Function(func));
}
}
Instruction::ReturnConst { idx } => {
let idx = idx.get(arg);
self.stack.push(constants[idx as usize].clone().into());
return ControlFlow::Break(());
}
Instruction::ReturnValue => return ControlFlow::Break(()),
Instruction::ExtendedArg => {}
_ => unimplemented!(
Expand Down
4 changes: 1 addition & 3 deletions crates/stdlib/src/opcode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@ mod opcode {
pub fn has_const(opcode: i32) -> bool {
matches!(
Self::try_from(opcode).map(|op| op.inner()),
Ok(AnyInstruction::Real(
Instruction::LoadConst { .. } | Instruction::ReturnConst { .. }
))
Ok(AnyInstruction::Real(Instruction::LoadConst { .. }))
)
}

Expand Down
4 changes: 0 additions & 4 deletions crates/vm/src/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1562,10 +1562,6 @@ impl ExecutingFrame<'_> {
// }
Ok(None)
}
Instruction::ReturnConst { idx } => {
let value = self.code.constants[idx.get(arg) as usize].clone().into();
self.unwind_blocks(vm, UnwindReason::Returning { value })
}
Instruction::ReturnValue => {
let value = self.pop_value();
self.unwind_blocks(vm, UnwindReason::Returning { value })
Expand Down