[Python-Dev] Suggest reverting today's checkin (recursive constant folding in the peephole optimizer)

Eugene Toder eltoder at gmail.com
Sat Mar 12 05:11:17 CET 2011


Experience shows that optimizations are always error prone, no matter
what framework or internal representation you use. I don't think we
should assume that simply rewriting all optimizations to work on AST
will make them bug free once and for all. On the contrary, I think
such a rewrite will introduce some bugs of it's own.

The remedy against this is well known. Instead of being afraid to
touch the code we should add more tests and verifiers. If had written
tests are not enough, test generator that produces python programs
with different structures can be written. Such generators are used by
many compiler writers. For verifiers, a function that checks that
bytecode is sane (doesn't reference invalid names or consts, doesn't
jump between instructions, all joins have same stack depth? etc) that
runs after optimizer in debug builds can save a lot of time.

Eugene


More information about the Python-Dev mailing list