Re: [Python-Dev] AST optimizer implemented in Python

2012-08-11 Thread Stefan Behnel
"Martin v. Löwis", 11.08.2012 23:27: >>> +1 We should add some form of setastoptimizer API in 3.4. Please start a >>> PEP for this. It would be nice to include the ability to properly cache >>> the >>> ast optimizer output so that it does not have to run every time (in pyc >>> files or similar,

Re: [Python-Dev] AST optimizer implemented in Python

2012-08-11 Thread Stefan Behnel
Victor Stinner, 11.08.2012 20:30: > 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. > > https://bitbucket.org/haypo/misc/src/tip/python/ast_optimizer.py Since you're about to do pretty much the sa

Re: [Python-Dev] AST optimizer implemented in Python

2012-08-11 Thread Stefan Behnel
Stefan Behnel, 12.08.2012 06:42: > Chris Angelico, 12.08.2012 01:22: >>> 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 var

Re: [Python-Dev] AST optimizer implemented in Python

2012-08-11 Thread Stefan Behnel
Chris Angelico, 12.08.2012 01:22: >> 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 th

Re: [Python-Dev] AST optimizer implemented in Python

2012-08-11 Thread Chris Angelico
On Sun, Aug 12, 2012 at 11:17 AM, Victor Stinner wrote: > The idea would be to allow the developer to specify explicitly what he > wants to optimize. I'm using a configuration class with a list of what > can be optimized (ex: len(int)), but it can be changed to something > different later. > > It

Re: [Python-Dev] AST optimizer implemented in Python

2012-08-11 Thread Victor Stinner
>> 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 t

Re: [Python-Dev] AST optimizer implemented in Python

2012-08-11 Thread Brett Cannon
On Sat, Aug 11, 2012 at 8:16 PM, Eric Snow wrote: > On Sat, Aug 11, 2012 at 6:03 PM, Brett Cannon wrote: > > It would also be very easy to expand importlib.abc.SourceLoader to add a > > method which is called with source and returns the bytecode to be written > > out > > Yes, please. Not having

Re: [Python-Dev] AST optimizer implemented in Python

2012-08-11 Thread Eric Snow
On Sat, Aug 11, 2012 at 6:03 PM, Brett Cannon wrote: > It would also be very easy to expand importlib.abc.SourceLoader to add a > method which is called with source and returns the bytecode to be written > out Yes, please. Not having to hack around this would be nice. > which people could overr

Re: [Python-Dev] AST optimizer implemented in Python

2012-08-11 Thread Brett Cannon
On Sat, Aug 11, 2012 at 2:30 PM, Victor Stinner wrote: > Hi, > > 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. > > https://bitbucket.org/haypo/misc/src/tip/python/ast_optimizer.py > > To test its

Re: [Python-Dev] AST optimizer implemented in Python

2012-08-11 Thread Chris Angelico
On Sun, Aug 12, 2012 at 4:30 AM, Victor Stinner 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.

Re: [Python-Dev] AST optimizer implemented in Python

2012-08-11 Thread Eric Snow
On Sat, Aug 11, 2012 at 3:27 PM, "Martin v. Löwis" wrote: > I think you misunderstood. What gps is concerned about (IIUC) that some > people add ast optimizers in some run of Python, but other AST optimizers in > a different run. Then, if you use a Python byte code > file, you should be able to fi

Re: [Python-Dev] AST optimizer implemented in Python

2012-08-11 Thread Ned Batchelder
On 8/11/2012 2:30 PM, Victor Stinner wrote: Hi, 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. https://bitbucket.org/haypo/misc/src/tip/python/ast_optimizer.py To test its peephole optimizations (

Re: [Python-Dev] AST optimizer implemented in Python

2012-08-11 Thread Martin v. Löwis
+1 We should add some form of setastoptimizer API in 3.4. Please start a PEP for this. It would be nice to include the ability to properly cache the ast optimizer output so that it does not have to run every time (in pyc files or similar, etc) but can verify that it is the specific ast optimi

Re: [Python-Dev] AST optimizer implemented in Python

2012-08-11 Thread Nam Nguyen
On Sat, Aug 11, 2012 at 11:47 AM, Gregory P. Smith wrote: > > On Sat, Aug 11, 2012 at 11:30 AM, Victor Stinner > wrote: >> >> Hi, >> >> 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. >> >> http

Re: [Python-Dev] AST optimizer implemented in Python

2012-08-11 Thread Gregory P. Smith
On Sat, Aug 11, 2012 at 11:30 AM, Victor Stinner wrote: > Hi, > > 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. > > https://bitbucket.org/haypo/misc/src/tip/python/ast_optimizer.py Neat! > >

[Python-Dev] AST optimizer implemented in Python

2012-08-11 Thread Victor Stinner
Hi, 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. https://bitbucket.org/haypo/misc/src/tip/python/ast_optimizer.py To test its peephole optimizations (by checking manually its final bytecode), I wr

Re: [Python-Dev] [Python-checkins] cpython: Issue #15502: Finish bringing importlib.abc in line with the current

2012-08-11 Thread Chris Jerdonek
On Sat, Aug 11, 2012 at 9:40 AM, Georg Brandl wrote: > On 08/11/2012 04:49 PM, R. David Murray wrote: >> On Fri, 10 Aug 2012 16:56:43 -0700, Chris Jerdonek >> wrote: >>> On Fri, Aug 10, 2012 at 9:21 AM, brett.cannon >>> wrote: >>> > http://hg.python.org/cpython/rev/0a75ce232f56 >>> > changeset:

Re: [Python-Dev] [Python-checkins] cpython: Issue #15502: Finish bringing importlib.abc in line with the current

2012-08-11 Thread Georg Brandl
On 08/11/2012 04:49 PM, R. David Murray wrote: > On Fri, 10 Aug 2012 16:56:43 -0700, Chris Jerdonek > wrote: >> On Fri, Aug 10, 2012 at 9:21 AM, brett.cannon >> wrote: >> > http://hg.python.org/cpython/rev/0a75ce232f56 >> > changeset: 78485:0a75ce232f56 >> > user:Brett Cannon >> > dat

Re: [Python-Dev] [Python-checkins] cpython: Issue #15502: Finish bringing importlib.abc in line with the current

2012-08-11 Thread R. David Murray
On Fri, 10 Aug 2012 16:56:43 -0700, Chris Jerdonek wrote: > On Fri, Aug 10, 2012 at 9:21 AM, brett.cannon > wrote: > > http://hg.python.org/cpython/rev/0a75ce232f56 > > changeset: 78485:0a75ce232f56 > > user:Brett Cannon > > date:Fri Aug 10 12:21:12 2012 -0400 > > summary: > >