Skip to content

Commit 02b8183

Browse files
committed
Modernize LOAD_ATTR_METHOD_LAZY_DICT
This concludes the LOAD_ATTR family.
1 parent 5690007 commit 02b8183

File tree

3 files changed

+24
-24
lines changed

3 files changed

+24
-24
lines changed

Python/bytecodes.c

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1447,7 +1447,7 @@ dummy_func(
14471447
LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN,
14481448
LOAD_ATTR_METHOD_WITH_VALUES,
14491449
LOAD_ATTR_METHOD_NO_DICT,
1450-
// LOAD_ATTR_METHOD_LAZY_DICT,
1450+
LOAD_ATTR_METHOD_LAZY_DICT,
14511451
};
14521452

14531453
inst(LOAD_ATTR, (unused/9, owner -- res2 if (oparg & 1), res)) {
@@ -2372,26 +2372,21 @@ dummy_func(
23722372
assert(oparg & 1);
23732373
}
23742374

2375-
// error: LOAD_ATTR has irregular stack effect
2376-
inst(LOAD_ATTR_METHOD_LAZY_DICT) {
2375+
inst(LOAD_ATTR_METHOD_LAZY_DICT, (unused/1, type_version/2, unused/2, descr/4, self -- res2 if (oparg & 1), res)) {
23772376
assert(cframe.use_tracing == 0);
2378-
PyObject *self = TOP();
23792377
PyTypeObject *self_cls = Py_TYPE(self);
2380-
_PyLoadMethodCache *cache = (_PyLoadMethodCache *)next_instr;
2381-
uint32_t type_version = read_u32(cache->type_version);
23822378
DEOPT_IF(self_cls->tp_version_tag != type_version, LOAD_ATTR);
23832379
Py_ssize_t dictoffset = self_cls->tp_dictoffset;
23842380
assert(dictoffset > 0);
23852381
PyObject *dict = *(PyObject **)((char *)self + dictoffset);
23862382
/* This object has a __dict__, just not yet created */
23872383
DEOPT_IF(dict != NULL, LOAD_ATTR);
23882384
STAT_INC(LOAD_ATTR, hit);
2389-
PyObject *res = read_obj(cache->descr);
2390-
assert(res != NULL);
2391-
assert(_PyType_HasFeature(Py_TYPE(res), Py_TPFLAGS_METHOD_DESCRIPTOR));
2392-
SET_TOP(Py_NewRef(res));
2393-
PUSH(self);
2394-
JUMPBY(INLINE_CACHE_ENTRIES_LOAD_ATTR);
2385+
assert(descr != NULL);
2386+
assert(_PyType_HasFeature(Py_TYPE(descr), Py_TPFLAGS_METHOD_DESCRIPTOR));
2387+
res2 = Py_NewRef(descr);
2388+
res = self;
2389+
assert(oparg & 1);
23952390
}
23962391

23972392
// stack effect: (__0, __array[oparg] -- )

Python/generated_cases.c.h

Lines changed: 14 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/opcode_metadata.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ _PyOpcode_num_popped(int opcode, int oparg) {
283283
case LOAD_ATTR_METHOD_NO_DICT:
284284
return 1;
285285
case LOAD_ATTR_METHOD_LAZY_DICT:
286-
return -1;
286+
return 1;
287287
case CALL_BOUND_METHOD_EXACT_ARGS:
288288
return -1;
289289
case KW_NAMES:
@@ -629,7 +629,7 @@ _PyOpcode_num_pushed(int opcode, int oparg) {
629629
case LOAD_ATTR_METHOD_NO_DICT:
630630
return ((oparg & 1) ? 1 : 0) + 1;
631631
case LOAD_ATTR_METHOD_LAZY_DICT:
632-
return -1;
632+
return ((oparg & 1) ? 1 : 0) + 1;
633633
case CALL_BOUND_METHOD_EXACT_ARGS:
634634
return -1;
635635
case KW_NAMES:
@@ -840,7 +840,7 @@ struct opcode_metadata {
840840
[PUSH_EXC_INFO] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IX },
841841
[LOAD_ATTR_METHOD_WITH_VALUES] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IBC00000000 },
842842
[LOAD_ATTR_METHOD_NO_DICT] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IBC00000000 },
843-
[LOAD_ATTR_METHOD_LAZY_DICT] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IX },
843+
[LOAD_ATTR_METHOD_LAZY_DICT] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IBC00000000 },
844844
[CALL_BOUND_METHOD_EXACT_ARGS] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IB },
845845
[KW_NAMES] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IB },
846846
[CALL] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IB },

0 commit comments

Comments
 (0)