Amaury Forgeot d'Arc avatar Amaury Forgeot d'Arc committed a9fe088 Merge

hg merge default.
Some conflicts in translator/c/src.

Comments (0)

Files changed (331)

     libpath = ctypes.util.find_library('db')
     if not libpath:
         # XXX this is hopeless...
-        libpath = ctypes.util.find_library('db-4.5')
-        if not libpath:
+        for c in '56789':
+            libpath = ctypes.util.find_library('db-4.%s' % c)
+            if libpath:
+                break
+        else:
             raise ImportError("Cannot find dbm library")
     lib = CDLL(libpath) # Linux
     _platform = 'bdb'

py/_io/capture.py

 
 
 class StdCaptureFD(Capture):
-    """ This class allows to capture writes to FD1 and FD2
+    """ This class allows capturing writes to FD1 and FD2
         and may connect a NULL file to FD0 (and prevent
         reads from sys.stdin).  If any of the 0,1,2 file descriptors
         is invalid it will not be captured.
         return l
 
 class StdCapture(Capture):
-    """ This class allows to capture writes to sys.stdout|stderr "in-memory"
-        and will raise errors on tries to read from sys.stdin. It only
+    """ This class allows capturing writes to sys.stdout|stderr "in-memory"
+        and will raise errors on read attempts from sys.stdin. It only
         modifies sys.stdout|stderr|stdin attributes and does not
         touch underlying File Descriptors (use StdCaptureFD for that).
     """

pypy/annotation/annrpython.py

-import sys
 import types
-from pypy.tool.ansi_print import ansi_log, raise_nicer_exception
+from pypy.tool.ansi_print import ansi_log
 from pypy.tool.pairtype import pair
 from pypy.tool.error import (format_blocked_annotation_error,
-                             format_someobject_error, AnnotatorError)
+                             AnnotatorError, gather_error, ErrorWrapper)
 from pypy.objspace.flow.model import (Variable, Constant, FunctionGraph,
                                       c_last_exception, checkgraph)
 from pypy.translator import simplify, transform
         self.links_followed = {} # set of links that have ever been followed
         self.notify = {}        # {block: {positions-to-reflow-from-when-done}}
         self.fixed_graphs = {}  # set of graphs not to annotate again
-        self.blocked_blocks = {} # set of {blocked_block: graph}
-        # --- the following information is recorded for debugging only ---
-        # --- and only if annotation.model.DEBUG is kept to True
-        self.why_not_annotated = {} # {block: (exc_type, exc_value, traceback)}
-                                    # records the location of BlockedInference
-                                    # exceptions that blocked some blocks.
+        self.blocked_blocks = {} # set of {blocked_block: (graph, index)}
+        # --- the following information is recorded for debugging ---
         self.blocked_graphs = {} # set of graphs that have blocked blocks
-        self.bindingshistory = {}# map Variables to lists of SomeValues
-        self.binding_caused_by = {}     # map Variables to position_keys
-               # records the caller position that caused bindings of inputargs
-               # to be updated
-        self.binding_cause_history = {} # map Variables to lists of positions
-                # history of binding_caused_by, kept in sync with
-                # bindingshistory
-        self.reflowcounter = {}
-        self.return_bindings = {} # map return Variables to their graphs
         # --- end of debugging information ---
         self.frozen = False
         if policy is None:
                 ret[key] = {}
         return ret
 
-    def _register_returnvar(self, flowgraph):
-        if annmodel.DEBUG:
-            self.return_bindings[flowgraph.getreturnvar()] = flowgraph
-
     #___ convenience high-level interface __________________
 
     def build_types(self, function, input_arg_types, complete_now=True,
     #___ medium-level interface ____________________________
 
     def addpendinggraph(self, flowgraph, inputcells):
-        self._register_returnvar(flowgraph)
         self.addpendingblock(flowgraph, flowgraph.startblock, inputcells)
 
-    def addpendingblock(self, graph, block, cells, called_from_graph=None):
+    def addpendingblock(self, graph, block, cells):
         """Register an entry point into block with the given input cells."""
         if graph in self.fixed_graphs:
             # special case for annotating/rtyping in several phases: calling
             for a in cells:
                 assert isinstance(a, annmodel.SomeObject)
             if block not in self.annotated:
-                self.bindinputargs(graph, block, cells, called_from_graph)
+                self.bindinputargs(graph, block, cells)
             else:
-                self.mergeinputargs(graph, block, cells, called_from_graph)
+                self.mergeinputargs(graph, block, cells)
             if not self.annotated[block]:
                 self.pendingblocks[block] = graph
 
         while True:
             while self.pendingblocks:
                 block, graph = self.pendingblocks.popitem()
-                if annmodel.DEBUG:
-                    self.flowin_block = block # we need to keep track of block
                 self.processblock(graph, block)
             self.policy.no_more_blocks_to_annotate(self)
             if not self.pendingblocks:
     def typeannotation(self, t):
         return signature.annotation(t, self.bookkeeper)
 
-    def ondegenerated(self, what, s_value, where=None, called_from_graph=None):
-        if self.policy.allow_someobjects:
-            return
-        # is the function itself tagged with allow_someobjects?
-        position_key = where or getattr(self.bookkeeper, 'position_key', None)
-        if position_key is not None:
-            graph, block, i = position_key
-            try:
-                if graph.func.allow_someobjects:
-                    return
-            except AttributeError:
-                pass
-
-        msgstr = format_someobject_error(self, position_key, what, s_value,
-                                         called_from_graph,
-                                         self.bindings.get(what, "(none)"))
-
-        raise AnnotatorError(msgstr)
-
-    def setbinding(self, arg, s_value, called_from_graph=None, where=None):
+    def setbinding(self, arg, s_value):
         if arg in self.bindings:
             assert s_value.contains(self.bindings[arg])
-            # for debugging purposes, record the history of bindings that
-            # have been given to this variable
-            if annmodel.DEBUG:
-                history = self.bindingshistory.setdefault(arg, [])
-                history.append(self.bindings[arg])
-                cause_history = self.binding_cause_history.setdefault(arg, [])
-                cause_history.append(self.binding_caused_by[arg])
-
-        degenerated = annmodel.isdegenerated(s_value)
-
-        if degenerated:
-            self.ondegenerated(arg, s_value, where=where,
-                               called_from_graph=called_from_graph)
-
         self.bindings[arg] = s_value
-        if annmodel.DEBUG:
-            if arg in self.return_bindings:
-                log.event("%s -> %s" % 
-                    (self.whereami((self.return_bindings[arg], None, None)), 
-                     s_value)) 
-
-            if arg in self.return_bindings and degenerated:
-                self.warning("result degenerated to SomeObject",
-                             (self.return_bindings[arg],None, None))
-                
-            self.binding_caused_by[arg] = called_from_graph
 
     def transfer_binding(self, v_target, v_source):
         assert v_source in self.bindings
         self.bindings[v_target] = self.bindings[v_source]
-        if annmodel.DEBUG:
-            self.binding_caused_by[v_target] = None
 
     def warning(self, msg, pos=None):
         if pos is None:
 
     #___ interface for annotator.bookkeeper _______
 
-    def recursivecall(self, graph, whence, inputcells): # whence = position_key|callback taking the annotator, graph 
+    def recursivecall(self, graph, whence, inputcells):
         if isinstance(whence, tuple):
-            parent_graph, parent_block, parent_index = position_key = whence
+            parent_graph, parent_block, parent_index = whence
             tag = parent_block, parent_index
             self.translator.update_call_graph(parent_graph, graph, tag)
-        else:
-            position_key = None
-        self._register_returnvar(graph)
         # self.notify[graph.returnblock] is a dictionary of call
         # points to this func which triggers a reflow whenever the
         # return block of this graph has been analysed.
             callpositions[callback] = True
 
         # generalize the function's input arguments
-        self.addpendingblock(graph, graph.startblock, inputcells,
-                             position_key)
+        self.addpendingblock(graph, graph.startblock, inputcells)
 
         # get the (current) return value
         v = graph.getreturnvar()
         #      input variables).
 
         #print '* processblock', block, cells
-        if annmodel.DEBUG:
-            self.reflowcounter.setdefault(block, 0)
-            self.reflowcounter[block] += 1
         self.annotated[block] = graph
         if block in self.blocked_blocks:
             del self.blocked_blocks[block]
             self.flowin(graph, block)
         except BlockedInference, e:
             self.annotated[block] = False   # failed, hopefully temporarily
-            self.blocked_blocks[block] = graph
+            self.blocked_blocks[block] = (graph, e.opindex)
         except Exception, e:
             # hack for debug tools only
             if not hasattr(e, '__annotator_block'):
         self.pendingblocks[block] = graph
         assert block in self.annotated
         self.annotated[block] = False  # must re-flow
-        self.blocked_blocks[block] = graph
+        self.blocked_blocks[block] = (graph, None)
 
-    def bindinputargs(self, graph, block, inputcells, called_from_graph=None):
+    def bindinputargs(self, graph, block, inputcells):
         # Create the initial bindings for the input args of a block.
         assert len(block.inputargs) == len(inputcells)
-        where = (graph, block, None)
         for a, cell in zip(block.inputargs, inputcells):
-            self.setbinding(a, cell, called_from_graph, where=where)
+            self.setbinding(a, cell)
         self.annotated[block] = False  # must flowin.
-        self.blocked_blocks[block] = graph
+        self.blocked_blocks[block] = (graph, None)
 
-    def mergeinputargs(self, graph, block, inputcells, called_from_graph=None):
+    def mergeinputargs(self, graph, block, inputcells):
         # Merge the new 'cells' with each of the block's existing input
         # variables.
         oldcells = [self.binding(a) for a in block.inputargs]
         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(graph, block, unions, called_from_graph)
+            self.bindinputargs(graph, block, unions)
 
     def whereami(self, position_key):
         graph, block, i = position_key
             for i in range(len(block.operations)):
                 try:
                     self.bookkeeper.enter((graph, block, i))
-                    self.consider_op(block.operations[i])
+                    self.consider_op(block, i)
                 finally:
                     self.bookkeeper.leave()
 
         except BlockedInference, e:
-            if annmodel.DEBUG:
-                self.why_not_annotated[block] = sys.exc_info()
-
             if (e.op is block.operations[-1] and
                 block.exitswitch == c_last_exception):
                 # this is the case where the last operation of the block will
                    and issubclass(link.exitcase, py.builtin.BaseException):
                 assert last_exception_var and last_exc_value_var
                 last_exc_value_object = self.bookkeeper.valueoftype(link.exitcase)
-                last_exception_object = annmodel.SomeObject()
-                last_exception_object.knowntype = type
+                last_exception_object = annmodel.SomeType()
                 if isinstance(last_exception_var, Constant):
                     last_exception_object.const = last_exception_var.value
                 last_exception_object.is_type_of = [last_exc_value_var]
                 if isinstance(last_exc_value_var, Variable):
                     self.setbinding(last_exc_value_var, last_exc_value_object)
 
-                last_exception_object = annmodel.SomeObject()
-                last_exception_object.knowntype = type
+                last_exception_object = annmodel.SomeType()
                 if isinstance(last_exception_var, Constant):
                     last_exception_object.const = last_exception_var.value
                 #if link.exitcase is Exception:
                         for v in cell.is_type_of:
                             new_vs = renaming.get(v,[])
                             renamed_is_type_of += new_vs
-                        newcell = annmodel.SomeObject()
-                        if cell.knowntype == type:
-                            newcell.knowntype = type
+                        assert cell.knowntype is type
+                        newcell = annmodel.SomeType()
                         if cell.is_constant():
                             newcell.const = cell.const
                         cell = newcell
 
     #___ creating the annotations based on operations ______
 
-    def consider_op(self, op):
+    def consider_op(self, block, opindex):
+        op = block.operations[opindex]
         argcells = [self.binding(a) for a in op.args]
         consider_meth = getattr(self,'consider_op_'+op.opname,
                                 None)
         # boom -- in the assert of setbinding()
         for arg in argcells:
             if isinstance(arg, annmodel.SomeImpossibleValue):
-                raise BlockedInference(self, op)
+                raise BlockedInference(self, op, opindex)
         try:
             resultcell = consider_meth(*argcells)
-        except Exception:
+        except Exception, e:
             graph = self.bookkeeper.position_key[0]
-            raise_nicer_exception(op, str(graph))
+            e.args = e.args + (
+                ErrorWrapper(gather_error(self, graph, block, opindex)),)
+            raise
         if resultcell is None:
             resultcell = self.noreturnvalue(op)
         elif resultcell == annmodel.s_ImpossibleValue:
-            raise BlockedInference(self, op) # the operation cannot succeed
+            raise BlockedInference(self, op, opindex) # the operation cannot succeed
         assert isinstance(resultcell, annmodel.SomeObject)
         assert isinstance(op.result, Variable)
         self.setbinding(op.result, resultcell)  # bind resultcell to op.result
     """This exception signals the type inference engine that the situation
     is currently blocked, and that it should try to progress elsewhere."""
 
-    def __init__(self, annotator, op):
+    def __init__(self, annotator, op, opindex):
         self.annotator = annotator
         try:
             self.break_at = annotator.bookkeeper.position_key
         except AttributeError:
             self.break_at = None
         self.op = op
+        self.opindex = opindex
 
     def __repr__(self):
         if not self.break_at:

pypy/annotation/binaryop.py

 from pypy.annotation.model import SomePBC, SomeFloat, s_None
 from pypy.annotation.model import SomeExternalObject, SomeWeakRef
 from pypy.annotation.model import SomeAddress, SomeTypedAddressAccess
-from pypy.annotation.model import SomeSingleFloat, SomeLongFloat
+from pypy.annotation.model import SomeSingleFloat, SomeLongFloat, SomeType
 from pypy.annotation.model import unionof, UnionError, missing_operation
-from pypy.annotation.model import isdegenerated, TLS
+from pypy.annotation.model import TLS
 from pypy.annotation.model import read_can_only_throw
 from pypy.annotation.model import add_knowntypedata, merge_knowntypedata
 from pypy.annotation.model import SomeGenericCallable
 def immutablevalue(x):
     return getbookkeeper().immutablevalue(x)
 
-def unioncheck(*somevalues):
-    s_value = unionof(*somevalues)
-    if isdegenerated(s_value):
-        if not getattr(TLS, 'no_side_effects_in_union', 0):
-            bookkeeper = getbookkeeper()
-            if bookkeeper is not None:
-                bookkeeper.ondegenerated('union', s_value)
-    return s_value
-
 # XXX unify this with ObjSpace.MethodTable
 BINARY_OPERATIONS = set(['add', 'sub', 'mul', 'div', 'mod',
                          'truediv', 'floordiv', 'divmod', 'pow',
 class __extend__(pairtype(SomeObject, SomeObject)):
 
     def union((obj1, obj2)):
-        if obj1 == obj2:
-            return obj1
-        else:
-            result = SomeObject()
-            if obj1.knowntype == obj2.knowntype and obj1.knowntype != object:
-                result.knowntype = obj1.knowntype
-            is_type_of1 = getattr(obj1, 'is_type_of', None)
-            is_type_of2 = getattr(obj2, 'is_type_of', None)
-            if obj1.is_immutable_constant() and obj2.is_immutable_constant() and obj1.const == obj2.const:
-                result.const = obj1.const
-                is_type_of = {}
-                if is_type_of1:
-                    for v in is_type_of1:
-                        is_type_of[v] = True
-                if is_type_of2:
-                    for v in is_type_of2:
-                        is_type_of[v] = True
-                if is_type_of:
-                    result.is_type_of = is_type_of.keys()
-            else:
-                if is_type_of1 and is_type_of1 == is_type_of2:
-                    result.is_type_of = is_type_of1
-            # try to preserve the origin of SomeObjects
-            if obj1 == result:
-                result = obj1
-            elif obj2 == result:
-                result = obj2
-            unioncheck(result)
-            return result
+        raise UnionError(obj1, obj2)
 
     # inplace_xxx ---> xxx by default
     def inplace_add((obj1, obj2)):      return pair(obj1, obj2).add()
 
     getitem_idx = getitem_idx_key
     getitem_key = getitem_idx_key
-        
+
+
+class __extend__(pairtype(SomeType, SomeType)):
+
+    def union((obj1, obj2)):
+        result = SomeType()
+        is_type_of1 = getattr(obj1, 'is_type_of', None)
+        is_type_of2 = getattr(obj2, 'is_type_of', None)
+        if obj1.is_immutable_constant() and obj2.is_immutable_constant() and obj1.const == obj2.const:
+            result.const = obj1.const
+            is_type_of = {}
+            if is_type_of1:
+                for v in is_type_of1:
+                    is_type_of[v] = True
+            if is_type_of2:
+                for v in is_type_of2:
+                    is_type_of[v] = True
+            if is_type_of:
+                result.is_type_of = is_type_of.keys()
+        else:
+            if is_type_of1 and is_type_of1 == is_type_of2:
+                result.is_type_of = is_type_of1
+        return result
+
 
 # cloning a function with identical code, for the can_only_throw attribute
 def _clone(f, can_only_throw = None):
 
     def union((tup1, tup2)):
         if len(tup1.items) != len(tup2.items):
-            return SomeObject()
+            raise UnionError("cannot take the union of a tuple of length %d "
+                             "and a tuple of length %d" % (len(tup1.items),
+                                                           len(tup2.items)))
         else:
-            unions = [unioncheck(x,y) for x,y in zip(tup1.items, tup2.items)]
+            unions = [unionof(x,y) for x,y in zip(tup1.items, tup2.items)]
             return SomeTuple(items = unions)
 
     def add((tup1, tup2)):
         return SomeTuple(items = tup1.items + tup2.items)
 
+    def eq(tup1tup2):
+        tup1tup2.union()
+        return s_Bool
+    ne = eq
+
+    def lt((tup1, tup2)):
+        raise Exception("unsupported: (...) < (...)")
+    def le((tup1, tup2)):
+        raise Exception("unsupported: (...) <= (...)")
+    def gt((tup1, tup2)):
+        raise Exception("unsupported: (...) > (...)")
+    def ge((tup1, tup2)):
+        raise Exception("unsupported: (...) >= (...)")
+
 
 class __extend__(pairtype(SomeDict, SomeDict)):
 
         else:
             basedef = ins1.classdef.commonbase(ins2.classdef)
             if basedef is None:
-                # print warning?
-                return SomeObject()
+                raise UnionError(ins1, ins2)
         flags = ins1.flags
         if flags:
             flags = flags.copy()
 class __extend__(pairtype(SomeIterator, SomeIterator)):
 
     def union((iter1, iter2)):
-        s_cont = unioncheck(iter1.s_container, iter2.s_container)
+        s_cont = unionof(iter1.s_container, iter2.s_container)
         if iter1.variant != iter2.variant:
             raise UnionError("merging incompatible iterators variants")
         return SomeIterator(s_cont, *iter1.variant)
             bltn1.s_self is None or bltn2.s_self is None):
             raise UnionError("cannot merge two different builtin functions "
                              "or methods:\n  %r\n  %r" % (bltn1, bltn2))
-        s_self = unioncheck(bltn1.s_self, bltn2.s_self)
+        s_self = unionof(bltn1.s_self, bltn2.s_self)
         return SomeBuiltin(bltn1.analyser, s_self, methodname=bltn1.methodname)
 
 class __extend__(pairtype(SomePBC, SomePBC)):
             unique_key = desc
             bk = desc.bookkeeper
             s_result = bk.emulate_pbc_call(unique_key, pbc, gencall.args_s)
-            s_result = unioncheck(s_result, gencall.s_result)
+            s_result = unionof(s_result, gencall.s_result)
             assert gencall.s_result.contains(s_result)
         return gencall
 

pypy/annotation/bookkeeper.py

      SomeUnicodeCodePoint, SomeOOStaticMeth, s_None, s_ImpossibleValue, \
      SomeLLADTMeth, SomeBool, SomeTuple, SomeOOClass, SomeImpossibleValue, \
      SomeUnicodeString, SomeList, SomeObject, HarmlesslyBlocked, \
-     SomeWeakRef, lltype_to_annotation
+     SomeWeakRef, lltype_to_annotation, SomeType
 from pypy.annotation.classdef import InstanceSource, ClassDef
 from pypy.annotation.listdef import ListDef, ListItem
 from pypy.annotation.dictdef import DictDef
         self.descs = {}          # map Python objects to their XxxDesc wrappers
         self.methoddescs = {}    # map (funcdesc, classdef) to the MethodDesc
         self.classdefs = []      # list of all ClassDefs
-        self.pbctypes = {}
         self.seen_mutable = {}
         self.listdefs = {}       # map position_keys to ListDefs
         self.dictdefs = {}       # map position_keys to DictDefs
 
         self.stats = Stats(self)
 
-        # used in SomeObject.__new__ for keeping debugging info
-        self._isomeobject_coming_from = identity_dict()
-
         delayed_imports()
 
     def count(self, category, *args):
         """Get the ClassDef associated with the given user cls.
         Avoid using this!  It breaks for classes that must be specialized.
         """
-        if cls is object:
-            return None
+        assert cls is not object
         desc = self.getdesc(cls)
         return desc.getuniqueclassdef()
 
         if hasattr(x, 'im_self') and x.im_self is None:
             x = x.im_func
             assert not hasattr(x, 'im_self')
-        if x is sys: # special case constant sys to someobject
-            return SomeObject()
         tp = type(x)
         if issubclass(tp, Symbolic): # symbolic constants support
             result = x.annotation()
             result = SomeOOInstance(ootype.typeOf(x))
         elif isinstance(x, (ootype._object)):
             result = SomeOOObject()
+        elif tp is type:
+            if (x is type(None) or      # add cases here if needed
+                x.__module__ == 'pypy.rpython.lltypesystem.lltype'):
+                result = SomeType()
+            else:
+                result = SomePBC([self.getdesc(x)])
         elif callable(x):
             if hasattr(x, 'im_self') and hasattr(x, 'im_func'):
                 # on top of PyPy, for cases like 'l.append' where 'l' is a
                 # for cases like 'l.append' where 'l' is a global constant list
                 s_self = self.immutablevalue(x.__self__, need_const)
                 result = s_self.find_method(x.__name__)
-                if result is None:
-                    result = SomeObject()
+                assert result is not None
             else:
                 result = None
             if result is None:
-                if (self.annotator.policy.allow_someobjects
-                    and getattr(x, '__module__', None) == '__builtin__'
-                    # XXX note that the print support functions are __builtin__
-                    and tp not in (types.FunctionType, types.MethodType)):
-                    result = SomeObject()
-                    result.knowntype = tp # at least for types this needs to be correct
-                else:
-                    result = SomePBC([self.getdesc(x)])
-        elif hasattr(x, '_freeze_') and x._freeze_():
+                result = SomePBC([self.getdesc(x)])
+        elif hasattr(x, '_freeze_'):
+            assert x._freeze_() is True
             # user-defined classes can define a method _freeze_(), which
             # is called when a prebuilt instance is found.  If the method
             # returns True, the instance is considered immutable and becomes
             result = SomePBC([self.getdesc(x)])
         elif hasattr(x, '__class__') \
                  and x.__class__.__module__ != '__builtin__':
+            if hasattr(x, '_cleanup_'):
+                x._cleanup_()
             self.see_mutable(x)
             result = SomeInstance(self.getuniqueclassdef(x.__class__))
         elif x is None:
             return s_None
         else:
-            result = SomeObject()
+            raise Exception("Don't know how to represent %r" % (x,))
         if need_const:
             result.const = x
         return result
-    
+
     def getdesc(self, pyobj):
         # get the XxxDesc wrapper for the given Python object, which must be
         # one of:
             elif isinstance(pyobj, types.MethodType):
                 if pyobj.im_self is None:   # unbound
                     return self.getdesc(pyobj.im_func)
-                elif (hasattr(pyobj.im_self, '_freeze_') and
-                      pyobj.im_self._freeze_()):  # method of frozen
+                if hasattr(pyobj.im_self, '_cleanup_'):
+                    pyobj.im_self._cleanup_()
+                if hasattr(pyobj.im_self, '_freeze_'):  # method of frozen
+                    assert pyobj.im_self._freeze_() is True
                     result = description.MethodOfFrozenDesc(self,
                         self.getdesc(pyobj.im_func),            # funcdesc
                         self.getdesc(pyobj.im_self))            # frozendesc
                         name)
             else:
                 # must be a frozen pre-built constant, but let's check
-                try:
-                    assert pyobj._freeze_()
-                except AttributeError:
+                if hasattr(pyobj, '_freeze_'):
+                    assert pyobj._freeze_() is True
+                else:
                     if hasattr(pyobj, '__call__'):
                         msg = "object with a __call__ is not RPython"
                     else:
             return False
         
     def getfrozen(self, pyobj):
-        result = description.FrozenDesc(self, pyobj)
-        cls = result.knowntype
-        if cls not in self.pbctypes:
-            self.pbctypes[cls] = True
-        return result
+        return description.FrozenDesc(self, pyobj)
 
     def getmethoddesc(self, funcdesc, originclassdef, selfclassdef, name,
                       flags={}):

pypy/annotation/builtin.py

 
 
 def builtin_isinstance(s_obj, s_type, variables=None):
-    r = SomeBool() 
+    r = SomeBool()
     if s_type.is_constant():
         typ = s_type.const
         if issubclass(typ, pypy.rlib.rarithmetic.base_int):
         else:
             if typ == long:
                 getbookkeeper().warning("isinstance(., long) is not RPython")
-                if s_obj.is_constant():
-                    r.const = isinstance(s_obj.const, long)
-                else:
-                    if type(s_obj) is not SomeObject: # only SomeObjects could be longs
-                        # type(s_obj) < SomeObject -> SomeBool(False)
-                        # type(s_obj) == SomeObject -> SomeBool()
-                        r.const = False
+                r.const = False
                 return r
-                
+
             assert not issubclass(typ, (int, long)) or typ in (bool, int, long), (
                 "for integers only isinstance(.,int|r_uint) are supported")
- 
+
             if s_obj.is_constant():
                 r.const = isinstance(s_obj.const, typ)
             elif our_issubclass(s_obj.knowntype, typ):
         for variable in variables:
             assert bk.annotator.binding(variable) == s_obj
         r.knowntypedata = {}
-        if (not isinstance(s_type, SomeBuiltin)
-            or typ.__module__ == '__builtin__'):
+        
+        if not hasattr(typ, '_freeze_') and isinstance(s_type, SomePBC):
             add_knowntypedata(r.knowntypedata, True, variables, bk.valueoftype(typ))
     return r
 

pypy/annotation/classdef.py

 Type inference for user-defined classes.
 """
 from pypy.annotation.model import SomePBC, s_ImpossibleValue, unionof
-from pypy.annotation.model import SomeInteger, isdegenerated, SomeTuple,\
-     SomeString
+from pypy.annotation.model import SomeInteger, SomeTuple, SomeString
 from pypy.annotation import description
 
 
         if source.instance_level:
             # a prebuilt instance source forces readonly=False, see above
             self.modified(classdef)
-        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)
-                
+        s_new_value = unionof(self.s_value, s_value)    # XXX "source %r attr %s" % (source, self.name),
         self.s_value = s_new_value
 
     def getvalue(self):
 
     def merge(self, other, classdef='?'):
         assert self.name == other.name
-        s_new_value = unionof(self.s_value, other.s_value)
-        if isdegenerated(s_new_value):
-            what = "%s attr %s" % (classdef, self.name)
-            self.bookkeeper.ondegenerated(what, s_new_value)
-
+        s_new_value = unionof(self.s_value, other.s_value)  # XXX "%s attr %s" % (classdef, self.name)
         self.s_value = s_new_value
         if not other.readonly:
             self.modified(classdef)

pypy/annotation/description.py

         defs_s = []
         if graph is None:
             signature = self.signature
-            defaults  = self.defaults
+            defaults = self.defaults
         else:
             signature = graph.signature
-            defaults  = graph.defaults
+            defaults = graph.defaults
         if defaults:
             for x in defaults:
-                defs_s.append(self.bookkeeper.immutablevalue(x))
+                if x is NODEFAULT:
+                    defs_s.append(None)
+                else:
+                    defs_s.append(self.bookkeeper.immutablevalue(x))
         try:
             inputcells = args.match_signature(signature, defs_s)
         except ArgErr, e:

pypy/annotation/dictdef.py

                 self.dictvalue is other.dictvalue)
 
     def union(self, other):
-        if (self.same_as(MOST_GENERAL_DICTDEF) or
-            other.same_as(MOST_GENERAL_DICTDEF)):
-            return MOST_GENERAL_DICTDEF   # without merging
-        else:
-            self.dictkey.merge(other.dictkey)
-            self.dictvalue.merge(other.dictvalue)
-            return self
+        self.dictkey.merge(other.dictkey)
+        self.dictvalue.merge(other.dictvalue)
+        return self
 
     def generalize_key(self, s_key):
         self.dictkey.generalize(s_key)
 
     def __repr__(self):
         return '<{%r: %r}>' % (self.dictkey.s_value, self.dictvalue.s_value)
-
-
-MOST_GENERAL_DICTDEF = DictDef(None, SomeObject(), SomeObject())

pypy/annotation/listdef.py

 from pypy.annotation.model import SomeObject, s_ImpossibleValue
 from pypy.annotation.model import SomeList, SomeString
-from pypy.annotation.model import unionof, TLS, UnionError, isdegenerated
+from pypy.annotation.model import unionof, TLS, UnionError
 
 
 class TooLateForChange(Exception):
             if s_new_value != s_value:
                 if self.dont_change_any_more:
                     raise TooLateForChange
-            if isdegenerated(s_new_value):
-                if self.bookkeeper:
-                    self.bookkeeper.ondegenerated(self, s_new_value)
-                elif other.bookkeeper:
-                    other.bookkeeper.ondegenerated(other, s_new_value)
             self.patch()    # which should patch all refs to 'other'
             if s_new_value != s_value:
                 self.s_value = s_new_value
 
     def generalize(self, s_other_value):
         s_new_value = unionof(self.s_value, s_other_value)
-        if isdegenerated(s_new_value) and self.bookkeeper:
-            self.bookkeeper.ondegenerated(self, s_new_value)        
         updated = s_new_value != self.s_value
         if updated:
             if self.dont_change_any_more:
         return self.listitem is other.listitem
 
     def union(self, other):
-        if (self.same_as(MOST_GENERAL_LISTDEF) or
-            other.same_as(MOST_GENERAL_LISTDEF)):
-            return MOST_GENERAL_LISTDEF   # without merging
-        else:
-            self.listitem.merge(other.listitem)
-            return self
+        self.listitem.merge(other.listitem)
+        return self
 
     def agree(self, other):
         s_self_value = self.read_item()
         #else: it's fine, don't set immutable=True at all (see
         #      test_can_merge_immutable_list_with_regular_list)
 
-MOST_GENERAL_LISTDEF = ListDef(None, SomeObject())
-
 s_list_of_strings = SomeList(ListDef(None, SomeString(no_nul=True),
                                      resized = True))

pypy/annotation/model.py

 from pypy.rlib.rarithmetic import r_singlefloat, r_longfloat
 import inspect, weakref
 
-DEBUG = False    # set to False to disable recording of debugging information
-
 class State(object):
     # A global attribute :-(  Patch it with 'True' to enable checking of
     # the no_nul attribute...
     """The set of all objects.  Each instance stands
     for an arbitrary object about which nothing is known."""
     __metaclass__ = extendabletype
+    immutable = False
     knowntype = object
-    immutable = False
+
+    def __init__(self):
+        assert type(self) is not SomeObject
 
     def __eq__(self, other):
         return (self.__class__ is other.__class__ and
         return self.immutable and 'const' in self.__dict__
 
     # delegate accesses to 'const' to accesses to 'const_box.value',
-    # where const_box is a Constant.  XXX the idea is to eventually
-    # use systematically 'const_box' instead of 'const' for
-    # non-immutable constant annotations
+    # where const_box is a Constant.  This is not a property, in order
+    # to allow 'self.const = xyz' to work as well.
     class ConstAccessDelegator(object):
         def __get__(self, obj, cls=None):
             return obj.const_box.value
     const = ConstAccessDelegator()
     del ConstAccessDelegator
 
-    # for debugging, record where each instance comes from
-    # this is disabled if DEBUG is set to False
-    def __new__(cls, *args, **kw):
-        new = super(SomeObject, cls).__new__
-        if new is object.__new__:
-            # Since python 2.6, object.__new__ warns
-            # when parameters are passed
-            self = new(cls)
-        else:
-            self = new(cls, *args, **kw)
-        if DEBUG:
-            try:
-                bookkeeper = pypy.annotation.bookkeeper.getbookkeeper()
-                position_key = bookkeeper.position_key
-            except AttributeError:
-                pass
-            else:
-                bookkeeper._isomeobject_coming_from[self] = position_key, None
+    def can_be_none(self):
+        return True
+
+    def nonnoneify(self):
         return self
 
-    def origin(self):
-        bookkeeper = pypy.annotation.bookkeeper.getbookkeeper()
-        if bookkeeper is None:
-            return None
-        return bookkeeper._isomeobject_coming_from.get(self, (None, None))[0]
-    origin = property(origin)
 
-    def caused_by_merge(self):
-        bookkeeper = pypy.annotation.bookkeeper.getbookkeeper()
-        if bookkeeper is None:
-            return None
-        return bookkeeper._isomeobject_coming_from.get(self, (None, None))[1]
-    def set_caused_by_merge(self, nvalue):
-        bookkeeper = pypy.annotation.bookkeeper.getbookkeeper()
-        if bookkeeper is None:
-            return
-        bookkeeper._isomeobject_coming_from[self] = self.origin, nvalue
-    caused_by_merge = property(caused_by_merge, set_caused_by_merge)
-    del set_caused_by_merge
+class SomeType(SomeObject):
+    "Stands for a type.  We might not be sure which one it is."
+    knowntype = type
+    immutable = True
 
     def can_be_none(self):
-        return True
-        
-    def nonnoneify(self):
-        return self
+        return False
 
 class SomeFloat(SomeObject):
     "Stands for a float or an integer."
 
 s_None = SomePBC([], can_be_None=True)
 s_Bool = SomeBool()
+s_Int  = SomeInteger()
 s_ImpossibleValue = SomeImpossibleValue()
 s_Str0 = SomeString(no_nul=True)
 
         # this is just a performance shortcut
         if s1 != s2:
             s1 = pair(s1, s2).union()
-    if DEBUG:
-        if s1.caused_by_merge is None and len(somevalues) > 1:
-            s1.caused_by_merge = somevalues
     return s1
 
-def isdegenerated(s_value):
-    return s_value.__class__ is SomeObject and s_value.knowntype is not type
-
 # make knowntypedata dictionary
 
 def add_knowntypedata(ktd, truth, vars, s_obj):

pypy/annotation/policy.py

 
 
 class BasicAnnotatorPolicy(object):
-    allow_someobjects = True
 
     def event(pol, bookkeeper, what, *args):
         pass
     def specialize__ll_and_arg(pol, *args):
         from pypy.rpython.annlowlevel import LowLevelAnnotatorPolicy
         return LowLevelAnnotatorPolicy.specialize__ll_and_arg(*args)
-
-class StrictAnnotatorPolicy(AnnotatorPolicy):
-    allow_someobjects = False

pypy/annotation/signature.py

 from pypy.annotation.model import SomeBool, SomeInteger, SomeString,\
      SomeFloat, SomeList, SomeDict, s_None, \
      SomeObject, SomeInstance, SomeTuple, lltype_to_annotation,\
-     unionof, SomeUnicodeString
-from pypy.annotation.listdef import ListDef, MOST_GENERAL_LISTDEF
-from pypy.annotation.dictdef import DictDef, MOST_GENERAL_DICTDEF
+     unionof, SomeUnicodeString, SomeType
+from pypy.annotation.listdef import ListDef
+from pypy.annotation.dictdef import DictDef
 
 _annotation_cache = {}
 
         return SomeString()
     elif t is unicode:
         return SomeUnicodeString()
-    elif t is list:
-        return SomeList(MOST_GENERAL_LISTDEF)
-    elif t is dict:
-        return SomeDict(MOST_GENERAL_DICTDEF)
-    # can't do tuple
     elif t is types.NoneType:
         return s_None
     elif bookkeeper and extregistry.is_registered_type(t, bookkeeper.policy):
         entry = extregistry.lookup_type(t, bookkeeper.policy)
         return entry.compute_annotation_bk(bookkeeper)
-    elif bookkeeper and t.__module__ != '__builtin__' and t not in bookkeeper.pbctypes:
+    elif t is type:
+        return SomeType()
+    elif bookkeeper and not hasattr(t, '_freeze_'):
         classdef = bookkeeper.getuniqueclassdef(t)
         return SomeInstance(classdef)
     else:
-        o = SomeObject()
-        if t != object:
-            o.knowntype = t
-        return o
+        raise AssertionError("annotationoftype(%r)" % (t,))
 
 class Sig(object):
 

pypy/annotation/test/test_annrpython.py

     assert isinstance(s_list, annmodel.SomeList)
     return s_list.listdef.listitem.s_value
 
-def somelist(s_type=annmodel.SomeObject()):
+def somelist(s_type):
     return annmodel.SomeList(ListDef(None, s_type))
 
 def dictkey(s_dict):
     assert isinstance(s_dict, annmodel.SomeDict)
     return s_dict.dictdef.dictvalue.s_value
 
-def somedict(s_key=annmodel.SomeObject(), s_value=annmodel.SomeObject()):
+def somedict(s_key, s_value):
     return annmodel.SomeDict(DictDef(None, s_key, s_value))
 
 
                                 annmodel.SomeInteger()
                                 ])
 
-    def test_inheritance2(self):
-        a = self.RPythonAnnotator()
-        s = a.build_types(snippet._inheritance_nonrunnable, [])
-        # result should be exactly:
-        assert s == annmodel.SomeTuple([
-                                annmodel.SomeInteger(),
-                                annmodel.SomeObject()
-                                ])
-
     def test_poor_man_range(self):
         a = self.RPythonAnnotator()
         s = a.build_types(snippet.poor_man_range, [int])
 
     def test_flow_type_info(self):
         a = self.RPythonAnnotator()
-        s = a.build_types(snippet.flow_type_info, [object])
+        s = a.build_types(snippet.flow_type_info, [int])
         a.simplify()
-        #a.translator.view()
+        assert s.knowntype == int
+
+        a = self.RPythonAnnotator()
+        s = a.build_types(snippet.flow_type_info, [str])
+        a.simplify()
         assert s.knowntype == int
 
     def test_flow_type_info_2(self):
 
     def test_flow_usertype_info(self):
         a = self.RPythonAnnotator()
-        s = a.build_types(snippet.flow_usertype_info, [object])
+        s = a.build_types(snippet.flow_usertype_info, [snippet.WithInit])
         #a.translator.view()
         assert isinstance(s, annmodel.SomeInstance)
         assert s.classdef == a.bookkeeper.getuniqueclassdef(snippet.WithInit)
         assert isinstance(s, annmodel.SomeInstance)
         assert s.classdef == a.bookkeeper.getuniqueclassdef(snippet.WithMoreInit)
 
-    def test_flow_identity_info(self):
-        a = self.RPythonAnnotator()
-        s = a.build_types(snippet.flow_identity_info, [object, object])
-        a.simplify()
-        #a.translator.view()
-        assert s == a.bookkeeper.immutablevalue((None, None))
-
     def test_mergefunctions(self):
         a = self.RPythonAnnotator()
         s = a.build_types(snippet.mergefunctions, [int])
         # the annotator (it doesn't check that they operate property, though)
         for example, methname, s_example in [
             ('', 'join',    annmodel.SomeString()),
-            ([], 'append',  somelist()),
-            ([], 'extend',  somelist()),
-            ([], 'reverse', somelist()),
-            ([], 'insert',  somelist()),
-            ([], 'pop',     somelist()),
+            ([], 'append',  somelist(annmodel.s_Int)),
+            ([], 'extend',  somelist(annmodel.s_Int)),
+            ([], 'reverse', somelist(annmodel.s_Int)),
+            ([], 'insert',  somelist(annmodel.s_Int)),
+            ([], 'pop',     somelist(annmodel.s_Int)),
             ]:
             constmeth = getattr(example, methname)
             s_constmeth = iv(constmeth)
 
     def test_simple_slicing(self):
         a = self.RPythonAnnotator()
-        s = a.build_types(snippet.simple_slice, [list])
+        s = a.build_types(snippet.simple_slice, [somelist(annmodel.s_Int)])
         assert isinstance(s, annmodel.SomeList)
 
     def test_simple_iter_list(self):
         a = self.RPythonAnnotator()
-        s = a.build_types(snippet.simple_iter, [list])
+        s = a.build_types(snippet.simple_iter, [somelist(annmodel.s_Int)])
         assert isinstance(s, annmodel.SomeIterator)
 
     def test_simple_iter_next(self):
         assert isinstance(dictkey(s), annmodel.SomeInteger)
         assert isinstance(dictvalue(s), annmodel.SomeInteger)
 
-        a = self.RPythonAnnotator()
-        s = a.build_types(snippet.dict_update, [str])
-        assert not isinstance(dictkey(s), annmodel.SomeString)
-        assert not isinstance(dictvalue(s), annmodel.SomeString)
-
     def test_dict_update_2(self):
         a = self.RPythonAnnotator()
         def g(n):
     def test_dict_keys2(self):
         a = self.RPythonAnnotator()
         s = a.build_types(snippet.dict_keys2, [])
-        assert not isinstance(listitem(s), annmodel.SomeString)
+        assert type(listitem(s)) is annmodel.SomeString
 
     def test_dict_values(self):
         a = self.RPythonAnnotator()
     def test_dict_values2(self):
         a = self.RPythonAnnotator()
         s = a.build_types(snippet.dict_values2, [])
-        assert not isinstance(listitem(s), annmodel.SomeString)
+        assert type(listitem(s)) is annmodel.SomeString
 
     def test_dict_items(self):
         a = self.RPythonAnnotator()
         s = a.build_types(operation_always_raising, [int])
         assert s == a.bookkeeper.immutablevalue(24)
 
-    def test_bltin_code_frame_confusion(self):
-        a = self.RPythonAnnotator()
-        a.build_types(snippet.bltin_code_frame_confusion,[])
-        f_flowgraph = graphof(a, snippet.bltin_code_frame_f)
-        g_flowgraph = graphof(a, snippet.bltin_code_frame_g)
-        # annotator confused by original bltin code/frame setup, we just get SomeObject here
-        assert a.binding(f_flowgraph.getreturnvar()).__class__ is annmodel.SomeObject
-        assert a.binding(g_flowgraph.getreturnvar()).__class__ is annmodel.SomeObject
-
-    def test_bltin_code_frame_reorg(self):
-        a = self.RPythonAnnotator()
-        a.build_types(snippet.bltin_code_frame_reorg,[])
-        f_flowgraph = graphof(a, snippet.bltin_code_frame_f)
-        g_flowgraph = graphof(a, snippet.bltin_code_frame_g)
-        assert isinstance(a.binding(f_flowgraph.getreturnvar()),
-                            annmodel.SomeInteger)
-        assert isinstance(a.binding(g_flowgraph.getreturnvar()),
-                          annmodel.SomeString)
-
     def test_propagation_of_fresh_instances_through_attrs(self):
         a = self.RPythonAnnotator()
         s = a.build_types(snippet.propagation_of_fresh_instances_through_attrs, [int])
         assert s.classdef is a.bookkeeper.getuniqueclassdef(snippet.Exc)
 
     def test_type_is(self):
-        class C(object):
+        class B(object):
+            pass
+        class C(B):
             pass
         def f(x):
-            if type(x) is C:
-                return x
-            raise Exception
-        a = self.RPythonAnnotator()
-        s = a.build_types(f, [object])
+            assert type(x) is C
+            return x
+        a = self.RPythonAnnotator()
+        s = a.build_types(f, [B])
         assert s.classdef is a.bookkeeper.getuniqueclassdef(C)
 
     def test_ann_assert(self):
             return None
 
         a = self.RPythonAnnotator()
-        s = a.build_types(f, [list])
+        s = a.build_types(f, [somelist(annmodel.s_Int)])
         assert s.classdef is a.bookkeeper.getuniqueclassdef(IndexError)  # KeyError ignored because l is a list
 
     def test_freeze_protocol(self):
         class Stuff:
-            def __init__(self, flag):
+            def __init__(self):
                 self.called = False
-                self.flag = flag
             def _freeze_(self):
                 self.called = True
-                return self.flag
-        myobj = Stuff(True)
+                return True
+        myobj = Stuff()
         a = self.RPythonAnnotator()
         s = a.build_types(lambda: myobj, [])
         assert myobj.called
         assert isinstance(s, annmodel.SomePBC)
         assert s.const == myobj
-        myobj = Stuff(False)
+
+    def test_cleanup_protocol(self): 
+        class Stuff:
+            def __init__(self):
+                self.called = False
+            def _cleanup_(self):
+                self.called = True
+        myobj = Stuff()
         a = self.RPythonAnnotator()
         s = a.build_types(lambda: myobj, [])
         assert myobj.called
         def f(a,b):
             return bool(a) or bool(b)
         a = self.RPythonAnnotator()
-        s = a.build_types(f, [int,list])
+        s = a.build_types(f, [int, somelist(annmodel.s_Int)])
         assert s.knowntype == bool
 
     def test_float(self):
         assert isinstance(s_item, annmodel.SomeInstance)
         assert s_item.classdef is a.bookkeeper.getuniqueclassdef(T)
 
-    def test_assert_type_is_list_doesnt_lose_info(self):
-        class T(object):
-            pass
-        def g(l):
-            assert type(l) is list
-            return l
-        def f():
-            l = [T()]
-            return g(l)
-        a = self.RPythonAnnotator()
-        s = a.build_types(f, [])
-        s_item = listitem(s)
-        assert isinstance(s_item, annmodel.SomeInstance)
-        assert s_item.classdef is a.bookkeeper.getuniqueclassdef(T)
-
-
     def test_int_str_mul(self):
         def f(x,a,b):
             return a*x+x*b
             except KeyError:
                 raise
         a = self.RPythonAnnotator()
-        a.build_types(f, [dict])
+        a.build_types(f, [somedict(annmodel.s_Int, annmodel.s_Int)])
         fg = graphof(a, f)
         et, ev = fg.exceptblock.inputargs
-        t = annmodel.SomeObject()
-        t.knowntype = type
+        t = annmodel.SomeType()
         t.const = KeyError
         t.is_type_of = [ev]
         assert a.binding(et) == t
             except:
                 raise
         a = self.RPythonAnnotator()
-        a.build_types(f, [dict])
+        a.build_types(f, [somedict(annmodel.s_Int, annmodel.s_Int)])
         fg = graphof(a, f)
         et, ev = fg.exceptblock.inputargs
-        t = annmodel.SomeObject()
-        t.knowntype = type
+        t = annmodel.SomeType()
         t.is_type_of = [ev]
         t.const = KeyError    # IndexError ignored because 'dic' is a dict
         assert a.binding(et) == t
                 finally:
                     h()
         a = self.RPythonAnnotator()
-        a.build_types(f, [int, list])
+        a.build_types(f, [int, somelist(annmodel.s_Int)])
         fg = graphof(a, f)
         et, ev = fg.exceptblock.inputargs
-        t = annmodel.SomeObject()
-        t.knowntype = type
+        t = annmodel.SomeType()
         t.is_type_of = [ev]
         assert a.binding(et) == t
         assert isinstance(a.binding(ev), annmodel.SomeInstance) and a.binding(ev).classdef == a.bookkeeper.getuniqueclassdef(Exception)
         a.build_types(f, [])
         fg = graphof(a, f)
         et, ev = fg.exceptblock.inputargs
-        t = annmodel.SomeObject()
-        t.knowntype = type
+        t = annmodel.SomeType()
         t.is_type_of = [ev]
         assert a.binding(et) == t
         assert isinstance(a.binding(ev), annmodel.SomeInstance) and a.binding(ev).classdef == a.bookkeeper.getuniqueclassdef(Exception)
 
-    def test_sys_attrs(self):
-        def f():
-            return sys.argv[0]
-        a = self.RPythonAnnotator()
-        try:
-            oldvalue = sys.argv
-            sys.argv = []
-            s = a.build_types(f, [])
-        finally:
-            sys.argv = oldvalue
-        assert s is not None
-
     def test_pow(self):
         def f(n):
             n **= 2
         a = self.RPythonAnnotator()
         s = a.build_types(f, [int, str, a.bookkeeper.immutablevalue(1.0), a.bookkeeper.immutablevalue('d'), a.bookkeeper.immutablevalue('e')])
         assert s == annmodel.SomeTuple([annmodel.SomeChar(), a.bookkeeper.immutablevalue(1.0)])
-        assert not [b for b in a.bindings.itervalues() if b.__class__ == annmodel.SomeObject]
 
     def test_is_true_coalesce2(self):
         def f(a,b,a1,b1,c,d,e):
                 return d,c
             return e,c
         a = self.RPythonAnnotator()
-        s = a.build_types(f, [int, str, float, list,  a.bookkeeper.immutablevalue(1.0), a.bookkeeper.immutablevalue('d'), a.bookkeeper.immutablevalue('e')])
-        assert s == annmodel.SomeTuple([annmodel.SomeChar(), a.bookkeeper.immutablevalue(1.0)])
-        assert not [b for b in a.bindings.itervalues() if b.__class__ == annmodel.SomeObject]
+        s = a.build_types(f, [int, str, float, somelist(annmodel.s_Int),
+                              a.bookkeeper.immutablevalue(1.0),
+                              a.bookkeeper.immutablevalue('d'),
+                              a.bookkeeper.immutablevalue('e')])
+        assert s == annmodel.SomeTuple([annmodel.SomeChar(),
+                                        a.bookkeeper.immutablevalue(1.0)])
 
     def test_is_true_coalesce_sanity(self):
         def f(a):
             t = type(x)
             return issubclass(t, A)
 
-        def f():
-            x = g(1)
-            y = g(0)
-            return x or y
-        a = self.RPythonAnnotator()
-        s = a.build_types(f, [])
-        assert s.knowntype == bool
-        assert not s.is_constant()
-        a = self.RPythonAnnotator()
-        # sanity check
+        a = self.RPythonAnnotator()
         x = annmodel.SomeInteger()
         x.const = 1
         s = a.build_types(g, [x])
 
         a = self.RPythonAnnotator()
         s = a.build_types(f, [int])
-        assert s.__class__ == annmodel.SomeObject
-        assert s.knowntype == type
+        assert isinstance(s, annmodel.SomeType)
 
     def test_annotate_iter_empty_container(self):
         def f():
                 v = -maxint
             return intmask(v * 10)
         P = policy.AnnotatorPolicy()
-        P.allow_someobjects = False
         a = self.RPythonAnnotator(policy=P)
         s = a.build_types(fun, [bool])
         assert isinstance(s, annmodel.SomeInteger)
             a = self.RPythonAnnotator()
             py.test.raises(Exception, a.build_types, fn, [])
 
+    def test_lower_char(self):
+        def fn(c):
+            return c.lower()
+        a = self.RPythonAnnotator()
+        s = a.build_types(fn, [annmodel.SomeChar()])
+        assert s == annmodel.SomeChar()
+
+    def test_isinstance_double_const(self):
+        class X(object):
+            def _freeze_(self):
+                return True
+
+        x = X()
+        
+        def f(i):
+            if i:
+                x1 = x
+            else:
+                x1 = None
+            print "hello" # this is to force the merge of blocks
+            return isinstance(x1, X)
+
+        a = self.RPythonAnnotator()
+        s = a.build_types(f, [annmodel.SomeInteger()])
+        assert isinstance(s, annmodel.SomeBool)
+
 def g(n):
     return [0,1,2,n]
 

pypy/annotation/test/test_model.py

 import autopath
 import py
 from pypy.annotation.model import *
-from pypy.annotation.listdef import ListDef, MOST_GENERAL_LISTDEF
+from pypy.annotation.listdef import ListDef
 from pypy.rpython.ootypesystem.ootype import ROOT
 
 
 listdef1 = ListDef(None, SomeTuple([SomeInteger(nonneg=True), SomeString()]))
 listdef2 = ListDef(None, SomeTuple([SomeInteger(nonneg=False), SomeString()]))
 
-s1 = SomeObject()
+s1 = SomeType()
 s2 = SomeInteger(nonneg=True)
 s3 = SomeInteger(nonneg=False)
 s4 = SomeList(listdef1)
 s5 = SomeList(listdef2)
 s6 = SomeImpossibleValue()
-slist = [s1,s2,s3,s4,s6]  # not s5 -- unionof(s4,s5) modifies s4 and s5
+slist = [s1, s2, s3, s4, s6]  # not s5 -- unionof(s4,s5) modifies s4 and s5
 
 
 class C(object):
 
 def test_equality():
     assert s1 != s2 != s3 != s4 != s5 != s6
-    assert s1 == SomeObject()
+    assert s1 == SomeType()
     assert s2 == SomeInteger(nonneg=True)
     assert s3 == SomeInteger(nonneg=False)
     assert s4 == SomeList(listdef1)
 
 def test_contains():
     assert ([(s,t) for s in slist for t in slist if s.contains(t)] ==
-            [(s1,s1), (s1,s2), (s1,s3), (s1,s4), (s1,s6),
-                      (s2,s2),                   (s2,s6),
-                      (s3,s2), (s3,s3),          (s3,s6),
-                                        (s4,s4), (s4,s6),
-                                                 (s6,s6)])
-
-def test_union():
-    assert ([unionof(s,t) for s in slist for t in slist] ==
-            [s1, s1, s1, s1, s1,
-             s1, s2, s3, s1, s2,
-             s1, s3, s3, s1, s3,
-             s1, s1, s1, s4, s4,
-             s1, s2, s3, s4, s6])
+            [(s1, s1),                               (s1, s6),
+                       (s2, s2),                     (s2, s6),
+                       (s3, s2), (s3, s3),           (s3, s6),
+                                           (s4, s4), (s4, s6),
+                                                     (s6, s6)])
 
 def test_commonbase_simple():
     class A0: 
 def test_list_contains():
     listdef1 = ListDef(None, SomeInteger(nonneg=True))
     s1 = SomeList(listdef1)
-    s2 = SomeList(MOST_GENERAL_LISTDEF)
+    listdef2 = ListDef(None, SomeInteger(nonneg=False))
+    s2 = SomeList(listdef2)
     assert s1 != s2
-    assert s2.contains(s1)
+    assert not s2.contains(s1)
     assert s1 != s2
     assert not s1.contains(s2)
     assert s1 != s2

pypy/annotation/unaryop.py

      SomeObject, SomeInteger, SomeBool, SomeString, SomeChar, SomeList, \
      SomeDict, SomeTuple, SomeImpossibleValue, SomeUnicodeCodePoint, \
      SomeInstance, SomeBuiltin, SomeFloat, SomeIterator, SomePBC, \
-     SomeExternalObject, SomeTypedAddressAccess, SomeAddress, \
+     SomeExternalObject, SomeTypedAddressAccess, SomeAddress, SomeType, \
      s_ImpossibleValue, s_Bool, s_None, \
      unionof, missing_operation, add_knowntypedata, HarmlesslyBlocked, \
      SomeGenericCallable, SomeWeakRef, SomeUnicodeString
     def type(obj, *moreargs):
         if moreargs:
             raise Exception, 'type() called with more than one argument'
-        if obj.is_constant():
-            if isinstance(obj, SomeInstance):
-                r = SomePBC([obj.classdef.classdesc])
-            else:
-                r = immutablevalue(obj.knowntype)
-        else:
-            r = SomeObject()
-            r.knowntype = type
+        r = SomeType()
         bk = getbookkeeper()
         fn, block, i = bk.position_key
         annotator = bk.annotator
     def float(obj):
         return SomeFloat()
 
-    def long(obj):
-        return SomeObject()   # XXX
-
     def delattr(obj, s_attr):
         if obj.__class__ != SomeObject or obj.knowntype != object:
             getbookkeeper().warning(
     def getattr(obj, s_attr):
         # get a SomeBuiltin if the SomeObject has
         # a corresponding method to handle it
-        if s_attr.is_constant() and isinstance(s_attr.const, str):
-            attr = s_attr.const
-            s_method = obj.find_method(attr)
-            if s_method is not None:
-                return s_method
-            # if the SomeObject is itself a constant, allow reading its attrs
-            if obj.is_immutable_constant() and hasattr(obj.const, attr):
-                return immutablevalue(getattr(obj.const, attr))
-        else:
-            getbookkeeper().warning('getattr(%r, %r) is not RPythonic enough' %
-                                    (obj, s_attr))
-        return SomeObject()
+        if not s_attr.is_constant() or not isinstance(s_attr.const, str):
+            raise AnnotatorError("getattr(%r, %r) has non-constant argument"
+                                 % (obj, s_attr))
+        attr = s_attr.const
+        s_method = obj.find_method(attr)
+        if s_method is not None:
+            return s_method
+        # if the SomeObject is itself a constant, allow reading its attrs
+        if obj.is_immutable_constant() and hasattr(obj.const, attr):
+            return immutablevalue(getattr(obj.const, attr))
+        raise AnnotatorError("Cannot find attribute %r on %r" % (attr, obj))
     getattr.can_only_throw = []
 
     def bind_callables_under(obj, classdef, name):
     def method_isupper(chr):
         return s_Bool
 
+    def method_lower(chr):
+        return chr
+
+    def method_upper(chr):
+        return chr
+
 class __extend__(SomeIterator):
 
     def iter(itr):

pypy/bin/reportstaticdata.py

 
 """
 Usage: reportstaticdata.py [-m1|-m2|-t] [OPTION]... FILENAME
-Print a report for the static data informations contained in FILENAME
+Print a report for the static data information contained in FILENAME
 
-The static data informations are saved in the file staticdata.info when
+The static data information is saved in the file staticdata.info when
 passing --dump_static_data_info to translate.py.
 
 Options:

pypy/bin/translatorshell.py

 
 Example:
 
-    t = Translation(func)
+    t = Translation(func, [int])       # pass the list of args types
     t.view()                           # control flow graph
 
-    t.annotate([int])                  # pass the list of args types
+    t.annotate()
     t.view()                           # graph + annotations under the mouse
 
     t.rtype()                          # use low level operations 

pypy/config/test/test_config.py

         else:
             return 'foo'
 
-    t = Translation(f)
-    t.rtype([int])
+    t = Translation(f, [int])
+    t.rtype()
     
     block = t.context.graphs[0].startblock
     assert len(block.exits[0].target.operations) == 0

pypy/config/translationoption.py