// gh-137573: inlining this function causes stack overflows
Py_NO_INLINE int
_PyOptimizer_Optimize(
- _PyInterpreterFrame *frame, _Py_CODEUNIT *start,
- _PyExecutorObject **executor_ptr, int chain_depth)
+ _PyInterpreterFrame *frame, PyThreadState *tstate)
{
- _PyStackRef *stack_pointer = frame->stackpointer;
PyInterpreterState *interp = _PyInterpreterState_GET();
+ int chain_depth = tstate->interp->jit_state.jit_tracer_initial_chain_depth;
assert(interp->jit);
assert(!interp->compiling);
+ assert(tstate->interp->jit_state.jit_tracer_initial_stack_depth >= 0);
+ #ifndef Py_GIL_DISABLED
interp->compiling = true;
// The first executor in a chain and the MAX_CHAIN_DEPTH'th executor *must*
// make progress in order to avoid infinite loops or excessively-long
interp->compiling = false;
return 0;
}
- insert_executor(code, start, index, *executor_ptr);
+ insert_executor(code, start, index, executor);
}
else {
- (*executor_ptr)->vm_data.code = NULL;
+ executor->vm_data.code = NULL;
+ }
+ if (chain_depth > 0) {
+ _PyExitData *prev_exit = tstate->interp->jit_state.jit_tracer_previous_exit;
+ assert(prev_exit != NULL);
+ prev_exit->executor = executor;;
}
- (*executor_ptr)->vm_data.chain_depth = chain_depth;
- assert((*executor_ptr)->vm_data.valid);
+ executor->vm_data.chain_depth = chain_depth;
+ assert(executor->vm_data.valid);
interp->compiling = false;
return 1;
+ #else
+ return 0;
+ #endif
}
static _PyExecutorObject *