Skip to content

Commit 63979ee

Browse files
committed
Merge remote-tracking branch 'upstream/main' into binary_subscr_to_op
2 parents 2cdee79 + f52a3a5 commit 63979ee

File tree

7 files changed

+609
-826
lines changed

7 files changed

+609
-826
lines changed

Doc/using/configure.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,16 @@ also be used to improve performance.
618618
Enable computed gotos in evaluation loop (enabled by default on supported
619619
compilers).
620620

621+
.. option:: --with-tail-call-interp
622+
623+
Enable interpreters using tail calls in CPython. If enabled, enabling PGO
624+
(:option:`--enable-optimizations`) is highly recommended. This option specifically
625+
requires a C compiler with proper tail call support, and the
626+
`preserve_none <https://clang.llvm.org/docs/AttributeReference.html#preserve-none>`_
627+
calling convention. For example, Clang 19 and newer supports this feature.
628+
629+
.. versionadded:: next
630+
621631
.. option:: --without-mimalloc
622632

623633
Disable the fast :ref:`mimalloc <mimalloc>` allocator

Doc/whatsnew/3.14.rst

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ Summary -- release highlights
6868
* :ref:`PEP 649: deferred evaluation of annotations <whatsnew314-pep649>`
6969
* :ref:`PEP 741: Python Configuration C API <whatsnew314-pep741>`
7070
* :ref:`PEP 761: Discontinuation of PGP signatures <whatsnew314-pep761>`
71+
* :ref:`A new tail-calling interpreter <whatsnew314-tail-call>`
7172

7273

7374
New features
@@ -208,6 +209,37 @@ configuration mechanisms).
208209
.. seealso::
209210
:pep:`741`.
210211

212+
.. _whatsnew314-tail-call:
213+
214+
A new tail-calling interpreter
215+
------------------------------
216+
217+
A new type of interpreter based on tail calls has been added to CPython.
218+
For certain newer compilers, this interpreter provides
219+
significantly better performance. Preliminary numbers on our machines suggest
220+
anywhere from -3% to 30% faster Python code, and a geometric mean of 9-15%
221+
faster on ``pyperformance`` depending on platform and architecture.
222+
223+
This interpreter currently only works with Clang 19 and newer
224+
on x86-64 and AArch64 architectures. However, we expect
225+
that a future release of GCC will support this as well.
226+
227+
This feature is opt-in for now. We highly recommend enabling profile-guided
228+
optimization with the new interpreter as it is the only configuration we have
229+
tested and can validate its improved performance.
230+
For further information on how to build Python, see
231+
:option:`--with-tail-call-interp`.
232+
233+
.. note::
234+
235+
This is not to be confused with `tail call optimization`__ of Python
236+
functions, which is currently not implemented in CPython.
237+
238+
__ https://en.wikipedia.org/wiki/Tail_call
239+
240+
(Contributed by Ken Jin in :gh:`128718`, with ideas on how to implement this
241+
in CPython by Mark Shannon, Garret Gu, Haoran Xu, and Josh Haberman.)
242+
211243

212244
Other language changes
213245
======================

Lib/test/test_asyncio/test_tasks.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2757,7 +2757,6 @@ async def func():
27572757
# Add patched Task & Future back to the test case
27582758
cls.Task = Task
27592759
cls.Future = Future
2760-
cls.all_tasks = tasks.all_tasks
27612760

27622761
# Add an extra unit-test
27632762
cls.test_subclasses_ctask_cfuture = test_subclasses_ctask_cfuture
@@ -2883,7 +2882,7 @@ class PyTask_CFutureSubclass_Tests(BaseTaskTests, test_utils.TestCase):
28832882

28842883
Future = getattr(futures, '_CFuture', None)
28852884
Task = tasks._PyTask
2886-
all_tasks = tasks._py_all_tasks
2885+
all_tasks = staticmethod(tasks._py_all_tasks)
28872886

28882887

28892888
@unittest.skipUnless(hasattr(tasks, '_CTask'),
@@ -2916,7 +2915,7 @@ class PyTask_PyFuture_Tests(BaseTaskTests, SetMethodsTest,
29162915
class PyTask_PyFuture_SubclassTests(BaseTaskTests, test_utils.TestCase):
29172916
Task = tasks._PyTask
29182917
Future = futures._PyFuture
2919-
2918+
all_tasks = staticmethod(tasks._py_all_tasks)
29202919

29212920
@unittest.skipUnless(hasattr(tasks, '_CTask'),
29222921
'requires the C _asyncio module')

0 commit comments

Comments
 (0)