[pypy-svn] r9624 - pypy/branch/annotation-no-rev-num

arigo at codespeak.net arigo at codespeak.net
Fri Mar 4 14:09:50 CET 2005


Author: arigo
Date: Fri Mar  4 14:09:50 2005
New Revision: 9624

Added:
   pypy/branch/annotation-no-rev-num/
      - copied from r9580, pypy/dist/pypy/annotation/
Modified:
   pypy/branch/annotation-no-rev-num/bookkeeper.py
   pypy/branch/annotation-no-rev-num/classdef.py
   pypy/branch/annotation-no-rev-num/model.py
   pypy/branch/annotation-no-rev-num/unaryop.py
Log:
A branch to play with revision-number-less annotations.

Actually now I wonder why I made a branch, before it took 10 minutes to 
make it work...



Modified: pypy/branch/annotation-no-rev-num/bookkeeper.py
==============================================================================
--- pypy/dist/pypy/annotation/bookkeeper.py	(original)
+++ pypy/branch/annotation-no-rev-num/bookkeeper.py	Fri Mar  4 14:09:50 2005
@@ -42,9 +42,6 @@
         del getthreadlocals().bookkeeper
         del self.position_key
 
-    def is_in_an_operation(self):
-        return hasattr(self, 'position_key')
-
     def getfactory(self, factorycls):
         """Get the Factory associated with the current position,
         or build it if it doesn't exist yet."""
@@ -146,12 +143,6 @@
         elif isinstance(t, (type, ClassType)) and \
                  t.__module__ != '__builtin__':
             classdef = self.getclassdef(t)
-            if self.is_in_an_operation():
-                # woha! instantiating a "mutable" SomeXxx like
-                # SomeInstance is always dangerous, because we need to
-                # allow reflowing from the current operation if/when
-                # the classdef later changes.
-                classdef.instantiation_locations[self.position_key] = True
             return SomeInstance(classdef)
         else:
             o = SomeObject()
@@ -173,7 +164,6 @@
                           "unsupported specialization type '%s'"%(x,)
 
             classdef = self.getclassdef(cls)
-            classdef.instantiation_locations[self.position_key] = True 
             s_instance = SomeInstance(classdef)
             # flow into __init__() if the class has got one
             init = getattr(cls, '__init__', None)

Modified: pypy/branch/annotation-no-rev-num/classdef.py
==============================================================================
--- pypy/dist/pypy/annotation/classdef.py	(original)
+++ pypy/branch/annotation-no-rev-num/classdef.py	Fri Mar  4 14:09:50 2005
@@ -19,6 +19,7 @@
         # XXX a SomeImpossibleValue() constant?  later!!
         self.s_value = SomeImpossibleValue()
         self.readonly = True
+        self.read_locations = {}
 
     def getvalue(self):
         while self.sources:
@@ -35,6 +36,7 @@
         self.sources.update(other.sources)
         self.s_value = unionof(self.s_value, other.s_value)
         self.readonly = self.readonly and other.readonly
+        self.read_locations.update(other.read_locations)
 
 
 class ClassDef:
@@ -43,8 +45,7 @@
     def __init__(self, cls, bookkeeper):
         self.bookkeeper = bookkeeper
         self.attrs = {}          # {name: Attribute}
-        self.revision = 0        # which increases the revision number
-        self.instantiation_locations = {}
+        #self.instantiation_locations = {}
         self.cls = cls
         self.subdefs = {}
         assert (len(cls.__bases__) <= 1 or
@@ -109,11 +110,11 @@
                     pending.append(sub)
                     seen[sub] = True
 
-    def getallinstantiations(self):
-        locations = {}
-        for clsdef in self.getallsubdefs():
-            locations.update(clsdef.instantiation_locations)
-        return locations
+##    def getallinstantiations(self):
+##        locations = {}
+##        for clsdef in self.getallsubdefs():
+##            locations.update(clsdef.instantiation_locations)
+##        return locations
 
     def _generalize_attr(self, attr, s_value):
         # first remove the attribute from subclasses -- including us!
@@ -122,8 +123,6 @@
             if attr in subdef.attrs:
                 subclass_attrs.append(subdef.attrs[attr])
                 del subdef.attrs[attr]
-            # bump the revision number of this class and all subclasses
-            subdef.revision += 1
 
         # do the generalization
         newattr = Attribute(attr, self.bookkeeper)
@@ -135,7 +134,7 @@
         self.attrs[attr] = newattr
 
         # reflow from all factories
-        for position in self.getallinstantiations():
+        for position in newattr.read_locations:
             self.bookkeeper.annotator.reflowfromposition(position)
 
     def generalize_attr(self, attr, s_value=None):

Modified: pypy/branch/annotation-no-rev-num/model.py
==============================================================================
--- pypy/dist/pypy/annotation/model.py	(original)
+++ pypy/branch/annotation-no-rev-num/model.py	Fri Mar  4 14:09:50 2005
@@ -170,7 +170,6 @@
     def __init__(self, classdef):
         self.classdef = classdef
         self.knowntype = classdef.cls
-        self.revision = classdef.revision
     def fmt_knowntype(self, kt):
         return None
     def fmt_classdef(self, cd):

Modified: pypy/branch/annotation-no-rev-num/unaryop.py
==============================================================================
--- pypy/dist/pypy/annotation/unaryop.py	(original)
+++ pypy/branch/annotation-no-rev-num/unaryop.py	Fri Mar  4 14:09:50 2005
@@ -160,34 +160,20 @@
 
 class __extend__(SomeInstance):
 
-    def currentdef(ins):
-        if ins.revision != ins.classdef.revision:
-            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
-            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()
-            return s_result
+            attrdef = ins.classdef.find_attribute(attr)
+            position = getbookkeeper().position_key
+            attrdef.read_locations[position] = True
+            return attrdef.getvalue()
         return SomeObject()
 
     def setattr(ins, s_attr, s_value):
         if s_attr.is_constant() and isinstance(s_attr.const, str):
             attr = s_attr.const
-            try:
-                clsdef = ins.currentdef().locate_attribute(attr)
-            except BlockedInference, blocked:
-                blocked.info = "%s .%s" % (blocked.info, attr)
-                raise blocked                
+            # find the (possibly parent) class where this attr is defined
+            clsdef = ins.classdef.locate_attribute(attr)
             attrdef = clsdef.attrs[attr]
             attrdef.readonly = False
 
@@ -196,16 +182,6 @@
                 return
             # create or update the attribute in clsdef
             clsdef.generalize_attr(attr, s_value)
-            raise BlockedInference
-        return
-
-    def contains(self, other):
-        # override the default contains() to ignore revision numbers
-        if self == other:
-            return True
-        s_union = pair(self, other).union()
-        return (isinstance(s_union, SomeInstance) and
-                s_union.classdef is self.classdef)
 
 
 class __extend__(SomeBuiltin):
@@ -251,10 +227,7 @@
         results = []
         for func, classdef in pbc.prebuiltinstances.items():
             if isclassdef(classdef): 
-                # create s_self and record the creation in the factory
                 s_self = SomeInstance(classdef)
-                classdef.instantiation_locations[
-                    bookkeeper.position_key] = True
                 args1 = args.prepend(s_self)
             else:
                 args1 = args



More information about the Pypy-commit mailing list