[pypy-commit] pypy disable_merge_different_int_types: (arigo, bivab): enforce sanity when merging inttypes
bivab
noreply at buildbot.pypy.org
Wed Nov 23 14:59:08 CET 2011
Author: David Schneider <david.schneider at picle.org>
Branch: disable_merge_different_int_types
Changeset: r49686:3cb58bdf354f
Date: 2011-11-23 14:50 +0100
http://bitbucket.org/pypy/pypy/changeset/3cb58bdf354f/
Log: (arigo, bivab): enforce sanity when merging inttypes
diff --git a/pypy/annotation/binaryop.py b/pypy/annotation/binaryop.py
--- a/pypy/annotation/binaryop.py
+++ b/pypy/annotation/binaryop.py
@@ -252,7 +252,29 @@
# unsignedness is considered a rare and contagious disease
def union((int1, int2)):
- knowntype = rarithmetic.compute_restype(int1.knowntype, int2.knowntype)
+ t1 = int1.knowntype
+ if t1 is bool:
+ t1 = int
+ t2 = int2.knowntype
+ if t2 is bool:
+ t2 = int
+
+ if t1 is t2:
+ knowntype = t1
+ elif t2 is int:
+ if not int2.is_constant():
+ raise Exception, "Merging %s and a non-constant 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 Exception, "Merging %s and a non-constant int is not allowed" % t2
+ knowntype = t2
+ # ensure constant int1 is in range of t2
+ t2(int1.const)
+ else:
+ raise Exception, "Merging these types (%s, %s) is not supported" % (t1, t2)
return SomeInteger(nonneg=int1.nonneg and int2.nonneg,
knowntype=knowntype)
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
@@ -856,6 +856,34 @@
py.test.raises(Exception, a.build_types, f, [])
# if you want to get a r_uint, you have to be explicit about it
+ def test_add_different_ints(self):
+ def f(a, b):
+ return a + b
+ a = self.RPythonAnnotator()
+ py.test.raises(Exception, a.build_types, f, [r_uint, int])
+
+ def test_merge_different_ints(self):
+ def f(a, b):
+ if a:
+ c = a
+ else:
+ c = b
+ return c
+ a = self.RPythonAnnotator()
+ py.test.raises(Exception, a.build_types, f, [r_uint, int])
+
+ def test_merge_ruint_zero(self):
+ def f(a):
+ if a:
+ c = a
+ else:
+ c = 0
+ return c
+ a = self.RPythonAnnotator()
+ s = a.build_types(f, [r_uint])
+ assert s == annmodel.SomeInteger(nonneg = True, unsigned = True)
+
+
def test_prebuilt_long_that_is_not_too_long(self):
small_constant = 12L
def f():
@@ -3029,7 +3057,7 @@
if g(x, y):
g(x, r_uint(y))
a = self.RPythonAnnotator()
- a.build_types(f, [int, int])
+ py.test.raises(Exception, a.build_types, f, [int, int])
def test_compare_with_zero(self):
def g():
diff --git a/pypy/rlib/rarithmetic.py b/pypy/rlib/rarithmetic.py
--- a/pypy/rlib/rarithmetic.py
+++ b/pypy/rlib/rarithmetic.py
@@ -143,7 +143,7 @@
return self_type
if self_type in (bool, int, long):
return other_type
- return build_int(None, self_type.SIGNED and other_type.SIGNED, max(self_type.BITS, other_type.BITS))
+ raise AssertionError, "Merging these types (%s, %s) is not supported" % (self_type, other_type)
def signedtype(t):
if t in (bool, int, long):
diff --git a/pypy/rlib/test/test_rarithmetic.py b/pypy/rlib/test/test_rarithmetic.py
--- a/pypy/rlib/test/test_rarithmetic.py
+++ b/pypy/rlib/test/test_rarithmetic.py
@@ -335,6 +335,14 @@
from pypy.rpython.lltypesystem.rffi import r_int_real
assert compute_restype(r_int_real, r_int_real) is r_int_real
+def test_compute_restype_incompatible():
+ from pypy.rpython.lltypesystem.rffi import r_int_real, r_short, r_ushort
+ testcases = [(r_uint, r_longlong), (r_int_real, r_uint),
+ (r_short, r_ushort), (r_ushort, r_uint)]
+ for t1, t2 in testcases:
+ py.test.raises(AssertionError, compute_restype, t1, t2)
+ py.test.raises(AssertionError, compute_restype, t2, t1)
+
def test_most_neg_value_of():
assert most_neg_value_of_same_type(123) == -sys.maxint-1
assert most_neg_value_of_same_type(r_uint(123)) == 0
More information about the pypy-commit
mailing list