Skip to content

Commit c85be33

Browse files
authored
gh-104610: Stop looking for PREDICT() in the cases generator (#105459)
We no longer use `PREDICT()`, it doesn't have any benefits.
1 parent f339ec5 commit c85be33

File tree

1 file changed

+5
-16
lines changed

1 file changed

+5
-16
lines changed

Tools/cases_generator/generate_cases.py

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
BEGIN_MARKER = "// BEGIN BYTECODES //"
3030
END_MARKER = "// END BYTECODES //"
3131
RE_PREDICTED = (
32-
r"^\s*(?:PREDICT\(|GO_TO_INSTRUCTION\(|DEOPT_IF\(.*?,\s*)(\w+)\);\s*(?://.*)?$"
32+
r"^\s*(?:GO_TO_INSTRUCTION\(|DEOPT_IF\(.*?,\s*)(\w+)\);\s*(?://.*)?$"
3333
)
3434
UNUSED = "unused"
3535
BITS_PER_CODE_UNIT = 16
@@ -234,7 +234,6 @@ class Instruction:
234234
name: str
235235
block: parser.Block
236236
block_text: list[str] # Block.text, less curlies, less PREDICT() calls
237-
predictions: list[str] # Prediction targets (instruction names)
238237
block_line: int # First line of block in original code
239238

240239
# Computed by constructor
@@ -255,7 +254,7 @@ def __init__(self, inst: parser.InstDef):
255254
self.kind = inst.kind
256255
self.name = inst.name
257256
self.block = inst.block
258-
self.block_text, self.check_eval_breaker, self.predictions, self.block_line = \
257+
self.block_text, self.check_eval_breaker, self.block_line = \
259258
extract_block_text(self.block)
260259
self.always_exits = always_exits(self.block_text)
261260
self.cache_effects = [
@@ -642,7 +641,7 @@ def analyze(self) -> None:
642641
def find_predictions(self) -> None:
643642
"""Find the instructions that need PREDICTED() labels."""
644643
for instr in self.instrs.values():
645-
targets = set(instr.predictions)
644+
targets = set()
646645
for line in instr.block_text:
647646
if m := re.match(RE_PREDICTED, line):
648647
targets.add(m.group(1))
@@ -1117,8 +1116,6 @@ def write_instr(self, instr: Instruction) -> None:
11171116
self.out.emit(f"PREDICTED({name});")
11181117
instr.write(self.out)
11191118
if not instr.always_exits:
1120-
for prediction in instr.predictions:
1121-
self.out.emit(f"PREDICT({prediction});")
11221119
if instr.check_eval_breaker:
11231120
self.out.emit("CHECK_EVAL_BREAKER();")
11241121
self.out.emit(f"DISPATCH();")
@@ -1195,7 +1192,7 @@ def wrap_super_or_macro(self, up: SuperOrMacroInstruction):
11951192
self.out.emit(f"DISPATCH();")
11961193

11971194

1198-
def extract_block_text(block: parser.Block) -> tuple[list[str], bool, list[str], int]:
1195+
def extract_block_text(block: parser.Block) -> tuple[list[str], bool, int]:
11991196
# Get lines of text with proper dedent
12001197
blocklines = block.text.splitlines(True)
12011198
first_token: lx.Token = block.tokens[0] # IndexError means the context is broken
@@ -1225,15 +1222,7 @@ def extract_block_text(block: parser.Block) -> tuple[list[str], bool, list[str],
12251222
if check_eval_breaker:
12261223
del blocklines[-1]
12271224

1228-
# Separate PREDICT(...) macros from end
1229-
predictions: list[str] = []
1230-
while blocklines and (
1231-
m := re.match(r"^\s*PREDICT\((\w+)\);\s*(?://.*)?$", blocklines[-1])
1232-
):
1233-
predictions.insert(0, m.group(1))
1234-
blocklines.pop()
1235-
1236-
return blocklines, check_eval_breaker, predictions, block_line
1225+
return blocklines, check_eval_breaker, block_line
12371226

12381227

12391228
def always_exits(lines: list[str]) -> bool:

0 commit comments

Comments
 (0)