summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorKen Jin <kenjin4096@gmail.com>2022-06-14 10:36:22 (GMT)
committerGitHub <noreply@github.com>2022-06-14 10:36:22 (GMT)
commitb083450f8896bb4a29ac522e4474d91c056b9f32 (patch)
tree74d923609496e622ec1e99e9381ee3f6c42b829b /Lib
parentcd543d0bc9aacca1dee02dea7ff4aec8966dcaf8 (diff)
downloadcpython-b083450f8896bb4a29ac522e4474d91c056b9f32.zip
cpython-b083450f8896bb4a29ac522e4474d91c056b9f32.tar.gz
cpython-b083450f8896bb4a29ac522e4474d91c056b9f32.tar.bz2
GH-93429: Merge `LOAD_METHOD` back into `LOAD_ATTR` (GH-93430)
Diffstat (limited to 'Lib')
-rw-r--r--Lib/dis.py5
-rw-r--r--Lib/importlib/_bootstrap_external.py3
-rw-r--r--Lib/opcode.py27
-rw-r--r--Lib/test/test_dis.py6
4 files changed, 19 insertions, 22 deletions
diff --git a/Lib/dis.py b/Lib/dis.py
index 5a5ee8d..4d30fd7 100644
--- a/Lib/dis.py
+++ b/Lib/dis.py
@@ -37,6 +37,7 @@ LOAD_CONST = opmap['LOAD_CONST']
LOAD_GLOBAL = opmap['LOAD_GLOBAL']
BINARY_OP = opmap['BINARY_OP']
JUMP_BACKWARD = opmap['JUMP_BACKWARD']
+LOAD_ATTR = opmap['LOAD_ATTR']
CACHE = opmap["CACHE"]
@@ -463,6 +464,10 @@ def _get_instructions_bytes(code, varname_from_oparg=None,
argval, argrepr = _get_name_info(arg//2, get_name)
if (arg & 1) and argrepr:
argrepr = "NULL + " + argrepr
+ elif deop == LOAD_ATTR:
+ argval, argrepr = _get_name_info(arg//2, get_name)
+ if (arg & 1) and argrepr:
+ argrepr = "NULL|self + " + argrepr
else:
argval, argrepr = _get_name_info(arg, get_name)
elif deop in hasjabs:
diff --git a/Lib/importlib/_bootstrap_external.py b/Lib/importlib/_bootstrap_external.py
index 8605c2a..252d0a5 100644
--- a/Lib/importlib/_bootstrap_external.py
+++ b/Lib/importlib/_bootstrap_external.py
@@ -408,6 +408,7 @@ _code_type = type(_write_atomic.__code__)
# Python 3.12a1 3501 (YIELD_VALUE oparg == stack_depth)
# Python 3.12a1 3502 (LOAD_FAST_CHECK, no NULL-check in LOAD_FAST)
# Python 3.12a1 3503 (Shrink LOAD_METHOD cache)
+# Python 3.12a1 3504 (Merge LOAD_METHOD back into LOAD_ATTR)
# Python 3.13 will start with 3550
@@ -421,7 +422,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 = (3503).to_bytes(2, 'little') + b'\r\n'
+MAGIC_NUMBER = (3504).to_bytes(2, 'little') + b'\r\n'
_RAW_MAGIC_NUMBER = int.from_bytes(MAGIC_NUMBER, 'little') # For import.c
diff --git a/Lib/opcode.py b/Lib/opcode.py
index 8ae997e..912b280 100644
--- a/Lib/opcode.py
+++ b/Lib/opcode.py
@@ -184,8 +184,6 @@ def_op('FORMAT_VALUE', 155)
def_op('BUILD_CONST_KEY_MAP', 156)
def_op('BUILD_STRING', 157)
-name_op('LOAD_METHOD', 160)
-
def_op('LIST_EXTEND', 162)
def_op('SET_UPDATE', 163)
def_op('DICT_MERGE', 164)
@@ -285,10 +283,17 @@ _specializations = {
],
"LOAD_ATTR": [
"LOAD_ATTR_ADAPTIVE",
+ # These potentially push [NULL, bound method] onto the stack.
+ "LOAD_ATTR_CLASS",
"LOAD_ATTR_INSTANCE_VALUE",
"LOAD_ATTR_MODULE",
"LOAD_ATTR_SLOT",
"LOAD_ATTR_WITH_HINT",
+ # These will always push [unbound method, self] onto the stack.
+ "LOAD_ATTR_METHOD_LAZY_DICT",
+ "LOAD_ATTR_METHOD_NO_DICT",
+ "LOAD_ATTR_METHOD_WITH_DICT",
+ "LOAD_ATTR_METHOD_WITH_VALUES",
],
"LOAD_CONST": [
"LOAD_CONST__LOAD_FAST",
@@ -302,15 +307,6 @@ _specializations = {
"LOAD_GLOBAL_BUILTIN",
"LOAD_GLOBAL_MODULE",
],
- "LOAD_METHOD": [
- "LOAD_METHOD_ADAPTIVE",
- "LOAD_METHOD_CLASS",
- "LOAD_METHOD_LAZY_DICT",
- "LOAD_METHOD_MODULE",
- "LOAD_METHOD_NO_DICT",
- "LOAD_METHOD_WITH_DICT",
- "LOAD_METHOD_WITH_VALUES",
- ],
"RESUME": [
"RESUME_QUICK",
],
@@ -373,19 +369,14 @@ _cache_format = {
"LOAD_ATTR": {
"counter": 1,
"version": 2,
- "index": 1,
+ "keys_version": 2,
+ "descr": 4,
},
"STORE_ATTR": {
"counter": 1,
"version": 2,
"index": 1,
},
- "LOAD_METHOD": {
- "counter": 1,
- "type_version": 2,
- "keys_version": 2,
- "descr": 4,
- },
"CALL": {
"counter": 1,
"func_version": 2,
diff --git a/Lib/test/test_dis.py b/Lib/test/test_dis.py
index 656d801..f616406 100644
--- a/Lib/test/test_dis.py
+++ b/Lib/test/test_dis.py
@@ -366,11 +366,11 @@ dis_traceback = """\
%3d LOAD_GLOBAL 0 (Exception)
CHECK_EXC_MATCH
- POP_JUMP_FORWARD_IF_FALSE 18 (to 72)
+ POP_JUMP_FORWARD_IF_FALSE 23 (to 82)
STORE_FAST 0 (e)
%3d LOAD_FAST 0 (e)
- LOAD_ATTR 1 (__traceback__)
+ LOAD_ATTR 2 (__traceback__)
STORE_FAST 1 (tb)
POP_EXCEPT
LOAD_CONST 0 (None)
@@ -1134,7 +1134,7 @@ class DisTests(DisTestBase):
1 2 LOAD_CONST 0 ('a')
4 LOAD_ATTR_SLOT 0 (__class__)
- 14 RETURN_VALUE
+ 24 RETURN_VALUE
"""
co = compile("'a'.__class__", "", "eval")
self.code_quicken(lambda: exec(co, {}, {}))