Open
Description
Feature or enhancement
Proposal:
For additional context see #126830 (comment).
Flow graph optimizer has more information and can do better job.
The problem is that we need to convert from UNARY_OP(-, CONST(1))
to CONST(-1)
, still before the code generation phase, because this leads to a few problems, one of which is shown below.
x = 1
match x:
case -0:
y = 0
eclips4@nixos ~/p/p/cpython (remove-ast-optimizer)> ./python example.py
File "/home/eclips4/programming/programming-languages/cpython/example.py", line 4
case -0:
^^
SyntaxError: patterns may only match literals and attribute lookups
cc @markshannon
Has this already been discussed elsewhere?
No response given
Links to previous discussion of this feature:
No response
Linked PRs
- gh-126835: Disable tuple folding in the AST optimizer #128802
- gh-126835: Move optimization of constant sequence creation from codegen to CFG #129426
- gh-126835: Move constant unaryop & binop folding to CFG #129550
- gh-126835: Move constant subscript folding to CFG #129568
- gh-126835: Fix
optimize_if_const_subscr
refleaks #129634 - gh-126835: make CFG optimizer skip over NOP's when looking for const sequence construction #129703
- gh-126835: Fold unary & binary complex constant expressions during code generation. #129963
- gh-126835: Remove unused docstring const #130016
- gh-126835: Move const list & set folding in for_iter & contains from ast_opt.c to flowgraph.c #130032
- gh-126835: Set location for noped out instructions after constant folding in CFG. #130109
- gh-126835: Move constant tuple folding to CFG #130769
- gh-126835: Avoid creating unnecessary tuple when looking for constant sequence during constant folding #131054
- gh-126835: Refine constant folding tests in
test_peepholer.py::TestTranforms
#131826 - gh-126835: Rename AST optimization related stuff after moving const folding to the peephole optimizier #131830