8000 gh-126835: make CFG optimizer skip over NOP's when looking for const sequence construction by WolframAlph · Pull Request #129703 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-126835: make CFG optimizer skip over NOP's when looking for const sequence construction #129703

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Feb 9, 2025
Prev Previous commit
Next Next commit
update tests
  • Loading branch information
WolframAlph committed Feb 8, 2025
commit 5866faa9cee56c3bc3b348ce25872c3781c7138a
12 changes: 9 additions & 3 deletions Lib/test/test_peepholer.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ def count_instr_recursively(f, opname):
return count


def get_binop_argval(arg):
for i, nb_op in enumerate(opcode._nb_ops):
if arg == nb_op[0]:
return i
assert False, f"{arg} is not a valid BINARY_OP argument."


class TestTranforms(BytecodeTestCase):

def check_jump_targets(self, code):
Expand Down Expand Up @@ -518,8 +525,7 @@ def test_folding_subscript(self):
('("a" * 10)[10]', True),
('(1, (1, 2))[2:6][0][2-1]', True),
]
subscr_argval = 26
assert opcode._nb_ops[subscr_argval][0] == 'NB_SUBSCR'
subscr_argval = get_binop_argval('NB_SUBSCR')
for expr, has_error in tests:
with self.subTest(expr=expr, has_error=has_error):
code = compile(expr, '', 'single')
Expand Down Expand Up @@ -1068,7 +1074,7 @@ def test_multiple_foldings(self):
('LOAD_SMALL_INT', 2, 0),
('BUILD_TUPLE', 1, 0),
('LOAD_SMALL_INT', 0, 0),
('BINARY_SUBSCR', None, 0),
('BINARY_OP', get_binop_argval('NB_SUBSCR'), 0),
('BUILD_TUPLE', 2, 0),
('RETURN_VALUE', None, 0)
]
Expand Down
Loading
0