10000 gh-98831: Modernize the LOAD_ATTR family by gvanrossum · Pull Request #101488 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-98831: Modernize the LOAD_ATTR family #101488

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Feb 1, 2023
Prev Previous commit
Next Next commit
Modernize LOAD_ATTR_PROPERTY
  • Loading branch information
gvanrossum committed Feb 1, 2023
commit 41a86d68d707183ea7a1cc961be9a5cde575936a
11 changes: 3 additions & 8 deletions Python/bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -1443,7 +1443,7 @@ dummy_func(
LOAD_ATTR_WITH_HINT,
LOAD_ATTR_SLOT,
LOAD_ATTR_CLASS,
// LOAD_ATTR_PROPERTY,
LOAD_ATTR_PROPERTY,
// LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN,
// LOAD_ATTR_METHOD_WITH_VALUES,
// LOAD_ATTR_METHOD_NO_DICT,
Expand Down Expand Up @@ -1594,21 +1594,15 @@ dummy_func(
Py_DECREF(cls);
}

// error: LOAD_ATTR has irregular stack effect
inst(LOAD_ATTR_PROPERTY) {
inst(LOAD_ATTR_PROPERTY, (unused/1, type_version/2, func_version/2, fget/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 *fget = read_obj(cache->descr);
assert(Py_IS_TYPE(fget, &PyFunction_Type));
PyFunctionObject *f = (PyFunctionObject *)fget;
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 @@ -1617,6 +1611,7 @@ dummy_func(
STAT_INC(LOAD_ATTR, hit);
Py_INCREF(fget);
_PyInterpreterFrame *new_frame = _PyFrame_PushUnchecked(tstate, f, 1);
// 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 @@ -197,7 +197,7 @@ _PyOpcode_num_popped(int opcode, int oparg) {
case LOAD_ATTR_CLASS:
return 1;
case LOAD_ATTR_PROPERTY:
return -1;
return 1;
case LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN:
return -1;
case STORE_ATTR_INSTANCE_VALUE:
Expand Down Expand Up @@ -543,7 +543,7 @@ _PyOpcode_num_pushed(int opcode, int oparg) {
case LOAD_ATTR_CLASS:
return ((oparg & 1) ? 1 : 0) + 1;
case LOAD_ATTR_PROPERTY:
return -1;
return ((oparg & 1) ? 1 : 0) + 1;
case LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN:
return -1;
case STORE_ATTR_INSTANCE_VALUE:
Expand Down Expand Up @@ -797,7 +797,7 @@ struct opcode_metadata {
[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_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_IB },
[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 },
[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 },
Expand Down
0