Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 0 additions & 3 deletions Lib/_opcode_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,7 @@
'BEFORE_WITH': 213,
'BINARY_SUBSCR': 214,
'BUILD_CONST_KEY_MAP': 215,
'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
17 changes: 4 additions & 13 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 Expand Up @@ -7876,11 +7870,8 @@ impl Compiler {
}

// Jump to target
if is_break {
emit!(self, Instruction::Break { target: exit_block });
} else {
emit!(self, Instruction::Continue { target: loop_block });
}
let target = if is_break { exit_block } else { loop_block };
emit!(self, PseudoInstruction::Jump { target });

Ok(())
}
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.

27 changes: 0 additions & 27 deletions crates/compiler-core/src/bytecode/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,16 +266,7 @@ pub enum Instruction {
BuildConstKeyMap {
size: Arg<u32>,
} = 215, // Placeholder
Break {
target: Arg<Label>,
} = 216,
Continue {
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 @@ -427,14 +418,7 @@ impl TryFrom<u8> for Instruction {
u8::from(Self::BuildConstKeyMap {
size: Arg::marker(),
}),
u8::from(Self::Break {
target: Arg::marker(),
}),
u8::from(Self::Continue {
target: Arg::marker(),
}),
u8::from(Self::JumpIfNotExcMatch(Arg::marker())),
u8::from(Self::ReturnConst { idx: Arg::marker() }),
u8::from(Self::SetExcInfo),
];

Expand Down Expand Up @@ -463,8 +447,6 @@ impl InstructionMetadata for Instruction {
| Self::PopJumpIfTrue { target: l }
| Self::PopJumpIfFalse { target: l }
| Self::ForIter { target: l }
| Self::Break { target: l }
| Self::Continue { target: l }
| Self::Send { target: l } => Some(*l),
_ => None,
}
Expand All @@ -476,10 +458,7 @@ impl InstructionMetadata for Instruction {
Self::JumpForward { .. }
| Self::JumpBackward { .. }
| Self::JumpBackwardNoInterrupt { .. }
| Self::Continue { .. }
| Self::Break { .. }
| Self::ReturnValue
| Self::ReturnConst { .. }
| Self::RaiseVarargs { .. }
| Self::Reraise { .. }
)
Expand Down Expand Up @@ -528,8 +507,6 @@ impl InstructionMetadata for Instruction {
Self::GetLen => 1,
Self::CallIntrinsic1 { .. } => 0, // Takes 1, pushes 1
Self::CallIntrinsic2 { .. } => -1, // Takes 2, pushes 1
Self::Continue { .. } => 0,
Self::Break { .. } => 0,
Self::PopJumpIfTrue { .. } => -1,
Self::PopJumpIfFalse { .. } => -1,
Self::MakeFunction => {
Expand Down Expand Up @@ -559,7 +536,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 @@ -838,7 +814,6 @@ impl InstructionMetadata for Instruction {
Self::BeforeWith => w!(BEFORE_WITH),
Self::BinaryOp { op } => write!(f, "{:pad$}({})", "BINARY_OP", op.get(arg)),
Self::BinarySubscr => w!(BINARY_SUBSCR),
Self::Break { target } => w!(BREAK, target),
Self::BuildList { size } => w!(BUILD_LIST, size),
Self::BuildMap { size } => w!(BUILD_MAP, size),
Self::BuildSet { size } => w!(BUILD_SET, size),
Expand All @@ -855,7 +830,6 @@ impl InstructionMetadata for Instruction {
Self::CleanupThrow => w!(CLEANUP_THROW),
Self::CompareOp { op } => w!(COMPARE_OP, ?op),
Self::ContainsOp(inv) => w!(CONTAINS_OP, ?inv),
Self::Continue { target } => w!(CONTINUE, target),
Self::ConvertValue { oparg } => write!(f, "{:pad$}{}", "CONVERT_VALUE", oparg.get(arg)),
Self::Copy { index } => w!(COPY, index),
Self::DeleteAttr { idx } => w!(DELETE_ATTR, name = idx),
Expand Down Expand Up @@ -935,7 +909,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
8 changes: 2 additions & 6 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 Expand Up @@ -104,9 +102,7 @@ mod opcode {
matches!(
Self::try_from(opcode).map(|op| op.inner()),
Ok(AnyInstruction::Real(
Instruction::Break { .. }
| Instruction::Continue { .. }
| Instruction::ForIter { .. }
Instruction::ForIter { .. }
| Instruction::JumpIfNotExcMatch(_)
| Instruction::PopJumpIfFalse { .. }
| Instruction::PopJumpIfTrue { .. }
Expand Down
29 changes: 0 additions & 29 deletions crates/vm/src/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,6 @@ enum UnwindReason {
/// We hit an exception, so unwind any try-except and finally blocks. The exception should be
/// on top of the vm exception stack.
Raising { exception: PyBaseExceptionRef },

// NoWorries,
/// We are unwinding blocks, since we hit break
Break { target: bytecode::Label },

/// We are unwinding blocks since we hit a continue statements.
Continue { target: bytecode::Label },
}

#[derive(Debug)]
Expand Down Expand Up @@ -658,12 +651,6 @@ impl ExecutingFrame<'_> {
Ok(None)
}

Instruction::Break { target } => self.unwind_blocks(
vm,
UnwindReason::Break {
target: target.get(arg),
},
),
Instruction::BuildList { size } => {
let sz = size.get(arg) as usize;
let elements = self.pop_multiple(sz).collect();
Expand Down Expand Up @@ -804,13 +791,6 @@ impl ExecutingFrame<'_> {
self.push_value(vm.ctx.new_bool(value).into());
Ok(None)
}
Instruction::Continue { target } => self.unwind_blocks(
vm,
UnwindReason::Continue {
target: target.get(arg),
},
),

Instruction::ConvertValue { oparg: conversion } => {
self.convert_value(conversion.get(arg), vm)
}
Expand Down Expand Up @@ -1562,10 +1542,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 Expand Up @@ -2059,11 +2035,6 @@ impl ExecutingFrame<'_> {
drop(fastlocals);
Ok(Some(ExecutionResult::Return(value)))
}
UnwindReason::Break { target } | UnwindReason::Continue { target } => {
// Break/continue: jump to the target label
self.jump(target);
Ok(None)
}
}
}

Expand Down
Loading