[pypy-svn] r45460 - pypy/dist/pypy/rpython

arigo at codespeak.net arigo at codespeak.net
Thu Aug 2 19:15:40 CEST 2007


Author: arigo
Date: Thu Aug  2 19:15:39 2007
New Revision: 45460

Modified:
   pypy/dist/pypy/rpython/normalizecalls.py
Log:
A hard-to-test fix in assign_inheritence_ids().  This tries to ensure
that newly seen classes all go to the end of the peers list as long as
they don't extend previous hierarchies (no common base class).


Modified: pypy/dist/pypy/rpython/normalizecalls.py
==============================================================================
--- pypy/dist/pypy/rpython/normalizecalls.py	(original)
+++ pypy/dist/pypy/rpython/normalizecalls.py	Thu Aug  2 19:15:39 2007
@@ -273,16 +273,6 @@
 
 # ____________________________________________________________
 
-class Max(object):
-    def __cmp__(self, other):
-        if self is other:
-            return 0
-        else:
-            return 1
-
-MAX = Max()    # a maximum object
-
-
 class TotalOrderSymbolic(ComputedIntSymbolic):
 
     def __init__(self, orderwitness, peers):
@@ -301,14 +291,34 @@
         if self.value is None:
             self.peers.sort()
             for i, peer in enumerate(self.peers):
-                assert peer.value is None
+                assert peer.value is None or peer.value == i
                 peer.value = i
             assert self.value is not None
         return self.value
 
+    def dump(self, annotator):   # for debugging
+        self.peers.sort()
+        mapping = {}
+        for classdef in annotator.bookkeeper.classdefs:
+            if hasattr(classdef, '_unique_cdef_id'):
+                mapping[classdef._unique_cdef_id] = classdef
+        for peer in self.peers:
+            if peer is self:
+                print '==>',
+            else:
+                print '   ',
+            print 'value %4s --' % (peer.value,), peer.orderwitness,
+            if peer.orderwitness[-1] in mapping:
+                print mapping[peer.orderwitness[-1]]
+            else:
+                print
+
 def assign_inheritance_ids(annotator):
     # we sort the classes by lexicographic order of reversed(mro),
-    # which gives a nice depth-first order.
+    # which gives a nice depth-first order.  The classes are turned
+    # into numbers in order to (1) help determinism, (2) ensure that
+    # new hierarchies of classes with no common base classes can be
+    # added later and get higher numbers.
     bk = annotator.bookkeeper
     try:
         lst = bk._inheritance_id_symbolics
@@ -316,11 +326,22 @@
         lst = bk._inheritance_id_symbolics = []
     for classdef in annotator.bookkeeper.classdefs:
         if not hasattr(classdef, 'minid'):
-            witness = list(classdef.getmro())
+            witness = [get_unique_cdef_id(cdef) for cdef in classdef.getmro()]
             witness.reverse()
             classdef.minid = TotalOrderSymbolic(witness, lst)
             classdef.maxid = TotalOrderSymbolic(witness + [MAX], lst)
 
+MAX = 1E100
+_cdef_id_counter = 0
+def get_unique_cdef_id(cdef):
+    global _cdef_id_counter
+    try:
+        return cdef._unique_cdef_id
+    except AttributeError:
+        cdef._unique_cdef_id = _cdef_id_counter
+        _cdef_id_counter += 1
+        return cdef._unique_cdef_id
+
 # ____________________________________________________________
 
 def perform_normalizations(rtyper):



More information about the Pypy-commit mailing list