Skip to content

Commit 36d3583

Browse files
Revert "gh-100288: Specialise LOAD_ATTR_METHOD for managed dictionaries (GH-100289)" (#100468)
This reverts commit c3c7848.
1 parent c3c7848 commit 36d3583

File tree

8 files changed

+43
-101
lines changed

8 files changed

+43
-101
lines changed

Include/internal/pycore_opcode.h

+11-11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/opcode.h

+17-18
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Lib/opcode.py

-1
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,6 @@ def pseudo_op(name, op, real_ops):
336336
# These will always push [unbound method, self] onto the stack.
337337
"LOAD_ATTR_METHOD_LAZY_DICT",
338338
"LOAD_ATTR_METHOD_NO_DICT",
339-
"LOAD_ATTR_METHOD_MANAGED_DICT",
340339
"LOAD_ATTR_METHOD_WITH_DICT",
341340
"LOAD_ATTR_METHOD_WITH_VALUES",
342341
],

Misc/NEWS.d/next/Core and Builtins/2022-12-16-08-50-16.gh-issue-100288.5XCk0G.rst

-1
This file was deleted.

Python/bytecodes.c

-25
Original file line numberDiff line numberDiff line change
@@ -2717,31 +2717,6 @@ dummy_func(
27172717
JUMPBY(INLINE_CACHE_ENTRIES_LOAD_ATTR);
27182718
}
27192719

2720-
// error: LOAD_ATTR has irregular stack effect
2721-
inst(LOAD_ATTR_METHOD_MANAGED_DICT) {
2722-
assert(cframe.use_tracing == 0);
2723-
PyObject *self = TOP();
2724-
PyTypeObject *self_cls = Py_TYPE(self);
2725-
_PyLoadMethodCache *cache = (_PyLoadMethodCache *)next_instr;
2726-
uint32_t type_version = read_u32(cache->type_version);
2727-
assert(type_version != 0);
2728-
DEOPT_IF(self_cls->tp_version_tag != type_version, LOAD_ATTR)
2729-
assert(self_cls->tp_flags & Py_TPFLAGS_MANAGED_DICT);
2730-
PyDictOrValues dorv = *_PyObject_DictOrValuesPointer(self);
2731-
DEOPT_IF(_PyDictOrValues_IsValues(dorv), LOAD_ATTR);
2732-
PyObject *dict = _PyDictOrValues_GetDict(dorv);
2733-
PyDictKeysObject *keys = (dict == NULL) ? NULL : ((PyDictObject *)dict)->ma_keys;
2734-
// Note: cache->keys_version can be 0 when dict is NULL.
2735-
DEOPT_IF(keys != NULL && keys->dk_version != read_u32(cache->keys_version), LOAD_ATTR);
2736-
STAT_INC(LOAD_ATTR, hit);
2737-
PyObject *res = read_obj(cache->descr);
2738-
assert(res != NULL);
2739-
assert(_PyType_HasFeature(Py_TYPE(res), Py_TPFLAGS_METHOD_DESCRIPTOR));
2740-
SET_TOP(Py_NewRef(res));
2741-
PUSH(self);
2742-
JUMPBY(INLINE_CACHE_ENTRIES_LOAD_ATTR);
2743-
}
2744-
27452720
// error: LOAD_ATTR has irregular stack effect
27462721
inst(LOAD_ATTR_METHOD_WITH_DICT) {
27472722
/* Can be either a managed dict, or a tp_dictoffset offset.*/

Python/generated_cases.c.h

-25
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/opcode_targets.h

+10-10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/specialize.c

+5-10
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ _PyCode_Quicken(PyCodeObject *code)
335335
#define SPEC_FAIL_ATTR_BUILTIN_CLASS_METHOD 22
336336
#define SPEC_FAIL_ATTR_CLASS_METHOD_OBJ 23
337337
#define SPEC_FAIL_ATTR_OBJECT_SLOT 24
338+
#define SPEC_FAIL_ATTR_HAS_MANAGED_DICT 25
338339
#define SPEC_FAIL_ATTR_INSTANCE_ATTRIBUTE 26
339340
#define SPEC_FAIL_ATTR_METACLASS_ATTRIBUTE 27
340341
#define SPEC_FAIL_ATTR_PROPERTY_NOT_PY_FUNCTION 28
@@ -1035,14 +1036,11 @@ PyObject *descr, DescriptorClassification kind)
10351036
PyDictKeysObject *keys;
10361037
if (owner_cls->tp_flags & Py_TPFLAGS_MANAGED_DICT) {
10371038
PyDictOrValues dorv = *_PyObject_DictOrValuesPointer(owner);
1039+
keys = ((PyHeapTypeObject *)owner_cls)->ht_cached_keys;
10381040
if (_PyDictOrValues_IsValues(dorv)) {
1039-
keys = ((PyHeapTypeObject *)owner_cls)->ht_cached_keys;
10401041
dictkind = MANAGED_VALUES;
10411042
}
10421043
else {
1043-
PyDictObject *dict = (PyDictObject *)_PyDictOrValues_GetDict(dorv);
1044-
keys = dict != NULL ? dict->ma_keys : NULL;
1045-
// User has directly accessed __dict__.
10461044
dictkind = MANAGED_DICT;
10471045
}
10481046
}
@@ -1069,7 +1067,7 @@ PyObject *descr, DescriptorClassification kind)
10691067
}
10701068
}
10711069
}
1072-
if (dictkind == MANAGED_VALUES || dictkind == OFFSET_DICT || (dictkind == MANAGED_DICT && keys != NULL)) {
1070+
if (dictkind == MANAGED_VALUES || dictkind == OFFSET_DICT) {
10731071
Py_ssize_t index = _PyDictKeys_StringLookup(keys, name);
10741072
if (index != DKIX_EMPTY) {
10751073
SPECIALIZATION_FAIL(LOAD_ATTR, SPEC_FAIL_ATTR_SHADOWED);
@@ -1090,11 +1088,8 @@ PyObject *descr, DescriptorClassification kind)
10901088
_py_set_opcode(instr, LOAD_ATTR_METHOD_WITH_VALUES);
10911089
break;
10921090
case MANAGED_DICT:
1093-
if (keys == NULL) {
1094-
write_u32(cache->keys_version, 0);
1095-
}
1096-
_py_set_opcode(instr, LOAD_ATTR_METHOD_MANAGED_DICT);
1097-
break;
1091+
SPECIALIZATION_FAIL(LOAD_ATTR, SPEC_FAIL_ATTR_HAS_MANAGED_DICT);
1092+
goto fail;
10981093
case OFFSET_DICT:
10991094
assert(owner_cls->tp_dictoffset > 0 && owner_cls->tp_dictoffset <= INT16_MAX);
11001095
_py_set_opcode(instr, LOAD_ATTR_METHOD_WITH_DICT);

0 commit comments

Comments
 (0)