[pypy-commit] pypy translation-cleanup: Don't build the flow graph when bootstrapping generator graphs

rlamy noreply at buildbot.pypy.org
Tue Oct 2 21:55:39 CEST 2012


Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: translation-cleanup
Changeset: r57750:eab196c1b02f
Date: 2012-10-02 20:55 +0100
http://bitbucket.org/pypy/pypy/changeset/eab196c1b02f/

Log:	Don't build the flow graph when bootstrapping generator graphs

	+ Split tweak_generator_graph()

diff --git a/pypy/objspace/flow/generator.py b/pypy/objspace/flow/generator.py
--- a/pypy/objspace/flow/generator.py
+++ b/pypy/objspace/flow/generator.py
@@ -11,21 +11,21 @@
     _immutable_ = True
     _attrs_ = ()
 
+def bootstrap_generator(graph):
+    # This is the first copy of the graph.  We replace it with
+    # a small bootstrap graph.
+    GeneratorIterator = make_generatoriterator_class(graph)
+    replace_graph_with_bootstrap(GeneratorIterator, graph)
+    # We attach a 'next' method to the GeneratorIterator class
+    # that will invoke the real function, based on a second
+    # copy of the graph.
+    attach_next_method(GeneratorIterator, graph)
+    return graph
 
 def tweak_generator_graph(graph):
-    if not hasattr(graph.func, '_generator_next_method_of_'):
-        # This is the first copy of the graph.  We replace it with
-        # a small bootstrap graph.
-        GeneratorIterator = make_generatoriterator_class(graph)
-        replace_graph_with_bootstrap(GeneratorIterator, graph)
-        # We attach a 'next' method to the GeneratorIterator class
-        # that will invoke the real function, based on a second
-        # copy of the graph.
-        attach_next_method(GeneratorIterator, graph)
-    else:
-        # This is the second copy of the graph.  Tweak it.
-        GeneratorIterator = graph.func._generator_next_method_of_
-        tweak_generator_body_graph(GeneratorIterator.Entry, graph)
+    # This is the second copy of the graph.  Tweak it.
+    GeneratorIterator = graph.func._generator_next_method_of_
+    tweak_generator_body_graph(GeneratorIterator.Entry, graph)
 
 
 def make_generatoriterator_class(graph):
diff --git a/pypy/objspace/flow/objspace.py b/pypy/objspace/flow/objspace.py
--- a/pypy/objspace/flow/objspace.py
+++ b/pypy/objspace/flow/objspace.py
@@ -10,7 +10,8 @@
 from pypy.objspace.flow import operation
 from pypy.objspace.flow.flowcontext import (FlowSpaceFrame, fixeggblocks,
     FSException, FlowingError)
-from pypy.objspace.flow.generator import tweak_generator_graph
+from pypy.objspace.flow.generator import (tweak_generator_graph,
+        bootstrap_generator)
 from pypy.objspace.flow.pygraph import PyGraph
 from pypy.objspace.flow.specialcase import SPECIAL_CASES
 from pypy.rlib.unroll import unrolling_iterable, _unroller
@@ -239,6 +240,14 @@
         if func.func_doc and func.func_doc.lstrip().startswith('NOT_RPYTHON'):
             raise Exception, "%r is tagged as NOT_RPYTHON" % (func,)
         code = HostCode._from_code(self, func.func_code)
+        if (code.is_generator and
+                not hasattr(func, '_generator_next_method_of_')):
+            graph = PyGraph(func, code)
+            block = graph.startblock
+            for name, w_value in zip(code.co_varnames, block.framestate.mergeable):
+                if isinstance(w_value, Variable):
+                    w_value.rename(name)
+            return bootstrap_generator(graph)
         graph = PyGraph(func, code)
         frame = self.frame = FlowSpaceFrame(self, graph, code)
         frame.build_flow()


More information about the pypy-commit mailing list