Skip to content

Commit 00bea3a

Browse files
committed
Remove break/continue ops
1 parent 1592428 commit 00bea3a

File tree

5 files changed

+3
-55
lines changed

5 files changed

+3
-55
lines changed

Lib/_opcode_metadata.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,6 @@
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,
222220
'SET_EXC_INFO': 223,
223221
'INSTRUMENTED_END_FOR': 234,

crates/codegen/src/compile.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7870,11 +7870,8 @@ impl Compiler {
78707870
}
78717871

78727872
// Jump to target
7873-
if is_break {
7874-
emit!(self, Instruction::Break { target: exit_block });
7875-
} else {
7876-
emit!(self, Instruction::Continue { target: loop_block });
7877-
}
7873+
let target = if is_break { exit_block } else { loop_block };
7874+
emit!(self, PseudoInstruction::Jump { target });
78787875

78797876
Ok(())
78807877
}

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

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -266,12 +266,6 @@ 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,
276270
SetExcInfo = 223,
277271
// CPython 3.14 RESUME (128)
@@ -424,12 +418,6 @@ impl TryFrom<u8> for Instruction {
424418
u8::from(Self::BuildConstKeyMap {
425419
size: Arg::marker(),
426420
}),
427-
u8::from(Self::Break {
428-
target: Arg::marker(),
429-
}),
430-
u8::from(Self::Continue {
431-
target: Arg::marker(),
432-
}),
433421
u8::from(Self::JumpIfNotExcMatch(Arg::marker())),
434422
u8::from(Self::SetExcInfo),
435423
];
@@ -459,8 +447,6 @@ impl InstructionMetadata for Instruction {
459447
| Self::PopJumpIfTrue { target: l }
460448
| Self::PopJumpIfFalse { target: l }
461449
| Self::ForIter { target: l }
462-
| Self::Break { target: l }
463-
| Self::Continue { target: l }
464450
| Self::Send { target: l } => Some(*l),
465451
_ => None,
466452
}
@@ -472,8 +458,6 @@ impl InstructionMetadata for Instruction {
472458
Self::JumpForward { .. }
473459
| Self::JumpBackward { .. }
474460
| Self::JumpBackwardNoInterrupt { .. }
475-
| Self::Continue { .. }
476-
| Self::Break { .. }
477461
| Self::ReturnValue
478462
| Self::RaiseVarargs { .. }
479463
| Self::Reraise { .. }
@@ -523,8 +507,6 @@ impl InstructionMetadata for Instruction {
523507
Self::GetLen => 1,
524508
Self::CallIntrinsic1 { .. } => 0, // Takes 1, pushes 1
525509
Self::CallIntrinsic2 { .. } => -1, // Takes 2, pushes 1
526-
Self::Continue { .. } => 0,
527-
Self::Break { .. } => 0,
528510
Self::PopJumpIfTrue { .. } => -1,
529511
Self::PopJumpIfFalse { .. } => -1,
530512
Self::MakeFunction => {
@@ -832,7 +814,6 @@ impl InstructionMetadata for Instruction {
832814
Self::BeforeWith => w!(BEFORE_WITH),
833815
Self::BinaryOp { op } => write!(f, "{:pad$}({})", "BINARY_OP", op.get(arg)),
834816
Self::BinarySubscr => w!(BINARY_SUBSCR),
835-
Self::Break { target } => w!(BREAK, target),
836817
Self::BuildList { size } => w!(BUILD_LIST, size),
837818
Self::BuildMap { size } => w!(BUILD_MAP, size),
838819
Self::BuildSet { size } => w!(BUILD_SET, size),
@@ -849,7 +830,6 @@ impl InstructionMetadata for Instruction {
849830
Self::CleanupThrow => w!(CLEANUP_THROW),
850831
Self::CompareOp { op } => w!(COMPARE_OP, ?op),
851832
Self::ContainsOp(inv) => w!(CONTAINS_OP, ?inv),
852-
Self::Continue { target } => w!(CONTINUE, target),
853833
Self::ConvertValue { oparg } => write!(f, "{:pad$}{}", "CONVERT_VALUE", oparg.get(arg)),
854834
Self::Copy { index } => w!(COPY, index),
855835
Self::DeleteAttr { idx } => w!(DELETE_ATTR, name = idx),

crates/stdlib/src/opcode.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,7 @@ mod opcode {
102102
matches!(
103103
Self::try_from(opcode).map(|op| op.inner()),
104104
Ok(AnyInstruction::Real(
105-
Instruction::Break { .. }
106-
| Instruction::Continue { .. }
107-
| Instruction::ForIter { .. }
105+
Instruction::ForIter { .. }
108106
| Instruction::JumpIfNotExcMatch(_)
109107
| Instruction::PopJumpIfFalse { .. }
110108
| Instruction::PopJumpIfTrue { .. }

crates/vm/src/frame.rs

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,6 @@ enum UnwindReason {
4545
/// We hit an exception, so unwind any try-except and finally blocks. The exception should be
4646
/// on top of the vm exception stack.
4747
Raising { exception: PyBaseExceptionRef },
48-
49-
// NoWorries,
50-
/// We are unwinding blocks, since we hit break
51-
Break { target: bytecode::Label },
52-
53-
/// We are unwinding blocks since we hit a continue statements.
54-
Continue { target: bytecode::Label },
5548
}
5649

5750
#[derive(Debug)]
@@ -658,12 +651,6 @@ impl ExecutingFrame<'_> {
658651
Ok(None)
659652
}
660653

661-
Instruction::Break { target } => self.unwind_blocks(
662-
vm,
663-
UnwindReason::Break {
664-
target: target.get(arg),
665-
},
666-
),
667654
Instruction::BuildList { size } => {
668655
let sz = size.get(arg) as usize;
669656
let elements = self.pop_multiple(sz).collect();
@@ -804,13 +791,6 @@ impl ExecutingFrame<'_> {
804791
self.push_value(vm.ctx.new_bool(value).into());
805792
Ok(None)
806793
}
807-
Instruction::Continue { target } => self.unwind_blocks(
808-
vm,
809-
UnwindReason::Continue {
810-
target: target.get(arg),
811-
},
812-
),
813-
814794
Instruction::ConvertValue { oparg: conversion } => {
815795
self.convert_value(conversion.get(arg), vm)
816796
}
@@ -2055,11 +2035,6 @@ impl ExecutingFrame<'_> {
20552035
drop(fastlocals);
20562036
Ok(Some(ExecutionResult::Return(value)))
20572037
}
2058-
UnwindReason::Break { target } | UnwindReason::Continue { target } => {
2059-
// Break/continue: jump to the target label
2060-
self.jump(target);
2061-
Ok(None)
2062-
}
20632038
}
20642039
}
20652040

0 commit comments

Comments
 (0)