remove check_raw after reducing it to one use only

This commit is contained in:
Ralf Jung 2020-02-28 09:15:04 +01:00
parent e9ab099d6f
commit 1fec68277a
2 changed files with 16 additions and 23 deletions

View File

@ -382,19 +382,14 @@ impl<'tcx, Tag> Scalar<Tag> {
}
}
#[inline(always)]
pub fn check_raw(data: u128, size: u8, target_size: Size) {
assert_eq!(target_size.bytes(), size as u64);
assert_ne!(size, 0, "you should never look at the bits of a ZST");
Scalar::check_data(data, size);
}
/// Do not call this method! Use either `assert_bits` or `force_bits`.
#[inline]
pub fn to_bits(self, target_size: Size) -> InterpResult<'tcx, u128> {
match self {
Scalar::Raw { data, size } => {
Self::check_raw(data, size, target_size);
assert_eq!(target_size.bytes(), size as u64);
assert_ne!(size, 0, "you should never look at the bits of a ZST");
Scalar::check_data(data, size);
Ok(data)
}
Scalar::Ptr(_) => throw_unsup!(ReadPointerAsBytes),

View File

@ -1396,21 +1396,19 @@ impl<'tcx> IntRange<'tcx> {
) -> Option<IntRange<'tcx>> {
if let Some((target_size, bias)) = Self::integral_size_and_signed_bias(tcx, value.ty) {
let ty = value.ty;
let val = if let ty::ConstKind::Value(ConstValue::Scalar(Scalar::Raw { data, size })) =
value.val
{
// For this specific pattern we can skip a lot of effort and go
// straight to the result, after doing a bit of checking. (We
// could remove this branch and just use the next branch, which
// is more general but much slower.)
Scalar::<()>::check_raw(data, size, target_size);
data
} else if let Some(val) = value.try_eval_bits(tcx, param_env, ty) {
// This is a more general form of the previous branch.
val
} else {
return None;
};
let val = (|| {
if let ty::ConstKind::Value(ConstValue::Scalar(scalar)) = value.val {
// For this specific pattern we can skip a lot of effort and go
// straight to the result, after doing a bit of checking. (We
// could remove this branch and just fall through, which
// is more general but much slower.)
if let Ok(bits) = scalar.to_bits_or_ptr(target_size, &tcx) {
return Some(bits);
}
}
// This is a more general form of the previous case.
value.try_eval_bits(tcx, param_env, ty)
})()?;
let val = val ^ bias;
Some(IntRange { range: val..=val, ty, span })
} else {