summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Include/internal/pycore_opcode.h22
-rw-r--r--Include/opcode.h35
-rw-r--r--Lib/opcode.py1
-rw-r--r--Misc/NEWS.d/next/Core and Builtins/2022-12-16-08-50-16.gh-issue-100288.5XCk0G.rst1
-rw-r--r--Python/bytecodes.c25
-rw-r--r--Python/generated_cases.c.h25
-rw-r--r--Python/opcode_targets.h20
-rw-r--r--Python/specialize.c15
8 files changed, 43 insertions, 101 deletions
diff --git a/Include/internal/pycore_opcode.h b/Include/internal/pycore_opcode.h
index d702580..da8a272 100644
--- a/Include/internal/pycore_opcode.h
+++ b/Include/internal/pycore_opcode.h
@@ -152,7 +152,6 @@ const uint8_t _PyOpcode_Deopt[256] = {
[LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN] = LOAD_ATTR,
[LOAD_ATTR_INSTANCE_VALUE] = LOAD_ATTR,
[LOAD_ATTR_METHOD_LAZY_DICT] = LOAD_ATTR,
- [LOAD_ATTR_METHOD_MANAGED_DICT] = LOAD_ATTR,
[LOAD_ATTR_METHOD_NO_DICT] = LOAD_ATTR,
[LOAD_ATTR_METHOD_WITH_DICT] = LOAD_ATTR,
[LOAD_ATTR_METHOD_WITH_VALUES] = LOAD_ATTR,
@@ -314,12 +313,12 @@ static const char *const _PyOpcode_OpName[263] = {
[LOAD_ATTR_WITH_HINT] = "LOAD_ATTR_WITH_HINT",
[LOAD_ATTR_METHOD_LAZY_DICT] = "LOAD_ATTR_METHOD_LAZY_DICT",
[LOAD_ATTR_METHOD_NO_DICT] = "LOAD_ATTR_METHOD_NO_DICT",
- [LOAD_ATTR_METHOD_MANAGED_DICT] = "LOAD_ATTR_METHOD_MANAGED_DICT",
+ [LOAD_ATTR_METHOD_WITH_DICT] = "LOAD_ATTR_METHOD_WITH_DICT",
[LIST_TO_TUPLE] = "LIST_TO_TUPLE",
[RETURN_VALUE] = "RETURN_VALUE",
[IMPORT_STAR] = "IMPORT_STAR",
[SETUP_ANNOTATIONS] = "SETUP_ANNOTATIONS",
- [LOAD_ATTR_METHOD_WITH_DICT] = "LOAD_ATTR_METHOD_WITH_DICT",
+ [LOAD_ATTR_METHOD_WITH_VALUES] = "LOAD_ATTR_METHOD_WITH_VALUES",
[ASYNC_GEN_WRAP] = "ASYNC_GEN_WRAP",
[PREP_RERAISE_STAR] = "PREP_RERAISE_STAR",
[POP_EXCEPT] = "POP_EXCEPT",
@@ -346,7 +345,7 @@ static const char *const _PyOpcode_OpName[263] = {
[JUMP_FORWARD] = "JUMP_FORWARD",
[JUMP_IF_FALSE_OR_POP] = "JUMP_IF_FALSE_OR_POP",
[JUMP_IF_TRUE_OR_POP] = "JUMP_IF_TRUE_OR_POP",
- [LOAD_ATTR_METHOD_WITH_VALUES] = "LOAD_ATTR_METHOD_WITH_VALUES",
+ [LOAD_CONST__LOAD_FAST] = "LOAD_CONST__LOAD_FAST",
[POP_JUMP_IF_FALSE] = "POP_JUMP_IF_FALSE",
[POP_JUMP_IF_TRUE] = "POP_JUMP_IF_TRUE",
[LOAD_GLOBAL] = "LOAD_GLOBAL",
@@ -354,7 +353,7 @@ static const char *const _PyOpcode_OpName[263] = {
[CONTAINS_OP] = "CONTAINS_OP",
[RERAISE] = "RERAISE",
[COPY] = "COPY",
- [LOAD_CONST__LOAD_FAST] = "LOAD_CONST__LOAD_FAST",
+ [LOAD_FAST__LOAD_CONST] = "LOAD_FAST__LOAD_CONST",
[BINARY_OP] = "BINARY_OP",
[SEND] = "SEND",
[LOAD_FAST] = "LOAD_FAST",
@@ -374,9 +373,9 @@ static const char *const _PyOpcode_OpName[263] = {
[STORE_DEREF] = "STORE_DEREF",
[DELETE_DEREF] = "DELETE_DEREF",
[JUMP_BACKWARD] = "JUMP_BACKWARD",
- [LOAD_FAST__LOAD_CONST] = "LOAD_FAST__LOAD_CONST",
- [CALL_FUNCTION_EX] = "CALL_FUNCTION_EX",
[LOAD_FAST__LOAD_FAST] = "LOAD_FAST__LOAD_FAST",
+ [CALL_FUNCTION_EX] = "CALL_FUNCTION_EX",
+ [LOAD_GLOBAL_BUILTIN] = "LOAD_GLOBAL_BUILTIN",
[EXTENDED_ARG] = "EXTENDED_ARG",
[LIST_APPEND] = "LIST_APPEND",
[SET_ADD] = "SET_ADD",
@@ -386,27 +385,27 @@ static const char *const _PyOpcode_OpName[263] = {
[YIELD_VALUE] = "YIELD_VALUE",
[RESUME] = "RESUME",
[MATCH_CLASS] = "MATCH_CLASS",
- [LOAD_GLOBAL_BUILTIN] = "LOAD_GLOBAL_BUILTIN",
[LOAD_GLOBAL_MODULE] = "LOAD_GLOBAL_MODULE",
+ [STORE_ATTR_INSTANCE_VALUE] = "STORE_ATTR_INSTANCE_VALUE",
[FORMAT_VALUE] = "FORMAT_VALUE",
[BUILD_CONST_KEY_MAP] = "BUILD_CONST_KEY_MAP",
[BUILD_STRING] = "BUILD_STRING",
- [STORE_ATTR_INSTANCE_VALUE] = "STORE_ATTR_INSTANCE_VALUE",
[STORE_ATTR_SLOT] = "STORE_ATTR_SLOT",
[STORE_ATTR_WITH_HINT] = "STORE_ATTR_WITH_HINT",
[STORE_FAST__LOAD_FAST] = "STORE_FAST__LOAD_FAST",
+ [STORE_FAST__STORE_FAST] = "STORE_FAST__STORE_FAST",
[LIST_EXTEND] = "LIST_EXTEND",
[SET_UPDATE] = "SET_UPDATE",
[DICT_MERGE] = "DICT_MERGE",
[DICT_UPDATE] = "DICT_UPDATE",
- [STORE_FAST__STORE_FAST] = "STORE_FAST__STORE_FAST",
[STORE_SUBSCR_DICT] = "STORE_SUBSCR_DICT",
[STORE_SUBSCR_LIST_INT] = "STORE_SUBSCR_LIST_INT",
[UNPACK_SEQUENCE_LIST] = "UNPACK_SEQUENCE_LIST",
[UNPACK_SEQUENCE_TUPLE] = "UNPACK_SEQUENCE_TUPLE",
+ [UNPACK_SEQUENCE_TWO_TUPLE] = "UNPACK_SEQUENCE_TWO_TUPLE",
[CALL] = "CALL",
[KW_NAMES] = "KW_NAMES",
- [UNPACK_SEQUENCE_TWO_TUPLE] = "UNPACK_SEQUENCE_TWO_TUPLE",
+ [173] = "<173>",
[174] = "<174>",
[175] = "<175>",
[176] = "<176>",
@@ -500,6 +499,7 @@ static const char *const _PyOpcode_OpName[263] = {
#endif
#define EXTRA_CASES \
+ case 173: \
case 174: \
case 175: \
case 176: \
diff --git a/Include/opcode.h b/Include/opcode.h
index 088c1a5..888250e 100644
--- a/Include/opcode.h
+++ b/Include/opcode.h
@@ -174,24 +174,23 @@ extern "C" {
#define LOAD_ATTR_WITH_HINT 78
#define LOAD_ATTR_METHOD_LAZY_DICT 79
#define LOAD_ATTR_METHOD_NO_DICT 80
-#define LOAD_ATTR_METHOD_MANAGED_DICT 81
-#define LOAD_ATTR_METHOD_WITH_DICT 86
-#define LOAD_ATTR_METHOD_WITH_VALUES 113
-#define LOAD_CONST__LOAD_FAST 121
-#define LOAD_FAST__LOAD_CONST 141
-#define LOAD_FAST__LOAD_FAST 143
-#define LOAD_GLOBAL_BUILTIN 153
-#define LOAD_GLOBAL_MODULE 154
-#define STORE_ATTR_INSTANCE_VALUE 158
-#define STORE_ATTR_SLOT 159
-#define STORE_ATTR_WITH_HINT 160
-#define STORE_FAST__LOAD_FAST 161
-#define STORE_FAST__STORE_FAST 166
-#define STORE_SUBSCR_DICT 167
-#define STORE_SUBSCR_LIST_INT 168
-#define UNPACK_SEQUENCE_LIST 169
-#define UNPACK_SEQUENCE_TUPLE 170
-#define UNPACK_SEQUENCE_TWO_TUPLE 173
+#define LOAD_ATTR_METHOD_WITH_DICT 81
+#define LOAD_ATTR_METHOD_WITH_VALUES 86
+#define LOAD_CONST__LOAD_FAST 113
+#define LOAD_FAST__LOAD_CONST 121
+#define LOAD_FAST__LOAD_FAST 141
+#define LOAD_GLOBAL_BUILTIN 143
+#define LOAD_GLOBAL_MODULE 153
+#define STORE_ATTR_INSTANCE_VALUE 154
+#define STORE_ATTR_SLOT 158
+#define STORE_ATTR_WITH_HINT 159
+#define STORE_FAST__LOAD_FAST 160
+#define STORE_FAST__STORE_FAST 161
+#define STORE_SUBSCR_DICT 166
+#define STORE_SUBSCR_LIST_INT 167
+#define UNPACK_SEQUENCE_LIST 168
+#define UNPACK_SEQUENCE_TUPLE 169
+#define UNPACK_SEQUENCE_TWO_TUPLE 170
#define DO_TRACING 255
#define HAS_ARG(op) ((((op) >= HAVE_ARGUMENT) && (!IS_PSEUDO_OPCODE(op)))\
diff --git a/Lib/opcode.py b/Lib/opcode.py
index 59f368c..fc57aff 100644
--- a/Lib/opcode.py
+++ b/Lib/opcode.py
@@ -336,7 +336,6 @@ _specializations = {
# These will always push [unbound method, self] onto the stack.
"LOAD_ATTR_METHOD_LAZY_DICT",
"LOAD_ATTR_METHOD_NO_DICT",
- "LOAD_ATTR_METHOD_MANAGED_DICT",
"LOAD_ATTR_METHOD_WITH_DICT",
"LOAD_ATTR_METHOD_WITH_VALUES",
],
diff --git a/Misc/NEWS.d/next/Core and Builtins/2022-12-16-08-50-16.gh-issue-100288.5XCk0G.rst b/Misc/NEWS.d/next/Core and Builtins/2022-12-16-08-50-16.gh-issue-100288.5XCk0G.rst
deleted file mode 100644
index 4518210..0000000
--- a/Misc/NEWS.d/next/Core and Builtins/2022-12-16-08-50-16.gh-issue-100288.5XCk0G.rst
+++ /dev/null
@@ -1 +0,0 @@
-Specialize method loading for objects with ``Py_TPFLAGS_MANAGED_DICT`` set.
diff --git a/Python/bytecodes.c b/Python/bytecodes.c
index c2f6a7a..c0b625b 100644
--- a/Python/bytecodes.c
+++ b/Python/bytecodes.c
@@ -2718,31 +2718,6 @@ dummy_func(
}
// error: LOAD_ATTR has irregular stack effect
- inst(LOAD_ATTR_METHOD_MANAGED_DICT) {
- assert(cframe.use_tracing == 0);
- PyObject *self = TOP();
- PyTypeObject *self_cls = Py_TYPE(self);
- _PyLoadMethodCache *cache = (_PyLoadMethodCache *)next_instr;
- uint32_t type_version = read_u32(cache->type_version);
- assert(type_version != 0);
- DEOPT_IF(self_cls->tp_version_tag != type_version, LOAD_ATTR)
- assert(self_cls->tp_flags & Py_TPFLAGS_MANAGED_DICT);
- PyDictOrValues dorv = *_PyObject_DictOrValuesPointer(self);
- DEOPT_IF(_PyDictOrValues_IsValues(dorv), LOAD_ATTR);
- PyObject *dict = _PyDictOrValues_GetDict(dorv);
- PyDictKeysObject *keys = (dict == NULL) ? NULL : ((PyDictObject *)dict)->ma_keys;
- // Note: cache->keys_version can be 0 when dict is NULL.
- DEOPT_IF(keys != NULL && keys->dk_version != read_u32(cache->keys_version), LOAD_ATTR);
- STAT_INC(LOAD_ATTR, hit);
- PyObject *res = read_obj(cache->descr);
- assert(res != NULL);
- assert(_PyType_HasFeature(Py_TYPE(res), Py_TPFLAGS_METHOD_DESCRIPTOR));
- SET_TOP(Py_NewRef(res));
- PUSH(self);
- JUMPBY(INLINE_CACHE_ENTRIES_LOAD_ATTR);
- }
-
- // error: LOAD_ATTR has irregular stack effect
inst(LOAD_ATTR_METHOD_WITH_DICT) {
/* Can be either a managed dict, or a tp_dictoffset offset.*/
assert(cframe.use_tracing == 0);
diff --git a/Python/generated_cases.c.h b/Python/generated_cases.c.h
index 0012ba8..42b7ca0 100644
--- a/Python/generated_cases.c.h
+++ b/Python/generated_cases.c.h
@@ -2964,31 +2964,6 @@
DISPATCH();
}
- TARGET(LOAD_ATTR_METHOD_MANAGED_DICT) {
- assert(cframe.use_tracing == 0);
- PyObject *self = TOP();
- PyTypeObject *self_cls = Py_TYPE(self);
- _PyLoadMethodCache *cache = (_PyLoadMethodCache *)next_instr;
- uint32_t type_version = read_u32(cache->type_version);
- assert(type_version != 0);
- DEOPT_IF(self_cls->tp_version_tag != type_version, LOAD_ATTR)
- assert(self_cls->tp_flags & Py_TPFLAGS_MANAGED_DICT);
- PyDictOrValues dorv = *_PyObject_DictOrValuesPointer(self);
- DEOPT_IF(_PyDictOrValues_IsValues(dorv), LOAD_ATTR);
- PyObject *dict = _PyDictOrValues_GetDict(dorv);
- PyDictKeysObject *keys = (dict == NULL) ? NULL : ((PyDictObject *)dict)->ma_keys;
- // Note: cache->keys_version can be 0 when dict is NULL.
- DEOPT_IF(keys != NULL && keys->dk_version != read_u32(cache->keys_version), LOAD_ATTR);
- STAT_INC(LOAD_ATTR, hit);
- PyObject *res = read_obj(cache->descr);
- assert(res != NULL);
- assert(_PyType_HasFeature(Py_TYPE(res), Py_TPFLAGS_METHOD_DESCRIPTOR));
- SET_TOP(Py_NewRef(res));
- PUSH(self);
- JUMPBY(INLINE_CACHE_ENTRIES_LOAD_ATTR);
- DISPATCH();
- }
-
TARGET(LOAD_ATTR_METHOD_WITH_DICT) {
/* Can be either a managed dict, or a tp_dictoffset offset.*/
assert(cframe.use_tracing == 0);
diff --git a/Python/opcode_targets.h b/Python/opcode_targets.h
index 67f5bac..be3ad01 100644
--- a/Python/opcode_targets.h
+++ b/Python/opcode_targets.h
@@ -80,12 +80,12 @@ static void *opcode_targets[256] = {
&&TARGET_LOAD_ATTR_WITH_HINT,
&&TARGET_LOAD_ATTR_METHOD_LAZY_DICT,
&&TARGET_LOAD_ATTR_METHOD_NO_DICT,
- &&TARGET_LOAD_ATTR_METHOD_MANAGED_DICT,
+ &&TARGET_LOAD_ATTR_METHOD_WITH_DICT,
&&TARGET_LIST_TO_TUPLE,
&&TARGET_RETURN_VALUE,
&&TARGET_IMPORT_STAR,
&&TARGET_SETUP_ANNOTATIONS,
- &&TARGET_LOAD_ATTR_METHOD_WITH_DICT,
+ &&TARGET_LOAD_ATTR_METHOD_WITH_VALUES,
&&TARGET_ASYNC_GEN_WRAP,
&&TARGET_PREP_RERAISE_STAR,
&&TARGET_POP_EXCEPT,
@@ -112,7 +112,7 @@ static void *opcode_targets[256] = {
&&TARGET_JUMP_FORWARD,
&&TARGET_JUMP_IF_FALSE_OR_POP,
&&TARGET_JUMP_IF_TRUE_OR_POP,
- &&TARGET_LOAD_ATTR_METHOD_WITH_VALUES,
+ &&TARGET_LOAD_CONST__LOAD_FAST,
&&TARGET_POP_JUMP_IF_FALSE,
&&TARGET_POP_JUMP_IF_TRUE,
&&TARGET_LOAD_GLOBAL,
@@ -120,7 +120,7 @@ static void *opcode_targets[256] = {
&&TARGET_CONTAINS_OP,
&&TARGET_RERAISE,
&&TARGET_COPY,
- &&TARGET_LOAD_CONST__LOAD_FAST,
+ &&TARGET_LOAD_FAST__LOAD_CONST,
&&TARGET_BINARY_OP,
&&TARGET_SEND,
&&TARGET_LOAD_FAST,
@@ -140,9 +140,9 @@ static void *opcode_targets[256] = {
&&TARGET_STORE_DEREF,
&&TARGET_DELETE_DEREF,
&&TARGET_JUMP_BACKWARD,
- &&TARGET_LOAD_FAST__LOAD_CONST,
- &&TARGET_CALL_FUNCTION_EX,
&&TARGET_LOAD_FAST__LOAD_FAST,
+ &&TARGET_CALL_FUNCTION_EX,
+ &&TARGET_LOAD_GLOBAL_BUILTIN,
&&TARGET_EXTENDED_ARG,
&&TARGET_LIST_APPEND,
&&TARGET_SET_ADD,
@@ -152,27 +152,27 @@ static void *opcode_targets[256] = {
&&TARGET_YIELD_VALUE,
&&TARGET_RESUME,
&&TARGET_MATCH_CLASS,
- &&TARGET_LOAD_GLOBAL_BUILTIN,
&&TARGET_LOAD_GLOBAL_MODULE,
+ &&TARGET_STORE_ATTR_INSTANCE_VALUE,
&&TARGET_FORMAT_VALUE,
&&TARGET_BUILD_CONST_KEY_MAP,
&&TARGET_BUILD_STRING,
- &&TARGET_STORE_ATTR_INSTANCE_VALUE,
&&TARGET_STORE_ATTR_SLOT,
&&TARGET_STORE_ATTR_WITH_HINT,
&&TARGET_STORE_FAST__LOAD_FAST,
+ &&TARGET_STORE_FAST__STORE_FAST,
&&TARGET_LIST_EXTEND,
&&TARGET_SET_UPDATE,
&&TARGET_DICT_MERGE,
&&TARGET_DICT_UPDATE,
- &&TARGET_STORE_FAST__STORE_FAST,
&&TARGET_STORE_SUBSCR_DICT,
&&TARGET_STORE_SUBSCR_LIST_INT,
&&TARGET_UNPACK_SEQUENCE_LIST,
&&TARGET_UNPACK_SEQUENCE_TUPLE,
+ &&TARGET_UNPACK_SEQUENCE_TWO_TUPLE,
&&TARGET_CALL,
&&TARGET_KW_NAMES,
- &&TARGET_UNPACK_SEQUENCE_TWO_TUPLE,
+ &&_unknown_opcode,
&&_unknown_opcode,
&&_unknown_opcode,
&&_unknown_opcode,
diff --git a/Python/specialize.c b/Python/specialize.c
index 5321574..d9af7b7 100644
--- a/Python/specialize.c
+++ b/Python/specialize.c
@@ -335,6 +335,7 @@ _PyCode_Quicken(PyCodeObject *code)
#define SPEC_FAIL_ATTR_BUILTIN_CLASS_METHOD 22
#define SPEC_FAIL_ATTR_CLASS_METHOD_OBJ 23
#define SPEC_FAIL_ATTR_OBJECT_SLOT 24
+#define SPEC_FAIL_ATTR_HAS_MANAGED_DICT 25
#define SPEC_FAIL_ATTR_INSTANCE_ATTRIBUTE 26
#define SPEC_FAIL_ATTR_METACLASS_ATTRIBUTE 27
#define SPEC_FAIL_ATTR_PROPERTY_NOT_PY_FUNCTION 28
@@ -1035,14 +1036,11 @@ PyObject *descr, DescriptorClassification kind)
PyDictKeysObject *keys;
if (owner_cls->tp_flags & Py_TPFLAGS_MANAGED_DICT) {
PyDictOrValues dorv = *_PyObject_DictOrValuesPointer(owner);
+ keys = ((PyHeapTypeObject *)owner_cls)->ht_cached_keys;
if (_PyDictOrValues_IsValues(dorv)) {
- keys = ((PyHeapTypeObject *)owner_cls)->ht_cached_keys;
dictkind = MANAGED_VALUES;
}
else {
- PyDictObject *dict = (PyDictObject *)_PyDictOrValues_GetDict(dorv);
- keys = dict != NULL ? dict->ma_keys : NULL;
- // User has directly accessed __dict__.
dictkind = MANAGED_DICT;
}
}
@@ -1069,7 +1067,7 @@ PyObject *descr, DescriptorClassification kind)
}
}
}
- if (dictkind == MANAGED_VALUES || dictkind == OFFSET_DICT || (dictkind == MANAGED_DICT && keys != NULL)) {
+ if (dictkind == MANAGED_VALUES || dictkind == OFFSET_DICT) {
Py_ssize_t index = _PyDictKeys_StringLookup(keys, name);
if (index != DKIX_EMPTY) {
SPECIALIZATION_FAIL(LOAD_ATTR, SPEC_FAIL_ATTR_SHADOWED);
@@ -1090,11 +1088,8 @@ PyObject *descr, DescriptorClassification kind)
_py_set_opcode(instr, LOAD_ATTR_METHOD_WITH_VALUES);
break;
case MANAGED_DICT:
- if (keys == NULL) {
- write_u32(cache->keys_version, 0);
- }
- _py_set_opcode(instr, LOAD_ATTR_METHOD_MANAGED_DICT);
- break;
+ SPECIALIZATION_FAIL(LOAD_ATTR, SPEC_FAIL_ATTR_HAS_MANAGED_DICT);
+ goto fail;
case OFFSET_DICT:
assert(owner_cls->tp_dictoffset > 0 && owner_cls->tp_dictoffset <= INT16_MAX);
_py_set_opcode(instr, LOAD_ATTR_METHOD_WITH_DICT);