Skip to content

Commit 6a2cc83

Browse files
committed
Modernize LOAD_ATTR_CLASS
1 parent 60b4fbd commit 6a2cc83

File tree

3 files changed

+18
-22
lines changed

3 files changed

+18
-22
lines changed

Python/bytecodes.c

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1442,7 +1442,7 @@ dummy_func(
14421442
LOAD_ATTR_MODULE,
14431443
LOAD_ATTR_WITH_HINT,
14441444
LOAD_ATTR_SLOT,
1445-
// LOAD_ATTR_CLASS,
1445+
LOAD_ATTR_CLASS,
14461446
// LOAD_ATTR_PROPERTY,
14471447
// LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN,
14481448
// LOAD_ATTR_METHOD_WITH_VALUES,
@@ -1578,27 +1578,20 @@ dummy_func(
15781578
Py_DECREF(owner);
15791579
}
15801580

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

1586-
PyObject *cls = TOP();
15871584
DEOPT_IF(!PyType_Check(cls), LOAD_ATTR);
1588-
uint32_t type_version = read_u32(cache->type_version);
15891585
DEOPT_IF(((PyTypeObject *)cls)->tp_version_tag != type_version,
15901586
LOAD_ATTR);
15911587
assert(type_version != 0);
15921588

15931589
STAT_INC(LOAD_ATTR, hit);
1594-
PyObject *res = read_obj(cache->descr);
1590+
res2 = NULL;
1591+
res = descr;
15951592
assert(res != NULL);
15961593
Py_INCREF(res);
1597-
SET_TOP(NULL);
1598-
STACK_GROW((oparg & 1));
1599-
SET_TOP(res);
16001594
Py_DECREF(cls);
1601-
JUMPBY(INLINE_CACHE_ENTRIES_LOAD_ATTR);
16021595
}
16031596

16041597
// error: LOAD_ATTR has irregular stack effect

Python/generated_cases.c.h

Lines changed: 11 additions & 8 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
@@ -195,7 +195,7 @@ _PyOpcode_num_popped(int opcode, int oparg) {
195195
case LOAD_ATTR_SLOT:
196196
return 1;
197197
case LOAD_ATTR_CLASS:
198-
return -1;
198+
return 1;
199199
case LOAD_ATTR_PROPERTY:
200200
return -1;
201201
case LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN:
@@ -541,7 +541,7 @@ _PyOpcode_num_pushed(int opcode, int oparg) {
541541
case LOAD_ATTR_SLOT:
542542
return ((oparg & 1) ? 1 : 0) + 1;
543543
case LOAD_ATTR_CLASS:
544-
return -1;
544+
return ((oparg & 1) ? 1 : 0) + 1;
545545
case LOAD_ATTR_PROPERTY:
546546
return -1;
547547
case LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN:
@@ -796,7 +796,7 @@ struct opcode_metadata {
796796
[LOAD_ATTR_MODULE] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IBC00000000 },
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 },
799-
[LOAD_ATTR_CLASS] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IB },
799+
[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_IB },
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 },

0 commit comments

Comments
 (0)