Skip to content

Commit 1a85b95

Browse files
Add JIT support and tests
1 parent 3687f0b commit 1a85b95

File tree

4 files changed

+52
-1
lines changed

4 files changed

+52
-1
lines changed

Lib/test/test_capi/test_opt.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,23 @@ def dummy(x):
400400
self.assertIn("_PUSH_FRAME", uops)
401401
self.assertIn("_BINARY_OP_ADD_INT", uops)
402402

403+
def test_call_py_ex(self):
404+
def testfunc(n):
405+
def ex_py(*args, **kwargs):
406+
return 1
407+
408+
for _ in range(n):
409+
args = (1, 2, 3)
410+
kwargs = {}
411+
ex_py(*args, **kwargs)
412+
413+
testfunc(TIER2_THRESHOLD)
414+
415+
ex = get_first_executor(testfunc)
416+
self.assertIsNotNone(ex)
417+
uops = get_opnames(ex)
418+
self.assertIn("_PUSH_FRAME", uops)
419+
403420
def test_branch_taken(self):
404421
def testfunc(n):
405422
for i in range(n):

Lib/test/test_opcache.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,23 @@ def instantiate():
591591
instantiate()
592592
self.assert_specialized(instantiate, "CALL_FUNCTION_EX_PY")
593593

594+
@requires_jit_disabled
595+
@requires_specialization_ft
596+
def test_specialize_call_function_ex_py_fail(self):
597+
def ex_py(*args, **kwargs):
598+
return 1
599+
600+
def instantiate():
601+
args = (1, 2, 3)
602+
kwargs = {}
603+
return ex_py(*args, **kwargs)
604+
605+
_testinternalcapi.set_vectorcall_nop(ex_py)
606+
# Trigger specialization
607+
for _ in range(_testinternalcapi.SPECIALIZATION_THRESHOLD):
608+
instantiate()
609+
self.assert_no_opcode(instantiate, "CALL_FUNCTION_EX_PY")
610+
594611
def make_deferred_ref_count_obj():
595612
"""Create an object that uses deferred reference counting.
596613

Python/optimizer_bytecodes.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -831,6 +831,17 @@ dummy_func(void) {
831831
new_frame = PyJitRef_Wrap((JitOptSymbol *)frame_new(ctx, co, 0, NULL, 0));
832832
}
833833

834+
op(_PY_FRAME_EX, (func_st, null, callargs_st, kwargs_st -- ex_frame)) {
835+
assert((this_instr + 2)->opcode == _PUSH_FRAME);
836+
PyCodeObject *co = get_code_with_logging((this_instr + 2));
837+
if (co == NULL) {
838+
ctx->done = true;
839+
break;
840+
}
841+
842+
ex_frame = PyJitRef_Wrap((JitOptSymbol *)frame_new(ctx, co, 0, NULL, 0));
843+
}
844+
834845
op(_CHECK_AND_ALLOCATE_OBJECT, (type_version/2, callable, self_or_null, args[oparg] -- callable, self_or_null, args[oparg])) {
835846
(void)type_version;
836847
(void)args;

Python/optimizer_cases.c.h

Lines changed: 7 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)