Skip to content

Commit d54c622

Browse files
committed
Modernize LOAD_ATTR_PROPERTY
1 parent 6a2cc83 commit d54c622

File tree

3 files changed

+11
-16
lines changed

3 files changed

+11
-16
lines changed

Python/bytecodes.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1443,7 +1443,7 @@ dummy_func(
14431443
LOAD_ATTR_WITH_HINT,
14441444
LOAD_ATTR_SLOT,
14451445
LOAD_ATTR_CLASS,
1446-
// LOAD_ATTR_PROPERTY,
1446+
LOAD_ATTR_PROPERTY,
14471447
// LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN,
14481448
// LOAD_ATTR_METHOD_WITH_VALUES,
14491449
// LOAD_ATTR_METHOD_NO_DICT,
@@ -1594,21 +1594,15 @@ dummy_func(
15941594
Py_DECREF(cls);
15951595
}
15961596

1597-
// error: LOAD_ATTR has irregular stack effect
1598-
inst(LOAD_ATTR_PROPERTY) {
1597+
inst(LOAD_ATTR_PROPERTY, (unused/1, type_version/2, func_version/2, fget/4, owner -- unused if (oparg & 1), unused)) {
15991598
assert(cframe.use_tracing == 0);
16001599
DEOPT_IF(tstate->interp->eval_frame, LOAD_ATTR);
1601-
_PyLoadMethodCache *cache = (_PyLoadMethodCache *)next_instr;
16021600

1603-
PyObject *owner = TOP();
16041601
PyTypeObject *cls = Py_TYPE(owner);
1605-
uint32_t type_version = read_u32(cache->type_version);
16061602
DEOPT_IF(cls->tp_version_tag != type_version, LOAD_ATTR);
16071603
assert(type_version != 0);
1608-
PyObject *fget = read_obj(cache->descr);
16091604
assert(Py_IS_TYPE(fget, &PyFunction_Type));
16101605
PyFunctionObject *f = (PyFunctionObject *)fget;
1611-
uint32_t func_version = read_u32(cache->keys_version);
16121606
assert(func_version != 0);
16131607
DEOPT_IF(f->func_version != func_version, LOAD_ATTR);
16141608
PyCodeObject *code = (PyCodeObject *)f->func_code;
@@ -1617,6 +1611,7 @@ dummy_func(
16171611
STAT_INC(LOAD_ATTR, hit);
16181612
Py_INCREF(fget);
16191613
_PyInterpreterFrame *new_frame = _PyFrame_PushUnchecked(tstate, f, 1);
1614+
// Manipulate stack directly because we exit with DISPATCH_INLINED().
16201615
SET_TOP(NULL);
16211616
int shrink_stack = !(oparg & 1);
16221617
STACK_SHRINK(shrink_stack);

Python/generated_cases.c.h

Lines changed: 5 additions & 5 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
@@ -197,7 +197,7 @@ _PyOpcode_num_popped(int opcode, int oparg) {
197197
case LOAD_ATTR_CLASS:
198198
return 1;
199199
case LOAD_ATTR_PROPERTY:
200-
return -1;
200+
return 1;
201201
case LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN:
202202
return -1;
203203
case STORE_ATTR_INSTANCE_VALUE:
@@ -543,7 +543,7 @@ _PyOpcode_num_pushed(int opcode, int oparg) {
543543
case LOAD_ATTR_CLASS:
544544
return ((oparg & 1) ? 1 : 0) + 1;
545545
case LOAD_ATTR_PROPERTY:
546-
return -1;
546+
return ((oparg & 1) ? 1 : 0) + 1;
547547
case LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN:
548548
return -1;
549549
case STORE_ATTR_INSTANCE_VALUE:
@@ -797,7 +797,7 @@ struct opcode_metadata {
797797
[LOAD_ATTR_WITH_HINT] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IBC00000000 },
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 },
800-
[LOAD_ATTR_PROPERTY] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IB },
800+
[LOAD_ATTR_PROPERTY] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IBC00000000 },
801801
[LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IB },
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 },

0 commit comments

Comments
 (0)