use common::{C_null, C_struct, C_str_slice, C_undef, C_uint, C_vector, is_undef};
use common::const_to_opt_u128;
use consts;
-use monomorphize::{self, Instance};
+use monomorphize;
use type_of;
use type_::Type;
use value::Value;
}
fn trans_def(ccx: &'a CrateContext<'a, 'tcx>,
- instance: Instance<'tcx>,
+ def_id: DefId,
+ substs: &'tcx Substs<'tcx>,
args: IndexVec<mir::Local, Const<'tcx>>)
-> Result<Const<'tcx>, ConstEvalErr<'tcx>> {
- let instance = instance.resolve_const(ccx.shared());
- let mir = ccx.tcx().item_mir(instance.def);
+ let instance = monomorphize::resolve_const(ccx.shared(), def_id, substs);
+ let mir = ccx.tcx().instance_mir(instance.def);
MirConstContext::new(ccx, &mir, instance.substs, args).trans()
}
mir::TerminatorKind::Call { ref func, ref args, ref destination, .. } => {
let fn_ty = func.ty(self.mir, tcx);
let fn_ty = self.monomorphize(&fn_ty);
- let instance = match fn_ty.sty {
- ty::TyFnDef(def_id, substs, _) => {
- Instance::new(def_id, substs)
- }
+ let (def_id, substs) = match fn_ty.sty {
+ ty::TyFnDef(def_id, substs, _) => (def_id, substs),
_ => span_bug!(span, "calling {:?} (of type {}) in constant",
func, fn_ty)
};
}
}
if let Some((ref dest, target)) = *destination {
- match MirConstContext::trans_def(self.ccx, instance, const_args) {
+ match MirConstContext::trans_def(self.ccx, def_id, substs, const_args) {
Ok(value) => self.store(dest, value, span),
Err(err) => if failure.is_ok() { failure = Err(err); }
}
}
let substs = self.monomorphize(&substs);
- let instance = Instance::new(def_id, substs);
- MirConstContext::trans_def(self.ccx, instance, IndexVec::new())
+ MirConstContext::trans_def(self.ccx, def_id, substs, IndexVec::new())
}
mir::Literal::Promoted { index } => {
let mir = &self.mir.promoted[index];
// Now create its substs [Closure, Tuple]
let input = tcx.closure_type(def_id)
.subst(tcx, substs.substs).input(0);
- let substs = tcx.mk_substs([operand.ty, input.skip_binder()]
+ let input = tcx.erase_late_bound_regions_and_normalize(&input);
+ let substs = tcx.mk_substs([operand.ty, input]
.iter().cloned().map(Kind::from));
Callee::def(self.ccx, call_once, substs)
.reify(self.ccx)
}
let substs = self.monomorphize(&substs);
- let instance = Instance::new(def_id, substs);
- MirConstContext::trans_def(bcx.ccx, instance, IndexVec::new())
+ MirConstContext::trans_def(bcx.ccx, def_id, substs, IndexVec::new())
}
mir::Literal::Promoted { index } => {
let mir = &self.mir.promoted[index];
def_id: DefId)
-> Result<ValueRef, ConstEvalErr<'tcx>>
{
- let instance = Instance::mono(ccx.shared(), def_id);
- MirConstContext::trans_def(ccx, instance, IndexVec::new()).map(|c| c.llval)
+ MirConstContext::trans_def(ccx, def_id, Substs::empty(), IndexVec::new())
+ .map(|c| c.llval)
}
/// Construct a constant value, suitable for initializing a