[3.13] gh-120367: fix removal of redundant NOPs and jumps after reordering hot-cold blocks (GH-120425) (#120621)

gh-120367: fix removal of redundant NOPs and jumps after reordering hot-cold blocks (GH-120425)
(cherry picked from commit 21866c8ed2)

Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
This commit is contained in:
Miss Islington (bot) 2024-06-17 17:07:20 +02:00 committed by GitHub
parent 7c47f93dff
commit 61a2229005
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 47 additions and 12 deletions

View file

@ -502,6 +502,33 @@ class TestSpecifics(unittest.TestCase):
with self.assertRaisesRegex(TypeError, "NamedExpr target must be a Name"):
compile(ast.fix_missing_locations(m), "<file>", "exec")
def test_compile_redundant_jumps_and_nops_after_moving_cold_blocks(self):
# See gh-120367
code=textwrap.dedent("""
try:
pass
except:
pass
else:
match name_2:
case b'':
pass
finally:
something
""")
tree = ast.parse(code)
# make all instructions locations the same to create redundancies
for node in ast.walk(tree):
if hasattr(node,"lineno"):
del node.lineno
del node.end_lineno
del node.col_offset
del node.end_col_offset
compile(ast.fix_missing_locations(tree), "<file>", "exec")
def test_compile_ast(self):
fname = __file__
if fname.lower().endswith('pyc'):