]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Fix handling of EXTENDED_ARG
authorKen Jin <28750310+Fidget-Spinner@users.noreply.github.com>
Thu, 9 Oct 2025 19:54:43 +0000 (20:54 +0100)
committerKen Jin <28750310+Fidget-Spinner@users.noreply.github.com>
Thu, 9 Oct 2025 19:54:43 +0000 (20:54 +0100)
Python/bytecodes.c
Python/ceval_macros.h
Python/executor_cases.c.h
Python/optimizer.c

index 15dbab0bef70f9e649920bfbfb3355881231fea2..812b323c137b2b0faf881e972e7492bc95f9e1d0 100644 (file)
@@ -5466,7 +5466,6 @@ dummy_func(
             _Py_CODEUNIT *target = frame->instr_ptr;
             _PyExitData *exit = (_PyExitData *)exit_p;
             _Py_BackoffCounter temperature = exit->temperature;
-            tstate->jit_exit = exit;
 #if defined(Py_DEBUG) && !defined(_Py_JIT)
             OPT_HIST(trace_uop_execution_counter, trace_run_length_hist);
             if (frame->lltrace >= 2) {
@@ -5481,10 +5480,8 @@ dummy_func(
             if (target->op.code == ENTER_EXECUTOR) {
                 PyCodeObject *code = _PyFrame_GetCode(frame);
                 _PyExecutorObject *executor = code->co_executors->executors[target->op.arg];
-                Py_INCREF(executor);
-                assert(tstate->jit_exit == exit);
-                exit->executor = executor;
-                TIER2_TO_TIER2(exit->executor);
+                tstate->jit_exit = NULL;
+                TIER2_TO_TIER2(executor);
             }
             else {
                 if (frame->owner >= FRAME_OWNED_BY_INTERPRETER) {
@@ -5497,7 +5494,7 @@ dummy_func(
                 exit->temperature = initial_temperature_backoff_counter();
                 _PyExecutorObject *previous_executor = _PyExecutor_FromExit(exit);
                 assert(tstate->current_executor == (PyObject *)previous_executor);
-                _PyJIT_InitializeTracing(tstate, frame, target, STACK_LEVEL(), 0, exit);
+                _PyJIT_InitializeTracing(tstate, frame, target, STACK_LEVEL(), 0, NULL);
                 GOTO_TIER_ONE(target, 1);
             }
         }
index edacf4418b97fdfaa29b52c4fb18035ae86927de..8085fb3f1928064cfd48ca7891ad5e87043cbd86 100644 (file)
 #define TRACING_JUMP_TO_LABEL(label) \
     RECORD_JUMP_TAKEN() \
     RECORD_TRACE_NO_DISPATCH() \
+    assert(!IS_JIT_TRACING()); \
+    RELOAD_TRACING(); \
     JUMP_TO_LABEL(label);
 
 #if _Py_TAIL_CALL_INTERP || USE_COMPUTED_GOTOS
         JUMP_TO_LABEL(error); \
     }
 #  define RECORD_TRACE_NO_DISPATCH() do { \
-        if (DISPATCH_TABLE_VAR == TRACING_DISPATCH_TABLE && add_to_code_trace(tstate, frame, old_code, old_func, this_instr, next_instr, opcode, oparg, _jump_taken)) { \
+        if (IS_JIT_TRACING() && add_to_code_trace(tstate, frame, old_code, old_func, this_instr, next_instr, opcode, oparg, _jump_taken)) { \
             BAIL_TRACING_NO_DISPATCH(); \
         } \
     } while (0);
index 86c47b5601048e551c2f77e645bcf39406f9d89a..58c57ea6b96fa84c7e182fe147cdb1db0f36caaa 100644 (file)
             _Py_CODEUNIT *target = frame->instr_ptr;
             _PyExitData *exit = (_PyExitData *)exit_p;
             _Py_BackoffCounter temperature = exit->temperature;
-            tstate->jit_exit = exit;
             #if defined(Py_DEBUG) && !defined(_Py_JIT)
             OPT_HIST(trace_uop_execution_counter, trace_run_length_hist);
             if (frame->lltrace >= 2) {
             if (target->op.code == ENTER_EXECUTOR) {
                 PyCodeObject *code = _PyFrame_GetCode(frame);
                 _PyExecutorObject *executor = code->co_executors->executors[target->op.arg];
-                Py_INCREF(executor);
-                assert(tstate->jit_exit == exit);
-                exit->executor = executor;
-                TIER2_TO_TIER2(exit->executor);
+                tstate->jit_exit = NULL;
+                TIER2_TO_TIER2(executor);
             }
             else {
                 if (frame->owner >= FRAME_OWNED_BY_INTERPRETER) {
                 exit->temperature = initial_temperature_backoff_counter();
                 _PyExecutorObject *previous_executor = _PyExecutor_FromExit(exit);
                 assert(tstate->current_executor == (PyObject *)previous_executor);
-                _PyJIT_InitializeTracing(tstate, frame, target, STACK_LEVEL(), 0, exit);
+                _PyJIT_InitializeTracing(tstate, frame, target, STACK_LEVEL(), 0, NULL);
                 GOTO_TIER_ONE(target, 1);
             }
             break;
index 03cd070c163e4929c181c80ea595f7208649613d..a8df28cd2a86f47684a37e495864638be652c0bc 100644 (file)
@@ -468,7 +468,6 @@ is_for_iter_test[MAX_UOP_ID + 1] = {
     [_GUARD_NOT_EXHAUSTED_RANGE] = 1,
     [_GUARD_NOT_EXHAUSTED_LIST] = 1,
     [_GUARD_NOT_EXHAUSTED_TUPLE] = 1,
-    [_FOR_ITER_TIER_TWO] = 1,
 };
 
 static const uint16_t
@@ -586,18 +585,11 @@ _PyJIT_translate_single_bytecode_to_trace(
 
     DPRINTF(2, "%d: %s(%d)\n", target, _PyOpcode_OpName[opcode], oparg);
 
-    // One for possible _DEOPT, one because _CHECK_VALIDITY itself might _DEOPT
-    max_length -= 2;
     if ((uint16_t)oparg != (uint64_t)oparg) {
-        // Back up over EXTENDED_ARGs
-        _PyUOpInstruction *curr = &trace[trace_length-1];
-        while (oparg > 0) {
-            oparg >>= 8;
-            trace_length--;
-        }
-        goto full;
+        goto unsupported;
     }
-
+    // One for possible _DEOPT, one because _CHECK_VALIDITY itself might _DEOPT
+    max_length -= 2;
 
     if (opcode == EXTENDED_ARG) {
         return 1;