10000 gh-126835: Move constant subscript folding to CFG by WolframAlph · Pull Request #129568 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-126835: Move constant subscript folding to CFG #129568

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 10 commits into from
Feb 4, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
update test_folding_subscript
  • Loading branch information
WolframAlph committed Feb 3, 2025
commit 5ad6781252ed3bf58471ae1a45b0299ed77d1adf
46 changes: 22 additions & 24 deletions Lib/test/test_peepholer.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,36 +475,34 @@ def test_constant_folding(self):

def test_folding_subscript(self):
tests = [
# small ints
('(1, )[0]', True, False),
('(255, )[0]', True, False),
('(1, (1, 2))[1][1]', True, False),
('(1, 2)[2-1]', True, False),
('(1, (1, 2))[1][2-1]', True, False),
('(1, (1, 2))[1:6][0][2-1]', True, False),
# regular ints
('(256, )[0]', False, False),
('(1, (1, 1000))[1][1]', False, False),
('(1, 1000)[2-1]', False, False),
('(1, (1, 1000))[1][2-1]', False, False),
# errors
('(1, )[1]', True, True),
('(1, )[-2]', False, True),
('"a"[1]', True, True),
('"a"[-2]', False, True),
('(1, (1, 2))[2:6][0][2-1]', True, True),
('(1, )[0]', False),
('(1, )[-1]', False),
('(1 + 2, )[0]', False),
('(1, (1, 2))[1][1]', False),
('(1, 2)[2-1]', False),
('(1, (1, 2))[1][2-1]', False),
('(1, (1, 2))[1:6][0][2-1]', False),
('"a"[0]', False),
('("a" + "b")[1]', False),
('("a" + "b", )[0][1]', False),
('("a" * 10)[9]', False),
('(1, )[1]', True),
('(1, )[-2]', True),
('"a"[1]', True),
('"a"[-2]', True),
('("a" + "b")[2]', True),
('("a" + "b", )[0][2]', True),
('("a" + "b", )[1][0]', True),
('("a" * 10)[10]', True),
('(1, (1, 2))[2:6][0][2-1]', True),
]
for expr, has_small_int, has_error in tests:
with self.subTest(expr=expr, has_small_int=has_small_int, has_error=has_error):
for expr, has_error in tests:
with self.subTest(expr=expr, has_error=has_error):
code = compile(expr, '', 'single')
if not has_error:
self.assertNotInBytecode(code, 'BINARY_SUBSCR')
else:
self.assertInBytecode(code, 'BINARY_SUBSCR')
if has_small_int:
self.assertInBytecode(code, 'LOAD_SMALL_INT')
else:
self.assertNotInBytecode(code, 'LOAD_SMALL_INT')
self.check_lnotab(code)

def test_in_literal_list(self):
Expand Down
0