Skip to content

Commit f28b5e0

Browse files
fixup and add test
1 parent d653515 commit f28b5e0

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

Lib/test/test_capi/test_opt.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5253,6 +5253,23 @@ def g():
52535253
PYTHON_JIT="1", PYTHON_JIT_STRESS="1")
52545254
self.assertEqual(result[0].rc, 0, result)
52555255

5256+
def test_call_kw(self):
5257+
def func(a):
5258+
return 42 * a
5259+
5260+
def testfunc(n):
5261+
x = 0
5262+
for _ in range(n):
5263+
x += func(a=1)
5264+
return x
5265+
5266+
res, ex = self._run_with_optimizer(testfunc, TIER2_THRESHOLD)
5267+
self.assertEqual(res, 42 * TIER2_THRESHOLD)
5268+
self.assertIsNotNone(ex)
5269+
uops = get_opnames(ex)
5270+
self.assertIn("_PUSH_FRAME", uops)
5271+
self.assertIn("_CHECK_FUNCTION_VERSION_KW", uops)
5272+
52565273
def test_func_version_guarded_on_change(self):
52575274
def testfunc(n):
52585275
for i in range(n):

Python/optimizer_bytecodes.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2273,6 +2273,10 @@ dummy_func(void) {
22732273
sym_set_recorded_value(func, (PyObject *)this_instr->operand0);
22742274
}
22752275

2276+
op(_RECORD_CALLABLE_KW, (func, self, args[oparg], kwnames -- func, self, args[oparg], kwnames)) {
2277+
sym_set_recorded_value(func, (PyObject *)this_instr->operand0);
2278+
}
2279+
22762280
op(_RECORD_BOUND_METHOD, (callable, self, args[oparg] -- callable, self, args[oparg])) {
22772281
sym_set_recorded_value(callable, (PyObject *)this_instr->operand0);
22782282
}

Python/optimizer_cases.c.h

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