PEP 511: add list of AST optimizer issues

This commit is contained in:
Victor Stinner 2016-01-15 02:14:44 +01:00
parent ac6203d00f
commit 307af6e57e
1 changed files with 30 additions and 5 deletions

View File

@ -34,6 +34,8 @@ Python 3.4 added a ``compile_source()`` method to
``importlib.abc.SourceLoader``. But code transformation is wider than just
importing modules, see described use cases below.
Writing an optimizer or a preprocessor is out of the scope of this PEP.
Usage 1: AST optimizer
----------------------
@ -58,18 +60,41 @@ Example of optimizations which can be implemented with an AST optimizer:
* `Dead code elimination
<https://en.wikipedia.org/wiki/Dead_code_elimination>`_
Using guards (see the PEP 510), it is possible to implement a much wider choice
of optimizations. Examples:
Using guards (see the `PEP 510
<https://www.python.org/dev/peps/pep-0510/>`_), it is possible to
implement a much wider choice of optimizations. Examples:
* Simplify iterable: replace ``range(3)`` with ``(0, 1, 2)`` when used
as iterable
* `Loop unrolling <https://en.wikipedia.org/wiki/Loop_unrolling>`_
* Call pure builtins: replace ``len("abc")`` with ``3``
* Copy used builtin symbols to constants
* See also `optimizations implemented in fatoptimizer
<https://fatoptimizer.readthedocs.org/en/latest/optimizations.html>`_,
a static optimizer for Python 3.6.
See also `optimizations implemented in fatoptimizer
<https://fatoptimizer.readthedocs.org/en/latest/optimizations.html>`_, a
static optimizer for Python 3.6.
The following issues can be implemented with an AST optimizer:
* `Issue #1346238
<https://bugs.python.org/issue1346238>`_: A constant folding
optimization pass for the AST
* `Issue #2181 <http://bugs.python.org/issue2181>`_:
optimize out local variables at end of function
* `Issue #2499 <http://bugs.python.org/issue2499>`_:
Fold unary + and not on constants
* `Issue #4264 <http://bugs.python.org/issue4264>`_:
Patch: optimize code to use LIST_APPEND instead of calling list.append
* `Issue #7682 <http://bugs.python.org/issue7682>`_:
Optimisation of if with constant expression
* `Issue #10399 <https://bugs.python.org/issue10399>`_: AST
Optimization: inlining of function calls
* `Issue #11549 <http://bugs.python.org/issue11549>`_:
Build-out an AST optimizer, moving some functionality out of the
peephole optimizer
* `Issue #17068 <http://bugs.python.org/issue17068>`_:
peephole optimization for constant strings
* `Issue #17430 <http://bugs.python.org/issue17430>`_:
missed peephole optimization
Usage 2: Preprocessor