]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
GH-112354: Treat _EXIT_TRACE like an unconditional side exit (GH-113104)
authorMark Shannon <mark@hotpy.org>
Thu, 14 Dec 2023 14:26:44 +0000 (14:26 +0000)
committerGitHub <noreply@github.com>
Thu, 14 Dec 2023 14:26:44 +0000 (14:26 +0000)
Include/internal/pycore_opcode_metadata.h
Python/bytecodes.c
Python/ceval.c
Python/ceval_macros.h
Python/executor_cases.c.h

index 2c512d97c421c97515ee686b577f6a01c41915a5..4670c34a83396377074f6a4297e0ea3df974b644 100644 (file)
@@ -1689,7 +1689,7 @@ const struct opcode_metadata _PyOpcode_opcode_metadata[OPCODE_METADATA_SIZE] = {
     [_JUMP_TO_TOP] = { true, INSTR_FMT_IX, HAS_EVAL_BREAK_FLAG },
     [_SET_IP] = { true, INSTR_FMT_IB, HAS_ARG_FLAG | HAS_ESCAPES_FLAG },
     [_SAVE_RETURN_OFFSET] = { true, INSTR_FMT_IB, HAS_ARG_FLAG },
-    [_EXIT_TRACE] = { true, INSTR_FMT_IX, 0 },
+    [_EXIT_TRACE] = { true, INSTR_FMT_IX, HAS_DEOPT_FLAG },
     [_INSERT] = { true, INSTR_FMT_IB, HAS_ARG_FLAG },
     [_CHECK_VALIDITY] = { true, INSTR_FMT_IX, HAS_DEOPT_FLAG },
 };
index 1ae83422730f8f7b77e8837f5519c4dead388998..68bb15c2b536eb99cee72c3f92bf655a4ac323d2 100644 (file)
@@ -4027,7 +4027,7 @@ dummy_func(
 
         op(_EXIT_TRACE, (--)) {
             TIER_TWO_ONLY
-            GOTO_TIER_ONE();
+            DEOPT_IF(1);
         }
 
         op(_INSERT, (unused[oparg], top -- top, unused[oparg])) {
index 8e0be7056919ea08eb5ee26b13515091a81bc9fa..27304d31e2794981d7e7427388396ddd57089676 100644 (file)
@@ -1063,31 +1063,16 @@ error_tier_two:
 
 // Jump here from DEOPT_IF()
 deoptimize:
-    // On DEOPT_IF we just repeat the last instruction.
-    // This presumes nothing was popped from the stack (nor pushed).
-    frame->instr_ptr = next_uop[-1].target + _PyCode_CODE(_PyFrame_GetCode(frame));
+    next_instr = next_uop[-1].target + _PyCode_CODE(_PyFrame_GetCode(frame));
     DPRINTF(2, "DEOPT: [UOp %d (%s), oparg %d, operand %" PRIu64 ", target %d @ %d -> %s]\n",
             uopcode, _PyUOpName(uopcode), next_uop[-1].oparg, next_uop[-1].operand, next_uop[-1].target,
             (int)(next_uop - current_executor->trace - 1),
             _PyOpcode_OpName[frame->instr_ptr->op.code]);
     OPT_HIST(trace_uop_execution_counter, trace_run_length_hist);
     UOP_STAT_INC(uopcode, miss);
-    frame->return_offset = 0;  // Dispatch to frame->instr_ptr
-    _PyFrame_SetStackPointer(frame, stack_pointer);
     Py_DECREF(current_executor);
-    // Fall through
-// Jump here from ENTER_EXECUTOR
-enter_tier_one:
-    next_instr = frame->instr_ptr;
-    goto resume_frame;
+    DISPATCH();
 
-// Jump here from _EXIT_TRACE
-exit_trace:
-    _PyFrame_SetStackPointer(frame, stack_pointer);
-    frame->instr_ptr = next_uop[-1].target + _PyCode_CODE(_PyFrame_GetCode(frame));
-    Py_DECREF(current_executor);
-    OPT_HIST(trace_uop_execution_counter, trace_run_length_hist);
-    goto enter_tier_one;
 }
 #if defined(__GNUC__)
 #  pragma GCC diagnostic pop
index ac44aecae046d8ffe2b5577384429026856d5509..a3606b17b71c62846d2cdd359b54fe45001c1dab 100644 (file)
@@ -392,8 +392,6 @@ stack_pointer = _PyFrame_GetStackPointer(frame);
 
 #define GOTO_TIER_TWO() goto enter_tier_two;
 
-#define GOTO_TIER_ONE() goto exit_trace;
-
 #define CURRENT_OPARG() (next_uop[-1].oparg)
 
 #define CURRENT_OPERAND() (next_uop[-1].operand)
index 14d9dd6e95e533f041e440babc287c7075e50f5c..2519a4ee546a5ed8dd5a5d1dcace73868958c253 100644 (file)
 
         case _EXIT_TRACE: {
             TIER_TWO_ONLY
-            GOTO_TIER_ONE();
+            if (1) goto deoptimize;
             break;
         }