[pypy-svn] r9580 - in pypy/dist/pypy: annotation objspace/flow translator translator/tool

pedronis at codespeak.net pedronis at codespeak.net
Wed Mar 2 14:33:52 CET 2005


Author: pedronis
Date: Wed Mar  2 14:33:52 2005
New Revision: 9580

Modified:
   pypy/dist/pypy/annotation/factory.py
   pypy/dist/pypy/annotation/unaryop.py
   pypy/dist/pypy/objspace/flow/model.py
   pypy/dist/pypy/translator/annrpython.py
   pypy/dist/pypy/translator/tool/make_dot.py
Log:
attach more info to BlockedInference exceptions

more uniform printing of flow positions

put @xxx info also the graphs, to ease finding blocked inference blocks in them



Modified: pypy/dist/pypy/annotation/factory.py
==============================================================================
--- pypy/dist/pypy/annotation/factory.py	(original)
+++ pypy/dist/pypy/annotation/factory.py	Wed Mar  2 14:33:52 2005
@@ -15,14 +15,25 @@
     """This exception signals the type inference engine that the situation
     is currently blocked, and that it should try to progress elsewhere."""
 
-    def __init__(self):
+    def __init__(self, info=None):
         try:
+            self.annotator = getbookkeeper().annotator
             self.break_at = getbookkeeper().position_key
         except AttributeError:
             self.break_at = None
+        self.info = info
 
     def __repr__(self):
-        return "<BlockedInference break_at %r>" %(self.break_at,)
+        if self.info:
+            info = "[%s]" % self.info
+        else:
+            info = ""
+        if not self.break_at:
+            break_at = "?"
+        else:
+            break_at = self.annotator.whereami(self.break_at)
+        return "<BlockedInference break_at %s %s>" %(break_at, info)
+
     __str__ = __repr__
 
 

Modified: pypy/dist/pypy/annotation/unaryop.py
==============================================================================
--- pypy/dist/pypy/annotation/unaryop.py	(original)
+++ pypy/dist/pypy/annotation/unaryop.py	Wed Mar  2 14:33:52 2005
@@ -162,15 +162,18 @@
 
     def currentdef(ins):
         if ins.revision != ins.classdef.revision:
-            #print ins.revision, ins.classdef.revision
-            raise BlockedInference
+            raise BlockedInference(info="stale inst of %s" % ins.classdef.cls)
         return ins.classdef
 
     def getattr(ins, s_attr):
         if s_attr.is_constant() and isinstance(s_attr.const, str):
             attr = s_attr.const
             #print 'getattr:', ins, attr, ins.classdef.revision
-            s_result = ins.currentdef().find_attribute(attr).getvalue()
+            try:
+                s_result = ins.currentdef().find_attribute(attr).getvalue()
+            except BlockedInference, blocked:
+                blocked.info = "%s .%s" % (blocked.info, attr)
+                raise blocked
             # we call this because it might raise BlockedInference if
             # the above line caused generalization.
             ins.currentdef()
@@ -180,7 +183,11 @@
     def setattr(ins, s_attr, s_value):
         if s_attr.is_constant() and isinstance(s_attr.const, str):
             attr = s_attr.const
-            clsdef = ins.currentdef().locate_attribute(attr)
+            try:
+                clsdef = ins.currentdef().locate_attribute(attr)
+            except BlockedInference, blocked:
+                blocked.info = "%s .%s" % (blocked.info, attr)
+                raise blocked                
             attrdef = clsdef.attrs[attr]
             attrdef.readonly = False
 

Modified: pypy/dist/pypy/objspace/flow/model.py
==============================================================================
--- pypy/dist/pypy/objspace/flow/model.py	(original)
+++ pypy/dist/pypy/objspace/flow/model.py	Wed Mar  2 14:33:52 2005
@@ -69,6 +69,12 @@
 
         self.exc_handler = False          # block at the start of exception handling code
 
+    def at(self):
+        if self.operations:
+            return "@%d" % self.operations[0].offset
+        else:
+            return ""
+
     def __str__(self):
         if self.operations:
             txt = "block@%d" % self.operations[0].offset

Modified: pypy/dist/pypy/translator/annrpython.py
==============================================================================
--- pypy/dist/pypy/translator/annrpython.py	(original)
+++ pypy/dist/pypy/translator/annrpython.py	Wed Mar  2 14:33:52 2005
@@ -143,7 +143,7 @@
                         import traceback
                         print '-+' * 30
                         print 'BLOCKED block at:',
-                        print self.why_not_annotated[block][1].break_at
+                        print self.whereami(self.why_not_annotated[block][1].break_at)
                         print 'because of:'
                         traceback.print_exception(*self.why_not_annotated[block])
                         print '-+' * 30
@@ -185,11 +185,11 @@
                 cause_history.append(self.binding_caused_by[arg])
         self.bindings[arg] = s_value
         if annmodel.DEBUG:
-            #if arg in self.return_bindings:
-            #    ansi_print("%s -> %s" % (self.whereami((self.return_bindings[arg],
-            #                                             None, None)),
-            #                             s_value),
-            #               esc="1") # bold
+            if arg in self.return_bindings:
+                ansi_print("%s -> %s" % (self.whereami((self.return_bindings[arg],
+                                                         None, None)),
+                                         s_value),
+                           esc="1") # bold
 
             if arg in self.return_bindings and s_value == annmodel.SomeObject():
                 ansi_print("*** WARNING: %s result degenerated to SomeObject" %
@@ -333,7 +333,15 @@
         else:
             name = 'UNKNOWN'
             firstlineno = -1
-        return "(%s:%d) %s" % (mod, firstlineno, name)
+        blk = ""
+        if block:
+            at = block.at()
+            if at:
+                blk = " block"+at
+        opid=""
+        if i is not None:
+            opid = " op=%d" % i
+        return "(%s:%d) %s%s%s" % (mod, firstlineno, name, blk, opid)
 
     def flowin(self, fn, block):
         #print 'Flowing', block, [self.binding(a) for a in block.inputargs]
@@ -422,7 +430,7 @@
         if resultcell is None:
             resultcell = annmodel.SomeImpossibleValue()  # no return value
         elif resultcell == annmodel.SomeImpossibleValue():
-            raise BlockedInference  # the operation cannot succeed
+            raise BlockedInference(info=op)  # the operation cannot succeed
         assert isinstance(resultcell, annmodel.SomeObject)
         assert isinstance(op.result, Variable)
         self.setbinding(op.result, resultcell)  # bind resultcell to op.result

Modified: pypy/dist/pypy/translator/tool/make_dot.py
==============================================================================
--- pypy/dist/pypy/translator/tool/make_dot.py	(original)
+++ pypy/dist/pypy/translator/tool/make_dot.py	Wed Mar  2 14:33:52 2005
@@ -141,7 +141,7 @@
             eh = 'EH'
         else:
             eh = ''
-        data = "%s(%s %s)\\ninputargs: %s\\n\\n" % (name, block.__class__.__name__, eh, iargs)
+        data = "%s%s(%s %s)\\ninputargs: %s\\n\\n" % (name, block.at(), block.__class__.__name__, eh, iargs)
         if block.operations and self.func:
             maxoffs = max([op.offset for op in block.operations])
             if maxoffs >= 0:



More information about the Pypy-commit mailing list