[pypy-commit] pypy online-transforms: rtype unbound builtin methods

rlamy noreply at buildbot.pypy.org
Wed Oct 29 20:00:48 CET 2014


Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: online-transforms
Changeset: r74281:1b205e84aafe
Date: 2014-10-29 19:00 +0000
http://bitbucket.org/pypy/pypy/changeset/1b205e84aafe/

Log:	rtype unbound builtin methods

diff --git a/rpython/rtyper/rbuiltin.py b/rpython/rtyper/rbuiltin.py
--- a/rpython/rtyper/rbuiltin.py
+++ b/rpython/rtyper/rbuiltin.py
@@ -7,7 +7,7 @@
 from rpython.rtyper import rclass
 from rpython.rtyper.rmodel import Repr
 from rpython.tool.pairtype import pairtype
-from rpython.tool.descriptor import normalize_method
+from rpython.tool.descriptor import normalize_method, InstanceMethod
 
 
 BUILTIN_TYPER = {}
@@ -86,7 +86,7 @@
     def __init__(self, builtinfunc):
         self.builtinfunc = builtinfunc
 
-    def findbltintyper(self, rtyper):
+    def findbltintyper(self, hop):
         "Find the function to use to specialize calls to this built-in func."
         try:
             return BUILTIN_TYPER[self.builtinfunc]
@@ -95,11 +95,18 @@
         if extregistry.is_registered(self.builtinfunc):
             entry = extregistry.lookup(self.builtinfunc)
             return entry.specialize_call
+        if isinstance(self.builtinfunc, InstanceMethod):
+            assert self.builtinfunc.im_self is None
+            name = 'rtype_method_' + self.builtinfunc.im_func.__name__
+            try:
+                return getattr(hop.args_r[0], name)
+            except AttributeError:
+                pass
         raise TyperError("don't know about built-in function %r" % (
             self.builtinfunc,))
 
     def _call(self, hop2, **kwds_i):
-        bltintyper = self.findbltintyper(hop2.rtyper)
+        bltintyper = self.findbltintyper(hop2)
         hop2.llops._called_exception_is_here_or_cannot_occur = False
         v_result = bltintyper(hop2, **kwds_i)
         if not hop2.llops._called_exception_is_here_or_cannot_occur:
diff --git a/rpython/rtyper/test/test_rbuiltin.py b/rpython/rtyper/test/test_rbuiltin.py
--- a/rpython/rtyper/test/test_rbuiltin.py
+++ b/rpython/rtyper/test/test_rbuiltin.py
@@ -38,6 +38,16 @@
         res = self.interpret(f, [])
         assert self.ll_to_string(res) == 'abc, def123'
 
+    def test_str_join_unbound(self):
+        def g(n):
+            if n:
+                return ["foo", "bar"]
+        def f(n):
+            g(0)
+            return str.join('', g(n))
+        res = self.interpret(f, [1])
+        assert self.ll_to_string(res) == "foobar"
+
     def test_method_repr(self):
         def g(n):
             if n >= 0:


More information about the pypy-commit mailing list