Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
address review
  • Loading branch information
kumaraditya303 committed Apr 8, 2026
commit 38f8396bc03858aafee6f44e2640fbf89adefb51
17 changes: 12 additions & 5 deletions Lib/test/test_capi/test_opt.py
Original file line number Diff line number Diff line change
Expand Up @@ -5013,23 +5013,30 @@ def g():

def test_call_super(self):
class A:
def method(self):
def method1(self):
return 42

def method2(self):
return 21

class B(A):
def method(self):
return super().method()
def method1(self):
return super().method1()

def method2(self):
return super(B, self).method2()

b = B()

def testfunc(n):
x = 0
for _ in range(n):
x += b.method()
x += b.method1()
x += b.method2()
return x

res, ex = self._run_with_optimizer(testfunc, TIER2_THRESHOLD)
self.assertEqual(res, 42 * TIER2_THRESHOLD)
self.assertEqual(res, 63 * TIER2_THRESHOLD)
self.assertIsNotNone(ex)
uops = get_opnames(ex)
self.assertNotIn("_LOAD_SUPER_ATTR_METHOD", uops)
Expand Down
2 changes: 1 addition & 1 deletion Python/bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -2639,7 +2639,7 @@ dummy_func(
op(_GUARD_NOS_TYPE_VERSION, (type_version/2, nos, unused -- nos, unused)) {
PyTypeObject *tp = (PyTypeObject *)PyStackRef_AsPyObjectBorrow(nos);
assert(type_version != 0);
assert(PyType_Check(tp));
EXIT_IF(!PyType_Check((PyObject *)tp));
EXIT_IF(FT_ATOMIC_LOAD_UINT_RELAXED(tp->tp_version_tag) != type_version);
}

Expand Down
30 changes: 26 additions & 4 deletions Python/executor_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 15 additions & 16 deletions Python/optimizer_analysis.c
Original file line number Diff line number Diff line change
Expand Up @@ -433,24 +433,23 @@ lookup_super_attr(JitOptContext *ctx, _PyBloomFilter *dependencies,
}
return sym_new_not_null(ctx);
}
if (Py_TYPE(lookup)->tp_flags & Py_TPFLAGS_METHOD_DESCRIPTOR) {
int opcode = mortal;
if (_Py_IsImmortal(lookup) || (obj_type->tp_flags & Py_TPFLAGS_IMMUTABLETYPE)) {
opcode = immortal;
}
ADD_OP(_SWAP, 3, 0);
ADD_OP(_POP_TOP, 0, 0);
ADD_OP(_POP_TOP, 0, 0);
ADD_OP(opcode, 0, (uintptr_t)lookup);
PyType_Watch(TYPE_WATCHER_ID, (PyObject *)su_type);
_Py_BloomFilter_Add(dependencies, su_type);
PyType_Watch(TYPE_WATCHER_ID, (PyObject *)obj_type);
_Py_BloomFilter_Add(dependencies, obj_type);
JitOptRef result = sym_new_const(ctx, lookup);
if ((Py_TYPE(lookup)->tp_flags & Py_TPFLAGS_METHOD_DESCRIPTOR) == 0) {
Py_DECREF(lookup);
return result;
return sym_new_not_null(ctx);
}
return sym_new_not_null(ctx);
int opcode = mortal;
if (_Py_IsImmortal(lookup) || (obj_type->tp_flags & Py_TPFLAGS_IMMUTABLETYPE)) {
opcode = immortal;
}
ADD_OP(_SWAP, 3, 0);
ADD_OP(_POP_TOP, 0, 0);
ADD_OP(_POP_TOP, 0, 0);
ADD_OP(opcode, 0, (uintptr_t)lookup);
PyType_Watch(TYPE_WATCHER_ID, (PyObject *)su_type);
_Py_BloomFilter_Add(dependencies, su_type);
PyType_Watch(TYPE_WATCHER_ID, (PyObject *)obj_type);
_Py_BloomFilter_Add(dependencies, obj_type);
return sym_new_const_steal(ctx, lookup);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to self: need steal version because _PySuper_Lookup returns a strong reference, unlike _PyType_Lookup

}

static
Expand Down
Loading