Skip to content
Prev Previous commit
Next Next commit
Modernize LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN
  • Loading branch information
gvanrossum committed Feb 1, 2023
commit d44375383408c854fee7d03da77c1edcf71147c9
11 changes: 3 additions & 8 deletions Python/bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -1444,7 +1444,7 @@ dummy_func(
LOAD_ATTR_SLOT,
LOAD_ATTR_CLASS,
LOAD_ATTR_PROPERTY,
// LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN,
LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN,
// LOAD_ATTR_METHOD_WITH_VALUES,
// LOAD_ATTR_METHOD_NO_DICT,
// LOAD_ATTR_METHOD_LAZY_DICT,
Expand Down Expand Up @@ -1620,20 +1620,14 @@ dummy_func(
DISPATCH_INLINED(new_frame);
}

// error: LOAD_ATTR has irregular stack effect
inst(LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN) {
inst(LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN, (unused/1, type_version/2, func_version/2, getattribute/4, owner -- unused if (oparg & 1), unused)) {
assert(cframe.use_tracing == 0);
DEOPT_IF(tstate->interp->eval_frame, LOAD_ATTR);
_PyLoadMethodCache *cache = (_PyLoadMethodCache *)next_instr;
PyObject *owner = TOP();
PyTypeObject *cls = Py_TYPE(owner);
uint32_t type_version = read_u32(cache->type_version);
DEOPT_IF(cls->tp_version_tag != type_version, LOAD_ATTR);
assert(type_version != 0);
PyObject *getattribute = read_obj(cache->descr);
assert(Py_IS_TYPE(getattribute, &PyFunction_Type));
PyFunctionObject *f = (PyFunctionObject *)getattribute;
uint32_t func_version = read_u32(cache->keys_version);
assert(func_version != 0);
DEOPT_IF(f->func_version != func_version, LOAD_ATTR);
PyCodeObject *code = (PyCodeObject *)f->func_code;
Expand All @@ -1644,6 +1638,7 @@ dummy_func(
PyObject *name = GETITEM(names, oparg >> 1);
Py_INCREF(f);
_PyInterpreterFrame *new_frame = _PyFrame_PushUnchecked(tstate, f, 2);
// Manipulate stack directly because we exit with DISPATCH_INLINED().
SET_TOP(NULL);
int shrink_stack = !(oparg & 1);
STACK_SHRINK(shrink_stack);
Expand Down
10 changes: 5 additions & 5 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 @@ -199,7 +199,7 @@ _PyOpcode_num_popped(int opcode, int oparg) {
case LOAD_ATTR_PROPERTY:
return 1;
case LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN:
return -1;
return 1;
case STORE_ATTR_INSTANCE_VALUE:
return 2;
case STORE_ATTR_WITH_HINT:
Expand Down Expand Up @@ -545,7 +545,7 @@ _PyOpcode_num_pushed(int opcode, int oparg) {
case LOAD_ATTR_PROPERTY:
return ((oparg & 1) ? 1 : 0) + 1;
case LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN:
return -1;
return ((oparg & 1) ? 1 : 0) + 1;
case STORE_ATTR_INSTANCE_VALUE:
return 0;
case STORE_ATTR_WITH_HINT:
Expand Down Expand Up @@ -798,7 +798,7 @@ struct opcode_metadata {
[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_IBC00000000 },
[LOAD_ATTR_PROPERTY] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IBC00000000 },
[LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IB },
[LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IBC00000000 },
[STORE_ATTR_INSTANCE_VALUE] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IXC000 },
[STORE_ATTR_WITH_HINT] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IBC000 },
[STORE_ATTR_SLOT] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IXC000 },
Expand Down