[pypy-commit] pypy disable_merge_different_int_types: (arigo, bivab) allow merging unsigned and non-negative signed values

bivab noreply at buildbot.pypy.org
Mon Nov 28 15:55:49 CET 2011


Author: David Schneider <david.schneider at picle.org>
Branch: disable_merge_different_int_types
Changeset: r49909:8e235e060794
Date: 2011-11-28 14:12 +0100
http://bitbucket.org/pypy/pypy/changeset/8e235e060794/

Log:	(arigo, bivab) allow merging unsigned and non-negative signed values

diff --git a/pypy/annotation/binaryop.py b/pypy/annotation/binaryop.py
--- a/pypy/annotation/binaryop.py
+++ b/pypy/annotation/binaryop.py
@@ -263,17 +263,13 @@
                 t2 = int
 
             if t2 is int:
-                if not int2.is_constant():
-                   raise UnionError, "Merging %s and a non-constant int is not allowed" % t1
+                if int2.nonneg == False:
+                    raise UnionError, "Merging %s and a possibly negative int is not allowed" % t1
                 knowntype = t1
-                # ensure constant int2 is in range of t1
-                t1(int2.const)
             elif t1 is int:
-                if not int1.is_constant():
-                   raise UnionError, "Merging %s and a non-constant int is not allowed" % t2
+                if int1.nonneg == False:
+                    raise UnionError, "Merging %s and a possibly negative int is not allowed" % t2
                 knowntype = t2
-                # ensure constant int1 is in range of t2
-                t2(int1.const)
             else:
                 raise UnionError, "Merging these types (%s, %s) is not supported" % (t1, t2)
         return SomeInteger(nonneg=int1.nonneg and int2.nonneg,
diff --git a/pypy/annotation/test/test_annrpython.py b/pypy/annotation/test/test_annrpython.py
--- a/pypy/annotation/test/test_annrpython.py
+++ b/pypy/annotation/test/test_annrpython.py
@@ -883,6 +883,18 @@
         s = a.build_types(f, [r_uint])
         assert s == annmodel.SomeInteger(nonneg = True, unsigned = True)
 
+    def test_merge_ruint_nonneg_signed(self):
+        def f(a, b):
+            if a:
+                c = a
+            else:
+                assert b >= 0
+                c = b
+            return c
+        a = self.RPythonAnnotator()
+        s = a.build_types(f, [r_uint, int])
+        assert s == annmodel.SomeInteger(nonneg = True, unsigned = True)
+
 
     def test_prebuilt_long_that_is_not_too_long(self):
         small_constant = 12L


More information about the pypy-commit mailing list