]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-114058: More robust method handling in redundancy eliminator (GH-115779)
authorKen Jin <kenjin@python.org>
Fri, 23 Feb 2024 07:42:03 +0000 (15:42 +0800)
committerGitHub <noreply@github.com>
Fri, 23 Feb 2024 07:42:03 +0000 (15:42 +0800)
Python/optimizer_analysis.c
Python/tier2_redundancy_eliminator_bytecodes.c
Python/tier2_redundancy_eliminator_cases.c.h

index 68ef8254b494a405fef3394dd065e85c641b9392..9503dcc74656cd8825ece7de3e196e024a349663 100644 (file)
@@ -315,6 +315,7 @@ sym_new_known_notnull(_Py_UOpsAbstractInterpContext *ctx)
     if (res == NULL) {
         return NULL;
     }
+    sym_set_flag(res, KNOWN);
     sym_set_flag(res, NOT_NULL);
     return res;
 }
index ff2b9a42272863c7d2aeb4059edcfe82ad8bfc69..ef7b43d53539ce642f1f35e5de5b1809aaf93d99 100644 (file)
@@ -295,6 +295,27 @@ dummy_func(void) {
         (void)owner;
     }
 
+    op(_LOAD_ATTR_METHOD_WITH_VALUES, (descr/4, owner -- attr, self if (1))) {
+        OUT_OF_SPACE_IF_NULL(attr = sym_new_known_notnull(ctx));
+        OUT_OF_SPACE_IF_NULL(self = sym_new_known_notnull(ctx));
+    }
+
+    op(_LOAD_ATTR_METHOD_NO_DICT, (descr/4, owner -- attr, self if (1))) {
+        OUT_OF_SPACE_IF_NULL(attr = sym_new_known_notnull(ctx));
+        OUT_OF_SPACE_IF_NULL(self = sym_new_known_notnull(ctx));
+    }
+
+    op(_LOAD_ATTR_METHOD_LAZY_DICT, (descr/4, owner -- attr, self if (1))) {
+        OUT_OF_SPACE_IF_NULL(attr = sym_new_known_notnull(ctx));
+        OUT_OF_SPACE_IF_NULL(self = sym_new_known_notnull(ctx));
+    }
+
+    op(_INIT_CALL_BOUND_METHOD_EXACT_ARGS, (callable, unused, unused[oparg] -- func, self, unused[oparg])) {
+        OUT_OF_SPACE_IF_NULL(func = sym_new_known_notnull(ctx));
+        OUT_OF_SPACE_IF_NULL(self = sym_new_known_notnull(ctx));
+    }
+
+
     op(_CHECK_FUNCTION_EXACT_ARGS, (func_version/2, callable, self_or_null, unused[oparg] -- callable, self_or_null, unused[oparg])) {
         sym_set_type(callable, &PyFunction_Type);
         (void)self_or_null;
index 58c11b7a1c87e0966338d877d0ed833a0522a126..ca9b5953d21012f67ec79e8e8e14bcf660613f14 100644 (file)
         }
 
         case _LOAD_ATTR_METHOD_WITH_VALUES: {
+            _Py_UOpsSymType *owner;
             _Py_UOpsSymType *attr;
             _Py_UOpsSymType *self = NULL;
-            attr = sym_new_unknown(ctx);
-            if (attr == NULL) goto out_of_space;
-            self = sym_new_unknown(ctx);
-            if (self == NULL) goto out_of_space;
+            owner = stack_pointer[-1];
+            PyObject *descr = (PyObject *)this_instr->operand;
+            OUT_OF_SPACE_IF_NULL(attr = sym_new_known_notnull(ctx));
+            OUT_OF_SPACE_IF_NULL(self = sym_new_known_notnull(ctx));
             stack_pointer[-1] = attr;
             stack_pointer[0] = self;
             stack_pointer += 1;
         }
 
         case _LOAD_ATTR_METHOD_NO_DICT: {
+            _Py_UOpsSymType *owner;
             _Py_UOpsSymType *attr;
             _Py_UOpsSymType *self = NULL;
-            attr = sym_new_unknown(ctx);
-            if (attr == NULL) goto out_of_space;
-            self = sym_new_unknown(ctx);
-            if (self == NULL) goto out_of_space;
+            owner = stack_pointer[-1];
+            PyObject *descr = (PyObject *)this_instr->operand;
+            OUT_OF_SPACE_IF_NULL(attr = sym_new_known_notnull(ctx));
+            OUT_OF_SPACE_IF_NULL(self = sym_new_known_notnull(ctx));
             stack_pointer[-1] = attr;
             stack_pointer[0] = self;
             stack_pointer += 1;
         }
 
         case _LOAD_ATTR_METHOD_LAZY_DICT: {
+            _Py_UOpsSymType *owner;
             _Py_UOpsSymType *attr;
             _Py_UOpsSymType *self = NULL;
-            attr = sym_new_unknown(ctx);
-            if (attr == NULL) goto out_of_space;
-            self = sym_new_unknown(ctx);
-            if (self == NULL) goto out_of_space;
+            owner = stack_pointer[-1];
+            PyObject *descr = (PyObject *)this_instr->operand;
+            OUT_OF_SPACE_IF_NULL(attr = sym_new_known_notnull(ctx));
+            OUT_OF_SPACE_IF_NULL(self = sym_new_known_notnull(ctx));
             stack_pointer[-1] = attr;
             stack_pointer[0] = self;
             stack_pointer += 1;
         }
 
         case _INIT_CALL_BOUND_METHOD_EXACT_ARGS: {
+            _Py_UOpsSymType *callable;
             _Py_UOpsSymType *func;
             _Py_UOpsSymType *self;
-            func = sym_new_unknown(ctx);
-            if (func == NULL) goto out_of_space;
-            self = sym_new_unknown(ctx);
-            if (self == NULL) goto out_of_space;
+            callable = stack_pointer[-2 - oparg];
+            OUT_OF_SPACE_IF_NULL(func = sym_new_known_notnull(ctx));
+            OUT_OF_SPACE_IF_NULL(self = sym_new_known_notnull(ctx));
             stack_pointer[-2 - oparg] = func;
             stack_pointer[-1 - oparg] = self;
             break;