Skip to content
Prev Previous commit
Next Next commit
Modernize LOAD_ATTR_WITH_HINT
  • Loading branch information
gvanrossum committed Feb 1, 2023
commit f24eb1d0951a556bd8e78e92fea776c2688116bc
16 changes: 4 additions & 12 deletions Python/bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -1444,7 +1444,7 @@ dummy_func(
LOAD_ATTR_MODULE,
// LOAD_ATTR_PROPERTY,
// LOAD_ATTR_SLOT,
// LOAD_ATTR_WITH_HINT,
LOAD_ATTR_WITH_HINT,
// LOAD_ATTR_METHOD_LAZY_DICT,
// LOAD_ATTR_METHOD_NO_DICT,
// LOAD_ATTR_METHOD_WITH_VALUES,
Expand Down Expand Up @@ -1533,14 +1533,9 @@ dummy_func(
Py_DECREF(owner);
}

// error: LOAD_ATTR has irregular stack effect
inst(LOAD_ATTR_WITH_HINT) {
inst(LOAD_ATTR_WITH_HINT, (unused/1, type_version/2, index/1, unused/5, owner -- res2 if (oparg & 1), res)) {
assert(cframe.use_tracing == 0);
PyObject *owner = TOP();
PyObject *res;
PyTypeObject *tp = Py_TYPE(owner);
_PyAttrCache *cache = (_PyAttrCache *)next_instr;
uint32_t type_version = read_u32(cache->version);
assert(type_version != 0);
DEOPT_IF(tp->tp_version_tag != type_version, LOAD_ATTR);
assert(tp->tp_flags & Py_TPFLAGS_MANAGED_DICT);
Expand All @@ -1550,7 +1545,7 @@ dummy_func(
DEOPT_IF(dict == NULL, LOAD_ATTR);
assert(PyDict_CheckExact((PyObject *)dict));
PyObject *name = GETITEM(names, oparg>>1);
uint16_t hint = cache->index;
uint16_t hint = index;
DEOPT_IF(hint >= (size_t)dict->ma_keys->dk_nentries, LOAD_ATTR);
if (DK_IS_UNICODE(dict->ma_keys)) {
PyDictUnicodeEntry *ep = DK_UNICODE_ENTRIES(dict->ma_keys) + hint;
Expand All @@ -1565,11 +1560,8 @@ dummy_func(
DEOPT_IF(res == NULL, LOAD_ATTR);
STAT_INC(LOAD_ATTR, hit);
Py_INCREF(res);
SET_TOP(NULL);
STACK_GROW((oparg & 1));
SET_TOP(res);
res2 = NULL;
Py_DECREF(owner);
JUMPBY(INLINE_CACHE_ENTRIES_LOAD_ATTR);
}

// error: LOAD_ATTR has irregular stack effect
Expand Down
20 changes: 11 additions & 9 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 @@ -191,7 +191,7 @@ _PyOpcode_num_popped(int opcode, int oparg) {
case LOAD_ATTR_MODULE:
return 1;
case LOAD_ATTR_WITH_HINT:
return -1;
return 1;
case LOAD_ATTR_SLOT:
return -1;
case LOAD_ATTR_CLASS:
Expand Down Expand Up @@ -537,7 +537,7 @@ _PyOpcode_num_pushed(int opcode, int oparg) {
case LOAD_ATTR_MODULE:
return ((oparg & 1) ? 1 : 0) + 1;
case LOAD_ATTR_WITH_HINT:
return -1;
return ((oparg & 1) ? 1 : 0) + 1;
case LOAD_ATTR_SLOT:
return -1;
case LOAD_ATTR_CLASS:
Expand Down Expand Up @@ -794,7 +794,7 @@ struct opcode_metadata {
[LOAD_ATTR] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IBC00000000 },
[LOAD_ATTR_INSTANCE_VALUE] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IBC00000000 },
[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_IB },
[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_IB },
[LOAD_ATTR_CLASS] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IB },
[LOAD_ATTR_PROPERTY] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IB },
Expand Down