]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Small fixes to code generator (#106845)
authorGuido van Rossum <guido@python.org>
Tue, 18 Jul 2023 01:30:41 +0000 (18:30 -0700)
committerGitHub <noreply@github.com>
Tue, 18 Jul 2023 01:30:41 +0000 (01:30 +0000)
These repair nits I found in PR gh-106798 (issue gh-106797) and in PR gh-106716 (issue gh-106706).

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

index c3a0dbb478a7c1710ee878c8c33206f64dd7a8e7..a5844b3135d39898acef0fb7551472a0e17be809 100644 (file)
@@ -842,15 +842,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;
+            return 2;
         case LOAD_ATTR_METHOD_NO_DICT:
-            return 1 + 1;
+            return 2;
         case LOAD_ATTR_NONDESCRIPTOR_WITH_VALUES:
-            return 0 + 1;
+            return 1;
         case LOAD_ATTR_NONDESCRIPTOR_NO_DICT:
-            return 0 + 1;
+            return 1;
         case LOAD_ATTR_METHOD_LAZY_DICT:
-            return 1 + 1;
+            return 2;
         case KW_NAMES:
             return 0;
         case INSTRUMENTED_CALL:
index 0148078d18bdc33114854627803d6869123edd46..0a8e4da46b8be374ded9facd2624b8bc3cf61905 100644 (file)
             res = self;
             STACK_GROW(1);
             stack_pointer[-1] = res;
-            stack_pointer[-(1 + 1)] = res2;
+            stack_pointer[-2] = res2;
             next_instr += 9;
             DISPATCH();
         }
             res = self;
             STACK_GROW(1);
             stack_pointer[-1] = res;
-            stack_pointer[-(1 + 1)] = res2;
+            stack_pointer[-2] = res2;
             next_instr += 9;
             DISPATCH();
         }
             assert(descr != NULL);
             Py_DECREF(self);
             res = Py_NewRef(descr);
-            STACK_GROW(0);
             stack_pointer[-1] = res;
             next_instr += 9;
             DISPATCH();
             assert(descr != NULL);
             Py_DECREF(self);
             res = Py_NewRef(descr);
-            STACK_GROW(0);
             stack_pointer[-1] = res;
             next_instr += 9;
             DISPATCH();
             res = self;
             STACK_GROW(1);
             stack_pointer[-1] = res;
-            stack_pointer[-(1 + 1)] = res2;
+            stack_pointer[-2] = res2;
             next_instr += 9;
             DISPATCH();
         }
index 037bee107cb13a1e9dbfa54be189a49c9149dd19..2713fc6774e845c047fba801c9667e210a98eea4 100644 (file)
@@ -99,7 +99,7 @@ def effect_size(effect: StackEffect) -> tuple[int, str]:
         return 0, effect.size
     elif effect.cond:
         if effect.cond in ("0", "1"):
-            return 0, effect.cond
+            return int(effect.cond), ""
         return 0, f"{maybe_parenthesize(effect.cond)} ? 1 : 0"
     else:
         return 1, ""
@@ -841,9 +841,9 @@ class Analyzer:
     def check_families(self) -> None:
         """Check each family:
 
-        - Must have at least 2 members
-        - All members must be known instructions
-        - All members must have the same cache, input and output effects
+        - Must have at least 2 members (including head)
+        - Head and all members must be known instructions
+        - Head and all members must have the same cache, input and output effects
         """
         for family in self.families.values():
             if family.name not in self.macro_instrs and family.name not in self.instrs:
@@ -868,7 +868,7 @@ class Analyzer:
                     self.error(
                         f"Family {family.name!r} has inconsistent "
                         f"(cache, input, output) effects:\n"
-                        f"  {family.members[0]} = {expected_effects}; "
+                        f"  {family.name} = {expected_effects}; "
                         f"{member} = {member_effects}",
                         family,
                     )