Skip to content

Commit 4fdeb4b

Browse files
DinoVfacebook-github-bot
authored andcommitted
Preserve jump when inlining no line number blocks
Summary: 3.14 has a new check to "Make sure we don't lose eval breaker checks" - if the jump would have removed an eval breaker check it's added back in. Reviewed By: alexmalyshev Differential Revision: D81825276 fbshipit-source-id: 8543d83bd4940d90ee0e2c31354d399b8f49b69d
1 parent 883c54e commit 4fdeb4b

2 files changed

Lines changed: 42 additions & 0 deletions

File tree

cinderx/PythonLib/cinderx/compiler/pyassem.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1346,6 +1346,7 @@ def extend_block(self, block: Block) -> bool:
13461346
last.set_to_nop()
13471347
for instr in target.insts:
13481348
block.insts.append(instr.copy())
1349+
13491350
block.next = None
13501351
block.is_exit = True
13511352
block.has_fallthrough = False
@@ -2461,6 +2462,37 @@ def should_inline_block(self, block: Block) -> bool:
24612462
return False
24622463
return True
24632464

2465+
def extend_block(self, block: Block) -> bool:
2466+
"""If this block ends with an unconditional jump to an exit block,
2467+
then remove the jump and extend this block with the target.
2468+
"""
2469+
if len(block.insts) == 0:
2470+
return False
2471+
last = block.insts[-1]
2472+
if last.opname not in UNCONDITIONAL_JUMP_OPCODES:
2473+
return False
2474+
target = last.target
2475+
assert target is not None
2476+
small_exit_block = target.exits and len(target.insts) <= MAX_COPY_SIZE
2477+
no_line_no_fallthrough = not target.has_fallthrough and target.has_no_lineno()
2478+
if not small_exit_block and not no_line_no_fallthrough:
2479+
return False
2480+
last = block.insts[-1]
2481+
removed = last.opname
2482+
last.set_to_nop()
2483+
for instr in target.insts:
2484+
block.insts.append(instr.copy())
2485+
2486+
last = block.insts[-1]
2487+
if last.opname in UNCONDITIONAL_JUMP_OPCODES and removed == "JUMP":
2488+
# Make sure we don't lose eval breaker checks
2489+
last.opname = "JUMP"
2490+
2491+
block.next = None
2492+
block.is_exit = True
2493+
block.has_fallthrough = False
2494+
return True
2495+
24642496
def finalize(self) -> None:
24652497
"""Perform final optimizations and normalization of flow graph."""
24662498
assert self.stage == ACTIVE, self.stage
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# pyre-ignore-all-errors
2+
def f(y):
3+
try:
4+
pass
5+
except TypeError:
6+
for x in y:
7+
break
8+
9+
x()
10+

0 commit comments

Comments
 (0)