https://github.com/python/cpython/commit/63289b9dfbc7d87e81f1517422ee91b6b6d19531
commit: 63289b9dfbc7d87e81f1517422ee91b6b6d19531
branch: main
author: Mark Shannon <[email protected]>
committer: markshannon <[email protected]>
date: 2024-03-20T18:24:02Z
summary:

GH-117066: Tier 2 optimizer: Don't throw away good traces if we can't optimize 
them perfectly. (GH-117067)

files:
M Python/optimizer_analysis.c
M Python/optimizer_bytecodes.c
M Python/optimizer_cases.c.h

diff --git a/Python/optimizer_analysis.c b/Python/optimizer_analysis.c
index 0c95616848a85b..603ac6815665ca 100644
--- a/Python/optimizer_analysis.c
+++ b/Python/optimizer_analysis.c
@@ -406,24 +406,28 @@ optimize_uops(
 out_of_space:
     DPRINTF(3, "\n");
     DPRINTF(1, "Out of space in abstract interpreter\n");
-    _Py_uop_abstractcontext_fini(ctx);
-    return 0;
-
+    goto done;
 error:
     DPRINTF(3, "\n");
     DPRINTF(1, "Encountered error in abstract interpreter\n");
     _Py_uop_abstractcontext_fini(ctx);
-    return 0;
+    return -1;
 
 hit_bottom:
     // Attempted to push a "bottom" (contradition) symbol onto the stack.
     // This means that the abstract interpreter has hit unreachable code.
-    // We *could* generate an _EXIT_TRACE or _FATAL_ERROR here, but it's
-    // simpler to just admit failure and not create the executor.
+    // We *could* generate an _EXIT_TRACE or _FATAL_ERROR here, but hitting
+    // bottom indicates type instability, so we are probably better off
+    // retrying later.
     DPRINTF(3, "\n");
     DPRINTF(1, "Hit bottom in abstract interpreter\n");
     _Py_uop_abstractcontext_fini(ctx);
     return 0;
+done:
+    /* Cannot optimize further, but there would be no benefit
+     * in retrying later */
+    _Py_uop_abstractcontext_fini(ctx);
+    return 1;
 }
 
 
diff --git a/Python/optimizer_bytecodes.c b/Python/optimizer_bytecodes.c
index ef08c0d8897c9f..a1ef644e4621e2 100644
--- a/Python/optimizer_bytecodes.c
+++ b/Python/optimizer_bytecodes.c
@@ -546,7 +546,9 @@ dummy_func(void) {
         PyFunctionObject *func = (PyFunctionObject *)(this_instr + 2)->operand;
         DPRINTF(3, "func: %p ", func);
         if (func == NULL) {
-            goto error;
+            DPRINTF(3, "\n");
+            DPRINTF(1, "Missing function\n");
+            goto done;
         }
         PyCodeObject *co = (PyCodeObject *)func->func_code;
 
diff --git a/Python/optimizer_cases.c.h b/Python/optimizer_cases.c.h
index 610d1b1aede9cc..a0ecf58905f287 100644
--- a/Python/optimizer_cases.c.h
+++ b/Python/optimizer_cases.c.h
@@ -1599,7 +1599,9 @@
             PyFunctionObject *func = (PyFunctionObject *)(this_instr + 
2)->operand;
             DPRINTF(3, "func: %p ", func);
             if (func == NULL) {
-                goto error;
+                DPRINTF(3, "\n");
+                DPRINTF(1, "Missing function\n");
+                goto done;
             }
             PyCodeObject *co = (PyCodeObject *)func->func_code;
             assert(self_or_null != NULL);

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]

Reply via email to