Commits

Even Wiik Thomassen committed 25a188f

error

  • Participants
  • Parent commits b5b8aea

Comments (0)

Files changed (1)

+============================= test session starts ==============================
+platform linux2 -- Python 2.7.3 -- pytest-2.2.4.dev2
+collecting ... collected 1 items
+
+pyhaskell/interpreter/test/test_jit.py F
+
+=================================== FAILURES ===================================
+____________________________ TestLLtype.test_append ____________________________
+
+self = <pyhaskell.interpreter.test.test_jit.TestLLtype instance at 0x27b2950>
+
+    def test_append(self):
+        n = Var("n")
+        m = Var("m")
+        x = Var("x")
+        xs = Var("xs")
+        f = ForwardReference()
+        f.become(function("f", [
+            ([Int(0), n], n),
+            ([n, m], app(prim_seq, m, app(f, app(prim_sub, n, Int(1)),
+                                             app(prim_add, n, m))))], recursive=True))
+        g = ForwardReference()
+        g.become(function("g", [
+            ([Int(0)], w_true),
+            ([n], app(g, app(prim_sub, n, Int(1))))], recursive=True))
+    
+        bottom = ForwardReference()
+        bottom.become(function("bottom", [
+            ([], app(bottom))], recursive=True))
+    
+        last = ForwardReference()
+        last2 = ForwardReference()
+        last.become(function("last", [
+            ([cons(x, xs)], app(last2, xs, x))], recursive=True))
+        last2.become(function("last2", [
+            ([w_nil, n], n),
+            ([xs, m], app(last, xs))], recursive=True))
+    
+        # l = app(take, Int(100), app(iterate, not_, w_true))
+        # l = app(filter_, id_, app(take, Int(100),
+        #                           app(iterate, not_, w_true)))
+        # l = app(map_, succ, app(fromto, Int(1), Int(100)))
+        # l = app(take, Int(100), app(from_, Int(1)))
+        # l = app(map_, succ, app(take, Int(100), app(from_, Int(1))))
+        # l = to_list(range(100))
+        # l = app(fromto, Int(1), Int(100))
+        l = app(append, app(fromto, Int(1), Int(100)), app(fromto, Int(1), Int(100)))
+        def interp(i):
+            if i < 0:
+                result = evaluate_hnf(
+                    app(last, l))
+            else:
+                result = evaluate_hnf(app(f, Int(i), Int(0)))
+                #result = evaluate_hnf(app(bottom))
+            return result.tostr()
+    
+        interp(-100)
+        self.meta_interp(interp, [-100], listcomp=True, backendopt=True,
+>                        listops=True)
+
+pyhaskell/interpreter/test/test_jit.py:71: 
+_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
+
+self = <pyhaskell.interpreter.test.test_jit.TestLLtype instance at 0x27b2950>
+
+    def meta_interp(self, *args, **kwds):
+        kwds['CPUClass'] = self.CPUClass
+        kwds['type_system'] = self.type_system
+        if "backendopt" not in kwds:
+            kwds["backendopt"] = False
+        old = codewriter.CodeWriter.debug
+        try:
+            codewriter.CodeWriter.debug = True
+>           return ll_meta_interp(*args, **kwds)
+        finally:
+
+../pypy/pypy/jit/metainterp/test/support.py:205: 
+_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
+
+function = <function interp at 0x27b0140>, args = [-100], backendopt = True
+type_system = 'lltype', listcomp = True, translationoptions = {}
+
+    def ll_meta_interp(function, args, backendopt=False, type_system='lltype',
+                       listcomp=False, translationoptions={}, **kwds):
+        if listcomp:
+            extraconfigopts = {'translation.list_comprehension_operations': True}
+        else:
+            extraconfigopts = {}
+        for key, value in translationoptions.items():
+            extraconfigopts['translation.' + key] = value
+        interp, graph = get_interpreter(function, args,
+                                        backendopt=False,  # will be done below
+                                        type_system=type_system,
+>                                       **extraconfigopts)
+
+../pypy/pypy/jit/metainterp/warmspot.py:64: 
+_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
+
+func = <function interp at 0x27b0140>, values = [-100], view = 'auto'
+viewbefore = 'auto'
+policy = <pypy.annotation.policy.AnnotatorPolicy object at 0x27b4b90>
+type_system = 'lltype', backendopt = False, config = None
+
+    def get_interpreter(func, values, view='auto', viewbefore='auto', policy=None,
+                        type_system="lltype", backendopt=False, config=None,
+                        **extraconfigopts):
+        extra_key = [(key, value) for key, value in extraconfigopts.iteritems()]
+        extra_key.sort()
+        extra_key = tuple(extra_key)
+        key = ((func,) + tuple([typeOf(x) for x in values]) +
+                (backendopt, extra_key))
+        try:
+            (t, interp, graph) = _tcache[key]
+        except KeyError:
+            def annotation(x):
+                T = typeOf(x)
+                return lltype_to_annotation(T)
+    
+            if policy is None:
+                from pypy.annotation.policy import AnnotatorPolicy
+                policy = AnnotatorPolicy()
+    
+            t, typer, graph = gengraph(func, [annotation(x) for x in values],
+                                       viewbefore, policy, type_system=type_system,
+                                       backendopt=backendopt, config=config,
+>                                      **extraconfigopts)
+
+../pypy/pypy/rpython/test/test_llinterp.py:93: 
+_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
+
+func = <function interp at 0x27b0140>
+argtypes = [SomeInteger(knowntype=int, nonneg=False, unsigned=False)]
+viewbefore = 'auto'
+policy = <pypy.annotation.policy.AnnotatorPolicy object at 0x27b4b90>
+type_system = 'lltype', backendopt = False, config = None
+
+    def gengraph(func, argtypes=[], viewbefore='auto', policy=None,
+                 type_system="lltype", backendopt=False, config=None,
+                 **extraconfigopts):
+        t = TranslationContext(config=config)
+        t.config.set(**extraconfigopts)
+        a = t.buildannotator(policy=policy)
+>       timelog("annotating", a.build_types, func, argtypes, main_entry_point=True)
+
+../pypy/pypy/rpython/test/test_llinterp.py:44: 
+_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
+
+prefix = 'annotating'
+call = <bound method RPythonAnnotator.build_types of <pypy.annotation.annrpython.RPythonAnnotator object at 0x27b4cd0>>
+
+    def timelog(prefix, call, *args, **kwds):
+        #import time
+        #print prefix, "...",
+        #start = time.time()
+>       res = call(*args, **kwds)
+
+../pypy/pypy/rpython/test/test_llinterp.py:33: 
+_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
+
+self = <pypy.annotation.annrpython.RPythonAnnotator object at 0x27b4cd0>
+function = <function interp at 0x27b0140>
+input_arg_types = [SomeInteger(knowntype=int, nonneg=False, unsigned=False)]
+complete_now = True, main_entry_point = True
+
+    def build_types(self, function, input_arg_types, complete_now=True,
+                    main_entry_point=False):
+        """Recursively build annotations about the specific entry point."""
+        assert isinstance(function, types.FunctionType), "fix that!"
+    
+        from pypy.annotation.policy import AnnotatorPolicy
+        policy = AnnotatorPolicy()
+        # make input arguments and set their type
+        args_s = [self.typeannotation(t) for t in input_arg_types]
+    
+        # XXX hack
+        annmodel.TLS.check_str_without_nul = (
+            self.translator.config.translation.check_str_without_nul)
+    
+        flowgraph, inputcells = self.get_call_parameters(function, args_s, policy)
+        if not isinstance(flowgraph, FunctionGraph):
+            assert isinstance(flowgraph, annmodel.SomeObject)
+            return flowgraph
+    
+        if main_entry_point:
+            self.translator.entry_point_graph = flowgraph
+>       return self.build_graph_types(flowgraph, inputcells, complete_now=complete_now)
+
+../pypy/pypy/annotation/annrpython.py:89: 
+_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
+
+self = <pypy.annotation.annrpython.RPythonAnnotator object at 0x27b4cd0>
+flowgraph = <FunctionGraph of (pyhaskell.interpreter.test.test_jit:60)interp at 0x28ecf50>
+inputcells = [SomeInteger(knowntype=int, nonneg=False, unsigned=False)]
+complete_now = True
+
+    def build_graph_types(self, flowgraph, inputcells, complete_now=True):
+        checkgraph(flowgraph)
+    
+        nbarg = len(flowgraph.getargs())
+        if len(inputcells) != nbarg:
+            raise TypeError("%s expects %d args, got %d" %(
+                            flowgraph, nbarg, len(inputcells)))
+    
+        # register the entry point
+        self.addpendinggraph(flowgraph, inputcells)
+        # recursively proceed until no more pending block is left
+        if complete_now:
+>           self.complete()
+
+../pypy/pypy/annotation/annrpython.py:142: 
+_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
+
+self = <pypy.annotation.annrpython.RPythonAnnotator object at 0x27b4cd0>
+
+    def complete(self):
+        """Process pending blocks until none is left."""
+        while True:
+            while self.pendingblocks:
+                block, graph = self.pendingblocks.popitem()
+>               self.processblock(graph, block)
+
+../pypy/pypy/annotation/annrpython.py:195: 
+_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
+
+self = <pypy.annotation.annrpython.RPythonAnnotator object at 0x27b4cd0>
+graph = <FunctionGraph of (pyhaskell.interpreter.test.test_haskell:64)prim_add at 0x2b78a90>
+block = block@36 with 2 exits(v0)
+
+    def processblock(self, graph, block):
+        # Important: this is not called recursively.
+        # self.flowin() can only issue calls to self.addpendingblock().
+        # The analysis of a block can be in three states:
+        #  * block not in self.annotated:
+        #      never seen the block.
+        #  * self.annotated[block] == False:
+        #      the input variables of the block are in self.bindings but we
+        #      still have to consider all the operations in the block.
+        #  * self.annotated[block] == graph-containing-block:
+        #      analysis done (at least until we find we must generalize the
+        #      input variables).
+    
+        #print '* processblock', block, cells
+        self.annotated[block] = graph
+        if block in self.blocked_blocks:
+            del self.blocked_blocks[block]
+        try:
+>           self.flowin(graph, block)
+
+../pypy/pypy/annotation/annrpython.py:340: 
+_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
+
+self = <pypy.annotation.annrpython.RPythonAnnotator object at 0x27b4cd0>
+graph = <FunctionGraph of (pyhaskell.interpreter.test.test_haskell:64)prim_add at 0x2b78a90>
+block = block@36 with 2 exits(v0)
+
+    def flowin(self, graph, block):
+        #print 'Flowing', block, [self.binding(a) for a in block.inputargs]
+        try:
+            for i in range(len(block.operations)):
+                try:
+                    self.bookkeeper.enter((graph, block, i))
+>                   self.consider_op(block, i)
+
+../pypy/pypy/annotation/annrpython.py:399: 
+_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
+
+self = <pypy.annotation.annrpython.RPythonAnnotator object at 0x27b4cd0>
+block = block@36 with 2 exits(v0), opindex = 1
+
+    def consider_op(self, block, opindex):
+        op = block.operations[opindex]
+>       argcells = [self.binding(a) for a in op.args]
+
+../pypy/pypy/annotation/annrpython.py:577: 
+_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
+
+self = <pypy.annotation.annrpython.RPythonAnnotator object at 0x27b4cd0>
+arg = (builtin_function_or_method locals), default = <object object at 0xf94270>
+
+    def binding(self, arg, default=FAIL):
+        "Gives the SomeValue corresponding to the given Variable or Constant."
+        if isinstance(arg, Variable):
+            try:
+                return self.bindings[arg]
+            except KeyError:
+                if default is not FAIL:
+                    return default
+                else:
+                    raise
+        elif isinstance(arg, Constant):
+            #if arg.value is undefined_value:   # undefined local variables
+            #    return annmodel.s_ImpossibleValue
+>           return self.bookkeeper.immutableconstant(arg)
+
+../pypy/pypy/annotation/annrpython.py:238: 
+_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
+
+self = <pypy.annotation.bookkeeper.Bookkeeper object at 0x28ec590>
+const = (builtin_function_or_method locals)
+
+    def immutableconstant(self, const):
+>       return self.immutablevalue(const.value)
+
+../pypy/pypy/annotation/bookkeeper.py:314: 
+_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
+
+self = <pypy.annotation.bookkeeper.Bookkeeper object at 0x28ec590>
+x = <built-in function locals>, need_const = True
+
+    def immutablevalue(self, x, need_const=True):
+        """The most precise SomeValue instance that contains the
+        immutable value x."""
+        # convert unbound methods to the underlying function
+        if hasattr(x, 'im_self') and x.im_self is None:
+            x = x.im_func
+            assert not hasattr(x, 'im_self')
+        tp = type(x)
+        if issubclass(tp, Symbolic): # symbolic constants support
+            result = x.annotation()
+            result.const_box = Constant(x)
+            return result
+        if tp is bool:
+            result = SomeBool()
+        elif tp is int:
+            result = SomeInteger(nonneg = x>=0)
+        elif tp is long:
+            if -sys.maxint-1 <= x <= sys.maxint:
+                x = int(x)
+                result = SomeInteger(nonneg = x>=0)
+            else:
+                raise Exception("seeing a prebuilt long (value %s)" % hex(x))
+        elif issubclass(tp, str): # py.lib uses annotated str subclasses
+            no_nul = not '\x00' in x
+            if len(x) == 1:
+                result = SomeChar(no_nul=no_nul)
+            else:
+                result = SomeString(no_nul=no_nul)
+        elif tp is unicode:
+            if len(x) == 1:
+                result = SomeUnicodeCodePoint()
+            else:
+                result = SomeUnicodeString()
+        elif tp is tuple:
+            result = SomeTuple(items = [self.immutablevalue(e, need_const) for e in x])
+        elif tp is float:
+            result = SomeFloat()
+        elif tp is list:
+            if need_const:
+                key = Constant(x)
+                try:
+                    return self.immutable_cache[key]
+                except KeyError:
+                    result = SomeList(ListDef(self, s_ImpossibleValue))
+                    self.immutable_cache[key] = result
+                    for e in x:
+                        result.listdef.generalize(self.immutablevalue(e))
+                    result.const_box = key
+                    return result
+            else:
+                listdef = ListDef(self, s_ImpossibleValue)
+                for e in x:
+                    listdef.generalize(self.immutablevalue(e, False))
+                result = SomeList(listdef)
+        elif tp is dict or tp is r_dict:
+            if need_const:
+                key = Constant(x)
+                try:
+                    return self.immutable_cache[key]
+                except KeyError:
+                    result = SomeDict(DictDef(self,
+                                              s_ImpossibleValue,
+                                              s_ImpossibleValue,
+                                              is_r_dict = tp is r_dict))
+                    self.immutable_cache[key] = result
+                    if tp is r_dict:
+                        s_eqfn = self.immutablevalue(x.key_eq)
+                        s_hashfn = self.immutablevalue(x.key_hash)
+                        result.dictdef.dictkey.update_rdict_annotations(s_eqfn,
+                                                                        s_hashfn)
+                    seen_elements = 0
+                    while seen_elements != len(x):
+                        items = x.items()
+                        for ek, ev in items:
+                            result.dictdef.generalize_key(self.immutablevalue(ek))
+                            result.dictdef.generalize_value(self.immutablevalue(ev))
+                            result.dictdef.seen_prebuilt_key(ek)
+                        seen_elements = len(items)
+                        # if the dictionary grew during the iteration,
+                        # start over again
+                    result.const_box = key
+                    return result
+            else:
+                dictdef = DictDef(self,
+                s_ImpossibleValue,
+                s_ImpossibleValue,
+                is_r_dict = tp is r_dict)
+                if tp is r_dict:
+                    s_eqfn = self.immutablevalue(x.key_eq)
+                    s_hashfn = self.immutablevalue(x.key_hash)
+                    dictdef.dictkey.update_rdict_annotations(s_eqfn,
+                        s_hashfn)
+                for ek, ev in x.iteritems():
+                    dictdef.generalize_key(self.immutablevalue(ek, False))
+                    dictdef.generalize_value(self.immutablevalue(ev, False))
+                    dictdef.seen_prebuilt_key(ek)
+                result = SomeDict(dictdef)
+        elif tp is weakref.ReferenceType:
+            x1 = x()
+            if x1 is None:
+                result = SomeWeakRef(None)    # dead weakref
+            else:
+                s1 = self.immutablevalue(x1)
+                assert isinstance(s1, SomeInstance)
+                result = SomeWeakRef(s1.classdef)
+        elif ishashable(x) and x in BUILTIN_ANALYZERS:
+            _module = getattr(x,"__module__","unknown")
+            result = SomeBuiltin(BUILTIN_ANALYZERS[x], methodname="%s.%s" % (_module, x.__name__))
+        elif extregistry.is_registered(x, self.policy):
+            entry = extregistry.lookup(x, self.policy)
+            result = entry.compute_annotation_bk(self)
+        elif isinstance(x, lltype._ptr):
+            result = SomePtr(lltype.typeOf(x))
+        elif isinstance(x, llmemory.fakeaddress):
+            result = SomeAddress()
+        elif isinstance(x, ootype._static_meth):
+            result = SomeOOStaticMeth(ootype.typeOf(x))
+        elif isinstance(x, ootype._class):
+            result = SomeOOClass(x._INSTANCE)   # NB. can be None
+        elif isinstance(x, ootype.instance_impl): # XXX
+            result = SomeOOInstance(ootype.typeOf(x))
+        elif isinstance(x, (ootype._record, ootype._string)):
+            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
+                # global constant list, the find_method() returns non-None
+                s_self = self.immutablevalue(x.im_self, need_const)
+                result = s_self.find_method(x.im_func.__name__)
+            elif hasattr(x, '__self__') and x.__self__ is not None:
+                # 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__)
+                assert result is not None
+            else:
+                result = None
+            if result is None:
+>               result = SomePBC([self.getdesc(x)])
+
+../pypy/pypy/annotation/bookkeeper.py:461: 
+_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
+
+self = <pypy.annotation.bookkeeper.Bookkeeper object at 0x28ec590>
+pyobj = <built-in function locals>
+
+    def getdesc(self, pyobj):
+        # get the XxxDesc wrapper for the given Python object, which must be
+        # one of:
+        #  * a user-defined Python function
+        #  * a Python type or class (but not a built-in one like 'int')
+        #  * a user-defined bound or unbound method object
+        #  * a frozen pre-built constant (with _freeze_() == True)
+        #  * a bound method of a frozen pre-built constant
+        try:
+            return self.descs[pyobj]
+        except KeyError:
+            if isinstance(pyobj, types.FunctionType):
+                result = description.FunctionDesc(self, pyobj)
+            elif isinstance(pyobj, (type, types.ClassType)):
+                if pyobj is object:
+                    raise Exception, "ClassDesc for object not supported"
+                if pyobj.__module__ == '__builtin__': # avoid making classdefs for builtin types
+                    result = self.getfrozen(pyobj)
+                else:
+                    result = description.ClassDesc(self, pyobj)
+            elif isinstance(pyobj, types.MethodType):
+                if pyobj.im_self is None:   # unbound
+                    return self.getdesc(pyobj.im_func)
+                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
+                else: # regular method
+                    origincls, name = origin_of_meth(pyobj)
+                    self.see_mutable(pyobj.im_self)
+                    assert pyobj == getattr(pyobj.im_self, name), (
+                        "%r is not %s.%s ??" % (pyobj, pyobj.im_self, name))
+                    # emulate a getattr to make sure it's on the classdef
+                    classdef = self.getuniqueclassdef(pyobj.im_class)
+                    classdef.find_attribute(name)
+                    result = self.getmethoddesc(
+                        self.getdesc(pyobj.im_func),            # funcdesc
+                        self.getuniqueclassdef(origincls),      # originclassdef
+                        classdef,                               # selfclassdef
+                        name)
+            else:
+                # must be a frozen pre-built constant, but let's check
+                if hasattr(pyobj, '_freeze_'):
+                    assert pyobj._freeze_() is True
+                else:
+                    if hasattr(pyobj, '__call__'):
+                        msg = "object with a __call__ is not RPython"
+                    else:
+                        msg = "unexpected prebuilt constant"
+>                   raise Exception("%s: %r" % (msg, pyobj))
+E                   Exception: object with a __call__ is not RPython: <built-in function locals>
+
+../pypy/pypy/annotation/bookkeeper.py:535: Exception
+=========================== 1 failed in 2.63 seconds ===========================