Skip to content

Commit 5690007

Browse files
committed
Modernize LOAD_ATTR_METHOD_NO_DICT
1 parent e99ba6d commit 5690007

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
@@ -1446,7 +1446,7 @@ dummy_func(
14461446
LOAD_ATTR_PROPERTY,
14471447
LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN,
14481448
LOAD_ATTR_METHOD_WITH_VALUES,
1449-
// LOAD_ATTR_METHOD_NO_DICT,
1449+
LOAD_ATTR_METHOD_NO_DICT,
14501450
// LOAD_ATTR_METHOD_LAZY_DICT,
14511451
};
14521452

@@ -2359,22 +2359,17 @@ dummy_func(
23592359
assert(oparg & 1);
23602360
}
23612361

2362-
// error: LOAD_ATTR has irregular stack effect
2363-
inst(LOAD_ATTR_METHOD_NO_DICT) {
2362+
inst(LOAD_ATTR_METHOD_NO_DICT, (unused/1, type_version/2, unused/2, descr/4, self -- res2 if (oparg & 1), res)) {
23642363
assert(cframe.use_tracing == 0);
2365-
PyObject *self = TOP();
23662364
PyTypeObject *self_cls = Py_TYPE(self);
2367-
_PyLoadMethodCache *cache = (_PyLoadMethodCache *)next_instr;
2368-
uint32_t type_version = read_u32(cache->type_version);
23692365
DEOPT_IF(self_cls->tp_version_tag != type_version, LOAD_ATTR);
23702366
assert(self_cls->tp_dictoffset == 0);
23712367
STAT_INC(LOAD_ATTR, hit);
2372-
PyObject *res = read_obj(cache->descr);
2373-
assert(res != NULL);
2374-
assert(_PyType_HasFeature(Py_TYPE(res), Py_TPFLAGS_METHOD_DESCRIPTOR));
2375-
SET_TOP(Py_NewRef(res));
2376-
PUSH(self);
2377-
JUMPBY(INLINE_CACHE_ENTRIES_LOAD_ATTR);
2368+
assert(descr != NULL);
2369+
assert(_PyType_HasFeature(Py_TYPE(descr), Py_TPFLAGS_METHOD_DESCRIPTOR));
2370+
res2 = Py_NewRef(descr);
2371+
res = self;
2372+
assert(oparg & 1);
23782373
}
23792374

23802375
// error: LOAD_ATTR has irregular stack effect

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
@@ -281,7 +281,7 @@ _PyOpcode_num_popped(int opcode, int oparg) {
281281
case LOAD_ATTR_METHOD_WITH_VALUES:
282282
return 1;
283283
case LOAD_ATTR_METHOD_NO_DICT:
284-
return -1;
284+
return 1;
285285
case LOAD_ATTR_METHOD_LAZY_DICT:
286286
return -1;
287287
case CALL_BOUND_METHOD_EXACT_ARGS:
@@ -627,7 +627,7 @@ _PyOpcode_num_pushed(int opcode, int oparg) {
627627
case LOAD_ATTR_METHOD_WITH_VALUES:
628628
return ((oparg & 1) ? 1 : 0) + 1;
629629
case LOAD_ATTR_METHOD_NO_DICT:
630-
return -1;
630+
return ((oparg & 1) ? 1 : 0) + 1;
631631
case LOAD_ATTR_METHOD_LAZY_DICT:
632632
return -1;
633633
case CALL_BOUND_METHOD_EXACT_ARGS:
@@ -839,7 +839,7 @@ struct opcode_metadata {
839839
[WITH_EXCEPT_START] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IX },
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 },
842-
[LOAD_ATTR_METHOD_NO_DICT] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IX },
842+
[LOAD_ATTR_METHOD_NO_DICT] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IBC00000000 },
843843
[LOAD_ATTR_METHOD_LAZY_DICT] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IX },
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 },

0 commit comments

Comments
 (0)