Skip to content

Commit 58c996c

Browse files
Move post-elaboration const-checking earlier in the pipeline
Instead we run `RemoveFalseEdges` and `RemoveUninitDrops` at the appropriate time. The extra `SimplifyCfg` avoids visiting unreachable blocks during `RemoveUninitDrops`.
1 parent 3e0e8be commit 58c996c

File tree

1 file changed

+14
-2
lines changed
  • compiler/rustc_mir_transform/src

1 file changed

+14
-2
lines changed

Diff for: compiler/rustc_mir_transform/src/lib.rs

+14-2
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ mod simplify_try;
7777
mod uninhabited_enum_branching;
7878
mod unreachable_prop;
7979

80-
use rustc_const_eval::transform::check_consts;
80+
use rustc_const_eval::transform::check_consts::{self, ConstCx};
8181
use rustc_const_eval::transform::promote_consts;
8282
use rustc_const_eval::transform::validate;
8383
pub use rustc_const_eval::transform::MirPass;
@@ -447,8 +447,20 @@ fn mir_drops_elaborated_and_const_checked<'tcx>(
447447
let (body, _) = tcx.mir_promoted(def);
448448
let mut body = body.steal();
449449

450+
// IMPORTANT
451+
remove_false_edges::RemoveFalseEdges.run_pass(tcx, &mut body);
452+
453+
// Do a little drop elaboration before const-checking if `const_precise_live_drops` is enabled.
454+
//
455+
// FIXME: Can't use `run_passes` for these, since `run_passes` SILENTLY DOES NOTHING IF THE MIR
456+
// PHASE DOESN'T CHANGE.
457+
if check_consts::post_drop_elaboration::checking_enabled(&ConstCx::new(tcx, &body)) {
458+
simplify::SimplifyCfg::new("remove-false-edges").run_pass(tcx, &mut body);
459+
remove_uninit_drops::RemoveUninitDrops.run_pass(tcx, &mut body);
460+
check_consts::post_drop_elaboration::check_live_drops(tcx, &body);
461+
}
462+
450463
run_post_borrowck_cleanup_passes(tcx, &mut body);
451-
check_consts::post_drop_elaboration::check_live_drops(tcx, &body);
452464
tcx.alloc_steal_mir(body)
453465
}
454466

0 commit comments

Comments
 (0)