Skip to content

Commit c43d20b

Browse files
committed
Special-case CHECK_EVAL_BREAKER()
1 parent f87f6e2 commit c43d20b

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

Tools/cases_generator/generate_cases.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,8 @@ def __init__(self, inst: parser.InstDef):
230230
self.kind = inst.kind
231231
self.name = inst.name
232232
self.block = inst.block
233-
self.block_text, self.predictions = extract_block_text(self.block)
233+
self.block_text, self.check_eval_breaker, self.predictions = \
234+
extract_block_text(self.block)
234235
self.always_exits = always_exits(self.block_text)
235236
self.cache_effects = [
236237
effect for effect in inst.inputs if isinstance(effect, parser.CacheEffect)
@@ -1016,6 +1017,8 @@ def write_instr(self, instr: Instruction) -> None:
10161017
if not instr.always_exits:
10171018
for prediction in instr.predictions:
10181019
self.out.emit(f"PREDICT({prediction});")
1020+
if instr.check_eval_breaker:
1021+
self.out.emit("CHECK_EVAL_BREAKER();")
10191022
self.out.emit(f"DISPATCH();")
10201023

10211024
def write_super(self, sup: SuperInstruction) -> None:
@@ -1091,7 +1094,7 @@ def wrap_super_or_macro(self, up: SuperOrMacroInstruction):
10911094
self.out.emit(f"DISPATCH();")
10921095

10931096

1094-
def extract_block_text(block: parser.Block) -> tuple[list[str], list[str]]:
1097+
def extract_block_text(block: parser.Block) -> tuple[list[str], bool, list[str]]:
10951098
# Get lines of text with proper dedent
10961099
blocklines = block.text.splitlines(True)
10971100

@@ -1111,6 +1114,12 @@ def extract_block_text(block: parser.Block) -> tuple[list[str], list[str]]:
11111114
while blocklines and not blocklines[-1].strip():
11121115
blocklines.pop()
11131116

1117+
# Separate CHECK_EVAL_BREAKER() macro from end
1118+
check_eval_breaker = \
1119+
blocklines != [] and blocklines[-1].strip() == "CHECK_EVAL_BREAKER();"
1120+
if check_eval_breaker:
1121+
del blocklines[-1]
1122+
11141123
# Separate PREDICT(...) macros from end
11151124
predictions: list[str] = []
11161125
while blocklines and (
@@ -1119,7 +1128,7 @@ def extract_block_text(block: parser.Block) -> tuple[list[str], list[str]]:
11191128
predictions.insert(0, m.group(1))
11201129
blocklines.pop()
11211130

1122-
return blocklines, predictions
1131+
return blocklines, check_eval_breaker, predictions
11231132

11241133

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

Tools/cases_generator/test_generator.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,15 +177,16 @@ def test_overlap():
177177
"""
178178
run_cases_test(input, output)
179179

180-
def test_predictions():
180+
def test_predictions_and_eval_breaker():
181181
input = """
182182
inst(OP1, (--)) {
183183
}
184184
inst(OP2, (--)) {
185185
}
186-
inst(OP3, (--)) {
186+
inst(OP3, (arg -- res)) {
187187
DEOPT_IF(xxx, OP1);
188188
PREDICT(OP2);
189+
CHECK_EVAL_BREAKER();
189190
}
190191
"""
191192
output = """
@@ -200,8 +201,12 @@ def test_predictions():
200201
}
201202
202203
TARGET(OP3) {
204+
PyObject *arg = PEEK(1);
205+
PyObject *res;
203206
DEOPT_IF(xxx, OP1);
207+
POKE(1, res);
204208
PREDICT(OP2);
209+
CHECK_EVAL_BREAKER();
205210
DISPATCH();
206211
}
207212
"""

0 commit comments

Comments
 (0)