Skip to content
Prev Previous commit
Next Next commit
Modernize LOAD_ATTR_CLASS
  • Loading branch information
gvanrossum committed Feb 1, 2023
commit f0bd9efa9bba416d6baf0f57339c0b752e0166c6
15 changes: 4 additions & 11 deletions Python/bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -1442,7 +1442,7 @@ dummy_func(
LOAD_ATTR_MODULE,
LOAD_ATTR_WITH_HINT,
LOAD_ATTR_SLOT,
// LOAD_ATTR_CLASS,
LOAD_ATTR_CLASS,
// LOAD_ATTR_PROPERTY,
// LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN,
// LOAD_ATTR_METHOD_WITH_VALUES,
Expand Down Expand Up @@ -1578,27 +1578,20 @@ dummy_func(
Py_DECREF(owner);
}

// error: LOAD_ATTR has irregular stack effect
inst(LOAD_ATTR_CLASS) {
inst(LOAD_ATTR_CLASS, (unused/1, type_version/2, unused/2, descr/4, cls -- res2 if (oparg & 1), res)) {
assert(cframe.use_tracing == 0);
_PyLoadMethodCache *cache = (_PyLoadMethodCache *)next_instr;

PyObject *cls = TOP();
DEOPT_IF(!PyType_Check(cls), LOAD_ATTR);
uint32_t type_version = read_u32(cache->type_version);
DEOPT_IF(((PyTypeObject *)cls)->tp_version_tag != type_version,
LOAD_ATTR);
assert(type_version != 0);

STAT_INC(LOAD_ATTR, hit);
PyObject *res = read_obj(cache->descr);
res2 = NULL;
res = descr;
assert(res != NULL);
Py_INCREF(res);
SET_TOP(NULL);
STACK_GROW((oparg & 1));
SET_TOP(res);
Py_DECREF(cls);
JUMPBY(INLINE_CACHE_ENTRIES_LOAD_ATTR);
}

// error: LOAD_ATTR has irregular stack effect
Expand Down
19 changes: 11 additions & 8 deletions Python/generated_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Python/opcode_metadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ _PyOpcode_num_popped(int opcode, int oparg) {
case LOAD_ATTR_SLOT:
return 1;
case LOAD_ATTR_CLASS:
return -1;
return 1;
case LOAD_ATTR_PROPERTY:
return -1;
case LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN:
Expand Down Expand Up @@ -541,7 +541,7 @@ _PyOpcode_num_pushed(int opcode, int oparg) {
case LOAD_ATTR_SLOT:
return ((oparg & 1) ? 1 : 0) + 1;
case LOAD_ATTR_CLASS:
return -1;
return ((oparg & 1) ? 1 : 0) + 1;
case LOAD_ATTR_PROPERTY:
return -1;
case LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN:
Expand Down Expand Up @@ -796,7 +796,7 @@ struct opcode_metadata {
[LOAD_ATTR_MODULE] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IBC00000000 },
[LOAD_ATTR_WITH_HINT] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IBC00000000 },
[LOAD_ATTR_SLOT] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IBC00000000 },
[LOAD_ATTR_CLASS] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IB },
[LOAD_ATTR_CLASS] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IBC00000000 },
[LOAD_ATTR_PROPERTY] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IB },
[LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IB },
[STORE_ATTR_INSTANCE_VALUE] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IXC000 },
Expand Down