Skip to content

Commit 3a721c1

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 + 2724389 commit 3a721c1

38 files changed

+103
-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: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ use crate::pass_manager::MirLint;
1616
pub(super) struct CheckCallRecursion;
1717

1818
impl<'tcx> MirLint<'tcx> for CheckCallRecursion {
19+
fn is_enabled(&self, tcx: TyCtxt<'tcx>) -> bool {
20+
!tcx.lints_that_dont_need_to_run(()).contains(&UNCONDITIONAL_RECURSION)
21+
}
22+
1923
fn run_lint(&self, tcx: TyCtxt<'tcx>, body: &Body<'tcx>) {
2024
let def_id = body.source.def_id().expect_local();
2125

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

4044
impl<'tcx> MirLint<'tcx> for CheckDropRecursion {
45+
fn is_enabled(&self, _tcx: TyCtxt<'tcx>) -> bool {
46+
!tcx.lints_that_dont_need_to_run(()).contains(&UNCONDITIONAL_RECURSION)
47+
}
48+
4149
fn run_lint(&self, tcx: TyCtxt<'tcx>, body: &Body<'tcx>) {
4250
let def_id = body.source.def_id().expect_local();
4351

compiler/rustc_mir_transform/src/check_const_item_mutation.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ use crate::errors;
1111
pub(super) struct CheckConstItemMutation;
1212

1313
impl<'tcx> crate::MirLint<'tcx> for CheckConstItemMutation {
14+
fn is_enabled(&self, tcx: TyCtxt<'tcx>) -> bool {
15+
!tcx.lints_that_dont_need_to_run(()).contains(&CONST_ITEM_MUTATION)
16+
}
17+
1418
fn run_lint(&self, tcx: TyCtxt<'tcx>, body: &Body<'tcx>) {
1519
let mut checker = ConstMutationChecker { body, tcx, target_local: None };
1620
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)