Skip to content
Permalink
Browse files

Move `to_const_value` from `MPlaceTy` to its only use site

  • Loading branch information
oli-obk committed Dec 26, 2019
1 parent 4a5c35b commit cac6f4c12db5fadff650267a8456d5835d19b136
Showing with 14 additions and 18 deletions.
  1. +13 −2 src/librustc_mir/const_eval/eval_queries.rs
  2. +1 −16 src/librustc_mir/interpret/place.rs
@@ -117,12 +117,23 @@ pub(super) fn op_to_const<'tcx>(
// structs containing such.
op.try_as_mplace(ecx)
};

let to_const_value = |mplace: MPlaceTy<'_>| match mplace.ptr {
Scalar::Ptr(ptr) => {
let alloc = ecx.tcx.alloc_map.lock().unwrap_memory(ptr.alloc_id);
ConstValue::ByRef { alloc, offset: ptr.offset }
}
Scalar::Raw { data, .. } => {
assert_eq!(data, mplace.layout.align.abi.bytes().into());
ConstValue::Scalar(Scalar::zst())
}
};
let val = match immediate {
Ok(mplace) => mplace.to_const_value(ecx.tcx.tcx),
Ok(mplace) => to_const_value(mplace),
// see comment on `let try_as_immediate` above
Err(ImmTy { imm: Immediate::Scalar(x), .. }) => match x {
ScalarMaybeUndef::Scalar(s) => ConstValue::Scalar(s),
ScalarMaybeUndef::Undef => op.assert_mem_place(ecx).to_const_value(ecx.tcx.tcx),
ScalarMaybeUndef::Undef => to_const_value(op.assert_mem_place(ecx)),
},
Err(ImmTy { imm: Immediate::ScalarPair(a, b), .. }) => {
let (data, start) = match a.not_undef().unwrap() {
@@ -6,13 +6,12 @@ use std::convert::TryFrom;
use std::hash::Hash;

use rustc::mir;
use rustc::mir::interpret::{truncate, ConstValue};
use rustc::mir::interpret::truncate;
use rustc::ty::layout::{
self, Align, HasDataLayout, LayoutOf, PrimitiveExt, Size, TyLayout, VariantIdx,
};
use rustc::ty::TypeFoldable;
use rustc::ty::{self, Ty};
use rustc::ty::{self, Ty, TyCtxt};
use rustc_macros::HashStable;

use super::{
@@ -196,20 +195,6 @@ impl<'tcx, Tag> MPlaceTy<'tcx, Tag> {
_ => bug!("vtable not supported on type {:?}", self.layout.ty),
}
}

#[inline(always)]
pub fn to_const_value(self, tcx: TyCtxt<'tcx>) -> ConstValue<'tcx> {
match self.mplace.ptr {
Scalar::Ptr(ptr) => {
let alloc = tcx.alloc_map.lock().unwrap_memory(ptr.alloc_id);
ConstValue::ByRef { alloc, offset: ptr.offset }
}
Scalar::Raw { data, .. } => {
assert_eq!(data, self.layout.align.abi.bytes().into());
ConstValue::Scalar(Scalar::zst())
}
}
}
}

// These are defined here because they produce a place.

0 comments on commit cac6f4c

Please sign in to comment.
You can’t perform that action at this time.