Skip to content

Commit 8862b83

Browse files
authored
Merge branch 'main' into fix/ubsan/exceptions-111178
2 parents 7906e3b + 624b93e commit 8862b83

File tree

81 files changed

+3118
-3091
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+3118
-3091
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,13 +247,13 @@ jobs:
247247
- true
248248
os:
249249
- ubuntu-24.04
250-
- ubuntu-24.04-arm
250+
- ubuntu-22.04-arm
251251
exclude:
252252
# Do not test BOLT with free-threading, to conserve resources
253253
- bolt: true
254254
free-threading: true
255255
# BOLT currently crashes during instrumentation on aarch64
256-
- os: ubuntu-24.04-arm
256+
- os: ubuntu-22.04-arm
257257
bolt: true
258258
uses: ./.github/workflows/reusable-ubuntu.yml
259259
with:

.github/workflows/jit.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ jobs:
8686
runner: ubuntu-24.04
8787
- target: aarch64-unknown-linux-gnu/gcc
8888
architecture: aarch64
89-
runner: ubuntu-24.04-arm
89+
runner: ubuntu-22.04-arm
9090
steps:
9191
- uses: actions/checkout@v4
9292
with:

.github/workflows/tail-call.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ jobs:
6262
runner: ubuntu-24.04
6363
- target: aarch64-unknown-linux-gnu/gcc
6464
architecture: aarch64
65-
runner: ubuntu-24.04-arm
65+
runner: ubuntu-22.04-arm
6666
steps:
6767
- uses: actions/checkout@v4
6868
with:

Doc/library/ctypes.rst

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1406,6 +1406,28 @@ the shared library name at development time, and hardcode that into the wrapper
14061406
module instead of using :func:`~ctypes.util.find_library` to locate the library at runtime.
14071407

14081408

1409+
.. _ctypes-listing-loaded-shared-libraries:
1410+
1411+
Listing loaded shared libraries
1412+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1413+
1414+
When writing code that relies on code loaded from shared libraries, it can be
1415+
useful to know which shared libraries have already been loaded into the current
1416+
process.
1417+
1418+
The :mod:`!ctypes.util` module provides the :func:`~ctypes.util.dllist` function,
1419+
which calls the different APIs provided by the various platforms to help determine
1420+
which shared libraries have already been loaded into the current process.
1421+
1422+
The exact output of this function will be system dependent. On most platforms,
1423+
the first entry of this list represents the current process itself, which may
1424+
be an empty string.
1425+
For example, on glibc-based Linux, the return may look like::
1426+
1427+
>>> from ctypes.util import dllist
1428+
>>> dllist()
1429+
['', 'linux-vdso.so.1', '/lib/x86_64-linux-gnu/libm.so.6', '/lib/x86_64-linux-gnu/libc.so.6', ... ]
1430+
14091431
.. _ctypes-loading-shared-libraries:
14101432

14111433
Loading shared libraries
@@ -2083,6 +2105,20 @@ Utility functions
20832105
.. availability:: Windows
20842106

20852107

2108+
.. function:: dllist()
2109+
:module: ctypes.util
2110+
2111+
Try to provide a list of paths of the shared libraries loaded into the current
2112+
process. These paths are not normalized or processed in any way. The function
2113+
can raise :exc:`OSError` if the underlying platform APIs fail.
2114+
The exact functionality is system dependent.
2115+
2116+
On most platforms, the first element of the list represents the current
2117+
executable file. It may be an empty string.
2118+
2119+
.. availability:: Windows, macOS, iOS, glibc, BSD libc, musl
2120+
.. versionadded:: next
2121+
20862122
.. function:: FormatError([code])
20872123

20882124
Returns a textual description of the error code *code*. If no error code is

Doc/library/dis.rst

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -703,15 +703,8 @@ not have to be) the original ``STACK[-2]``.
703703
STACK.append(lhs op rhs)
704704

705705
.. versionadded:: 3.11
706-
707-
708-
.. opcode:: BINARY_SUBSCR
709-
710-
Implements::
711-
712-
key = STACK.pop()
713-
container = STACK.pop()
714-
STACK.append(container[key])
706+
.. versionchanged:: 3.14
707+
With oparg :``NB_SUBSCR``, implements binary subscript (replaces opcode ``BINARY_SUBSCR``)
715708

716709

717710
.. opcode:: STORE_SUBSCR

Doc/library/pathlib.rst

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,6 +1177,38 @@ Querying file type and status
11771177
.. versionadded:: 3.5
11781178

11791179

1180+
.. attribute:: Path.info
1181+
1182+
A :class:`~pathlib.types.PathInfo` object that supports querying file type
1183+
information. The object exposes methods that cache their results, which can
1184+
help reduce the number of system calls needed when switching on file type.
1185+
For example::
1186+
1187+
>>> p = Path('src')
1188+
>>> if p.info.is_symlink():
1189+
... print('symlink')
1190+
... elif p.info.is_dir():
1191+
... print('directory')
1192+
... elif p.info.exists():
1193+
... print('something else')
1194+
... else:
1195+
... print('not found')
1196+
...
1197+
directory
1198+
1199+
If the path was generated from :meth:`Path.iterdir` then this attribute is
1200+
initialized with some information about the file type gleaned from scanning
1201+
the parent directory. Merely accessing :attr:`Path.info` does not perform
1202+
any filesystem queries.
1203+
1204+
To fetch up-to-date information, it's best to call :meth:`Path.is_dir`,
1205+
:meth:`~Path.is_file` and :meth:`~Path.is_symlink` rather than methods of
1206+
this attribute. There is no way to reset the cache; instead you can create
1207+
a new path object with an empty info cache via ``p = Path(p)``.
1208+
1209+
.. versionadded:: 3.14
1210+
1211+
11801212
Reading and writing files
11811213
^^^^^^^^^^^^^^^^^^^^^^^^^
11821214

@@ -1903,3 +1935,56 @@ Below is a table mapping various :mod:`os` functions to their corresponding
19031935
.. [4] :func:`os.walk` always follows symlinks when categorizing paths into
19041936
*dirnames* and *filenames*, whereas :meth:`Path.walk` categorizes all
19051937
symlinks into *filenames* when *follow_symlinks* is false (the default.)
1938+
1939+
1940+
Protocols
1941+
---------
1942+
1943+
.. module:: pathlib.types
1944+
:synopsis: pathlib types for static type checking
1945+
1946+
1947+
The :mod:`pathlib.types` module provides types for static type checking.
1948+
1949+
.. versionadded:: 3.14
1950+
1951+
1952+
.. class:: PathInfo()
1953+
1954+
A :class:`typing.Protocol` describing the
1955+
:attr:`Path.info <pathlib.Path.info>` attribute. Implementations may
1956+
return cached results from their methods.
1957+
1958+
.. method:: exists(*, follow_symlinks=True)
1959+
1960+
Return ``True`` if the path is an existing file or directory, or any
1961+
other kind of file; return ``False`` if the path doesn't exist.
1962+
1963+
If *follow_symlinks* is ``False``, return ``True`` for symlinks without
1964+
checking if their targets exist.
1965+
1966+
.. method:: is_dir(*, follow_symlinks=True)
1967+
1968+
Return ``True`` if the path is a directory, or a symbolic link pointing
1969+
to a directory; return ``False`` if the path is (or points to) any other
1970+
kind of file, or if it doesn't exist.
1971+
1972+
If *follow_symlinks* is ``False``, return ``True`` only if the path
1973+
is a directory (without following symlinks); return ``False`` if the
1974+
path is any other kind of file, or if it doesn't exist.
1975+
1976+
.. method:: is_file(*, follow_symlinks=True)
1977+
1978+
Return ``True`` if the path is a file, or a symbolic link pointing to
1979+
a file; return ``False`` if the path is (or points to) a directory or
1980+
other non-file, or if it doesn't exist.
1981+
1982+
If *follow_symlinks* is ``False``, return ``True`` only if the path
1983+
is a file (without following symlinks); return ``False`` if the path
1984+
is a directory or other other non-file, or if it doesn't exist.
1985+
1986+
.. method:: is_symlink()
1987+
1988+
Return ``True`` if the path is a symbolic link (even if broken); return
1989+
``False`` if the path is a directory or any kind of file, or if it
1990+
doesn't exist.

Doc/library/pdb.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,17 @@ can be overridden by the local file.
697697
.. pdbcommand:: q(uit)
698698

699699
Quit from the debugger. The program being executed is aborted.
700+
An end-of-file input is equivalent to :pdbcmd:`quit`.
701+
702+
A confirmation prompt will be shown if the debugger is invoked in
703+
``'inline'`` mode. Either ``y``, ``Y``, ``<Enter>`` or ``EOF``
704+
will confirm the quit.
705+
706+
.. versionchanged:: 3.14
707+
A confirmation prompt will be shown if the debugger is invoked in
708+
``'inline'`` mode. After the confirmation, the debugger will call
709+
:func:`sys.exit` immediately, instead of raising :exc:`bdb.BdbQuit`
710+
in the next trace event.
700711

701712
.. pdbcommand:: debug code
702713

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: 55 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 type of 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 type of 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, Garrett Gu, Haoran Xu, and Josh Haberman.)
242+
211243

212244
Other language changes
213245
======================
@@ -357,6 +389,9 @@ ctypes
357389
complex C types.
358390
(Contributed by Sergey B Kirpichev in :gh:`61103`).
359391

392+
* Add :func:`ctypes.util.dllist` for listing the shared libraries
393+
loaded by the current process.
394+
(Contributed by Brian Ward in :gh:`119349`.)
360395

361396
datetime
362397
--------
@@ -585,6 +620,15 @@ pathlib
585620

586621
(Contributed by Barney Gale in :gh:`73991`.)
587622

623+
* Add :attr:`pathlib.Path.info` attribute, which stores an object
624+
implementing the :class:`pathlib.types.PathInfo` protocol (also new). The
625+
object supports querying the file type and internally caching
626+
:func:`~os.stat` results. Path objects generated by
627+
:meth:`~pathlib.Path.iterdir` are initialized with file type information
628+
gleaned from scanning the parent directory.
629+
630+
(Contributed by Barney Gale in :gh:`125413`.)
631+
588632

589633
pdb
590634
---
@@ -600,6 +644,11 @@ pdb
600644
command when :mod:`pdb` is in ``inline`` mode.
601645
(Contributed by Tian Gao in :gh:`123757`.)
602646

647+
* A confirmation prompt will be shown when the user tries to quit :mod:`pdb`
648+
in ``inline`` mode. ``y``, ``Y``, ``<Enter>`` or ``EOF`` will confirm
649+
the quit and call :func:`sys.exit`, instead of raising :exc:`bdb.BdbQuit`.
650+
(Contributed by Tian Gao in :gh:`124704`.)
651+
603652

604653
pickle
605654
------
@@ -1167,6 +1216,12 @@ Others
11671216
:meth:`~object.__index__`. (Contributed by Mark Dickinson in :gh:`119743`.)
11681217

11691218

1219+
CPython Bytecode Changes
1220+
========================
1221+
1222+
* Replaced the opcode ``BINARY_SUBSCR`` by :opcode:`BINARY_OP` with oparg ``NB_SUBSCR``.
1223+
(Contributed by Irit Katriel in :gh:`100239`.)
1224+
11701225
Porting to Python 3.14
11711226
======================
11721227

Include/cpython/pystats.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ typedef struct _optimization_stats {
129129
uint64_t inner_loop;
130130
uint64_t recursive_call;
131131
uint64_t low_confidence;
132+
uint64_t unknown_callee;
132133
uint64_t executors_invalidated;
133134
UOpStats opcode[PYSTATS_MAX_UOP_ID + 1];
134135
uint64_t unsupported_opcode[256];

0 commit comments

Comments
 (0)