[pypy-commit] pypy disable_merge_different_int_types: (arigo, bivab): allow to merge different int types if they have both the same signedness. Generalizing to the larger type
bivab
noreply at buildbot.pypy.org
Wed Nov 23 18:04:21 CET 2011
Author: David Schneider <david.schneider at picle.org>
Branch: disable_merge_different_int_types
Changeset: r49697:b336e9e40643
Date: 2011-11-23 17:40 +0100
http://bitbucket.org/pypy/pypy/changeset/b336e9e40643/
Log: (arigo, bivab): allow to merge different int types if they have both
the same signedness. Generalizing to the larger type
diff --git a/pypy/annotation/binaryop.py b/pypy/annotation/binaryop.py
--- a/pypy/annotation/binaryop.py
+++ b/pypy/annotation/binaryop.py
@@ -252,32 +252,30 @@
# unsignedness is considered a rare and contagious disease
def union((int1, int2)):
- t1 = int1.knowntype
- if t1 is bool:
- t1 = int
- t2 = int2.knowntype
- if t2 is bool:
- t2 = int
+ if int1.unsigned == int2.unsigned:
+ knowntype = rarithmetic.compute_restype(int1.knowntype, int2.knowntype)
+ else:
+ 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 (t1 is int and t2 is rarithmetic.r_int) or (
- t2 is int and t1 is rarithmetic.r_int):
- knowntype = rarithmetic.r_int
- elif t2 is int:
- if not int2.is_constant():
- raise UnionError, "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 UnionError, "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 UnionError, "Merging these types (%s, %s) is not supported" % (t1, t2)
+ if t2 is int:
+ if not int2.is_constant():
+ raise UnionError, "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 UnionError, "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 UnionError, "Merging these types (%s, %s) is not supported" % (t1, t2)
return SomeInteger(nonneg=int1.nonneg and int2.nonneg,
knowntype=knowntype)
diff --git a/pypy/rlib/rarithmetic.py b/pypy/rlib/rarithmetic.py
--- a/pypy/rlib/rarithmetic.py
+++ b/pypy/rlib/rarithmetic.py
@@ -143,6 +143,8 @@
return self_type
if self_type in (bool, int, long):
return other_type
+ if self_type.SIGNED == other_type.SIGNED:
+ return build_int(None, self_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):
More information about the pypy-commit
mailing list