Skip to content

Commit 38f8396

Browse files
address review
1 parent 264732d commit 38f8396

File tree

4 files changed

+54
-26
lines changed

4 files changed

+54
-26
lines changed

Lib/test/test_capi/test_opt.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5013,23 +5013,30 @@ def g():
50135013

50145014
def test_call_super(self):
50155015
class A:
5016-
def method(self):
5016+
def method1(self):
50175017
return 42
50185018

5019+
def method2(self):
5020+
return 21
5021+
50195022
class B(A):
5020-
def method(self):
5021-
return super().method()
5023+
def method1(self):
5024+
return super().method1()
5025+
5026+
def method2(self):
5027+
return super(B, self).method2()
50225028

50235029
b = B()
50245030

50255031
def testfunc(n):
50265032
x = 0
50275033
for _ in range(n):
5028-
x += b.method()
5034+
x += b.method1()
5035+
x += b.method2()
50295036
return x
50305037

50315038
res, ex = self._run_with_optimizer(testfunc, TIER2_THRESHOLD)
5032-
self.assertEqual(res, 42 * TIER2_THRESHOLD)
5039+
self.assertEqual(res, 63 * TIER2_THRESHOLD)
50335040
self.assertIsNotNone(ex)
50345041
uops = get_opnames(ex)
50355042
self.assertNotIn("_LOAD_SUPER_ATTR_METHOD", uops)

Python/bytecodes.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2639,7 +2639,7 @@ dummy_func(
26392639
op(_GUARD_NOS_TYPE_VERSION, (type_version/2, nos, unused -- nos, unused)) {
26402640
PyTypeObject *tp = (PyTypeObject *)PyStackRef_AsPyObjectBorrow(nos);
26412641
assert(type_version != 0);
2642-
assert(PyType_Check(tp));
2642+
EXIT_IF(!PyType_Check((PyObject *)tp));
26432643
EXIT_IF(FT_ATOMIC_LOAD_UINT_RELAXED(tp->tp_version_tag) != type_version);
26442644
}
26452645

Python/executor_cases.c.h

Lines changed: 26 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/optimizer_analysis.c

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -433,24 +433,23 @@ lookup_super_attr(JitOptContext *ctx, _PyBloomFilter *dependencies,
433433
}
434434
return sym_new_not_null(ctx);
435435
}
436-
if (Py_TYPE(lookup)->tp_flags & Py_TPFLAGS_METHOD_DESCRIPTOR) {
437-
int opcode = mortal;
438-
if (_Py_IsImmortal(lookup) || (obj_type->tp_flags & Py_TPFLAGS_IMMUTABLETYPE)) {
439-
opcode = immortal;
440-
}
441-
ADD_OP(_SWAP, 3, 0);
442-
ADD_OP(_POP_TOP, 0, 0);
443-
ADD_OP(_POP_TOP, 0, 0);
444-
ADD_OP(opcode, 0, (uintptr_t)lookup);
445-
PyType_Watch(TYPE_WATCHER_ID, (PyObject *)su_type);
446-
_Py_BloomFilter_Add(dependencies, su_type);
447-
PyType_Watch(TYPE_WATCHER_ID, (PyObject *)obj_type);
448-
_Py_BloomFilter_Add(dependencies, obj_type);
449-
JitOptRef result = sym_new_const(ctx, lookup);
436+
if ((Py_TYPE(lookup)->tp_flags & Py_TPFLAGS_METHOD_DESCRIPTOR) == 0) {
450437
Py_DECREF(lookup);
451-
return result;
438+
return sym_new_not_null(ctx);
452439
}
453-
return sym_new_not_null(ctx);
440+
int opcode = mortal;
441+
if (_Py_IsImmortal(lookup) || (obj_type->tp_flags & Py_TPFLAGS_IMMUTABLETYPE)) {
442+
opcode = immortal;
443+
}
444+
ADD_OP(_SWAP, 3, 0);
445+
ADD_OP(_POP_TOP, 0, 0);
446+
ADD_OP(_POP_TOP, 0, 0);
447+
ADD_OP(opcode, 0, (uintptr_t)lookup);
448+
PyType_Watch(TYPE_WATCHER_ID, (PyObject *)su_type);
449+
_Py_BloomFilter_Add(dependencies, su_type);
450+
PyType_Watch(TYPE_WATCHER_ID, (PyObject *)obj_type);
451+
_Py_BloomFilter_Add(dependencies, obj_type);
452+
return sym_new_const_steal(ctx, lookup);
454453
}
455454

456455
static

0 commit comments

Comments
 (0)