[Python-checkins] gh-106797: Remove warning logs from Python/generated_cases.c.h (gh-106798)

corona10 webhook-mailer at python.org
Sun Jul 16 20:09:14 EDT 2023


https://github.com/python/cpython/commit/48956cc60ea05bc50b6cd73e53dd9a7d4b1dac9f
commit: 48956cc60ea05bc50b6cd73e53dd9a7d4b1dac9f
branch: main
author: Dong-hee Na <donghee.na at python.org>
committer: corona10 <donghee.na92 at gmail.com>
date: 2023-07-17T09:09:11+09:00
summary:

gh-106797: Remove warning logs from Python/generated_cases.c.h (gh-106798)

files:
M Include/internal/pycore_opcode_metadata.h
M Python/generated_cases.c.h
M Tools/cases_generator/generate_cases.py

diff --git a/Include/internal/pycore_opcode_metadata.h b/Include/internal/pycore_opcode_metadata.h
index 8373f56653b1c..3b2eab23e092f 100644
--- a/Include/internal/pycore_opcode_metadata.h
+++ b/Include/internal/pycore_opcode_metadata.h
@@ -839,15 +839,15 @@ _PyOpcode_num_pushed(int opcode, int oparg, bool jump) {
         case PUSH_EXC_INFO:
             return 2;
         case LOAD_ATTR_METHOD_WITH_VALUES:
-            return (1 ? 1 : 0) + 1;
+            return 1 + 1;
         case LOAD_ATTR_METHOD_NO_DICT:
-            return (1 ? 1 : 0) + 1;
+            return 1 + 1;
         case LOAD_ATTR_NONDESCRIPTOR_WITH_VALUES:
-            return (0 ? 1 : 0) + 1;
+            return 0 + 1;
         case LOAD_ATTR_NONDESCRIPTOR_NO_DICT:
-            return (0 ? 1 : 0) + 1;
+            return 0 + 1;
         case LOAD_ATTR_METHOD_LAZY_DICT:
-            return (1 ? 1 : 0) + 1;
+            return 1 + 1;
         case KW_NAMES:
             return 0;
         case INSTRUMENTED_CALL:
diff --git a/Python/generated_cases.c.h b/Python/generated_cases.c.h
index 68531dc074769..392914c0521e9 100644
--- a/Python/generated_cases.c.h
+++ b/Python/generated_cases.c.h
@@ -3360,9 +3360,9 @@
             res2 = Py_NewRef(descr);
             assert(_PyType_HasFeature(Py_TYPE(res2), Py_TPFLAGS_METHOD_DESCRIPTOR));
             res = self;
-            STACK_GROW((1 ? 1 : 0));
+            STACK_GROW(1);
             stack_pointer[-1] = res;
-            if (1) { stack_pointer[-(1 + (1 ? 1 : 0))] = res2; }
+            stack_pointer[-(1 + 1)] = res2;
             next_instr += 9;
             DISPATCH();
         }
@@ -3382,16 +3382,15 @@
             assert(_PyType_HasFeature(Py_TYPE(descr), Py_TPFLAGS_METHOD_DESCRIPTOR));
             res2 = Py_NewRef(descr);
             res = self;
-            STACK_GROW((1 ? 1 : 0));
+            STACK_GROW(1);
             stack_pointer[-1] = res;
-            if (1) { stack_pointer[-(1 + (1 ? 1 : 0))] = res2; }
+            stack_pointer[-(1 + 1)] = res2;
             next_instr += 9;
             DISPATCH();
         }
 
         TARGET(LOAD_ATTR_NONDESCRIPTOR_WITH_VALUES) {
             PyObject *self = stack_pointer[-1];
-            PyObject *res2 = NULL;
             PyObject *res;
             uint32_t type_version = read_u32(&next_instr[1].cache);
             uint32_t keys_version = read_u32(&next_instr[3].cache);
@@ -3410,16 +3409,14 @@
             assert(descr != NULL);
             Py_DECREF(self);
             res = Py_NewRef(descr);
-            STACK_GROW((0 ? 1 : 0));
+            STACK_GROW(0);
             stack_pointer[-1] = res;
-            if (0) { stack_pointer[-(1 + (0 ? 1 : 0))] = res2; }
             next_instr += 9;
             DISPATCH();
         }
 
         TARGET(LOAD_ATTR_NONDESCRIPTOR_NO_DICT) {
             PyObject *self = stack_pointer[-1];
-            PyObject *res2 = NULL;
             PyObject *res;
             uint32_t type_version = read_u32(&next_instr[1].cache);
             PyObject *descr = read_obj(&next_instr[5].cache);
@@ -3432,9 +3429,8 @@
             assert(descr != NULL);
             Py_DECREF(self);
             res = Py_NewRef(descr);
-            STACK_GROW((0 ? 1 : 0));
+            STACK_GROW(0);
             stack_pointer[-1] = res;
-            if (0) { stack_pointer[-(1 + (0 ? 1 : 0))] = res2; }
             next_instr += 9;
             DISPATCH();
         }
@@ -3458,9 +3454,9 @@
             assert(_PyType_HasFeature(Py_TYPE(descr), Py_TPFLAGS_METHOD_DESCRIPTOR));
             res2 = Py_NewRef(descr);
             res = self;
-            STACK_GROW((1 ? 1 : 0));
+            STACK_GROW(1);
             stack_pointer[-1] = res;
-            if (1) { stack_pointer[-(1 + (1 ? 1 : 0))] = res2; }
+            stack_pointer[-(1 + 1)] = res2;
             next_instr += 9;
             DISPATCH();
         }
diff --git a/Tools/cases_generator/generate_cases.py b/Tools/cases_generator/generate_cases.py
index df5de6e299aaa..a0a8b8cbe4bab 100644
--- a/Tools/cases_generator/generate_cases.py
+++ b/Tools/cases_generator/generate_cases.py
@@ -98,6 +98,8 @@ def effect_size(effect: StackEffect) -> tuple[int, str]:
         assert not effect.cond, "Array effects cannot have a condition"
         return 0, effect.size
     elif effect.cond:
+        if effect.cond in ("0", "1"):
+            return 0, effect.cond
         return 0, f"{maybe_parenthesize(effect.cond)} ? 1 : 0"
     else:
         return 1, ""
@@ -217,7 +219,7 @@ def stack_adjust(
             self.emit(f"STACK_GROW({osym});")
 
     def declare(self, dst: StackEffect, src: StackEffect | None):
-        if dst.name == UNUSED:
+        if dst.name == UNUSED or dst.cond == "0":
             return
         typ = f"{dst.type}" if dst.type else "PyObject *"
         if src:
@@ -241,7 +243,10 @@ def assign(self, dst: StackEffect, src: StackEffect):
             self.emit(f"Py_XSETREF({dst.name}, {cast}{src.name});")
         else:
             stmt = f"{dst.name} = {cast}{src.name};"
-            if src.cond:
+            if src.cond and src.cond != "1":
+                if src.cond == "0":
+                    # It will not be executed
+                    return
                 stmt = f"if ({src.cond}) {{ {stmt} }}"
             self.emit(stmt)
 
@@ -1067,7 +1072,10 @@ def effect_str(effects: list[StackEffect]) -> str:
                     for effect in comp.instr.output_effects:
                         assert not effect.size, effect
                         if effect.cond:
-                            pushed_symbolic.append(maybe_parenthesize(f"{maybe_parenthesize(effect.cond)} ? 1 : 0"))
+                            if effect.cond in ("0", "1"):
+                                pushed_symbolic.append(effect.cond)
+                            else:
+                                pushed_symbolic.append(maybe_parenthesize(f"{maybe_parenthesize(effect.cond)} ? 1 : 0"))
                         sp += 1
                         high = max(sp, high)
                 if high != max(0, sp):



More information about the Python-checkins mailing list