diff --git a/Lib/_opcode_metadata.py b/Lib/_opcode_metadata.py index f219132b9c3..2effcd30536 100644 --- a/Lib/_opcode_metadata.py +++ b/Lib/_opcode_metadata.py @@ -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, diff --git a/Lib/dis.py b/Lib/dis.py index 797e0f8a088..77308aac958 100644 --- a/Lib/dis.py +++ b/Lib/dis.py @@ -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'] diff --git a/Lib/test/test_dis.py b/Lib/test/test_dis.py index a585643cba6..f1252fb242a 100644 --- a/Lib/test/test_dis.py +++ b/Lib/test/test_dis.py @@ -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 diff --git a/Lib/test/test_peepholer.py b/Lib/test/test_peepholer.py index 50ac8aef2f3..87ebc3e395a 100644 --- a/Lib/test/test_peepholer.py +++ b/Lib/test/test_peepholer.py @@ -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 diff --git a/crates/codegen/src/compile.rs b/crates/codegen/src/compile.rs index 93a759c7ff4..6902c092988 100644 --- a/crates/codegen/src/compile.rs +++ b/crates/codegen/src/compile.rs @@ -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) } @@ -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(()) } diff --git a/crates/codegen/src/snapshots/rustpython_codegen__compile__tests__if_ands.snap b/crates/codegen/src/snapshots/rustpython_codegen__compile__tests__if_ands.snap index 4c9c29887ee..fb052cb2665 100644 --- a/crates/codegen/src/snapshots/rustpython_codegen__compile__tests__if_ands.snap +++ b/crates/codegen/src/snapshots/rustpython_codegen__compile__tests__if_ands.snap @@ -9,4 +9,5 @@ expression: "compile_exec(\"\\\nif True and False and False:\n pass\n\")" 4 LOAD_CONST (False) 5 POP_JUMP_IF_FALSE (6) - 2 >> 6 RETURN_CONST (None) + 2 >> 6 LOAD_CONST (None) + 7 RETURN_VALUE diff --git a/crates/codegen/src/snapshots/rustpython_codegen__compile__tests__if_mixed.snap b/crates/codegen/src/snapshots/rustpython_codegen__compile__tests__if_mixed.snap index a93479df96e..021f88e3d47 100644 --- a/crates/codegen/src/snapshots/rustpython_codegen__compile__tests__if_mixed.snap +++ b/crates/codegen/src/snapshots/rustpython_codegen__compile__tests__if_mixed.snap @@ -11,4 +11,5 @@ expression: "compile_exec(\"\\\nif (True and False) or (False and True):\n pa 6 LOAD_CONST (True) 7 POP_JUMP_IF_FALSE (8) - 2 >> 8 RETURN_CONST (None) + 2 >> 8 LOAD_CONST (None) + 9 RETURN_VALUE diff --git a/crates/codegen/src/snapshots/rustpython_codegen__compile__tests__if_ors.snap b/crates/codegen/src/snapshots/rustpython_codegen__compile__tests__if_ors.snap index 37a862cc65a..2096e88374a 100644 --- a/crates/codegen/src/snapshots/rustpython_codegen__compile__tests__if_ors.snap +++ b/crates/codegen/src/snapshots/rustpython_codegen__compile__tests__if_ors.snap @@ -9,4 +9,5 @@ expression: "compile_exec(\"\\\nif True or False or False:\n pass\n\")" 4 LOAD_CONST (False) 5 POP_JUMP_IF_FALSE (6) - 2 >> 6 RETURN_CONST (None) + 2 >> 6 LOAD_CONST (None) + 7 RETURN_VALUE diff --git a/crates/codegen/src/snapshots/rustpython_codegen__compile__tests__nested_double_async_with.snap b/crates/codegen/src/snapshots/rustpython_codegen__compile__tests__nested_double_async_with.snap index eeef8ea4b3f..c5b2be80ee8 100644 --- a/crates/codegen/src/snapshots/rustpython_codegen__compile__tests__nested_double_async_with.snap +++ b/crates/codegen/src/snapshots/rustpython_codegen__compile__tests__nested_double_async_with.snap @@ -1,6 +1,5 @@ --- source: crates/codegen/src/compile.rs -assertion_line: 8626 expression: "compile_exec(\"\\\nasync def test():\n for stop_exc in (StopIteration('spam'), StopAsyncIteration('ham')):\n with self.subTest(type=type(stop_exc)):\n try:\n async with egg():\n raise stop_exc\n except Exception as ex:\n self.assertIs(ex, stop_exc)\n else:\n self.fail(f'{stop_exc} was suppressed')\n\")" --- 3 0 LOAD_CONST (): 1 0 RESUME (0) @@ -142,8 +141,10 @@ expression: "compile_exec(\"\\\nasync def test():\n for stop_exc in (StopIter 127 RERAISE (1) >> 128 JUMP_BACKWARD (11) >> 129 POP_TOP - 130 RETURN_CONST (None) + 130 LOAD_CONST (None) + 131 RETURN_VALUE 1 MAKE_FUNCTION 2 STORE_NAME (0, test) - 3 RETURN_CONST (None) + 3 LOAD_CONST (None) + 4 RETURN_VALUE diff --git a/crates/compiler-core/src/bytecode/instruction.rs b/crates/compiler-core/src/bytecode/instruction.rs index d8ba8da7a01..d7705ace5dd 100644 --- a/crates/compiler-core/src/bytecode/instruction.rs +++ b/crates/compiler-core/src/bytecode/instruction.rs @@ -266,16 +266,7 @@ pub enum Instruction { BuildConstKeyMap { size: Arg, } = 215, // Placeholder - Break { - target: Arg