use rustc::mir::interpret::{
read_target_uint, AllocId, AllocKind, Allocation, ConstValue, EvalResult, GlobalId, Scalar,
};
-use rustc::ty::Const;
+use rustc::ty::{Const, LazyConst};
use rustc_mir::interpret::{
EvalContext, MPlaceTy, Machine, Memory, MemoryKind, OpTy, PlaceTy, Pointer, StackPopCleanup,
};
}))
.unwrap();
- let const_ = force_eval_const(fx, const_);
trans_const_place(fx, const_)
}
pub fn force_eval_const<'a, 'tcx: 'a>(
fx: &FunctionCx<'a, 'tcx, impl Backend>,
- const_: &'tcx Const<'tcx>,
-) -> &'tcx Const<'tcx> {
- match const_.val {
- ConstValue::Unevaluated(def_id, ref substs) => {
+ const_: &'tcx LazyConst<'tcx>,
+) -> Const<'tcx> {
+ match *const_ {
+ LazyConst::Unevaluated(def_id, ref substs) => {
let param_env = ParamEnv::reveal_all();
let instance = Instance::resolve(fx.tcx, param_env, def_id, substs).unwrap();
let cid = GlobalId {
};
fx.tcx.const_eval(param_env.and(cid)).unwrap()
}
- _ => const_,
+ LazyConst::Evaluated(const_) => const_,
}
}
fn trans_const_value<'a, 'tcx: 'a>(
fx: &mut FunctionCx<'a, 'tcx, impl Backend>,
- const_: &'tcx Const<'tcx>,
+ const_: Const<'tcx>,
) -> CValue<'tcx> {
let ty = fx.monomorphize(&const_.ty);
let layout = fx.layout_of(ty);
fn trans_const_place<'a, 'tcx: 'a>(
fx: &mut FunctionCx<'a, 'tcx, impl Backend>,
- const_: &'tcx Const<'tcx>,
+ const_: Const<'tcx>,
) -> CPlace<'tcx> {
// Adapted from https://github.com/rust-lang/rust/pull/53671/files#diff-e0b58bb6712edaa8595ad7237542c958L551
let result = || -> EvalResult<'tcx, &'tcx Allocation> {
span: DUMMY_SP,
ty: const_.ty,
user_ty: None,
- literal: const_,
+ literal: fx.tcx.intern_lazy_const(LazyConst::Evaluated(const_)),
})),
None,
)?;
let needs_drop = CValue::const_val(fx, fx.tcx.types.bool, needs_drop);
ret.write_cvalue(fx, needs_drop);
};
+ panic_if_uninhabited, <T> () {
+ if fx.layout_of(T).abi.is_uninhabited() {
+ crate::trap::trap_panic(&mut fx.bcx);
+ }
+ };
_ if intrinsic.starts_with("atomic_fence"), () {};
_ if intrinsic.starts_with("atomic_singlethreadfence"), () {};
pub fn get_vtable<'a, 'tcx: 'a>(
fx: &mut FunctionCx<'a, 'tcx, impl Backend>,
ty: Ty<'tcx>,
- trait_ref: ty::PolyExistentialTraitRef<'tcx>,
+ trait_ref: Option<ty::PolyExistentialTraitRef<'tcx>>,
) -> Value {
let data_id = if let Some(data_id) = fx.caches.vtables.get(&(ty, trait_ref)) {
*data_id
fn build_vtable<'a, 'tcx: 'a>(
fx: &mut FunctionCx<'a, 'tcx, impl Backend>,
ty: Ty<'tcx>,
- trait_ref: ty::PolyExistentialTraitRef<'tcx>,
+ trait_ref: Option<ty::PolyExistentialTraitRef<'tcx>>,
) -> DataId {
let tcx = fx.tcx;
let usize_size = fx.layout_of(fx.tcx.types.usize).size.bytes() as usize;
let mut components: Vec<_> = vec![Some(drop_in_place_fn), None, None];
- let trait_ref = trait_ref.with_self_ty(tcx, ty);
- let methods = tcx.vtable_methods(trait_ref);
- let methods = methods.iter().cloned().map(|opt_mth| {
+ let methods_root;
+ let methods = if let Some(trait_ref) = trait_ref {
+ methods_root = tcx.vtable_methods(trait_ref.with_self_ty(tcx, ty));
+ methods_root.iter()
+ } else {
+ (&[]).iter()
+ };
+ let methods = methods.cloned().map(|opt_mth| {
opt_mth.map_or(None, |(def_id, substs)| {
Some(import_function(
tcx,