diff --git a/pep-0511.txt b/pep-0511.txt index 762cbd8c2..b9e58af1b 100644 --- a/pep-0511.txt +++ b/pep-0511.txt @@ -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 `_ -Using guards (see the PEP 510), it is possible to implement a much wider choice -of optimizations. Examples: +Using guards (see the `PEP 510 +`_), 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 `_ * Call pure builtins: replace ``len("abc")`` with ``3`` * Copy used builtin symbols to constants +* See also `optimizations implemented in fatoptimizer + `_, + a static optimizer for Python 3.6. -See also `optimizations implemented in fatoptimizer -`_, a -static optimizer for Python 3.6. +The following issues can be implemented with an AST optimizer: + +* `Issue #1346238 + `_: A constant folding + optimization pass for the AST +* `Issue #2181 `_: + optimize out local variables at end of function +* `Issue #2499 `_: + Fold unary + and not on constants +* `Issue #4264 `_: + Patch: optimize code to use LIST_APPEND instead of calling list.append +* `Issue #7682 `_: + Optimisation of if with constant expression +* `Issue #10399 `_: AST + Optimization: inlining of function calls +* `Issue #11549 `_: + Build-out an AST optimizer, moving some functionality out of the + peephole optimizer +* `Issue #17068 `_: + peephole optimization for constant strings +* `Issue #17430 `_: + missed peephole optimization Usage 2: Preprocessor