File tree Expand file tree Collapse file tree 3 files changed +24
-3
lines changed Expand file tree Collapse file tree 3 files changed +24
-3
lines changed Original file line number Diff line number Diff line change 7575 X(LOAD_SUPER_ATTR) \
7676 X(MAKE_CELL) \
7777 X(NOT_TAKEN) \
78+ X(POP_ITER) \
7879 X(POP_JUMP_IF_NONE) \
7980 X(POP_JUMP_IF_NOT_NONE) \
8081 X(PUSH_EXC_INFO) \
@@ -187,6 +188,7 @@ enum {
187188 X(LOAD_SMALL_INT) \
188189 X(MAKE_OPNAME) \
189190 X(NOT_TAKEN) \
191+ X(POP_ITER) \
190192 X(ROT_FOUR) \
191193 X(ROT_N) \
192194 X(ROT_THREE) \
Original file line number Diff line number Diff line change @@ -172,6 +172,7 @@ bool isSupportedOpcode(int opcode) {
172172 case NOT_TAKEN:
173173 case POP_BLOCK:
174174 case POP_EXCEPT:
175+ case POP_ITER:
175176 case POP_JUMP_IF_FALSE:
176177 case POP_JUMP_IF_NONE:
177178 case POP_JUMP_IF_NONZERO:
@@ -452,6 +453,7 @@ static bool should_snapshot(
452453 case LOAD_FAST_CHECK:
453454 case LOAD_LOCAL:
454455 case NOP:
456+ case POP_ITER:
455457 case POP_TOP:
456458 case PRIMITIVE_BOX:
457459 case PRIMITIVE_LOAD_CONST:
@@ -1146,6 +1148,7 @@ void HIRBuilder::translate(
11461148 emitPopJumpIfNone (tc, bc_instr);
11471149 break ;
11481150 }
1151+ case POP_ITER:
11491152 case POP_TOP: {
11501153 tc.frame .stack .pop ();
11511154 break ;
@@ -1516,9 +1519,15 @@ void HIRBuilder::translate(
15161519 case FOR_ITER: {
15171520 auto condbr = static_cast <CondBranchIterNotDone*>(last_instr);
15181521 auto new_frame = tc.frame ;
1519- // Pop both the sentinel value signaling iteration is complete
1520- // and the iterator itself.
1521- new_frame.stack .discard (2 );
1522+ if constexpr (PY_VERSION_HEX >= 0x030E0000 ) {
1523+ // Just pop the sentinel value. The target POP_ITER will pop the
1524+ // iterator.
1525+ new_frame.stack .discard (1 );
1526+ } else {
1527+ // Pop both the sentinel value signaling iteration is complete
1528+ // and the iterator itself.
1529+ new_frame.stack .discard (2 );
1530+ }
15221531 queue.emplace_back (condbr->true_bb (), tc.frame );
15231532 queue.emplace_back (condbr->false_bb (), new_frame);
15241533 break ;
Original file line number Diff line number Diff line change @@ -264,6 +264,16 @@ def x(a):
264264 self ._assertBytecodeContains (x , "TO_BOOL" )
265265 self ._assertBytecodeContains (x , "POP_JUMP_IF_FALSE" )
266266
267+ def test_POP_ITER (self ):
268+ @cinder_support .fail_if_deopt
269+ @cinder_support .failUnlessJITCompiled
270+ def x ():
271+ for y in range (2 ):
272+ return y
273+
274+ self .assertEqual (x (), 0 )
275+ self ._assertBytecodeContains (x , "POP_ITER" )
276+
267277
268278if __name__ == "__main__" :
269279 unittest .main ()
You can’t perform that action at this time.
0 commit comments