[pypy-commit] pypy default: Simplify the graph before turning it into a generator, to get rid

arigo noreply at buildbot.pypy.org
Mon Dec 26 15:37:55 CET 2011


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r50873:d373deb39b4d
Date: 2011-12-26 15:22 +0100
http://bitbucket.org/pypy/pypy/changeset/d373deb39b4d/

Log:	Simplify the graph before turning it into a generator, to get rid of
	the extra variables passed around.

diff --git a/pypy/translator/generator.py b/pypy/translator/generator.py
--- a/pypy/translator/generator.py
+++ b/pypy/translator/generator.py
@@ -2,7 +2,7 @@
 from pypy.objspace.flow.model import Variable, Constant, FunctionGraph
 from pypy.translator.unsimplify import insert_empty_startblock
 from pypy.translator.unsimplify import split_block
-from pypy.translator.simplify import eliminate_empty_blocks
+from pypy.translator.simplify import eliminate_empty_blocks, simplify_graph
 from pypy.tool.sourcetools import func_with_new_name
 from pypy.interpreter.argument import Signature
 
@@ -64,6 +64,7 @@
     def next(self):
         entry = self.current
         self.current = None
+        assert entry is not None      # else, recursive generator invocation
         (next_entry, return_value) = func(entry)
         self.current = next_entry
         return return_value
@@ -91,6 +92,10 @@
     block.inputargs = [v_entry1]
 
 def tweak_generator_body_graph(Entry, graph):
+    # First, always run simplify_graph in order to reduce the number of
+    # variables passed around
+    simplify_graph(graph)
+    #
     assert graph.startblock.operations[0].opname == 'generator_mark'
     graph.startblock.operations.pop(0)
     #


More information about the pypy-commit mailing list