Author: Ronan Lamy <ronan.l...@gmail.com>
Branch: extregistry-refactor
Changeset: r62326:f5464a2d44dd
Date: 2013-03-13 02:10 +0000
http://bitbucket.org/pypy/pypy/changeset/f5464a2d44dd/

Log:    kill genericcallable

diff --git a/rpython/annotator/binaryop.py b/rpython/annotator/binaryop.py
--- a/rpython/annotator/binaryop.py
+++ b/rpython/annotator/binaryop.py
@@ -18,7 +18,6 @@
 from rpython.annotator.model import TLS
 from rpython.annotator.model import read_can_only_throw
 from rpython.annotator.model import add_knowntypedata, merge_knowntypedata
-from rpython.annotator.model import SomeGenericCallable
 from rpython.annotator.bookkeeper import getbookkeeper
 from rpython.flowspace.model import Variable, Constant
 from rpython.rlib import rarithmetic
@@ -812,20 +811,6 @@
                     s.const = False    # no common desc in the two sets
         return s
 
-class __extend__(pairtype(SomeGenericCallable, SomePBC)):
-    def union((gencall, pbc)):
-        for desc in pbc.descriptions:
-            unique_key = desc
-            bk = desc.bookkeeper
-            s_result = bk.emulate_pbc_call(unique_key, pbc, gencall.args_s)
-            s_result = unionof(s_result, gencall.s_result)
-            assert gencall.s_result.contains(s_result)
-        return gencall
-
-class __extend__(pairtype(SomePBC, SomeGenericCallable)):
-    def union((pbc, gencall)):
-        return pair(gencall, pbc).union()
-
 class __extend__(pairtype(SomeImpossibleValue, SomeObject)):
     def union((imp1, obj2)):
         return obj2
diff --git a/rpython/annotator/model.py b/rpython/annotator/model.py
--- a/rpython/annotator/model.py
+++ b/rpython/annotator/model.py
@@ -449,16 +449,6 @@
         else:
             return kt.__name__
 
-class SomeGenericCallable(SomeObject):
-    """ Stands for external callable with known signature
-    """
-    def __init__(self, args, result):
-        self.args_s = args
-        self.s_result = result
-
-    def can_be_None(self):
-        return True
-
 class SomeBuiltin(SomeObject):
     "Stands for a built-in function or method with special-cased analysis."
     knowntype = BuiltinFunctionType  # == BuiltinMethodType
diff --git a/rpython/annotator/test/test_annrpython.py 
b/rpython/annotator/test/test_annrpython.py
--- a/rpython/annotator/test/test_annrpython.py
+++ b/rpython/annotator/test/test_annrpython.py
@@ -3014,33 +3014,6 @@
         s = a.build_types(fun, [])
         assert s.const == 0
 
-    def test_some_generic_function_call(self):
-        def h(x):
-            return int(x)
-
-        def c(x):
-            return int(x)
-
-        def g(a, x):
-            if x == -1:
-                a = None
-            if x < 0:
-                if x == -1:
-                    a = h
-                else:
-                    a = c
-                x = x + .01
-            return a(x)
-
-        #def fun(x):
-
-        a = self.RPythonAnnotator(policy=policy.AnnotatorPolicy())
-        s = a.build_types(g, [annmodel.SomeGenericCallable(
-            args=[annmodel.SomeFloat()], result=annmodel.SomeInteger()),
-                              annmodel.SomeFloat()])
-        assert isinstance(s, annmodel.SomeInteger)
-        assert not hasattr(s, 'const')
-
     def test_compare_int_bool(self):
         def fun(x):
             return 50 < x
diff --git a/rpython/annotator/test/test_signature.py 
b/rpython/annotator/test/test_signature.py
--- a/rpython/annotator/test/test_signature.py
+++ b/rpython/annotator/test/test_signature.py
@@ -6,10 +6,3 @@
     assert _annotation_key({str:(str, [str])}) == ('dict', (str, (str, 
('list', str))))
     for i in ([[str]], [str], (int, int, {str: [str]})):
         assert hash(_annotation_key(i))
-
-def test_genericcallable():
-    py.test.skip("this two annotations should be equal - fix!")
-    from rpython.rtyper.extfunc import genericcallable
-    s1 = annotation([genericcallable([str], int)])
-    s2 = annotation([genericcallable([str], int)])
-    assert s1 == s2
diff --git a/rpython/annotator/unaryop.py b/rpython/annotator/unaryop.py
--- a/rpython/annotator/unaryop.py
+++ b/rpython/annotator/unaryop.py
@@ -12,7 +12,7 @@
      SomeTypedAddressAccess, SomeAddress, SomeType, \
      s_ImpossibleValue, s_Bool, s_None, \
      unionof, missing_operation, add_knowntypedata, HarmlesslyBlocked, \
-     SomeGenericCallable, SomeWeakRef, SomeUnicodeString
+     SomeWeakRef, SomeUnicodeString
 from rpython.annotator.bookkeeper import getbookkeeper
 from rpython.annotator import builtin
 from rpython.annotator.binaryop import _clone ## XXX where to put this?
@@ -741,14 +741,6 @@
         else:
             return SomeObject()    # len() on a pbc? no chance
 
-class __extend__(SomeGenericCallable):
-    def call(self, args):
-        bookkeeper = getbookkeeper()
-        for arg, expected in zip(args.unpack()[0], self.args_s):
-            assert expected.contains(arg)
-
-        return self.s_result
-
 # annotation of low-level types
 from rpython.annotator.model import SomePtr, SomeLLADTMeth
 from rpython.annotator.model import SomeOOInstance, SomeOOBoundMeth, 
SomeOOStaticMeth
diff --git a/rpython/rtyper/extfunc.py b/rpython/rtyper/extfunc.py
--- a/rpython/rtyper/extfunc.py
+++ b/rpython/rtyper/extfunc.py
@@ -125,23 +125,6 @@
     def _freeze_(self):
         return True
 
-class genericcallable(object):
-    """ A way to specify the callable annotation, but deferred until
-    we have bookkeeper
-    """
-    def __init__(self, args, result=None):
-        self.args = args
-        self.result = result
-
-class _ext_callable(ExtRegistryEntry):
-    _type_ = genericcallable
-    # we defer a bit annotation here
-
-    def compute_result_annotation(self):
-        return annmodel.SomeGenericCallable([annotation(i, self.bookkeeper)
-                                             for i in self.instance.args],
-                           annotation(self.instance.result, self.bookkeeper))
-
 class ExtFuncEntry(ExtRegistryEntry):
     safe_not_sandboxed = False
 
@@ -249,7 +232,7 @@
     llfakeimpl, oofakeimpl: optional; if provided, they are called by the 
llinterpreter
     sandboxsafe: use True if the function performs no I/O (safe for --sandbox)
     """
-    
+
     if export_name is None:
         export_name = function.__name__
 
diff --git a/rpython/rtyper/lltypesystem/rgeneric.py 
b/rpython/rtyper/lltypesystem/rgeneric.py
deleted file mode 100644
--- a/rpython/rtyper/lltypesystem/rgeneric.py
+++ /dev/null
@@ -1,9 +0,0 @@
-
-from rpython.rtyper.rgeneric import AbstractGenericCallableRepr
-from rpython.rtyper.lltypesystem.lltype import Ptr, FuncType
-
-class GenericCallableRepr(AbstractGenericCallableRepr):
-    def create_low_leveltype(self):
-        l_args = [r_arg.lowleveltype for r_arg in self.args_r]
-        l_retval = self.r_result.lowleveltype
-        return Ptr(FuncType(l_args, l_retval))
diff --git a/rpython/rtyper/ootypesystem/rgeneric.py 
b/rpython/rtyper/ootypesystem/rgeneric.py
deleted file mode 100644
--- a/rpython/rtyper/ootypesystem/rgeneric.py
+++ /dev/null
@@ -1,9 +0,0 @@
-
-from rpython.rtyper.rgeneric import AbstractGenericCallableRepr
-from rpython.rtyper.ootypesystem import ootype
-
-class GenericCallableRepr(AbstractGenericCallableRepr):
-    def create_low_leveltype(self):
-        l_args = [r_arg.lowleveltype for r_arg in self.args_r]
-        l_retval = self.r_result.lowleveltype
-        return ootype.StaticMethod(l_args, l_retval)
diff --git a/rpython/rtyper/rgeneric.py b/rpython/rtyper/rgeneric.py
deleted file mode 100644
--- a/rpython/rtyper/rgeneric.py
+++ /dev/null
@@ -1,56 +0,0 @@
-from rpython.annotator import model as annmodel
-from rpython.rtyper.lltypesystem import lltype
-from rpython.rtyper.rmodel import Repr
-from rpython.rtyper.rpbc import AbstractFunctionsPBCRepr
-from rpython.tool.pairtype import pairtype
-
-
-class AbstractGenericCallableRepr(Repr):
-    def __init__(self, rtyper, s_generic):
-        self.rtyper = rtyper
-        self.s_generic = s_generic
-        self.args_r = [self.rtyper.getrepr(arg) for arg in s_generic.args_s]
-        self.r_result = self.rtyper.getrepr(s_generic.s_result)
-        self.lowleveltype = self.create_low_leveltype()
-
-    def rtype_simple_call(self, hop):
-        return self.call('simple_call', hop)
-
-    def rtype_call_args(self, hop):
-        return self.call('call_args', hop)
-
-    def call(self, opname, hop):
-        vlist = hop.inputargs(self, *self.args_r) + 
[hop.inputconst(lltype.Void, None)]
-        hop.exception_is_here()
-        v_result = hop.genop('indirect_call', vlist, resulttype=self.r_result)
-        return v_result
-
-    def convert_const(self, value):
-        bookkeeper = self.rtyper.annotator.bookkeeper
-        if value is None:
-            return self.rtyper.type_system.null_callable(self.lowleveltype)
-        r_func = self.rtyper.getrepr(bookkeeper.immutablevalue(value))
-        return r_func.get_unique_llfn().value
-
-    def _setup_repr(self):
-        for r in self.args_r:
-            r.setup()
-        self.r_result.setup()
-
-class __extend__(annmodel.SomeGenericCallable):
-    def rtyper_makerepr(self, rtyper):
-        return rtyper.type_system.rgeneric.GenericCallableRepr(rtyper, self)
-
-    def rtyper_makekey(self):
-        return self.__class__, tuple([i.rtyper_makekey() for i in 
self.args_s]),\
-              self.s_result.rtyper_makekey()
-
-class __extend__(pairtype(AbstractFunctionsPBCRepr, 
AbstractGenericCallableRepr)):
-    def convert_from_to((pbcrepr, gencallrepr), v, llops):
-        if pbcrepr.lowleveltype is lltype.Void:
-            r = gencallrepr.convert_const(pbcrepr.s_pbc.const)
-            r.setup()
-            return r
-        if pbcrepr.lowleveltype == gencallrepr.lowleveltype:
-            return v
-        return NotImplemented
diff --git a/rpython/rtyper/rtyper.py b/rpython/rtyper/rtyper.py
--- a/rpython/rtyper/rtyper.py
+++ b/rpython/rtyper/rtyper.py
@@ -1013,7 +1013,6 @@
 from rpython.rtyper import rstr, rdict, rlist, rbytearray
 from rpython.rtyper import rclass, rbuiltin, rpbc
 from rpython.rtyper import rptr
-from rpython.rtyper import rgeneric
 from rpython.rtyper import rweakref
 from rpython.rtyper import raddress # memory addresses
 from rpython.rtyper.ootypesystem import rootype
diff --git a/rpython/rtyper/test/test_extfunc.py 
b/rpython/rtyper/test/test_extfunc.py
--- a/rpython/rtyper/test/test_extfunc.py
+++ b/rpython/rtyper/test/test_extfunc.py
@@ -58,32 +58,6 @@
         res = interpret(f, [])
         assert res == 7
 
-    def test_callback(self):
-        """
-        Verify annotation when a callback function is in the arguments list.
-        """
-        def d(y):
-            return eval("y()")
-
-        class DTestFuncEntry(ExtFuncEntry):
-            _about_ = d
-            name = 'd'
-            signature_args = [annmodel.SomeGenericCallable(args=[], result=
-                                                           
annmodel.SomeFloat())]
-            signature_result = annmodel.SomeFloat()
-
-        def callback():
-            return 2.5
-
-        def f():
-            return d(callback)
-
-        policy = AnnotatorPolicy()
-        a = RPythonAnnotator(policy=policy)
-        s = a.build_types(f, [])
-        assert isinstance(s, annmodel.SomeFloat)
-        assert a.translator._graphof(callback)
-
     def test_register_external_signature(self):
         """
         Test the standard interface for external functions.
@@ -198,5 +172,5 @@
             return os_execve(l)
         py.test.raises(Exception, a.build_types, g, [[str]])
         a.build_types(g, [[str0]])  # Does not raise
-        
 
+
diff --git a/rpython/rtyper/test/test_rgeneric.py 
b/rpython/rtyper/test/test_rgeneric.py
deleted file mode 100644
--- a/rpython/rtyper/test/test_rgeneric.py
+++ /dev/null
@@ -1,47 +0,0 @@
-from rpython.rtyper.rtyper import RPythonTyper
-from rpython.annotator import model as annmodel
-from rpython.annotator.annrpython import RPythonAnnotator
-from rpython.annotator import policy
-from rpython.rtyper.test.test_llinterp import interpret, interpret_raises
-
-import py
-from rpython.rtyper.test.tool import LLRtypeMixin, OORtypeMixin
-
-class BaseRGenericTest:
-    def test_some_generic_function_call(self):
-        def h(x):
-            return int(x)
-
-        def c(x):
-            return int(x) + 1
-
-        def default(x):
-            return int(x) + 3
-        
-        def g(a, x):
-            if x == -1:
-                a = None
-            if x > 0:
-                if x == 1:
-                    a = h
-                else:
-                    a = c
-                x = x + 0.01
-            return a(x)
-
-        def f(x):
-            return g(default, x)
-
-        g._annenforceargs_ = policy.Sig(annmodel.SomeGenericCallable(
-            args=[annmodel.SomeFloat()], result=annmodel.SomeInteger()),
-                                        float)
-
-        assert interpret(f, [1.]) == 1
-        assert interpret(f, [10.]) == 11
-        assert interpret(f, [-3.]) == 0
-
-class TestLLRgeneric(BaseRGenericTest, LLRtypeMixin):
-    pass
-
-class TestOORgeneric(BaseRGenericTest, OORtypeMixin):
-    pass
diff --git a/rpython/rtyper/typesystem.py b/rpython/rtyper/typesystem.py
--- a/rpython/rtyper/typesystem.py
+++ b/rpython/rtyper/typesystem.py
@@ -21,7 +21,7 @@
             except ImportError:
                 return None
         if name in ('rclass', 'rpbc', 'rbuiltin', 'rtuple', 'rlist',
-                    'rslice', 'rdict', 'rrange', 'rstr', 'rgeneric',
+                    'rslice', 'rdict', 'rrange', 'rstr',
                     'll_str', 'rbuilder', 'rvirtualizable2', 'rbytearray',
                     'exceptiondata'):
             mod = load(name)
@@ -50,7 +50,7 @@
     def getcallabletype(self, ARGS, RESTYPE):
         cls = self.callable_trait[0]
         return cls(ARGS, RESTYPE)
-        
+
     def getcallable(self, graph, getconcretetype=None):
         """Return callable given a Python function."""
         if getconcretetype is None:
@@ -59,7 +59,7 @@
         lloutput = getconcretetype(graph.getreturnvar())
 
         typ, constr = self.callable_trait
-        
+
         FT = typ(llinputs, lloutput)
         name = graph.name
         if hasattr(graph, 'func') and callable(graph.func):
@@ -138,7 +138,7 @@
         if robj1.lowleveltype != robj2.lowleveltype:
             raise TyperError('is of instances of different pointer types: %r, 
%r' % (
                 roriginal1, roriginal2))
-            
+
         v_list = hop.inputargs(robj1, robj2)
         return hop.genop('ptr_eq', v_list, resulttype=lltype.Bool)
 
@@ -177,7 +177,7 @@
              robj2.lowleveltype is not ootype.Class):
             raise TyperError('is of instances of the non-instances: %r, %r' % (
                 roriginal1, roriginal2))
-            
+
         v_list = hop.inputargs(robj1, robj2)
         return hop.genop('oois', v_list, resulttype=lltype.Bool)
 
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to