Skip to content

Commit f13faf5

Browse files
committed
Remove eval_promoted const-prop hack
1 parent 7381465 commit f13faf5

File tree

3 files changed

+10
-26
lines changed

3 files changed

+10
-26
lines changed

src/librustc_mir/const_eval.rs

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,6 @@ pub(crate) fn mk_eval_cx<'mir, 'tcx>(
4949
InterpCx::new(tcx.at(span), param_env, CompileTimeInterpreter::new(), Default::default())
5050
}
5151

52-
pub(crate) fn eval_promoted<'mir, 'tcx>(
53-
tcx: TyCtxt<'tcx>,
54-
cid: GlobalId<'tcx>,
55-
body: &'mir mir::Body<'tcx>,
56-
param_env: ty::ParamEnv<'tcx>,
57-
) -> InterpResult<'tcx, MPlaceTy<'tcx>> {
58-
let span = tcx.def_span(cid.instance.def_id());
59-
let mut ecx = mk_eval_cx(tcx, span, param_env);
60-
eval_body_using_ecx(&mut ecx, cid, body, param_env)
61-
}
62-
6352
fn op_to_const<'tcx>(
6453
ecx: &CompileTimeEvalContext<'_, 'tcx>,
6554
op: OpTy<'tcx>,
@@ -360,7 +349,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
360349
}
361350
}
362351
// This is a const fn. Call it.
363-
Ok(Some(match ecx.load_mir(instance.def) {
352+
Ok(Some(match ecx.load_mir(instance.def, None) {
364353
Ok(body) => body,
365354
Err(err) => {
366355
if let err_unsup!(NoMirFor(ref path)) = err.kind {
@@ -664,14 +653,8 @@ pub fn const_eval_raw_provider<'tcx>(
664653
Default::default()
665654
);
666655

667-
let res = ecx.load_mir(cid.instance.def);
668-
res.map(|body| {
669-
if let Some(index) = cid.promoted {
670-
&tcx.promoted_mir(def_id)[index]
671-
} else {
672-
body
673-
}
674-
}).and_then(
656+
let res = ecx.load_mir(cid.instance.def, cid.promoted);
657+
res.and_then(
675658
|body| eval_body_using_ecx(&mut ecx, cid, body, key.param_env)
676659
).and_then(|place| {
677660
Ok(RawConst {

src/librustc_mir/interpret/eval_context.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
294294
pub fn load_mir(
295295
&self,
296296
instance: ty::InstanceDef<'tcx>,
297+
promoted: Option<mir::Promoted>,
297298
) -> InterpResult<'tcx, &'tcx mir::Body<'tcx>> {
298299
// do not continue if typeck errors occurred (can only occur in local crate)
299300
let did = instance.def_id();
@@ -303,7 +304,10 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
303304
{
304305
throw_inval!(TypeckError)
305306
}
306-
trace!("load mir {:?}", instance);
307+
trace!("load mir(instance={:?}, promoted={:?})", instance, promoted);
308+
if let Some(promoted) = promoted {
309+
return Ok(&self.tcx.promoted_mir(did)[promoted]);
310+
}
307311
match instance {
308312
ty::InstanceDef::Item(def_id) => if self.tcx.is_mir_available(did) {
309313
Ok(self.tcx.optimized_mir(did))

src/librustc_mir/transform/const_prop.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use crate::interpret::{
2727
ImmTy, MemoryKind, StackPopCleanup, LocalValue, LocalState,
2828
};
2929
use crate::const_eval::{
30-
CompileTimeInterpreter, error_to_const_error, eval_promoted, mk_eval_cx,
30+
CompileTimeInterpreter, error_to_const_error, mk_eval_cx,
3131
};
3232
use crate::transform::{MirPass, MirSource};
3333

@@ -297,11 +297,8 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
297297
instance,
298298
promoted: Some(*promoted),
299299
};
300-
// cannot use `const_eval` here, because that would require having the MIR
301-
// for the current function available, but we're producing said MIR right now
302300
let res = self.use_ecx(source_info, |this| {
303-
let body = &this.tcx.promoted_mir(this.source.def_id())[*promoted];
304-
eval_promoted(this.tcx, cid, body, this.param_env)
301+
this.ecx.const_eval_raw(cid)
305302
})?;
306303
trace!("evaluated promoted {:?} to {:?}", promoted, res);
307304
res.into()

0 commit comments

Comments
 (0)