Visitar URL original
gh-87729: specialize LOAD_SUPER_ATTR_METHOD by carljm · Pull Request #103809 · python/cpython · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
0a0ebe2
gh-87729: add instruction for faster zero-arg super()
carljm Apr 10, 2023
f14a3bf
add news entry
carljm Apr 13, 2023
5625e73
document LOAD_ZERO_SUPER_ATTR
carljm Apr 13, 2023
0775efe
fix gdb test_wrapper_call
carljm Apr 13, 2023
f229b5b
optimize 2-arg super also
carljm Apr 13, 2023
626999d
fix incompatible assignment
carljm Apr 13, 2023
9384106
Merge branch 'main' into superopt
carljm Apr 13, 2023
92c943b
fix bad first arg
carljm Apr 13, 2023
09804cd
specialize LOAD_SUPER_ATTR for methods
carljm Apr 14, 2023
775ed0f
Apply suggestions from code review
carljm Apr 14, 2023
2077f1a
don't unnecessarily re-find args in error case
carljm Apr 14, 2023
64da49f
Merge branch 'main' into superopt
carljm Apr 14, 2023
4759ad9
update generated cases
carljm Apr 14, 2023
94399c2
fix incompatible types
carljm Apr 14, 2023
b73cff0
Merge branch 'superopt' into superopt_spec
carljm Apr 14, 2023
5627d66
don't double execute descriptor on specialization fail
carljm Apr 14, 2023
5136459
Merge branch 'main' into superopt
carljm Apr 17, 2023
82945b2
review comments
carljm Apr 17, 2023
3a3cb74
update generated cases with new comment
carljm Apr 17, 2023
079c65a
Merge branch 'superopt' into superopt_spec
carljm Apr 17, 2023
e4466a7
simplify oparg & 2 handling
carljm Apr 19, 2023
5c0a21c
Merge branch 'main' into superopt
carljm Apr 19, 2023
f161268
cleanup and clarification
carljm Apr 20, 2023
df442c0
move __class__ special case out of the fast path
carljm Apr 20, 2023
19b8025
Merge branch 'main' into superopt
carljm Apr 24, 2023
0de5bc6
Merge branch 'main' into superopt
carljm Apr 24, 2023
1972ca4
Merge branch 'superopt' into superopt_spec
carljm Apr 24, 2023
6858a6f
re-add comment
carljm Apr 24, 2023
dbe1665
Merge branch 'main' into superopt
carljm Apr 24, 2023
793a69a
Merge branch 'superopt' into superopt_spec
carljm Apr 24, 2023
af807d6
Merge branch 'main' into superopt_spec
carljm Apr 24, 2023
373cbc4
update previous NEWS entry
carljm Apr 24, 2023
3236f45
Merge branch 'main' into superopt_spec
carljm Apr 24, 2023
3d0e51a
credit Vlad
carljm Apr 24, 2023
c96d5c1
Merge branch 'main' into superopt_spec
ambv Apr 25, 2023
ad4008e
Merge branch 'main' into superopt_spec
carljm Apr 25, 2023
66d6271
Merge branch 'main' into superopt_spec
carljm Apr 25, 2023
fc6fcea
simplify LOAD_SUPER_ATTR, let specialization optimize
carljm Apr 25, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
cleanup and clarification
  • Loading branch information
carljm committed Apr 20, 2023
commit f16126880434ee8ee005a6a00dcac9d86ff20720
24 changes: 12 additions & 12 deletions Objects/typeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -9357,17 +9357,17 @@ super_repr(PyObject *self)
su->type ? su->type->tp_name : "NULL");
}

// if `method` is non-NULL, we are looking for a method descriptor,
// and setting `*method` to 1 means we found one.
static PyObject *
do_super_lookup(superobject *su, PyTypeObject *su_type, PyObject *su_obj,
PyTypeObject *su_obj_type, PyObject *name, int *meth_found)
PyTypeObject *su_obj_type, PyObject *name, int *method)
{
PyTypeObject *starttype;
PyObject *mro, *res;
Py_ssize_t i, n;
int temp_su = 0;

starttype = su_obj_type;
if (starttype == NULL)
if (su_obj_type == NULL)
goto skip;

/* We want __class__ to return the class of the super object
Expand All @@ -9377,7 +9377,7 @@ do_super_lookup(superobject *su, PyTypeObject *su_type, PyObject *su_obj,
_PyUnicode_Equal(name, &_Py_ID(__class__)))
goto skip;

mro = starttype->tp_mro;
mro = su_obj_type->tp_mro;
if (mro == NULL)
goto skip;

Expand All @@ -9393,7 +9393,7 @@ do_super_lookup(superobject *su, PyTypeObject *su_type, PyObject *su_obj,
if (i >= n)
goto skip;

/* keep a strong reference to mro because starttype->tp_mro can be
/* keep a strong reference to mro because su_obj_type->tp_mro can be
replaced during PyDict_GetItemWithError(dict, name) */
Py_INCREF(mro);
do {
Expand All @@ -9404,8 +9404,8 @@ do_super_lookup(superobject *su, PyTypeObject *su_type, PyObject *su_obj,
res = PyDict_GetItemWithError(dict, name);
if (res != NULL) {
Py_INCREF(res);
if (meth_found && _PyType_HasFeature(Py_TYPE(res), Py_TPFLAGS_METHOD_DESCRIPTOR)) {
*meth_found = 1;
if (method && _PyType_HasFeature(Py_TYPE(res), Py_TPFLAGS_METHOD_DESCRIPTOR)) {
*method = 1;
}
else {
descrgetfunc f = Py_TYPE(res)->tp_descr_get;
Expand All @@ -9414,8 +9414,8 @@ do_super_lookup(superobject *su, PyTypeObject *su_type, PyObject *su_obj,
res2 = f(res,
/* Only pass 'obj' param if this is instance-mode super
(See SF ID #743627) */
(su_obj == (PyObject *)starttype) ? NULL : su_obj,
(PyObject *)starttype);
(su_obj == (PyObject *)su_obj_type) ? NULL : su_obj,
(PyObject *)su_obj_type);
Py_SETREF(res, res2);
}
}
Expand Down Expand Up @@ -9509,13 +9509,13 @@ supercheck(PyTypeObject *type, PyObject *obj)
}

PyObject *
_PySuper_Lookup(PyTypeObject *su_type, PyObject *su_obj, PyObject *name, int *meth_found)
_PySuper_Lookup(PyTypeObject *su_type, PyObject *su_obj, PyObject *name, int *method)
{
PyTypeObject *su_obj_type = supercheck(su_type, su_obj);
if (su_obj_type == NULL) {
return NULL;
}
PyObject *res = do_super_lookup(NULL, su_type, su_obj, su_obj_type, name, meth_found);
PyObject *res = do_super_lookup(NULL, su_type, su_obj, su_obj_type, name, method);
Py_DECREF(su_obj_type);
return res;
}
Expand Down
6 changes: 3 additions & 3 deletions Python/bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -1557,16 +1557,16 @@ dummy_func(
inst(LOAD_SUPER_ATTR, (global_super, class, self -- res2 if (oparg & 1), res)) {
PyObject *name = GETITEM(frame->f_code->co_names, oparg >> 2);
if (global_super == (PyObject *)&PySuper_Type && PyType_Check(class)) {
int meth_found = 0;
int method = 0;
Py_DECREF(global_super);
res = _PySuper_Lookup((PyTypeObject *)class, self, name, oparg & 1 ? &meth_found : NULL);
res = _PySuper_Lookup((PyTypeObject *)class, self, name, oparg & 1 ? &method : NULL);
Py_DECREF(class);
if (res == NULL) {
Py_DECREF(self);
ERROR_IF(true, error);
}
// Works with CALL, pushes two values: either `meth | self` or `NULL | meth`.
if (meth_found) {
if (method) {
res2 = res;
res = self; // transfer ownership
} else {
Expand Down
Loading