Skip to content

Commit 8df9aed

Browse files
Merge remote-tracking branch 'upstream/main' into jit_ft
2 parents aff296a + 9525911 commit 8df9aed

File tree

94 files changed

+2597
-1593
lines changed

Some content is hidden

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

94 files changed

+2597
-1593
lines changed

Doc/c-api/apiabiversion.rst

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,23 @@ See :ref:`stable` for a discussion of API and ABI stability across versions.
3434
This can be ``0xA`` for alpha, ``0xB`` for beta, ``0xC`` for release
3535
candidate or ``0xF`` for final.
3636

37+
38+
.. c:namespace:: NULL
39+
.. c:macro:: PY_RELEASE_LEVEL_ALPHA
40+
:no-typesetting:
41+
.. c:macro:: PY_RELEASE_LEVEL_BETA
42+
:no-typesetting:
43+
.. c:macro:: PY_RELEASE_LEVEL_GAMMA
44+
:no-typesetting:
45+
.. c:macro:: PY_RELEASE_LEVEL_FINAL
46+
:no-typesetting:
47+
48+
For completeness, the values are available as macros:
49+
:c:macro:`!PY_RELEASE_LEVEL_ALPHA` (``0xA``),
50+
:c:macro:`!PY_RELEASE_LEVEL_BETA` (``0xB``),
51+
:c:macro:`!PY_RELEASE_LEVEL_GAMMA` (``0xC``), and
52+
:c:macro:`!PY_RELEASE_LEVEL_FINAL` (``0xF``).
53+
3754
.. c:macro:: PY_RELEASE_SERIAL
3855
3956
The ``2`` in ``3.4.1a2``. Zero for final releases.
@@ -46,6 +63,10 @@ See :ref:`stable` for a discussion of API and ABI stability across versions.
4663
Use this for numeric comparisons, for example,
4764
``#if PY_VERSION_HEX >= ...``.
4865

66+
.. c:macro:: PY_VERSION
67+
68+
The Python version as a string, for example, ``"3.4.1a2"``.
69+
4970

5071
Run-time version
5172
----------------

Doc/c-api/module.rst

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -820,15 +820,18 @@ struct:
820820
.. versionadded:: 3.5
821821
822822
.. c:macro:: PYTHON_API_VERSION
823+
PYTHON_API_STRING
823824
824-
The C API version. Defined for backwards compatibility.
825+
The C API version, as an integer (``1013``) and string (``"1013"``), respectively.
826+
Defined for backwards compatibility.
825827
826828
Currently, this constant is not updated in new Python versions, and is not
827829
useful for versioning. This may change in the future.
828830
829831
.. c:macro:: PYTHON_ABI_VERSION
832+
PYTHON_ABI_STRING
830833
831-
Defined as ``3`` for backwards compatibility.
834+
Defined as ``3`` and ``"3"``, respectively, for backwards compatibility.
832835
833836
Currently, this constant is not updated in new Python versions, and is not
834837
useful for versioning. This may change in the future.

Doc/library/concurrent.futures.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ or separate processes, using :class:`ProcessPoolExecutor`.
2121
Each implements the same interface, which is defined
2222
by the abstract :class:`Executor` class.
2323

24+
:class:`concurrent.futures.Future` must not be confused with
25+
:class:`asyncio.Future`, which is designed for use with :mod:`asyncio`
26+
tasks and coroutines. See the :doc:`asyncio's Future <asyncio-future>`
27+
documentation for a detailed comparison of the two.
28+
2429
.. include:: ../includes/wasm-notavail.rst
2530

2631
Executor Objects

Doc/library/importlib.resources.abc.rst

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,14 @@
6363
If the resource does not concretely exist on the file system,
6464
raise :exc:`FileNotFoundError`.
6565

66-
.. method:: is_resource(name)
66+
.. method:: is_resource(path)
6767
:abstractmethod:
6868

69-
Returns ``True`` if the named *name* is considered a resource.
70-
:exc:`FileNotFoundError` is raised if *name* does not exist.
69+
Returns ``True`` if the named *path* is considered a resource.
70+
:exc:`FileNotFoundError` is raised if *path* does not exist.
71+
72+
.. versionchanged:: 3.10
73+
The argument *name* was renamed to *path*.
7174

7275
.. method:: contents()
7376
:abstractmethod:

Doc/library/importlib.rst

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -210,12 +210,6 @@ Functions
210210
:exc:`ModuleNotFoundError` is raised when the module being reloaded lacks
211211
a :class:`~importlib.machinery.ModuleSpec`.
212212

213-
.. versionchanged:: 3.15
214-
If *module* is a lazy module that has not yet been materialized (i.e.,
215-
loaded via :class:`importlib.util.LazyLoader` and not yet accessed),
216-
calling :func:`reload` is a no-op and returns the module unchanged.
217-
This prevents the reload from unintentionally triggering the lazy load.
218-
219213
.. warning::
220214
This function is not thread-safe. Calling it from multiple threads can result
221215
in unexpected behavior. It's recommended to use the :class:`threading.Lock`

Doc/library/stdtypes.rst

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2369,7 +2369,9 @@ expression support in the :mod:`re` module).
23692369

23702370
If the string starts with the *prefix* string, return
23712371
``string[len(prefix):]``. Otherwise, return a copy of the original
2372-
string::
2372+
string:
2373+
2374+
.. doctest::
23732375

23742376
>>> 'TestHook'.removeprefix('Test')
23752377
'Hook'
@@ -2378,12 +2380,16 @@ expression support in the :mod:`re` module).
23782380

23792381
.. versionadded:: 3.9
23802382

2383+
See also :meth:`removesuffix` and :meth:`startswith`.
2384+
23812385

23822386
.. method:: str.removesuffix(suffix, /)
23832387

23842388
If the string ends with the *suffix* string and that *suffix* is not empty,
23852389
return ``string[:-len(suffix)]``. Otherwise, return a copy of the
2386-
original string::
2390+
original string:
2391+
2392+
.. doctest::
23872393

23882394
>>> 'MiscTests'.removesuffix('Tests')
23892395
'Misc'
@@ -2392,12 +2398,22 @@ expression support in the :mod:`re` module).
23922398

23932399
.. versionadded:: 3.9
23942400

2401+
See also :meth:`removeprefix` and :meth:`endswith`.
2402+
23952403

23962404
.. method:: str.replace(old, new, /, count=-1)
23972405

23982406
Return a copy of the string with all occurrences of substring *old* replaced by
23992407
*new*. If *count* is given, only the first *count* occurrences are replaced.
24002408
If *count* is not specified or ``-1``, then all occurrences are replaced.
2409+
For example:
2410+
2411+
.. doctest::
2412+
2413+
>>> 'spam, spam, spam'.replace('spam', 'eggs')
2414+
'eggs, eggs, eggs'
2415+
>>> 'spam, spam, spam'.replace('spam', 'eggs', 1)
2416+
'eggs, spam, spam'
24012417

24022418
.. versionchanged:: 3.13
24032419
*count* is now supported as a keyword argument.
@@ -2408,6 +2424,16 @@ expression support in the :mod:`re` module).
24082424
Return the highest index in the string where substring *sub* is found, such
24092425
that *sub* is contained within ``s[start:end]``. Optional arguments *start*
24102426
and *end* are interpreted as in slice notation. Return ``-1`` on failure.
2427+
For example:
2428+
2429+
.. doctest::
2430+
2431+
>>> 'spam, spam, spam'.rfind('sp')
2432+
12
2433+
>>> 'spam, spam, spam'.rfind('sp', 0, 10)
2434+
6
2435+
2436+
See also :meth:`find` and :meth:`rindex`.
24112437

24122438

24132439
.. method:: str.rindex(sub[, start[, end]])

Doc/library/test.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,12 @@ The :mod:`test.support` module defines the following functions:
492492
tests.
493493

494494

495+
.. function:: get_resource_value(resource)
496+
497+
Return the value specified for *resource* (as :samp:`-u {resource}={value}`).
498+
Return ``None`` if *resource* is disabled or no value is specified.
499+
500+
495501
.. function:: python_is_optimized()
496502

497503
Return ``True`` if Python was not built with ``-O0`` or ``-Og``.

Include/internal/pycore_genobject.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ PyGenObject *_PyGen_GetGeneratorFromFrame(_PyInterpreterFrame *frame)
2222
}
2323

2424
PyAPI_FUNC(PyObject *)_PyGen_yf(PyGenObject *);
25-
extern void _PyGen_Finalize(PyObject *self);
25+
extern int _PyGen_ClearFrame(PyGenObject *self);
2626

2727
// Export for '_asyncio' shared extension
2828
PyAPI_FUNC(int) _PyGen_SetStopIterationValue(PyObject *);

Include/internal/pycore_optimizer.h

Lines changed: 3 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ extern "C" {
1212
#include "pycore_uop.h" // _PyUOpInstruction
1313
#include "pycore_uop_ids.h"
1414
#include "pycore_stackref.h" // _PyStackRef
15+
#include "pycore_optimizer_types.h"
1516
#include <stdbool.h>
1617

1718

@@ -86,7 +87,7 @@ PyAPI_FUNC(void) _Py_Executors_InvalidateCold(PyInterpreterState *interp);
8687
#define JIT_CLEANUP_THRESHOLD 1000
8788

8889
int _Py_uop_analyze_and_optimize(
89-
PyFunctionObject *func,
90+
_PyThreadStateImpl *tstate,
9091
_PyUOpInstruction *trace, int trace_len, int curr_stackentries,
9192
_PyBloomFilter *dependencies);
9293

@@ -114,86 +115,6 @@ static inline uint16_t uop_get_error_target(const _PyUOpInstruction *inst)
114115
return inst->error_target;
115116
}
116117

117-
// Holds locals, stack, locals, stack ... co_consts (in that order)
118-
#define MAX_ABSTRACT_INTERP_SIZE 4096
119-
120-
#define TY_ARENA_SIZE (UOP_MAX_TRACE_LENGTH * 5)
121-
122-
// Need extras for root frame and for overflow frame (see TRACE_STACK_PUSH())
123-
#define MAX_ABSTRACT_FRAME_DEPTH (16)
124-
125-
// The maximum number of side exits that we can take before requiring forward
126-
// progress (and inserting a new ENTER_EXECUTOR instruction). In practice, this
127-
// is the "maximum amount of polymorphism" that an isolated trace tree can
128-
// handle before rejoining the rest of the program.
129-
#define MAX_CHAIN_DEPTH 4
130-
131-
/* Symbols */
132-
/* See explanation in optimizer_symbols.c */
133-
134-
135-
typedef enum _JitSymType {
136-
JIT_SYM_UNKNOWN_TAG = 1,
137-
JIT_SYM_NULL_TAG = 2,
138-
JIT_SYM_NON_NULL_TAG = 3,
139-
JIT_SYM_BOTTOM_TAG = 4,
140-
JIT_SYM_TYPE_VERSION_TAG = 5,
141-
JIT_SYM_KNOWN_CLASS_TAG = 6,
142-
JIT_SYM_KNOWN_VALUE_TAG = 7,
143-
JIT_SYM_TUPLE_TAG = 8,
144-
JIT_SYM_TRUTHINESS_TAG = 9,
145-
JIT_SYM_COMPACT_INT = 10,
146-
} JitSymType;
147-
148-
typedef struct _jit_opt_known_class {
149-
uint8_t tag;
150-
uint32_t version;
151-
PyTypeObject *type;
152-
} JitOptKnownClass;
153-
154-
typedef struct _jit_opt_known_version {
155-
uint8_t tag;
156-
uint32_t version;
157-
} JitOptKnownVersion;
158-
159-
typedef struct _jit_opt_known_value {
160-
uint8_t tag;
161-
PyObject *value;
162-
} JitOptKnownValue;
163-
164-
#define MAX_SYMBOLIC_TUPLE_SIZE 7
165-
166-
typedef struct _jit_opt_tuple {
167-
uint8_t tag;
168-
uint8_t length;
169-
uint16_t items[MAX_SYMBOLIC_TUPLE_SIZE];
170-
} JitOptTuple;
171-
172-
typedef struct {
173-
uint8_t tag;
174-
bool invert;
175-
uint16_t value;
176-
} JitOptTruthiness;
177-
178-
typedef struct {
179-
uint8_t tag;
180-
} JitOptCompactInt;
181-
182-
typedef union _jit_opt_symbol {
183-
uint8_t tag;
184-
JitOptKnownClass cls;
185-
JitOptKnownValue value;
186-
JitOptKnownVersion version;
187-
JitOptTuple tuple;
188-
JitOptTruthiness truthiness;
189-
JitOptCompactInt compact;
190-
} JitOptSymbol;
191-
192-
193-
// This mimics the _PyStackRef API
194-
typedef union {
195-
uintptr_t bits;
196-
} JitOptRef;
197118

198119
#define REF_IS_BORROWED 1
199120

@@ -240,48 +161,6 @@ PyJitRef_IsBorrowed(JitOptRef ref)
240161
return (ref.bits & REF_IS_BORROWED) == REF_IS_BORROWED;
241162
}
242163

243-
struct _Py_UOpsAbstractFrame {
244-
bool globals_watched;
245-
// The version number of the globals dicts, once checked. 0 if unchecked.
246-
uint32_t globals_checked_version;
247-
// Max stacklen
248-
int stack_len;
249-
int locals_len;
250-
PyFunctionObject *func;
251-
PyCodeObject *code;
252-
253-
JitOptRef *stack_pointer;
254-
JitOptRef *stack;
255-
JitOptRef *locals;
256-
};
257-
258-
typedef struct _Py_UOpsAbstractFrame _Py_UOpsAbstractFrame;
259-
260-
typedef struct ty_arena {
261-
int ty_curr_number;
262-
int ty_max_number;
263-
JitOptSymbol arena[TY_ARENA_SIZE];
264-
} ty_arena;
265-
266-
typedef struct _JitOptContext {
267-
char done;
268-
char out_of_space;
269-
bool contradiction;
270-
// Has the builtins dict been watched?
271-
bool builtins_watched;
272-
// The current "executing" frame.
273-
_Py_UOpsAbstractFrame *frame;
274-
_Py_UOpsAbstractFrame frames[MAX_ABSTRACT_FRAME_DEPTH];
275-
int curr_frame_depth;
276-
277-
// Arena for the symbolic types.
278-
ty_arena t_arena;
279-
280-
JitOptRef *n_consumed;
281-
JitOptRef *limit;
282-
JitOptRef locals_and_stack[MAX_ABSTRACT_INTERP_SIZE];
283-
} JitOptContext;
284-
285164
extern bool _Py_uop_sym_is_null(JitOptRef sym);
286165
extern bool _Py_uop_sym_is_not_null(JitOptRef sym);
287166
extern bool _Py_uop_sym_is_const(JitOptContext *ctx, JitOptRef sym);
@@ -357,6 +236,7 @@ _PyJit_TryInitializeTracing(PyThreadState *tstate, _PyInterpreterFrame *frame,
357236
int oparg);
358237

359238
void _PyJit_FinalizeTracing(PyThreadState *tstate);
239+
void _PyJit_TracerFree(_PyThreadStateImpl *_tstate);
360240

361241
void _PyJit_Tracer_InvalidateDependency(PyThreadState *old_tstate, void *obj);
362242

0 commit comments

Comments
 (0)