Rename to WrappingRange

This commit is contained in:
Andreas Liljeqvist 2021-08-23 14:24:34 +02:00
parent 70433955f4
commit e8e6d9bd86
4 changed files with 19 additions and 22 deletions

View File

@ -17,7 +17,7 @@ use rustc_middle::mir::mono::MonoItem;
use rustc_middle::ty::{self, Instance, Ty};
use rustc_middle::{bug, span_bug};
use rustc_target::abi::{
AddressSpace, Align, AllocationRange, HasDataLayout, LayoutOf, Primitive, Scalar, Size,
AddressSpace, Align, HasDataLayout, LayoutOf, Primitive, Scalar, Size, WrappingRange,
};
use tracing::debug;
@ -61,10 +61,7 @@ pub fn const_alloc_to_llvm(cx: &CodegenCx<'ll, '_>, alloc: &Allocation) -> &'ll
Pointer::new(alloc_id, Size::from_bytes(ptr_offset)),
&cx.tcx,
),
&Scalar {
value: Primitive::Pointer,
valid_range: AllocationRange { start: 0, end: !0 },
},
&Scalar { value: Primitive::Pointer, valid_range: WrappingRange { start: 0, end: !0 } },
cx.type_i8p_ext(address_space),
));
next_offset = offset + pointer_size;

View File

@ -499,7 +499,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
let scalar_unit = |value: Primitive| {
let bits = value.size(dl).bits();
assert!(bits <= 128);
Scalar { value, valid_range: AllocationRange { start: 0, end: (!0 >> (128 - bits)) } }
Scalar { value, valid_range: WrappingRange { start: 0, end: (!0 >> (128 - bits)) } }
};
let scalar = |value: Primitive| tcx.intern_layout(Layout::scalar(self, scalar_unit(value)));
@ -512,13 +512,13 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
// Basic scalars.
ty::Bool => tcx.intern_layout(Layout::scalar(
self,
Scalar { value: Int(I8, false), valid_range: AllocationRange { start: 0, end: 1 } },
Scalar { value: Int(I8, false), valid_range: WrappingRange { start: 0, end: 1 } },
)),
ty::Char => tcx.intern_layout(Layout::scalar(
self,
Scalar {
value: Int(I32, false),
valid_range: AllocationRange { start: 0, end: 0x10FFFF },
valid_range: WrappingRange { start: 0, end: 0x10FFFF },
},
)),
ty::Int(ity) => scalar(Int(Integer::from_int_ty(dl, ity), true)),
@ -529,7 +529,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
}),
ty::FnPtr(_) => {
let mut ptr = scalar_unit(Pointer);
ptr.valid_range = AllocationRange { start: 1, end: ptr.valid_range.end };
ptr.valid_range = WrappingRange { start: 1, end: ptr.valid_range.end };
tcx.intern_layout(Layout::scalar(self, ptr))
}
@ -548,7 +548,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
let mut data_ptr = scalar_unit(Pointer);
if !ty.is_unsafe_ptr() {
data_ptr.valid_range =
AllocationRange { start: 1, end: data_ptr.valid_range.end };
WrappingRange { start: 1, end: data_ptr.valid_range.end };
}
let pointee = tcx.normalize_erasing_regions(param_env, pointee);
@ -565,7 +565,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
ty::Dynamic(..) => {
let mut vtable = scalar_unit(Pointer);
vtable.valid_range =
AllocationRange { start: 1, end: vtable.valid_range.end };
WrappingRange { start: 1, end: vtable.valid_range.end };
vtable
}
_ => return Err(LayoutError::Unknown(unsized_part)),
@ -1261,7 +1261,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
let tag_mask = !0u128 >> (128 - ity.size().bits());
let tag = Scalar {
value: Int(ity, signed),
valid_range: AllocationRange {
valid_range: WrappingRange {
start: (min as u128 & tag_mask),
end: (max as u128 & tag_mask),
},
@ -1545,7 +1545,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
let discr_int_ty = discr_int.to_ty(tcx, false);
let tag = Scalar {
value: Primitive::Int(discr_int, false),
valid_range: AllocationRange { start: 0, end: max_discr },
valid_range: WrappingRange { start: 0, end: max_discr },
};
let tag_layout = self.tcx.intern_layout(Layout::scalar(self, tag.clone()));
let tag_layout = TyAndLayout { ty: discr_int_ty, layout: tag_layout };

View File

@ -15,7 +15,7 @@ use rustc_middle::ty;
use rustc_middle::ty::layout::TyAndLayout;
use rustc_span::symbol::{sym, Symbol};
use rustc_target::abi::{
Abi, AllocationRange, LayoutOf, Scalar as ScalarAbi, Size, VariantIdx, Variants,
Abi, LayoutOf, Scalar as ScalarAbi, Size, VariantIdx, Variants, WrappingRange,
};
use std::hash::Hash;
@ -184,8 +184,8 @@ fn write_path(out: &mut String, path: &[PathElem]) {
// Formats such that a sentence like "expected something {}" to mean
// "expected something <in the given range>" makes sense.
fn wrapping_range_format(r: AllocationRange, max_hi: u128) -> String {
let AllocationRange { start: lo, end: hi } = r;
fn wrapping_range_format(r: WrappingRange, max_hi: u128) -> String {
let WrappingRange { start: lo, end: hi } = r;
assert!(hi <= max_hi);
if lo > hi {
format!("less or equal to {}, or greater or equal to {}", hi, lo)
@ -624,7 +624,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
) -> InterpResult<'tcx> {
let value = self.read_scalar(op)?;
let valid_range = scalar_layout.valid_range.clone();
let AllocationRange { start: lo, end: hi } = valid_range;
let WrappingRange { start: lo, end: hi } = valid_range;
// Determine the allowed range
// `max_hi` is as big as the size fits
let max_hi = u128::MAX >> (128 - op.layout.size.bits());

View File

@ -690,12 +690,12 @@ impl Primitive {
/// semantics.
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
#[derive(HashStable_Generic)]
pub struct AllocationRange {
pub struct WrappingRange {
pub start: u128,
pub end: u128,
}
impl AllocationRange {
impl WrappingRange {
/// Returns `true` if `v` is contained in the range.
#[inline]
pub fn contains(&self, v: u128) -> bool {
@ -723,13 +723,13 @@ pub struct Scalar {
// FIXME(eddyb) always use the shortest range, e.g., by finding
// the largest space between two consecutive valid values and
// taking everything else as the (shortest) valid range.
pub valid_range: AllocationRange,
pub valid_range: WrappingRange,
}
impl Scalar {
pub fn is_bool(&self) -> bool {
matches!(self.value, Int(I8, false))
&& matches!(self.valid_range, AllocationRange { start: 0, end: 1 })
&& matches!(self.valid_range, WrappingRange { start: 0, end: 1 })
}
/// Returns the valid range as a `x..y` range.
@ -1022,7 +1022,7 @@ impl Niche {
return None;
}
Some((start, Scalar { value, valid_range: AllocationRange { start: v.start, end } }))
Some((start, Scalar { value, valid_range: WrappingRange { start: v.start, end } }))
}
}