From 678b085936eb746235bf51111f90f6b7bccc8928 Mon Sep 17 00:00:00 2001 From: Yan Yanchii Date: Fri, 28 Mar 2025 12:33:53 +0100 Subject: [PATCH 01/10] rename ast_opt.c -> ast_process.c --- .github/CODEOWNERS | 2 +- InternalDocs/compiler.md | 4 ++-- Makefile.pre.in | 2 +- PCbuild/_freeze_module.vcxproj | 2 +- PCbuild/_freeze_module.vcxproj.filters | 2 +- PCbuild/pythoncore.vcxproj | 2 +- PCbuild/pythoncore.vcxproj.filters | 2 +- Python/{ast_opt.c => ast_process.c} | 0 Tools/c-analyzer/cpython/ignored.tsv | 1 - 9 files changed, 8 insertions(+), 9 deletions(-) rename Python/{ast_opt.c => ast_process.c} (100%) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 11e8acd963aa03..73c21b571b1ddc 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -188,7 +188,7 @@ Include/internal/pycore_time.h @pganssle @abalkin # AST Python/ast.c @isidentical @JelleZijlstra @eclips4 -Python/ast_opt.c @isidentical @eclips4 +Python/ast_process.c @isidentical @eclips4 Parser/asdl.py @isidentical @JelleZijlstra @eclips4 Parser/asdl_c.py @isidentical @JelleZijlstra @eclips4 Lib/ast.py @isidentical @JelleZijlstra @eclips4 diff --git a/InternalDocs/compiler.md b/InternalDocs/compiler.md index 8ca19a42b91b83..cb455cf02fc881 100644 --- a/InternalDocs/compiler.md +++ b/InternalDocs/compiler.md @@ -505,8 +505,8 @@ Important files * [Python/ast.c](../Python/ast.c): Used for validating the AST. - * [Python/ast_opt.c](../Python/ast_opt.c): - Optimizes the AST. + * [Python/ast_process.c](../Python/ast_process.c): + Processes the AST before compiling. * [Python/ast_unparse.c](../Python/ast_unparse.c): Converts the AST expression node back into a string (for string annotations). diff --git a/Makefile.pre.in b/Makefile.pre.in index 9f90df6019dea9..2fb95e924ac587 100644 --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -426,7 +426,7 @@ PYTHON_OBJS= \ Python/asdl.o \ Python/assemble.o \ Python/ast.o \ - Python/ast_opt.o \ + Python/ast_process.o \ Python/ast_unparse.o \ Python/bltinmodule.o \ Python/brc.o \ diff --git a/PCbuild/_freeze_module.vcxproj b/PCbuild/_freeze_module.vcxproj index 1f3f3170f3fa48..fdc40e7a4fa77f 100644 --- a/PCbuild/_freeze_module.vcxproj +++ b/PCbuild/_freeze_module.vcxproj @@ -190,7 +190,7 @@ - + diff --git a/PCbuild/_freeze_module.vcxproj.filters b/PCbuild/_freeze_module.vcxproj.filters index 0a64de1d4f0e88..3c9df1dc7a98f7 100644 --- a/PCbuild/_freeze_module.vcxproj.filters +++ b/PCbuild/_freeze_module.vcxproj.filters @@ -34,7 +34,7 @@ Source Files - + Source Files diff --git a/PCbuild/pythoncore.vcxproj b/PCbuild/pythoncore.vcxproj index d2aafce058d05e..1ae2e8698a5442 100644 --- a/PCbuild/pythoncore.vcxproj +++ b/PCbuild/pythoncore.vcxproj @@ -580,7 +580,7 @@ - + diff --git a/PCbuild/pythoncore.vcxproj.filters b/PCbuild/pythoncore.vcxproj.filters index 873f7d65a26a87..8ff96b3601cbb0 100644 --- a/PCbuild/pythoncore.vcxproj.filters +++ b/PCbuild/pythoncore.vcxproj.filters @@ -1325,7 +1325,7 @@ Python - + Python diff --git a/Python/ast_opt.c b/Python/ast_process.c similarity index 100% rename from Python/ast_opt.c rename to Python/ast_process.c diff --git a/Tools/c-analyzer/cpython/ignored.tsv b/Tools/c-analyzer/cpython/ignored.tsv index 2be3e1a420b91d..b128abca39fb41 100644 --- a/Tools/c-analyzer/cpython/ignored.tsv +++ b/Tools/c-analyzer/cpython/ignored.tsv @@ -349,7 +349,6 @@ Objects/unicodeobject.c unicode_translate_call_errorhandler argparse - Parser/parser.c - reserved_keywords - Parser/parser.c - soft_keywords - Parser/lexer/lexer.c - type_comment_prefix - -Python/ast_opt.c fold_unaryop ops - Python/ceval.c - _PyEval_BinaryOps - Python/ceval.c - _Py_INTERPRETER_TRAMPOLINE_INSTRUCTIONS - Python/codecs.c - Py_hexdigits - From e080e27a69993e0444350b8a3322660b84094888 Mon Sep 17 00:00:00 2001 From: Yan Yanchii Date: Fri, 28 Mar 2025 14:34:50 +0100 Subject: [PATCH 02/10] _PyASTOptimizeState -> _PyASTProcessState --- Python/ast_process.c | 73 ++++++++++++++++++++++---------------------- 1 file changed, 36 insertions(+), 37 deletions(-) diff --git a/Python/ast_process.c b/Python/ast_process.c index 4d5e5589ac06ca..fcc778d8cb78f2 100644 --- a/Python/ast_process.c +++ b/Python/ast_process.c @@ -1,4 +1,3 @@ -/* AST Optimizer */ #include "Python.h" #include "pycore_ast.h" // _PyAST_GetDocString() #include "pycore_c_array.h" // _Py_CArray_EnsureCapacity() @@ -22,7 +21,7 @@ typedef struct { _Py_c_array_t cf_finally; /* context for PEP 765 check */ int cf_finally_used; -} _PyASTOptimizeState; +} _PyASTProcessState; #define ENTER_RECURSIVE() \ if (Py_EnterRecursiveCall(" during compilation")) { \ @@ -32,14 +31,14 @@ if (Py_EnterRecursiveCall(" during compilation")) { \ #define LEAVE_RECURSIVE() Py_LeaveRecursiveCall(); static ControlFlowInFinallyContext* -get_cf_finally_top(_PyASTOptimizeState *state) +get_cf_finally_top(_PyASTProcessState *state) { int idx = state->cf_finally_used; return ((ControlFlowInFinallyContext*)state->cf_finally.array) + idx; } static int -push_cf_context(_PyASTOptimizeState *state, stmt_ty node, bool finally, bool funcdef, bool loop) +push_cf_context(_PyASTProcessState *state, stmt_ty node, bool finally, bool funcdef, bool loop) { if (_Py_CArray_EnsureCapacity(&state->cf_finally, state->cf_finally_used+1) < 0) { return 0; @@ -55,14 +54,14 @@ push_cf_context(_PyASTOptimizeState *state, stmt_ty node, bool finally, bool fun } static void -pop_cf_context(_PyASTOptimizeState *state) +pop_cf_context(_PyASTProcessState *state) { assert(state->cf_finally_used > 0); state->cf_finally_used--; } static int -control_flow_in_finally_warning(const char *kw, stmt_ty n, _PyASTOptimizeState *state) +control_flow_in_finally_warning(const char *kw, stmt_ty n, _PyASTProcessState *state) { PyObject *msg = PyUnicode_FromFormat("'%s' in a 'finally' block", kw); if (msg == NULL) { @@ -76,7 +75,7 @@ control_flow_in_finally_warning(const char *kw, stmt_ty n, _PyASTOptimizeState * } static int -before_return(_PyASTOptimizeState *state, stmt_ty node_) +before_return(_PyASTProcessState *state, stmt_ty node_) { if (state->cf_finally_used > 0) { ControlFlowInFinallyContext *ctx = get_cf_finally_top(state); @@ -90,7 +89,7 @@ before_return(_PyASTOptimizeState *state, stmt_ty node_) } static int -before_loop_exit(_PyASTOptimizeState *state, stmt_ty node_, const char *kw) +before_loop_exit(_PyASTProcessState *state, stmt_ty node_, const char *kw) { if (state->cf_finally_used > 0) { ControlFlowInFinallyContext *ctx = get_cf_finally_top(state); @@ -365,7 +364,7 @@ optimize_format(expr_ty node, PyObject *fmt, asdl_expr_seq *elts, PyArena *arena } static int -fold_binop(expr_ty node, PyArena *arena, _PyASTOptimizeState *state) +fold_binop(expr_ty node, PyArena *arena, _PyASTProcessState *state) { if (state->syntax_check_only) { return 1; @@ -389,18 +388,18 @@ fold_binop(expr_ty node, PyArena *arena, _PyASTOptimizeState *state) return 1; } -static int astfold_mod(mod_ty node_, PyArena *ctx_, _PyASTOptimizeState *state); -static int astfold_stmt(stmt_ty node_, PyArena *ctx_, _PyASTOptimizeState *state); -static int astfold_expr(expr_ty node_, PyArena *ctx_, _PyASTOptimizeState *state); -static int astfold_arguments(arguments_ty node_, PyArena *ctx_, _PyASTOptimizeState *state); -static int astfold_comprehension(comprehension_ty node_, PyArena *ctx_, _PyASTOptimizeState *state); -static int astfold_keyword(keyword_ty node_, PyArena *ctx_, _PyASTOptimizeState *state); -static int astfold_arg(arg_ty node_, PyArena *ctx_, _PyASTOptimizeState *state); -static int astfold_withitem(withitem_ty node_, PyArena *ctx_, _PyASTOptimizeState *state); -static int astfold_excepthandler(excepthandler_ty node_, PyArena *ctx_, _PyASTOptimizeState *state); -static int astfold_match_case(match_case_ty node_, PyArena *ctx_, _PyASTOptimizeState *state); -static int astfold_pattern(pattern_ty node_, PyArena *ctx_, _PyASTOptimizeState *state); -static int astfold_type_param(type_param_ty node_, PyArena *ctx_, _PyASTOptimizeState *state); +static int astfold_mod(mod_ty node_, PyArena *ctx_, _PyASTProcessState *state); +static int astfold_stmt(stmt_ty node_, PyArena *ctx_, _PyASTProcessState *state); +static int astfold_expr(expr_ty node_, PyArena *ctx_, _PyASTProcessState *state); +static int astfold_arguments(arguments_ty node_, PyArena *ctx_, _PyASTProcessState *state); +static int astfold_comprehension(comprehension_ty node_, PyArena *ctx_, _PyASTProcessState *state); +static int astfold_keyword(keyword_ty node_, PyArena *ctx_, _PyASTProcessState *state); +static int astfold_arg(arg_ty node_, PyArena *ctx_, _PyASTProcessState *state); +static int astfold_withitem(withitem_ty node_, PyArena *ctx_, _PyASTProcessState *state); +static int astfold_excepthandler(excepthandler_ty node_, PyArena *ctx_, _PyASTProcessState *state); +static int astfold_match_case(match_case_ty node_, PyArena *ctx_, _PyASTProcessState *state); +static int astfold_pattern(pattern_ty node_, PyArena *ctx_, _PyASTProcessState *state); +static int astfold_type_param(type_param_ty node_, PyArena *ctx_, _PyASTProcessState *state); #define CALL(FUNC, TYPE, ARG) \ if (!FUNC((ARG), ctx_, state)) \ @@ -436,7 +435,7 @@ stmt_seq_remove_item(asdl_stmt_seq *stmts, Py_ssize_t idx) } static int -astfold_body(asdl_stmt_seq *stmts, PyArena *ctx_, _PyASTOptimizeState *state) +astfold_body(asdl_stmt_seq *stmts, PyArena *ctx_, _PyASTProcessState *state) { int docstring = _PyAST_GetDocString(stmts) != NULL; if (docstring && (state->optimize >= 2)) { @@ -466,7 +465,7 @@ astfold_body(asdl_stmt_seq *stmts, PyArena *ctx_, _PyASTOptimizeState *state) } static int -astfold_mod(mod_ty node_, PyArena *ctx_, _PyASTOptimizeState *state) +astfold_mod(mod_ty node_, PyArena *ctx_, _PyASTProcessState *state) { switch (node_->kind) { case Module_kind: @@ -488,7 +487,7 @@ astfold_mod(mod_ty node_, PyArena *ctx_, _PyASTOptimizeState *state) } static int -astfold_expr(expr_ty node_, PyArena *ctx_, _PyASTOptimizeState *state) +astfold_expr(expr_ty node_, PyArena *ctx_, _PyASTProcessState *state) { ENTER_RECURSIVE(); switch (node_->kind) { @@ -613,14 +612,14 @@ astfold_expr(expr_ty node_, PyArena *ctx_, _PyASTOptimizeState *state) } static int -astfold_keyword(keyword_ty node_, PyArena *ctx_, _PyASTOptimizeState *state) +astfold_keyword(keyword_ty node_, PyArena *ctx_, _PyASTProcessState *state) { CALL(astfold_expr, expr_ty, node_->value); return 1; } static int -astfold_comprehension(comprehension_ty node_, PyArena *ctx_, _PyASTOptimizeState *state) +astfold_comprehension(comprehension_ty node_, PyArena *ctx_, _PyASTProcessState *state) { CALL(astfold_expr, expr_ty, node_->target); CALL(astfold_expr, expr_ty, node_->iter); @@ -629,7 +628,7 @@ astfold_comprehension(comprehension_ty node_, PyArena *ctx_, _PyASTOptimizeState } static int -astfold_arguments(arguments_ty node_, PyArena *ctx_, _PyASTOptimizeState *state) +astfold_arguments(arguments_ty node_, PyArena *ctx_, _PyASTProcessState *state) { CALL_SEQ(astfold_arg, arg, node_->posonlyargs); CALL_SEQ(astfold_arg, arg, node_->args); @@ -642,7 +641,7 @@ astfold_arguments(arguments_ty node_, PyArena *ctx_, _PyASTOptimizeState *state) } static int -astfold_arg(arg_ty node_, PyArena *ctx_, _PyASTOptimizeState *state) +astfold_arg(arg_ty node_, PyArena *ctx_, _PyASTProcessState *state) { if (!(state->ff_features & CO_FUTURE_ANNOTATIONS)) { CALL_OPT(astfold_expr, expr_ty, node_->annotation); @@ -651,7 +650,7 @@ astfold_arg(arg_ty node_, PyArena *ctx_, _PyASTOptimizeState *state) } static int -astfold_stmt(stmt_ty node_, PyArena *ctx_, _PyASTOptimizeState *state) +astfold_stmt(stmt_ty node_, PyArena *ctx_, _PyASTProcessState *state) { ENTER_RECURSIVE(); switch (node_->kind) { @@ -806,7 +805,7 @@ astfold_stmt(stmt_ty node_, PyArena *ctx_, _PyASTOptimizeState *state) } static int -astfold_excepthandler(excepthandler_ty node_, PyArena *ctx_, _PyASTOptimizeState *state) +astfold_excepthandler(excepthandler_ty node_, PyArena *ctx_, _PyASTProcessState *state) { switch (node_->kind) { case ExceptHandler_kind: @@ -820,7 +819,7 @@ astfold_excepthandler(excepthandler_ty node_, PyArena *ctx_, _PyASTOptimizeState } static int -astfold_withitem(withitem_ty node_, PyArena *ctx_, _PyASTOptimizeState *state) +astfold_withitem(withitem_ty node_, PyArena *ctx_, _PyASTProcessState *state) { CALL(astfold_expr, expr_ty, node_->context_expr); CALL_OPT(astfold_expr, expr_ty, node_->optional_vars); @@ -828,7 +827,7 @@ astfold_withitem(withitem_ty node_, PyArena *ctx_, _PyASTOptimizeState *state) } static int -fold_const_match_patterns(expr_ty node, PyArena *ctx_, _PyASTOptimizeState *state) +fold_const_match_patterns(expr_ty node, PyArena *ctx_, _PyASTProcessState *state) { if (state->syntax_check_only) { return 1; @@ -869,7 +868,7 @@ fold_const_match_patterns(expr_ty node, PyArena *ctx_, _PyASTOptimizeState *stat } static int -astfold_pattern(pattern_ty node_, PyArena *ctx_, _PyASTOptimizeState *state) +astfold_pattern(pattern_ty node_, PyArena *ctx_, _PyASTProcessState *state) { // Currently, this is really only used to form complex/negative numeric // constants in MatchValue and MatchMapping nodes @@ -911,7 +910,7 @@ astfold_pattern(pattern_ty node_, PyArena *ctx_, _PyASTOptimizeState *state) } static int -astfold_match_case(match_case_ty node_, PyArena *ctx_, _PyASTOptimizeState *state) +astfold_match_case(match_case_ty node_, PyArena *ctx_, _PyASTProcessState *state) { CALL(astfold_pattern, expr_ty, node_->pattern); CALL_OPT(astfold_expr, expr_ty, node_->guard); @@ -920,7 +919,7 @@ astfold_match_case(match_case_ty node_, PyArena *ctx_, _PyASTOptimizeState *stat } static int -astfold_type_param(type_param_ty node_, PyArena *ctx_, _PyASTOptimizeState *state) +astfold_type_param(type_param_ty node_, PyArena *ctx_, _PyASTProcessState *state) { switch (node_->kind) { case TypeVar_kind: @@ -945,8 +944,8 @@ int _PyAST_Optimize(mod_ty mod, PyArena *arena, PyObject *filename, int optimize, int ff_features, int syntax_check_only) { - _PyASTOptimizeState state; - memset(&state, 0, sizeof(_PyASTOptimizeState)); + _PyASTProcessState state; + memset(&state, 0, sizeof(_PyASTProcessState)); state.filename = filename; state.optimize = optimize; state.ff_features = ff_features; From 5153ea52377471891a3e56bd69cf7773d6dd490b Mon Sep 17 00:00:00 2001 From: Yan Yanchii Date: Fri, 28 Mar 2025 14:38:20 +0100 Subject: [PATCH 03/10] _PyAST_Optimize -> _PyAST_Process --- Include/internal/pycore_compile.h | 2 +- Python/ast_process.c | 2 +- Python/compile.c | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Include/internal/pycore_compile.h b/Include/internal/pycore_compile.h index a606c2afe0a234..2cd88ca2ca4392 100644 --- a/Include/internal/pycore_compile.h +++ b/Include/internal/pycore_compile.h @@ -43,7 +43,7 @@ extern int _PyCompile_AstOptimize( struct _arena *arena, int syntax_check_only); -extern int _PyAST_Optimize( +extern int _PyAST_Process( struct _mod *, struct _arena *arena, PyObject *filename, diff --git a/Python/ast_process.c b/Python/ast_process.c index fcc778d8cb78f2..881cca905dfd9f 100644 --- a/Python/ast_process.c +++ b/Python/ast_process.c @@ -941,7 +941,7 @@ astfold_type_param(type_param_ty node_, PyArena *ctx_, _PyASTProcessState *state #undef CALL_SEQ int -_PyAST_Optimize(mod_ty mod, PyArena *arena, PyObject *filename, int optimize, +_PyAST_Process(mod_ty mod, PyArena *arena, PyObject *filename, int optimize, int ff_features, int syntax_check_only) { _PyASTProcessState state; diff --git a/Python/compile.c b/Python/compile.c index 15ef7214d44b9c..0f74a8aea7011e 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -135,7 +135,7 @@ compiler_setup(compiler *c, mod_ty mod, PyObject *filename, c->c_optimize = (optimize == -1) ? _Py_GetConfig()->optimization_level : optimize; c->c_save_nested_seqs = false; - if (!_PyAST_Optimize(mod, arena, filename, c->c_optimize, merged, 0)) { + if (!_PyAST_Process(mod, arena, filename, c->c_optimize, merged, 0)) { return ERROR; } c->c_st = _PySymtable_Build(mod, filename, &c->c_future); @@ -1492,7 +1492,7 @@ _PyCompile_AstOptimize(mod_ty mod, PyObject *filename, PyCompilerFlags *cf, if (optimize == -1) { optimize = _Py_GetConfig()->optimization_level; } - if (!_PyAST_Optimize(mod, arena, filename, optimize, flags, no_const_folding)) { + if (!_PyAST_Process(mod, arena, filename, optimize, flags, no_const_folding)) { return -1; } return 0; From ad5d0809637a721a2efdb37ab843bfaebbf3a8eb Mon Sep 17 00:00:00 2001 From: Yan Yanchii Date: Fri, 28 Mar 2025 14:40:28 +0100 Subject: [PATCH 04/10] _PyCompile_AstOptimize -> _PyCompile_AstProcess --- Include/internal/pycore_compile.h | 4 ++-- Python/bltinmodule.c | 2 +- Python/compile.c | 2 +- Python/pythonrun.c | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Include/internal/pycore_compile.h b/Include/internal/pycore_compile.h index 2cd88ca2ca4392..4aeb46364cbb32 100644 --- a/Include/internal/pycore_compile.h +++ b/Include/internal/pycore_compile.h @@ -34,8 +34,8 @@ PyAPI_FUNC(PyCodeObject*) _PyAST_Compile( int optimize, struct _arena *arena); -/* AST optimizations */ -extern int _PyCompile_AstOptimize( +/* AST processing */ +extern int _PyCompile_AstProcess( struct _mod *mod, PyObject *filename, PyCompilerFlags *flags, diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index 3221d5acf96f71..46ae6a7d963df7 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -845,7 +845,7 @@ builtin_compile_impl(PyObject *module, PyObject *source, PyObject *filename, goto error; } int syntax_check_only = ((flags & PyCF_OPTIMIZED_AST) == PyCF_ONLY_AST); /* unoptiomized AST */ - if (_PyCompile_AstOptimize(mod, filename, &cf, optimize, + if (_PyCompile_AstProcess(mod, filename, &cf, optimize, arena, syntax_check_only) < 0) { _PyArena_Free(arena); goto error; diff --git a/Python/compile.c b/Python/compile.c index 0f74a8aea7011e..c1d21a765cf218 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -1481,7 +1481,7 @@ _PyAST_Compile(mod_ty mod, PyObject *filename, PyCompilerFlags *pflags, } int -_PyCompile_AstOptimize(mod_ty mod, PyObject *filename, PyCompilerFlags *cf, +_PyCompile_AstProcess(mod_ty mod, PyObject *filename, PyCompilerFlags *cf, int optimize, PyArena *arena, int no_const_folding) { _PyFutureFeatures future; diff --git a/Python/pythonrun.c b/Python/pythonrun.c index 23af8b6f6be8e8..35260f5893d1d1 100644 --- a/Python/pythonrun.c +++ b/Python/pythonrun.c @@ -1498,7 +1498,7 @@ Py_CompileStringObject(const char *str, PyObject *filename, int start, } if (flags && (flags->cf_flags & PyCF_ONLY_AST)) { int syntax_check_only = ((flags->cf_flags & PyCF_OPTIMIZED_AST) == PyCF_ONLY_AST); /* unoptiomized AST */ - if (_PyCompile_AstOptimize(mod, filename, flags, optimize, arena, syntax_check_only) < 0) { + if (_PyCompile_AstProcess(mod, filename, flags, optimize, arena, syntax_check_only) < 0) { _PyArena_Free(arena); return NULL; } From 3a6abefa17e5e85a00c514128f9d5d6fb6ed50d4 Mon Sep 17 00:00:00 2001 From: Yan Yanchii Date: Fri, 28 Mar 2025 15:08:05 +0100 Subject: [PATCH 05/10] add news --- .../2025-03-28-15-06-55.gh-issue-126835.IpcMTn.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Misc/NEWS.d/next/Core_and_Builtins/2025-03-28-15-06-55.gh-issue-126835.IpcMTn.rst diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2025-03-28-15-06-55.gh-issue-126835.IpcMTn.rst b/Misc/NEWS.d/next/Core_and_Builtins/2025-03-28-15-06-55.gh-issue-126835.IpcMTn.rst new file mode 100644 index 00000000000000..f4cfcc7a787a13 --- /dev/null +++ b/Misc/NEWS.d/next/Core_and_Builtins/2025-03-28-15-06-55.gh-issue-126835.IpcMTn.rst @@ -0,0 +1,2 @@ +Move constant folding to the peephole optimizer. Rename AST optimization +related files/structs/functions. From e2a3cbc84e37ae935d7dc2e004eb21c0cc2e2cd6 Mon Sep 17 00:00:00 2001 From: Yan Yanchii Date: Fri, 28 Mar 2025 15:45:42 +0100 Subject: [PATCH 06/10] address review --- .../2025-03-28-15-06-55.gh-issue-126835.IpcMTn.rst | 3 ++- Python/ast_process.c | 2 +- Python/compile.c | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2025-03-28-15-06-55.gh-issue-126835.IpcMTn.rst b/Misc/NEWS.d/next/Core_and_Builtins/2025-03-28-15-06-55.gh-issue-126835.IpcMTn.rst index f4cfcc7a787a13..0ff82417abaa9a 100644 --- a/Misc/NEWS.d/next/Core_and_Builtins/2025-03-28-15-06-55.gh-issue-126835.IpcMTn.rst +++ b/Misc/NEWS.d/next/Core_and_Builtins/2025-03-28-15-06-55.gh-issue-126835.IpcMTn.rst @@ -1,2 +1,3 @@ Move constant folding to the peephole optimizer. Rename AST optimization -related files/structs/functions. +related files (ast_opt.c -> ast_process.c), structs (_PyASTOptimizeState -> _PyASTProcessState) +and functions (_PyAST_Optimize -> _PyAST_Process, _PyCompile_AstOptimize -> _PyCompile_AstProcess). diff --git a/Python/ast_process.c b/Python/ast_process.c index 881cca905dfd9f..2cd303da35da0d 100644 --- a/Python/ast_process.c +++ b/Python/ast_process.c @@ -942,7 +942,7 @@ astfold_type_param(type_param_ty node_, PyArena *ctx_, _PyASTProcessState *state int _PyAST_Process(mod_ty mod, PyArena *arena, PyObject *filename, int optimize, - int ff_features, int syntax_check_only) + int ff_features, int syntax_check_only) { _PyASTProcessState state; memset(&state, 0, sizeof(_PyASTProcessState)); diff --git a/Python/compile.c b/Python/compile.c index c1d21a765cf218..e0a67b3c8b037e 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -1482,7 +1482,7 @@ _PyAST_Compile(mod_ty mod, PyObject *filename, PyCompilerFlags *pflags, int _PyCompile_AstProcess(mod_ty mod, PyObject *filename, PyCompilerFlags *cf, - int optimize, PyArena *arena, int no_const_folding) + int optimize, PyArena *arena, int no_const_folding) { _PyFutureFeatures future; if (!_PyFuture_FromAST(mod, filename, &future)) { From 2d1bc6fa0a81e4e9643e41c371d58757852a449f Mon Sep 17 00:00:00 2001 From: Yan Yanchii Date: Fri, 28 Mar 2025 15:48:09 +0100 Subject: [PATCH 07/10] mention full file path --- .../2025-03-28-15-06-55.gh-issue-126835.IpcMTn.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2025-03-28-15-06-55.gh-issue-126835.IpcMTn.rst b/Misc/NEWS.d/next/Core_and_Builtins/2025-03-28-15-06-55.gh-issue-126835.IpcMTn.rst index 0ff82417abaa9a..9ed55660e9c712 100644 --- a/Misc/NEWS.d/next/Core_and_Builtins/2025-03-28-15-06-55.gh-issue-126835.IpcMTn.rst +++ b/Misc/NEWS.d/next/Core_and_Builtins/2025-03-28-15-06-55.gh-issue-126835.IpcMTn.rst @@ -1,3 +1,3 @@ Move constant folding to the peephole optimizer. Rename AST optimization -related files (ast_opt.c -> ast_process.c), structs (_PyASTOptimizeState -> _PyASTProcessState) +related files (Python/ast_opt.c -> Python/ast_process.c), structs (_PyASTOptimizeState -> _PyASTProcessState) and functions (_PyAST_Optimize -> _PyAST_Process, _PyCompile_AstOptimize -> _PyCompile_AstProcess). From 3b434604954079dbea978a5d08406d735ef36364 Mon Sep 17 00:00:00 2001 From: Yan Yanchii Date: Sun, 4 May 2025 09:22:30 +0200 Subject: [PATCH 08/10] rename process to preprocess --- .github/CODEOWNERS | 2 +- Include/internal/pycore_compile.h | 6 +++--- InternalDocs/compiler.md | 4 ++-- Makefile.pre.in | 2 +- .../2025-03-28-15-06-55.gh-issue-126835.IpcMTn.rst | 4 ++-- PCbuild/_freeze_module.vcxproj | 2 +- PCbuild/_freeze_module.vcxproj.filters | 2 +- PCbuild/pythoncore.vcxproj | 2 +- PCbuild/pythoncore.vcxproj.filters | 2 +- Python/{ast_process.c => ast_preprocess.c} | 4 ++-- Python/bltinmodule.c | 2 +- Python/compile.c | 8 ++++---- Python/pythonrun.c | 2 +- 13 files changed, 21 insertions(+), 21 deletions(-) rename Python/{ast_process.c => ast_preprocess.c} (99%) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 73c21b571b1ddc..16331b65e52979 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -188,7 +188,7 @@ Include/internal/pycore_time.h @pganssle @abalkin # AST Python/ast.c @isidentical @JelleZijlstra @eclips4 -Python/ast_process.c @isidentical @eclips4 +Python/ast_preprocess.c @isidentical @eclips4 Parser/asdl.py @isidentical @JelleZijlstra @eclips4 Parser/asdl_c.py @isidentical @JelleZijlstra @eclips4 Lib/ast.py @isidentical @JelleZijlstra @eclips4 diff --git a/Include/internal/pycore_compile.h b/Include/internal/pycore_compile.h index 4aeb46364cbb32..aecc50be1e6c34 100644 --- a/Include/internal/pycore_compile.h +++ b/Include/internal/pycore_compile.h @@ -34,8 +34,8 @@ PyAPI_FUNC(PyCodeObject*) _PyAST_Compile( int optimize, struct _arena *arena); -/* AST processing */ -extern int _PyCompile_AstProcess( +/* AST preprocessing */ +extern int _PyCompile_AstPreprocess( struct _mod *mod, PyObject *filename, PyCompilerFlags *flags, @@ -43,7 +43,7 @@ extern int _PyCompile_AstProcess( struct _arena *arena, int syntax_check_only); -extern int _PyAST_Process( +extern int _PyAST_Preprocess( struct _mod *, struct _arena *arena, PyObject *filename, diff --git a/InternalDocs/compiler.md b/InternalDocs/compiler.md index cb455cf02fc881..02bbdf6071fa12 100644 --- a/InternalDocs/compiler.md +++ b/InternalDocs/compiler.md @@ -505,8 +505,8 @@ Important files * [Python/ast.c](../Python/ast.c): Used for validating the AST. - * [Python/ast_process.c](../Python/ast_process.c): - Processes the AST before compiling. + * [Python/ast_preprocess.c](../Python/ast_preprocess.c): + Preprocesses the AST before compiling. * [Python/ast_unparse.c](../Python/ast_unparse.c): Converts the AST expression node back into a string (for string annotations). diff --git a/Makefile.pre.in b/Makefile.pre.in index 2fb95e924ac587..88b66561293ca5 100644 --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -426,7 +426,7 @@ PYTHON_OBJS= \ Python/asdl.o \ Python/assemble.o \ Python/ast.o \ - Python/ast_process.o \ + Python/ast_preprocess.o \ Python/ast_unparse.o \ Python/bltinmodule.o \ Python/brc.o \ diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2025-03-28-15-06-55.gh-issue-126835.IpcMTn.rst b/Misc/NEWS.d/next/Core_and_Builtins/2025-03-28-15-06-55.gh-issue-126835.IpcMTn.rst index 9ed55660e9c712..36f6b06d8b7b90 100644 --- a/Misc/NEWS.d/next/Core_and_Builtins/2025-03-28-15-06-55.gh-issue-126835.IpcMTn.rst +++ b/Misc/NEWS.d/next/Core_and_Builtins/2025-03-28-15-06-55.gh-issue-126835.IpcMTn.rst @@ -1,3 +1,3 @@ Move constant folding to the peephole optimizer. Rename AST optimization -related files (Python/ast_opt.c -> Python/ast_process.c), structs (_PyASTOptimizeState -> _PyASTProcessState) -and functions (_PyAST_Optimize -> _PyAST_Process, _PyCompile_AstOptimize -> _PyCompile_AstProcess). +related files (Python/ast_opt.c -> Python/ast_preprocess.c), structs (_PyASTOptimizeState -> _PyASTProcessState) +and functions (_PyAST_Optimize -> _PyAST_Preprocess, _PyCompile_AstOptimize -> _PyCompile_AstPreprocess). diff --git a/PCbuild/_freeze_module.vcxproj b/PCbuild/_freeze_module.vcxproj index fdc40e7a4fa77f..8c161835af9a8c 100644 --- a/PCbuild/_freeze_module.vcxproj +++ b/PCbuild/_freeze_module.vcxproj @@ -190,7 +190,7 @@ - + diff --git a/PCbuild/_freeze_module.vcxproj.filters b/PCbuild/_freeze_module.vcxproj.filters index 3c9df1dc7a98f7..332d466b1f7409 100644 --- a/PCbuild/_freeze_module.vcxproj.filters +++ b/PCbuild/_freeze_module.vcxproj.filters @@ -34,7 +34,7 @@ Source Files - + Source Files diff --git a/PCbuild/pythoncore.vcxproj b/PCbuild/pythoncore.vcxproj index 1ae2e8698a5442..549d6284972afc 100644 --- a/PCbuild/pythoncore.vcxproj +++ b/PCbuild/pythoncore.vcxproj @@ -580,7 +580,7 @@ - + diff --git a/PCbuild/pythoncore.vcxproj.filters b/PCbuild/pythoncore.vcxproj.filters index 8ff96b3601cbb0..0e6d42cc959ba5 100644 --- a/PCbuild/pythoncore.vcxproj.filters +++ b/PCbuild/pythoncore.vcxproj.filters @@ -1325,7 +1325,7 @@ Python - + Python diff --git a/Python/ast_process.c b/Python/ast_preprocess.c similarity index 99% rename from Python/ast_process.c rename to Python/ast_preprocess.c index 2cd303da35da0d..60c14c79db3e5b 100644 --- a/Python/ast_process.c +++ b/Python/ast_preprocess.c @@ -941,8 +941,8 @@ astfold_type_param(type_param_ty node_, PyArena *ctx_, _PyASTProcessState *state #undef CALL_SEQ int -_PyAST_Process(mod_ty mod, PyArena *arena, PyObject *filename, int optimize, - int ff_features, int syntax_check_only) +_PyAST_Preprocess(mod_ty mod, PyArena *arena, PyObject *filename, int optimize, + int ff_features, int syntax_check_only) { _PyASTProcessState state; memset(&state, 0, sizeof(_PyASTProcessState)); diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index 46ae6a7d963df7..3d0295ee3883f2 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -845,7 +845,7 @@ builtin_compile_impl(PyObject *module, PyObject *source, PyObject *filename, goto error; } int syntax_check_only = ((flags & PyCF_OPTIMIZED_AST) == PyCF_ONLY_AST); /* unoptiomized AST */ - if (_PyCompile_AstProcess(mod, filename, &cf, optimize, + if (_PyCompile_AstPreprocess(mod, filename, &cf, optimize, arena, syntax_check_only) < 0) { _PyArena_Free(arena); goto error; diff --git a/Python/compile.c b/Python/compile.c index e0a67b3c8b037e..c04391e682f9ac 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -135,7 +135,7 @@ compiler_setup(compiler *c, mod_ty mod, PyObject *filename, c->c_optimize = (optimize == -1) ? _Py_GetConfig()->optimization_level : optimize; c->c_save_nested_seqs = false; - if (!_PyAST_Process(mod, arena, filename, c->c_optimize, merged, 0)) { + if (!_PyAST_Preprocess(mod, arena, filename, c->c_optimize, merged, 0)) { return ERROR; } c->c_st = _PySymtable_Build(mod, filename, &c->c_future); @@ -1481,8 +1481,8 @@ _PyAST_Compile(mod_ty mod, PyObject *filename, PyCompilerFlags *pflags, } int -_PyCompile_AstProcess(mod_ty mod, PyObject *filename, PyCompilerFlags *cf, - int optimize, PyArena *arena, int no_const_folding) +_PyCompile_AstPreprocess(mod_ty mod, PyObject *filename, PyCompilerFlags *cf, + int optimize, PyArena *arena, int no_const_folding) { _PyFutureFeatures future; if (!_PyFuture_FromAST(mod, filename, &future)) { @@ -1492,7 +1492,7 @@ _PyCompile_AstProcess(mod_ty mod, PyObject *filename, PyCompilerFlags *cf, if (optimize == -1) { optimize = _Py_GetConfig()->optimization_level; } - if (!_PyAST_Process(mod, arena, filename, optimize, flags, no_const_folding)) { + if (!_PyAST_Preprocess(mod, arena, filename, optimize, flags, no_const_folding)) { return -1; } return 0; diff --git a/Python/pythonrun.c b/Python/pythonrun.c index 35260f5893d1d1..4ee287af72fdb2 100644 --- a/Python/pythonrun.c +++ b/Python/pythonrun.c @@ -1498,7 +1498,7 @@ Py_CompileStringObject(const char *str, PyObject *filename, int start, } if (flags && (flags->cf_flags & PyCF_ONLY_AST)) { int syntax_check_only = ((flags->cf_flags & PyCF_OPTIMIZED_AST) == PyCF_ONLY_AST); /* unoptiomized AST */ - if (_PyCompile_AstProcess(mod, filename, flags, optimize, arena, syntax_check_only) < 0) { + if (_PyCompile_AstPreprocess(mod, filename, flags, optimize, arena, syntax_check_only) < 0) { _PyArena_Free(arena); return NULL; } From 72cca4fc50672a2cb42cf88a23f6c17cfba0a4d0 Mon Sep 17 00:00:00 2001 From: Yan Yanchii Date: Sun, 4 May 2025 09:31:43 +0200 Subject: [PATCH 09/10] _PyASTProcessState -> _PyASTPreprocessState --- ...-03-28-15-06-55.gh-issue-126835.IpcMTn.rst | 2 +- Python/ast_preprocess.c | 72 +++++++++---------- 2 files changed, 37 insertions(+), 37 deletions(-) diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2025-03-28-15-06-55.gh-issue-126835.IpcMTn.rst b/Misc/NEWS.d/next/Core_and_Builtins/2025-03-28-15-06-55.gh-issue-126835.IpcMTn.rst index 36f6b06d8b7b90..caa7784acd7124 100644 --- a/Misc/NEWS.d/next/Core_and_Builtins/2025-03-28-15-06-55.gh-issue-126835.IpcMTn.rst +++ b/Misc/NEWS.d/next/Core_and_Builtins/2025-03-28-15-06-55.gh-issue-126835.IpcMTn.rst @@ -1,3 +1,3 @@ Move constant folding to the peephole optimizer. Rename AST optimization -related files (Python/ast_opt.c -> Python/ast_preprocess.c), structs (_PyASTOptimizeState -> _PyASTProcessState) +related files (Python/ast_opt.c -> Python/ast_preprocess.c), structs (_PyASTOptimizeState -> _PyASTPreprocessState) and functions (_PyAST_Optimize -> _PyAST_Preprocess, _PyCompile_AstOptimize -> _PyCompile_AstPreprocess). diff --git a/Python/ast_preprocess.c b/Python/ast_preprocess.c index 60c14c79db3e5b..db8de4dd004546 100644 --- a/Python/ast_preprocess.c +++ b/Python/ast_preprocess.c @@ -21,7 +21,7 @@ typedef struct { _Py_c_array_t cf_finally; /* context for PEP 765 check */ int cf_finally_used; -} _PyASTProcessState; +} _PyASTPreprocessState; #define ENTER_RECURSIVE() \ if (Py_EnterRecursiveCall(" during compilation")) { \ @@ -31,14 +31,14 @@ if (Py_EnterRecursiveCall(" during compilation")) { \ #define LEAVE_RECURSIVE() Py_LeaveRecursiveCall(); static ControlFlowInFinallyContext* -get_cf_finally_top(_PyASTProcessState *state) +get_cf_finally_top(_PyASTPreprocessState *state) { int idx = state->cf_finally_used; return ((ControlFlowInFinallyContext*)state->cf_finally.array) + idx; } static int -push_cf_context(_PyASTProcessState *state, stmt_ty node, bool finally, bool funcdef, bool loop) +push_cf_context(_PyASTPreprocessState *state, stmt_ty node, bool finally, bool funcdef, bool loop) { if (_Py_CArray_EnsureCapacity(&state->cf_finally, state->cf_finally_used+1) < 0) { return 0; @@ -54,14 +54,14 @@ push_cf_context(_PyASTProcessState *state, stmt_ty node, bool finally, bool func } static void -pop_cf_context(_PyASTProcessState *state) +pop_cf_context(_PyASTPreprocessState *state) { assert(state->cf_finally_used > 0); state->cf_finally_used--; } static int -control_flow_in_finally_warning(const char *kw, stmt_ty n, _PyASTProcessState *state) +control_flow_in_finally_warning(const char *kw, stmt_ty n, _PyASTPreprocessState *state) { PyObject *msg = PyUnicode_FromFormat("'%s' in a 'finally' block", kw); if (msg == NULL) { @@ -75,7 +75,7 @@ control_flow_in_finally_warning(const char *kw, stmt_ty n, _PyASTProcessState *s } static int -before_return(_PyASTProcessState *state, stmt_ty node_) +before_return(_PyASTPreprocessState *state, stmt_ty node_) { if (state->cf_finally_used > 0) { ControlFlowInFinallyContext *ctx = get_cf_finally_top(state); @@ -89,7 +89,7 @@ before_return(_PyASTProcessState *state, stmt_ty node_) } static int -before_loop_exit(_PyASTProcessState *state, stmt_ty node_, const char *kw) +before_loop_exit(_PyASTPreprocessState *state, stmt_ty node_, const char *kw) { if (state->cf_finally_used > 0) { ControlFlowInFinallyContext *ctx = get_cf_finally_top(state); @@ -364,7 +364,7 @@ optimize_format(expr_ty node, PyObject *fmt, asdl_expr_seq *elts, PyArena *arena } static int -fold_binop(expr_ty node, PyArena *arena, _PyASTProcessState *state) +fold_binop(expr_ty node, PyArena *arena, _PyASTPreprocessState *state) { if (state->syntax_check_only) { return 1; @@ -388,18 +388,18 @@ fold_binop(expr_ty node, PyArena *arena, _PyASTProcessState *state) return 1; } -static int astfold_mod(mod_ty node_, PyArena *ctx_, _PyASTProcessState *state); -static int astfold_stmt(stmt_ty node_, PyArena *ctx_, _PyASTProcessState *state); -static int astfold_expr(expr_ty node_, PyArena *ctx_, _PyASTProcessState *state); -static int astfold_arguments(arguments_ty node_, PyArena *ctx_, _PyASTProcessState *state); -static int astfold_comprehension(comprehension_ty node_, PyArena *ctx_, _PyASTProcessState *state); -static int astfold_keyword(keyword_ty node_, PyArena *ctx_, _PyASTProcessState *state); -static int astfold_arg(arg_ty node_, PyArena *ctx_, _PyASTProcessState *state); -static int astfold_withitem(withitem_ty node_, PyArena *ctx_, _PyASTProcessState *state); -static int astfold_excepthandler(excepthandler_ty node_, PyArena *ctx_, _PyASTProcessState *state); -static int astfold_match_case(match_case_ty node_, PyArena *ctx_, _PyASTProcessState *state); -static int astfold_pattern(pattern_ty node_, PyArena *ctx_, _PyASTProcessState *state); -static int astfold_type_param(type_param_ty node_, PyArena *ctx_, _PyASTProcessState *state); +static int astfold_mod(mod_ty node_, PyArena *ctx_, _PyASTPreprocessState *state); +static int astfold_stmt(stmt_ty node_, PyArena *ctx_, _PyASTPreprocessState *state); +static int astfold_expr(expr_ty node_, PyArena *ctx_, _PyASTPreprocessState *state); +static int astfold_arguments(arguments_ty node_, PyArena *ctx_, _PyASTPreprocessState *state); +static int astfold_comprehension(comprehension_ty node_, PyArena *ctx_, _PyASTPreprocessState *state); +static int astfold_keyword(keyword_ty node_, PyArena *ctx_, _PyASTPreprocessState *state); +static int astfold_arg(arg_ty node_, PyArena *ctx_, _PyASTPreprocessState *state); +static int astfold_withitem(withitem_ty node_, PyArena *ctx_, _PyASTPreprocessState *state); +static int astfold_excepthandler(excepthandler_ty node_, PyArena *ctx_, _PyASTPreprocessState *state); +static int astfold_match_case(match_case_ty node_, PyArena *ctx_, _PyASTPreprocessState *state); +static int astfold_pattern(pattern_ty node_, PyArena *ctx_, _PyASTPreprocessState *state); +static int astfold_type_param(type_param_ty node_, PyArena *ctx_, _PyASTPreprocessState *state); #define CALL(FUNC, TYPE, ARG) \ if (!FUNC((ARG), ctx_, state)) \ @@ -435,7 +435,7 @@ stmt_seq_remove_item(asdl_stmt_seq *stmts, Py_ssize_t idx) } static int -astfold_body(asdl_stmt_seq *stmts, PyArena *ctx_, _PyASTProcessState *state) +astfold_body(asdl_stmt_seq *stmts, PyArena *ctx_, _PyASTPreprocessState *state) { int docstring = _PyAST_GetDocString(stmts) != NULL; if (docstring && (state->optimize >= 2)) { @@ -465,7 +465,7 @@ astfold_body(asdl_stmt_seq *stmts, PyArena *ctx_, _PyASTProcessState *state) } static int -astfold_mod(mod_ty node_, PyArena *ctx_, _PyASTProcessState *state) +astfold_mod(mod_ty node_, PyArena *ctx_, _PyASTPreprocessState *state) { switch (node_->kind) { case Module_kind: @@ -487,7 +487,7 @@ astfold_mod(mod_ty node_, PyArena *ctx_, _PyASTProcessState *state) } static int -astfold_expr(expr_ty node_, PyArena *ctx_, _PyASTProcessState *state) +astfold_expr(expr_ty node_, PyArena *ctx_, _PyASTPreprocessState *state) { ENTER_RECURSIVE(); switch (node_->kind) { @@ -612,14 +612,14 @@ astfold_expr(expr_ty node_, PyArena *ctx_, _PyASTProcessState *state) } static int -astfold_keyword(keyword_ty node_, PyArena *ctx_, _PyASTProcessState *state) +astfold_keyword(keyword_ty node_, PyArena *ctx_, _PyASTPreprocessState *state) { CALL(astfold_expr, expr_ty, node_->value); return 1; } static int -astfold_comprehension(comprehension_ty node_, PyArena *ctx_, _PyASTProcessState *state) +astfold_comprehension(comprehension_ty node_, PyArena *ctx_, _PyASTPreprocessState *state) { CALL(astfold_expr, expr_ty, node_->target); CALL(astfold_expr, expr_ty, node_->iter); @@ -628,7 +628,7 @@ astfold_comprehension(comprehension_ty node_, PyArena *ctx_, _PyASTProcessState } static int -astfold_arguments(arguments_ty node_, PyArena *ctx_, _PyASTProcessState *state) +astfold_arguments(arguments_ty node_, PyArena *ctx_, _PyASTPreprocessState *state) { CALL_SEQ(astfold_arg, arg, node_->posonlyargs); CALL_SEQ(astfold_arg, arg, node_->args); @@ -641,7 +641,7 @@ astfold_arguments(arguments_ty node_, PyArena *ctx_, _PyASTProcessState *state) } static int -astfold_arg(arg_ty node_, PyArena *ctx_, _PyASTProcessState *state) +astfold_arg(arg_ty node_, PyArena *ctx_, _PyASTPreprocessState *state) { if (!(state->ff_features & CO_FUTURE_ANNOTATIONS)) { CALL_OPT(astfold_expr, expr_ty, node_->annotation); @@ -650,7 +650,7 @@ astfold_arg(arg_ty node_, PyArena *ctx_, _PyASTProcessState *state) } static int -astfold_stmt(stmt_ty node_, PyArena *ctx_, _PyASTProcessState *state) +astfold_stmt(stmt_ty node_, PyArena *ctx_, _PyASTPreprocessState *state) { ENTER_RECURSIVE(); switch (node_->kind) { @@ -805,7 +805,7 @@ astfold_stmt(stmt_ty node_, PyArena *ctx_, _PyASTProcessState *state) } static int -astfold_excepthandler(excepthandler_ty node_, PyArena *ctx_, _PyASTProcessState *state) +astfold_excepthandler(excepthandler_ty node_, PyArena *ctx_, _PyASTPreprocessState *state) { switch (node_->kind) { case ExceptHandler_kind: @@ -819,7 +819,7 @@ astfold_excepthandler(excepthandler_ty node_, PyArena *ctx_, _PyASTProcessState } static int -astfold_withitem(withitem_ty node_, PyArena *ctx_, _PyASTProcessState *state) +astfold_withitem(withitem_ty node_, PyArena *ctx_, _PyASTPreprocessState *state) { CALL(astfold_expr, expr_ty, node_->context_expr); CALL_OPT(astfold_expr, expr_ty, node_->optional_vars); @@ -827,7 +827,7 @@ astfold_withitem(withitem_ty node_, PyArena *ctx_, _PyASTProcessState *state) } static int -fold_const_match_patterns(expr_ty node, PyArena *ctx_, _PyASTProcessState *state) +fold_const_match_patterns(expr_ty node, PyArena *ctx_, _PyASTPreprocessState *state) { if (state->syntax_check_only) { return 1; @@ -868,7 +868,7 @@ fold_const_match_patterns(expr_ty node, PyArena *ctx_, _PyASTProcessState *state } static int -astfold_pattern(pattern_ty node_, PyArena *ctx_, _PyASTProcessState *state) +astfold_pattern(pattern_ty node_, PyArena *ctx_, _PyASTPreprocessState *state) { // Currently, this is really only used to form complex/negative numeric // constants in MatchValue and MatchMapping nodes @@ -910,7 +910,7 @@ astfold_pattern(pattern_ty node_, PyArena *ctx_, _PyASTProcessState *state) } static int -astfold_match_case(match_case_ty node_, PyArena *ctx_, _PyASTProcessState *state) +astfold_match_case(match_case_ty node_, PyArena *ctx_, _PyASTPreprocessState *state) { CALL(astfold_pattern, expr_ty, node_->pattern); CALL_OPT(astfold_expr, expr_ty, node_->guard); @@ -919,7 +919,7 @@ astfold_match_case(match_case_ty node_, PyArena *ctx_, _PyASTProcessState *state } static int -astfold_type_param(type_param_ty node_, PyArena *ctx_, _PyASTProcessState *state) +astfold_type_param(type_param_ty node_, PyArena *ctx_, _PyASTPreprocessState *state) { switch (node_->kind) { case TypeVar_kind: @@ -944,8 +944,8 @@ int _PyAST_Preprocess(mod_ty mod, PyArena *arena, PyObject *filename, int optimize, int ff_features, int syntax_check_only) { - _PyASTProcessState state; - memset(&state, 0, sizeof(_PyASTProcessState)); + _PyASTPreprocessState state; + memset(&state, 0, sizeof(_PyASTPreprocessState)); state.filename = filename; state.optimize = optimize; state.ff_features = ff_features; From 8a59650a38d49c5fed185315806490e3052bc116 Mon Sep 17 00:00:00 2001 From: Yan Yanchii Date: Sun, 4 May 2025 09:42:13 +0200 Subject: [PATCH 10/10] update comment --- Python/ast_preprocess.c | 1 + 1 file changed, 1 insertion(+) diff --git a/Python/ast_preprocess.c b/Python/ast_preprocess.c index db8de4dd004546..bafd67ed790b20 100644 --- a/Python/ast_preprocess.c +++ b/Python/ast_preprocess.c @@ -1,3 +1,4 @@ +/* AST pre-processing */ #include "Python.h" #include "pycore_ast.h" // _PyAST_GetDocString() #include "pycore_c_array.h" // _Py_CArray_EnsureCapacity()