[pypy-svn] r17226 - in pypy/dist/pypy: annotation translator

pedronis at codespeak.net pedronis at codespeak.net
Mon Sep 5 14:30:44 CEST 2005


Author: pedronis
Date: Mon Sep  5 14:30:42 2005
New Revision: 17226

Modified:
   pypy/dist/pypy/annotation/bookkeeper.py
   pypy/dist/pypy/annotation/classdef.py
   pypy/dist/pypy/annotation/listdef.py
   pypy/dist/pypy/annotation/model.py
   pypy/dist/pypy/translator/annrpython.py
Log:
try at better crash early on SomeObject logic. we check on setbinding, attr and dict/list generalisation



Modified: pypy/dist/pypy/annotation/bookkeeper.py
==============================================================================
--- pypy/dist/pypy/annotation/bookkeeper.py	(original)
+++ pypy/dist/pypy/annotation/bookkeeper.py	Mon Sep  5 14:30:42 2005
@@ -684,8 +684,10 @@
                 self.spec_callsite_keys_results[occurence] = prev_key, r
 
         return r
-        
 
+    def ondegenerated(self, what, s_value, where=None, called_from=None):
+        self.annotator.ondegenerated(what, s_value, where=where, called_from=called_from)
+        
     def whereami(self):
         return self.annotator.whereami(self.position_key)
 

Modified: pypy/dist/pypy/annotation/classdef.py
==============================================================================
--- pypy/dist/pypy/annotation/classdef.py	(original)
+++ pypy/dist/pypy/annotation/classdef.py	Mon Sep  5 14:30:42 2005
@@ -4,8 +4,8 @@
 
 from __future__ import generators
 from types import FunctionType
-from pypy.annotation.model import SomeImpossibleValue, SomePBC, tracking_unionof
-from pypy.annotation.model import SomeInteger
+from pypy.annotation.model import SomeImpossibleValue, SomePBC, unionof
+from pypy.annotation.model import SomeInteger, isdegenerated
 
 
 # The main purpose of a ClassDef is to collect information about class/instance
@@ -88,15 +88,28 @@
         else:
             # a prebuilt instance source forces readonly=False, see above
             self.readonly = False
-        self.s_value = tracking_unionof(self, self.s_value, s_value)
+        s_new_value = unionof(self.s_value, s_value)       
+        if isdegenerated(s_new_value):            
+            self.bookkeeper.ondegenerated("source %r attr %s" % (source, self.name),
+                                          s_new_value)
+                
+        self.s_value = s_new_value
 
     def getvalue(self):
         # Same as 'self.s_value' for historical reasons.
         return self.s_value
 
-    def merge(self, other):
+    def merge(self, other, classdef=None):
         assert self.name == other.name
-        self.s_value = tracking_unionof(self, self.s_value, other.s_value)
+        s_new_value = unionof(self.s_value, other.s_value)
+        if isdegenerated(s_new_value):
+            if classdef is None:
+                what = "? attr %s" % self.name
+            else:
+                what = "%r attr %s" % (classdef, self.name)
+            self.bookkeeper.ondegenerated(what, s_new_value)
+
+        self.s_value = s_new_value        
         self.readonly = self.readonly and other.readonly
         self.read_locations.update(other.read_locations)
 
@@ -294,7 +307,7 @@
 
         # keep all subattributes' values
         for subattr in subclass_attrs:
-            newattr.merge(subattr)
+            newattr.merge(subattr, classdef=self)
 
         # store this new Attribute, generalizing the previous ones from
         # subclasses -- invariant (A)

Modified: pypy/dist/pypy/annotation/listdef.py
==============================================================================
--- pypy/dist/pypy/annotation/listdef.py	(original)
+++ pypy/dist/pypy/annotation/listdef.py	Mon Sep  5 14:30:42 2005
@@ -1,5 +1,5 @@
 from pypy.annotation.model import SomeObject, SomeImpossibleValue
-from pypy.annotation.model import tracking_unionof, TLS, UnionError
+from pypy.annotation.model import unionof, TLS, UnionError, isdegenerated
 
 
 class ListItem:
@@ -28,7 +28,9 @@
             self.patch()    # which should patch all refs to 'other'
             s_value = self.s_value
             s_other_value = other.s_value
-            s_new_value = tracking_unionof(self.__class__.__name__, s_value, s_other_value)
+            s_new_value = unionof(s_value, s_other_value)
+            if isdegenerated(s_new_value):
+                self.bookkeeper.ondegenerated(self, s_new_value)
             if s_new_value != s_value:
                 self.s_value = s_new_value
                 # reflow from reading points
@@ -44,7 +46,9 @@
             listdef.listitem = self
 
     def generalize(self, s_other_value):
-        s_new_value = tracking_unionof(self.__class__.__name__, self.s_value, s_other_value)
+        s_new_value = unionof(self.s_value, s_other_value)
+        if isdegenerated(s_new_value):
+            self.bookkeeper.ondegenerated(self, s_new_value)        
         if s_new_value != self.s_value:
             self.s_value = s_new_value
             # reflow from all reading points

Modified: pypy/dist/pypy/annotation/model.py
==============================================================================
--- pypy/dist/pypy/annotation/model.py	(original)
+++ pypy/dist/pypy/annotation/model.py	Mon Sep  5 14:30:42 2005
@@ -493,10 +493,13 @@
         s1.caused_by_merge = somevalues
     return s1
 
+def isdegenerated(s_value):
+    return s_value.__class__ is SomeObject and s_value.knowntype is not type
+
 def tracking_unionof(ctxt, *somevalues):
     s1 = unionof(*somevalues)
-    if not s1.origin and type(ctxt) is tuple:
-        s1.origin = ctxt+(0,)
+    #if not s1.origin and type(ctxt) is tuple:
+    #    s1.origin = ctxt+(0,)
     return s1
         
 # make knowntypedata dictionary

Modified: pypy/dist/pypy/translator/annrpython.py
==============================================================================
--- pypy/dist/pypy/translator/annrpython.py	(original)
+++ pypy/dist/pypy/translator/annrpython.py	Mon Sep  5 14:30:42 2005
@@ -217,7 +217,26 @@
         else:
             raise TypeError, 'Variable or Constant expected, got %r' % (arg,)
 
-    def setbinding(self, arg, s_value, called_from=None):
+    def ondegenerated(self, what, s_value, where=None, called_from=None):
+        if self.policy.allow_someobjects:
+            return
+        msglines = ["annotation of %r degenerated to SomeObject()" % (what,)]
+        try:
+            position_key = where or self.bookkeeper.position_key
+        except AttributeError:
+            pass
+        else:
+            msglines.append(".. position: %s" % (self.whereami(position_key),))
+        if called_from is not None:
+            msglines.append(".. called from %r" % (called_from,))
+            if hasattr(called_from, '__module__'):
+                msglines[-1] += " from module %r"% (called_from.__module__,)
+        if s_value.origin is not None:
+            msglines.append(".. SomeObject() origin: %s" % (
+                self.whereami(s_value.origin),))
+        raise AnnotatorError('\n'.join(msglines))        
+
+    def setbinding(self, arg, s_value, called_from=None, where=None):
         if arg in self.bindings:
             assert s_value.contains(self.bindings[arg])
             # for debugging purposes, record the history of bindings that
@@ -227,25 +246,12 @@
                 history.append(self.bindings[arg])
                 cause_history = self.binding_cause_history.setdefault(arg, [])
                 cause_history.append(self.binding_caused_by[arg])
-        degenerated = (s_value.__class__ is annmodel.SomeObject and
-                       s_value.knowntype is not type)
-        if degenerated and not self.policy.allow_someobjects:
-            msglines = ["annotation of %r degenerated to SomeObject()" % (arg,)]
-            try:
-                position_key = self.bookkeeper.position_key
-            except AttributeError:
-                pass
-            else:
-                msglines.append(".. %r position: %s" % (
-                    arg, self.whereami(position_key),))
-            if called_from is not None:
-                msglines.append(".. called from %r" % (called_from,))
-                if hasattr(called_from, '__module__'):
-                    msglines[-1] += " from module %r"% (called_from.__module__,)
-            if s_value.origin is not None:
-                msglines.append(".. SomeObject() origin: %s" % (
-                    self.whereami(s_value.origin),))
-            raise AnnotatorError('\n'.join(msglines))
+
+        degenerated = annmodel.isdegenerated(s_value)
+
+        if degenerated:
+            self.ondegenerated(arg, s_value, where=where, called_from=called_from)
+
         self.bindings[arg] = s_value
         if annmodel.DEBUG:
             if arg in self.return_bindings:
@@ -373,21 +379,21 @@
         assert block in self.annotated
         self.annotated[block] = False  # must re-flow
 
-    def bindinputargs(self, fn, block, inputcells, called_from=None):
+    def bindinputargs(self, fn, block, inputcells, called_from=None, where=None):
         # Create the initial bindings for the input args of a block.
         assert len(block.inputargs) == len(inputcells)
         for a, cell in zip(block.inputargs, inputcells):
-            self.setbinding(a, cell, called_from)
+            self.setbinding(a, cell, called_from, where=where)
         self.annotated[block] = False  # must flowin.
 
     def mergeinputargs(self, fn, block, inputcells, called_from=None):
         # Merge the new 'cells' with each of the block's existing input
         # variables.
         oldcells = [self.binding(a) for a in block.inputargs]
-        unions = [annmodel.tracking_unionof((fn, block), c1,c2) for c1, c2 in zip(oldcells,inputcells)]
+        unions = [annmodel.unionof(c1,c2) for c1, c2 in zip(oldcells,inputcells)]
         # if the merged cells changed, we must redo the analysis
         if unions != oldcells:
-            self.bindinputargs(fn, block, unions, called_from)
+            self.bindinputargs(fn, block, unions, called_from, where=(fn, block, None))
 
     def whereami(self, position_key):
         fn, block, i = position_key



More information about the Pypy-commit mailing list