Skip to content

Commit 7bee1e9

Browse files
authored
Merge branch 'main' into subprocess-fast-wait
2 parents 300692e + 67535ab commit 7bee1e9

32 files changed

+1291
-860
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ Tools/wasm/config.site-wasm32-emscripten @freakboy3742 @emmatyping
176176
Tools/wasm/emscripten @freakboy3742 @emmatyping
177177

178178
# WebAssembly (WASI)
179+
Platforms/WASI @brettcannon @emmatyping @savannahostrowski
179180
Tools/wasm/wasi-env @brettcannon @emmatyping @savannahostrowski
180181
Tools/wasm/wasi.py @brettcannon @emmatyping @savannahostrowski
181182
Tools/wasm/wasi @brettcannon @emmatyping @savannahostrowski

.github/workflows/reusable-wasi.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,14 @@ jobs:
4747
- name: "Runner image version"
4848
run: echo "IMAGE_OS_VERSION=${ImageOS}-${ImageVersion}" >> "$GITHUB_ENV"
4949
- name: "Configure build Python"
50-
run: python3 Tools/wasm/wasi configure-build-python -- --config-cache --with-pydebug
50+
run: python3 Platforms/WASI configure-build-python -- --config-cache --with-pydebug
5151
- name: "Make build Python"
52-
run: python3 Tools/wasm/wasi make-build-python
52+
run: python3 Platforms/WASI make-build-python
5353
- name: "Configure host"
5454
# `--with-pydebug` inferred from configure-build-python
55-
run: python3 Tools/wasm/wasi configure-host -- --config-cache
55+
run: python3 Platforms/WASI configure-host -- --config-cache
5656
- name: "Make host"
57-
run: python3 Tools/wasm/wasi make-host
57+
run: python3 Platforms/WASI make-host
5858
- name: "Display build info"
5959
run: make --directory "${CROSS_BUILD_WASI}" pythoninfo
6060
- name: "Test"

Doc/c-api/conversion.rst

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ The following functions provide locale-independent string to number conversions.
130130
131131
*flags* can be zero or more of the following values or-ed together:
132132
133+
.. c:namespace:: NULL
134+
133135
.. c:macro:: Py_DTSF_SIGN
134136
135137
Always precede the returned string with a sign
@@ -151,9 +153,21 @@ The following functions provide locale-independent string to number conversions.
151153
152154
.. versionadded:: 3.11
153155
154-
If *ptype* is non-``NULL``, then the value it points to will be set to one of
155-
``Py_DTST_FINITE``, ``Py_DTST_INFINITE``, or ``Py_DTST_NAN``, signifying that
156-
*val* is a finite number, an infinite number, or not a number, respectively.
156+
If *ptype* is non-``NULL``, then the value it points to will be set to one
157+
of the following constants depending on the type of *val*:
158+
159+
.. list-table::
160+
:header-rows: 1
161+
:align: left
162+
163+
* - *\*ptype*
164+
- type of *val*
165+
* - .. c:macro:: Py_DTST_FINITE
166+
- finite number
167+
* - .. c:macro:: Py_DTST_INFINITE
168+
- infinite number
169+
* - .. c:macro:: Py_DTST_NAN
170+
- not a number
157171
158172
The return value is a pointer to *buffer* with the converted string or
159173
``NULL`` if the conversion failed. The caller is responsible for freeing the

Doc/howto/remote_debugging.rst

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@ execute Python code remotely.
88

99
Most platforms require elevated privileges to attach to another Python process.
1010

11+
Disabling remote debugging
12+
--------------------------
13+
14+
To disable remote debugging support, use any of the following:
15+
16+
* Set the :envvar:`PYTHON_DISABLE_REMOTE_DEBUG` environment variable to ``1`` before
17+
starting the interpreter.
18+
* Use the :option:`-X disable_remote_debug` command-line option.
19+
* Compile Python with the :option:`--without-remote-debug` build flag.
20+
1121
.. _permission-requirements:
1222

1323
Permission requirements
@@ -614,4 +624,3 @@ To inject and execute a Python script in a remote process:
614624
6. Set ``_PY_EVAL_PLEASE_STOP_BIT`` in the ``eval_breaker`` field.
615625
7. Resume the process (if suspended). The script will execute at the next safe
616626
evaluation point.
617-

Doc/library/sys.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1997,6 +1997,9 @@ always available. Unless explicitly noted otherwise, all variables are read-only
19971997
interpreter is pre-release (alpha, beta, or release candidate) then the
19981998
local and remote interpreters must be the same exact version.
19991999

2000+
See :ref:`remote-debugging` for more information about the remote debugging
2001+
mechanism.
2002+
20002003
.. audit-event:: sys.remote_exec pid script_path
20012004

20022005
When the code is executed in the remote process, an
@@ -2015,6 +2018,7 @@ always available. Unless explicitly noted otherwise, all variables are read-only
20152018

20162019
.. availability:: Unix, Windows.
20172020
.. versionadded:: 3.14
2021+
See :pep:`768` for more details.
20182022

20192023

20202024
.. function:: _enablelegacywindowsfsencoding()

Include/internal/pycore_optimizer.h

Lines changed: 95 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,102 @@ extern "C" {
1616
#include <stdbool.h>
1717

1818

19+
typedef struct _PyJitUopBuffer {
20+
_PyUOpInstruction *start;
21+
_PyUOpInstruction *next;
22+
_PyUOpInstruction *end;
23+
} _PyJitUopBuffer;
24+
25+
26+
typedef struct _JitOptContext {
27+
char done;
28+
char out_of_space;
29+
bool contradiction;
30+
// Has the builtins dict been watched?
31+
bool builtins_watched;
32+
// The current "executing" frame.
33+
_Py_UOpsAbstractFrame *frame;
34+
_Py_UOpsAbstractFrame frames[MAX_ABSTRACT_FRAME_DEPTH];
35+
int curr_frame_depth;
36+
37+
// Arena for the symbolic types.
38+
ty_arena t_arena;
39+
40+
JitOptRef *n_consumed;
41+
JitOptRef *limit;
42+
JitOptRef locals_and_stack[MAX_ABSTRACT_INTERP_SIZE];
43+
_PyJitUopBuffer out_buffer;
44+
} JitOptContext;
45+
46+
47+
static inline void
48+
uop_buffer_init(_PyJitUopBuffer *trace, _PyUOpInstruction *start, uint32_t size)
49+
{
50+
trace->next = trace->start = start;
51+
trace->end = start + size;
52+
}
53+
54+
static inline _PyUOpInstruction *
55+
uop_buffer_last(_PyJitUopBuffer *trace)
56+
{
57+
assert(trace->next > trace->start);
58+
return trace->next-1;
59+
}
60+
61+
static inline int
62+
uop_buffer_length(_PyJitUopBuffer *trace)
63+
{
64+
return (int)(trace->next - trace->start);
65+
}
66+
67+
static inline int
68+
uop_buffer_remaining_space(_PyJitUopBuffer *trace)
69+
{
70+
return (int)(trace->end - trace->next);
71+
}
72+
73+
typedef struct _PyJitTracerInitialState {
74+
int stack_depth;
75+
int chain_depth;
76+
struct _PyExitData *exit;
77+
PyCodeObject *code; // Strong
78+
PyFunctionObject *func; // Strong
79+
struct _PyExecutorObject *executor; // Strong
80+
_Py_CODEUNIT *start_instr;
81+
_Py_CODEUNIT *close_loop_instr;
82+
_Py_CODEUNIT *jump_backward_instr;
83+
} _PyJitTracerInitialState;
84+
85+
typedef struct _PyJitTracerPreviousState {
86+
bool dependencies_still_valid;
87+
int instr_oparg;
88+
int instr_stacklevel;
89+
_Py_CODEUNIT *instr;
90+
PyCodeObject *instr_code; // Strong
91+
struct _PyInterpreterFrame *instr_frame;
92+
_PyBloomFilter dependencies;
93+
} _PyJitTracerPreviousState;
94+
95+
typedef struct _PyJitTracerTranslatorState {
96+
int jump_backward_seen;
97+
} _PyJitTracerTranslatorState;
98+
99+
typedef struct _PyJitTracerState {
100+
bool is_tracing;
101+
_PyJitTracerInitialState initial_state;
102+
_PyJitTracerPreviousState prev_state;
103+
_PyJitTracerTranslatorState translator_state;
104+
JitOptContext opt_context;
105+
_PyJitUopBuffer code_buffer;
106+
_PyJitUopBuffer out_buffer;
107+
_PyUOpInstruction uop_array[2 * UOP_MAX_TRACE_LENGTH];
108+
} _PyJitTracerState;
109+
19110
typedef struct _PyExecutorLinkListNode {
20111
struct _PyExecutorObject *next;
21112
struct _PyExecutorObject *previous;
22113
} _PyExecutorLinkListNode;
23114

24-
25115
typedef struct {
26116
uint8_t opcode;
27117
uint8_t oparg;
@@ -86,8 +176,8 @@ PyAPI_FUNC(void) _Py_Executors_InvalidateCold(PyInterpreterState *interp);
86176

87177
int _Py_uop_analyze_and_optimize(
88178
_PyThreadStateImpl *tstate,
89-
_PyUOpInstruction *trace, int trace_len, int curr_stackentries,
90-
_PyBloomFilter *dependencies);
179+
_PyUOpInstruction *input, int trace_len, int curr_stackentries,
180+
_PyUOpInstruction *output, _PyBloomFilter *dependencies);
91181

92182
extern PyTypeObject _PyUOpExecutor_Type;
93183

@@ -205,6 +295,8 @@ extern JitOptRef _Py_uop_sym_new_truthiness(JitOptContext *ctx, JitOptRef value,
205295
extern bool _Py_uop_sym_is_compact_int(JitOptRef sym);
206296
extern JitOptRef _Py_uop_sym_new_compact_int(JitOptContext *ctx);
207297
extern void _Py_uop_sym_set_compact_int(JitOptContext *ctx, JitOptRef sym);
298+
extern JitOptRef _Py_uop_sym_new_predicate(JitOptContext *ctx, JitOptRef lhs_ref, JitOptRef rhs_ref, JitOptPredicateKind kind);
299+
extern void _Py_uop_sym_apply_predicate_narrowing(JitOptContext *ctx, JitOptRef sym, bool branch_is_true);
208300

209301
extern void _Py_uop_abstractcontext_init(JitOptContext *ctx);
210302
extern void _Py_uop_abstractcontext_fini(JitOptContext *ctx);

Include/internal/pycore_optimizer_types.h

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ typedef enum _JitSymType {
4040
JIT_SYM_TUPLE_TAG = 8,
4141
JIT_SYM_TRUTHINESS_TAG = 9,
4242
JIT_SYM_COMPACT_INT = 10,
43+
JIT_SYM_PREDICATE_TAG = 11,
4344
} JitSymType;
4445

4546
typedef struct _jit_opt_known_class {
@@ -72,6 +73,18 @@ typedef struct {
7273
uint16_t value;
7374
} JitOptTruthiness;
7475

76+
typedef enum {
77+
JIT_PRED_IS,
78+
JIT_PRED_IS_NOT,
79+
} JitOptPredicateKind;
80+
81+
typedef struct {
82+
uint8_t tag;
83+
uint8_t kind;
84+
uint16_t lhs;
85+
uint16_t rhs;
86+
} JitOptPredicate;
87+
7588
typedef struct {
7689
uint8_t tag;
7790
} JitOptCompactInt;
@@ -84,6 +97,7 @@ typedef union _jit_opt_symbol {
8497
JitOptTuple tuple;
8598
JitOptTruthiness truthiness;
8699
JitOptCompactInt compact;
100+
JitOptPredicate predicate;
87101
} JitOptSymbol;
88102

89103
// This mimics the _PyStackRef API
@@ -112,27 +126,6 @@ typedef struct ty_arena {
112126
JitOptSymbol arena[TY_ARENA_SIZE];
113127
} ty_arena;
114128

115-
typedef struct _JitOptContext {
116-
char done;
117-
char out_of_space;
118-
bool contradiction;
119-
// Has the builtins dict been watched?
120-
bool builtins_watched;
121-
// The current "executing" frame.
122-
_Py_UOpsAbstractFrame *frame;
123-
_Py_UOpsAbstractFrame frames[MAX_ABSTRACT_FRAME_DEPTH];
124-
int curr_frame_depth;
125-
126-
// Arena for the symbolic types.
127-
ty_arena t_arena;
128-
129-
JitOptRef *n_consumed;
130-
JitOptRef *limit;
131-
JitOptRef locals_and_stack[MAX_ABSTRACT_INTERP_SIZE];
132-
_PyUOpInstruction *out_buffer;
133-
int out_len;
134-
} JitOptContext;
135-
136129

137130
#ifdef __cplusplus
138131
}

Include/internal/pycore_tstate.h

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ extern "C" {
1212
#include "pycore_freelist_state.h" // struct _Py_freelists
1313
#include "pycore_interpframe_structs.h" // _PyInterpreterFrame
1414
#include "pycore_mimalloc.h" // struct _mimalloc_thread_state
15-
#include "pycore_optimizer_types.h" // JitOptContext
1615
#include "pycore_qsbr.h" // struct qsbr
1716
#include "pycore_uop.h" // struct _PyUOpInstruction
1817
#include "pycore_structs.h"
@@ -24,46 +23,6 @@ struct _gc_thread_state {
2423
};
2524
#endif
2625

27-
#if _Py_TIER2
28-
typedef struct _PyJitTracerInitialState {
29-
int stack_depth;
30-
int chain_depth;
31-
struct _PyExitData *exit;
32-
PyCodeObject *code; // Strong
33-
PyFunctionObject *func; // Strong
34-
struct _PyExecutorObject *executor; // Strong
35-
_Py_CODEUNIT *start_instr;
36-
_Py_CODEUNIT *close_loop_instr;
37-
_Py_CODEUNIT *jump_backward_instr;
38-
} _PyJitTracerInitialState;
39-
40-
typedef struct _PyJitTracerPreviousState {
41-
bool dependencies_still_valid;
42-
int code_max_size;
43-
int code_curr_size;
44-
int instr_oparg;
45-
int instr_stacklevel;
46-
_Py_CODEUNIT *instr;
47-
PyCodeObject *instr_code; // Strong
48-
struct _PyInterpreterFrame *instr_frame;
49-
_PyBloomFilter dependencies;
50-
} _PyJitTracerPreviousState;
51-
52-
typedef struct _PyJitTracerTranslatorState {
53-
int jump_backward_seen;
54-
} _PyJitTracerTranslatorState;
55-
56-
typedef struct _PyJitTracerState {
57-
bool is_tracing;
58-
_PyJitTracerInitialState initial_state;
59-
_PyJitTracerPreviousState prev_state;
60-
_PyJitTracerTranslatorState translator_state;
61-
JitOptContext opt_context;
62-
_PyUOpInstruction code_buffer[UOP_MAX_TRACE_LENGTH];
63-
_PyUOpInstruction out_buffer[UOP_MAX_TRACE_LENGTH];
64-
} _PyJitTracerState;
65-
66-
#endif
6726

6827
// Every PyThreadState is actually allocated as a _PyThreadStateImpl. The
6928
// PyThreadState fields are exposed as part of the C API, although most fields
@@ -141,7 +100,7 @@ typedef struct _PyThreadStateImpl {
141100
Py_ssize_t reftotal; // this thread's total refcount operations
142101
#endif
143102
#if _Py_TIER2
144-
_PyJitTracerState *jit_tracer_state;
103+
struct _PyJitTracerState *jit_tracer_state;
145104
#endif
146105
} _PyThreadStateImpl;
147106

Include/internal/pycore_uop.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,10 @@ typedef struct _PyUOpInstruction{
3838
// This is the length of the trace we translate initially.
3939
#ifdef Py_DEBUG
4040
// With asserts, the stencils are a lot larger
41-
#define UOP_MAX_TRACE_LENGTH 2000
41+
#define UOP_MAX_TRACE_LENGTH 1000
4242
#else
43-
#define UOP_MAX_TRACE_LENGTH 5000
43+
#define UOP_MAX_TRACE_LENGTH 2500
4444
#endif
45-
#define UOP_BUFFER_SIZE (UOP_MAX_TRACE_LENGTH * sizeof(_PyUOpInstruction))
4645

4746
/* Bloom filter with m = 256
4847
* https://en.wikipedia.org/wiki/Bloom_filter */

0 commit comments

Comments
 (0)