diff options
author | Yan Yanchii <yyanchiy@gmail.com> | 2025-05-04 20:07:35 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-05-04 21:07:35 +0300 |
commit | 0a1fedb70b94217055114357fa5f5be5ea62bdbe (patch) | |
tree | 944d91dc5c995c29584a52deebd0bd1fe141ceaf /Python | |
parent | 8eaaf1640232191319f83917ef72e7853af25681 (diff) | |
download | cpython-0a1fedb70b94217055114357fa5f5be5ea62bdbe.tar.gz cpython-0a1fedb70b94217055114357fa5f5be5ea62bdbe.zip |
gh-126835: Rename `ast_opt.c` to `ast_preprocess.c` and related stuff after moving const folding to the peephole optimizier (#131830)
Diffstat (limited to 'Python')
-rw-r--r-- | Python/ast_preprocess.c (renamed from Python/ast_opt.c) | 78 | ||||
-rw-r--r-- | Python/bltinmodule.c | 2 | ||||
-rw-r--r-- | Python/compile.c | 8 | ||||
-rw-r--r-- | Python/pythonrun.c | 2 |
4 files changed, 45 insertions, 45 deletions
diff --git a/Python/ast_opt.c b/Python/ast_preprocess.c index 4d5e5589ac0..bafd67ed790 100644 --- a/Python/ast_opt.c +++ b/Python/ast_preprocess.c @@ -1,4 +1,4 @@ -/* AST Optimizer */ +/* AST pre-processing */ #include "Python.h" #include "pycore_ast.h" // _PyAST_GetDocString() #include "pycore_c_array.h" // _Py_CArray_EnsureCapacity() @@ -22,7 +22,7 @@ typedef struct { _Py_c_array_t cf_finally; /* context for PEP 765 check */ int cf_finally_used; -} _PyASTOptimizeState; +} _PyASTPreprocessState; #define ENTER_RECURSIVE() \ if (Py_EnterRecursiveCall(" during compilation")) { \ @@ -32,14 +32,14 @@ if (Py_EnterRecursiveCall(" during compilation")) { \ #define LEAVE_RECURSIVE() Py_LeaveRecursiveCall(); static ControlFlowInFinallyContext* -get_cf_finally_top(_PyASTOptimizeState *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(_PyASTOptimizeState *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; @@ -55,14 +55,14 @@ push_cf_context(_PyASTOptimizeState *state, stmt_ty node, bool finally, bool fun } static void -pop_cf_context(_PyASTOptimizeState *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, _PyASTOptimizeState *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) { @@ -76,7 +76,7 @@ control_flow_in_finally_warning(const char *kw, stmt_ty n, _PyASTOptimizeState * } static int -before_return(_PyASTOptimizeState *state, stmt_ty node_) +before_return(_PyASTPreprocessState *state, stmt_ty node_) { if (state->cf_finally_used > 0) { ControlFlowInFinallyContext *ctx = get_cf_finally_top(state); @@ -90,7 +90,7 @@ before_return(_PyASTOptimizeState *state, stmt_ty node_) } static int -before_loop_exit(_PyASTOptimizeState *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); @@ -365,7 +365,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, _PyASTPreprocessState *state) { if (state->syntax_check_only) { return 1; @@ -389,18 +389,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_, _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)) \ @@ -436,7 +436,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_, _PyASTPreprocessState *state) { int docstring = _PyAST_GetDocString(stmts) != NULL; if (docstring && (state->optimize >= 2)) { @@ -466,7 +466,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_, _PyASTPreprocessState *state) { switch (node_->kind) { case Module_kind: @@ -488,7 +488,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_, _PyASTPreprocessState *state) { ENTER_RECURSIVE(); switch (node_->kind) { @@ -613,14 +613,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_, _PyASTPreprocessState *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_, _PyASTPreprocessState *state) { CALL(astfold_expr, expr_ty, node_->target); CALL(astfold_expr, expr_ty, node_->iter); @@ -629,7 +629,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_, _PyASTPreprocessState *state) { CALL_SEQ(astfold_arg, arg, node_->posonlyargs); CALL_SEQ(astfold_arg, arg, node_->args); @@ -642,7 +642,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_, _PyASTPreprocessState *state) { if (!(state->ff_features & CO_FUTURE_ANNOTATIONS)) { CALL_OPT(astfold_expr, expr_ty, node_->annotation); @@ -651,7 +651,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_, _PyASTPreprocessState *state) { ENTER_RECURSIVE(); switch (node_->kind) { @@ -806,7 +806,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_, _PyASTPreprocessState *state) { switch (node_->kind) { case ExceptHandler_kind: @@ -820,7 +820,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_, _PyASTPreprocessState *state) { CALL(astfold_expr, expr_ty, node_->context_expr); CALL_OPT(astfold_expr, expr_ty, node_->optional_vars); @@ -828,7 +828,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_, _PyASTPreprocessState *state) { if (state->syntax_check_only) { return 1; @@ -869,7 +869,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_, _PyASTPreprocessState *state) { // Currently, this is really only used to form complex/negative numeric // constants in MatchValue and MatchMapping nodes @@ -911,7 +911,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_, _PyASTPreprocessState *state) { CALL(astfold_pattern, expr_ty, node_->pattern); CALL_OPT(astfold_expr, expr_ty, node_->guard); @@ -920,7 +920,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_, _PyASTPreprocessState *state) { switch (node_->kind) { case TypeVar_kind: @@ -942,11 +942,11 @@ astfold_type_param(type_param_ty node_, PyArena *ctx_, _PyASTOptimizeState *stat #undef CALL_SEQ int -_PyAST_Optimize(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) { - _PyASTOptimizeState state; - memset(&state, 0, sizeof(_PyASTOptimizeState)); + _PyASTPreprocessState state; + memset(&state, 0, sizeof(_PyASTPreprocessState)); state.filename = filename; state.optimize = optimize; state.ff_features = ff_features; diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index 3221d5acf96..3d0295ee388 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_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 15ef7214d44..c04391e682f 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_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_AstOptimize(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_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_Preprocess(mod, arena, filename, optimize, flags, no_const_folding)) { return -1; } return 0; diff --git a/Python/pythonrun.c b/Python/pythonrun.c index 23af8b6f6be..4ee287af72f 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_AstPreprocess(mod, filename, flags, optimize, arena, syntax_check_only) < 0) { _PyArena_Free(arena); return NULL; } |