Skip to content

Commit 2496008

Browse files
Use TyCtxt instead of Sess in is_enabled
1 parent 706f244 commit 2496008

33 files changed

+78
-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_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>) {

compiler/rustc_mir_transform/src/early_otherwise_branch.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ use crate::patch::MirPatch;
9393
pub(super) struct EarlyOtherwiseBranch;
9494

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

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

compiler/rustc_mir_transform/src/gvn.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ use crate::ssa::SsaLocals;
114114
pub(super) struct GVN;
115115

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

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

compiler/rustc_mir_transform/src/inline.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,17 @@ struct CallSite<'tcx> {
4343
pub struct Inline;
4444

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

51-
match sess.mir_opt_level() {
51+
match tcx.sess.mir_opt_level() {
5252
0 | 1 => false,
5353
2 => {
54-
(sess.opts.optimize == OptLevel::More || sess.opts.optimize == OptLevel::Aggressive)
55-
&& sess.opts.incremental == None
54+
(tcx.sess.opts.optimize == OptLevel::More
55+
|| tcx.sess.opts.optimize == OptLevel::Aggressive)
56+
&& tcx.sess.opts.incremental == None
5657
}
5758
_ => true,
5859
}
@@ -82,7 +83,7 @@ impl ForceInline {
8283
}
8384

8485
impl<'tcx> crate::MirPass<'tcx> for ForceInline {
85-
fn is_enabled(&self, _: &rustc_session::Session) -> bool {
86+
fn is_enabled(&self, _: TyCtxt<'tcx>) -> bool {
8687
true
8788
}
8889

compiler/rustc_mir_transform/src/instsimplify.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ impl<'tcx> crate::MirPass<'tcx> for InstSimplify {
2424
}
2525
}
2626

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

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

compiler/rustc_mir_transform/src/jump_threading.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ const MAX_COST: usize = 100;
6161
const MAX_PLACES: usize = 100;
6262

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

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

compiler/rustc_mir_transform/src/large_enums.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use rustc_middle::mir::interpret::AllocId;
44
use rustc_middle::mir::*;
55
use rustc_middle::ty::util::IntTypeExt;
66
use rustc_middle::ty::{self, AdtDef, Ty, TyCtxt};
7-
use rustc_session::Session;
87

98
use crate::patch::MirPatch;
109

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

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

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

compiler/rustc_mir_transform/src/lower_slice_len.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ use rustc_middle::ty::TyCtxt;
88
pub(super) struct LowerSliceLenCalls;
99

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

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

compiler/rustc_mir_transform/src/match_branches.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ use crate::patch::MirPatch;
1313
pub(super) struct MatchBranchSimplification;
1414

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

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

compiler/rustc_mir_transform/src/mentioned_items.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use rustc_middle::mir::visit::Visitor;
22
use rustc_middle::mir::{self, Location, MentionedItem};
33
use rustc_middle::ty::adjustment::PointerCoercion;
44
use rustc_middle::ty::{self, TyCtxt};
5-
use rustc_session::Session;
65
use rustc_span::source_map::Spanned;
76

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

1615
impl<'tcx> crate::MirPass<'tcx> for MentionedItems {
17-
fn is_enabled(&self, _sess: &Session) -> bool {
16+
fn is_enabled(&self, _tcx: TyCtxt<'tcx>) -> bool {
1817
// If this pass is skipped the collector assume that nothing got mentioned! We could
1918
// potentially skip it in opt-level 0 if we are sure that opt-level will never *remove* uses
2019
// of anything, but that still seems fragile. Furthermore, even debug builds use level 1, so

compiler/rustc_mir_transform/src/multiple_return_terminators.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ use crate::simplify;
1010
pub(super) struct MultipleReturnTerminators;
1111

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

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

compiler/rustc_mir_transform/src/nrvo.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ use tracing::{debug, trace};
3333
pub(super) struct RenameReturnPlace;
3434

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

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

compiler/rustc_mir_transform/src/pass_manager.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use std::collections::hash_map::Entry;
44
use rustc_data_structures::fx::{FxHashMap, FxIndexSet};
55
use rustc_middle::mir::{self, Body, MirPhase, RuntimePhase};
66
use rustc_middle::ty::TyCtxt;
7-
use rustc_session::Session;
87
use tracing::trace;
98

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

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

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

112-
fn is_enabled(&self, _sess: &Session) -> bool {
111+
fn is_enabled(&self, _tcx: TyCtxt<'tcx>) -> bool {
113112
true
114113
}
115114

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

131-
fn is_enabled(&self, sess: &Session) -> bool {
132-
self.0.is_enabled(sess)
130+
fn is_enabled(&self, tcx: TyCtxt<'tcx>) -> bool {
131+
self.0.is_enabled(tcx)
133132
}
134133

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

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

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

212211
if !pass.can_be_overridden() {
213-
return pass.is_enabled(tcx.sess);
212+
return pass.is_enabled(tcx);
214213
}
215214

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

230229
fn run_passes_inner<'tcx>(

compiler/rustc_mir_transform/src/prettify.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use rustc_index::{IndexSlice, IndexVec};
99
use rustc_middle::mir::visit::{MutVisitor, PlaceContext, Visitor};
1010
use rustc_middle::mir::*;
1111
use rustc_middle::ty::TyCtxt;
12-
use rustc_session::Session;
1312

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

2019
impl<'tcx> crate::MirPass<'tcx> for ReorderBasicBlocks {
21-
fn is_enabled(&self, _session: &Session) -> bool {
20+
fn is_enabled(&self, _tcx: TyCtxt<'tcx>) -> bool {
2221
false
2322
}
2423

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

5251
impl<'tcx> crate::MirPass<'tcx> for ReorderLocals {
53-
fn is_enabled(&self, _session: &Session) -> bool {
52+
fn is_enabled(&self, _tcx: TyCtxt<'tcx>) -> bool {
5453
false
5554
}
5655

compiler/rustc_mir_transform/src/ref_prop.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ use crate::ssa::{SsaLocals, StorageLiveLocals};
7272
pub(super) struct ReferencePropagation;
7373

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

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

compiler/rustc_mir_transform/src/remove_noop_landing_pads.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ use crate::patch::MirPatch;
1212
pub(super) struct RemoveNoopLandingPads;
1313

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

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

compiler/rustc_mir_transform/src/remove_place_mention.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ use tracing::trace;
77
pub(super) struct RemovePlaceMention;
88

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

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

0 commit comments

Comments
 (0)