]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
GH-117066: Tier 2 optimizer: Don't throw away good traces if we can't optimize them...
authorMark Shannon <mark@hotpy.org>
Wed, 20 Mar 2024 18:24:02 +0000 (18:24 +0000)
committerGitHub <noreply@github.com>
Wed, 20 Mar 2024 18:24:02 +0000 (18:24 +0000)
Python/optimizer_analysis.c
Python/optimizer_bytecodes.c
Python/optimizer_cases.c.h

index 0c95616848a85bdf247c2abdd00bc6208c5d584c..603ac6815665cabad2a0f6d3d3e11dc298abdf98 100644 (file)
@@ -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;
 }
 
 
index ef08c0d8897c9ffd09f10c81e59b67894df8d29a..a1ef644e4621e2f042a43e350b5a075b96fa07bf 100644 (file)
@@ -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;
 
index 610d1b1aede9cc3c64a014e36eac156dd19c1b7f..a0ecf58905f2878d2c031090047ec258c74d72f6 100644 (file)
             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);