8000 gh-107901: add the HAS_EVAL_BREAK instruction flag by iritkatriel · Pull Request #108375 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-107901: add the HAS_EVAL_BREAK instruction flag #108375

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 9 commits into from
Aug 25, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
36 changes: 19 additions & 17 deletions Include/internal/pycore_opcode_metadata.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Tools/cases_generator/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,8 @@ def analyze_pseudo(self, pseudo: parsing.Pseudo) -> PseudoInstruction:
# Make sure the targets have the same fmt
fmts = list(set([t.instr_fmt for t in targets]))
assert len(fmts) == 1
assert len(list(set([t.instr_flags.bitmap() for t in targets]))) == 1
ignored_flags = ['HAS_EVAL_BREAK_FLAG']
assert len(list(set([t.instr_flags.bitmap(ignore=ignored_flags) for t in targets]))) == 1
return PseudoInstruction(pseudo.name, targets, fmts[0], targets[0].instr_flags)

def analyze_instruction(
Expand Down
9 changes: 6 additions & 3 deletions Tools/cases_generator/flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class InstructionFlags:
HAS_JUMP_FLAG: bool
HAS_FREE_FLAG: bool
HAS_LOCAL_FLAG: bool
HAS_EVAL_BREAK_FLAG: bool

def __post_init__(self) -> None:
self.bitmask = {name: (1 << i) for i, name in enumerate(self.names())}
Expand All @@ -37,11 +38,12 @@ def fromInstruction(instr: parsing.Node) -> "InstructionFlags":
variable_used(instr, "GETLOCAL") or variable_used(instr, "SETLOCAL")
)
and not has_free,
HAS_EVAL_BREAK_FLAG=variable_used(instr, "CHECK_EVAL_BREAKER"),
)

@staticmethod
def newEmpty() -> "InstructionFlags":
return InstructionFlags(False, False, False, False, False, False)
return InstructionFlags(False, False, False, False, False, False, False)

def add(self, other: "InstructionFlags") -> None:
for name, value in dataclasses.asdict(other).items():
Expand All @@ -53,10 +55,11 @@ def names(self, value: bool | None = None) -> list[str]:
return list(dataclasses.asdict(self).keys())
return [n for n, v in dataclasses.asdict(self).items() if v == value]

def bitmap(self) -> int:
def bitmap(self, ignore: list[str] = []) -> int:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using a mutable default sets alarm bells off in my head, even though you're safe in this case. Maybe make it an abstract set?

flags = 0
assert all(hasattr(self, name) for name in ignore)
for name in self.names():
if getattr(self, name):
if getattr(self, name) and name not in ignore:
flags |= self.bitmask[name]
return flags

Expand Down
0