Skip to content

Commit a49bcab

Browse files
committed
Update
1 parent 0c2a74f commit a49bcab

File tree

5 files changed

+20
-7
lines changed

5 files changed

+20
-7
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/bytecodes.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2961,7 +2961,9 @@ dummy_func(
29612961
start--;
29622962
}
29632963
_PyExecutorObject *executor;
2964+
assert(!_PyInterpreterState_GET()->compiling);
29642965
int optimized = _PyOptimizer_Optimize(frame, start, &executor, 0);
2966+
assert(!_PyInterpreterState_GET()->compiling);
29652967
if (optimized <= 0) {
29662968
this_instr[1].counter = restart_backoff_counter(counter);
29672969
ERROR_IF(optimized < 0);

Python/generated_cases.c.h

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/optimizer.c

Lines changed: 13 additions & 5 deletions
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
@@ -125,12 +128,14 @@ _PyOptimizer_Optimize(
125128
bool progress_needed = chain_depth == 0;
126129
PyCodeObject *code = _PyFrame_GetCode(frame);
127130
assert(PyCode_Check(code));
131+
int ret = 0;
128132
if (progress_needed && !has_space_for_executor(code, start)) {
129-
return 0;
133+
goto end;
130134
}
131135
int err = uop_optimize(frame, start, executor_ptr, (int)(stack_pointer - _PyFrame_Stackbase(frame)), progress_needed);
132136
if (err <= 0) {
133-
return err;
137+
ret = err;
138+
goto end;
134139
}
135140
assert(*executor_ptr != NULL);
136141
if (progress_needed) {
@@ -143,7 +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);
146-
return 0;
151+
goto end;
147152
}
148153
insert_executor(code, start, index, *executor_ptr);
149154
}
@@ -152,7 +157,9 @@ _PyOptimizer_Optimize(
152157
}
153158
(*executor_ptr)->vm_data.chain_depth = chain_depth;
154159
assert((*executor_ptr)->vm_data.valid);
155-
return 1;
160+
end:
161+
interp->compiling = false;
162+
return ret;
156163
}
157164

158165
static _PyExecutorObject *
@@ -1281,6 +1288,7 @@ uop_optimize(
12811288
_PyBloomFilter dependencies;
12821289
_Py_BloomFilter_Init(&dependencies);
12831290
PyInterpreterState *interp = _PyInterpreterState_GET();
1291+
assert(interp->compiling);
12841292
if (interp->jit_uop_buffer == NULL) {
12851293
interp->jit_uop_buffer = (_PyUOpInstruction *)_PyObject_VirtualAlloc(UOP_BUFFER_SIZE);
12861294
if (interp->jit_uop_buffer == NULL) {

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)