Calculate discriminant bounds within 64 bits

Since discriminants do not support i128 yet, lets just calculate the boundaries within the 64 bits
that are supported. This also avoids an issue with bootstrapping on 32 bit systems due to #38727.
This commit is contained in:
Simonas Kazlauskas 2016-12-31 04:55:29 +02:00
parent 6b359635ec
commit ee69cd7925
5 changed files with 17 additions and 10 deletions

View file

@ -20,7 +20,8 @@ use ty::{self, Ty, TyCtxt, TypeFoldable};
use syntax::ast::{FloatTy, IntTy, UintTy};
use syntax::attr;
use syntax_pos::DUMMY_SP;
use rustc_i128::{i128, u128};
use rustc_i128::u128;
use rustc_const_math::ConstInt;
use std::cmp;
use std::fmt;
@ -1198,20 +1199,25 @@ impl<'a, 'gcx, 'tcx> Layout {
if def.is_enum() && def.variants.iter().all(|v| v.fields.is_empty()) {
// All bodies empty -> intlike
let (mut min, mut max, mut non_zero) = (i128::max_value(),
i128::min_value(),
let (mut min, mut max, mut non_zero) = (i64::max_value(),
i64::min_value(),
true);
for v in &def.variants {
let x = v.disr_val.to_u128_unchecked() as i128;
let x = match v.disr_val.erase_type() {
ConstInt::InferSigned(i) => i as i64,
ConstInt::Infer(i) => i as u64 as i64,
_ => bug!()
};
if x == 0 { non_zero = false; }
if x < min { min = x; }
if x > max { max = x; }
}
// FIXME: should take i128?
// FIXME: should handle i128? signed-value based impl is weird and hard to
// grok.
let (discr, signed) = Integer::repr_discr(tcx, ty, &hints[..],
min as i64,
max as i64);
min,
max);
return success(CEnum {
discr: discr,
signed: signed,