Skip to content

Commit c1ed313

Browse files
committed
Remove retired instructions
1 parent 0710f31 commit c1ed313

File tree

5 files changed

+72
-130
lines changed

5 files changed

+72
-130
lines changed

Lib/_opcode_metadata.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -136,24 +136,24 @@
136136
'CALL_METHOD_KW': 126,
137137
'CALL_METHOD_EX': 127,
138138
'CONTINUE': 128,
139-
'END_FINALLY': 129,
140-
'ENTER_FINALLY': 130,
141-
'JUMP': 131,
142-
'JUMP_IF_FALSE_OR_POP': 132,
143-
'JUMP_IF_TRUE_OR_POP': 133,
144-
'JUMP_IF_NOT_EXC_MATCH': 134,
145-
'LOAD_CLASSDEREF': 135,
146-
'LOAD_CLOSURE': 136,
147-
'LOAD_METHOD': 137,
148-
'POP_BLOCK': 138,
149-
'REVERSE': 139,
150-
'SET_EXC_INFO': 140,
151-
'SETUP_EXCEPT': 141,
152-
'SETUP_FINALLY': 142,
153-
'SETUP_LOOP': 143,
154-
'SUBSCRIPT': 144,
155-
'UNARY_OP': 145,
156-
'YIELD_FROM': 146,
139+
'JUMP': 129,
140+
'JUMP_IF_FALSE_OR_POP': 130,
141+
'JUMP_IF_TRUE_OR_POP': 131,
142+
'JUMP_IF_NOT_EXC_MATCH': 132,
143+
'LOAD_CLASSDEREF': 133,
144+
'LOAD_CLOSURE': 134,
145+
'LOAD_METHOD': 135,
146+
'POP_BLOCK': 136,
147+
'REVERSE': 137,
148+
'SET_EXC_INFO': 138,
149+
'SUBSCRIPT': 139,
150+
'UNARY_OP': 140,
151+
'RESERVED_141': 141,
152+
'RESERVED_142': 142,
153+
'RESERVED_143': 143,
154+
'RESERVED_144': 144,
155+
'RESERVED_145': 145,
156+
'RESERVED_146': 146,
157157
'RESERVED_147': 147,
158158
'RESERVED_148': 148,
159159
'RESUME': 149,

crates/compiler-core/src/bytecode.rs

Lines changed: 35 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,98 +1022,88 @@ pub enum Instruction {
10221022
YieldValue {
10231023
arg: Arg<u32>,
10241024
},
1025-
// ==================== RustPython-only instructions (119-145) ====================
1026-
// 119: BREAK (RustPython-only)
1025+
// ==================== RustPython-only instructions (119+) ====================
1026+
// 119: BREAK
10271027
Break {
10281028
target: Arg<Label>,
10291029
},
1030-
// 120: BUILD_LIST_FROM_TUPLES (RustPython-only)
1030+
// 120: BUILD_LIST_FROM_TUPLES
10311031
BuildListFromTuples {
10321032
size: Arg<u32>,
10331033
},
1034-
// 121: BUILD_MAP_FOR_CALL (RustPython-only)
1034+
// 121: BUILD_MAP_FOR_CALL
10351035
BuildMapForCall {
10361036
size: Arg<u32>,
10371037
},
1038-
// 122: BUILD_SET_FROM_TUPLES (RustPython-only)
1038+
// 122: BUILD_SET_FROM_TUPLES
10391039
BuildSetFromTuples {
10401040
size: Arg<u32>,
10411041
},
1042-
// 123: BUILD_TUPLE_FROM_ITER (RustPython-only)
1042+
// 123: BUILD_TUPLE_FROM_ITER
10431043
BuildTupleFromIter,
1044-
// 124: BUILD_TUPLE_FROM_TUPLES (RustPython-only)
1044+
// 124: BUILD_TUPLE_FROM_TUPLES
10451045
BuildTupleFromTuples {
10461046
size: Arg<u32>,
10471047
},
1048-
// 125: CALL_METHOD (RustPython-only)
1048+
// 125: CALL_METHOD
10491049
CallMethodPositional {
10501050
nargs: Arg<u32>,
10511051
},
1052-
// 126: CALL_METHOD_KW (RustPython-only)
1052+
// 126: CALL_METHOD_KW
10531053
CallMethodKeyword {
10541054
nargs: Arg<u32>,
10551055
},
1056-
// 127: CALL_METHOD_EX (RustPython-only)
1056+
// 127: CALL_METHOD_EX
10571057
CallMethodEx {
10581058
has_kwargs: Arg<bool>,
10591059
},
1060-
// 128: CONTINUE (RustPython-only)
1060+
// 128: CONTINUE
10611061
Continue {
10621062
target: Arg<Label>,
10631063
},
1064-
// 129: END_FINALLY (RustPython-only)
1065-
EndFinally,
1066-
// 130: ENTER_FINALLY (RustPython-only)
1067-
EnterFinally,
1068-
// 131: JUMP (RustPython-only, CPython uses pseudo-op 256)
1064+
// 129: JUMP (CPython uses pseudo-op 256)
10691065
Jump {
10701066
target: Arg<Label>,
10711067
},
1072-
// 132: JUMP_IF_FALSE_OR_POP (RustPython-only)
1068+
// 130: JUMP_IF_FALSE_OR_POP
10731069
JumpIfFalseOrPop {
10741070
target: Arg<Label>,
10751071
},
1076-
// 133: JUMP_IF_TRUE_OR_POP (RustPython-only)
1072+
// 131: JUMP_IF_TRUE_OR_POP
10771073
JumpIfTrueOrPop {
10781074
target: Arg<Label>,
10791075
},
1080-
// 134: JUMP_IF_NOT_EXC_MATCH (RustPython-only)
1076+
// 132: JUMP_IF_NOT_EXC_MATCH
10811077
JumpIfNotExcMatch(Arg<Label>),
1082-
// 135: LOAD_CLASSDEREF (RustPython-only)
1078+
// 133: LOAD_CLASSDEREF
10831079
LoadClassDeref(Arg<NameIdx>),
1084-
// 136: LOAD_CLOSURE (RustPython-only, CPython uses pseudo-op 258)
1080+
// 134: LOAD_CLOSURE (CPython uses pseudo-op 258)
10851081
LoadClosure(Arg<NameIdx>),
1086-
// 137: LOAD_METHOD (RustPython-only, CPython uses pseudo-op 259)
1082+
// 135: LOAD_METHOD (CPython uses pseudo-op 259)
10871083
LoadMethod {
10881084
idx: Arg<NameIdx>,
10891085
},
1090-
// 138: POP_BLOCK (RustPython-only, CPython uses pseudo-op 263)
1086+
// 136: POP_BLOCK (CPython uses pseudo-op 263)
10911087
PopBlock,
1092-
// 139: REVERSE (RustPython-only)
1088+
// 137: REVERSE
10931089
Reverse {
10941090
amount: Arg<u32>,
10951091
},
1096-
// 140: SET_EXC_INFO (RustPython-only)
1092+
// 138: SET_EXC_INFO
10971093
SetExcInfo,
1098-
// 141: SETUP_EXCEPT (RustPython-only)
1099-
SetupExcept {
1100-
handler: Arg<Label>,
1101-
},
1102-
// 142: SETUP_FINALLY (RustPython-only, CPython uses pseudo-op 265)
1103-
SetupFinally {
1104-
handler: Arg<Label>,
1105-
},
1106-
// 143: SETUP_LOOP (RustPython-only)
1107-
SetupLoop,
1108-
// 144: SUBSCRIPT (RustPython-only)
1094+
// 139: SUBSCRIPT
11091095
Subscript,
1110-
// 145: UNARY_OP (RustPython-only, combines UNARY_*)
1096+
// 140: UNARY_OP (combines UNARY_*)
11111097
UnaryOperation {
11121098
op: Arg<UnaryOperator>,
11131099
},
1114-
// 146: YIELD_FROM (RustPython-only)
1115-
YieldFrom,
1116-
// 147-148: Reserved for future RustPython-only opcodes
1100+
// 141-148: Reserved (padding to keep RESUME at 149)
1101+
Reserved141,
1102+
Reserved142,
1103+
Reserved143,
1104+
Reserved144,
1105+
Reserved145,
1106+
Reserved146,
11171107
Reserved147,
11181108
Reserved148,
11191109
// 149: RESUME
@@ -1882,8 +1872,6 @@ impl Instruction {
18821872
| JumpIfTrueOrPop { target: l }
18831873
| JumpIfFalseOrPop { target: l }
18841874
| ForIter { target: l }
1885-
| SetupFinally { handler: l }
1886-
| SetupExcept { handler: l }
18871875
| Break { target: l }
18881876
| Continue { target: l }
18891877
| Send { target: l }
@@ -1936,7 +1924,8 @@ impl Instruction {
19361924
pub fn stack_effect(&self, arg: OpArg, jump: bool) -> i32 {
19371925
match self {
19381926
// Dummy/placeholder instructions (never executed)
1939-
Cache | Reserved3 | Reserved17 | Reserved147 | Reserved148 => 0,
1927+
Cache | Reserved3 | Reserved17 | Reserved141 | Reserved142 | Reserved143
1928+
| Reserved144 | Reserved145 | Reserved146 | Reserved147 | Reserved148 => 0,
19401929
BinarySlice | EndFor | ExitInitCheck | GetYieldFromIter | InterpreterExit
19411930
| LoadAssertionError | LoadLocals | PushNull | ReturnGenerator | StoreSlice
19421931
| UnaryInvert | UnaryNegative | UnaryNot => 0,
@@ -2026,7 +2015,6 @@ impl Instruction {
20262015
ReturnConst { .. } => 0,
20272016
Resume { .. } => 0,
20282017
YieldValue { .. } => 0,
2029-
YieldFrom => -1,
20302018
// SEND: (receiver, val) -> (receiver, retval) - no change, both paths keep same depth
20312019
Send { .. } => 0,
20322020
// END_SEND: (receiver, value) -> (value)
@@ -2037,8 +2025,7 @@ impl Instruction {
20372025
PushExcInfo => 1, // [exc] -> [prev_exc, exc]
20382026
CheckExcMatch => 0, // [exc, type] -> [exc, bool] (pops type, pushes bool)
20392027
Reraise { .. } => 0, // Exception raised, stack effect doesn't matter
2040-
SetupAnnotation | SetupLoop | SetupFinally { .. } | EnterFinally | EndFinally => 0,
2041-
SetupExcept { .. } => jump as i32,
2028+
SetupAnnotation => 0,
20422029
BeforeWith => 1, // push __exit__, then replace ctx_mgr with __enter__ result
20432030
WithExceptStart => 1, // push __exit__ result
20442031
PopBlock => 0,
@@ -2174,10 +2161,8 @@ impl Instruction {
21742161
match self {
21752162
// Dummy/placeholder instructions
21762163
Cache => w!(CACHE),
2177-
Reserved3 => w!(RESERVED),
2178-
Reserved17 => w!(RESERVED),
2179-
Reserved147 => w!(RESERVED),
2180-
Reserved148 => w!(RESERVED),
2164+
Reserved3 | Reserved17 | Reserved141 | Reserved142 | Reserved143 | Reserved144
2165+
| Reserved145 | Reserved146 | Reserved147 | Reserved148 => w!(RESERVED),
21812166
BinarySlice => w!(BINARY_SLICE),
21822167
EndFor => w!(END_FOR),
21832168
ExitInitCheck => w!(EXIT_INIT_CHECK),
@@ -2251,9 +2236,7 @@ impl Instruction {
22512236
DeleteSubscript => w!(DELETE_SUBSCR),
22522237
DictUpdate { index } => w!(DICT_UPDATE, index),
22532238
EndAsyncFor => w!(END_ASYNC_FOR),
2254-
EndFinally => w!(END_FINALLY),
22552239
EndSend => w!(END_SEND),
2256-
EnterFinally => w!(ENTER_FINALLY),
22572240
ExtendedArg => w!(EXTENDED_ARG, Arg::<u32>::marker()),
22582241
ForIter { target } => w!(FOR_ITER, target),
22592242
FormatSimple => w!(FORMAT_SIMPLE),
@@ -2306,9 +2289,6 @@ impl Instruction {
23062289
SetExcInfo => w!(SET_EXC_INFO),
23072290
SetFunctionAttribute { attr } => w!(SET_FUNCTION_ATTRIBUTE, ?attr),
23082291
SetupAnnotation => w!(SETUP_ANNOTATIONS),
2309-
SetupExcept { handler } => w!(SETUP_EXCEPT, handler),
2310-
SetupFinally { handler } => w!(SETUP_FINALLY, handler),
2311-
SetupLoop => w!(SETUP_LOOP),
23122292
StoreAttr { idx } => w!(STORE_ATTR, name = idx),
23132293
StoreDeref(idx) => w!(STORE_DEREF, cell_name = idx),
23142294
StoreFast(idx) => w!(STORE_FAST, varname = idx),
@@ -2329,7 +2309,6 @@ impl Instruction {
23292309
UnpackEx { args } => w!(UNPACK_EX, args),
23302310
UnpackSequence { size } => w!(UNPACK_SEQUENCE, size),
23312311
WithExceptStart => w!(WITH_EXCEPT_START),
2332-
YieldFrom => w!(YIELD_FROM),
23332312
YieldValue { arg } => w!(YIELD_VALUE, arg),
23342313
}
23352314
}

crates/stdlib/src/opcode.rs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,6 @@ mod opcode {
117117
| Instruction::PopJumpIfNone { .. }
118118
| Instruction::PopJumpIfNotNone { .. }
119119
| Instruction::Send { .. }
120-
| Instruction::SetupExcept { .. }
121-
| Instruction::SetupFinally { .. }
122120
)
123121
} else {
124122
false
@@ -167,18 +165,10 @@ mod opcode {
167165

168166
/// Check if instruction has exception info
169167
#[must_use]
170-
pub fn has_exc(opcode: i32) -> bool {
171-
if !Self::is_valid(opcode) {
172-
return false;
173-
}
174-
if let Ok(instr) = Instruction::try_from(opcode as u8) {
175-
matches!(
176-
instr,
177-
Instruction::SetupExcept { .. } | Instruction::SetupFinally { .. }
178-
)
179-
} else {
180-
false
181-
}
168+
pub fn has_exc(_opcode: i32) -> bool {
169+
// No instructions have exception info in RustPython
170+
// (exception handling is done via exception table)
171+
false
182172
}
183173
}
184174

crates/vm/src/frame.rs

Lines changed: 9 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,6 @@ impl ExecutingFrame<'_> {
447447
let lasti = self.lasti() as usize;
448448
if let Some(unit) = self.code.instructions.get(lasti) {
449449
match &unit.op {
450-
bytecode::Instruction::YieldFrom => return Some(self.top_value()),
451450
bytecode::Instruction::Send { .. } => return Some(self.top_value()),
452451
bytecode::Instruction::Resume { .. } => {
453452
// Check if previous instruction was YIELD_VALUE with arg >= 1
@@ -905,10 +904,6 @@ impl ExecutingFrame<'_> {
905904
Err(exc)
906905
}
907906
}
908-
// EndFinally is now a pseudo-instruction - exception table handles this
909-
bytecode::Instruction::EndFinally => Ok(None),
910-
// EnterFinally is now a pseudo-instruction - exception table handles this
911-
bytecode::Instruction::EnterFinally => Ok(None),
912907
bytecode::Instruction::ExtendedArg => {
913908
*extend_arg = true;
914909
Ok(None)
@@ -1582,12 +1577,6 @@ impl ExecutingFrame<'_> {
15821577
self.execute_set_function_attribute(vm, attr.get(arg))
15831578
}
15841579
bytecode::Instruction::SetupAnnotation => self.setup_annotations(vm),
1585-
// SetupExcept is now a pseudo-instruction - exception table handles this
1586-
bytecode::Instruction::SetupExcept { handler: _ } => Ok(None),
1587-
// SetupFinally is now a pseudo-instruction - exception table handles this
1588-
bytecode::Instruction::SetupFinally { handler: _ } => Ok(None),
1589-
// Note: SetupLoop is now a pseudo-instruction
1590-
bytecode::Instruction::SetupLoop => Ok(None),
15911580
// CPython 3.12+ BEFORE_WITH instruction
15921581
bytecode::Instruction::BeforeWith => {
15931582
// TOS: context_manager
@@ -1710,7 +1699,6 @@ impl ExecutingFrame<'_> {
17101699

17111700
Ok(None)
17121701
}
1713-
bytecode::Instruction::YieldFrom => self.execute_yield_from(vm),
17141702
bytecode::Instruction::YieldValue { arg: oparg } => {
17151703
let value = self.pop_value();
17161704
// arg=0: direct yield (wrapped for async generators)
@@ -1800,8 +1788,6 @@ impl ExecutingFrame<'_> {
18001788
bytecode::Instruction::Cache
18011789
| bytecode::Instruction::Reserved3
18021790
| bytecode::Instruction::Reserved17
1803-
| bytecode::Instruction::Reserved147
1804-
| bytecode::Instruction::Reserved148
18051791
| bytecode::Instruction::BinarySlice
18061792
| bytecode::Instruction::EndFor
18071793
| bytecode::Instruction::ExitInitCheck
@@ -1831,7 +1817,15 @@ impl ExecutingFrame<'_> {
18311817
| bytecode::Instruction::PopJumpIfNone { .. }
18321818
| bytecode::Instruction::PopJumpIfNotNone { .. }
18331819
| bytecode::Instruction::SetUpdate { .. }
1834-
| bytecode::Instruction::StoreFastStoreFast { .. } => {
1820+
| bytecode::Instruction::StoreFastStoreFast { .. }
1821+
| bytecode::Instruction::Reserved141
1822+
| bytecode::Instruction::Reserved142
1823+
| bytecode::Instruction::Reserved143
1824+
| bytecode::Instruction::Reserved144
1825+
| bytecode::Instruction::Reserved145
1826+
| bytecode::Instruction::Reserved146
1827+
| bytecode::Instruction::Reserved147
1828+
| bytecode::Instruction::Reserved148 => {
18351829
unreachable!(
18361830
"placeholder instruction should not be executed: {:?}",
18371831
instruction
@@ -2292,27 +2286,6 @@ impl ExecutingFrame<'_> {
22922286
}
22932287
}
22942288

2295-
fn execute_yield_from(&mut self, vm: &VirtualMachine) -> FrameResult {
2296-
// Value send into iterator:
2297-
let val = self.pop_value();
2298-
let coro = self.top_value();
2299-
let result = self._send(coro, val, vm)?;
2300-
2301-
// PyIterReturn returned from e.g. gen.__next__() or gen.send()
2302-
match result {
2303-
PyIterReturn::Return(value) => {
2304-
// Set back program counter:
2305-
self.update_lasti(|i| *i -= 1);
2306-
Ok(Some(ExecutionResult::Yield(value)))
2307-
}
2308-
PyIterReturn::StopIteration(value) => {
2309-
let value = vm.unwrap_or_none(value);
2310-
self.replace_top(value);
2311-
Ok(None)
2312-
}
2313-
}
2314-
}
2315-
23162289
fn execute_unpack_ex(&mut self, vm: &VirtualMachine, before: u8, after: u8) -> FrameResult {
23172290
let (before, after) = (before as usize, after as usize);
23182291
let value = self.pop_value();

0 commit comments

Comments
 (0)