summaryrefslogtreecommitdiffstats
path: root/Python/ast_opt.c
diff options
context:
space:
mode:
authorIrit Katriel <1055913+iritkatriel@users.noreply.github.com>2023-05-31 19:21:46 (GMT)
committerGitHub <noreply@github.com>2023-05-31 19:21:46 (GMT)
commitf990bb8b2d8ee900fe4b0775399f6ef4ca61bb3f (patch)
treeee881a03ea85e09057749e8ef82838b657dbaa02 /Python/ast_opt.c
parentdd29ae26f89ba7db596127b6eba83bb3a45c167b (diff)
downloadcpython-f990bb8b2d8ee900fe4b0775399f6ef4ca61bb3f.zip
cpython-f990bb8b2d8ee900fe4b0775399f6ef4ca61bb3f.tar.gz
cpython-f990bb8b2d8ee900fe4b0775399f6ef4ca61bb3f.tar.bz2
gh-105148: make _PyASTOptimizeState internal to ast_opt.c (#105149)
Diffstat (limited to 'Python/ast_opt.c')
-rw-r--r--Python/ast_opt.c26
1 files changed, 19 insertions, 7 deletions
diff --git a/Python/ast_opt.c b/Python/ast_opt.c
index 274bd13..276e910 100644
--- a/Python/ast_opt.c
+++ b/Python/ast_opt.c
@@ -1,12 +1,20 @@
/* AST Optimizer */
#include "Python.h"
#include "pycore_ast.h" // _PyAST_GetDocString()
-#include "pycore_compile.h" // _PyASTOptimizeState
#include "pycore_long.h" // _PyLong
#include "pycore_pystate.h" // _PyThreadState_GET()
#include "pycore_format.h" // F_LJUST
+typedef struct {
+ int optimize;
+ int ff_features;
+
+ int recursion_depth; /* current recursion depth */
+ int recursion_limit; /* recursion limit */
+} _PyASTOptimizeState;
+
+
static int
make_const(expr_ty node, PyObject *val, PyArena *arena)
{
@@ -1106,11 +1114,15 @@ astfold_type_param(type_param_ty node_, PyArena *ctx_, _PyASTOptimizeState *stat
#define COMPILER_STACK_FRAME_SCALE 3
int
-_PyAST_Optimize(mod_ty mod, PyArena *arena, _PyASTOptimizeState *state)
+_PyAST_Optimize(mod_ty mod, PyArena *arena, int optimize, int ff_features)
{
PyThreadState *tstate;
int starting_recursion_depth;
+ _PyASTOptimizeState state;
+ state.optimize = optimize;
+ state.ff_features = ff_features;
+
/* Setup recursion depth check counters */
tstate = _PyThreadState_GET();
if (!tstate) {
@@ -1119,17 +1131,17 @@ _PyAST_Optimize(mod_ty mod, PyArena *arena, _PyASTOptimizeState *state)
/* Be careful here to prevent overflow. */
int recursion_depth = C_RECURSION_LIMIT - tstate->c_recursion_remaining;
starting_recursion_depth = recursion_depth * COMPILER_STACK_FRAME_SCALE;
- state->recursion_depth = starting_recursion_depth;
- state->recursion_limit = C_RECURSION_LIMIT * COMPILER_STACK_FRAME_SCALE;
+ state.recursion_depth = starting_recursion_depth;
+ state.recursion_limit = C_RECURSION_LIMIT * COMPILER_STACK_FRAME_SCALE;
- int ret = astfold_mod(mod, arena, state);
+ int ret = astfold_mod(mod, arena, &state);
assert(ret || PyErr_Occurred());
/* Check that the recursion depth counting balanced correctly */
- if (ret && state->recursion_depth != starting_recursion_depth) {
+ if (ret && state.recursion_depth != starting_recursion_depth) {
PyErr_Format(PyExc_SystemError,
"AST optimizer recursion depth mismatch (before=%d, after=%d)",
- starting_recursion_depth, state->recursion_depth);
+ starting_recursion_depth, state.recursion_depth);
return 0;
}