Coverage Report

Created: 2026-11-20 06:19

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/cpython3/Python/ast_preprocess.c
Line
Count
Source
1
/* AST pre-processing */
2
#include "Python.h"
3
#include "pycore_ast.h"           // _PyAST_GetDocString()
4
#include "pycore_c_array.h"       // _Py_CArray_EnsureCapacity()
5
#include "pycore_format.h"        // F_LJUST
6
#include "pycore_runtime.h"       // _Py_STR()
7
#include "pycore_unicodeobject.h" // _PyUnicode_EqualToASCIIString()
8
9
10
/* See PEP 765 */
11
typedef struct {
12
    bool in_finally;
13
    bool in_funcdef;
14
    bool in_loop;
15
} ControlFlowInFinallyContext;
16
17
typedef struct {
18
    PyObject *filename;
19
    PyObject *module;
20
    int optimize;
21
    int ff_features;
22
    int syntax_check_only;
23
    int enable_warnings;
24
25
    _Py_c_array_t cf_finally;       /* context for PEP 765 check */
26
    int cf_finally_used;
27
} _PyASTPreprocessState;
28
29
2.39M
#define ENTER_RECURSIVE() \
30
2.39M
if (Py_EnterRecursiveCall(" during compilation")) { \
31
0
    return 0; \
32
0
}
33
34
2.39M
#define LEAVE_RECURSIVE() Py_LeaveRecursiveCall();
35
36
static ControlFlowInFinallyContext*
37
get_cf_finally_top(_PyASTPreprocessState *state)
38
18.1k
{
39
18.1k
    int idx = state->cf_finally_used;
40
18.1k
    return ((ControlFlowInFinallyContext*)state->cf_finally.array) + idx;
41
18.1k
}
42
43
static int
44
push_cf_context(_PyASTPreprocessState *state, stmt_ty node, bool finally, bool funcdef, bool loop)
45
16.6k
{
46
16.6k
    if (_Py_CArray_EnsureCapacity(&state->cf_finally, state->cf_finally_used+1) < 0) {
47
0
        return 0;
48
0
    }
49
50
16.6k
    state->cf_finally_used++;
51
16.6k
    ControlFlowInFinallyContext *ctx = get_cf_finally_top(state);
52
53
16.6k
    ctx->in_finally = finally;
54
16.6k
    ctx->in_funcdef = funcdef;
55
16.6k
    ctx->in_loop = loop;
56
16.6k
    return 1;
57
16.6k
}
58
59
static void
60
pop_cf_context(_PyASTPreprocessState *state)
61
16.6k
{
62
16.6k
    assert(state->cf_finally_used > 0);
63
16.6k
    state->cf_finally_used--;
64
16.6k
}
65
66
static int
67
control_flow_in_finally_warning(const char *kw, stmt_ty n, _PyASTPreprocessState *state)
68
400
{
69
400
    PyObject *msg = PyUnicode_FromFormat("'%s' in a 'finally' block", kw);
70
400
    if (msg == NULL) {
71
0
        return 0;
72
0
    }
73
400
    int ret = _PyErr_EmitSyntaxWarning(msg, state->filename, n->lineno,
74
400
                                       n->col_offset + 1, n->end_lineno,
75
400
                                       n->end_col_offset + 1,
76
400
                                       state->module);
77
400
    Py_DECREF(msg);
78
400
    return ret < 0 ? 0 : 1;
79
400
}
80
81
static int
82
before_return(_PyASTPreprocessState *state, stmt_ty node_)
83
1.51k
{
84
1.51k
    if (state->enable_warnings && state->cf_finally_used > 0) {
85
716
        ControlFlowInFinallyContext *ctx = get_cf_finally_top(state);
86
716
        if (ctx->in_finally && ! ctx->in_funcdef) {
87
49
            if (!control_flow_in_finally_warning("return", node_, state)) {
88
0
                return 0;
89
0
            }
90
49
        }
91
716
    }
92
1.51k
    return 1;
93
1.51k
}
94
95
static int
96
before_loop_exit(_PyASTPreprocessState *state, stmt_ty node_, const char *kw)
97
1.07k
{
98
1.07k
    if (state->enable_warnings && state->cf_finally_used > 0) {
99
862
        ControlFlowInFinallyContext *ctx = get_cf_finally_top(state);
100
862
        if (ctx->in_finally && ! ctx->in_loop) {
101
351
            if (!control_flow_in_finally_warning(kw, node_, state)) {
102
0
                return 0;
103
0
            }
104
351
        }
105
862
    }
106
1.07k
    return 1;
107
1.07k
}
108
109
#define PUSH_CONTEXT(S, N, FINALLY, FUNCDEF, LOOP) \
110
16.6k
    if (!push_cf_context((S), (N), (FINALLY), (FUNCDEF), (LOOP))) { \
111
0
        return 0; \
112
0
    }
113
114
16.6k
#define POP_CONTEXT(S) pop_cf_context(S)
115
116
5.05k
#define BEFORE_FINALLY(S, N)    PUSH_CONTEXT((S), (N), true, false, false)
117
5.05k
#define AFTER_FINALLY(S)        POP_CONTEXT(S)
118
8.55k
#define BEFORE_FUNC_BODY(S, N)  PUSH_CONTEXT((S), (N), false, true, false)
119
8.55k
#define AFTER_FUNC_BODY(S)      POP_CONTEXT(S)
120
3.00k
#define BEFORE_LOOP_BODY(S, N)  PUSH_CONTEXT((S), (N), false, false, true)
121
3.00k
#define AFTER_LOOP_BODY(S)      POP_CONTEXT(S)
122
123
#define BEFORE_RETURN(S, N) \
124
1.51k
    if (!before_return((S), (N))) { \
125
0
        return 0; \
126
0
    }
127
128
#define BEFORE_LOOP_EXIT(S, N, KW) \
129
1.07k
    if (!before_loop_exit((S), (N), (KW))) { \
130
0
        return 0; \
131
0
    }
132
133
static int
134
make_const(expr_ty node, PyObject *val, PyArena *arena)
135
2.45k
{
136
    // Even if no new value was calculated, make_const may still
137
    // need to clear an error (e.g. for division by zero)
138
2.45k
    if (val == NULL) {
139
29
        if (PyErr_ExceptionMatches(PyExc_KeyboardInterrupt)) {
140
0
            return 0;
141
0
        }
142
29
        PyErr_Clear();
143
29
        return 1;
144
29
    }
145
2.42k
    if (_PyArena_AddPyObject(arena, val) < 0) {
146
0
        Py_DECREF(val);
147
0
        return 0;
148
0
    }
149
2.42k
    node->kind = Constant_kind;
150
2.42k
    node->v.Constant.kind = NULL;
151
2.42k
    node->v.Constant.value = val;
152
2.42k
    return 1;
153
2.42k
}
154
155
1.46k
#define COPY_NODE(TO, FROM) (memcpy((TO), (FROM), sizeof(struct _expr)))
156
157
static int
158
has_starred(asdl_expr_seq *elts)
159
6.86k
{
160
6.86k
    Py_ssize_t n = asdl_seq_LEN(elts);
161
14.0k
    for (Py_ssize_t i = 0; i < n; i++) {
162
7.19k
        expr_ty e = (expr_ty)asdl_seq_GET(elts, i);
163
7.19k
        if (e->kind == Starred_kind) {
164
35
            return 1;
165
35
        }
166
7.19k
    }
167
6.82k
    return 0;
168
6.86k
}
169
170
static expr_ty
171
parse_literal(PyObject *fmt, Py_ssize_t *ppos, PyArena *arena)
172
8.59k
{
173
8.59k
    const void *data = PyUnicode_DATA(fmt);
174
8.59k
    int kind = PyUnicode_KIND(fmt);
175
8.59k
    Py_ssize_t size = PyUnicode_GET_LENGTH(fmt);
176
8.59k
    Py_ssize_t start, pos;
177
8.59k
    int has_percents = 0;
178
8.59k
    start = pos = *ppos;
179
201k
    while (pos < size) {
180
198k
        if (PyUnicode_READ(kind, data, pos) != '%') {
181
175k
            pos++;
182
175k
        }
183
23.2k
        else if (pos+1 < size && PyUnicode_READ(kind, data, pos+1) == '%') {
184
17.1k
            has_percents = 1;
185
17.1k
            pos += 2;
186
17.1k
        }
187
6.01k
        else {
188
6.01k
            break;
189
6.01k
        }
190
198k
    }
191
8.59k
    *ppos = pos;
192
8.59k
    if (pos == start) {
193
1.27k
        return NULL;
194
1.27k
    }
195
7.31k
    PyObject *str = PyUnicode_Substring(fmt, start, pos);
196
    /* str = str.replace('%%', '%') */
197
7.31k
    if (str && has_percents) {
198
3.07k
        _Py_DECLARE_STR(dbl_percent, "%%");
199
3.07k
        Py_SETREF(str, PyUnicode_Replace(str, &_Py_STR(dbl_percent),
200
3.07k
                                         _Py_LATIN1_CHR('%'), -1));
201
3.07k
    }
202
7.31k
    if (!str) {
203
0
        return NULL;
204
0
    }
205
206
7.31k
    if (_PyArena_AddPyObject(arena, str) < 0) {
207
0
        Py_DECREF(str);
208
0
        return NULL;
209
0
    }
210
7.31k
    return _PyAST_Constant(str, NULL, -1, -1, -1, -1, arena);
211
7.31k
}
212
213
4.14k
#define MAXDIGITS 3
214
215
static int
216
simple_format_arg_parse(PyObject *fmt, Py_ssize_t *ppos,
217
                        int *spec, int *flags, int *width, int *prec)
218
5.31k
{
219
5.31k
    Py_ssize_t pos = *ppos, len = PyUnicode_GET_LENGTH(fmt);
220
5.31k
    Py_UCS4 ch;
221
222
14.3k
#define NEXTC do {                      \
223
14.3k
    if (pos >= len) {                   \
224
1.26k
        return 0;                       \
225
1.26k
    }                                   \
226
14.3k
    ch = PyUnicode_READ_CHAR(fmt, pos); \
227
13.0k
    pos++;                              \
228
13.0k
} while (0)
229
230
5.31k
    *flags = 0;
231
9.40k
    while (1) {
232
9.40k
        NEXTC;
233
8.68k
        switch (ch) {
234
1.01k
            case '-': *flags |= F_LJUST; continue;
235
48
            case '+': *flags |= F_SIGN; continue;
236
2.00k
            case ' ': *flags |= F_BLANK; continue;
237
386
            case '#': *flags |= F_ALT; continue;
238
639
            case '0': *flags |= F_ZERO; continue;
239
8.68k
        }
240
4.59k
        break;
241
8.68k
    }
242
4.59k
    if ('0' <= ch && ch <= '9') {
243
1.37k
        *width = 0;
244
1.37k
        int digits = 0;
245
3.53k
        while ('0' <= ch && ch <= '9') {
246
2.80k
            *width = *width * 10 + (ch - '0');
247
2.80k
            NEXTC;
248
2.65k
            if (++digits >= MAXDIGITS) {
249
488
                return 0;
250
488
            }
251
2.65k
        }
252
1.37k
    }
253
254
3.95k
    if (ch == '.') {
255
1.26k
        NEXTC;
256
956
        *prec = 0;
257
956
        if ('0' <= ch && ch <= '9') {
258
455
            int digits = 0;
259
1.14k
            while ('0' <= ch && ch <= '9') {
260
841
                *prec = *prec * 10 + (ch - '0');
261
841
                NEXTC;
262
753
                if (++digits >= MAXDIGITS) {
263
66
                    return 0;
264
66
                }
265
753
            }
266
455
        }
267
956
    }
268
3.49k
    *spec = ch;
269
3.49k
    *ppos = pos;
270
3.49k
    return 1;
271
272
3.95k
#undef NEXTC
273
3.95k
}
274
275
static expr_ty
276
parse_format(PyObject *fmt, Py_ssize_t *ppos, expr_ty arg, PyArena *arena)
277
5.31k
{
278
5.31k
    int spec, flags, width = -1, prec = -1;
279
5.31k
    if (!simple_format_arg_parse(fmt, ppos, &spec, &flags, &width, &prec)) {
280
        // Unsupported format.
281
1.81k
        return NULL;
282
1.81k
    }
283
3.49k
    if (spec == 's' || spec == 'r' || spec == 'a') {
284
1.76k
        char buf[1 + MAXDIGITS + 1 + MAXDIGITS + 1], *p = buf;
285
1.76k
        if (!(flags & F_LJUST) && width > 0) {
286
461
            *p++ = '>';
287
461
        }
288
1.76k
        if (width >= 0) {
289
522
            p += snprintf(p, MAXDIGITS + 1, "%d", width);
290
522
        }
291
1.76k
        if (prec >= 0) {
292
221
            p += snprintf(p, MAXDIGITS + 2, ".%d", prec);
293
221
        }
294
1.76k
        expr_ty format_spec = NULL;
295
1.76k
        if (p != buf) {
296
719
            PyObject *str = PyUnicode_FromString(buf);
297
719
            if (str == NULL) {
298
0
                return NULL;
299
0
            }
300
719
            if (_PyArena_AddPyObject(arena, str) < 0) {
301
0
                Py_DECREF(str);
302
0
                return NULL;
303
0
            }
304
719
            format_spec = _PyAST_Constant(str, NULL, -1, -1, -1, -1, arena);
305
719
            if (format_spec == NULL) {
306
0
                return NULL;
307
0
            }
308
719
        }
309
1.76k
        return _PyAST_FormattedValue(arg, spec, format_spec,
310
1.76k
                                     arg->lineno, arg->col_offset,
311
1.76k
                                     arg->end_lineno, arg->end_col_offset,
312
1.76k
                                     arena);
313
1.76k
    }
314
    // Unsupported format.
315
1.72k
    return NULL;
316
3.49k
}
317
318
static int
319
optimize_format(expr_ty node, PyObject *fmt, asdl_expr_seq *elts, PyArena *arena)
320
6.82k
{
321
6.82k
    Py_ssize_t pos = 0;
322
6.82k
    Py_ssize_t cnt = 0;
323
6.82k
    asdl_expr_seq *seq = _Py_asdl_expr_seq_new(asdl_seq_LEN(elts) * 2 + 1, arena);
324
6.82k
    if (!seq) {
325
0
        return 0;
326
0
    }
327
6.82k
    seq->size = 0;
328
329
8.59k
    while (1) {
330
8.59k
        expr_ty lit = parse_literal(fmt, &pos, arena);
331
8.59k
        if (lit) {
332
7.31k
            asdl_seq_SET(seq, seq->size++, lit);
333
7.31k
        }
334
1.27k
        else if (PyErr_Occurred()) {
335
0
            return 0;
336
0
        }
337
338
8.59k
        if (pos >= PyUnicode_GET_LENGTH(fmt)) {
339
2.57k
            break;
340
2.57k
        }
341
6.01k
        if (cnt >= asdl_seq_LEN(elts)) {
342
            // More format units than items.
343
708
            return 1;
344
708
        }
345
6.01k
        assert(PyUnicode_READ_CHAR(fmt, pos) == '%');
346
5.31k
        pos++;
347
5.31k
        expr_ty expr = parse_format(fmt, &pos, asdl_seq_GET(elts, cnt), arena);
348
5.31k
        cnt++;
349
5.31k
        if (!expr) {
350
3.54k
            return !PyErr_Occurred();
351
3.54k
        }
352
1.76k
        asdl_seq_SET(seq, seq->size++, expr);
353
1.76k
    }
354
2.57k
    if (cnt < asdl_seq_LEN(elts)) {
355
        // More items than format units.
356
1.10k
        return 1;
357
1.10k
    }
358
1.46k
    expr_ty res = _PyAST_JoinedStr(seq,
359
1.46k
                                   node->lineno, node->col_offset,
360
1.46k
                                   node->end_lineno, node->end_col_offset,
361
1.46k
                                   arena);
362
1.46k
    if (!res) {
363
0
        return 0;
364
0
    }
365
1.46k
    COPY_NODE(node, res);
366
//     PySys_FormatStderr("format = %R\n", fmt);
367
1.46k
    return 1;
368
1.46k
}
369
370
static int
371
fold_binop(expr_ty node, PyArena *arena, _PyASTPreprocessState *state)
372
527k
{
373
527k
    if (state->syntax_check_only) {
374
41.2k
        return 1;
375
41.2k
    }
376
486k
    expr_ty lhs, rhs;
377
486k
    lhs = node->v.BinOp.left;
378
486k
    rhs = node->v.BinOp.right;
379
486k
    if (lhs->kind != Constant_kind) {
380
328k
        return 1;
381
328k
    }
382
158k
    PyObject *lv = lhs->v.Constant.value;
383
384
158k
    if (node->v.BinOp.op == Mod &&
385
12.2k
        rhs->kind == Tuple_kind &&
386
158k
        PyUnicode_Check(lv) &&
387
6.86k
        !has_starred(rhs->v.Tuple.elts))
388
6.82k
    {
389
6.82k
        return optimize_format(node, lv, rhs->v.Tuple.elts, arena);
390
6.82k
    }
391
392
151k
    return 1;
393
158k
}
394
395
static int astfold_mod(mod_ty node_, PyArena *ctx_, _PyASTPreprocessState *state);
396
static int astfold_stmt(stmt_ty node_, PyArena *ctx_, _PyASTPreprocessState *state);
397
static int astfold_expr(expr_ty node_, PyArena *ctx_, _PyASTPreprocessState *state);
398
static int astfold_arguments(arguments_ty node_, PyArena *ctx_, _PyASTPreprocessState *state);
399
static int astfold_comprehension(comprehension_ty node_, PyArena *ctx_, _PyASTPreprocessState *state);
400
static int astfold_keyword(keyword_ty node_, PyArena *ctx_, _PyASTPreprocessState *state);
401
static int astfold_arg(arg_ty node_, PyArena *ctx_, _PyASTPreprocessState *state);
402
static int astfold_withitem(withitem_ty node_, PyArena *ctx_, _PyASTPreprocessState *state);
403
static int astfold_excepthandler(excepthandler_ty node_, PyArena *ctx_, _PyASTPreprocessState *state);
404
static int astfold_match_case(match_case_ty node_, PyArena *ctx_, _PyASTPreprocessState *state);
405
static int astfold_pattern(pattern_ty node_, PyArena *ctx_, _PyASTPreprocessState *state);
406
static int astfold_type_param(type_param_ty node_, PyArena *ctx_, _PyASTPreprocessState *state);
407
408
#define CALL(FUNC, TYPE, ARG) \
409
2.29M
    if (!FUNC((ARG), ctx_, state)) \
410
2.29M
        return 0;
411
412
#define CALL_OPT(FUNC, TYPE, ARG) \
413
211k
    if ((ARG) != NULL && !FUNC((ARG), ctx_, state)) \
414
211k
        return 0;
415
416
435k
#define CALL_SEQ(FUNC, TYPE, ARG) { \
417
435k
    Py_ssize_t i; \
418
435k
    asdl_ ## TYPE ## _seq *seq = (ARG); /* avoid variable capture */ \
419
1.16M
    for (i = 0; i < asdl_seq_LEN(seq); i++) { \
420
731k
        TYPE ## _ty elt = (TYPE ## _ty)asdl_seq_GET(seq, i); \
421
731k
        if (elt != NULL && !FUNC(elt, ctx_, state)) \
422
731k
            return 0; \
423
731k
    } \
424
435k
}
425
426
427
static int
428
stmt_seq_remove_item(asdl_stmt_seq *stmts, Py_ssize_t idx)
429
102
{
430
102
    if (idx >= asdl_seq_LEN(stmts)) {
431
0
        return 0;
432
0
    }
433
433
    for (Py_ssize_t i = idx; i < asdl_seq_LEN(stmts) - 1; i++) {
434
331
        stmt_ty st = (stmt_ty)asdl_seq_GET(stmts, i+1);
435
331
        asdl_seq_SET(stmts, i, st);
436
331
    }
437
102
    stmts->size--;
438
102
    return 1;
439
102
}
440
441
static int
442
remove_docstring(asdl_stmt_seq *stmts, Py_ssize_t idx, PyArena *ctx_)
443
193
{
444
193
    assert(_PyAST_GetDocString(stmts) != NULL);
445
    // In case there's just the docstring in the body, replace it with `pass`
446
    // keyword, so body won't be empty.
447
193
    if (asdl_seq_LEN(stmts) == 1) {
448
91
        stmt_ty docstring = (stmt_ty)asdl_seq_GET(stmts, 0);
449
91
        stmt_ty pass = _PyAST_Pass(
450
91
            docstring->lineno, docstring->col_offset,
451
            // we know that `pass` always takes 4 chars and a single line,
452
            // while docstring can span on multiple lines
453
91
            docstring->lineno, docstring->col_offset + 4,
454
91
            ctx_
455
91
        );
456
91
        if (pass == NULL) {
457
0
            return 0;
458
0
        }
459
91
        asdl_seq_SET(stmts, 0, pass);
460
91
        return 1;
461
91
    }
462
    // In case there are more than 1 body items, just remove the docstring.
463
102
    return stmt_seq_remove_item(stmts, idx);
464
193
}
465
466
static int
467
astfold_body(asdl_stmt_seq *stmts, PyArena *ctx_, _PyASTPreprocessState *state)
468
31.6k
{
469
31.6k
    int docstring = _PyAST_GetDocString(stmts) != NULL;
470
31.6k
    if (docstring && (state->optimize >= 2)) {
471
        /* remove the docstring */
472
193
        if (!remove_docstring(stmts, 0, ctx_)) {
473
0
            return 0;
474
0
        }
475
193
        docstring = 0;
476
193
    }
477
31.6k
    CALL_SEQ(astfold_stmt, stmt, stmts);
478
31.6k
    if (!docstring && _PyAST_GetDocString(stmts) != NULL) {
479
59
        stmt_ty st = (stmt_ty)asdl_seq_GET(stmts, 0);
480
59
        asdl_expr_seq *values = _Py_asdl_expr_seq_new(1, ctx_);
481
59
        if (!values) {
482
0
            return 0;
483
0
        }
484
59
        asdl_seq_SET(values, 0, st->v.Expr.value);
485
59
        expr_ty expr = _PyAST_JoinedStr(values, st->lineno, st->col_offset,
486
59
                                        st->end_lineno, st->end_col_offset,
487
59
                                        ctx_);
488
59
        if (!expr) {
489
0
            return 0;
490
0
        }
491
59
        st->v.Expr.value = expr;
492
59
    }
493
31.6k
    return 1;
494
31.6k
}
495
496
static int
497
astfold_mod(mod_ty node_, PyArena *ctx_, _PyASTPreprocessState *state)
498
14.6k
{
499
14.6k
    switch (node_->kind) {
500
9.81k
    case Module_kind:
501
9.81k
        CALL(astfold_body, asdl_seq, node_->v.Module.body);
502
9.81k
        break;
503
2.75k
    case Interactive_kind:
504
2.75k
        CALL_SEQ(astfold_stmt, stmt, node_->v.Interactive.body);
505
2.75k
        break;
506
2.04k
    case Expression_kind:
507
2.04k
        CALL(astfold_expr, expr_ty, node_->v.Expression.body);
508
2.04k
        break;
509
    // The following top level nodes don't participate in constant folding
510
0
    case FunctionType_kind:
511
0
        break;
512
    // No default case, so the compiler will emit a warning if new top level
513
    // compilation nodes are added without being handled here
514
14.6k
    }
515
14.6k
    return 1;
516
14.6k
}
517
518
static int
519
astfold_expr(expr_ty node_, PyArena *ctx_, _PyASTPreprocessState *state)
520
2.18M
{
521
2.18M
    ENTER_RECURSIVE();
522
2.18M
    switch (node_->kind) {
523
2.32k
    case BoolOp_kind:
524
2.32k
        CALL_SEQ(astfold_expr, expr, node_->v.BoolOp.values);
525
2.32k
        break;
526
527k
    case BinOp_kind:
527
527k
        CALL(astfold_expr, expr_ty, node_->v.BinOp.left);
528
527k
        CALL(astfold_expr, expr_ty, node_->v.BinOp.right);
529
527k
        CALL(fold_binop, expr_ty, node_);
530
527k
        break;
531
276k
    case UnaryOp_kind:
532
276k
        CALL(astfold_expr, expr_ty, node_->v.UnaryOp.operand);
533
276k
        break;
534
12.1k
    case Lambda_kind:
535
12.1k
        CALL(astfold_arguments, arguments_ty, node_->v.Lambda.args);
536
12.1k
        CALL(astfold_expr, expr_ty, node_->v.Lambda.body);
537
12.1k
        break;
538
2.14k
    case IfExp_kind:
539
2.14k
        CALL(astfold_expr, expr_ty, node_->v.IfExp.test);
540
2.14k
        CALL(astfold_expr, expr_ty, node_->v.IfExp.body);
541
2.14k
        CALL(astfold_expr, expr_ty, node_->v.IfExp.orelse);
542
2.14k
        break;
543
2.09k
    case Dict_kind:
544
2.09k
        CALL_SEQ(astfold_expr, expr, node_->v.Dict.keys);
545
2.09k
        CALL_SEQ(astfold_expr, expr, node_->v.Dict.values);
546
2.09k
        break;
547
8.09k
    case Set_kind:
548
8.09k
        CALL_SEQ(astfold_expr, expr, node_->v.Set.elts);
549
8.09k
        break;
550
641
    case ListComp_kind:
551
641
        CALL(astfold_expr, expr_ty, node_->v.ListComp.elt);
552
641
        CALL_SEQ(astfold_comprehension, comprehension, node_->v.ListComp.generators);
553
641
        break;
554
2.73k
    case SetComp_kind:
555
2.73k
        CALL(astfold_expr, expr_ty, node_->v.SetComp.elt);
556
2.73k
        CALL_SEQ(astfold_comprehension, comprehension, node_->v.SetComp.generators);
557
2.73k
        break;
558
701
    case DictComp_kind:
559
701
        CALL(astfold_expr, expr_ty, node_->v.DictComp.key);
560
701
        if (node_->v.DictComp.value != NULL){
561
516
            CALL(astfold_expr, expr_ty, node_->v.DictComp.value);
562
516
        }
563
701
        CALL_SEQ(astfold_comprehension, comprehension, node_->v.DictComp.generators);
564
701
        break;
565
1.19k
    case GeneratorExp_kind:
566
1.19k
        CALL(astfold_expr, expr_ty, node_->v.GeneratorExp.elt);
567
1.19k
        CALL_SEQ(astfold_comprehension, comprehension, node_->v.GeneratorExp.generators);
568
1.19k
        break;
569
904
    case Await_kind:
570
904
        CALL(astfold_expr, expr_ty, node_->v.Await.value);
571
904
        break;
572
2.16k
    case Yield_kind:
573
2.16k
        CALL_OPT(astfold_expr, expr_ty, node_->v.Yield.value);
574
2.16k
        break;
575
139
    case YieldFrom_kind:
576
139
        CALL(astfold_expr, expr_ty, node_->v.YieldFrom.value);
577
139
        break;
578
17.4k
    case Compare_kind:
579
17.4k
        CALL(astfold_expr, expr_ty, node_->v.Compare.left);
580
17.4k
        CALL_SEQ(astfold_expr, expr, node_->v.Compare.comparators);
581
17.4k
        break;
582
15.6k
    case Call_kind:
583
15.6k
        CALL(astfold_expr, expr_ty, node_->v.Call.func);
584
15.6k
        CALL_SEQ(astfold_expr, expr, node_->v.Call.args);
585
15.6k
        CALL_SEQ(astfold_keyword, keyword, node_->v.Call.keywords);
586
15.6k
        break;
587
3.17k
    case FormattedValue_kind:
588
3.17k
        CALL(astfold_expr, expr_ty, node_->v.FormattedValue.value);
589
3.17k
        CALL_OPT(astfold_expr, expr_ty, node_->v.FormattedValue.format_spec);
590
3.17k
        break;
591
1.77k
    case Interpolation_kind:
592
1.77k
        CALL(astfold_expr, expr_ty, node_->v.Interpolation.value);
593
1.77k
        CALL_OPT(astfold_expr, expr_ty, node_->v.Interpolation.format_spec);
594
1.77k
        break;
595
3.13k
    case JoinedStr_kind:
596
3.13k
        CALL_SEQ(astfold_expr, expr, node_->v.JoinedStr.values);
597
3.13k
        break;
598
788
    case TemplateStr_kind:
599
788
        CALL_SEQ(astfold_expr, expr, node_->v.TemplateStr.values);
600
788
        break;
601
19.8k
    case Attribute_kind:
602
19.8k
        CALL(astfold_expr, expr_ty, node_->v.Attribute.value);
603
19.8k
        break;
604
24.9k
    case Subscript_kind:
605
24.9k
        CALL(astfold_expr, expr_ty, node_->v.Subscript.value);
606
24.9k
        CALL(astfold_expr, expr_ty, node_->v.Subscript.slice);
607
24.9k
        break;
608
15.5k
    case Starred_kind:
609
15.5k
        CALL(astfold_expr, expr_ty, node_->v.Starred.value);
610
15.5k
        break;
611
16.0k
    case Slice_kind:
612
16.0k
        CALL_OPT(astfold_expr, expr_ty, node_->v.Slice.lower);
613
16.0k
        CALL_OPT(astfold_expr, expr_ty, node_->v.Slice.upper);
614
16.0k
        CALL_OPT(astfold_expr, expr_ty, node_->v.Slice.step);
615
16.0k
        break;
616
6.75k
    case List_kind:
617
6.75k
        CALL_SEQ(astfold_expr, expr, node_->v.List.elts);
618
6.75k
        break;
619
79.7k
    case Tuple_kind:
620
79.7k
        CALL_SEQ(astfold_expr, expr, node_->v.Tuple.elts);
621
79.7k
        break;
622
460k
    case Name_kind:
623
460k
        if (state->syntax_check_only) {
624
24.9k
            break;
625
24.9k
        }
626
435k
        if (node_->v.Name.ctx == Load &&
627
298k
                _PyUnicode_EqualToASCIIString(node_->v.Name.id, "__debug__")) {
628
380
            LEAVE_RECURSIVE();
629
380
            return make_const(node_, PyBool_FromLong(!state->optimize), ctx_);
630
380
        }
631
434k
        break;
632
434k
    case NamedExpr_kind:
633
1.95k
        CALL(astfold_expr, expr_ty, node_->v.NamedExpr.value);
634
1.95k
        break;
635
674k
    case Constant_kind:
636
        // Already a constant, nothing further to do
637
674k
        break;
638
    // No default case, so the compiler will emit a warning if new expression
639
    // kinds are added without being handled here
640
2.18M
    }
641
2.18M
    LEAVE_RECURSIVE();
642
2.18M
    return 1;
643
2.18M
}
644
645
static int
646
astfold_keyword(keyword_ty node_, PyArena *ctx_, _PyASTPreprocessState *state)
647
6.88k
{
648
6.88k
    CALL(astfold_expr, expr_ty, node_->value);
649
6.88k
    return 1;
650
6.88k
}
651
652
static int
653
astfold_comprehension(comprehension_ty node_, PyArena *ctx_, _PyASTPreprocessState *state)
654
6.56k
{
655
6.56k
    CALL(astfold_expr, expr_ty, node_->target);
656
6.56k
    CALL(astfold_expr, expr_ty, node_->iter);
657
6.56k
    CALL_SEQ(astfold_expr, expr, node_->ifs);
658
6.56k
    return 1;
659
6.56k
}
660
661
static int
662
astfold_arguments(arguments_ty node_, PyArena *ctx_, _PyASTPreprocessState *state)
663
20.6k
{
664
20.6k
    CALL_SEQ(astfold_arg, arg, node_->posonlyargs);
665
20.6k
    CALL_SEQ(astfold_arg, arg, node_->args);
666
20.6k
    CALL_OPT(astfold_arg, arg_ty, node_->vararg);
667
20.6k
    CALL_SEQ(astfold_arg, arg, node_->kwonlyargs);
668
20.6k
    CALL_SEQ(astfold_expr, expr, node_->kw_defaults);
669
20.6k
    CALL_OPT(astfold_arg, arg_ty, node_->kwarg);
670
20.6k
    CALL_SEQ(astfold_expr, expr, node_->defaults);
671
20.6k
    return 1;
672
20.6k
}
673
674
static int
675
astfold_arg(arg_ty node_, PyArena *ctx_, _PyASTPreprocessState *state)
676
28.7k
{
677
28.7k
    if (!(state->ff_features & CO_FUTURE_ANNOTATIONS)) {
678
28.1k
        CALL_OPT(astfold_expr, expr_ty, node_->annotation);
679
28.1k
    }
680
28.7k
    return 1;
681
28.7k
}
682
683
static int
684
astfold_stmt(stmt_ty node_, PyArena *ctx_, _PyASTPreprocessState *state)
685
192k
{
686
192k
    ENTER_RECURSIVE();
687
192k
    switch (node_->kind) {
688
5.50k
    case FunctionDef_kind: {
689
5.50k
        CALL_SEQ(astfold_type_param, type_param, node_->v.FunctionDef.type_params);
690
5.50k
        CALL(astfold_arguments, arguments_ty, node_->v.FunctionDef.args);
691
5.50k
        BEFORE_FUNC_BODY(state, node_);
692
5.50k
        CALL(astfold_body, asdl_seq, node_->v.FunctionDef.body);
693
5.50k
        AFTER_FUNC_BODY(state);
694
5.50k
        CALL_SEQ(astfold_expr, expr, node_->v.FunctionDef.decorator_list);
695
5.50k
        if (!(state->ff_features & CO_FUTURE_ANNOTATIONS)) {
696
5.23k
            CALL_OPT(astfold_expr, expr_ty, node_->v.FunctionDef.returns);
697
5.23k
        }
698
5.50k
        break;
699
5.50k
    }
700
5.50k
    case AsyncFunctionDef_kind: {
701
3.05k
        CALL_SEQ(astfold_type_param, type_param, node_->v.AsyncFunctionDef.type_params);
702
3.05k
        CALL(astfold_arguments, arguments_ty, node_->v.AsyncFunctionDef.args);
703
3.05k
        BEFORE_FUNC_BODY(state, node_);
704
3.05k
        CALL(astfold_body, asdl_seq, node_->v.AsyncFunctionDef.body);
705
3.05k
        AFTER_FUNC_BODY(state);
706
3.05k
        CALL_SEQ(astfold_expr, expr, node_->v.AsyncFunctionDef.decorator_list);
707
3.05k
        if (!(state->ff_features & CO_FUTURE_ANNOTATIONS)) {
708
2.87k
            CALL_OPT(astfold_expr, expr_ty, node_->v.AsyncFunctionDef.returns);
709
2.87k
        }
710
3.05k
        break;
711
3.05k
    }
712
13.3k
    case ClassDef_kind:
713
13.3k
        CALL_SEQ(astfold_type_param, type_param, node_->v.ClassDef.type_params);
714
13.3k
        CALL_SEQ(astfold_expr, expr, node_->v.ClassDef.bases);
715
13.3k
        CALL_SEQ(astfold_keyword, keyword, node_->v.ClassDef.keywords);
716
13.3k
        CALL(astfold_body, asdl_seq, node_->v.ClassDef.body);
717
13.3k
        CALL_SEQ(astfold_expr, expr, node_->v.ClassDef.decorator_list);
718
13.3k
        break;
719
1.51k
    case Return_kind:
720
1.51k
        BEFORE_RETURN(state, node_);
721
1.51k
        CALL_OPT(astfold_expr, expr_ty, node_->v.Return.value);
722
1.51k
        break;
723
1.03k
    case Delete_kind:
724
1.03k
        CALL_SEQ(astfold_expr, expr, node_->v.Delete.targets);
725
1.03k
        break;
726
7.01k
    case Assign_kind:
727
7.01k
        CALL_SEQ(astfold_expr, expr, node_->v.Assign.targets);
728
7.01k
        CALL(astfold_expr, expr_ty, node_->v.Assign.value);
729
7.01k
        break;
730
5.82k
    case AugAssign_kind:
731
5.82k
        CALL(astfold_expr, expr_ty, node_->v.AugAssign.target);
732
5.82k
        CALL(astfold_expr, expr_ty, node_->v.AugAssign.value);
733
5.82k
        break;
734
25.5k
    case AnnAssign_kind:
735
25.5k
        CALL(astfold_expr, expr_ty, node_->v.AnnAssign.target);
736
25.5k
        if (!(state->ff_features & CO_FUTURE_ANNOTATIONS)) {
737
20.3k
            CALL(astfold_expr, expr_ty, node_->v.AnnAssign.annotation);
738
20.3k
        }
739
25.5k
        CALL_OPT(astfold_expr, expr_ty, node_->v.AnnAssign.value);
740
25.5k
        break;
741
2.57k
    case TypeAlias_kind:
742
2.57k
        CALL(astfold_expr, expr_ty, node_->v.TypeAlias.name);
743
2.57k
        CALL_SEQ(astfold_type_param, type_param, node_->v.TypeAlias.type_params);
744
2.57k
        CALL(astfold_expr, expr_ty, node_->v.TypeAlias.value);
745
2.57k
        break;
746
494
    case For_kind: {
747
494
        CALL(astfold_expr, expr_ty, node_->v.For.target);
748
494
        CALL(astfold_expr, expr_ty, node_->v.For.iter);
749
494
        BEFORE_LOOP_BODY(state, node_);
750
494
        CALL_SEQ(astfold_stmt, stmt, node_->v.For.body);
751
494
        AFTER_LOOP_BODY(state);
752
494
        CALL_SEQ(astfold_stmt, stmt, node_->v.For.orelse);
753
494
        break;
754
494
    }
755
364
    case AsyncFor_kind: {
756
364
        CALL(astfold_expr, expr_ty, node_->v.AsyncFor.target);
757
364
        CALL(astfold_expr, expr_ty, node_->v.AsyncFor.iter);
758
364
        BEFORE_LOOP_BODY(state, node_);
759
364
        CALL_SEQ(astfold_stmt, stmt, node_->v.AsyncFor.body);
760
364
        AFTER_LOOP_BODY(state);
761
364
        CALL_SEQ(astfold_stmt, stmt, node_->v.AsyncFor.orelse);
762
364
        break;
763
364
    }
764
2.15k
    case While_kind: {
765
2.15k
        CALL(astfold_expr, expr_ty, node_->v.While.test);
766
2.15k
        BEFORE_LOOP_BODY(state, node_);
767
2.15k
        CALL_SEQ(astfold_stmt, stmt, node_->v.While.body);
768
2.15k
        AFTER_LOOP_BODY(state);
769
2.15k
        CALL_SEQ(astfold_stmt, stmt, node_->v.While.orelse);
770
2.15k
        break;
771
2.15k
    }
772
1.42k
    case If_kind:
773
1.42k
        CALL(astfold_expr, expr_ty, node_->v.If.test);
774
1.42k
        CALL_SEQ(astfold_stmt, stmt, node_->v.If.body);
775
1.42k
        CALL_SEQ(astfold_stmt, stmt, node_->v.If.orelse);
776
1.42k
        break;
777
773
    case With_kind:
778
773
        CALL_SEQ(astfold_withitem, withitem, node_->v.With.items);
779
773
        CALL_SEQ(astfold_stmt, stmt, node_->v.With.body);
780
773
        break;
781
1.80k
    case AsyncWith_kind:
782
1.80k
        CALL_SEQ(astfold_withitem, withitem, node_->v.AsyncWith.items);
783
1.80k
        CALL_SEQ(astfold_stmt, stmt, node_->v.AsyncWith.body);
784
1.80k
        break;
785
410
    case Raise_kind:
786
410
        CALL_OPT(astfold_expr, expr_ty, node_->v.Raise.exc);
787
410
        CALL_OPT(astfold_expr, expr_ty, node_->v.Raise.cause);
788
410
        break;
789
4.30k
    case Try_kind: {
790
4.30k
        CALL_SEQ(astfold_stmt, stmt, node_->v.Try.body);
791
4.30k
        CALL_SEQ(astfold_excepthandler, excepthandler, node_->v.Try.handlers);
792
4.30k
        CALL_SEQ(astfold_stmt, stmt, node_->v.Try.orelse);
793
4.30k
        BEFORE_FINALLY(state, node_);
794
4.30k
        CALL_SEQ(astfold_stmt, stmt, node_->v.Try.finalbody);
795
4.30k
        AFTER_FINALLY(state);
796
4.30k
        break;
797
4.30k
    }
798
750
    case TryStar_kind: {
799
750
        CALL_SEQ(astfold_stmt, stmt, node_->v.TryStar.body);
800
750
        CALL_SEQ(astfold_excepthandler, excepthandler, node_->v.TryStar.handlers);
801
750
        CALL_SEQ(astfold_stmt, stmt, node_->v.TryStar.orelse);
802
750
        BEFORE_FINALLY(state, node_);
803
750
        CALL_SEQ(astfold_stmt, stmt, node_->v.TryStar.finalbody);
804
750
        AFTER_FINALLY(state);
805
750
        break;
806
750
    }
807
3.03k
    case Assert_kind:
808
3.03k
        CALL(astfold_expr, expr_ty, node_->v.Assert.test);
809
3.03k
        CALL_OPT(astfold_expr, expr_ty, node_->v.Assert.msg);
810
3.03k
        break;
811
103k
    case Expr_kind:
812
103k
        CALL(astfold_expr, expr_ty, node_->v.Expr.value);
813
103k
        break;
814
756
    case Match_kind:
815
756
        CALL(astfold_expr, expr_ty, node_->v.Match.subject);
816
756
        CALL_SEQ(astfold_match_case, match_case, node_->v.Match.cases);
817
756
        break;
818
224
    case Break_kind:
819
224
        BEFORE_LOOP_EXIT(state, node_, "break");
820
224
        break;
821
850
    case Continue_kind:
822
850
        BEFORE_LOOP_EXIT(state, node_, "continue");
823
850
        break;
824
    // The following statements don't contain any subexpressions to be folded
825
1.77k
    case Import_kind:
826
5.38k
    case ImportFrom_kind:
827
6.18k
    case Global_kind:
828
6.33k
    case Nonlocal_kind:
829
6.80k
    case Pass_kind:
830
6.80k
        break;
831
    // No default case, so the compiler will emit a warning if new statement
832
    // kinds are added without being handled here
833
192k
    }
834
192k
    LEAVE_RECURSIVE();
835
192k
    return 1;
836
192k
}
837
838
static int
839
astfold_excepthandler(excepthandler_ty node_, PyArena *ctx_, _PyASTPreprocessState *state)
840
3.55k
{
841
3.55k
    switch (node_->kind) {
842
3.55k
    case ExceptHandler_kind:
843
3.55k
        CALL_OPT(astfold_expr, expr_ty, node_->v.ExceptHandler.type);
844
3.55k
        CALL_SEQ(astfold_stmt, stmt, node_->v.ExceptHandler.body);
845
3.55k
        break;
846
    // No default case, so the compiler will emit a warning if new handler
847
    // kinds are added without being handled here
848
3.55k
    }
849
3.55k
    return 1;
850
3.55k
}
851
852
static int
853
astfold_withitem(withitem_ty node_, PyArena *ctx_, _PyASTPreprocessState *state)
854
11.7k
{
855
11.7k
    CALL(astfold_expr, expr_ty, node_->context_expr);
856
11.7k
    CALL_OPT(astfold_expr, expr_ty, node_->optional_vars);
857
11.7k
    return 1;
858
11.7k
}
859
860
static int
861
fold_const_match_patterns(expr_ty node, PyArena *ctx_, _PyASTPreprocessState *state)
862
8.84k
{
863
8.84k
    if (state->syntax_check_only) {
864
704
        return 1;
865
704
    }
866
8.13k
    switch (node->kind)
867
8.13k
    {
868
545
        case UnaryOp_kind:
869
545
        {
870
545
            if ((node->v.UnaryOp.op == USub || node->v.UnaryOp.op == UAdd) &&
871
545
                node->v.UnaryOp.operand->kind == Constant_kind)
872
545
            {
873
545
                PyObject *operand = node->v.UnaryOp.operand->v.Constant.value;
874
545
                PyObject *folded = node->v.UnaryOp.op == USub ? PyNumber_Negative(operand) : PyNumber_Positive(operand);
875
545
                return make_const(node, folded, ctx_);
876
545
            }
877
0
            break;
878
545
        }
879
1.52k
        case BinOp_kind:
880
1.52k
        {
881
1.52k
            operator_ty op = node->v.BinOp.op;
882
1.52k
            if ((op == Add || op == Sub) &&
883
1.52k
                node->v.BinOp.right->kind == Constant_kind)
884
1.52k
            {
885
1.52k
                CALL(fold_const_match_patterns, expr_ty, node->v.BinOp.left);
886
1.52k
                if (node->v.BinOp.left->kind == Constant_kind) {
887
1.52k
                    PyObject *left = node->v.BinOp.left->v.Constant.value;
888
1.52k
                    PyObject *right = node->v.BinOp.right->v.Constant.value;
889
1.52k
                    PyObject *folded = op == Add ? PyNumber_Add(left, right) : PyNumber_Subtract(left, right);
890
1.52k
                    return make_const(node, folded, ctx_);
891
1.52k
                }
892
1.52k
            }
893
0
            break;
894
1.52k
        }
895
6.06k
        default:
896
6.06k
            break;
897
8.13k
    }
898
6.06k
    return 1;
899
8.13k
}
900
901
static int
902
astfold_pattern(pattern_ty node_, PyArena *ctx_, _PyASTPreprocessState *state)
903
26.2k
{
904
    // Currently, this is really only used to form complex/negative numeric
905
    // constants in MatchValue and MatchMapping nodes
906
    // We still recurse into all subexpressions and subpatterns anyway
907
26.2k
    ENTER_RECURSIVE();
908
26.2k
    switch (node_->kind) {
909
6.63k
        case MatchValue_kind:
910
6.63k
            CALL(fold_const_match_patterns, expr_ty, node_->v.MatchValue.value);
911
6.63k
            break;
912
453
        case MatchSingleton_kind:
913
453
            break;
914
2.09k
        case MatchSequence_kind:
915
2.09k
            CALL_SEQ(astfold_pattern, pattern, node_->v.MatchSequence.patterns);
916
2.09k
            break;
917
705
        case MatchMapping_kind:
918
705
            CALL_SEQ(fold_const_match_patterns, expr, node_->v.MatchMapping.keys);
919
705
            CALL_SEQ(astfold_pattern, pattern, node_->v.MatchMapping.patterns);
920
705
            break;
921
2.11k
        case MatchClass_kind:
922
2.11k
            CALL(astfold_expr, expr_ty, node_->v.MatchClass.cls);
923
2.11k
            CALL_SEQ(astfold_pattern, pattern, node_->v.MatchClass.patterns);
924
2.11k
            CALL_SEQ(astfold_pattern, pattern, node_->v.MatchClass.kwd_patterns);
925
2.11k
            break;
926
1.26k
        case MatchStar_kind:
927
1.26k
            break;
928
11.0k
        case MatchAs_kind:
929
11.0k
            if (node_->v.MatchAs.pattern) {
930
118
                CALL(astfold_pattern, pattern_ty, node_->v.MatchAs.pattern);
931
118
            }
932
11.0k
            break;
933
11.0k
        case MatchOr_kind:
934
1.91k
            CALL_SEQ(astfold_pattern, pattern, node_->v.MatchOr.patterns);
935
1.91k
            break;
936
    // No default case, so the compiler will emit a warning if new pattern
937
    // kinds are added without being handled here
938
26.2k
    }
939
26.2k
    LEAVE_RECURSIVE();
940
26.2k
    return 1;
941
26.2k
}
942
943
static int
944
astfold_match_case(match_case_ty node_, PyArena *ctx_, _PyASTPreprocessState *state)
945
2.71k
{
946
2.71k
    CALL(astfold_pattern, expr_ty, node_->pattern);
947
2.71k
    CALL_OPT(astfold_expr, expr_ty, node_->guard);
948
2.71k
    CALL_SEQ(astfold_stmt, stmt, node_->body);
949
2.71k
    return 1;
950
2.71k
}
951
952
static int
953
astfold_type_param(type_param_ty node_, PyArena *ctx_, _PyASTPreprocessState *state)
954
16.5k
{
955
16.5k
    switch (node_->kind) {
956
13.5k
        case TypeVar_kind:
957
13.5k
            CALL_OPT(astfold_expr, expr_ty, node_->v.TypeVar.bound);
958
13.5k
            CALL_OPT(astfold_expr, expr_ty, node_->v.TypeVar.default_value);
959
13.5k
            break;
960
1.03k
        case ParamSpec_kind:
961
1.03k
            CALL_OPT(astfold_expr, expr_ty, node_->v.ParamSpec.default_value);
962
1.03k
            break;
963
1.99k
        case TypeVarTuple_kind:
964
1.99k
            CALL_OPT(astfold_expr, expr_ty, node_->v.TypeVarTuple.default_value);
965
1.99k
            break;
966
16.5k
    }
967
16.5k
    return 1;
968
16.5k
}
969
970
#undef CALL
971
#undef CALL_OPT
972
#undef CALL_SEQ
973
974
int
975
_PyAST_Preprocess(mod_ty mod, PyArena *arena, PyObject *filename, int optimize,
976
                  int ff_features, int syntax_check_only, int enable_warnings,
977
                  PyObject *module)
978
14.6k
{
979
14.6k
    _PyASTPreprocessState state;
980
14.6k
    memset(&state, 0, sizeof(_PyASTPreprocessState));
981
14.6k
    state.filename = filename;
982
14.6k
    state.module = module;
983
14.6k
    state.optimize = optimize;
984
14.6k
    state.ff_features = ff_features;
985
14.6k
    state.syntax_check_only = syntax_check_only;
986
14.6k
    state.enable_warnings = enable_warnings;
987
14.6k
    if (_Py_CArray_Init(&state.cf_finally, sizeof(ControlFlowInFinallyContext), 20) < 0) {
988
0
        return -1;
989
0
    }
990
991
14.6k
    int ret = astfold_mod(mod, arena, &state);
992
14.6k
    assert(ret || PyErr_Occurred());
993
994
14.6k
    _Py_CArray_Fini(&state.cf_finally);
995
14.6k
    return ret;
996
14.6k
}