summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorBrandt Bucher <brandt@python.org>2022-01-26 20:47:45 (GMT)
committerGitHub <noreply@github.com>2022-01-26 20:47:45 (GMT)
commit85483668647e7840c7b9a1877caaf2ef14a4443f (patch)
tree48c1ba3dc17fb6c39d100e114178e1cc9ca19e88 /Lib
parentd4a85f104bf9d2e368f25c9a567eaaa2cc39a96a (diff)
downloadcpython-85483668647e7840c7b9a1877caaf2ef14a4443f.zip
cpython-85483668647e7840c7b9a1877caaf2ef14a4443f.tar.gz
cpython-85483668647e7840c7b9a1877caaf2ef14a4443f.tar.bz2
bpo-46528: Simplify the VM's stack manipulations (GH-30902)
Diffstat (limited to 'Lib')
-rw-r--r--Lib/importlib/_bootstrap_external.py4
-rw-r--r--Lib/opcode.py7
-rw-r--r--Lib/test/test__opcode.py1
-rw-r--r--Lib/test/test_dis.py4
-rw-r--r--Lib/test/test_peepholer.py4
5 files changed, 8 insertions, 12 deletions
diff --git a/Lib/importlib/_bootstrap_external.py b/Lib/importlib/_bootstrap_external.py
index cd4f69c..c05add9 100644
--- a/Lib/importlib/_bootstrap_external.py
+++ b/Lib/importlib/_bootstrap_external.py
@@ -382,6 +382,8 @@ _code_type = type(_write_atomic.__code__)
# Python 3.11a4 3474 (Add RESUME opcode)
# Python 3.11a5 3475 (Add RETURN_GENERATOR opcode)
# Python 3.11a5 3476 (Add ASYNC_GEN_WRAP opcode)
+# Python 3.11a5 3477 (Replace DUP_TOP/DUP_TOP_TWO with COPY and
+# ROT_TWO/ROT_THREE/ROT_FOUR/ROT_N with SWAP)
# Python 3.12 will start with magic number 3500
@@ -395,7 +397,7 @@ _code_type = type(_write_atomic.__code__)
# Whenever MAGIC_NUMBER is changed, the ranges in the magic_values array
# in PC/launcher.c must also be updated.
-MAGIC_NUMBER = (3476).to_bytes(2, 'little') + b'\r\n'
+MAGIC_NUMBER = (3477).to_bytes(2, 'little') + b'\r\n'
_RAW_MAGIC_NUMBER = int.from_bytes(MAGIC_NUMBER, 'little') # For import.c
_PYCACHE = '__pycache__'
diff --git a/Lib/opcode.py b/Lib/opcode.py
index 1bd48ee..37da05d 100644
--- a/Lib/opcode.py
+++ b/Lib/opcode.py
@@ -55,11 +55,6 @@ def jabs_op(name, op):
# Blank lines correspond to available opcodes
def_op('POP_TOP', 1)
-def_op('ROT_TWO', 2)
-def_op('ROT_THREE', 3)
-def_op('DUP_TOP', 4)
-def_op('DUP_TOP_TWO', 5)
-def_op('ROT_FOUR', 6)
def_op('NOP', 9)
def_op('UNARY_POSITIVE', 10)
@@ -116,7 +111,7 @@ name_op('STORE_ATTR', 95) # Index in name list
name_op('DELETE_ATTR', 96) # ""
name_op('STORE_GLOBAL', 97) # ""
name_op('DELETE_GLOBAL', 98) # ""
-def_op('ROT_N', 99)
+def_op('SWAP', 99)
def_op('LOAD_CONST', 100) # Index in const list
hasconst.append(100)
name_op('LOAD_NAME', 101) # Index in name list
diff --git a/Lib/test/test__opcode.py b/Lib/test/test__opcode.py
index f6b6b3d..7c1c0cf 100644
--- a/Lib/test/test__opcode.py
+++ b/Lib/test/test__opcode.py
@@ -11,7 +11,6 @@ class OpcodeTests(unittest.TestCase):
def test_stack_effect(self):
self.assertEqual(stack_effect(dis.opmap['POP_TOP']), -1)
- self.assertEqual(stack_effect(dis.opmap['DUP_TOP_TWO']), 2)
self.assertEqual(stack_effect(dis.opmap['BUILD_SLICE'], 0), -1)
self.assertEqual(stack_effect(dis.opmap['BUILD_SLICE'], 1), -1)
self.assertEqual(stack_effect(dis.opmap['BUILD_SLICE'], 3), -2)
diff --git a/Lib/test/test_dis.py b/Lib/test/test_dis.py
index c65b014..7259064 100644
--- a/Lib/test/test_dis.py
+++ b/Lib/test/test_dis.py
@@ -1195,8 +1195,8 @@ expected_opinfo_jumpy = [
Instruction(opname='CALL_NO_KW', opcode=169, arg=1, argval=1, argrepr='', offset=156, starts_line=None, is_jump_target=False, positions=None),
Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=158, starts_line=None, is_jump_target=False, positions=None),
Instruction(opname='LOAD_CONST', opcode=100, arg=0, argval=None, argrepr='None', offset=160, starts_line=25, is_jump_target=False, positions=None),
- Instruction(opname='DUP_TOP', opcode=4, arg=None, argval=None, argrepr='', offset=162, starts_line=None, is_jump_target=False, positions=None),
- Instruction(opname='DUP_TOP', opcode=4, arg=None, argval=None, argrepr='', offset=164, starts_line=None, is_jump_target=False, positions=None),
+ Instruction(opname='LOAD_CONST', opcode=100, arg=0, argval=None, argrepr='None', offset=162, starts_line=None, is_jump_target=False, positions=None),
+ Instruction(opname='LOAD_CONST', opcode=100, arg=0, argval=None, argrepr='None', offset=164, starts_line=None, is_jump_target=False, positions=None),
Instruction(opname='CALL_NO_KW', opcode=169, arg=3, argval=3, argrepr='', offset=166, starts_line=None, is_jump_target=False, positions=None),
Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=168, starts_line=None, is_jump_target=False, positions=None),
Instruction(opname='JUMP_FORWARD', opcode=110, arg=25, argval=222, argrepr='to 222', offset=170, starts_line=None, is_jump_target=False, positions=None),
diff --git a/Lib/test/test_peepholer.py b/Lib/test/test_peepholer.py
index 8306c89..659f654 100644
--- a/Lib/test/test_peepholer.py
+++ b/Lib/test/test_peepholer.py
@@ -119,8 +119,8 @@ class TestTranforms(BytecodeTestCase):
def test_pack_unpack(self):
for line, elem in (
('a, = a,', 'LOAD_CONST',),
- ('a, b = a, b', 'ROT_TWO',),
- ('a, b, c = a, b, c', 'ROT_THREE',),
+ ('a, b = a, b', 'SWAP',),
+ ('a, b, c = a, b, c', 'SWAP',),
):
with self.subTest(line=line):
code = compile(line,'','single')