summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_peepholer.py
diff options
context:
space:
mode:
authorMark Shannon <mark@hotpy.org>2024-10-29 11:15:42 (GMT)
committerGitHub <noreply@github.com>2024-10-29 11:15:42 (GMT)
commitfaa3272fb8d63d481a136cc0467a0cba6ed7b264 (patch)
tree474ac9edbff637a8edb280846a1d3d9b113915c4 /Lib/test/test_peepholer.py
parent67f5c5bd6fcc956a785edef3be67e8cbe470cd31 (diff)
downloadcpython-faa3272fb8d63d481a136cc0467a0cba6ed7b264.zip
cpython-faa3272fb8d63d481a136cc0467a0cba6ed7b264.tar.gz
cpython-faa3272fb8d63d481a136cc0467a0cba6ed7b264.tar.bz2
GH-125837: Split `LOAD_CONST` into three. (GH-125972)
* Add LOAD_CONST_IMMORTAL opcode * Add LOAD_SMALL_INT opcode * Remove RETURN_CONST opcode
Diffstat (limited to 'Lib/test/test_peepholer.py')
-rw-r--r--Lib/test/test_peepholer.py48
1 files changed, 32 insertions, 16 deletions
diff --git a/Lib/test/test_peepholer.py b/Lib/test/test_peepholer.py
index b143f3d..c7da151 100644
--- a/Lib/test/test_peepholer.py
+++ b/Lib/test/test_peepholer.py
@@ -114,7 +114,7 @@ class TestTranforms(BytecodeTestCase):
return None
self.assertNotInBytecode(f, 'LOAD_GLOBAL')
- self.assertInBytecode(f, 'RETURN_CONST', None)
+ self.assertInBytecode(f, 'LOAD_CONST', None)
self.check_lnotab(f)
def test_while_one(self):
@@ -131,7 +131,7 @@ class TestTranforms(BytecodeTestCase):
def test_pack_unpack(self):
for line, elem in (
- ('a, = a,', 'RETURN_CONST',),
+ ('a, = a,', 'LOAD_CONST',),
('a, b = a, b', 'SWAP',),
('a, b, c = a, b, c', 'SWAP',),
):
@@ -162,7 +162,7 @@ class TestTranforms(BytecodeTestCase):
# One LOAD_CONST for the tuple, one for the None return value
load_consts = [instr for instr in dis.get_instructions(code)
if instr.opname == 'LOAD_CONST']
- self.assertEqual(len(load_consts), 1)
+ self.assertEqual(len(load_consts), 2)
self.check_lnotab(code)
# Bug 1053819: Tuple of constants misidentified when presented with:
@@ -248,14 +248,17 @@ class TestTranforms(BytecodeTestCase):
):
with self.subTest(line=line):
code = compile(line, '', 'single')
- self.assertInBytecode(code, 'LOAD_CONST', elem)
+ if isinstance(elem, int):
+ self.assertInBytecode(code, 'LOAD_SMALL_INT', elem)
+ else:
+ self.assertInBytecode(code, 'LOAD_CONST', elem)
for instr in dis.get_instructions(code):
self.assertFalse(instr.opname.startswith('BINARY_'))
self.check_lnotab(code)
# Verify that unfoldables are skipped
code = compile('a=2+"b"', '', 'single')
- self.assertInBytecode(code, 'LOAD_CONST', 2)
+ self.assertInBytecode(code, 'LOAD_SMALL_INT', 2)
self.assertInBytecode(code, 'LOAD_CONST', 'b')
self.check_lnotab(code)
@@ -307,7 +310,10 @@ class TestTranforms(BytecodeTestCase):
):
with self.subTest(line=line):
code = compile(line, '', 'single')
- self.assertInBytecode(code, 'LOAD_CONST', elem)
+ if isinstance(elem, int):
+ self.assertInBytecode(code, 'LOAD_SMALL_INT', elem)
+ else:
+ self.assertInBytecode(code, 'LOAD_CONST', elem)
for instr in dis.get_instructions(code):
self.assertFalse(instr.opname.startswith('UNARY_'))
self.check_lnotab(code)
@@ -989,9 +995,11 @@ class DirectCfgOptimizerTests(CfgOptimizationTestCase):
expected_insts = [
('LOAD_NAME', 1, 11),
('POP_JUMP_IF_TRUE', lbl := self.Label(), 12),
- ('RETURN_CONST', 1, 13),
+ ('LOAD_CONST', 1, 13),
+ ('RETURN_VALUE', None, 13),
lbl,
- ('RETURN_CONST', 2, 14),
+ ('LOAD_CONST', 2, 14),
+ ('RETURN_VALUE', None, 14),
]
self.cfg_optimization_test(insts,
expected_insts,
@@ -1013,7 +1021,8 @@ class DirectCfgOptimizerTests(CfgOptimizationTestCase):
expected_insts = [
('NOP', None, 11),
('NOP', None, 12),
- ('RETURN_CONST', 1, 14),
+ ('LOAD_CONST', 1, 14),
+ ('RETURN_VALUE', None, 14),
]
self.cfg_optimization_test(insts,
expected_insts,
@@ -1057,15 +1066,19 @@ class DirectCfgOptimizerTests(CfgOptimizationTestCase):
insts = [
('SETUP_FINALLY', handler := self.Label(), 10),
('POP_BLOCK', None, -1),
- ('RETURN_CONST', 1, 11),
+ ('LOAD_CONST', 1, 11),
+ ('RETURN_VALUE', None, 11),
handler,
- ('RETURN_CONST', 2, 12),
+ ('LOAD_CONST', 2, 12),
+ ('RETURN_VALUE', None, 12),
]
expected_insts = [
('SETUP_FINALLY', handler := self.Label(), 10),
- ('RETURN_CONST', 1, 11),
+ ('LOAD_CONST', 1, 11),
+ ('RETURN_VALUE', None, 11),
handler,
- ('RETURN_CONST', 2, 12),
+ ('LOAD_CONST', 2, 12),
+ ('RETURN_VALUE', None, 12),
]
self.cfg_optimization_test(insts, expected_insts, consts=list(range(5)))
@@ -1088,7 +1101,8 @@ class DirectCfgOptimizerTests(CfgOptimizationTestCase):
('NOP', None, 3),
('STORE_FAST', 1, 4),
('POP_TOP', None, 4),
- ('RETURN_CONST', 0)
+ ('LOAD_CONST', 0, 5),
+ ('RETURN_VALUE', None, 5)
]
self.cfg_optimization_test(insts, expected_insts, consts=list(range(3)), nlocals=1)
@@ -1109,7 +1123,8 @@ class DirectCfgOptimizerTests(CfgOptimizationTestCase):
('NOP', None, 3),
('POP_TOP', None, 4),
('STORE_FAST', 1, 4),
- ('RETURN_CONST', 0, 5)
+ ('LOAD_CONST', 0, 5),
+ ('RETURN_VALUE', None, 5)
]
self.cfg_optimization_test(insts, expected_insts, consts=list(range(3)), nlocals=1)
@@ -1131,7 +1146,8 @@ class DirectCfgOptimizerTests(CfgOptimizationTestCase):
('STORE_FAST', 1, 4),
('STORE_FAST', 1, 5),
('STORE_FAST', 1, 6),
- ('RETURN_CONST', 0, 5)
+ ('LOAD_CONST', 0, 5),
+ ('RETURN_VALUE', None, 5)
]
self.cfg_optimization_test(insts, expected_insts, consts=list(range(3)), nlocals=1)