Skip to content

Commit 7389eca

Browse files
committed
gh-131798: Add gh-131798: Add _IS_NONE to the JIT optimizer (GH-148369) to the JIT optimizer
1 parent ba1e1c1 commit 7389eca

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-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):

Python/optimizer_bytecodes.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,6 +1213,13 @@ dummy_func(void) {
12131213
(void)framesize;
12141214
}
12151215

1216+
op(_CHECK_IS_NOT_PY_CALLABLE, (callable, unused, unused[oparg] -- callable, unused, unused[oparg])) {
1217+
PyTypeObject *type = sym_get_type(callable);
1218+
if (type && type != &PyFunction_Type && type != &PyMethod_Type) {
1219+
ADD_OP(_NOP, 0, 0);
1220+
}
1221+
}
1222+
12161223
op(_PUSH_FRAME, (new_frame -- )) {
12171224
SYNC_SP();
12181225
if (!CURRENT_FRAME_IS_INIT_SHIM()) {

Python/optimizer_cases.c.h

Lines changed: 6 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)