Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions compiler/rustc_mir_transform/src/add_retag.rs
Original file line number Diff line number Diff line change
@@ -49,8 +49,8 @@ fn may_contain_reference<'tcx>(ty: Ty<'tcx>, depth: u32, tcx: TyCtxt<'tcx>) -> b
}

impl<'tcx> crate::MirPass<'tcx> for AddRetag {
fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
sess.opts.unstable_opts.mir_emit_retag
fn is_enabled(&self, tcx: TyCtxt<'tcx>) -> bool {
tcx.sess.opts.unstable_opts.mir_emit_retag
}

fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
5 changes: 2 additions & 3 deletions compiler/rustc_mir_transform/src/check_alignment.rs
Original file line number Diff line number Diff line change
@@ -4,15 +4,14 @@ use rustc_middle::mir::interpret::Scalar;
use rustc_middle::mir::visit::PlaceContext;
use rustc_middle::mir::*;
use rustc_middle::ty::{Ty, TyCtxt};
use rustc_session::Session;

use crate::check_pointers::{BorrowedFieldProjectionMode, PointerCheck, check_pointers};

pub(super) struct CheckAlignment;

impl<'tcx> crate::MirPass<'tcx> for CheckAlignment {
fn is_enabled(&self, sess: &Session) -> bool {
sess.ub_checks()
fn is_enabled(&self, tcx: TyCtxt<'tcx>) -> bool {
tcx.sess.ub_checks()
}

fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
9 changes: 9 additions & 0 deletions compiler/rustc_mir_transform/src/check_call_recursion.rs
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@ use rustc_hir::LangItem;
use rustc_hir::def::DefKind;
use rustc_middle::mir::{self, BasicBlock, BasicBlocks, Body, Terminator, TerminatorKind};
use rustc_middle::ty::{self, GenericArg, GenericArgs, Instance, Ty, TyCtxt};
use rustc_session::lint::LintId;
use rustc_session::lint::builtin::UNCONDITIONAL_RECURSION;
use rustc_span::Span;

@@ -16,6 +17,10 @@ use crate::pass_manager::MirLint;
pub(super) struct CheckCallRecursion;

impl<'tcx> MirLint<'tcx> for CheckCallRecursion {
fn is_enabled(&self, tcx: TyCtxt<'tcx>) -> bool {
!tcx.lints_that_dont_need_to_run(()).contains(&LintId::of(UNCONDITIONAL_RECURSION))
}

fn run_lint(&self, tcx: TyCtxt<'tcx>, body: &Body<'tcx>) {
let def_id = body.source.def_id().expect_local();

@@ -38,6 +43,10 @@ impl<'tcx> MirLint<'tcx> for CheckCallRecursion {
pub(super) struct CheckDropRecursion;

impl<'tcx> MirLint<'tcx> for CheckDropRecursion {
fn is_enabled(&self, tcx: TyCtxt<'tcx>) -> bool {
!tcx.lints_that_dont_need_to_run(()).contains(&LintId::of(UNCONDITIONAL_RECURSION))
}

fn run_lint(&self, tcx: TyCtxt<'tcx>, body: &Body<'tcx>) {
let def_id = body.source.def_id().expect_local();

5 changes: 5 additions & 0 deletions compiler/rustc_mir_transform/src/check_const_item_mutation.rs
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@ use rustc_hir::HirId;
use rustc_middle::mir::visit::Visitor;
use rustc_middle::mir::*;
use rustc_middle::ty::TyCtxt;
use rustc_session::lint::LintId;
use rustc_session::lint::builtin::CONST_ITEM_MUTATION;
use rustc_span::Span;
use rustc_span::def_id::DefId;
@@ -11,6 +12,10 @@ use crate::errors;
pub(super) struct CheckConstItemMutation;

impl<'tcx> crate::MirLint<'tcx> for CheckConstItemMutation {
fn is_enabled(&self, tcx: TyCtxt<'tcx>) -> bool {
!tcx.lints_that_dont_need_to_run(()).contains(&LintId::of(CONST_ITEM_MUTATION))
}

fn run_lint(&self, tcx: TyCtxt<'tcx>, body: &Body<'tcx>) {
let mut checker = ConstMutationChecker { body, tcx, target_local: None };
checker.visit_body(body);
5 changes: 2 additions & 3 deletions compiler/rustc_mir_transform/src/check_null.rs
Original file line number Diff line number Diff line change
@@ -2,15 +2,14 @@ use rustc_index::IndexVec;
use rustc_middle::mir::visit::{MutatingUseContext, NonMutatingUseContext, PlaceContext};
use rustc_middle::mir::*;
use rustc_middle::ty::{Ty, TyCtxt};
use rustc_session::Session;

use crate::check_pointers::{BorrowedFieldProjectionMode, PointerCheck, check_pointers};

pub(super) struct CheckNull;

impl<'tcx> crate::MirPass<'tcx> for CheckNull {
fn is_enabled(&self, sess: &Session) -> bool {
sess.ub_checks()
fn is_enabled(&self, tcx: TyCtxt<'tcx>) -> bool {
tcx.sess.ub_checks()
}

fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
4 changes: 2 additions & 2 deletions compiler/rustc_mir_transform/src/copy_prop.rs
Original file line number Diff line number Diff line change
@@ -20,8 +20,8 @@ use crate::ssa::SsaLocals;
pub(super) struct CopyProp;

impl<'tcx> crate::MirPass<'tcx> for CopyProp {
fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
sess.mir_opt_level() >= 1
fn is_enabled(&self, tcx: TyCtxt<'tcx>) -> bool {
tcx.sess.mir_opt_level() >= 1
}

#[instrument(level = "trace", skip(self, tcx, body))]
4 changes: 2 additions & 2 deletions compiler/rustc_mir_transform/src/coverage/mod.rs
Original file line number Diff line number Diff line change
@@ -29,8 +29,8 @@ use crate::coverage::mappings::ExtractedMappings;
pub(super) struct InstrumentCoverage;

impl<'tcx> crate::MirPass<'tcx> for InstrumentCoverage {
fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
sess.instrument_coverage()
fn is_enabled(&self, tcx: TyCtxt<'tcx>) -> bool {
tcx.sess.instrument_coverage()
}

fn run_pass(&self, tcx: TyCtxt<'tcx>, mir_body: &mut mir::Body<'tcx>) {
4 changes: 2 additions & 2 deletions compiler/rustc_mir_transform/src/dataflow_const_prop.rs
Original file line number Diff line number Diff line change
@@ -35,8 +35,8 @@ const PLACE_LIMIT: usize = 100;
pub(super) struct DataflowConstProp;

impl<'tcx> crate::MirPass<'tcx> for DataflowConstProp {
fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
sess.mir_opt_level() >= 3
fn is_enabled(&self, tcx: TyCtxt<'tcx>) -> bool {
tcx.sess.mir_opt_level() >= 3
}

#[instrument(skip_all level = "debug")]
4 changes: 2 additions & 2 deletions compiler/rustc_mir_transform/src/dead_store_elimination.rs
Original file line number Diff line number Diff line change
@@ -140,8 +140,8 @@ impl<'tcx> crate::MirPass<'tcx> for DeadStoreElimination {
}
}

fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
sess.mir_opt_level() >= 2
fn is_enabled(&self, tcx: TyCtxt<'tcx>) -> bool {
tcx.sess.mir_opt_level() >= 2
}

fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
4 changes: 2 additions & 2 deletions compiler/rustc_mir_transform/src/dest_prop.rs
Original file line number Diff line number Diff line change
@@ -149,7 +149,7 @@ use tracing::{debug, trace};
pub(super) struct DestinationPropagation;

impl<'tcx> crate::MirPass<'tcx> for DestinationPropagation {
fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
fn is_enabled(&self, tcx: TyCtxt<'tcx>) -> bool {
// For now, only run at MIR opt level 3. Two things need to be changed before this can be
// turned on by default:
// 1. Because of the overeager removal of storage statements, this can cause stack space
@@ -158,7 +158,7 @@ impl<'tcx> crate::MirPass<'tcx> for DestinationPropagation {
// 2. Despite being an overall perf improvement, this still causes a 30% regression in
// keccak. We can temporarily fix this by bounding function size, but in the long term
// we should fix this by being smarter about invalidating analysis results.
sess.mir_opt_level() >= 3
tcx.sess.mir_opt_level() >= 3
}

fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
4 changes: 2 additions & 2 deletions compiler/rustc_mir_transform/src/early_otherwise_branch.rs
Original file line number Diff line number Diff line change
@@ -93,8 +93,8 @@ use crate::patch::MirPatch;
pub(super) struct EarlyOtherwiseBranch;

impl<'tcx> crate::MirPass<'tcx> for EarlyOtherwiseBranch {
fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
sess.mir_opt_level() >= 2
fn is_enabled(&self, tcx: TyCtxt<'tcx>) -> bool {
tcx.sess.mir_opt_level() >= 2
}

fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
4 changes: 4 additions & 0 deletions compiler/rustc_mir_transform/src/errors.rs
Original file line number Diff line number Diff line change
@@ -92,6 +92,10 @@ impl<'a, P: std::fmt::Debug> LintDiagnostic<'a, ()> for AssertLint<P> {
}

impl AssertLintKind {
pub(crate) fn all_lints() -> [&'static Lint; 2] {
[lint::builtin::ARITHMETIC_OVERFLOW, lint::builtin::UNCONDITIONAL_PANIC]
}

pub(crate) fn lint(&self) -> &'static Lint {
match self {
AssertLintKind::ArithmeticOverflow => lint::builtin::ARITHMETIC_OVERFLOW,
5 changes: 5 additions & 0 deletions compiler/rustc_mir_transform/src/function_item_references.rs
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@ use rustc_hir::def_id::DefId;
use rustc_middle::mir::visit::Visitor;
use rustc_middle::mir::*;
use rustc_middle::ty::{self, EarlyBinder, GenericArgsRef, Ty, TyCtxt};
use rustc_session::lint::LintId;
use rustc_session::lint::builtin::FUNCTION_ITEM_REFERENCES;
use rustc_span::source_map::Spanned;
use rustc_span::{Span, sym};
@@ -13,6 +14,10 @@ use crate::errors;
pub(super) struct FunctionItemReferences;

impl<'tcx> crate::MirLint<'tcx> for FunctionItemReferences {
fn is_enabled(&self, tcx: TyCtxt<'tcx>) -> bool {
!tcx.lints_that_dont_need_to_run(()).contains(&LintId::of(FUNCTION_ITEM_REFERENCES))
}

fn run_lint(&self, tcx: TyCtxt<'tcx>, body: &Body<'tcx>) {
let mut checker = FunctionItemRefChecker { tcx, body };
checker.visit_body(body);
4 changes: 2 additions & 2 deletions compiler/rustc_mir_transform/src/gvn.rs
Original file line number Diff line number Diff line change
@@ -114,8 +114,8 @@ use crate::ssa::SsaLocals;
pub(super) struct GVN;

impl<'tcx> crate::MirPass<'tcx> for GVN {
fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
sess.mir_opt_level() >= 2
fn is_enabled(&self, tcx: TyCtxt<'tcx>) -> bool {
tcx.sess.mir_opt_level() >= 2
}

#[instrument(level = "trace", skip(self, tcx, body))]
13 changes: 7 additions & 6 deletions compiler/rustc_mir_transform/src/inline.rs
Original file line number Diff line number Diff line change
@@ -43,16 +43,17 @@ struct CallSite<'tcx> {
pub struct Inline;

impl<'tcx> crate::MirPass<'tcx> for Inline {
fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
if let Some(enabled) = sess.opts.unstable_opts.inline_mir {
fn is_enabled(&self, tcx: TyCtxt<'tcx>) -> bool {
if let Some(enabled) = tcx.sess.opts.unstable_opts.inline_mir {
return enabled;
}

match sess.mir_opt_level() {
match tcx.sess.mir_opt_level() {
0 | 1 => false,
2 => {
(sess.opts.optimize == OptLevel::More || sess.opts.optimize == OptLevel::Aggressive)
&& sess.opts.incremental == None
(tcx.sess.opts.optimize == OptLevel::More
|| tcx.sess.opts.optimize == OptLevel::Aggressive)
&& tcx.sess.opts.incremental == None
}
_ => true,
}
@@ -82,7 +83,7 @@ impl ForceInline {
}

impl<'tcx> crate::MirPass<'tcx> for ForceInline {
fn is_enabled(&self, _: &rustc_session::Session) -> bool {
fn is_enabled(&self, _: TyCtxt<'tcx>) -> bool {
true
}

4 changes: 2 additions & 2 deletions compiler/rustc_mir_transform/src/instsimplify.rs
Original file line number Diff line number Diff line change
@@ -24,8 +24,8 @@ impl<'tcx> crate::MirPass<'tcx> for InstSimplify {
}
}

fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
sess.mir_opt_level() > 0
fn is_enabled(&self, tcx: TyCtxt<'tcx>) -> bool {
tcx.sess.mir_opt_level() > 0
}

fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
4 changes: 2 additions & 2 deletions compiler/rustc_mir_transform/src/jump_threading.rs
Original file line number Diff line number Diff line change
@@ -61,8 +61,8 @@ const MAX_COST: usize = 100;
const MAX_PLACES: usize = 100;

impl<'tcx> crate::MirPass<'tcx> for JumpThreading {
fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
sess.mir_opt_level() >= 2
fn is_enabled(&self, tcx: TyCtxt<'tcx>) -> bool {
tcx.sess.mir_opt_level() >= 2
}

#[instrument(skip_all level = "debug")]
6 changes: 6 additions & 0 deletions compiler/rustc_mir_transform/src/known_panics_lint.rs
Original file line number Diff line number Diff line change
@@ -19,6 +19,7 @@ use rustc_middle::mir::visit::{MutatingUseContext, NonMutatingUseContext, PlaceC
use rustc_middle::mir::*;
use rustc_middle::ty::layout::{LayoutError, LayoutOf, LayoutOfHelpers, TyAndLayout};
use rustc_middle::ty::{self, ConstInt, ScalarInt, Ty, TyCtxt, TypeVisitableExt};
use rustc_session::lint::LintId;
use rustc_span::Span;
use tracing::{debug, instrument, trace};

@@ -27,6 +28,11 @@ use crate::errors::{AssertLint, AssertLintKind};
pub(super) struct KnownPanicsLint;

impl<'tcx> crate::MirLint<'tcx> for KnownPanicsLint {
fn is_enabled(&self, tcx: TyCtxt<'tcx>) -> bool {
let ignored_lints = tcx.lints_that_dont_need_to_run(());
!AssertLintKind::all_lints().iter().all(|lint| ignored_lints.contains(&LintId::of(lint)))
}

fn run_lint(&self, tcx: TyCtxt<'tcx>, body: &Body<'tcx>) {
if body.tainted_by_errors.is_some() {
return;
5 changes: 2 additions & 3 deletions compiler/rustc_mir_transform/src/large_enums.rs
Original file line number Diff line number Diff line change
@@ -4,7 +4,6 @@ use rustc_middle::mir::interpret::AllocId;
use rustc_middle::mir::*;
use rustc_middle::ty::util::IntTypeExt;
use rustc_middle::ty::{self, AdtDef, Ty, TyCtxt};
use rustc_session::Session;

use crate::patch::MirPatch;

@@ -29,11 +28,11 @@ pub(super) struct EnumSizeOpt {
}

impl<'tcx> crate::MirPass<'tcx> for EnumSizeOpt {
fn is_enabled(&self, sess: &Session) -> bool {
fn is_enabled(&self, tcx: TyCtxt<'tcx>) -> bool {
// There are some differences in behavior on wasm and ARM that are not properly
// understood, so we conservatively treat this optimization as unsound:
// https://github.com/rust-lang/rust/pull/85158#issuecomment-1101836457
sess.opts.unstable_opts.unsound_mir_opts || sess.mir_opt_level() >= 3
tcx.sess.opts.unstable_opts.unsound_mir_opts || tcx.sess.mir_opt_level() >= 3
}

fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
4 changes: 2 additions & 2 deletions compiler/rustc_mir_transform/src/lower_slice_len.rs
Original file line number Diff line number Diff line change
@@ -8,8 +8,8 @@ use rustc_middle::ty::TyCtxt;
pub(super) struct LowerSliceLenCalls;

impl<'tcx> crate::MirPass<'tcx> for LowerSliceLenCalls {
fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
sess.mir_opt_level() > 0
fn is_enabled(&self, tcx: TyCtxt<'tcx>) -> bool {
tcx.sess.mir_opt_level() > 0
}

fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
4 changes: 2 additions & 2 deletions compiler/rustc_mir_transform/src/match_branches.rs
Original file line number Diff line number Diff line change
@@ -13,8 +13,8 @@ use crate::patch::MirPatch;
pub(super) struct MatchBranchSimplification;

impl<'tcx> crate::MirPass<'tcx> for MatchBranchSimplification {
fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
sess.mir_opt_level() >= 1
fn is_enabled(&self, tcx: TyCtxt<'tcx>) -> bool {
tcx.sess.mir_opt_level() >= 1
}

fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
3 changes: 1 addition & 2 deletions compiler/rustc_mir_transform/src/mentioned_items.rs
Original file line number Diff line number Diff line change
@@ -2,7 +2,6 @@ use rustc_middle::mir::visit::Visitor;
use rustc_middle::mir::{self, Location, MentionedItem};
use rustc_middle::ty::adjustment::PointerCoercion;
use rustc_middle::ty::{self, TyCtxt};
use rustc_session::Session;
use rustc_span::source_map::Spanned;

pub(super) struct MentionedItems;
@@ -14,7 +13,7 @@ struct MentionedItemsVisitor<'a, 'tcx> {
}

impl<'tcx> crate::MirPass<'tcx> for MentionedItems {
fn is_enabled(&self, _sess: &Session) -> bool {
fn is_enabled(&self, _tcx: TyCtxt<'tcx>) -> bool {
// If this pass is skipped the collector assume that nothing got mentioned! We could
// potentially skip it in opt-level 0 if we are sure that opt-level will never *remove* uses
// of anything, but that still seems fragile. Furthermore, even debug builds use level 1, so
Original file line number Diff line number Diff line change
@@ -10,8 +10,8 @@ use crate::simplify;
pub(super) struct MultipleReturnTerminators;

impl<'tcx> crate::MirPass<'tcx> for MultipleReturnTerminators {
fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
sess.mir_opt_level() >= 4
fn is_enabled(&self, tcx: TyCtxt<'tcx>) -> bool {
tcx.sess.mir_opt_level() >= 4
}

fn run_pass(&self, _: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
4 changes: 2 additions & 2 deletions compiler/rustc_mir_transform/src/nrvo.rs
Original file line number Diff line number Diff line change
@@ -33,9 +33,9 @@ use tracing::{debug, trace};
pub(super) struct RenameReturnPlace;

impl<'tcx> crate::MirPass<'tcx> for RenameReturnPlace {
fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
fn is_enabled(&self, tcx: TyCtxt<'tcx>) -> bool {
// unsound: #111005
sess.mir_opt_level() > 0 && sess.opts.unstable_opts.unsound_mir_opts
tcx.sess.mir_opt_level() > 0 && tcx.sess.opts.unstable_opts.unsound_mir_opts
}

fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut mir::Body<'tcx>) {
17 changes: 8 additions & 9 deletions compiler/rustc_mir_transform/src/pass_manager.rs
Original file line number Diff line number Diff line change
@@ -4,7 +4,6 @@ use std::collections::hash_map::Entry;
use rustc_data_structures::fx::{FxHashMap, FxIndexSet};
use rustc_middle::mir::{self, Body, MirPhase, RuntimePhase};
use rustc_middle::ty::TyCtxt;
use rustc_session::Session;
use tracing::trace;

use crate::lint::lint_body;
@@ -75,7 +74,7 @@ pub(super) trait MirPass<'tcx> {
}

/// Returns `true` if this pass is enabled with the current combination of compiler flags.
fn is_enabled(&self, _sess: &Session) -> bool {
fn is_enabled(&self, _tcx: TyCtxt<'tcx>) -> bool {
true
}

@@ -109,7 +108,7 @@ pub(super) trait MirLint<'tcx> {
}
}

fn is_enabled(&self, _sess: &Session) -> bool {
fn is_enabled(&self, _tcx: TyCtxt<'tcx>) -> bool {
true
}

@@ -128,8 +127,8 @@ where
self.0.name()
}

fn is_enabled(&self, sess: &Session) -> bool {
self.0.is_enabled(sess)
fn is_enabled(&self, tcx: TyCtxt<'tcx>) -> bool {
self.0.is_enabled(tcx)
}

fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
@@ -155,8 +154,8 @@ where
self.1.name()
}

fn is_enabled(&self, sess: &Session) -> bool {
sess.mir_opt_level() >= self.0 as usize
fn is_enabled(&self, tcx: TyCtxt<'tcx>) -> bool {
tcx.sess.mir_opt_level() >= self.0 as usize
}

fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
@@ -210,7 +209,7 @@ where
let name = pass.name();

if !pass.can_be_overridden() {
return pass.is_enabled(tcx.sess);
return pass.is_enabled(tcx);
}

let overridden_passes = &tcx.sess.opts.unstable_opts.mir_enable_passes;
@@ -224,7 +223,7 @@ where
*polarity
});
let suppressed = !pass.is_required() && matches!(optimizations, Optimizations::Suppressed);
overridden.unwrap_or_else(|| !suppressed && pass.is_enabled(tcx.sess))
overridden.unwrap_or_else(|| !suppressed && pass.is_enabled(tcx))
}

fn run_passes_inner<'tcx>(
5 changes: 2 additions & 3 deletions compiler/rustc_mir_transform/src/prettify.rs
Original file line number Diff line number Diff line change
@@ -9,7 +9,6 @@ use rustc_index::{IndexSlice, IndexVec};
use rustc_middle::mir::visit::{MutVisitor, PlaceContext, Visitor};
use rustc_middle::mir::*;
use rustc_middle::ty::TyCtxt;
use rustc_session::Session;

/// Rearranges the basic blocks into a *reverse post-order*.
///
@@ -18,7 +17,7 @@ use rustc_session::Session;
pub(super) struct ReorderBasicBlocks;

impl<'tcx> crate::MirPass<'tcx> for ReorderBasicBlocks {
fn is_enabled(&self, _session: &Session) -> bool {
fn is_enabled(&self, _tcx: TyCtxt<'tcx>) -> bool {
false
}

@@ -50,7 +49,7 @@ impl<'tcx> crate::MirPass<'tcx> for ReorderBasicBlocks {
pub(super) struct ReorderLocals;

impl<'tcx> crate::MirPass<'tcx> for ReorderLocals {
fn is_enabled(&self, _session: &Session) -> bool {
fn is_enabled(&self, _tcx: TyCtxt<'tcx>) -> bool {
false
}

4 changes: 2 additions & 2 deletions compiler/rustc_mir_transform/src/ref_prop.rs
Original file line number Diff line number Diff line change
@@ -72,8 +72,8 @@ use crate::ssa::{SsaLocals, StorageLiveLocals};
pub(super) struct ReferencePropagation;

impl<'tcx> crate::MirPass<'tcx> for ReferencePropagation {
fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
sess.mir_opt_level() >= 2
fn is_enabled(&self, tcx: TyCtxt<'tcx>) -> bool {
tcx.sess.mir_opt_level() >= 2
}

#[instrument(level = "trace", skip(self, tcx, body))]
4 changes: 2 additions & 2 deletions compiler/rustc_mir_transform/src/remove_noop_landing_pads.rs
Original file line number Diff line number Diff line change
@@ -12,8 +12,8 @@ use crate::patch::MirPatch;
pub(super) struct RemoveNoopLandingPads;

impl<'tcx> crate::MirPass<'tcx> for RemoveNoopLandingPads {
fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
sess.panic_strategy() != PanicStrategy::Abort
fn is_enabled(&self, tcx: TyCtxt<'tcx>) -> bool {
tcx.sess.panic_strategy() != PanicStrategy::Abort
}

fn run_pass(&self, _tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
4 changes: 2 additions & 2 deletions compiler/rustc_mir_transform/src/remove_place_mention.rs
Original file line number Diff line number Diff line change
@@ -7,8 +7,8 @@ use tracing::trace;
pub(super) struct RemovePlaceMention;

impl<'tcx> crate::MirPass<'tcx> for RemovePlaceMention {
fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
!sess.opts.unstable_opts.mir_preserve_ub
fn is_enabled(&self, tcx: TyCtxt<'tcx>) -> bool {
!tcx.sess.opts.unstable_opts.mir_preserve_ub
}

fn run_pass(&self, _: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
4 changes: 2 additions & 2 deletions compiler/rustc_mir_transform/src/remove_storage_markers.rs
Original file line number Diff line number Diff line change
@@ -7,8 +7,8 @@ use tracing::trace;
pub(super) struct RemoveStorageMarkers;

impl<'tcx> crate::MirPass<'tcx> for RemoveStorageMarkers {
fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
sess.mir_opt_level() > 0 && !sess.emit_lifetime_markers()
fn is_enabled(&self, tcx: TyCtxt<'tcx>) -> bool {
tcx.sess.mir_opt_level() > 0 && !tcx.sess.emit_lifetime_markers()
}

fn run_pass(&self, _tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
4 changes: 2 additions & 2 deletions compiler/rustc_mir_transform/src/remove_zsts.rs
Original file line number Diff line number Diff line change
@@ -7,8 +7,8 @@ use rustc_middle::ty::{self, Ty, TyCtxt};
pub(super) struct RemoveZsts;

impl<'tcx> crate::MirPass<'tcx> for RemoveZsts {
fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
sess.mir_opt_level() > 0
fn is_enabled(&self, tcx: TyCtxt<'tcx>) -> bool {
tcx.sess.mir_opt_level() > 0
}

fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
4 changes: 2 additions & 2 deletions compiler/rustc_mir_transform/src/simplify.rs
Original file line number Diff line number Diff line change
@@ -406,8 +406,8 @@ impl<'tcx> crate::MirPass<'tcx> for SimplifyLocals {
}
}

fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
sess.mir_opt_level() > 0
fn is_enabled(&self, tcx: TyCtxt<'tcx>) -> bool {
tcx.sess.mir_opt_level() > 0
}

fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
Original file line number Diff line number Diff line change
@@ -26,8 +26,8 @@ use tracing::trace;
pub(super) struct SimplifyComparisonIntegral;

impl<'tcx> crate::MirPass<'tcx> for SimplifyComparisonIntegral {
fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
sess.mir_opt_level() > 0
fn is_enabled(&self, tcx: TyCtxt<'tcx>) -> bool {
tcx.sess.mir_opt_level() > 0
}

fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
4 changes: 2 additions & 2 deletions compiler/rustc_mir_transform/src/single_use_consts.rs
Original file line number Diff line number Diff line change
@@ -22,8 +22,8 @@ use rustc_middle::ty::TyCtxt;
pub(super) struct SingleUseConsts;

impl<'tcx> crate::MirPass<'tcx> for SingleUseConsts {
fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
sess.mir_opt_level() > 0
fn is_enabled(&self, tcx: TyCtxt<'tcx>) -> bool {
tcx.sess.mir_opt_level() > 0
}

fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
4 changes: 2 additions & 2 deletions compiler/rustc_mir_transform/src/sroa.rs
Original file line number Diff line number Diff line change
@@ -15,8 +15,8 @@ use crate::patch::MirPatch;
pub(super) struct ScalarReplacementOfAggregates;

impl<'tcx> crate::MirPass<'tcx> for ScalarReplacementOfAggregates {
fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
sess.mir_opt_level() >= 2
fn is_enabled(&self, tcx: TyCtxt<'tcx>) -> bool {
tcx.sess.mir_opt_level() >= 2
}

#[instrument(level = "debug", skip(self, tcx, body))]
4 changes: 2 additions & 2 deletions compiler/rustc_mir_transform/src/strip_debuginfo.rs
Original file line number Diff line number Diff line change
@@ -9,8 +9,8 @@ use rustc_session::config::MirStripDebugInfo;
pub(super) struct StripDebugInfo;

impl<'tcx> crate::MirPass<'tcx> for StripDebugInfo {
fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
sess.opts.unstable_opts.mir_strip_debuginfo != MirStripDebugInfo::None
fn is_enabled(&self, tcx: TyCtxt<'tcx>) -> bool {
tcx.sess.opts.unstable_opts.mir_strip_debuginfo != MirStripDebugInfo::None
}

fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
Original file line number Diff line number Diff line change
@@ -78,8 +78,8 @@ fn variant_discriminants<'tcx>(
}

impl<'tcx> crate::MirPass<'tcx> for UnreachableEnumBranching {
fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
sess.mir_opt_level() > 0
fn is_enabled(&self, tcx: TyCtxt<'tcx>) -> bool {
tcx.sess.mir_opt_level() > 0
}

fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
8 changes: 4 additions & 4 deletions compiler/rustc_mir_transform/src/unreachable_prop.rs
Original file line number Diff line number Diff line change
@@ -13,13 +13,13 @@ use crate::patch::MirPatch;

pub(super) struct UnreachablePropagation;

impl crate::MirPass<'_> for UnreachablePropagation {
fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
impl<'tcx> crate::MirPass<'tcx> for UnreachablePropagation {
fn is_enabled(&self, tcx: TyCtxt<'tcx>) -> bool {
// Enable only under -Zmir-opt-level=2 as this can make programs less debuggable.
sess.mir_opt_level() >= 2
tcx.sess.mir_opt_level() >= 2
}

fn run_pass<'tcx>(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
let mut patch = MirPatch::new(body);
let mut unreachable_blocks = FxHashSet::default();