Skip to content

Commit

Permalink
pythonGH-111485: Fix handling of FOR_ITER in Tier 2 (pythonGH-113394)
Browse files Browse the repository at this point in the history
  • Loading branch information
markshannon authored and Glyphack committed Jan 27, 2024
1 parent 8f0cda4 commit 5973adc
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions Python/optimizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -518,11 +518,11 @@ translate_bytecode_to_trace(

uint32_t opcode = instr->op.code;
uint32_t oparg = instr->op.arg;
uint32_t extras = 0;
uint32_t extended = 0;

if (opcode == EXTENDED_ARG) {
instr++;
extras += 1;
extended = 1;
opcode = instr->op.code;
oparg = (oparg << 8) | instr->op.arg;
if (opcode == EXTENDED_ARG) {
Expand Down Expand Up @@ -577,6 +577,7 @@ translate_bytecode_to_trace(
}

case JUMP_BACKWARD:
case JUMP_BACKWARD_NO_INTERRUPT:
{
if (instr + 2 - oparg == initial_instr && code == initial_code) {
RESERVE(1);
Expand Down Expand Up @@ -623,15 +624,7 @@ translate_bytecode_to_trace(
int offset = expansion->uops[i].offset + 1;
switch (expansion->uops[i].size) {
case OPARG_FULL:
if (extras && OPCODE_HAS_JUMP(opcode)) {
if (opcode == JUMP_BACKWARD_NO_INTERRUPT) {
oparg -= extras;
}
else {
assert(opcode != JUMP_BACKWARD);
oparg += extras;
}
}
assert(opcode != JUMP_BACKWARD_NO_INTERRUPT && opcode != JUMP_BACKWARD);
break;
case OPARG_CACHE_1:
operand = read_u16(&instr[offset].cache);
Expand All @@ -656,7 +649,7 @@ translate_bytecode_to_trace(
uop = _PyUOp_Replacements[uop];
assert(uop != 0);
if (uop == _FOR_ITER_TIER_TWO) {
target += 1 + INLINE_CACHE_ENTRIES_FOR_ITER + oparg + 1;
target += 1 + INLINE_CACHE_ENTRIES_FOR_ITER + oparg + 1 + extended;
assert(_PyCode_CODE(code)[target-1].op.code == END_FOR ||
_PyCode_CODE(code)[target-1].op.code == INSTRUMENTED_END_FOR);
}
Expand Down

0 comments on commit 5973adc

Please sign in to comment.