Skip to content

Commit 96ca1f9

Browse files
authored
Merge branch 'main' into fix-pulldom-resource-leak-148428
2 parents baaf87f + 03d2f03 commit 96ca1f9

File tree

4 files changed

+37
-0
lines changed

4 files changed

+37
-0
lines changed

Lib/test/test_capi/test_opt.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2755,6 +2755,21 @@ def testfunc(n):
27552755
self.assertNotIn("_GUARD_TOS_INT", uops)
27562756
self.assertIn("_POP_TOP_NOP", uops)
27572757

2758+
def test_check_is_not_py_callable(self):
2759+
def testfunc(n):
2760+
total = 0
2761+
f = len
2762+
xs = (1, 2, 3)
2763+
for _ in range(n):
2764+
total += f(xs)
2765+
return total
2766+
2767+
res, ex = self._run_with_optimizer(testfunc, TIER2_THRESHOLD)
2768+
self.assertEqual(res, 3 * TIER2_THRESHOLD)
2769+
self.assertIsNotNone(ex)
2770+
uops = get_opnames(ex)
2771+
self.assertNotIn("_CHECK_IS_NOT_PY_CALLABLE", uops)
2772+
27582773
def test_call_len_string(self):
27592774
def testfunc(n):
27602775
for _ in range(n):
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix a bug in the JIT optimizer where class attribute loads were not invalidated after type mutation.

Python/optimizer_bytecodes.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,10 @@ dummy_func(void) {
226226
}
227227
else {
228228
sym_set_const(owner, type);
229+
if ((((PyTypeObject *)type)->tp_flags & Py_TPFLAGS_IMMUTABLETYPE) == 0) {
230+
PyType_Watch(TYPE_WATCHER_ID, type);
231+
_Py_BloomFilter_Add(dependencies, type);
232+
}
229233
}
230234
}
231235
}
@@ -1213,6 +1217,13 @@ dummy_func(void) {
12131217
(void)framesize;
12141218
}
12151219

1220+
op(_CHECK_IS_NOT_PY_CALLABLE, (callable, unused, unused[oparg] -- callable, unused, unused[oparg])) {
1221+
PyTypeObject *type = sym_get_type(callable);
1222+
if (type && type != &PyFunction_Type && type != &PyMethod_Type) {
1223+
ADD_OP(_NOP, 0, 0);
1224+
}
1225+
}
1226+
12161227
op(_PUSH_FRAME, (new_frame -- )) {
12171228
SYNC_SP();
12181229
if (!CURRENT_FRAME_IS_INIT_SHIM()) {

Python/optimizer_cases.c.h

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

0 commit comments

Comments
 (0)