Skip to content

Commit 58c8823

Browse files
committed
remap mir before running optimization passes
1 parent bd61b8f commit 58c8823

File tree

1 file changed

+7
-4
lines changed
  • compiler/rustc_mir_transform/src

1 file changed

+7
-4
lines changed

compiler/rustc_mir_transform/src/lib.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,9 @@ fn inner_mir_for_ctfe(tcx: TyCtxt<'_>, def: ty::WithOptConstParam<LocalDefId>) -
387387
.body_const_context(def.did)
388388
.expect("mir_for_ctfe should not be used for runtime functions");
389389

390-
let mut body = tcx.mir_drops_elaborated_and_const_checked(def).borrow().clone();
390+
let body = tcx.mir_drops_elaborated_and_const_checked(def).borrow().clone();
391+
392+
let mut body = remap_mir_for_const_eval_select(tcx, body, hir::Constness::Const);
391393

392394
match context {
393395
// Do not const prop functions, either they get executed at runtime or exported to metadata,
@@ -416,7 +418,7 @@ fn inner_mir_for_ctfe(tcx: TyCtxt<'_>, def: ty::WithOptConstParam<LocalDefId>) -
416418

417419
debug_assert!(!body.has_free_regions(), "Free regions in MIR for CTFE");
418420

419-
remap_mir_for_const_eval_select(tcx, body, hir::Constness::Const)
421+
body
420422
}
421423

422424
/// Obtain just the main MIR (no promoteds) and run some cleanups on it. This also runs
@@ -620,14 +622,15 @@ fn inner_optimized_mir(tcx: TyCtxt<'_>, did: LocalDefId) -> Body<'_> {
620622
Some(other) => panic!("do not use `optimized_mir` for constants: {:?}", other),
621623
}
622624
debug!("about to call mir_drops_elaborated...");
623-
let mut body =
625+
let body =
624626
tcx.mir_drops_elaborated_and_const_checked(ty::WithOptConstParam::unknown(did)).steal();
627+
let mut body = remap_mir_for_const_eval_select(tcx, body, hir::Constness::NotConst);
625628
debug!("body: {:#?}", body);
626629
run_optimization_passes(tcx, &mut body);
627630

628631
debug_assert!(!body.has_free_regions(), "Free regions in optimized MIR");
629632

630-
remap_mir_for_const_eval_select(tcx, body, hir::Constness::NotConst)
633+
body
631634
}
632635

633636
/// Fetch all the promoteds of an item and prepare their MIR bodies to be ready for

0 commit comments

Comments
 (0)