1
Fork 0

s/Scalar::Raw/Scalar::Int

This commit is contained in:
oli 2020-11-01 16:57:03 +00:00
parent 3a7970848c
commit df4d717d0b
13 changed files with 48 additions and 48 deletions

View file

@ -137,7 +137,7 @@ pub(super) fn op_to_const<'tcx>(
let alloc = ecx.tcx.global_alloc(ptr.alloc_id).unwrap_memory();
ConstValue::ByRef { alloc, offset: ptr.offset }
}
Scalar::Raw(int) => {
Scalar::Int(int) => {
assert!(mplace.layout.is_zst());
assert_eq!(
int.assert_bits(ecx.tcx.data_layout.pointer_size)
@ -162,7 +162,7 @@ pub(super) fn op_to_const<'tcx>(
Scalar::Ptr(ptr) => {
(ecx.tcx.global_alloc(ptr.alloc_id).unwrap_memory(), ptr.offset.bytes())
}
Scalar::Raw { .. } => (
Scalar::Int { .. } => (
ecx.tcx
.intern_const_alloc(Allocation::from_byte_aligned_bytes(b"" as &[u8])),
0,

View file

@ -181,9 +181,9 @@ impl<'mir, 'tcx: 'mir> CompileTimeEvalContext<'mir, 'tcx> {
fn guaranteed_eq(&mut self, a: Scalar, b: Scalar) -> bool {
match (a, b) {
// Comparisons between integers are always known.
(Scalar::Raw { .. }, Scalar::Raw { .. }) => a == b,
(Scalar::Int { .. }, Scalar::Int { .. }) => a == b,
// Equality with integers can never be known for sure.
(Scalar::Raw { .. }, Scalar::Ptr(_)) | (Scalar::Ptr(_), Scalar::Raw { .. }) => false,
(Scalar::Int { .. }, Scalar::Ptr(_)) | (Scalar::Ptr(_), Scalar::Int { .. }) => false,
// FIXME: return `true` for when both sides are the same pointer, *except* that
// some things (like functions and vtables) do not have stable addresses
// so we need to be careful around them (see e.g. #73722).
@ -194,11 +194,11 @@ impl<'mir, 'tcx: 'mir> CompileTimeEvalContext<'mir, 'tcx> {
fn guaranteed_ne(&mut self, a: Scalar, b: Scalar) -> bool {
match (a, b) {
// Comparisons between integers are always known.
(Scalar::Raw(_), Scalar::Raw(_)) => a != b,
(Scalar::Int(_), Scalar::Int(_)) => a != b,
// Comparisons of abstract pointers with null pointers are known if the pointer
// is in bounds, because if they are in bounds, the pointer can't be null.
// Inequality with integers other than null can never be known for sure.
(Scalar::Raw(int), Scalar::Ptr(ptr)) | (Scalar::Ptr(ptr), Scalar::Raw(int)) => {
(Scalar::Int(int), Scalar::Ptr(ptr)) | (Scalar::Ptr(ptr), Scalar::Int(int)) => {
int == ScalarInt::null(int.size()) && !self.memory.ptr_may_be_null(ptr)
}
// FIXME: return `true` for at least some comparisons where we can reliably

View file

@ -212,7 +212,7 @@ impl<'tcx, Tag: Copy> ImmTy<'tcx, Tag> {
pub fn to_const_int(self) -> ConstInt {
assert!(self.layout.ty.is_integral());
let int = match self.to_scalar().expect("to_const_int doesn't work on scalar pairs") {
Scalar::Raw(int) => int,
Scalar::Int(int) => int,
Scalar::Ptr(_) => bug!("to_const_int doesn't work on pointers"),
};
ConstInt::new(int, self.layout.ty.is_signed(), self.layout.ty.is_ptr_sized_integral())
@ -541,7 +541,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
let tag_scalar = |scalar| -> InterpResult<'tcx, _> {
Ok(match scalar {
Scalar::Ptr(ptr) => Scalar::Ptr(self.global_base_pointer(ptr)?),
Scalar::Raw(int) => Scalar::Raw(int),
Scalar::Int(int) => Scalar::Int(int),
})
};
// Early-return cases.

View file

@ -721,7 +721,7 @@ where
dest.layout.size,
"Size mismatch when writing pointer"
),
Immediate::Scalar(ScalarMaybeUninit::Scalar(Scalar::Raw(int))) => {
Immediate::Scalar(ScalarMaybeUninit::Scalar(Scalar::Int(int))) => {
assert_eq!(int.size(), dest.layout.size, "Size mismatch when writing bits")
}
Immediate::Scalar(ScalarMaybeUninit::Uninit) => {} // uninit can have any size

View file

@ -40,7 +40,7 @@ impl<'tcx> MirPass<'tcx> for SimplifyComparisonIntegral {
let bbs = &mut body.basic_blocks_mut();
let bb = &mut bbs[opt.bb_idx];
let new_value = match opt.branch_value_scalar {
Scalar::Raw(int) => {
Scalar::Int(int) => {
let layout = tcx
.layout_of(param_env.and(opt.branch_value_ty))
.expect("if we have an evaluated constant we must know the layout");

View file

@ -630,7 +630,7 @@ pub fn write_allocations<'tcx>(
ConstValue::Scalar(interpret::Scalar::Ptr(ptr)) => {
Either::Left(Either::Left(std::iter::once(ptr.alloc_id)))
}
ConstValue::Scalar(interpret::Scalar::Raw { .. }) => {
ConstValue::Scalar(interpret::Scalar::Int { .. }) => {
Either::Left(Either::Right(std::iter::empty()))
}
ConstValue::ByRef { alloc, .. } | ConstValue::Slice { data: alloc, .. } => {