Skip to content

Commit 2a9167e

Browse files
authored
Allow the JIT to be used on Python 3.14 (#543)
Follows #538
1 parent d7759a1 commit 2a9167e

File tree

2 files changed

+235
-2
lines changed

2 files changed

+235
-2
lines changed

cpython-unix/build-cpython.sh

+8-2
Original file line numberDiff line numberDiff line change
@@ -428,9 +428,9 @@ if [ -n "${CPYTHON_OPTIMIZED}" ]; then
428428
# Allow users to enable the experimental JIT on 3.13+
429429
if [[ -n "${PYTHON_MEETS_MINIMUM_VERSION_3_13}" ]]; then
430430

431-
# The JIT build is failing on macOS and 3.14+ due to compiler errors
431+
# The JIT build is failing on macOS due to compiler errors
432432
# Only enable on Linux / 3.13 until that's fixed upstream
433-
if [[ -n "${PYTHON_MEETS_MAXIMUM_VERSION_3_13}" && "${PYBUILD_PLATFORM}" != "macos" ]]; then
433+
if [[ "${PYBUILD_PLATFORM}" != "macos" ]]; then
434434
CONFIGURE_FLAGS="${CONFIGURE_FLAGS} --enable-experimental-jit=yes-off"
435435
fi
436436

@@ -439,6 +439,12 @@ if [ -n "${CPYTHON_OPTIMIZED}" ]; then
439439
# version.
440440
patch -p1 -i "${ROOT}/patch-jit-llvm-19.patch"
441441
fi
442+
443+
if [[ -n "${PYTHON_MEETS_MINIMUM_VERSION_3_14}" ]]; then
444+
# On 3.14, we also use the tail calling interpreter which was incompatible with the JIT
445+
# until https://github.com/python/cpython/pull/129820 — backport that
446+
patch -p1 -i "${ROOT}/patch-jit-tail-call-compat-314-129820.patch"
447+
fi
442448
fi
443449
fi
444450

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,227 @@
1+
diff --git a/configure b/configure
2+
index 65b8e711cdccae..ee47feafc73fc1 100755
3+
--- a/configure
4+
+++ b/configure
5+
@@ -29281,18 +29281,6 @@ esac
6+
fi
7+
8+
9+
-# Do not enable tail-calling interpreter if tier 2 is enabled.
10+
-if ${tier2_flags:+false} :
11+
-then :
12+
-
13+
- case "$ac_cv_tail_call" in yes*)
14+
-
15+
-printf "%s\n" "#define Py_TAIL_CALL_INTERP 1" >>confdefs.h
16+
-
17+
- esac
18+
-
19+
-fi
20+
-
21+
22+
case $ac_sys_system in
23+
AIX*)
24+
diff --git a/configure.ac b/configure.ac
25+
index 0c6063d87d654a..c68938ba9e168d 100644
26+
--- a/configure.ac
27+
+++ b/configure.ac
28+
@@ -7041,19 +7041,6 @@ fi
29+
],
30+
[AC_MSG_RESULT([no value specified])])
31+
32+
-# Do not enable tail-calling interpreter if tier 2 is enabled.
33+
-AS_VAR_IF(
34+
- [tier2_flags],
35+
- [],
36+
- [
37+
- case "$ac_cv_tail_call" in yes*)
38+
- AC_DEFINE([Py_TAIL_CALL_INTERP], [1],
39+
- [Define if the C compiler supports efficient proper tail calls.])
40+
- esac
41+
- ],
42+
- []
43+
-)
44+
-
45+
46+
case $ac_sys_system in
47+
AIX*)
48+
diff --git a/pyconfig.h.in b/pyconfig.h.in
49+
index 9ea01ad3fc0a31..4295b4f5ea5fbd 100644
50+
--- a/pyconfig.h.in
51+
+++ b/pyconfig.h.in
52+
@@ -1718,7 +1718,7 @@
53+
/* The version of SunOS/Solaris as reported by `uname -r' without the dot. */
54+
#undef Py_SUNOS_VERSION
55+
56+
-/* Define if the C compiler supports efficient proper tail calls. */
57+
+/* Define if you want to use tail-calling interpreters in CPython. */
58+
#undef Py_TAIL_CALL_INTERP
59+
60+
/* Define if you want to enable tracing references for debugging purpose */
61+
62+
From dae88e3ca730576256a0b8d2bc9e78b8cacab645 Mon Sep 17 00:00:00 2001
63+
From: Ken Jin <[email protected]>
64+
Date: Sat, 8 Feb 2025 01:32:05 +0800
65+
Subject: [PATCH 2/6] Get JIT working minimally with tailcalling interpreter
66+
67+
---
68+
Python/ceval_macros.h | 19 +++++++++++++++++++
69+
1 file changed, 19 insertions(+)
70+
71+
diff --git a/Python/ceval_macros.h b/Python/ceval_macros.h
72+
index 44bb52a09aab5f..2c7729743b1705 100644
73+
--- a/Python/ceval_macros.h
74+
+++ b/Python/ceval_macros.h
75+
@@ -384,6 +384,24 @@ _PyFrame_SetStackPointer(frame, stack_pointer)
76+
/* Tier-switching macros. */
77+
78+
#ifdef _Py_JIT
79+
+#ifdef Py_TAIL_CALL_INTERP
80+
+#define GOTO_TIER_TWO(EXECUTOR) \
81+
+do { \
82+
+ OPT_STAT_INC(traces_executed); \
83+
+ jit_func jitted = (EXECUTOR)->jit_code; \
84+
+ next_instr = jitted(frame, stack_pointer, tstate); \
85+
+ Py_DECREF(tstate->previous_executor); \
86+
+ tstate->previous_executor = NULL; \
87+
+ frame = tstate->current_frame; \
88+
+ if (next_instr == NULL) { \
89+
+ next_instr = frame->instr_ptr; \
90+
+ stack_pointer = _PyFrame_GetStackPointer(frame); \
91+
+ return _TAIL_CALL_error(TAIL_CALL_ARGS); \
92+
+ } \
93+
+ stack_pointer = _PyFrame_GetStackPointer(frame); \
94+
+ DISPATCH(); \
95+
+} while (0)
96+
+#else
97+
#define GOTO_TIER_TWO(EXECUTOR) \
98+
do { \
99+
OPT_STAT_INC(traces_executed); \
100+
@@ -400,6 +418,7 @@ do { \
101+
stack_pointer = _PyFrame_GetStackPointer(frame); \
102+
DISPATCH(); \
103+
} while (0)
104+
+#endif
105+
#else
106+
#define GOTO_TIER_TWO(EXECUTOR) \
107+
do { \
108+
109+
From 230d497620d73e17a099326f7e54078e91254e5a Mon Sep 17 00:00:00 2001
110+
From: Ken Jin <[email protected]>
111+
Date: Tue, 11 Feb 2025 16:05:57 +0800
112+
Subject: [PATCH 3/6] Update ceval_macros.h
113+
114+
---
115+
Python/ceval_macros.h | 2 +-
116+
1 file changed, 1 insertion(+), 1 deletion(-)
117+
118+
diff --git a/Python/ceval_macros.h b/Python/ceval_macros.h
119+
index 2c7729743b1705..0f4dd61f367dbb 100644
120+
--- a/Python/ceval_macros.h
121+
+++ b/Python/ceval_macros.h
122+
@@ -384,7 +384,7 @@ _PyFrame_SetStackPointer(frame, stack_pointer)
123+
/* Tier-switching macros. */
124+
125+
#ifdef _Py_JIT
126+
-#ifdef Py_TAIL_CALL_INTERP
127+
+#if Py_TAIL_CALL_INTERP
128+
#define GOTO_TIER_TWO(EXECUTOR) \
129+
do { \
130+
OPT_STAT_INC(traces_executed); \
131+
132+
From c46391470ca8b4d6a4b9c0d9f75c7fcce6ac303a Mon Sep 17 00:00:00 2001
133+
From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com>
134+
Date: Tue, 11 Feb 2025 08:06:47 +0000
135+
Subject: [PATCH 4/6] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?=
136+
=?UTF-8?q?rb=5Fit.?=
137+
MIME-Version: 1.0
138+
Content-Type: text/plain; charset=UTF-8
139+
Content-Transfer-Encoding: 8bit
140+
141+
---
142+
.../next/Build/2025-02-11-08-06-44.gh-issue-129819.7rn4dY.rst | 1 +
143+
1 file changed, 1 insertion(+)
144+
create mode 100644 Misc/NEWS.d/next/Build/2025-02-11-08-06-44.gh-issue-129819.7rn4dY.rst
145+
146+
diff --git a/Misc/NEWS.d/next/Build/2025-02-11-08-06-44.gh-issue-129819.7rn4dY.rst b/Misc/NEWS.d/next/Build/2025-02-11-08-06-44.gh-issue-129819.7rn4dY.rst
147+
new file mode 100644
148+
index 00000000000000..2463e4dba24ae9
149+
--- /dev/null
150+
+++ b/Misc/NEWS.d/next/Build/2025-02-11-08-06-44.gh-issue-129819.7rn4dY.rst
151+
@@ -0,0 +1 @@
152+
+Allow building the JIT with the tailcall interpreter.
153+
154+
From 105ab11ce4fcc3d659ccaf36197ea281b853e23a Mon Sep 17 00:00:00 2001
155+
From: Ken Jin <[email protected]>
156+
Date: Wed, 12 Feb 2025 16:14:23 +0800
157+
Subject: [PATCH 5/6] Address review
158+
159+
---
160+
Python/ceval_macros.h | 2 +-
161+
1 file changed, 1 insertion(+), 1 deletion(-)
162+
163+
diff --git a/Python/ceval_macros.h b/Python/ceval_macros.h
164+
index 0f4dd61f367dbb..9562ad9d349a11 100644
165+
--- a/Python/ceval_macros.h
166+
+++ b/Python/ceval_macros.h
167+
@@ -396,7 +396,7 @@ do { \
168+
if (next_instr == NULL) { \
169+
next_instr = frame->instr_ptr; \
170+
stack_pointer = _PyFrame_GetStackPointer(frame); \
171+
- return _TAIL_CALL_error(TAIL_CALL_ARGS); \
172+
+ return JUMP_TO_LABEL(error); \
173+
} \
174+
stack_pointer = _PyFrame_GetStackPointer(frame); \
175+
DISPATCH(); \
176+
177+
From 76c2c96fed4abc68e8879f3d65755d5cba8a4b16 Mon Sep 17 00:00:00 2001
178+
From: Ken Jin <[email protected]>
179+
Date: Thu, 13 Feb 2025 01:06:07 +0800
180+
Subject: [PATCH 6/6] one-liner
181+
182+
---
183+
Python/ceval_macros.h | 21 +--------------------
184+
1 file changed, 1 insertion(+), 20 deletions(-)
185+
186+
diff --git a/Python/ceval_macros.h b/Python/ceval_macros.h
187+
index 2422bf3bcf38f1..4f0071d5e1a09f 100644
188+
--- a/Python/ceval_macros.h
189+
+++ b/Python/ceval_macros.h
190+
@@ -381,24 +381,6 @@ _PyFrame_SetStackPointer(frame, stack_pointer)
191+
/* Tier-switching macros. */
192+
193+
#ifdef _Py_JIT
194+
-#if Py_TAIL_CALL_INTERP
195+
-#define GOTO_TIER_TWO(EXECUTOR) \
196+
-do { \
197+
- OPT_STAT_INC(traces_executed); \
198+
- jit_func jitted = (EXECUTOR)->jit_code; \
199+
- next_instr = jitted(frame, stack_pointer, tstate); \
200+
- Py_DECREF(tstate->previous_executor); \
201+
- tstate->previous_executor = NULL; \
202+
- frame = tstate->current_frame; \
203+
- if (next_instr == NULL) { \
204+
- next_instr = frame->instr_ptr; \
205+
- stack_pointer = _PyFrame_GetStackPointer(frame); \
206+
- return JUMP_TO_LABEL(error); \
207+
- } \
208+
- stack_pointer = _PyFrame_GetStackPointer(frame); \
209+
- DISPATCH(); \
210+
-} while (0)
211+
-#else
212+
#define GOTO_TIER_TWO(EXECUTOR) \
213+
do { \
214+
OPT_STAT_INC(traces_executed); \
215+
@@ -413,11 +395,10 @@ do { \
216+
stack_pointer = _PyFrame_GetStackPointer(frame); \
217+
if (next_instr == NULL) { \
218+
next_instr = frame->instr_ptr; \
219+
- goto error; \
220+
+ JUMP_TO_LABEL(error); \
221+
} \
222+
DISPATCH(); \
223+
} while (0)
224+
-#endif
225+
#else
226+
#define GOTO_TIER_TWO(EXECUTOR) \
227+
do { \

0 commit comments

Comments
 (0)