summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorMark Shannon <mark@hotpy.org>2023-06-19 09:32:20 (GMT)
committerGitHub <noreply@github.com>2023-06-19 09:32:20 (GMT)
commit581619941ecce986a2fc8cbddd95256daa25fb26 (patch)
tree4531fd801297edeed79d2ce6dcba28117ff9dafc /Objects
parent4426279a4399158027a1145cff1c4c92424bf5b5 (diff)
downloadcpython-581619941ecce986a2fc8cbddd95256daa25fb26.zip
cpython-581619941ecce986a2fc8cbddd95256daa25fb26.tar.gz
cpython-581619941ecce986a2fc8cbddd95256daa25fb26.tar.bz2
GH-104584: Assorted fixes for the optimizer API. (GH-105683)
* Add test for long loops * Clear ENTER_EXECUTOR when deopting code objects.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/codeobject.c24
1 files changed, 20 insertions, 4 deletions
diff --git a/Objects/codeobject.c b/Objects/codeobject.c
index 377cac5..a53584c 100644
--- a/Objects/codeobject.c
+++ b/Objects/codeobject.c
@@ -1466,11 +1466,27 @@ PyCode_GetFreevars(PyCodeObject *code)
}
static void
+clear_executors(PyCodeObject *co)
+{
+ for (int i = 0; i < co->co_executors->size; i++) {
+ Py_CLEAR(co->co_executors->executors[i]);
+ }
+ PyMem_Free(co->co_executors);
+ co->co_executors = NULL;
+}
+
+static void
deopt_code(PyCodeObject *code, _Py_CODEUNIT *instructions)
{
Py_ssize_t len = Py_SIZE(code);
for (int i = 0; i < len; i++) {
int opcode = _Py_GetBaseOpcode(code, i);
+ if (opcode == ENTER_EXECUTOR) {
+ _PyExecutorObject *exec = code->co_executors->executors[instructions[i].op.arg];
+ opcode = exec->vm_data.opcode;
+ instructions[i].op.arg = exec->vm_data.oparg;
+ }
+ assert(opcode != ENTER_EXECUTOR);
int caches = _PyOpcode_Caches[opcode];
instructions[i].op.code = opcode;
for (int j = 1; j <= caches; j++) {
@@ -1679,10 +1695,7 @@ code_dealloc(PyCodeObject *co)
PyMem_Free(co_extra);
}
if (co->co_executors != NULL) {
- for (int i = 0; i < co->co_executors->size; i++) {
- Py_CLEAR(co->co_executors->executors[i]);
- }
- PyMem_Free(co->co_executors);
+ clear_executors(co);
}
Py_XDECREF(co->co_consts);
@@ -2278,6 +2291,9 @@ void
_PyStaticCode_Fini(PyCodeObject *co)
{
deopt_code(co, _PyCode_CODE(co));
+ if (co->co_executors != NULL) {
+ clear_executors(co);
+ }
PyMem_Free(co->co_extra);
if (co->_co_cached != NULL) {
Py_CLEAR(co->_co_cached->_co_code);