[pypy-svn] r79752 - in pypy/trunk/pypy: annotation annotation/test rpython rpython/lltypesystem rpython/ootypesystem

cfbolz at codespeak.net cfbolz at codespeak.net
Thu Dec 2 16:01:42 CET 2010


Author: cfbolz
Date: Thu Dec  2 16:01:39 2010
New Revision: 79752

Modified:
   pypy/trunk/pypy/annotation/annrpython.py
   pypy/trunk/pypy/annotation/bookkeeper.py
   pypy/trunk/pypy/annotation/description.py
   pypy/trunk/pypy/annotation/model.py
   pypy/trunk/pypy/annotation/specialize.py
   pypy/trunk/pypy/annotation/test/test_annrpython.py
   pypy/trunk/pypy/rpython/lltypesystem/rbuiltin.py
   pypy/trunk/pypy/rpython/lltypesystem/rclass.py
   pypy/trunk/pypy/rpython/lltypesystem/rdict.py
   pypy/trunk/pypy/rpython/lltypesystem/rpbc.py
   pypy/trunk/pypy/rpython/ootypesystem/rpbc.py
   pypy/trunk/pypy/rpython/rpbc.py
Log:
a small improvement in the annotator: use a real set instead of a dict for
descriptions. not a big thing, but makes a few lines nicer.


Modified: pypy/trunk/pypy/annotation/annrpython.py
==============================================================================
--- pypy/trunk/pypy/annotation/annrpython.py	(original)
+++ pypy/trunk/pypy/annotation/annrpython.py	Thu Dec  2 16:01:39 2010
@@ -145,7 +145,7 @@
         classdef.add_source_for_attribute(attr, classdef.classdesc)
         self.bookkeeper
         assert isinstance(s_result, annmodel.SomePBC)
-        olddesc = s_result.descriptions.iterkeys().next()
+        olddesc = s_result.any_description()
         desc = olddesc.bind_self(classdef)
         args = self.bookkeeper.build_args("simple_call", args_s[:])
         desc.consider_call_site(self.bookkeeper, desc.getcallfamily(), [desc],

Modified: pypy/trunk/pypy/annotation/bookkeeper.py
==============================================================================
--- pypy/trunk/pypy/annotation/bookkeeper.py	(original)
+++ pypy/trunk/pypy/annotation/bookkeeper.py	Thu Dec  2 16:01:39 2010
@@ -262,7 +262,7 @@
                                             args_s, s_result)
 
     def consider_call_site_for_pbc(self, s_callable, opname, args_s, s_result):
-        descs = s_callable.descriptions.keys()
+        descs = list(s_callable.descriptions)
         if not descs:
             return
         family = descs[0].getcallfamily()
@@ -590,7 +590,7 @@
         assert s_attr.is_constant()
         attr = s_attr.const
 
-        descs = pbc.descriptions.keys()
+        descs = list(pbc.descriptions)
         if not descs:
             return s_ImpossibleValue
 
@@ -633,7 +633,7 @@
         """Analyse a call to a SomePBC() with the given args (list of
         annotations).
         """
-        descs = pbc.descriptions.keys()
+        descs = list(pbc.descriptions)
         if not descs:
             return s_ImpossibleValue
         first = descs[0]

Modified: pypy/trunk/pypy/annotation/description.py
==============================================================================
--- pypy/trunk/pypy/annotation/description.py	(original)
+++ pypy/trunk/pypy/annotation/description.py	Thu Dec  2 16:01:39 2010
@@ -672,7 +672,7 @@
             if isinstance(s_init, SomePBC):
                 assert len(s_init.descriptions) == 1, (
                     "unexpected dynamic __init__?")
-                initfuncdesc = s_init.descriptions.keys()[0]
+                initfuncdesc, = s_init.descriptions
                 if isinstance(initfuncdesc, FunctionDesc):
                     initmethdesc = bookkeeper.getmethoddesc(initfuncdesc,
                                                             classdef,
@@ -800,8 +800,8 @@
                                                         desc.selfclassdef,
                                                         desc.name,
                                                         commonflags)
-                del descs[desc]
-                descs[newdesc] = None
+                descs.remove(desc)
+                descs.add(newdesc)
 
         # --- case 1 ---
         groups = {}
@@ -816,7 +816,7 @@
                     for desc2 in group:
                         cdef2 = desc2.selfclassdef
                         if cdef1 is not cdef2 and cdef1.issubclass(cdef2):
-                            del descs[desc1]
+                            descs.remove(desc1)
                             break
     simplify_desc_set = staticmethod(simplify_desc_set)
 

Modified: pypy/trunk/pypy/annotation/model.py
==============================================================================
--- pypy/trunk/pypy/annotation/model.py	(original)
+++ pypy/trunk/pypy/annotation/model.py	Thu Dec  2 16:01:39 2010
@@ -356,8 +356,8 @@
     immutable = True
 
     def __init__(self, descriptions, can_be_None=False, subset_of=None):
-        # descriptions is a set of Desc instances.
-        descriptions = dict.fromkeys(descriptions)
+        # descriptions is a set of Desc instances
+        descriptions = set(descriptions)
         self.descriptions = descriptions
         self.can_be_None = can_be_None
         self.subset_of = subset_of
@@ -379,6 +379,9 @@
                 if desc.pyobj is not None:
                     self.const = desc.pyobj
 
+    def any_description(self):
+        return iter(self.descriptions).next()
+
     def getKind(self):
         "Return the common Desc class of all descriptions in this PBC."
         kinds = {}

Modified: pypy/trunk/pypy/annotation/specialize.py
==============================================================================
--- pypy/trunk/pypy/annotation/specialize.py	(original)
+++ pypy/trunk/pypy/annotation/specialize.py	Thu Dec  2 16:01:39 2010
@@ -345,7 +345,8 @@
             key.append(s.const)
         elif isinstance(s, SomePBC) and len(s.descriptions) == 1:
             # for test_specialize_arg_bound_method
-            key.append(s.descriptions.keys()[0])
+            desc, = s.descriptions
+            key.append(desc)
         else:
             raise Exception("specialize:arg(%d): argument not constant: %r"
                             % (i, s))

Modified: pypy/trunk/pypy/annotation/test/test_annrpython.py
==============================================================================
--- pypy/trunk/pypy/annotation/test/test_annrpython.py	(original)
+++ pypy/trunk/pypy/annotation/test/test_annrpython.py	Thu Dec  2 16:01:39 2010
@@ -1010,7 +1010,7 @@
         bookkeeper = a.bookkeeper
 
         def getmdesc(bmeth):
-            return bookkeeper.immutablevalue(bmeth).descriptions.keys()[0]
+            return bookkeeper.immutablevalue(bmeth).any_description()
 
         mdescA_m = getmdesc(A().m)
         mdescC_m = getmdesc(C().m)
@@ -2862,7 +2862,7 @@
         assert s.items[0].flags == {'access_directly': True}
         assert isinstance(s.items[1], annmodel.SomePBC)
         assert len(s.items[1].descriptions) == 1
-        assert s.items[1].descriptions.keys()[0].flags == {'access_directly':
+        assert s.items[1].any_description().flags == {'access_directly':
                                                            True}
         assert isinstance(s.items[2], annmodel.SomeInstance)
         assert s.items[2].flags == {'access_directly': True}

Modified: pypy/trunk/pypy/rpython/lltypesystem/rbuiltin.py
==============================================================================
--- pypy/trunk/pypy/rpython/lltypesystem/rbuiltin.py	(original)
+++ pypy/trunk/pypy/rpython/lltypesystem/rbuiltin.py	Thu Dec  2 16:01:39 2010
@@ -42,7 +42,7 @@
         return hop.genop('cast_pointer', [v_inst],    # v_type implicit in r_result
                          resulttype = hop.r_result.lowleveltype)
 
-    classdef = s_class.descriptions.keys()[0].getuniqueclassdef()
+    classdef = s_class.any_description().getuniqueclassdef()
     return rclass.rtype_new_instance(hop.rtyper, classdef, hop.llops)
 
 def rtype_builtin_hasattr(hop):

Modified: pypy/trunk/pypy/rpython/lltypesystem/rclass.py
==============================================================================
--- pypy/trunk/pypy/rpython/lltypesystem/rclass.py	(original)
+++ pypy/trunk/pypy/rpython/lltypesystem/rclass.py	Thu Dec  2 16:01:39 2010
@@ -392,7 +392,7 @@
                 source_classdef = source_desc.getclassdef(None)
                 source_repr = getinstancerepr(self.rtyper, source_classdef)
                 assert len(s_func.descriptions) == 1
-                funcdesc = s_func.descriptions.keys()[0]
+                funcdesc, = s_func.descriptions
                 graph = funcdesc.getuniquegraph()
                 FUNCTYPE = FuncType([Ptr(source_repr.object_type)], Void)
                 destrptr = functionptr(FUNCTYPE, graph.name,

Modified: pypy/trunk/pypy/rpython/lltypesystem/rdict.py
==============================================================================
--- pypy/trunk/pypy/rpython/lltypesystem/rdict.py	(original)
+++ pypy/trunk/pypy/rpython/lltypesystem/rdict.py	Thu Dec  2 16:01:39 2010
@@ -581,7 +581,7 @@
 def ll_dict_lookup_clean(d, hash):
     # a simplified version of ll_dict_lookup() which assumes that the
     # key is new, and the dictionary doesn't contain deleted entries.
-    # It only find the next free slot for the given hash.
+    # It only finds the next free slot for the given hash.
     entries = d.entries
     mask = len(entries) - 1
     i = hash & mask

Modified: pypy/trunk/pypy/rpython/lltypesystem/rpbc.py
==============================================================================
--- pypy/trunk/pypy/rpython/lltypesystem/rpbc.py	(original)
+++ pypy/trunk/pypy/rpython/lltypesystem/rpbc.py	Thu Dec  2 16:01:39 2010
@@ -127,7 +127,7 @@
     def __init__(self, rtyper, s_pbc):
         self.rtyper = rtyper
         self.s_pbc = s_pbc
-        self.callfamily = s_pbc.descriptions.iterkeys().next().getcallfamily()
+        self.callfamily = s_pbc.any_description().getcallfamily()
         concretetable, uniquerows = get_concrete_calltable(self.rtyper,
                                                            self.callfamily)
         assert len(uniquerows) == 1
@@ -166,7 +166,7 @@
         return self, 0
 
     def get_s_signatures(self, shape):
-        funcdesc = self.s_pbc.descriptions.iterkeys().next()
+        funcdesc = self.s_pbc.any_description()
         return funcdesc.get_s_signatures(shape)
 
     def convert_desc(self, funcdesc):
@@ -230,7 +230,7 @@
         bk = self.rtyper.annotator.bookkeeper
         args = bk.build_args(opname, hop.args_s[1:])
         s_pbc = hop.args_s[0]   # possibly more precise than self.s_pbc
-        descs = s_pbc.descriptions.keys()
+        descs = list(s_pbc.descriptions)
         shape, index = description.FunctionDesc.variant_for_call_site(bk, self.callfamily, descs, args)
         row_of_graphs = self.callfamily.calltables[shape][index]
         anygraph = row_of_graphs.itervalues().next()  # pick any witness

Modified: pypy/trunk/pypy/rpython/ootypesystem/rpbc.py
==============================================================================
--- pypy/trunk/pypy/rpython/ootypesystem/rpbc.py	(original)
+++ pypy/trunk/pypy/rpython/ootypesystem/rpbc.py	Thu Dec  2 16:01:39 2010
@@ -49,7 +49,7 @@
         return hop.genop('runtimenew', [v_class], resulttype=resulttype)
 
     def getlowleveltype(self):
-        classdescs = self.s_pbc.descriptions.keys()
+        classdescs = list(self.s_pbc.descriptions)
         # if any of the classdefs get the lowleveltype ootype.Class,
         # we can only pick ootype.Class for us too.  Otherwise META.
         for classdesc in classdescs:
@@ -70,7 +70,7 @@
 class MethodImplementations(object):
 
     def __init__(self, rtyper, methdescs):
-        samplemdesc = methdescs.iterkeys().next()
+        samplemdesc = iter(methdescs).next()
         concretetable, uniquerows = get_concrete_calltable(rtyper,
                                              samplemdesc.funcdesc.getcallfamily())
         self.row_mapping = {}
@@ -117,7 +117,7 @@
     concretetable = None # set by _setup_repr_final
 
     def _setup_repr_final(self):
-        sampledesc = self.s_pbc.descriptions.iterkeys().next()
+        sampledesc = self.s_pbc.any_description()
         self.concretetable, _ = get_concrete_calltable(self.rtyper,
                                              sampledesc.funcdesc.getcallfamily())
 

Modified: pypy/trunk/pypy/rpython/rpbc.py
==============================================================================
--- pypy/trunk/pypy/rpython/rpbc.py	(original)
+++ pypy/trunk/pypy/rpython/rpbc.py	Thu Dec  2 16:01:39 2010
@@ -15,11 +15,10 @@
 
 from pypy.rpython import callparse
 
-
 def small_cand(rtyper, s_pbc):
     if 1 < len(s_pbc.descriptions) < rtyper.getconfig().translation.withsmallfuncsets and \
            hasattr(rtyper.type_system.rpbc, 'SmallFunctionSetPBCRepr'):
-        callfamily = s_pbc.descriptions.iterkeys().next().getcallfamily()
+        callfamily = s_pbc.any_description().getcallfamily()
         concretetable, uniquerows = get_concrete_calltable(rtyper, callfamily)
         if len(uniquerows) == 1 and (not s_pbc.subset_of or small_cand(rtyper, s_pbc.subset_of)):
             return True
@@ -31,7 +30,7 @@
             return none_frozen_pbc_repr 
         kind = self.getKind()
         if issubclass(kind, description.FunctionDesc):
-            sample = self.descriptions.keys()[0]
+            sample = self.any_description()
             callfamily = sample.querycallfamily()
             if callfamily and callfamily.total_calltable_size > 0:
                 if sample.overridden:
@@ -181,7 +180,7 @@
     def __init__(self, rtyper, s_pbc):
         self.rtyper = rtyper
         self.s_pbc = s_pbc
-        self.callfamily = s_pbc.descriptions.iterkeys().next().getcallfamily()
+        self.callfamily = s_pbc.any_description().getcallfamily()
         if len(s_pbc.descriptions) == 1 and not s_pbc.can_be_None:
             # a single function
             self.lowleveltype = Void
@@ -207,7 +206,7 @@
         return self, 0
 
     def get_s_signatures(self, shape):
-        funcdesc = self.s_pbc.descriptions.iterkeys().next()
+        funcdesc = self.s_pbc.any_description()
         return funcdesc.get_s_signatures(shape)
 
 ##    def function_signatures(self):
@@ -322,7 +321,7 @@
         bk = self.rtyper.annotator.bookkeeper
         args = bk.build_args(opname, hop.args_s[1:])
         s_pbc = hop.args_s[0]   # possibly more precise than self.s_pbc
-        descs = s_pbc.descriptions.keys()
+        descs = list(s_pbc.descriptions)
         shape, index = description.FunctionDesc.variant_for_call_site(bk, self.callfamily, descs, args)
         row_of_graphs = self.callfamily.calltables[shape][index]
         anygraph = row_of_graphs.itervalues().next()  # pick any witness
@@ -368,7 +367,7 @@
     return robject.pyobj_repr
 
 def getFrozenPBCRepr(rtyper, s_pbc):
-    descs = s_pbc.descriptions.keys()
+    descs = list(s_pbc.descriptions)
     assert len(descs) >= 1
     if len(descs) == 1 and not s_pbc.can_be_None:
         return SingleFrozenPBCRepr(descs[0])
@@ -530,7 +529,7 @@
 
     def __init__(self, rtyper, s_pbc):
         self.rtyper = rtyper
-        self.funcdesc = s_pbc.descriptions.keys()[0].funcdesc
+        self.funcdesc = s_pbc.any_description().funcdesc
 
         # a hack to force the underlying function to show up in call_families
         # (generally not needed, as normalizecalls() should ensure this,
@@ -662,7 +661,7 @@
         and the ClassRepr of the class which stores this attribute in
         its vtable.
         """
-        classdescs = self.s_pbc.descriptions.keys()
+        classdescs = list(self.s_pbc.descriptions)
         access = classdescs[0].queryattrfamily(attrname)
         for classdesc in classdescs[1:]:
             access1 = classdesc.queryattrfamily(attrname)
@@ -819,7 +818,7 @@
         if s_pbc.isNone():
             raise TyperError("unsupported: variable of type "
                              "bound-method-object or None")
-        mdescs = s_pbc.descriptions.keys()
+        mdescs = list(s_pbc.descriptions)
         methodname = mdescs[0].name
         classdef = mdescs[0].selfclassdef
         flags    = mdescs[0].flags



More information about the Pypy-commit mailing list