https://github.com/python/cpython/commit/a33ffe4785f90f68227ddf2ec3e06d5ceaf76cec
commit: a33ffe4785f90f68227ddf2ec3e06d5ceaf76cec
branch: main
author: Ken Jin <[email protected]>
committer: Fidget-Spinner <[email protected]>
date: 2024-02-23T15:42:03+08:00
summary:

gh-114058: More robust method handling in redundancy eliminator (GH-115779)

files:
M Python/optimizer_analysis.c
M Python/tier2_redundancy_eliminator_bytecodes.c
M Python/tier2_redundancy_eliminator_cases.c.h

diff --git a/Python/optimizer_analysis.c b/Python/optimizer_analysis.c
index 68ef8254b494a4..9503dcc74656cd 100644
--- a/Python/optimizer_analysis.c
+++ b/Python/optimizer_analysis.c
@@ -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;
 }
diff --git a/Python/tier2_redundancy_eliminator_bytecodes.c 
b/Python/tier2_redundancy_eliminator_bytecodes.c
index ff2b9a42272863..ef7b43d53539ce 100644
--- a/Python/tier2_redundancy_eliminator_bytecodes.c
+++ b/Python/tier2_redundancy_eliminator_bytecodes.c
@@ -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;
diff --git a/Python/tier2_redundancy_eliminator_cases.c.h 
b/Python/tier2_redundancy_eliminator_cases.c.h
index 58c11b7a1c87e0..ca9b5953d21012 100644
--- a/Python/tier2_redundancy_eliminator_cases.c.h
+++ b/Python/tier2_redundancy_eliminator_cases.c.h
@@ -1300,12 +1300,13 @@
         }
 
         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;
@@ -1313,12 +1314,13 @@
         }
 
         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;
@@ -1346,12 +1348,13 @@
         }
 
         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;
@@ -1373,12 +1376,12 @@
         }
 
         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;

_______________________________________________
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