summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorMark Shannon <mark@hotpy.org>2023-12-12 19:02:24 (GMT)
committerGitHub <noreply@github.com>2023-12-12 19:02:24 (GMT)
commit956023826a393b5704d3414dcd01f1bcbeaeda15 (patch)
tree733a71e8bdcbb8630c89375bf6bc1d5e51b5b5c4 /Python
parent9898e6104171dcdd88b32776e69ca2cddf515e63 (diff)
downloadcpython-956023826a393b5704d3414dcd01f1bcbeaeda15.zip
cpython-956023826a393b5704d3414dcd01f1bcbeaeda15.tar.gz
cpython-956023826a393b5704d3414dcd01f1bcbeaeda15.tar.bz2
GH-108866: Guarantee forward progress in executors. (GH-113006)
Diffstat (limited to 'Python')
-rw-r--r--Python/bytecodes.c11
-rw-r--r--Python/generated_cases.c.h12
-rw-r--r--Python/optimizer.c8
3 files changed, 13 insertions, 18 deletions
diff --git a/Python/bytecodes.c b/Python/bytecodes.c
index e0f3735..1ae8342 100644
--- a/Python/bytecodes.c
+++ b/Python/bytecodes.c
@@ -2352,20 +2352,17 @@ dummy_func(
PyCodeObject *code = _PyFrame_GetCode(frame);
_PyExecutorObject *executor = (_PyExecutorObject *)code->co_executors->executors[oparg&255];
- int original_oparg = executor->vm_data.oparg | (oparg & 0xfffff00);
- JUMPBY(1-original_oparg);
- frame->instr_ptr = next_instr;
Py_INCREF(executor);
if (executor->execute == _PyUOpExecute) {
current_executor = (_PyUOpExecutorObject *)executor;
GOTO_TIER_TWO();
}
- frame = executor->execute(executor, frame, stack_pointer);
- if (frame == NULL) {
- frame = tstate->current_frame;
+ next_instr = executor->execute(executor, frame, stack_pointer);
+ frame = tstate->current_frame;
+ if (next_instr == NULL) {
goto resume_with_error;
}
- goto enter_tier_one;
+ stack_pointer = _PyFrame_GetStackPointer(frame);
}
replaced op(_POP_JUMP_IF_FALSE, (unused/1, cond -- )) {
diff --git a/Python/generated_cases.c.h b/Python/generated_cases.c.h
index 8f68bc6..65e6f11 100644
--- a/Python/generated_cases.c.h
+++ b/Python/generated_cases.c.h
@@ -2328,20 +2328,18 @@
CHECK_EVAL_BREAKER();
PyCodeObject *code = _PyFrame_GetCode(frame);
_PyExecutorObject *executor = (_PyExecutorObject *)code->co_executors->executors[oparg&255];
- int original_oparg = executor->vm_data.oparg | (oparg & 0xfffff00);
- JUMPBY(1-original_oparg);
- frame->instr_ptr = next_instr;
Py_INCREF(executor);
if (executor->execute == _PyUOpExecute) {
current_executor = (_PyUOpExecutorObject *)executor;
GOTO_TIER_TWO();
}
- frame = executor->execute(executor, frame, stack_pointer);
- if (frame == NULL) {
- frame = tstate->current_frame;
+ next_instr = executor->execute(executor, frame, stack_pointer);
+ frame = tstate->current_frame;
+ if (next_instr == NULL) {
goto resume_with_error;
}
- goto enter_tier_one;
+ stack_pointer = _PyFrame_GetStackPointer(frame);
+ DISPATCH();
}
TARGET(EXIT_INIT_CHECK) {
diff --git a/Python/optimizer.c b/Python/optimizer.c
index dd24fbe..7c46bd6 100644
--- a/Python/optimizer.c
+++ b/Python/optimizer.c
@@ -167,6 +167,7 @@ _PyOptimizer_BackEdge(_PyInterpreterFrame *frame, _Py_CODEUNIT *src, _Py_CODEUNI
}
_PyOptimizerObject *opt = interp->optimizer;
_PyExecutorObject *executor = NULL;
+ /* Start optimizing at the destination to guarantee forward progress */
int err = opt->optimize(opt, code, dest, &executor, (int)(stack_pointer - _PyFrame_Stackbase(frame)));
if (err <= 0) {
assert(executor == NULL);
@@ -247,14 +248,13 @@ PyTypeObject _PyCounterExecutor_Type = {
.tp_methods = executor_methods,
};
-static _PyInterpreterFrame *
+static _Py_CODEUNIT *
counter_execute(_PyExecutorObject *self, _PyInterpreterFrame *frame, PyObject **stack_pointer)
{
((_PyCounterExecutorObject *)self)->optimizer->count++;
_PyFrame_SetStackPointer(frame, stack_pointer);
- frame->instr_ptr = ((_PyCounterExecutorObject *)self)->next_instr;
Py_DECREF(self);
- return frame;
+ return ((_PyCounterExecutorObject *)self)->next_instr;
}
static int
@@ -891,7 +891,7 @@ uop_optimize(
/* Dummy execute() function for UOp Executor.
* The actual implementation is inlined in ceval.c,
* in _PyEval_EvalFrameDefault(). */
-_PyInterpreterFrame *
+_Py_CODEUNIT *
_PyUOpExecute(_PyExecutorObject *executor, _PyInterpreterFrame *frame, PyObject **stack_pointer)
{
Py_FatalError("Tier 2 is now inlined into Tier 1");