[pypy-svn] r31953 - in pypy/dist/pypy: annotation tool

arigo at codespeak.net arigo at codespeak.net
Sat Sep 2 19:13:55 CEST 2006


Author: arigo
Date: Sat Sep  2 19:13:53 2006
New Revision: 31953

Modified:
   pypy/dist/pypy/annotation/annrpython.py
   pypy/dist/pypy/tool/error.py
Log:
(pedronis, arigo)

Ooooooooups.  In case of multiple annotation errors they where shown
with the source code of *another* graph - at the bytecode position where
they occurred in their true graph.  Produces very nice nonsense.



Modified: pypy/dist/pypy/annotation/annrpython.py
==============================================================================
--- pypy/dist/pypy/annotation/annrpython.py	(original)
+++ pypy/dist/pypy/annotation/annrpython.py	Sat Sep  2 19:13:53 2006
@@ -38,6 +38,7 @@
         self.links_followed = {} # set of links that have ever been followed
         self.notify = {}        # {block: {positions-to-reflow-from-when-done}}
         self.fixed_graphs = {}  # set of graphs not to annotate again
+        self.blocked_blocks = {} # set of {blocked_block: graph}
         # --- the following information is recorded for debugging only ---
         # --- and only if annotation.model.DEBUG is kept to True
         self.why_not_annotated = {} # {block: (exc_type, exc_value, traceback)}
@@ -256,32 +257,14 @@
             newgraphs = self.translator.graphs  #all of them
             got_blocked_blocks = False in self.annotated.values()
         if got_blocked_blocks:
-            if annmodel.DEBUG:
-                for block in self.annotated:
-                    if self.annotated[block] is False:
-                        graph = self.why_not_annotated[block][1].break_at[0]
-                        self.blocked_graphs[graph] = True
-##                        import traceback
-##                        blocked_err = []
-##                        blocked_err.append('-+' * 30 +'\n')
-##                        blocked_err.append('BLOCKED block at :' +
-##                                           self.whereami(self.why_not_annotated[block][1].break_at) +
-##                                           '\n')
-##                        blocked_err.append('because of:\n')
-##                        blocked_err.extend(traceback.format_exception(*self.why_not_annotated[block]))
-##                        from pypy.interpreter.pytraceback import offset2lineno
-##
-##                        offset = block.operations[self.why_not_annotated[block][1].break_at[2]].offset
-##                        lineno = offset2lineno(graph.func.func_code, offset)
-##                        blocked_err.append("Happened at file %s line %d\n" % (graph.filename, lineno))
-##                        blocked_err.append(graph.source.split("\n")[lineno-graph.startline] + "\n")
-##                        blocked_err.append('-+' * 30 +'\n')
-##                        log.ERROR(''.join(blocked_err))
+            for graph in self.blocked_graphs.values():
+                self.blocked_graphs[graph] = True
 
             blocked_blocks = [block for block, done in self.annotated.items()
                                     if done is False]
+            assert len(blocked_blocks) == len(self.blocked_blocks)
 
-            text = format_blocked_annotation_error(self, blocked_blocks, graph)
+            text = format_blocked_annotation_error(self, self.blocked_blocks)
             #raise SystemExit()
             raise AnnotatorError(text)
         for graph in newgraphs:
@@ -486,10 +469,13 @@
             self.reflowcounter.setdefault(block, 0)
             self.reflowcounter[block] += 1
         self.annotated[block] = graph
+        if block in self.blocked_blocks:
+            del self.blocked_blocks[block]
         try:
             self.flowin(graph, block)
         except BlockedInference, e:
             self.annotated[block] = False   # failed, hopefully temporarily
+            self.blocked_blocks[block] = graph
         except Exception, e:
             # hack for debug tools only
             if not hasattr(e, '__annotator_block'):
@@ -508,6 +494,7 @@
         self.pendingblocks[block] = graph
         assert block in self.annotated
         self.annotated[block] = False  # must re-flow
+        self.blocked_blocks[block] = graph
 
     def bindinputargs(self, graph, block, inputcells, called_from_graph=None):
         # Create the initial bindings for the input args of a block.
@@ -516,6 +503,7 @@
         for a, cell in zip(block.inputargs, inputcells):
             self.setbinding(a, cell, called_from_graph, where=where)
         self.annotated[block] = False  # must flowin.
+        self.blocked_blocks[block] = graph
 
     def mergeinputargs(self, graph, block, inputcells, called_from_graph=None):
         # Merge the new 'cells' with each of the block's existing input

Modified: pypy/dist/pypy/tool/error.py
==============================================================================
--- pypy/dist/pypy/tool/error.py	(original)
+++ pypy/dist/pypy/tool/error.py	Sat Sep  2 19:13:53 2006
@@ -93,9 +93,9 @@
             msg.extend(traceback.format_exception(*annotator.why_not_annotated[block]))
     return "\n".join(msg)
 
-def format_blocked_annotation_error(annotator, blocked_blocks, graph):
+def format_blocked_annotation_error(annotator, blocked_blocks):
     text = []
-    for block in blocked_blocks:
+    for block, graph in blocked_blocks.items():
         text.append(gather_error(annotator, block, graph))
     return '\n'.join(text)
     



More information about the Pypy-commit mailing list