Rename to WrappingRange
This commit is contained in:
parent
70433955f4
commit
e8e6d9bd86
4 changed files with 19 additions and 22 deletions
|
@ -17,7 +17,7 @@ use rustc_middle::mir::mono::MonoItem;
|
||||||
use rustc_middle::ty::{self, Instance, Ty};
|
use rustc_middle::ty::{self, Instance, Ty};
|
||||||
use rustc_middle::{bug, span_bug};
|
use rustc_middle::{bug, span_bug};
|
||||||
use rustc_target::abi::{
|
use rustc_target::abi::{
|
||||||
AddressSpace, Align, AllocationRange, HasDataLayout, LayoutOf, Primitive, Scalar, Size,
|
AddressSpace, Align, HasDataLayout, LayoutOf, Primitive, Scalar, Size, WrappingRange,
|
||||||
};
|
};
|
||||||
use tracing::debug;
|
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)),
|
Pointer::new(alloc_id, Size::from_bytes(ptr_offset)),
|
||||||
&cx.tcx,
|
&cx.tcx,
|
||||||
),
|
),
|
||||||
&Scalar {
|
&Scalar { value: Primitive::Pointer, valid_range: WrappingRange { start: 0, end: !0 } },
|
||||||
value: Primitive::Pointer,
|
|
||||||
valid_range: AllocationRange { start: 0, end: !0 },
|
|
||||||
},
|
|
||||||
cx.type_i8p_ext(address_space),
|
cx.type_i8p_ext(address_space),
|
||||||
));
|
));
|
||||||
next_offset = offset + pointer_size;
|
next_offset = offset + pointer_size;
|
||||||
|
|
|
@ -499,7 +499,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
|
||||||
let scalar_unit = |value: Primitive| {
|
let scalar_unit = |value: Primitive| {
|
||||||
let bits = value.size(dl).bits();
|
let bits = value.size(dl).bits();
|
||||||
assert!(bits <= 128);
|
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)));
|
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.
|
// Basic scalars.
|
||||||
ty::Bool => tcx.intern_layout(Layout::scalar(
|
ty::Bool => tcx.intern_layout(Layout::scalar(
|
||||||
self,
|
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(
|
ty::Char => tcx.intern_layout(Layout::scalar(
|
||||||
self,
|
self,
|
||||||
Scalar {
|
Scalar {
|
||||||
value: Int(I32, false),
|
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)),
|
ty::Int(ity) => scalar(Int(Integer::from_int_ty(dl, ity), true)),
|
||||||
|
@ -529,7 +529,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
|
||||||
}),
|
}),
|
||||||
ty::FnPtr(_) => {
|
ty::FnPtr(_) => {
|
||||||
let mut ptr = scalar_unit(Pointer);
|
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))
|
tcx.intern_layout(Layout::scalar(self, ptr))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -548,7 +548,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
|
||||||
let mut data_ptr = scalar_unit(Pointer);
|
let mut data_ptr = scalar_unit(Pointer);
|
||||||
if !ty.is_unsafe_ptr() {
|
if !ty.is_unsafe_ptr() {
|
||||||
data_ptr.valid_range =
|
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);
|
let pointee = tcx.normalize_erasing_regions(param_env, pointee);
|
||||||
|
@ -565,7 +565,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
|
||||||
ty::Dynamic(..) => {
|
ty::Dynamic(..) => {
|
||||||
let mut vtable = scalar_unit(Pointer);
|
let mut vtable = scalar_unit(Pointer);
|
||||||
vtable.valid_range =
|
vtable.valid_range =
|
||||||
AllocationRange { start: 1, end: vtable.valid_range.end };
|
WrappingRange { start: 1, end: vtable.valid_range.end };
|
||||||
vtable
|
vtable
|
||||||
}
|
}
|
||||||
_ => return Err(LayoutError::Unknown(unsized_part)),
|
_ => 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_mask = !0u128 >> (128 - ity.size().bits());
|
||||||
let tag = Scalar {
|
let tag = Scalar {
|
||||||
value: Int(ity, signed),
|
value: Int(ity, signed),
|
||||||
valid_range: AllocationRange {
|
valid_range: WrappingRange {
|
||||||
start: (min as u128 & tag_mask),
|
start: (min as u128 & tag_mask),
|
||||||
end: (max 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 discr_int_ty = discr_int.to_ty(tcx, false);
|
||||||
let tag = Scalar {
|
let tag = Scalar {
|
||||||
value: Primitive::Int(discr_int, false),
|
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 = self.tcx.intern_layout(Layout::scalar(self, tag.clone()));
|
||||||
let tag_layout = TyAndLayout { ty: discr_int_ty, layout: tag_layout };
|
let tag_layout = TyAndLayout { ty: discr_int_ty, layout: tag_layout };
|
||||||
|
|
|
@ -15,7 +15,7 @@ use rustc_middle::ty;
|
||||||
use rustc_middle::ty::layout::TyAndLayout;
|
use rustc_middle::ty::layout::TyAndLayout;
|
||||||
use rustc_span::symbol::{sym, Symbol};
|
use rustc_span::symbol::{sym, Symbol};
|
||||||
use rustc_target::abi::{
|
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;
|
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
|
// Formats such that a sentence like "expected something {}" to mean
|
||||||
// "expected something <in the given range>" makes sense.
|
// "expected something <in the given range>" makes sense.
|
||||||
fn wrapping_range_format(r: AllocationRange, max_hi: u128) -> String {
|
fn wrapping_range_format(r: WrappingRange, max_hi: u128) -> String {
|
||||||
let AllocationRange { start: lo, end: hi } = r;
|
let WrappingRange { start: lo, end: hi } = r;
|
||||||
assert!(hi <= max_hi);
|
assert!(hi <= max_hi);
|
||||||
if lo > hi {
|
if lo > hi {
|
||||||
format!("less or equal to {}, or greater or equal to {}", hi, lo)
|
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> {
|
) -> InterpResult<'tcx> {
|
||||||
let value = self.read_scalar(op)?;
|
let value = self.read_scalar(op)?;
|
||||||
let valid_range = scalar_layout.valid_range.clone();
|
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
|
// Determine the allowed range
|
||||||
// `max_hi` is as big as the size fits
|
// `max_hi` is as big as the size fits
|
||||||
let max_hi = u128::MAX >> (128 - op.layout.size.bits());
|
let max_hi = u128::MAX >> (128 - op.layout.size.bits());
|
||||||
|
|
|
@ -690,12 +690,12 @@ impl Primitive {
|
||||||
/// semantics.
|
/// semantics.
|
||||||
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
|
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
|
||||||
#[derive(HashStable_Generic)]
|
#[derive(HashStable_Generic)]
|
||||||
pub struct AllocationRange {
|
pub struct WrappingRange {
|
||||||
pub start: u128,
|
pub start: u128,
|
||||||
pub end: u128,
|
pub end: u128,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AllocationRange {
|
impl WrappingRange {
|
||||||
/// Returns `true` if `v` is contained in the range.
|
/// Returns `true` if `v` is contained in the range.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn contains(&self, v: u128) -> bool {
|
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
|
// FIXME(eddyb) always use the shortest range, e.g., by finding
|
||||||
// the largest space between two consecutive valid values and
|
// the largest space between two consecutive valid values and
|
||||||
// taking everything else as the (shortest) valid range.
|
// taking everything else as the (shortest) valid range.
|
||||||
pub valid_range: AllocationRange,
|
pub valid_range: WrappingRange,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Scalar {
|
impl Scalar {
|
||||||
pub fn is_bool(&self) -> bool {
|
pub fn is_bool(&self) -> bool {
|
||||||
matches!(self.value, Int(I8, false))
|
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.
|
/// Returns the valid range as a `x..y` range.
|
||||||
|
@ -1022,7 +1022,7 @@ impl Niche {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
Some((start, Scalar { value, valid_range: AllocationRange { start: v.start, end } }))
|
Some((start, Scalar { value, valid_range: WrappingRange { start: v.start, end } }))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue