]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-103951: enable optimization for fast attribute access on module subclasses (GH...
authorSergey B Kirpichev <skirpichev@gmail.com>
Fri, 15 Nov 2024 08:03:38 +0000 (11:03 +0300)
committerGitHub <noreply@github.com>
Fri, 15 Nov 2024 08:03:38 +0000 (16:03 +0800)
Co-authored-by: Nicolas Tessore <n.tessore@ucl.ac.uk>
Misc/NEWS.d/next/Core_and_Builtins/2024-11-01-09-58-06.gh-issue-103951.6qduwj.rst [new file with mode: 0644]
Python/bytecodes.c
Python/executor_cases.c.h
Python/generated_cases.c.h
Python/specialize.c

diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2024-11-01-09-58-06.gh-issue-103951.6qduwj.rst b/Misc/NEWS.d/next/Core_and_Builtins/2024-11-01-09-58-06.gh-issue-103951.6qduwj.rst
new file mode 100644 (file)
index 0000000..39b54e0
--- /dev/null
@@ -0,0 +1,2 @@
+Relax optimization requirements to allow fast attribute access to module
+subclasses.
index 04983fd861ec5984b4b84b7a461286b5cb062b3e..c85b49842daf443ed267ca23c74e631b22df6d85 100644 (file)
@@ -2132,7 +2132,7 @@ dummy_func(
 
         op(_CHECK_ATTR_MODULE, (dict_version/2, owner -- owner)) {
             PyObject *owner_o = PyStackRef_AsPyObjectBorrow(owner);
-            DEOPT_IF(!PyModule_CheckExact(owner_o));
+            DEOPT_IF(Py_TYPE(owner_o)->tp_getattro != PyModule_Type.tp_getattro);
             PyDictObject *dict = (PyDictObject *)((PyModuleObject *)owner_o)->md_dict;
             assert(dict != NULL);
             DEOPT_IF(dict->ma_keys->dk_version != dict_version);
index 494ace1bd858228714af5ce73a1f4737859bbb6f..2c2a09adf281a7e7c19b571573476c73a8e1f747 100644 (file)
             owner = stack_pointer[-1];
             uint32_t dict_version = (uint32_t)CURRENT_OPERAND0();
             PyObject *owner_o = PyStackRef_AsPyObjectBorrow(owner);
-            if (!PyModule_CheckExact(owner_o)) {
+            if (Py_TYPE(owner_o)->tp_getattro != PyModule_Type.tp_getattro) {
                 UOP_STAT_INC(uopcode, miss);
                 JUMP_TO_JUMP_TARGET();
             }
index 77bf6ad3781f17b16c7c425ebc16d159a4c04288..15308d6f1f714635611b3c7287a7241897ed7c6c 100644 (file)
                 owner = stack_pointer[-1];
                 uint32_t dict_version = read_u32(&this_instr[2].cache);
                 PyObject *owner_o = PyStackRef_AsPyObjectBorrow(owner);
-                DEOPT_IF(!PyModule_CheckExact(owner_o), LOAD_ATTR);
+                DEOPT_IF(Py_TYPE(owner_o)->tp_getattro != PyModule_Type.tp_getattro, LOAD_ATTR);
                 PyDictObject *dict = (PyDictObject *)((PyModuleObject *)owner_o)->md_dict;
                 assert(dict != NULL);
                 DEOPT_IF(dict->ma_keys->dk_version != dict_version, LOAD_ATTR);
index 0699e7be5e6b9c4c406b334f6352e6c696437d20..4c8cf8534b3dc7371c067ee9c26d18f6a3396393 100644 (file)
@@ -1219,7 +1219,7 @@ _Py_Specialize_LoadAttr(_PyStackRef owner_st, _Py_CODEUNIT *instr, PyObject *nam
         SPECIALIZATION_FAIL(LOAD_ATTR, SPEC_FAIL_OTHER);
         fail = true;
     }
-    else if (PyModule_CheckExact(owner)) {
+    else if (Py_TYPE(owner)->tp_getattro == PyModule_Type.tp_getattro) {
         fail = specialize_module_load_attr(owner, instr, name);
     }
     else if (PyType_Check(owner)) {