Skip to content

Commit 79d7e7f

Browse files
authored
Merge branch 'main' into main
2 parents 8c93ec8 + e872c19 commit 79d7e7f

File tree

14 files changed

+378
-262
lines changed

14 files changed

+378
-262
lines changed

Doc/c-api/set.rst

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ the constructor functions work with any iterable Python object.
8989
actually iterable. The constructor is also useful for copying a set
9090
(``c=set(s)``).
9191
92+
.. note::
93+
94+
The operation is atomic on :term:`free threading <free-threaded build>`
95+
when *iterable* is a :class:`set`, :class:`frozenset`, :class:`dict` or :class:`frozendict`.
96+
9297
9398
.. c:function:: PyObject* PyFrozenSet_New(PyObject *iterable)
9499
@@ -97,6 +102,11 @@ the constructor functions work with any iterable Python object.
97102
set on success or ``NULL`` on failure. Raise :exc:`TypeError` if *iterable* is
98103
not actually iterable.
99104
105+
.. note::
106+
107+
The operation is atomic on :term:`free threading <free-threaded build>`
108+
when *iterable* is a :class:`set`, :class:`frozenset`, :class:`dict` or :class:`frozendict`.
109+
100110
101111
The following functions and macros are available for instances of :class:`set`
102112
or :class:`frozenset` or instances of their subtypes.
@@ -124,6 +134,10 @@ or :class:`frozenset` or instances of their subtypes.
124134
the *key* is unhashable. Raise :exc:`SystemError` if *anyset* is not a
125135
:class:`set`, :class:`frozenset`, or an instance of a subtype.
126136
137+
.. note::
138+
139+
The operation is atomic on :term:`free threading <free-threaded build>`
140+
when *key* is :class:`str`, :class:`int`, :class:`float`, :class:`bool` or :class:`bytes`.
127141
128142
.. c:function:: int PySet_Add(PyObject *set, PyObject *key)
129143
@@ -135,6 +149,12 @@ or :class:`frozenset` or instances of their subtypes.
135149
:exc:`SystemError` if *set* is not an instance of :class:`set` or its
136150
subtype.
137151
152+
.. note::
153+
154+
The operation is atomic on :term:`free threading <free-threaded build>`
155+
when *key* is :class:`str`, :class:`int`, :class:`float`, :class:`bool` or :class:`bytes`.
156+
157+
138158
139159
The following functions are available for instances of :class:`set` or its
140160
subtypes but not for instances of :class:`frozenset` or its subtypes.
@@ -149,6 +169,11 @@ subtypes but not for instances of :class:`frozenset` or its subtypes.
149169
temporary frozensets. Raise :exc:`SystemError` if *set* is not an
150170
instance of :class:`set` or its subtype.
151171
172+
.. note::
173+
174+
The operation is atomic on :term:`free threading <free-threaded build>`
175+
when *key* is :class:`str`, :class:`int`, :class:`float`, :class:`bool` or :class:`bytes`.
176+
152177
153178
.. c:function:: PyObject* PySet_Pop(PyObject *set)
154179
@@ -164,6 +189,12 @@ subtypes but not for instances of :class:`frozenset` or its subtypes.
164189
success. Return ``-1`` and raise :exc:`SystemError` if *set* is not an instance of
165190
:class:`set` or its subtype.
166191
192+
.. note::
193+
194+
In the :term:`free-threaded build`, the set is emptied before its entries
195+
are cleared, so other threads will observe an empty set rather than
196+
intermediate states.
197+
167198
168199
Deprecated API
169200
^^^^^^^^^^^^^^

Doc/data/threadsafety.dat

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,29 @@ PyByteArray_GET_SIZE:atomic:
186186
PyByteArray_AsString:compatible:
187187
PyByteArray_AS_STRING:compatible:
188188

189+
# Creation - may iterate the iterable argument, calling arbitrary code.
190+
# Atomic for sets, frozensets, dicts, and frozendicts.
191+
PySet_New:shared:
192+
PyFrozenSet_New:shared:
193+
194+
# Size - uses atomic load on free-threaded builds
195+
PySet_Size:atomic:
196+
PySet_GET_SIZE:atomic:
197+
198+
# Contains - lock-free, atomic with simple types
199+
PySet_Contains:shared:
200+
201+
# Mutations - hold per-object lock for duration
202+
# atomic with simple types
203+
PySet_Add:shared:
204+
PySet_Discard:shared:
205+
206+
# Pop - hold per-object lock for duration
207+
PySet_Pop:atomic:
208+
209+
# Clear - empties the set before clearing
210+
PySet_Clear:atomic:
211+
189212
# Capsule objects (Doc/c-api/capsule.rst)
190213

191214
# Type check - read ob_type pointer, always safe

Doc/whatsnew/3.15.rst

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1428,7 +1428,6 @@ end users running Python do not need LLVM installed. Instructions for
14281428
installing LLVM can be found in the `JIT compiler documentation
14291429
<https://github.com/python/cpython/blob/main/Tools/jit/README.md>`__
14301430
for all supported platforms.
1431-
14321431
(Contributed by Savannah Ostrowski in :gh:`140973`.)
14331432

14341433
.. rubric:: A new tracing frontend
@@ -1440,7 +1439,6 @@ code. For example, simple Python object creation is now understood by the
14401439
supported. This was made possible by an overhauled JIT tracing frontend
14411440
that records actual execution paths through code, rather than estimating
14421441
them as the previous implementation did.
1443-
14441442
(Contributed by Ken Jin in :gh:`139109`. Support for Windows added by
14451443
Mark Shannon in :gh:`141703`.)
14461444

@@ -1450,35 +1448,40 @@ A basic form of register allocation has been added to the JIT compiler's
14501448
optimizer. This allows the JIT compiler to avoid certain stack operations
14511449
altogether and instead operate on registers. This allows the JIT to produce
14521450
more efficient traces by avoiding reads and writes to memory.
1453-
14541451
(Contributed by Mark Shannon in :gh:`135379`.)
14551452

14561453
.. rubric:: More JIT optimizations
14571454

14581455
More `constant-propagation <https://en.wikipedia.org/wiki/Constant_folding>`__
14591456
is now performed. This means when the JIT compiler detects that certain user
14601457
code results in constants, the code can be simplified by the JIT.
1461-
14621458
(Contributed by Ken Jin and Savannah Ostrowski in :gh:`132732`.)
14631459

1464-
The JIT avoids :term:`reference count`\ s where possible. This generally
1460+
:term:`Reference count`\ s are avoided whenever it is safe to do so. This generally
14651461
reduces the cost of most operations in Python.
1466-
14671462
(Contributed by Ken Jin, Donghee Na, Zheao Li, Hai Zhu, Savannah Ostrowski,
14681463
Reiden Ong, Noam Cohen, Tomas Roun, PuQing, Cajetan Rodrigues, and Sacul in :gh:`134584`.)
14691464

1465+
The JIT optimizer now supports significantly more operations than in 3.14.
1466+
(Contributed by Kumar Aditya, Ken Jin, and Sacul in :gh:`131798`.)
1467+
14701468
.. rubric:: Better machine code generation
14711469

14721470
The JIT compiler's machine code generator now produces better machine code
14731471
for x86-64 and AArch64 macOS and Linux targets. In general, users should
14741472
experience lower memory usage for generated machine code and more efficient
1475-
machine code versus the old JIT.
1476-
1473+
machine code versus 3.14.
14771474
(Contributed by Brandt Bucher in :gh:`136528` and :gh:`136528`.
14781475
Implementation for AArch64 contributed by Mark Shannon in :gh:`139855`.
14791476
Additional optimizations for AArch64 contributed by Mark Shannon and
14801477
Diego Russo in :gh:`140683` and :gh:`142305`.)
14811478

1479+
.. rubric:: Maintainability
1480+
1481+
The JIT optimizer's operations have been simplified.
1482+
This was made possible by a refactoring of JIT data structures.
1483+
(Contributed by Zhongtian Zheng in :gh:`148211` and Hai Zhu in :gh:`143421`.)
1484+
14821485

14831486
Removed
14841487
========

Include/internal/pycore_ceval.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -439,21 +439,21 @@ _Py_BuiltinCallFast_StackRef(
439439
int total_args);
440440

441441
PyAPI_FUNC(PyObject *)
442-
_Py_BuiltinCallFastWithKeywords_StackRefSteal(
442+
_Py_BuiltinCallFastWithKeywords_StackRef(
443443
_PyStackRef callable,
444444
_PyStackRef *arguments,
445445
int total_args);
446446

447447
PyAPI_FUNC(PyObject *)
448-
_PyCallMethodDescriptorFast_StackRefSteal(
448+
_PyCallMethodDescriptorFast_StackRef(
449449
_PyStackRef callable,
450450
PyCFunctionFast cfunc,
451451
PyObject *self,
452452
_PyStackRef *arguments,
453453
int total_args);
454454

455455
PyAPI_FUNC(PyObject *)
456-
_PyCallMethodDescriptorFastWithKeywords_StackRefSteal(
456+
_PyCallMethodDescriptorFastWithKeywords_StackRef(
457457
_PyStackRef callable,
458458
PyCFunctionFastWithKeywords cfunc,
459459
PyObject *self,

Include/internal/pycore_opcode_metadata.h

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

Include/internal/pycore_uop_ids.h

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

0 commit comments

Comments
 (0)