Skip to content

Commit b8df695

Browse files
committed
pythongh-104635: add NO_SIDE_EFFECT flag to opcode metadata
1 parent 5890621 commit b8df695

File tree

2 files changed

+32
-15
lines changed

2 files changed

+32
-15
lines changed

Python/opcode_metadata.h

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

Tools/cases_generator/generate_cases.py

+16-1
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ class InstructionFlags:
252252
HAS_CONST_FLAG: bool
253253
HAS_NAME_FLAG: bool
254254
HAS_JUMP_FLAG: bool
255+
NO_SIDE_EFFECT_FLAG: bool
255256

256257
def __post_init__(self):
257258
self.bitmask = {
@@ -265,11 +266,12 @@ def fromInstruction(instr: "AnyInstruction"):
265266
HAS_CONST_FLAG=variable_used(instr, "FRAME_CO_CONSTS"),
266267
HAS_NAME_FLAG=variable_used(instr, "FRAME_CO_NAMES"),
267268
HAS_JUMP_FLAG=variable_used(instr, "JUMPBY"),
269+
NO_SIDE_EFFECT_FLAG=no_side_effect(instr),
268270
)
269271

270272
@staticmethod
271273
def newEmpty():
272-
return InstructionFlags(False, False, False, False)
274+
return InstructionFlags(False, False, False, False, False)
273275

274276
def add(self, other: "InstructionFlags") -> None:
275277
for name, value in dataclasses.asdict(other).items():
@@ -1585,6 +1587,19 @@ def variable_used(node: parser.Node, name: str) -> bool:
15851587
)
15861588

15871589

1590+
def no_side_effect(node: parser.Node) -> bool:
1591+
if node.name.startswith("JUMP"):
1592+
return False
1593+
for token in node.tokens:
1594+
token_text = token.text.lower()
1595+
if token.kind == "IDENTIFIER":
1596+
if token_text in ("error_if", "go_to_instruction"):
1597+
return False
1598+
if token_text.startswith("py") or token_text.startswith("_py"):
1599+
return False
1600+
return True
1601+
1602+
15881603
def main():
15891604
"""Parse command line, parse input, analyze, write output."""
15901605
args = arg_parser.parse_args() # Prints message and sys.exit(2) on error

0 commit comments

Comments
 (0)