[pypy-commit] pypy jit-ordereddict: It doesn't make sense for bytearray() to return a constant,

arigo noreply at buildbot.pypy.org
Wed Dec 25 22:01:03 CET 2013


Author: Armin Rigo <arigo at tunes.org>
Branch: jit-ordereddict
Changeset: r68545:621e891ddae3
Date: 2013-12-25 22:00 +0100
http://bitbucket.org/pypy/pypy/changeset/621e891ddae3/

Log:	It doesn't make sense for bytearray() to return a constant, either
	at annotation or during rtyping.

diff --git a/rpython/annotator/builtin.py b/rpython/annotator/builtin.py
--- a/rpython/annotator/builtin.py
+++ b/rpython/annotator/builtin.py
@@ -122,7 +122,7 @@
     return constpropagate(unicode, [s_unicode], SomeUnicodeString())
 
 def builtin_bytearray(s_str):
-    return constpropagate(bytearray, [s_str], SomeByteArray())
+    return SomeByteArray()
 
 def our_issubclass(cls1, cls2):
     """ we're going to try to be less silly in the face of old-style classes"""
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
@@ -3987,7 +3987,9 @@
             return bytearray("xyz")
 
         a = self.RPythonAnnotator()
-        assert isinstance(a.build_types(f, []), annmodel.SomeByteArray)
+        s = a.build_types(f, [])
+        assert isinstance(s, annmodel.SomeByteArray)
+        assert not s.is_constant()   # never a constant!
 
     def test_bytearray_add(self):
         def f(a):
diff --git a/rpython/rtyper/rstr.py b/rpython/rtyper/rstr.py
--- a/rpython/rtyper/rstr.py
+++ b/rpython/rtyper/rstr.py
@@ -400,10 +400,6 @@
         return hop.gendirectcall(self.ll.ll_str2unicode, v_str)
 
     def rtype_bytearray(self, hop):
-        if hop.args_s[0].is_constant():
-            # convertion errors occur during annotation, so cannot any more:
-            hop.exception_cannot_occur()
-            return hop.inputconst(hop.r_result, hop.s_result.const)
         hop.exception_is_here()
         return hop.gendirectcall(self.ll.ll_str2bytearray,
                                  hop.inputarg(hop.args_r[0].repr, 0))
diff --git a/rpython/rtyper/test/test_rbytearray.py b/rpython/rtyper/test/test_rbytearray.py
--- a/rpython/rtyper/test/test_rbytearray.py
+++ b/rpython/rtyper/test/test_rbytearray.py
@@ -57,3 +57,17 @@
 
         ll_res = self.interpret(f, [123])
         assert hlstr(ll_res) == "2"
+
+    def test_bytearray_not_constant(self):
+        for constant in ['f', 'foo']:
+            def f(x):
+                i = 0
+                total = 0
+                while i < x:
+                    b = bytearray(constant)
+                    b[0] = b[0] + 1
+                    total += b[0]
+                    i += 1
+                return total
+            ll_res = self.interpret(f, [5])
+            assert ll_res == f(5)


More information about the pypy-commit mailing list