From 81632c62d200e2a019da3e092c3b2703e878c2e8 Mon Sep 17 00:00:00 2001
From: Batuhan Taskaya
Date: Sun, 6 Jun 2021 02:21:14 +0300
Subject: [PATCH] [TEMP] bpo-11105: use PY_LOCAL()s for AST converter functions
---
Parser/asdl_c.py | 9 +++++++--
Python/Python-ast.c | 41 +++++++++++++++++++++++------------------
2 files changed, 30 insertions(+), 20 deletions(-)
diff --git a/Parser/asdl_c.py b/Parser/asdl_c.py
index 4e5c5c8f7f7093..f2eef06e178a9d 100755
--- a/Parser/asdl_c.py
+++ b/Parser/asdl_c.py
@@ -432,7 +432,7 @@ def recursive_call(self, node, level):
def funcHeader(self, name):
ctype = get_c_type(name)
- self.emit("int", 0)
+ self.emit("Py_LOCAL_INLINE(int)", 0)
self.emit("obj2ast_%s(struct ast_state *state, PyObject* obj, %s* out, PyArena* arena)" % (name, ctype), 0)
self.emit("{", 0)
self.emit("int isinstance;", 1)
@@ -514,7 +514,7 @@ def visitSum(self, sum, name):
def visitProduct(self, prod, name):
ctype = get_c_type(name)
- self.emit("int", 0)
+ self.emit("Py_LOCAL_INLINE(int)", 0)
self.emit("obj2ast_%s(struct ast_state *state, PyObject* obj, %s* out, PyArena* arena)" % (name, ctype), 0)
self.emit("{", 0)
self.emit("PyObject* tmp = NULL;", 1)
@@ -1434,6 +1434,11 @@ def generate_module_def(mod, f, internal_h):
generate_ast_state(module_state, internal_h)
print(textwrap.dedent("""
+ /* enable more aggressive intra-module optimizations, where available
+ to reduce the stack usage for windows. */
+
+ #define PY_LOCAL_AGGRESSIVE
+
#include "Python.h"
#include "pycore_ast.h"
#include "pycore_ast_state.h" // struct ast_state
diff --git a/Python/Python-ast.c b/Python/Python-ast.c
index ce6e6a93ea70f0..3711484e8f4c90 100644
--- a/Python/Python-ast.c
+++ b/Python/Python-ast.c
@@ -1,5 +1,10 @@
// File automatically generated by Parser/asdl_c.py.
+/* enable more aggressive intra-module optimizations, where available
+ to reduce the stack usage for windows. */
+
+#define PY_LOCAL_AGGRESSIVE
+
#include "Python.h"
#include "pycore_ast.h"
#include "pycore_ast_state.h" // struct ast_state
@@ -5330,7 +5335,7 @@ ast2obj_type_ignore(struct ast_state *state, void* _o)
}
-int
+Py_LOCAL_INLINE(int)
obj2ast_mod(struct ast_state *state, PyObject* obj, mod_ty* out, PyArena* arena)
{
int isinstance;
@@ -5581,7 +5586,7 @@ obj2ast_mod(struct ast_state *state, PyObject* obj, mod_ty* out, PyArena* arena)
return 1;
}
-int
+Py_LOCAL_INLINE(int)
obj2ast_stmt(struct ast_state *state, PyObject* obj, stmt_ty* out, PyArena*
arena)
{
@@ -7834,7 +7839,7 @@ obj2ast_stmt(struct ast_state *state, PyObject* obj, stmt_ty* out, PyArena*
return 1;
}
-int
+Py_LOCAL_INLINE(int)
obj2ast_expr(struct ast_state *state, PyObject* obj, expr_ty* out, PyArena*
arena)
{
@@ -9595,7 +9600,7 @@ obj2ast_expr(struct ast_state *state, PyObject* obj, expr_ty* out, PyArena*
return 1;
}
-int
+Py_LOCAL_INLINE(int)
obj2ast_expr_context(struct ast_state *state, PyObject* obj, expr_context_ty*
out, PyArena* arena)
{
@@ -9630,7 +9635,7 @@ obj2ast_expr_context(struct ast_state *state, PyObject* obj, expr_context_ty*
return 1;
}
-int
+Py_LOCAL_INLINE(int)
obj2ast_boolop(struct ast_state *state, PyObject* obj, boolop_ty* out, PyArena*
arena)
{
@@ -9657,7 +9662,7 @@ obj2ast_boolop(struct ast_state *state, PyObject* obj, boolop_ty* out, PyArena*
return 1;
}
-int
+Py_LOCAL_INLINE(int)
obj2ast_operator(struct ast_state *state, PyObject* obj, operator_ty* out,
PyArena* arena)
{
@@ -9772,7 +9777,7 @@ obj2ast_operator(struct ast_state *state, PyObject* obj, operator_ty* out,
return 1;
}
-int
+Py_LOCAL_INLINE(int)
obj2ast_unaryop(struct ast_state *state, PyObject* obj, unaryop_ty* out,
PyArena* arena)
{
@@ -9815,7 +9820,7 @@ obj2ast_unaryop(struct ast_state *state, PyObject* obj, unaryop_ty* out,
return 1;
}
-int
+Py_LOCAL_INLINE(int)
obj2ast_cmpop(struct ast_state *state, PyObject* obj, cmpop_ty* out, PyArena*
arena)
{
@@ -9906,7 +9911,7 @@ obj2ast_cmpop(struct ast_state *state, PyObject* obj, cmpop_ty* out, PyArena*
return 1;
}
-int
+Py_LOCAL_INLINE(int)
obj2ast_comprehension(struct ast_state *state, PyObject* obj, comprehension_ty*
out, PyArena* arena)
{
@@ -10011,7 +10016,7 @@ obj2ast_comprehension(struct ast_state *state, PyObject* obj, comprehension_ty*
return 1;
}
-int
+Py_LOCAL_INLINE(int)
obj2ast_excepthandler(struct ast_state *state, PyObject* obj, excepthandler_ty*
out, PyArena* arena)
{
@@ -10189,7 +10194,7 @@ obj2ast_excepthandler(struct ast_state *state, PyObject* obj, excepthandler_ty*
return 1;
}
-int
+Py_LOCAL_INLINE(int)
obj2ast_arguments(struct ast_state *state, PyObject* obj, arguments_ty* out,
PyArena* arena)
{
@@ -10429,7 +10434,7 @@ obj2ast_arguments(struct ast_state *state, PyObject* obj, arguments_ty* out,
return 1;
}
-int
+Py_LOCAL_INLINE(int)
obj2ast_arg(struct ast_state *state, PyObject* obj, arg_ty* out, PyArena* arena)
{
PyObject* tmp = NULL;
@@ -10568,7 +10573,7 @@ obj2ast_arg(struct ast_state *state, PyObject* obj, arg_ty* out, PyArena* arena)
return 1;
}
-int
+Py_LOCAL_INLINE(int)
obj2ast_keyword(struct ast_state *state, PyObject* obj, keyword_ty* out,
PyArena* arena)
{
@@ -10690,7 +10695,7 @@ obj2ast_keyword(struct ast_state *state, PyObject* obj, keyword_ty* out,
return 1;
}
-int
+Py_LOCAL_INLINE(int)
obj2ast_alias(struct ast_state *state, PyObject* obj, alias_ty* out, PyArena*
arena)
{
@@ -10812,7 +10817,7 @@ obj2ast_alias(struct ast_state *state, PyObject* obj, alias_ty* out, PyArena*
return 1;
}
-int
+Py_LOCAL_INLINE(int)
obj2ast_withitem(struct ast_state *state, PyObject* obj, withitem_ty* out,
PyArena* arena)
{
@@ -10861,7 +10866,7 @@ obj2ast_withitem(struct ast_state *state, PyObject* obj, withitem_ty* out,
return 1;
}
-int
+Py_LOCAL_INLINE(int)
obj2ast_match_case(struct ast_state *state, PyObject* obj, match_case_ty* out,
PyArena* arena)
{
@@ -10948,7 +10953,7 @@ obj2ast_match_case(struct ast_state *state, PyObject* obj, match_case_ty* out,
return 1;
}
-int
+Py_LOCAL_INLINE(int)
obj2ast_pattern(struct ast_state *state, PyObject* obj, pattern_ty* out,
PyArena* arena)
{
@@ -11529,7 +11534,7 @@ obj2ast_pattern(struct ast_state *state, PyObject* obj, pattern_ty* out,
return 1;
}
-int
+Py_LOCAL_INLINE(int)
obj2ast_type_ignore(struct ast_state *state, PyObject* obj, type_ignore_ty*
out, PyArena* arena)
{