Skip to content
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

gh-107901: add the HAS_EVAL_BREAK instruction flag #108375

Merged
merged 9 commits into from
Aug 25, 2023
Merged
Show file tree
Hide file tree
Changes from 8 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 = set(('HAS_EVAL_BREAK_FLAG',))
assert len(list(set([t.instr_flags.bitmap(ignore=ignored_flags) for t in targets]))) == 1
iritkatriel marked this conversation as resolved.
Show resolved Hide resolved
return PseudoInstruction(pseudo.name, targets, fmts[0], targets[0].instr_flags)

def analyze_instruction(
Expand Down
10 changes: 7 additions & 3 deletions Tools/cases_generator/flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from formatting import Formatter
import lexer as lx
import parsing
from typing import AbstractSet


@dataclasses.dataclass
Expand All @@ -15,6 +16,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 +39,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 +56,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: AbstractSet[str] = set()) -> int:
iritkatriel marked this conversation as resolved.
Show resolved Hide resolved
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