Skip to content

Commit fd18b45

Browse files
Update passes with new interface
1 parent c1a501b commit fd18b45

32 files changed

+141
-98
lines changed

compiler/rustc_const_eval/src/transform/promote_consts.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ pub struct PromoteTemps<'tcx> {
4141
}
4242

4343
impl<'tcx> MirPass<'tcx> for PromoteTemps<'tcx> {
44+
fn phase_change(&self) -> Option<MirPhase> {
45+
Some(MirPhase::ConstPromotion)
46+
}
47+
4448
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
4549
// There's not really any point in promoting errorful MIR.
4650
//

compiler/rustc_mir_dataflow/src/rustc_peek.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use crate::{Analysis, JoinSemiLattice, Results, ResultsCursor};
2020

2121
pub struct SanityCheck;
2222

23+
// FIXME: This should be a `MirLint`, but it needs to be moved back to `rustc_mir_transform` first.
2324
impl<'tcx> MirPass<'tcx> for SanityCheck {
2425
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
2526
use crate::has_rustc_mir_with;

compiler/rustc_mir_transform/src/add_retag.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ fn may_be_reference(ty: Ty<'tcx>) -> bool {
5858
}
5959

6060
impl<'tcx> MirPass<'tcx> for AddRetag {
61-
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
62-
if !tcx.sess.opts.debugging_opts.mir_emit_retag {
63-
return;
64-
}
61+
fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
62+
sess.opts.debugging_opts.mir_emit_retag
63+
}
6564

65+
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
6666
// We need an `AllCallEdges` pass before we can do any work.
6767
super::add_call_guards::AllCallEdges.run_pass(tcx, body);
6868

compiler/rustc_mir_transform/src/check_const_item_mutation.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ use rustc_middle::ty::TyCtxt;
66
use rustc_session::lint::builtin::CONST_ITEM_MUTATION;
77
use rustc_span::def_id::DefId;
88

9-
use crate::MirPass;
9+
use crate::MirLint;
1010

1111
pub struct CheckConstItemMutation;
1212

13-
impl<'tcx> MirPass<'tcx> for CheckConstItemMutation {
14-
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
13+
impl<'tcx> MirLint<'tcx> for CheckConstItemMutation {
14+
fn run_lint(&self, tcx: TyCtxt<'tcx>, body: &Body<'tcx>) {
1515
let mut checker = ConstMutationChecker { body, tcx, target_local: None };
1616
checker.visit_body(&body);
1717
}

compiler/rustc_mir_transform/src/check_packed_ref.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ use rustc_session::lint::builtin::UNALIGNED_REFERENCES;
77
use rustc_span::symbol::sym;
88

99
use crate::util;
10-
use crate::MirPass;
10+
use crate::MirLint;
1111

1212
pub(crate) fn provide(providers: &mut Providers) {
1313
*providers = Providers { unsafe_derive_on_repr_packed, ..*providers };
1414
}
1515

1616
pub struct CheckPackedRef;
1717

18-
impl<'tcx> MirPass<'tcx> for CheckPackedRef {
19-
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
18+
impl<'tcx> MirLint<'tcx> for CheckPackedRef {
19+
fn run_lint(&self, tcx: TyCtxt<'tcx>, body: &Body<'tcx>) {
2020
let param_env = tcx.param_env(body.source.def_id());
2121
let source_info = SourceInfo::outermost(body.span);
2222
let mut checker = PackedRefChecker { body, tcx, param_env, source_info };

compiler/rustc_mir_transform/src/const_debuginfo.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ use rustc_index::{bit_set::BitSet, vec::IndexVec};
1515
pub struct ConstDebugInfo;
1616

1717
impl<'tcx> MirPass<'tcx> for ConstDebugInfo {
18-
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
19-
if !tcx.sess.opts.debugging_opts.unsound_mir_opts {
20-
return;
21-
}
18+
fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
19+
sess.opts.debugging_opts.unsound_mir_opts && sess.mir_opt_level() > 0
20+
}
2221

22+
fn run_pass(&self, _: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
2323
trace!("running ConstDebugInfo on {:?}", body.source);
2424

2525
for (local, constant) in find_optimization_oportunities(body) {

compiler/rustc_mir_transform/src/const_goto.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,11 @@ use super::simplify::{simplify_cfg, simplify_locals};
2727
pub struct ConstGoto;
2828

2929
impl<'tcx> MirPass<'tcx> for ConstGoto {
30+
fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
31+
sess.mir_opt_level() >= 4
32+
}
33+
3034
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
31-
if tcx.sess.mir_opt_level() < 4 {
32-
return;
33-
}
3435
trace!("Running ConstGoto on {:?}", body.source);
3536
let param_env = tcx.param_env_reveal_all_normalized(body.source.def_id());
3637
let mut opt_finder =

compiler/rustc_mir_transform/src/const_prop.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,13 @@ macro_rules! throw_machine_stop_str {
6262
pub struct ConstProp;
6363

6464
impl<'tcx> MirPass<'tcx> for ConstProp {
65+
fn is_enabled(&self, _sess: &rustc_session::Session) -> bool {
66+
// FIXME(#70073): Unlike the other passes in "optimizations", this one emits errors, so it
67+
// runs even when MIR optimizations are disabled. We should separate the lint out from the
68+
// transform and move the lint as early in the pipeline as possible.
69+
true
70+
}
71+
6572
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
6673
// will be evaluated by miri and produce its errors there
6774
if body.source.promoted.is_some() {

compiler/rustc_mir_transform/src/coverage/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ impl Error {
4949
pub struct InstrumentCoverage;
5050

5151
impl<'tcx> MirPass<'tcx> for InstrumentCoverage {
52+
fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
53+
sess.instrument_coverage()
54+
}
55+
5256
fn run_pass(&self, tcx: TyCtxt<'tcx>, mir_body: &mut mir::Body<'tcx>) {
5357
let mir_source = mir_body.source;
5458

compiler/rustc_mir_transform/src/deduplicate_blocks.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@ use super::simplify::simplify_cfg;
1515
pub struct DeduplicateBlocks;
1616

1717
impl<'tcx> MirPass<'tcx> for DeduplicateBlocks {
18+
fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
19+
sess.mir_opt_level() >= 4
20+
}
21+
1822
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
19-
if tcx.sess.mir_opt_level() < 4 {
20-
return;
21-
}
2223
debug!("Running DeduplicateBlocks on `{:?}`", body.source);
2324
let duplicates = find_duplicates(body);
2425
let has_opts_to_apply = !duplicates.is_empty();

0 commit comments

Comments
 (0)