[pypy-svn] r4325 - in pypy/trunk/src/pypy: annotation translator

arigo at codespeak.net arigo at codespeak.net
Sat May 8 14:12:06 CEST 2004


Author: arigo
Date: Sat May  8 14:12:06 2004
New Revision: 4325

Modified:
   pypy/trunk/src/pypy/annotation/binaryop.py
   pypy/trunk/src/pypy/annotation/factory.py
   pypy/trunk/src/pypy/annotation/unaryop.py
   pypy/trunk/src/pypy/translator/annrpython.py
Log:
More small changes.  No longer use the BlockedInference exception for both
stopping the inference and invalidating other blocks; there is now a dedicated
interface to invalidate other blocks.



Modified: pypy/trunk/src/pypy/annotation/binaryop.py
==============================================================================
--- pypy/trunk/src/pypy/annotation/binaryop.py	(original)
+++ pypy/trunk/src/pypy/annotation/binaryop.py	Sat May  8 14:12:06 2004
@@ -8,7 +8,7 @@
 from pypy.annotation.model import SomeTuple, SomeImpossibleValue
 from pypy.annotation.model import SomeInstance, SomeFunction
 from pypy.annotation.model import unionof, set, setunion, missing_operation
-from pypy.annotation.factory import BlockedInference
+from pypy.annotation.factory import BlockedInference, getbookkeeper
 
 
 # XXX unify this with ObjSpace.MethodTable
@@ -110,9 +110,9 @@
 
     def setitem((lst1, int2), s_value):
         if not lst1.s_item.contains(s_value):
+            bookkeeper = getbookkeeper()
             for factory in lst1.factories:
-                factory.generalize(s_value)
-            raise BlockedInference(lst1.factories)
+                factory.generalize(s_value, bookkeeper)
 
 
 class __extend__(pairtype(SomeInteger, SomeList)):

Modified: pypy/trunk/src/pypy/annotation/factory.py
==============================================================================
--- pypy/trunk/src/pypy/annotation/factory.py	(original)
+++ pypy/trunk/src/pypy/annotation/factory.py	Sat May  8 14:12:06 2004
@@ -18,9 +18,7 @@
     """This exception signals the type inference engine that the situation
     is currently blocked, and that it should try to progress elsewhere."""
 
-    def __init__(self, factories = ()):
-        # factories that need to be invalidated
-        self.invalidatefactories = factories
+    def __init__(self):
         try:
             self.break_at = getbookkeeper().position_key
         except AttributeError:
@@ -111,8 +109,10 @@
     def create(self):
         return SomeList(factories = {self: True}, s_item = self.s_item)
 
-    def generalize(self, s_new_item):
+    def generalize(self, s_new_item, bookkeeper=None):
         self.s_item = unionof(self.s_item, s_new_item)
+        if bookkeeper:
+            bookkeeper.annotator.reflowfromposition(self.position_key)
 
 
 class FuncCallFactory:
@@ -182,7 +182,7 @@
             factories.update(clsdef.instancefactories)
         return factories
 
-    def generalize(self, attr, s_value):
+    def generalize(self, attr, s_value, bookkeeper=None):
         # we make sure that an attribute never appears both in a class
         # and in some subclass, in two steps:
         # (1) assert that the attribute is in no superclass
@@ -197,3 +197,7 @@
             # bump the revision number of this class and all subclasses
             subdef.revision += 1
         self.attrs[attr] = unionof(s_value, *subclass_values)
+        # reflow from all factories
+        if bookkeeper:
+            for factory in self.getallfactories():
+                bookkeeper.annotator.reflowfromposition(factory.position_key)

Modified: pypy/trunk/src/pypy/annotation/unaryop.py
==============================================================================
--- pypy/trunk/src/pypy/annotation/unaryop.py	(original)
+++ pypy/trunk/src/pypy/annotation/unaryop.py	Sat May  8 14:12:06 2004
@@ -55,7 +55,7 @@
     def currentdef(ins):
         if ins.revision != ins.classdef.revision:
             #print ins.revision, ins.classdef.revision
-            raise BlockedInference()
+            raise BlockedInference
         return ins.classdef
 
     def getattr(ins, s_attr):
@@ -67,8 +67,8 @@
                     return clsdef.attrs[attr]
             # maybe the attribute exists in some subclass? if so, lift it
             clsdef = ins.classdef
-            clsdef.generalize(attr, SomeImpossibleValue())
-            raise BlockedInference(clsdef.getallfactories())
+            clsdef.generalize(attr, SomeImpossibleValue(), getbookkeeper())
+            raise BlockedInference
         return SomeObject()
 
     def setattr(ins, s_attr, s_value):
@@ -85,8 +85,8 @@
                 # if the attribute doesn't exist yet, create it here
                 clsdef = ins.classdef
             # create or update the attribute in clsdef
-            clsdef.generalize(attr, s_value)
-            raise BlockedInference(clsdef.getallfactories())
+            clsdef.generalize(attr, s_value, getbookkeeper())
+            raise BlockedInference
         return SomeObject()
 
 

Modified: pypy/trunk/src/pypy/translator/annrpython.py
==============================================================================
--- pypy/trunk/src/pypy/translator/annrpython.py	(original)
+++ pypy/trunk/src/pypy/translator/annrpython.py	Sat May  8 14:12:06 2004
@@ -114,7 +114,13 @@
     def buildflowgraph(self, func):
         space = FlowObjSpace()
         graph = space.build_flow(func)
-        self.notify[graph.returnblock] = graph.funccallfactories = {}
+        # the dictionary of all FuncCallFactories (call points to this func)
+        # is populated via graph.funccallfactories in pypy.annotation.factory
+        # and read via self.notify[graph.returnblock] whenever the return block
+        # of this graph has been analysed.
+        callfactories = {}
+        graph.funccallfactories = callfactories
+        self.notify[graph.returnblock] = callfactories
         return graph
 
     def generalizeinputargs(self, flowgraph, inputcells):
@@ -126,6 +132,10 @@
         v = flowgraph.getreturnvar()
         return self.bindings.get(v, annmodel.SomeImpossibleValue())
 
+    def reflowfromposition(self, position_key):
+        block, index = position_key
+        self.reflowpendingblock(block)
+
 
     #___ simplification (should be moved elsewhere?) _______
 
@@ -190,9 +200,6 @@
                 #import traceback, sys
                 #traceback.print_tb(sys.exc_info()[2])
                 self.annotated[block] = False   # failed, hopefully temporarily
-                for factory in e.invalidatefactories:
-                    oldblock, oldindex = factory.position_key
-                    self.reflowpendingblock(oldblock)
 
     def reflowpendingblock(self, block):
         self.pendingblocks.append((block, None))
@@ -227,11 +234,8 @@
             self.addpendingblock(link.target, cells)
         if block in self.notify:
             # invalidate some factories when this block is done
-            factories = self.notify[block].keys()
-            self.notify[block].clear()  # don't del: the dict can be re-populated
-            for factory in factories:
-                oldblock, oldindex = factory.position_key
-                self.reflowpendingblock(oldblock)
+            for factory in self.notify[block]:
+                self.reflowfromposition(factory.position_key)
 
 
     #___ creating the annotations based on operations ______


More information about the Pypy-commit mailing list