Skip to content

Commit b430f7b

Browse files
committed
Merge remote-tracking branch 'upstream/main' into cpython-enable-gil
2 parents 2d8c2b2 + b4bdf83 commit b430f7b

52 files changed

Lines changed: 1301 additions & 572 deletions

Some content is hidden

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

.github/workflows/build.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ jobs:
208208
with:
209209
config_hash: ${{ needs.check_source.outputs.config_hash }}
210210
# macos-14 is M1, macos-13 is Intel
211-
os-matrix: '["macos-14", "macos-13"]'
211+
os-matrix: '["macos-14-xlarge", "macos-13-large"]'
212212

213213
build_macos_free_threading:
214214
name: 'macOS (free-threading)'
@@ -218,8 +218,8 @@ jobs:
218218
with:
219219
config_hash: ${{ needs.check_source.outputs.config_hash }}
220220
free-threading: true
221-
# macos-14 is M1
222-
os-matrix: '["macos-14"]'
221+
# macos-14-large is Intel with 12 cores (most parallelism)
222+
os-matrix: '["macos-14-large"]'
223223

224224
build_ubuntu:
225225
name: 'Ubuntu'

.github/workflows/jit.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
jit:
2424
name: ${{ matrix.target }} (${{ matrix.debug && 'Debug' || 'Release' }})
2525
runs-on: ${{ matrix.runner }}
26-
timeout-minutes: 75
26+
timeout-minutes: 90
2727
strategy:
2828
fail-fast: false
2929
matrix:

.github/workflows/reusable-macos.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ jobs:
5050
--prefix=/opt/python-dev \
5151
--with-openssl="$(brew --prefix openssl@3.0)"
5252
- name: Build CPython
53-
run: make -j4
53+
run: make -j8
5454
- name: Display build info
5555
run: make pythoninfo
5656
- name: Tests

Doc/library/ast.rst

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ Node classes
6161

6262
.. attribute:: _fields
6363

64-
Each concrete class has an attribute :attr:`_fields` which gives the names
64+
Each concrete class has an attribute :attr:`!_fields` which gives the names
6565
of all child nodes.
6666

6767
Each instance of a concrete class has one attribute for each child node,
@@ -74,6 +74,18 @@ Node classes
7474
as Python lists. All possible attributes must be present and have valid
7575
values when compiling an AST with :func:`compile`.
7676

77+
.. attribute:: _field_types
78+
79+
The :attr:`!_field_types` attribute on each concrete class is a dictionary
80+
mapping field names (as also listed in :attr:`_fields`) to their types.
81+
82+
.. doctest::
83+
84+
>>> ast.TypeVar._field_types
85+
{'name': <class 'str'>, 'bound': ast.expr | None, 'default_value': ast.expr | None}
86+
87+
.. versionadded:: 3.13
88+
7789
.. attribute:: lineno
7890
col_offset
7991
end_lineno

Doc/library/typing.rst

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3648,8 +3648,14 @@ Aliases to asynchronous ABCs in :mod:`collections.abc`
36483648
is no ``ReturnType`` type parameter. As with :class:`Generator`, the
36493649
``SendType`` behaves contravariantly.
36503650

3651-
If your generator will only yield values, set the ``SendType`` to
3652-
``None``::
3651+
The ``SendType`` defaults to :const:`!None`::
3652+
3653+
async def infinite_stream(start: int) -> AsyncGenerator[int]:
3654+
while True:
3655+
yield start
3656+
start = await increment(start)
3657+
3658+
It is also possible to set this type explicitly::
36533659

36543660
async def infinite_stream(start: int) -> AsyncGenerator[int, None]:
36553661
while True:
@@ -3671,6 +3677,9 @@ Aliases to asynchronous ABCs in :mod:`collections.abc`
36713677
now supports subscripting (``[]``).
36723678
See :pep:`585` and :ref:`types-genericalias`.
36733679

3680+
.. versionchanged:: 3.13
3681+
The ``SendType`` parameter now has a default.
3682+
36743683
.. class:: AsyncIterable(Generic[T_co])
36753684

36763685
Deprecated alias to :class:`collections.abc.AsyncIterable`.
@@ -3754,8 +3763,14 @@ Aliases to other ABCs in :mod:`collections.abc`
37543763
of :class:`Generator` behaves contravariantly, not covariantly or
37553764
invariantly.
37563765

3757-
If your generator will only yield values, set the ``SendType`` and
3758-
``ReturnType`` to ``None``::
3766+
The ``SendType`` and ``ReturnType`` parameters default to :const:`!None`::
3767+
3768+
def infinite_stream(start: int) -> Generator[int]:
3769+
while True:
3770+
yield start
3771+
start += 1
3772+
3773+
It is also possible to set these types explicitly::
37593774

37603775
def infinite_stream(start: int) -> Generator[int, None, None]:
37613776
while True:
@@ -3774,6 +3789,9 @@ Aliases to other ABCs in :mod:`collections.abc`
37743789
:class:`collections.abc.Generator` now supports subscripting (``[]``).
37753790
See :pep:`585` and :ref:`types-genericalias`.
37763791

3792+
.. versionchanged:: 3.13
3793+
Default values for the send and return types were added.
3794+
37773795
.. class:: Hashable
37783796

37793797
Deprecated alias to :class:`collections.abc.Hashable`.

Doc/whatsnew/3.13.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,12 @@ ast
384384
argument that does not map to a field on the AST node is now deprecated,
385385
and will raise an exception in Python 3.15.
386386

387+
These changes do not apply to user-defined subclasses of :class:`ast.AST`,
388+
unless the class opts in to the new behavior by setting the attribute
389+
:attr:`ast.AST._field_types`.
390+
391+
(Contributed by Jelle Zijlstra in :gh:`105858` and :gh:`117486`.)
392+
387393
* :func:`ast.parse` now accepts an optional argument *optimize*
388394
which is passed on to the :func:`compile` built-in. This makes it
389395
possible to obtain an optimized AST.

Include/cpython/optimizer.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,16 +141,22 @@ void _Py_ExecutorDetach(_PyExecutorObject *);
141141
void _Py_BloomFilter_Init(_PyBloomFilter *);
142142
void _Py_BloomFilter_Add(_PyBloomFilter *bloom, void *obj);
143143
PyAPI_FUNC(void) _Py_Executor_DependsOn(_PyExecutorObject *executor, void *obj);
144-
PyAPI_FUNC(void) _Py_Executors_InvalidateDependency(PyInterpreterState *interp, void *obj, int is_invalidation);
145-
PyAPI_FUNC(void) _Py_Executors_InvalidateAll(PyInterpreterState *interp, int is_invalidation);
146-
147144
/* For testing */
148145
PyAPI_FUNC(PyObject *)PyUnstable_Optimizer_NewCounter(void);
149146
PyAPI_FUNC(PyObject *)PyUnstable_Optimizer_NewUOpOptimizer(void);
150147

151148
#define _Py_MAX_ALLOWED_BUILTINS_MODIFICATIONS 3
152149
#define _Py_MAX_ALLOWED_GLOBALS_MODIFICATIONS 6
153150

151+
#ifdef _Py_TIER2
152+
PyAPI_FUNC(void) _Py_Executors_InvalidateDependency(PyInterpreterState *interp, void *obj, int is_invalidation);
153+
PyAPI_FUNC(void) _Py_Executors_InvalidateAll(PyInterpreterState *interp, int is_invalidation);
154+
#else
155+
# define _Py_Executors_InvalidateDependency(A, B, C) ((void)0)
156+
# define _Py_Executors_InvalidateAll(A, B) ((void)0)
157+
#endif
158+
159+
154160
#ifdef __cplusplus
155161
}
156162
#endif

Include/cpython/pystate.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ struct _ts {
188188

189189
PyObject *previous_executor;
190190

191+
uint64_t dict_global_version;
191192
};
192193

193194
#ifdef Py_DEBUG

Include/internal/pycore_code.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ extern "C" {
88
# error "this header requires Py_BUILD_CORE define"
99
#endif
1010

11+
#include "pycore_lock.h" // PyMutex
12+
1113

1214
// We hide some of the newer PyCodeObject fields behind macros.
1315
// This helps with backporting certain changes to 3.12.
@@ -16,6 +18,14 @@ extern "C" {
1618
#define _PyCode_HAS_INSTRUMENTATION(CODE) \
1719
(CODE->_co_instrumentation_version > 0)
1820

21+
struct _py_code_state {
22+
PyMutex mutex;
23+
// Interned constants from code objects. Used by the free-threaded build.
24+
struct _Py_hashtable_t *constants;
25+
};
26+
27+
extern PyStatus _PyCode_Init(PyInterpreterState *interp);
28+
extern void _PyCode_Fini(PyInterpreterState *interp);
1929

2030
#define CODE_MAX_WATCHERS 8
2131

Include/internal/pycore_dict.h

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,10 @@ PyAPI_FUNC(PyObject *)_PyDict_LoadGlobal(PyDictObject *, PyDictObject *, PyObjec
105105

106106
/* Consumes references to key and value */
107107
PyAPI_FUNC(int) _PyDict_SetItem_Take2(PyDictObject *op, PyObject *key, PyObject *value);
108-
extern int _PyObjectDict_SetItem(PyTypeObject *tp, PyObject **dictptr, PyObject *name, PyObject *value);
109108
extern int _PyDict_SetItem_LockHeld(PyDictObject *dict, PyObject *name, PyObject *value);
110109
extern int _PyDict_GetItemRef_Unicode_LockHeld(PyDictObject *op, PyObject *key, PyObject **result);
111110
extern int _PyDict_GetItemRef_KnownHash(PyDictObject *op, PyObject *key, Py_hash_t hash, PyObject **result);
111+
extern int _PyObjectDict_SetItem(PyTypeObject *tp, PyObject *obj, PyObject **dictptr, PyObject *name, PyObject *value);
112112

113113
extern int _PyDict_Pop_KnownHash(
114114
PyDictObject *dict,
@@ -221,8 +221,25 @@ static inline PyDictUnicodeEntry* DK_UNICODE_ENTRIES(PyDictKeysObject *dk) {
221221
#define DICT_WATCHER_AND_MODIFICATION_MASK ((1 << (DICT_MAX_WATCHERS + DICT_WATCHED_MUTATION_BITS)) - 1)
222222

223223
#ifdef Py_GIL_DISABLED
224-
#define DICT_NEXT_VERSION(INTERP) \
225-
(_Py_atomic_add_uint64(&(INTERP)->dict_state.global_version, DICT_VERSION_INCREMENT) + DICT_VERSION_INCREMENT)
224+
225+
#define THREAD_LOCAL_DICT_VERSION_COUNT 256
226+
#define THREAD_LOCAL_DICT_VERSION_BATCH THREAD_LOCAL_DICT_VERSION_COUNT * DICT_VERSION_INCREMENT
227+
228+
static inline uint64_t
229+
dict_next_version(PyInterpreterState *interp)
230+
{
231+
PyThreadState *tstate = PyThreadState_GET();
232+
uint64_t cur_progress = (tstate->dict_global_version &
233+
(THREAD_LOCAL_DICT_VERSION_BATCH - 1));
234+
if (cur_progress == 0) {
235+
uint64_t next = _Py_atomic_add_uint64(&interp->dict_state.global_version,
236+
THREAD_LOCAL_DICT_VERSION_BATCH);
237+
tstate->dict_global_version = next;
238+
}
239+
return tstate->dict_global_version += DICT_VERSION_INCREMENT;
240+
}
241+
242+
#define DICT_NEXT_VERSION(INTERP) dict_next_version(INTERP)
226243

227244
#else
228245
#define DICT_NEXT_VERSION(INTERP) \

0 commit comments

Comments
 (0)