@@ -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
158165static _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 ) {
0 commit comments