[pypy-svn] r34123 - in pypy/dist/pypy: annotation annotation/test tool

fijal at codespeak.net fijal at codespeak.net
Fri Nov 3 16:55:40 CET 2006


Author: fijal
Date: Fri Nov  3 16:55:38 2006
New Revision: 34123

Modified:
   pypy/dist/pypy/annotation/annrpython.py
   pypy/dist/pypy/annotation/specialize.py
   pypy/dist/pypy/annotation/test/test_annrpython.py
   pypy/dist/pypy/tool/error.py
Log:
Fixed a bit displaying of annotation errors. Added more specialisation possibilities.


Modified: pypy/dist/pypy/annotation/annrpython.py
==============================================================================
--- pypy/dist/pypy/annotation/annrpython.py	(original)
+++ pypy/dist/pypy/annotation/annrpython.py	Fri Nov  3 16:55:38 2006
@@ -312,7 +312,7 @@
 
         graph = position_key[0]
         msgstr = format_someobject_error(self, position_key, what, s_value,
-                                         called_from_graph)
+                                         called_from_graph, self.bindings[what])
         
 
         raise AnnotatorError(msgstr)

Modified: pypy/dist/pypy/annotation/specialize.py
==============================================================================
--- pypy/dist/pypy/annotation/specialize.py	(original)
+++ pypy/dist/pypy/annotation/specialize.py	Fri Nov  3 16:55:38 2006
@@ -377,9 +377,9 @@
     key = tuple([args_s[i].const for i in argindices])
     return funcdesc.cachedgraph(key)
 
-def specialize_argtype(funcdesc, args_s, i):
-    key = args_s[i].knowntype
-    return funcdesc.cachedgraph(key)        
+def specialize_argtype(funcdesc, args_s, *argindices):
+    key = tuple([args_s[i].knowntype for i in argindices])
+    return funcdesc.cachedgraph(key)
 
 def specialize_arglistitemtype(funcdesc, args_s, i):
     s = args_s[i]

Modified: pypy/dist/pypy/annotation/test/test_annrpython.py
==============================================================================
--- pypy/dist/pypy/annotation/test/test_annrpython.py	(original)
+++ pypy/dist/pypy/annotation/test/test_annrpython.py	Fri Nov  3 16:55:38 2006
@@ -1006,6 +1006,42 @@
         assert a.binding(graph2.getreturnvar()).classdef == C2df
         assert graph1 in a.translator.graphs
         assert graph2 in a.translator.graphs
+    
+    def test_specialcase_args(self):
+        class C1(object):
+            pass
+        
+        class C2(object):
+            pass
+        
+        def alloc(cls, cls2):
+            i = cls()
+            assert isinstance(i, cls)
+            j = cls2()
+            assert isinstance(j, cls2)
+            return i
+        
+        def f():
+            alloc(C1, C1)
+            alloc(C1, C2)
+            alloc(C2, C1)
+            alloc(C2, C2)
+        
+        alloc._annspecialcase_ = "specialize:arg(0,1)"
+        
+        a = self.RPythonAnnotator()
+        C1df = a.bookkeeper.getuniqueclassdef(C1)
+        C2df = a.bookkeeper.getuniqueclassdef(C2)
+        s = a.build_types(f, [])
+        allocdesc = a.bookkeeper.getdesc(alloc)
+        s_C1 = a.bookkeeper.immutablevalue(C1)
+        s_C2 = a.bookkeeper.immutablevalue(C2)
+        graph1 = allocdesc.specialize([s_C1, s_C2])
+        graph2 = allocdesc.specialize([s_C2, s_C2])
+        assert a.binding(graph1.getreturnvar()).classdef == C1df
+        assert a.binding(graph2.getreturnvar()).classdef == C2df
+        assert graph1 in a.translator.graphs
+        assert graph2 in a.translator.graphs
 
     def test_assert_list_doesnt_lose_info(self):
         class T(object):

Modified: pypy/dist/pypy/tool/error.py
==============================================================================
--- pypy/dist/pypy/tool/error.py	(original)
+++ pypy/dist/pypy/tool/error.py	Fri Nov  3 16:55:38 2006
@@ -99,7 +99,7 @@
         text.append(gather_error(annotator, block, graph))
     return '\n'.join(text)
     
-def format_someobject_error(annotator, position_key, what, s_value, called_from_graph):
+def format_someobject_error(annotator, position_key, what, s_value, called_from_graph, binding=""):
     #block = getattr(annotator, 'flowin_block', None) or block
     msg = ["annotation of %r degenerated to SomeObject()" % (what,)]
     if position_key is not None:
@@ -111,6 +111,8 @@
     if s_value.origin is not None:
         msg.append(".. SomeObject() origin: %s" % (
             annotator.whereami(s_value.origin),))
+    msg.append("Previous annotation:")
+    msg.append("  " + str(binding))
     return "\n".join(msg)
 
 def format_global_error(graph, offset, message):



More information about the Pypy-commit mailing list