On Sun, Aug 12, 2012 at 4:30 AM, Victor Stinner
<victor.stin...@gmail.com> wrote:
> I started to implement an AST optimizer in Python. It's easy to create
> a new AST tree, so I'm surprised that I didn't find any existing
> project.

Very nice idea!

> Other idea to improve this optimizer:
>  - move invariant out of loops. Example: "x=[]; for i in range(10):
> x.append(i)" => "x=[]; x_append=x.append; for i in range(10):
> x_append(i)". Require to infer the type of variables.

But this is risky. It's theoretically possible for x.append to replace
itself. Sure it may not be a normal or common thing to do, but it's
possible. And yet it could be pretty advantageous for most programs.

Perhaps the best way is to hide potentially-risky optimizations behind
command-line options? The default mode could be to do every change
that's guaranteed not to affect execution, and everything else is an
extra (like French, music, and washing).

ChrisA
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to