Skip to content

Commit 99daf59

Browse files
committed
Modernize LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN
1 parent d54c622 commit 99daf59

File tree

3 files changed

+11
-16
lines changed

3 files changed

+11
-16
lines changed

Python/bytecodes.c

+3-8
Original file line numberDiff line numberDiff line change
@@ -1444,7 +1444,7 @@ dummy_func(
14441444
LOAD_ATTR_SLOT,
14451445
LOAD_ATTR_CLASS,
14461446
LOAD_ATTR_PROPERTY,
1447-
// LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN,
1447+
LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN,
14481448
// LOAD_ATTR_METHOD_WITH_VALUES,
14491449
// LOAD_ATTR_METHOD_NO_DICT,
14501450
// LOAD_ATTR_METHOD_LAZY_DICT,
@@ -1620,20 +1620,14 @@ dummy_func(
16201620
DISPATCH_INLINED(new_frame);
16211621
}
16221622

1623-
// error: LOAD_ATTR has irregular stack effect
1624-
inst(LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN) {
1623+
inst(LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN, (unused/1, type_version/2, func_version/2, getattribute/4, owner -- unused if (oparg & 1), unused)) {
16251624
assert(cframe.use_tracing == 0);
16261625
DEOPT_IF(tstate->interp->eval_frame, LOAD_ATTR);
1627-
_PyLoadMethodCache *cache = (_PyLoadMethodCache *)next_instr;
1628-
PyObject *owner = TOP();
16291626
PyTypeObject *cls = Py_TYPE(owner);
1630-
uint32_t type_version = read_u32(cache->type_version);
16311627
DEOPT_IF(cls->tp_version_tag != type_version, LOAD_ATTR);
16321628
assert(type_version != 0);
1633-
PyObject *getattribute = read_obj(cache->descr);
16341629
assert(Py_IS_TYPE(getattribute, &PyFunction_Type));
16351630
PyFunctionObject *f = (PyFunctionObject *)getattribute;
1636-
uint32_t func_version = read_u32(cache->keys_version);
16371631
assert(func_version != 0);
16381632
DEOPT_IF(f->func_version != func_version, LOAD_ATTR);
16391633
PyCodeObject *code = (PyCodeObject *)f->func_code;
@@ -1644,6 +1638,7 @@ dummy_func(
16441638
PyObject *name = GETITEM(names, oparg >> 1);
16451639
Py_INCREF(f);
16461640
_PyInterpreterFrame *new_frame = _PyFrame_PushUnchecked(tstate, f, 2);
1641+
// Manipulate stack directly because we exit with DISPATCH_INLINED().
16471642
SET_TOP(NULL);
16481643
int shrink_stack = !(oparg & 1);
16491644
STACK_SHRINK(shrink_stack);

Python/generated_cases.c.h

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

Python/opcode_metadata.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ _PyOpcode_num_popped(int opcode, int oparg) {
199199
case LOAD_ATTR_PROPERTY:
200200
return 1;
201201
case LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN:
202-
return -1;
202+
return 1;
203203
case STORE_ATTR_INSTANCE_VALUE:
204204
return 2;
205205
case STORE_ATTR_WITH_HINT:
@@ -545,7 +545,7 @@ _PyOpcode_num_pushed(int opcode, int oparg) {
545545
case LOAD_ATTR_PROPERTY:
546546
return ((oparg & 1) ? 1 : 0) + 1;
547547
case LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN:
548-
return -1;
548+
return ((oparg & 1) ? 1 : 0) + 1;
549549
case STORE_ATTR_INSTANCE_VALUE:
550550
return 0;
551551
case STORE_ATTR_WITH_HINT:
@@ -798,7 +798,7 @@ struct opcode_metadata {
798798
[LOAD_ATTR_SLOT] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IBC00000000 },
799799
[LOAD_ATTR_CLASS] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IBC00000000 },
800800
[LOAD_ATTR_PROPERTY] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IBC00000000 },
801-
[LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IB },
801+
[LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IBC00000000 },
802802
[STORE_ATTR_INSTANCE_VALUE] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IXC000 },
803803
[STORE_ATTR_WITH_HINT] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IBC000 },
804804
[STORE_ATTR_SLOT] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IXC000 },

0 commit comments

Comments
 (0)