summaryrefslogtreecommitdiffstats
path: root/Python/specialize.c
diff options
context:
space:
mode:
authorCarl Meyer <carl@oddbird.net>2023-05-11 14:08:13 (GMT)
committerGitHub <noreply@github.com>2023-05-11 14:08:13 (GMT)
commit77262458fe3fe9f3f0266bbf578675a906b1e353 (patch)
treeb066d678cfdba47c64e82ed49ecb73a1d1d8a701 /Python/specialize.c
parentddc0e70a326180d90a45dfd8abeded9c9f911217 (diff)
downloadcpython-77262458fe3fe9f3f0266bbf578675a906b1e353.zip
cpython-77262458fe3fe9f3f0266bbf578675a906b1e353.tar.gz
cpython-77262458fe3fe9f3f0266bbf578675a906b1e353.tar.bz2
gh-87729: improve hit rate of LOAD_SUPER_ATTR specialization (#104270)
Diffstat (limited to 'Python/specialize.c')
-rw-r--r--Python/specialize.c33
1 files changed, 5 insertions, 28 deletions
diff --git a/Python/specialize.c b/Python/specialize.c
index 45f1cb4..5071d8e 100644
--- a/Python/specialize.c
+++ b/Python/specialize.c
@@ -323,11 +323,8 @@ _PyCode_Quicken(PyCodeObject *code)
/* Super */
-#define SPEC_FAIL_SUPER_NOT_LOAD_METHOD 9
-#define SPEC_FAIL_SUPER_BAD_CLASS 10
-#define SPEC_FAIL_SUPER_SHADOWED 11
-#define SPEC_FAIL_SUPER_NOT_METHOD 12
-#define SPEC_FAIL_SUPER_ERROR_OR_NOT_FOUND 13
+#define SPEC_FAIL_SUPER_BAD_CLASS 9
+#define SPEC_FAIL_SUPER_SHADOWED 10
/* Attributes */
@@ -516,15 +513,10 @@ specialize_module_load_attr(
/* Attribute specialization */
void
-_Py_Specialize_LoadSuperAttr(PyObject *global_super, PyObject *cls, PyObject *self,
- _Py_CODEUNIT *instr, PyObject *name, int load_method) {
+_Py_Specialize_LoadSuperAttr(PyObject *global_super, PyObject *cls, _Py_CODEUNIT *instr, int load_method) {
assert(ENABLE_SPECIALIZATION);
assert(_PyOpcode_Caches[LOAD_SUPER_ATTR] == INLINE_CACHE_ENTRIES_LOAD_SUPER_ATTR);
_PySuperAttrCache *cache = (_PySuperAttrCache *)(instr + 1);
- if (!load_method) {
- SPECIALIZATION_FAIL(LOAD_SUPER_ATTR, SPEC_FAIL_SUPER_NOT_LOAD_METHOD);
- goto fail;
- }
if (global_super != (PyObject *)&PySuper_Type) {
SPECIALIZATION_FAIL(LOAD_SUPER_ATTR, SPEC_FAIL_SUPER_SHADOWED);
goto fail;
@@ -533,23 +525,8 @@ _Py_Specialize_LoadSuperAttr(PyObject *global_super, PyObject *cls, PyObject *se
SPECIALIZATION_FAIL(LOAD_SUPER_ATTR, SPEC_FAIL_SUPER_BAD_CLASS);
goto fail;
}
- PyTypeObject *tp = (PyTypeObject *)cls;
- PyObject *res = _PySuper_LookupDescr(tp, self, name);
- if (res == NULL) {
- SPECIALIZATION_FAIL(LOAD_SUPER_ATTR, SPEC_FAIL_SUPER_ERROR_OR_NOT_FOUND);
- PyErr_Clear();
- goto fail;
- }
- if (_PyType_HasFeature(Py_TYPE(res), Py_TPFLAGS_METHOD_DESCRIPTOR)) {
- write_u32(cache->class_version, tp->tp_version_tag);
- write_u32(cache->self_type_version, Py_TYPE(self)->tp_version_tag);
- write_obj(cache->method, res); // borrowed
- instr->op.code = LOAD_SUPER_ATTR_METHOD;
- Py_DECREF(res);
- goto success;
- }
- Py_DECREF(res);
- SPECIALIZATION_FAIL(LOAD_SUPER_ATTR, SPEC_FAIL_SUPER_NOT_METHOD);
+ instr->op.code = load_method ? LOAD_SUPER_ATTR_METHOD : LOAD_SUPER_ATTR_ATTR;
+ goto success;
fail:
STAT_INC(LOAD_SUPER_ATTR, failure);