Skip to content

Commit 3c0f65e

Browse files
authored
gh-109287: fix overrides in cases generator (#110419)
1 parent bb057b3 commit 3c0f65e

File tree

4 files changed

+37
-31
lines changed

4 files changed

+37
-31
lines changed

Lib/test/test_generated_cases.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,41 @@ def test_macro_push_push(self):
598598
"""
599599
self.run_cases_test(input, output)
600600

601+
def test_override_inst(self):
602+
input = """
603+
inst(OP, (--)) {
604+
spam();
605+
}
606+
override inst(OP, (--)) {
607+
ham();
608+
}
609+
"""
610+
output = """
611+
TARGET(OP) {
612+
ham();
613+
DISPATCH();
614+
}
615+
"""
616+
self.run_cases_test(input, output)
617+
618+
def test_override_op(self):
619+
input = """
620+
op(OP, (--)) {
621+
spam();
622+
}
623+
macro(M) = OP;
624+
override op(OP, (--)) {
625+
ham();
626+
}
627+
"""
628+
output = """
629+
TARGET(M) {
630+
ham();
631+
DISPATCH();
632+
}
633+
"""
634+
self.run_cases_test(input, output)
635+
601636

602637
if __name__ == "__main__":
603638
unittest.main()

Tools/cases_generator/analysis.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
InstructionOrCacheEffect,
1313
MacroInstruction,
1414
MacroParts,
15-
OverriddenInstructionPlaceHolder,
1615
PseudoInstruction,
1716
)
1817
import parsing
@@ -66,7 +65,6 @@ def note(self, msg: str, node: parsing.Node) -> None:
6665
parsing.InstDef
6766
| parsing.Macro
6867
| parsing.Pseudo
69-
| OverriddenInstructionPlaceHolder
7068
]
7169
instrs: dict[str, Instruction] # Includes ops
7270
macros: dict[str, parsing.Macro]
@@ -141,7 +139,7 @@ def parse_file(self, filename: str, instrs_idx: dict[str, int]) -> None:
141139
match thing:
142140
case parsing.InstDef(name=name):
143141
macro: parsing.Macro | None = None
144-
if thing.kind == "inst":
142+
if thing.kind == "inst" and not thing.override:
145143
macro = parsing.Macro(name, [parsing.OpName(name)])
146144
if name in self.instrs:
147145
if not thing.override:
@@ -150,12 +148,7 @@ def parse_file(self, filename: str, instrs_idx: dict[str, int]) -> None:
150148
f"previous definition @ {self.instrs[name].inst.context}",
151149
thing_first_token,
152150
)
153-
placeholder = OverriddenInstructionPlaceHolder(name=name)
154-
self.everything[instrs_idx[name]] = placeholder
155-
if macro is not None:
156-
self.warning(
157-
f"Overriding desugared {macro.name} may not work", thing
158-
)
151+
self.everything[instrs_idx[name]] = thing
159152
if name not in self.instrs and thing.override:
160153
raise psr.make_syntax_error(
161154
f"Definition of '{name}' @ {thing.context} is supposed to be "

Tools/cases_generator/generate_cases.py

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
MacroInstruction,
2727
MacroParts,
2828
PseudoInstruction,
29-
OverriddenInstructionPlaceHolder,
3029
TIER_ONE,
3130
TIER_TWO,
3231
)
@@ -208,8 +207,6 @@ def write_stack_effect_functions(self) -> None:
208207
popped_data: list[tuple[AnyInstruction, str]] = []
209208
pushed_data: list[tuple[AnyInstruction, str]] = []
210209
for thing in self.everything:
211-
if isinstance(thing, OverriddenInstructionPlaceHolder):
212-
continue
213210
if isinstance(thing, parsing.Macro) and thing.name in self.instrs:
214211
continue
215212
instr, popped, pushed = self.get_stack_effect_info(thing)
@@ -393,8 +390,6 @@ def write_metadata(self, metadata_filename: str, pymetadata_filename: str) -> No
393390
for thing in self.everything:
394391
format: str | None = None
395392
match thing:
396-
case OverriddenInstructionPlaceHolder():
397-
continue
398393
case parsing.InstDef():
399394
format = self.instrs[thing.name].instr_fmt
400395
case parsing.Macro():
@@ -492,8 +487,6 @@ def write_metadata(self, metadata_filename: str, pymetadata_filename: str) -> No
492487
# Write metadata for each instruction
493488
for thing in self.everything:
494489
match thing:
495-
case OverriddenInstructionPlaceHolder():
496-
continue
497490
case parsing.InstDef():
498491
self.write_metadata_for_inst(self.instrs[thing.name])
499492
case parsing.Macro():
@@ -774,8 +767,6 @@ def write_instructions(
774767
n_macros = 0
775768
for thing in self.everything:
776769
match thing:
777-
case OverriddenInstructionPlaceHolder():
778-
self.write_overridden_instr_place_holder(thing)
779770
case parsing.InstDef():
780771
pass
781772
case parsing.Macro():
@@ -836,14 +827,6 @@ def write_abstract_interpreter_instructions(
836827
file=sys.stderr,
837828
)
838829

839-
def write_overridden_instr_place_holder(
840-
self, place_holder: OverriddenInstructionPlaceHolder
841-
) -> None:
842-
self.out.emit("")
843-
self.out.emit(
844-
f"{self.out.comment} TARGET({place_holder.name}) overridden by later definition"
845-
)
846-
847830

848831
def is_super_instruction(mac: MacroInstruction) -> bool:
849832
if (

Tools/cases_generator/instructions.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -295,11 +295,6 @@ class PseudoInstruction:
295295
instr_flags: InstructionFlags
296296

297297

298-
@dataclasses.dataclass
299-
class OverriddenInstructionPlaceHolder:
300-
name: str
301-
302-
303298
AnyInstruction = Instruction | MacroInstruction | PseudoInstruction
304299

305300

0 commit comments

Comments
 (0)