Skip to content

Commit 7ea143a

Browse files
authored
bpo-29469: Move constant folding to AST optimizer (GH-2858)
1 parent b5fd9ad commit 7ea143a

File tree

11 files changed

+4431
-3966
lines changed

11 files changed

+4431
-3966
lines changed

Doc/whatsnew/3.7.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,9 @@ Optimizations
581581
and :meth:`selectors.DevpollSelector.modify` may be around 10% faster under
582582
heavy loads. (Contributed by Giampaolo Rodola' in :issue:`30014`)
583583

584+
* Constant folding is moved from peephole optimizer to new AST optimizer.
585+
(Contributed by Eugene Toder and INADA Naoki in :issue:`29469`)
586+
584587
Build and C API Changes
585588
=======================
586589

Include/compile.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ PyAPI_FUNC(PyObject*) _Py_Mangle(PyObject *p, PyObject *name);
7575
#define PY_INVALID_STACK_EFFECT INT_MAX
7676
PyAPI_FUNC(int) PyCompile_OpcodeStackEffect(int opcode, int oparg);
7777

78+
PyAPI_FUNC(int) _PyAST_Optimize(struct _mod *, PyArena *arena);
79+
7880
#ifdef __cplusplus
7981
}
8082
#endif

Makefile.pre.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,7 @@ PYTHON_OBJS= \
319319
Python/Python-ast.o \
320320
Python/asdl.o \
321321
Python/ast.o \
322+
Python/ast_opt.o \
322323
Python/bltinmodule.o \
323324
Python/ceval.o \
324325
Python/compile.o \
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Move constant folding from bytecode layer to AST layer.
2+
Original patch by Eugene Toder.

PCbuild/pythoncore.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@
356356
<ClCompile Include="..\Python\_warnings.c" />
357357
<ClCompile Include="..\Python\asdl.c" />
358358
<ClCompile Include="..\Python\ast.c" />
359+
<ClCompile Include="..\Python\ast_opt.c" />
359360
<ClCompile Include="..\Python\bltinmodule.c" />
360361
<ClCompile Include="..\Python\bootstrap_hash.c" />
361362
<ClCompile Include="..\Python\ceval.c" />

PCbuild/pythoncore.vcxproj.filters

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -824,6 +824,9 @@
824824
<ClCompile Include="..\Python\ast.c">
825825
<Filter>Python</Filter>
826826
</ClCompile>
827+
<ClCompile Include="..\Python\ast_opt.c">
828+
<Filter>Python</Filter>
829+
</ClCompile>
827830
<ClCompile Include="..\Python\bltinmodule.c">
828831
<Filter>Python</Filter>
829832
</ClCompile>

0 commit comments

Comments
 (0)