Skip to content

Commit 05825f5

Browse files
committed
fix
1 parent f88ee3b commit 05825f5

File tree

4 files changed

+12
-3
lines changed

4 files changed

+12
-3
lines changed

Include/internal/pycore_interp_structs.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -899,8 +899,6 @@ struct _is {
899899
struct _stoptheworld_state stoptheworld;
900900
struct _qsbr_shared qsbr;
901901

902-
struct _PyUOpInstruction *jit_uop_buffer;
903-
904902
#if defined(Py_GIL_DISABLED)
905903
struct _mimalloc_interp_state mimalloc;
906904
struct _brc_state brc; // biased reference counting state
@@ -952,6 +950,8 @@ struct _is {
952950
struct callable_cache callable_cache;
953951
PyObject *common_consts[NUM_COMMON_CONSTANTS];
954952
bool jit;
953+
bool compiling;
954+
struct _PyUOpInstruction *jit_uop_buffer;
955955
struct _PyExecutorObject *executor_list_head;
956956
struct _PyExecutorObject *executor_deletion_list_head;
957957
struct _PyExecutorObject *cold_executor;

Python/optimizer.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,10 @@ _PyOptimizer_Optimize(
116116
_PyExecutorObject **executor_ptr, int chain_depth)
117117
{
118118
_PyStackRef *stack_pointer = frame->stackpointer;
119-
assert(_PyInterpreterState_GET()->jit);
119+
PyInterpreterState *interp = _PyInterpreterState_GET();
120+
assert(interp->jit);
121+
assert(!interp->compiling);
122+
interp->compiling = true;
120123
// The first executor in a chain and the MAX_CHAIN_DEPTH'th executor *must*
121124
// make progress in order to avoid infinite loops or excessively-long
122125
// side-exit chains. We can only insert the executor into the bytecode if
@@ -126,10 +129,12 @@ _PyOptimizer_Optimize(
126129
PyCodeObject *code = _PyFrame_GetCode(frame);
127130
assert(PyCode_Check(code));
128131
if (progress_needed && !has_space_for_executor(code, start)) {
132+
interp->compiling = false;
129133
return 0;
130134
}
131135
int err = uop_optimize(frame, start, executor_ptr, (int)(stack_pointer - _PyFrame_Stackbase(frame)), progress_needed);
132136
if (err <= 0) {
137+
interp->compiling = false;
133138
return err;
134139
}
135140
assert(*executor_ptr != NULL);
@@ -143,6 +148,7 @@ _PyOptimizer_Optimize(
143148
* it might get confused by the executor disappearing,
144149
* but there is not much we can do about that here. */
145150
Py_DECREF(*executor_ptr);
151+
interp->compiling = false;
146152
return 0;
147153
}
148154
insert_executor(code, start, index, *executor_ptr);
@@ -152,6 +158,7 @@ _PyOptimizer_Optimize(
152158
}
153159
(*executor_ptr)->vm_data.chain_depth = chain_depth;
154160
assert((*executor_ptr)->vm_data.valid);
161+
interp->compiling = false;
155162
return 1;
156163
}
157164

Python/pylifecycle.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1702,6 +1702,7 @@ finalize_modules(PyThreadState *tstate)
17021702

17031703
// Invalidate all executors and turn off JIT:
17041704
interp->jit = false;
1705+
interp->compiling = false;
17051706
#ifdef _Py_TIER2
17061707
_Py_Executors_InvalidateAll(interp, 0);
17071708
#endif

Python/pystate.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,7 @@ init_interpreter(PyInterpreterState *interp,
577577
}
578578
interp->_code_object_generation = 0;
579579
interp->jit = false;
580+
interp->compiling = false;
580581
interp->executor_list_head = NULL;
581582
interp->executor_deletion_list_head = NULL;
582583
interp->executor_deletion_list_remaining_capacity = 0;

0 commit comments

Comments
 (0)