Skip to content

gh-109287: fix overrides in cases generator #110419

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions Lib/test/test_generated_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,41 @@ def test_macro_push_push(self):
"""
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()
11 changes: 2 additions & 9 deletions Tools/cases_generator/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
InstructionOrCacheEffect,
MacroInstruction,
MacroParts,
OverriddenInstructionPlaceHolder,
PseudoInstruction,
)
import parsing
Expand Down Expand Up @@ -66,7 +65,6 @@ def note(self, msg: str, node: parsing.Node) -> None:
parsing.InstDef
| parsing.Macro
| parsing.Pseudo
| OverriddenInstructionPlaceHolder
]
instrs: dict[str, Instruction] # Includes ops
macros: dict[str, parsing.Macro]
Expand Down Expand Up @@ -141,7 +139,7 @@ def parse_file(self, filename: str, instrs_idx: dict[str, int]) -> None:
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:
Expand All @@ -150,12 +148,7 @@ def parse_file(self, filename: str, instrs_idx: dict[str, int]) -> None:
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 "
Expand Down
17 changes: 0 additions & 17 deletions Tools/cases_generator/generate_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
MacroInstruction,
MacroParts,
PseudoInstruction,
OverriddenInstructionPlaceHolder,
TIER_ONE,
TIER_TWO,
)
Expand Down Expand Up @@ -208,8 +207,6 @@ def write_stack_effect_functions(self) -> None:
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)
Expand Down Expand Up @@ -393,8 +390,6 @@ def write_metadata(self, metadata_filename: str, pymetadata_filename: str) -> No
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():
Expand Down Expand Up @@ -492,8 +487,6 @@ def write_metadata(self, metadata_filename: str, pymetadata_filename: str) -> No
# 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():
Expand Down Expand Up @@ -774,8 +767,6 @@ def write_instructions(
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():
Expand Down Expand Up @@ -836,14 +827,6 @@ def write_abstract_interpreter_instructions(
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 (
Expand Down
5 changes: 0 additions & 5 deletions Tools/cases_generator/instructions.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,11 +295,6 @@ class PseudoInstruction:
instr_flags: InstructionFlags


@dataclasses.dataclass
class OverriddenInstructionPlaceHolder:
name: str


AnyInstruction = Instruction | MacroInstruction | PseudoInstruction


Expand Down