]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-109287: fix overrides in cases generator (#110419)
authorCarl Meyer <carl@oddbird.net>
Thu, 5 Oct 2023 22:05:29 +0000 (15:05 -0700)
committerGitHub <noreply@github.com>
Thu, 5 Oct 2023 22:05:29 +0000 (15:05 -0700)
Lib/test/test_generated_cases.py
Tools/cases_generator/analysis.py
Tools/cases_generator/generate_cases.py
Tools/cases_generator/instructions.py

index 5971d2e436e4aa51773a77205330d4f65c86dd57..790e6b1b1b91e6b3cc6773a3fedc6d0c24ae7ea3 100644 (file)
@@ -598,6 +598,41 @@ class TestGeneratedCases(unittest.TestCase):
         """
         self.run_cases_test(input, output)
 
+    def test_override_inst(self):
+        input = """
+        inst(OP, (--)) {
+            spam();
+        }
+        override inst(OP, (--)) {
+            ham();
+        }
+        """
+        output = """
+        TARGET(OP) {
+            ham();
+            DISPATCH();
+        }
+        """
+        self.run_cases_test(input, output)
+
+    def test_override_op(self):
+        input = """
+        op(OP, (--)) {
+            spam();
+        }
+        macro(M) = OP;
+        override op(OP, (--)) {
+            ham();
+        }
+        """
+        output = """
+        TARGET(M) {
+            ham();
+            DISPATCH();
+        }
+        """
+        self.run_cases_test(input, output)
+
 
 if __name__ == "__main__":
     unittest.main()
index 7bbc924e5083f1bb6b7ff0b3acc761edcea5395b..b2fa0205bea342b87eb47a8eac8a80d953c29bce 100644 (file)
@@ -12,7 +12,6 @@ from instructions import (
     InstructionOrCacheEffect,
     MacroInstruction,
     MacroParts,
-    OverriddenInstructionPlaceHolder,
     PseudoInstruction,
 )
 import parsing
@@ -66,7 +65,6 @@ class Analyzer:
         parsing.InstDef
         | parsing.Macro
         | parsing.Pseudo
-        | OverriddenInstructionPlaceHolder
     ]
     instrs: dict[str, Instruction]  # Includes ops
     macros: dict[str, parsing.Macro]
@@ -141,7 +139,7 @@ class Analyzer:
             match thing:
                 case parsing.InstDef(name=name):
                     macro: parsing.Macro | None = None
-                    if thing.kind == "inst":
+                    if thing.kind == "inst" and not thing.override:
                         macro = parsing.Macro(name, [parsing.OpName(name)])
                     if name in self.instrs:
                         if not thing.override:
@@ -150,12 +148,7 @@ class Analyzer:
                                 f"previous definition @ {self.instrs[name].inst.context}",
                                 thing_first_token,
                             )
-                        placeholder = OverriddenInstructionPlaceHolder(name=name)
-                        self.everything[instrs_idx[name]] = placeholder
-                        if macro is not None:
-                            self.warning(
-                                f"Overriding desugared {macro.name} may not work", thing
-                            )
+                        self.everything[instrs_idx[name]] = thing
                     if name not in self.instrs and thing.override:
                         raise psr.make_syntax_error(
                             f"Definition of '{name}' @ {thing.context} is supposed to be "
index 01ab83bedb29850f42240aa913a9fbb5a28c7c29..dbb16418c0cb249880cf7de6307ee0265d4227c4 100644 (file)
@@ -26,7 +26,6 @@ from instructions import (
     MacroInstruction,
     MacroParts,
     PseudoInstruction,
-    OverriddenInstructionPlaceHolder,
     TIER_ONE,
     TIER_TWO,
 )
@@ -208,8 +207,6 @@ class Generator(Analyzer):
         popped_data: list[tuple[AnyInstruction, str]] = []
         pushed_data: list[tuple[AnyInstruction, str]] = []
         for thing in self.everything:
-            if isinstance(thing, OverriddenInstructionPlaceHolder):
-                continue
             if isinstance(thing, parsing.Macro) and thing.name in self.instrs:
                 continue
             instr, popped, pushed = self.get_stack_effect_info(thing)
@@ -393,8 +390,6 @@ class Generator(Analyzer):
         for thing in self.everything:
             format: str | None = None
             match thing:
-                case OverriddenInstructionPlaceHolder():
-                    continue
                 case parsing.InstDef():
                     format = self.instrs[thing.name].instr_fmt
                 case parsing.Macro():
@@ -492,8 +487,6 @@ class Generator(Analyzer):
                 # Write metadata for each instruction
                 for thing in self.everything:
                     match thing:
-                        case OverriddenInstructionPlaceHolder():
-                            continue
                         case parsing.InstDef():
                             self.write_metadata_for_inst(self.instrs[thing.name])
                         case parsing.Macro():
@@ -774,8 +767,6 @@ class Generator(Analyzer):
             n_macros = 0
             for thing in self.everything:
                 match thing:
-                    case OverriddenInstructionPlaceHolder():
-                        self.write_overridden_instr_place_holder(thing)
                     case parsing.InstDef():
                         pass
                     case parsing.Macro():
@@ -836,14 +827,6 @@ class Generator(Analyzer):
             file=sys.stderr,
         )
 
-    def write_overridden_instr_place_holder(
-        self, place_holder: OverriddenInstructionPlaceHolder
-    ) -> None:
-        self.out.emit("")
-        self.out.emit(
-            f"{self.out.comment} TARGET({place_holder.name}) overridden by later definition"
-        )
-
 
 def is_super_instruction(mac: MacroInstruction) -> bool:
     if (
index bd7b7dfbaa8f70fe0393b2789962acd73963da70..c6b551675e3e7e9ee82dff1bf743a0d93ce3c55b 100644 (file)
@@ -295,11 +295,6 @@ class PseudoInstruction:
     instr_flags: InstructionFlags
 
 
-@dataclasses.dataclass
-class OverriddenInstructionPlaceHolder:
-    name: str
-
-
 AnyInstruction = Instruction | MacroInstruction | PseudoInstruction