Skip to content

Commit 5f41376

Browse files
authored
gh-107901: add the HAS_EVAL_BREAK instruction flag (#108375)
1 parent 5a25daa commit 5f41376

File tree

3 files changed

+28
-21
lines changed

3 files changed

+28
-21
lines changed

Include/internal/pycore_opcode_metadata.h

+19-17
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Tools/cases_generator/analysis.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,8 @@ def analyze_pseudo(self, pseudo: parsing.Pseudo) -> PseudoInstruction:
381381
# Make sure the targets have the same fmt
382382
fmts = list(set([t.instr_fmt for t in targets]))
383383
assert len(fmts) == 1
384-
assert len(list(set([t.instr_flags.bitmap() for t in targets]))) == 1
384+
ignored_flags = {'HAS_EVAL_BREAK_FLAG'}
385+
assert len({t.instr_flags.bitmap(ignore=ignored_flags) for t in targets}) == 1
385386
return PseudoInstruction(pseudo.name, targets, fmts[0], targets[0].instr_flags)
386387

387388
def analyze_instruction(

Tools/cases_generator/flags.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from formatting import Formatter
44
import lexer as lx
55
import parsing
6+
from typing import AbstractSet
67

78

89
@dataclasses.dataclass
@@ -15,6 +16,7 @@ class InstructionFlags:
1516
HAS_JUMP_FLAG: bool
1617
HAS_FREE_FLAG: bool
1718
HAS_LOCAL_FLAG: bool
19+
HAS_EVAL_BREAK_FLAG: bool
1820

1921
def __post_init__(self) -> None:
2022
self.bitmask = {name: (1 << i) for i, name in enumerate(self.names())}
@@ -37,11 +39,12 @@ def fromInstruction(instr: parsing.Node) -> "InstructionFlags":
3739
variable_used(instr, "GETLOCAL") or variable_used(instr, "SETLOCAL")
3840
)
3941
and not has_free,
42+
HAS_EVAL_BREAK_FLAG=variable_used(instr, "CHECK_EVAL_BREAKER"),
4043
)
4144

4245
@staticmethod
4346
def newEmpty() -> "InstructionFlags":
44-
return InstructionFlags(False, False, False, False, False, False)
47+
return InstructionFlags(False, False, False, False, False, False, False)
4548

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

56-
def bitmap(self) -> int:
59+
def bitmap(self, ignore: AbstractSet[str] = frozenset()) -> int:
5760
flags = 0
61+
assert all(hasattr(self, name) for name in ignore)
5862
for name in self.names():
59-
if getattr(self, name):
63+
if getattr(self, name) and name not in ignore:
6064
flags |= self.bitmask[name]
6165
return flags
6266

0 commit comments

Comments
 (0)