Skip to content

Commit 301d58b

Browse files
eendebakptclaude
andcommitted
Address review: remove _PyUop_Uncached from is_terminator
is_terminator() is only called before stack_allocate, where opcodes are always base opcodes. Use the raw opcode directly with an assert. In sanity_check (which sees replicated opcodes post-stack_allocate), inline the terminator check using the already-computed base_opcode. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent fa87839 commit 301d58b

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

Python/optimizer.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -601,10 +601,8 @@ add_to_trace(
601601
static int
602602
is_terminator(const _PyUOpInstruction *uop)
603603
{
604-
int opcode = _PyUop_Uncached[uop->opcode];
605-
if (opcode == 0) {
606-
opcode = uop->opcode;
607-
}
604+
int opcode = uop->opcode;
605+
assert(opcode <= MAX_UOP_ID);
608606
return (
609607
opcode == _EXIT_TRACE ||
610608
opcode == _DEOPT ||
@@ -1348,7 +1346,10 @@ sanity_check(_PyExecutorObject *executor)
13481346
CHECK(inst->format == UOP_FORMAT_JUMP);
13491347
CHECK(inst->error_target < executor->code_size);
13501348
}
1351-
if (is_terminator(inst)) {
1349+
if (base_opcode == _EXIT_TRACE ||
1350+
base_opcode == _DEOPT ||
1351+
base_opcode == _JUMP_TO_TOP ||
1352+
base_opcode == _DYNAMIC_EXIT) {
13521353
ended = true;
13531354
i++;
13541355
break;

0 commit comments

Comments
 (0)