Skip to content

Commit e0cceaf

Browse files
authored
Remove ReturnConst/Break/Continue ops (#6816)
* Remove ReturnConst * Remove break/continue ops
1 parent 3bcd071 commit e0cceaf

14 files changed

+20
-99
lines changed

Lib/_opcode_metadata.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,10 +216,7 @@
216216
'BEFORE_WITH': 213,
217217
'BINARY_SUBSCR': 214,
218218
'BUILD_CONST_KEY_MAP': 215,
219-
'BREAK': 216,
220-
'CONTINUE': 217,
221219
'JUMP_IF_NOT_EXC_MATCH': 220,
222-
'RETURN_CONST': 222,
223220
'SET_EXC_INFO': 223,
224221
'INSTRUMENTED_END_FOR': 234,
225222
'INSTRUMENTED_POP_ITER': 235,

Lib/dis.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434

3535
ENTER_EXECUTOR = opmap['ENTER_EXECUTOR']
3636
LOAD_CONST = opmap['LOAD_CONST']
37-
RETURN_CONST = opmap['RETURN_CONST']
3837
LOAD_GLOBAL = opmap['LOAD_GLOBAL']
3938
BINARY_OP = opmap['BINARY_OP']
4039
JUMP_BACKWARD = opmap['JUMP_BACKWARD']

Lib/test/test_dis.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,8 @@ def bug42562():
210210

211211
dis_bug42562 = """\
212212
RESUME 0
213-
RETURN_CONST 0 (None)
213+
LOAD_CONST 0 (None)
214+
RETURN_VALUE
214215
"""
215216

216217
# Extended arg followed by NOP

Lib/test/test_peepholer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def f():
117117
return None
118118

119119
self.assertNotInBytecode(f, 'LOAD_GLOBAL')
120-
self.assertInBytecode(f, 'RETURN_CONST', None)
120+
self.assertInBytecode(f, 'LOAD_CONST', None)
121121
self.check_lnotab(f)
122122

123123
@unittest.expectedFailure # TODO: RUSTPYTHON

crates/codegen/src/compile.rs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7688,17 +7688,11 @@ impl Compiler {
76887688
}
76897689

76907690
fn emit_return_const(&mut self, constant: ConstantData) {
7691-
let idx = self.arg_constant(constant);
7692-
self.emit_arg(idx, |idx| Instruction::ReturnConst { idx })
7691+
self.emit_load_const(constant);
7692+
emit!(self, Instruction::ReturnValue)
76937693
}
76947694

76957695
fn emit_return_value(&mut self) {
7696-
if let Some(inst) = self.current_block().instructions.last_mut()
7697-
&& let AnyInstruction::Real(Instruction::LoadConst { idx }) = inst.instr
7698-
{
7699-
inst.instr = Instruction::ReturnConst { idx }.into();
7700-
return;
7701-
}
77027696
emit!(self, Instruction::ReturnValue)
77037697
}
77047698

@@ -7876,11 +7870,8 @@ impl Compiler {
78767870
}
78777871

78787872
// Jump to target
7879-
if is_break {
7880-
emit!(self, Instruction::Break { target: exit_block });
7881-
} else {
7882-
emit!(self, Instruction::Continue { target: loop_block });
7883-
}
7873+
let target = if is_break { exit_block } else { loop_block };
7874+
emit!(self, PseudoInstruction::Jump { target });
78847875

78857876
Ok(())
78867877
}

crates/codegen/src/snapshots/rustpython_codegen__compile__tests__if_ands.snap

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/codegen/src/snapshots/rustpython_codegen__compile__tests__if_mixed.snap

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/codegen/src/snapshots/rustpython_codegen__compile__tests__if_ors.snap

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/codegen/src/snapshots/rustpython_codegen__compile__tests__nested_double_async_with.snap

Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/compiler-core/src/bytecode/instruction.rs

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -266,16 +266,7 @@ pub enum Instruction {
266266
BuildConstKeyMap {
267267
size: Arg<u32>,
268268
} = 215, // Placeholder
269-
Break {
270-
target: Arg<Label>,
271-
} = 216,
272-
Continue {
273-
target: Arg<Label>,
274-
} = 217,
275269
JumpIfNotExcMatch(Arg<Label>) = 220,
276-
ReturnConst {
277-
idx: Arg<u32>,
278-
} = 222,
279270
SetExcInfo = 223,
280271
// CPython 3.14 RESUME (128)
281272
Resume {
@@ -427,14 +418,7 @@ impl TryFrom<u8> for Instruction {
427418
u8::from(Self::BuildConstKeyMap {
428419
size: Arg::marker(),
429420
}),
430-
u8::from(Self::Break {
431-
target: Arg::marker(),
432-
}),
433-
u8::from(Self::Continue {
434-
target: Arg::marker(),
435-
}),
436421
u8::from(Self::JumpIfNotExcMatch(Arg::marker())),
437-
u8::from(Self::ReturnConst { idx: Arg::marker() }),
438422
u8::from(Self::SetExcInfo),
439423
];
440424

@@ -463,8 +447,6 @@ impl InstructionMetadata for Instruction {
463447
| Self::PopJumpIfTrue { target: l }
464448
| Self::PopJumpIfFalse { target: l }
465449
| Self::ForIter { target: l }
466-
| Self::Break { target: l }
467-
| Self::Continue { target: l }
468450
| Self::Send { target: l } => Some(*l),
469451
_ => None,
470452
}
@@ -476,10 +458,7 @@ impl InstructionMetadata for Instruction {
476458
Self::JumpForward { .. }
477459
| Self::JumpBackward { .. }
478460
| Self::JumpBackwardNoInterrupt { .. }
479-
| Self::Continue { .. }
480-
| Self::Break { .. }
481461
| Self::ReturnValue
482-
| Self::ReturnConst { .. }
483462
| Self::RaiseVarargs { .. }
484463
| Self::Reraise { .. }
485464
)
@@ -528,8 +507,6 @@ impl InstructionMetadata for Instruction {
528507
Self::GetLen => 1,
529508
Self::CallIntrinsic1 { .. } => 0, // Takes 1, pushes 1
530509
Self::CallIntrinsic2 { .. } => -1, // Takes 2, pushes 1
531-
Self::Continue { .. } => 0,
532-
Self::Break { .. } => 0,
533510
Self::PopJumpIfTrue { .. } => -1,
534511
Self::PopJumpIfFalse { .. } => -1,
535512
Self::MakeFunction => {
@@ -559,7 +536,6 @@ impl InstructionMetadata for Instruction {
559536
Self::ContainsOp(_) => -1,
560537
Self::JumpIfNotExcMatch(_) => -2,
561538
Self::ReturnValue => -1,
562-
Self::ReturnConst { .. } => 0,
563539
Self::Resume { .. } => 0,
564540
Self::YieldValue { .. } => 0,
565541
// SEND: (receiver, val) -> (receiver, retval) - no change, both paths keep same depth
@@ -838,7 +814,6 @@ impl InstructionMetadata for Instruction {
838814
Self::BeforeWith => w!(BEFORE_WITH),
839815
Self::BinaryOp { op } => write!(f, "{:pad$}({})", "BINARY_OP", op.get(arg)),
840816
Self::BinarySubscr => w!(BINARY_SUBSCR),
841-
Self::Break { target } => w!(BREAK, target),
842817
Self::BuildList { size } => w!(BUILD_LIST, size),
843818
Self::BuildMap { size } => w!(BUILD_MAP, size),
844819
Self::BuildSet { size } => w!(BUILD_SET, size),
@@ -855,7 +830,6 @@ impl InstructionMetadata for Instruction {
855830
Self::CleanupThrow => w!(CLEANUP_THROW),
856831
Self::CompareOp { op } => w!(COMPARE_OP, ?op),
857832
Self::ContainsOp(inv) => w!(CONTAINS_OP, ?inv),
858-
Self::Continue { target } => w!(CONTINUE, target),
859833
Self::ConvertValue { oparg } => write!(f, "{:pad$}{}", "CONVERT_VALUE", oparg.get(arg)),
860834
Self::Copy { index } => w!(COPY, index),
861835
Self::DeleteAttr { idx } => w!(DELETE_ATTR, name = idx),
@@ -935,7 +909,6 @@ impl InstructionMetadata for Instruction {
935909
Self::RaiseVarargs { kind } => w!(RAISE_VARARGS, ?kind),
936910
Self::Reraise { depth } => w!(RERAISE, depth),
937911
Self::Resume { arg } => w!(RESUME, arg),
938-
Self::ReturnConst { idx } => fmt_const("RETURN_CONST", arg, f, idx),
939912
Self::ReturnValue => w!(RETURN_VALUE),
940913
Self::Send { target } => w!(SEND, target),
941914
Self::SetAdd { i } => w!(SET_ADD, i),

0 commit comments

Comments
 (0)