Skip to content

Commit b4aad3c

Browse files
committed
Address code review
1 parent 5d816a2 commit b4aad3c

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

Python/optimizer.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -591,8 +591,6 @@ translate_bytecode_to_trace(
591591

592592
for (;;) {
593593
target = INSTR_IP(instr, code);
594-
// Every instruction might need _DEOPT, and _DEOPT might have _ERROR_POP_N before it
595-
max_length -= 2;
596594

597595
uint32_t opcode = instr->op.code;
598596
uint32_t oparg = instr->op.arg;
@@ -631,6 +629,8 @@ translate_bytecode_to_trace(
631629
assert(opcode != ENTER_EXECUTOR && opcode != EXTENDED_ARG);
632630
RESERVE_RAW(2, "_CHECK_VALIDITY");
633631
ADD_TO_TRACE(_CHECK_VALIDITY, 0, 0, target);
632+
// Need to reserve 1 stub in case the _CHECK_VALIDITY results in a _DEOPT_IF
633+
max_length--;
634634
if (!OPCODE_HAS_NO_SAVE_IP(opcode)) {
635635
RESERVE_RAW(2, "_SET_IP");
636636
ADD_TO_TRACE(_SET_IP, 0, (uintptr_t)instr, target);
@@ -652,6 +652,15 @@ translate_bytecode_to_trace(
652652
RESERVE_RAW(2, "_EXIT_TRACE");
653653
max_length--;
654654
}
655+
if (OPCODE_HAS_ERROR(opcode)) {
656+
// Make space for error stub and final _EXIT_TRACE:
657+
RESERVE_RAW(2, "_ERROR_POP_N");
658+
max_length--;
659+
}
660+
if (OPCODE_HAS_DEOPT(opcode)) {
661+
RESERVE_RAW(2, "_DEOPT");
662+
max_length--;
663+
}
655664
switch (opcode) {
656665
case POP_JUMP_IF_NONE:
657666
case POP_JUMP_IF_NOT_NONE:

0 commit comments

Comments
 (0)