Skip to content

Commit 2557a2e

Browse files
Auto merge of #142937 - compiler-errors:ignore-lints, r=<try>
[perf] Don't run some `MirLints` if lints are not enabled <!-- homu-ignore:start --> <!-- If this PR is related to an unstable feature or an otherwise tracked effort, please link to the relevant tracking issue here. If you don't know of a related tracking issue or there are none, feel free to ignore this. This PR will get automatically assigned to a reviewer. In case you would like a specific user to review your work, you can assign it to them by using r? <reviewer name> --> <!-- homu-ignore:end -->
2 parents 706f244 + e97279b commit 2557a2e

38 files changed

+107
-83
lines changed

compiler/rustc_mir_transform/src/add_retag.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ fn may_contain_reference<'tcx>(ty: Ty<'tcx>, depth: u32, tcx: TyCtxt<'tcx>) -> b
4949
}
5050

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

5656
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {

compiler/rustc_mir_transform/src/check_alignment.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@ use rustc_middle::mir::interpret::Scalar;
44
use rustc_middle::mir::visit::PlaceContext;
55
use rustc_middle::mir::*;
66
use rustc_middle::ty::{Ty, TyCtxt};
7-
use rustc_session::Session;
87

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

1110
pub(super) struct CheckAlignment;
1211

1312
impl<'tcx> crate::MirPass<'tcx> for CheckAlignment {
14-
fn is_enabled(&self, sess: &Session) -> bool {
15-
sess.ub_checks()
13+
fn is_enabled(&self, tcx: TyCtxt<'tcx>) -> bool {
14+
tcx.sess.ub_checks()
1615
}
1716

1817
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {

compiler/rustc_mir_transform/src/check_call_recursion.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use rustc_hir::LangItem;
77
use rustc_hir::def::DefKind;
88
use rustc_middle::mir::{self, BasicBlock, BasicBlocks, Body, Terminator, TerminatorKind};
99
use rustc_middle::ty::{self, GenericArg, GenericArgs, Instance, Ty, TyCtxt};
10+
use rustc_session::lint::LintId;
1011
use rustc_session::lint::builtin::UNCONDITIONAL_RECURSION;
1112
use rustc_span::Span;
1213

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

1819
impl<'tcx> MirLint<'tcx> for CheckCallRecursion {
20+
fn is_enabled(&self, tcx: TyCtxt<'tcx>) -> bool {
21+
!tcx.lints_that_dont_need_to_run(()).contains(&LintId::of(UNCONDITIONAL_RECURSION))
22+
}
23+
1924
fn run_lint(&self, tcx: TyCtxt<'tcx>, body: &Body<'tcx>) {
2025
let def_id = body.source.def_id().expect_local();
2126

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

4045
impl<'tcx> MirLint<'tcx> for CheckDropRecursion {
46+
fn is_enabled(&self, tcx: TyCtxt<'tcx>) -> bool {
47+
!tcx.lints_that_dont_need_to_run(()).contains(&LintId::of(UNCONDITIONAL_RECURSION))
48+
}
49+
4150
fn run_lint(&self, tcx: TyCtxt<'tcx>, body: &Body<'tcx>) {
4251
let def_id = body.source.def_id().expect_local();
4352

compiler/rustc_mir_transform/src/check_const_item_mutation.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use rustc_hir::HirId;
22
use rustc_middle::mir::visit::Visitor;
33
use rustc_middle::mir::*;
44
use rustc_middle::ty::TyCtxt;
5+
use rustc_session::lint::LintId;
56
use rustc_session::lint::builtin::CONST_ITEM_MUTATION;
67
use rustc_span::Span;
78
use rustc_span::def_id::DefId;
@@ -11,6 +12,10 @@ use crate::errors;
1112
pub(super) struct CheckConstItemMutation;
1213

1314
impl<'tcx> crate::MirLint<'tcx> for CheckConstItemMutation {
15+
fn is_enabled(&self, tcx: TyCtxt<'tcx>) -> bool {
16+
!tcx.lints_that_dont_need_to_run(()).contains(&LintId::of(CONST_ITEM_MUTATION))
17+
}
18+
1419
fn run_lint(&self, tcx: TyCtxt<'tcx>, body: &Body<'tcx>) {
1520
let mut checker = ConstMutationChecker { body, tcx, target_local: None };
1621
checker.visit_body(body);

compiler/rustc_mir_transform/src/check_null.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@ use rustc_index::IndexVec;
22
use rustc_middle::mir::visit::{MutatingUseContext, NonMutatingUseContext, PlaceContext};
33
use rustc_middle::mir::*;
44
use rustc_middle::ty::{Ty, TyCtxt};
5-
use rustc_session::Session;
65

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

98
pub(super) struct CheckNull;
109

1110
impl<'tcx> crate::MirPass<'tcx> for CheckNull {
12-
fn is_enabled(&self, sess: &Session) -> bool {
13-
sess.ub_checks()
11+
fn is_enabled(&self, tcx: TyCtxt<'tcx>) -> bool {
12+
tcx.sess.ub_checks()
1413
}
1514

1615
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {

compiler/rustc_mir_transform/src/copy_prop.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ use crate::ssa::SsaLocals;
2020
pub(super) struct CopyProp;
2121

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

2727
#[instrument(level = "trace", skip(self, tcx, body))]

compiler/rustc_mir_transform/src/coverage/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ use crate::coverage::mappings::ExtractedMappings;
2929
pub(super) struct InstrumentCoverage;
3030

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

3636
fn run_pass(&self, tcx: TyCtxt<'tcx>, mir_body: &mut mir::Body<'tcx>) {

compiler/rustc_mir_transform/src/dataflow_const_prop.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ const PLACE_LIMIT: usize = 100;
3535
pub(super) struct DataflowConstProp;
3636

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

4242
#[instrument(skip_all level = "debug")]

compiler/rustc_mir_transform/src/dead_store_elimination.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ impl<'tcx> crate::MirPass<'tcx> for DeadStoreElimination {
140140
}
141141
}
142142

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

147147
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {

compiler/rustc_mir_transform/src/dest_prop.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ use tracing::{debug, trace};
149149
pub(super) struct DestinationPropagation;
150150

151151
impl<'tcx> crate::MirPass<'tcx> for DestinationPropagation {
152-
fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
152+
fn is_enabled(&self, tcx: TyCtxt<'tcx>) -> bool {
153153
// For now, only run at MIR opt level 3. Two things need to be changed before this can be
154154
// turned on by default:
155155
// 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 {
158158
// 2. Despite being an overall perf improvement, this still causes a 30% regression in
159159
// keccak. We can temporarily fix this by bounding function size, but in the long term
160160
// we should fix this by being smarter about invalidating analysis results.
161-
sess.mir_opt_level() >= 3
161+
tcx.sess.mir_opt_level() >= 3
162162
}
163163

164164
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {

0 commit comments

Comments
 (0)