Add simpler entry points to const eval for common usages.
This commit is contained in:
parent
6b561b4917
commit
c010d843aa
23 changed files with 195 additions and 253 deletions
|
|
@ -638,12 +638,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
|||
projection: &[],
|
||||
} = place.as_ref()
|
||||
{
|
||||
let param_env = ty::ParamEnv::reveal_all();
|
||||
let cid = mir::interpret::GlobalId {
|
||||
instance: self.instance,
|
||||
promoted: Some(promoted),
|
||||
};
|
||||
let c = bx.tcx().const_eval(param_env.and(cid));
|
||||
let c = bx.tcx().const_eval_promoted(self.instance, promoted);
|
||||
let (llval, ty) = self.simd_shuffle_indices(
|
||||
&bx,
|
||||
terminator.source_info.span,
|
||||
|
|
|
|||
|
|
@ -43,17 +43,14 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
|||
match constant.literal.val {
|
||||
ty::ConstKind::Unevaluated(def_id, substs) => {
|
||||
let substs = self.monomorphize(&substs);
|
||||
let instance = ty::Instance::resolve(
|
||||
self.cx.tcx(), ty::ParamEnv::reveal_all(), def_id, substs,
|
||||
).unwrap();
|
||||
let cid = mir::interpret::GlobalId {
|
||||
instance,
|
||||
promoted: None,
|
||||
};
|
||||
self.cx.tcx().const_eval(ty::ParamEnv::reveal_all().and(cid)).map_err(|err| {
|
||||
self.cx.tcx().sess.span_err(constant.span, "erroneous constant encountered");
|
||||
err
|
||||
})
|
||||
self.cx.tcx()
|
||||
.const_eval_resolve(ty::ParamEnv::reveal_all(), def_id, substs, None)
|
||||
.map_err(|err| {
|
||||
self.cx.tcx().sess.span_err(
|
||||
constant.span,
|
||||
"erroneous constant encountered");
|
||||
err
|
||||
})
|
||||
},
|
||||
_ => Ok(self.monomorphize(&constant.literal)),
|
||||
}
|
||||
|
|
|
|||
|
|
@ -473,14 +473,9 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
|||
}),
|
||||
projection: [],
|
||||
} => {
|
||||
let param_env = ty::ParamEnv::reveal_all();
|
||||
let instance = Instance::new(*def_id, self.monomorphize(substs));
|
||||
let cid = mir::interpret::GlobalId {
|
||||
instance: instance,
|
||||
promoted: Some(*promoted),
|
||||
};
|
||||
let layout = cx.layout_of(self.monomorphize(&ty));
|
||||
match bx.tcx().const_eval(param_env.and(cid)) {
|
||||
match bx.tcx().const_eval_promoted(instance, *promoted) {
|
||||
Ok(val) => match val.val {
|
||||
ty::ConstKind::Value(mir::interpret::ConstValue::ByRef {
|
||||
alloc, offset
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue