Skip to content

Commit a17e426

Browse files
Stop using MoveDataParamEnv for places that don't need a param-env
1 parent 6106b05 commit a17e426

File tree

6 files changed

+50
-64
lines changed

6 files changed

+50
-64
lines changed

compiler/rustc_borrowck/src/lib.rs

+6-9
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ use rustc_mir_dataflow::impls::{
4848
use rustc_mir_dataflow::move_paths::{InitIndex, MoveOutIndex, MovePathIndex};
4949
use rustc_mir_dataflow::move_paths::{InitLocation, LookupResult, MoveData};
5050
use rustc_mir_dataflow::Analysis;
51-
use rustc_mir_dataflow::MoveDataParamEnv;
5251

5352
use crate::session_diagnostics::VarNeedNotMut;
5453

@@ -196,17 +195,15 @@ fn do_mir_borrowck<'tcx>(
196195
.iter_enumerated()
197196
.map(|(idx, body)| (idx, MoveData::gather_moves(body, tcx, param_env, |_| true)));
198197

199-
let mdpe = MoveDataParamEnv { move_data, param_env };
200-
201-
let mut flow_inits = MaybeInitializedPlaces::new(tcx, body, &mdpe)
198+
let mut flow_inits = MaybeInitializedPlaces::new(tcx, body, &move_data)
202199
.into_engine(tcx, body)
203200
.pass_name("borrowck")
204201
.iterate_to_fixpoint()
205202
.into_results_cursor(body);
206203

207204
let locals_are_invalidated_at_exit = tcx.hir().body_owner_kind(def).is_fn_or_closure();
208205
let borrow_set =
209-
Rc::new(BorrowSet::build(tcx, body, locals_are_invalidated_at_exit, &mdpe.move_data));
206+
Rc::new(BorrowSet::build(tcx, body, locals_are_invalidated_at_exit, &move_data));
210207

211208
// Compute non-lexical lifetimes.
212209
let nll::NllOutput {
@@ -224,7 +221,7 @@ fn do_mir_borrowck<'tcx>(
224221
&location_table,
225222
param_env,
226223
&mut flow_inits,
227-
&mdpe.move_data,
224+
&move_data,
228225
&borrow_set,
229226
tcx.closure_captures(def),
230227
consumer_options,
@@ -256,11 +253,11 @@ fn do_mir_borrowck<'tcx>(
256253
.into_engine(tcx, body)
257254
.pass_name("borrowck")
258255
.iterate_to_fixpoint();
259-
let flow_uninits = MaybeUninitializedPlaces::new(tcx, body, &mdpe)
256+
let flow_uninits = MaybeUninitializedPlaces::new(tcx, body, &move_data)
260257
.into_engine(tcx, body)
261258
.pass_name("borrowck")
262259
.iterate_to_fixpoint();
263-
let flow_ever_inits = EverInitializedPlaces::new(body, &mdpe)
260+
let flow_ever_inits = EverInitializedPlaces::new(body, &move_data)
264261
.into_engine(tcx, body)
265262
.pass_name("borrowck")
266263
.iterate_to_fixpoint();
@@ -326,7 +323,7 @@ fn do_mir_borrowck<'tcx>(
326323
infcx: &infcx,
327324
param_env,
328325
body,
329-
move_data: &mdpe.move_data,
326+
move_data: &move_data,
330327
location_table: &location_table,
331328
movable_coroutine,
332329
locals_are_invalidated_at_exit,

compiler/rustc_mir_dataflow/src/drop_flag_effects.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use rustc_target::abi::VariantIdx;
44
use tracing::debug;
55

66
use super::move_paths::{InitKind, LookupResult, MoveData, MovePathIndex};
7-
use super::MoveDataParamEnv;
87

98
pub fn move_path_children_matching<'tcx, F>(
109
move_data: &MoveData<'tcx>,
@@ -70,12 +69,11 @@ pub fn on_all_children_bits<'tcx, F>(
7069

7170
pub fn drop_flag_effects_for_function_entry<'tcx, F>(
7271
body: &Body<'tcx>,
73-
ctxt: &MoveDataParamEnv<'tcx>,
72+
move_data: &MoveData<'tcx>,
7473
mut callback: F,
7574
) where
7675
F: FnMut(MovePathIndex, DropFlagState),
7776
{
78-
let move_data = &ctxt.move_data;
7977
for arg in body.args_iter() {
8078
let place = mir::Place::from(arg);
8179
let lookup_result = move_data.rev_lookup.find(place.as_ref());
@@ -87,13 +85,12 @@ pub fn drop_flag_effects_for_function_entry<'tcx, F>(
8785

8886
pub fn drop_flag_effects_for_location<'tcx, F>(
8987
body: &Body<'tcx>,
90-
ctxt: &MoveDataParamEnv<'tcx>,
88+
move_data: &MoveData<'tcx>,
9189
loc: Location,
9290
mut callback: F,
9391
) where
9492
F: FnMut(MovePathIndex, DropFlagState),
9593
{
96-
let move_data = &ctxt.move_data;
9794
debug!("drop_flag_effects_for_location({:?})", loc);
9895

9996
// first, move out of the RHS

compiler/rustc_mir_dataflow/src/impls/initialized.rs

+25-34
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use crate::elaborate_drops::DropFlagState;
1111
use crate::framework::SwitchIntEdgeEffects;
1212
use crate::move_paths::{HasMoveData, InitIndex, InitKind, LookupResult, MoveData, MovePathIndex};
1313
use crate::on_lookup_result_bits;
14-
use crate::MoveDataParamEnv;
1514
use crate::{drop_flag_effects, on_all_children_bits};
1615
use crate::{lattice, AnalysisDomain, GenKill, GenKillAnalysis, MaybeReachable};
1716

@@ -53,17 +52,13 @@ use crate::{lattice, AnalysisDomain, GenKill, GenKillAnalysis, MaybeReachable};
5352
pub struct MaybeInitializedPlaces<'a, 'mir, 'tcx> {
5453
tcx: TyCtxt<'tcx>,
5554
body: &'mir Body<'tcx>,
56-
mdpe: &'a MoveDataParamEnv<'tcx>,
55+
move_data: &'a MoveData<'tcx>,
5756
skip_unreachable_unwind: bool,
5857
}
5958

6059
impl<'a, 'mir, 'tcx> MaybeInitializedPlaces<'a, 'mir, 'tcx> {
61-
pub fn new(
62-
tcx: TyCtxt<'tcx>,
63-
body: &'mir Body<'tcx>,
64-
mdpe: &'a MoveDataParamEnv<'tcx>,
65-
) -> Self {
66-
MaybeInitializedPlaces { tcx, body, mdpe, skip_unreachable_unwind: false }
60+
pub fn new(tcx: TyCtxt<'tcx>, body: &'mir Body<'tcx>, move_data: &'a MoveData<'tcx>) -> Self {
61+
MaybeInitializedPlaces { tcx, body, move_data, skip_unreachable_unwind: false }
6762
}
6863

6964
pub fn skipping_unreachable_unwind(mut self) -> Self {
@@ -90,7 +85,7 @@ impl<'a, 'mir, 'tcx> MaybeInitializedPlaces<'a, 'mir, 'tcx> {
9085

9186
impl<'a, 'mir, 'tcx> HasMoveData<'tcx> for MaybeInitializedPlaces<'a, 'mir, 'tcx> {
9287
fn move_data(&self) -> &MoveData<'tcx> {
93-
&self.mdpe.move_data
88+
self.move_data
9489
}
9590
}
9691

@@ -132,22 +127,18 @@ impl<'a, 'mir, 'tcx> HasMoveData<'tcx> for MaybeInitializedPlaces<'a, 'mir, 'tcx
132127
pub struct MaybeUninitializedPlaces<'a, 'mir, 'tcx> {
133128
tcx: TyCtxt<'tcx>,
134129
body: &'mir Body<'tcx>,
135-
mdpe: &'a MoveDataParamEnv<'tcx>,
130+
move_data: &'a MoveData<'tcx>,
136131

137132
mark_inactive_variants_as_uninit: bool,
138133
skip_unreachable_unwind: BitSet<mir::BasicBlock>,
139134
}
140135

141136
impl<'a, 'mir, 'tcx> MaybeUninitializedPlaces<'a, 'mir, 'tcx> {
142-
pub fn new(
143-
tcx: TyCtxt<'tcx>,
144-
body: &'mir Body<'tcx>,
145-
mdpe: &'a MoveDataParamEnv<'tcx>,
146-
) -> Self {
137+
pub fn new(tcx: TyCtxt<'tcx>, body: &'mir Body<'tcx>, move_data: &'a MoveData<'tcx>) -> Self {
147138
MaybeUninitializedPlaces {
148139
tcx,
149140
body,
150-
mdpe,
141+
move_data,
151142
mark_inactive_variants_as_uninit: false,
152143
skip_unreachable_unwind: BitSet::new_empty(body.basic_blocks.len()),
153144
}
@@ -174,7 +165,7 @@ impl<'a, 'mir, 'tcx> MaybeUninitializedPlaces<'a, 'mir, 'tcx> {
174165

175166
impl<'a, 'tcx> HasMoveData<'tcx> for MaybeUninitializedPlaces<'a, '_, 'tcx> {
176167
fn move_data(&self) -> &MoveData<'tcx> {
177-
&self.mdpe.move_data
168+
self.move_data
178169
}
179170
}
180171

@@ -214,18 +205,18 @@ impl<'a, 'tcx> HasMoveData<'tcx> for MaybeUninitializedPlaces<'a, '_, 'tcx> {
214205
/// that would require a dynamic drop-flag at that statement.
215206
pub struct DefinitelyInitializedPlaces<'a, 'tcx> {
216207
body: &'a Body<'tcx>,
217-
mdpe: &'a MoveDataParamEnv<'tcx>,
208+
move_data: &'a MoveData<'tcx>,
218209
}
219210

220211
impl<'a, 'tcx> DefinitelyInitializedPlaces<'a, 'tcx> {
221-
pub fn new(body: &'a Body<'tcx>, mdpe: &'a MoveDataParamEnv<'tcx>) -> Self {
222-
DefinitelyInitializedPlaces { body, mdpe }
212+
pub fn new(body: &'a Body<'tcx>, move_data: &'a MoveData<'tcx>) -> Self {
213+
DefinitelyInitializedPlaces { body, move_data }
223214
}
224215
}
225216

226217
impl<'a, 'tcx> HasMoveData<'tcx> for DefinitelyInitializedPlaces<'a, 'tcx> {
227218
fn move_data(&self) -> &MoveData<'tcx> {
228-
&self.mdpe.move_data
219+
self.move_data
229220
}
230221
}
231222

@@ -260,18 +251,18 @@ impl<'a, 'tcx> HasMoveData<'tcx> for DefinitelyInitializedPlaces<'a, 'tcx> {
260251
/// ```
261252
pub struct EverInitializedPlaces<'a, 'mir, 'tcx> {
262253
body: &'mir Body<'tcx>,
263-
mdpe: &'a MoveDataParamEnv<'tcx>,
254+
move_data: &'a MoveData<'tcx>,
264255
}
265256

266257
impl<'a, 'mir, 'tcx> EverInitializedPlaces<'a, 'mir, 'tcx> {
267-
pub fn new(body: &'mir Body<'tcx>, mdpe: &'a MoveDataParamEnv<'tcx>) -> Self {
268-
EverInitializedPlaces { body, mdpe }
258+
pub fn new(body: &'mir Body<'tcx>, move_data: &'a MoveData<'tcx>) -> Self {
259+
EverInitializedPlaces { body, move_data }
269260
}
270261
}
271262

272263
impl<'a, 'tcx> HasMoveData<'tcx> for EverInitializedPlaces<'a, '_, 'tcx> {
273264
fn move_data(&self) -> &MoveData<'tcx> {
274-
&self.mdpe.move_data
265+
self.move_data
275266
}
276267
}
277268

@@ -329,7 +320,7 @@ impl<'tcx> AnalysisDomain<'tcx> for MaybeInitializedPlaces<'_, '_, 'tcx> {
329320
fn initialize_start_block(&self, _: &mir::Body<'tcx>, state: &mut Self::Domain) {
330321
*state =
331322
MaybeReachable::Reachable(ChunkedBitSet::new_empty(self.move_data().move_paths.len()));
332-
drop_flag_effects_for_function_entry(self.body, self.mdpe, |path, s| {
323+
drop_flag_effects_for_function_entry(self.body, self.move_data, |path, s| {
333324
assert!(s == DropFlagState::Present);
334325
state.gen_(path);
335326
});
@@ -349,7 +340,7 @@ impl<'tcx> GenKillAnalysis<'tcx> for MaybeInitializedPlaces<'_, '_, 'tcx> {
349340
statement: &mir::Statement<'tcx>,
350341
location: Location,
351342
) {
352-
drop_flag_effects_for_location(self.body, self.mdpe, location, |path, s| {
343+
drop_flag_effects_for_location(self.body, self.move_data, location, |path, s| {
353344
Self::update_bits(trans, path, s)
354345
});
355346

@@ -381,7 +372,7 @@ impl<'tcx> GenKillAnalysis<'tcx> for MaybeInitializedPlaces<'_, '_, 'tcx> {
381372
{
382373
edges = TerminatorEdges::Single(target);
383374
}
384-
drop_flag_effects_for_location(self.body, self.mdpe, location, |path, s| {
375+
drop_flag_effects_for_location(self.body, self.move_data, location, |path, s| {
385376
Self::update_bits(state, path, s)
386377
});
387378
edges
@@ -466,7 +457,7 @@ impl<'tcx> AnalysisDomain<'tcx> for MaybeUninitializedPlaces<'_, '_, 'tcx> {
466457
// set all bits to 1 (uninit) before gathering counter-evidence
467458
state.insert_all();
468459

469-
drop_flag_effects_for_function_entry(self.body, self.mdpe, |path, s| {
460+
drop_flag_effects_for_function_entry(self.body, self.move_data, |path, s| {
470461
assert!(s == DropFlagState::Present);
471462
state.remove(path);
472463
});
@@ -486,7 +477,7 @@ impl<'tcx> GenKillAnalysis<'tcx> for MaybeUninitializedPlaces<'_, '_, 'tcx> {
486477
_statement: &mir::Statement<'tcx>,
487478
location: Location,
488479
) {
489-
drop_flag_effects_for_location(self.body, self.mdpe, location, |path, s| {
480+
drop_flag_effects_for_location(self.body, self.move_data, location, |path, s| {
490481
Self::update_bits(trans, path, s)
491482
});
492483

@@ -500,7 +491,7 @@ impl<'tcx> GenKillAnalysis<'tcx> for MaybeUninitializedPlaces<'_, '_, 'tcx> {
500491
terminator: &'mir mir::Terminator<'tcx>,
501492
location: Location,
502493
) -> TerminatorEdges<'mir, 'tcx> {
503-
drop_flag_effects_for_location(self.body, self.mdpe, location, |path, s| {
494+
drop_flag_effects_for_location(self.body, self.move_data, location, |path, s| {
504495
Self::update_bits(trans, path, s)
505496
});
506497
if self.skip_unreachable_unwind.contains(location.block) {
@@ -593,7 +584,7 @@ impl<'a, 'tcx> AnalysisDomain<'tcx> for DefinitelyInitializedPlaces<'a, 'tcx> {
593584
fn initialize_start_block(&self, _: &mir::Body<'tcx>, state: &mut Self::Domain) {
594585
state.0.clear();
595586

596-
drop_flag_effects_for_function_entry(self.body, self.mdpe, |path, s| {
587+
drop_flag_effects_for_function_entry(self.body, self.move_data, |path, s| {
597588
assert!(s == DropFlagState::Present);
598589
state.0.insert(path);
599590
});
@@ -613,7 +604,7 @@ impl<'tcx> GenKillAnalysis<'tcx> for DefinitelyInitializedPlaces<'_, 'tcx> {
613604
_statement: &mir::Statement<'tcx>,
614605
location: Location,
615606
) {
616-
drop_flag_effects_for_location(self.body, self.mdpe, location, |path, s| {
607+
drop_flag_effects_for_location(self.body, self.move_data, location, |path, s| {
617608
Self::update_bits(trans, path, s)
618609
})
619610
}
@@ -624,7 +615,7 @@ impl<'tcx> GenKillAnalysis<'tcx> for DefinitelyInitializedPlaces<'_, 'tcx> {
624615
terminator: &'mir mir::Terminator<'tcx>,
625616
location: Location,
626617
) -> TerminatorEdges<'mir, 'tcx> {
627-
drop_flag_effects_for_location(self.body, self.mdpe, location, |path, s| {
618+
drop_flag_effects_for_location(self.body, self.move_data, location, |path, s| {
628619
Self::update_bits(trans, path, s)
629620
});
630621
terminator.edges()

compiler/rustc_mir_dataflow/src/rustc_peek.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use crate::impls::{
88
};
99
use crate::move_paths::{HasMoveData, MoveData};
1010
use crate::move_paths::{LookupResult, MovePathIndex};
11-
use crate::MoveDataParamEnv;
1211
use crate::{Analysis, JoinSemiLattice, ResultsCursor};
1312
use rustc_ast::MetaItem;
1413
use rustc_hir::def_id::DefId;
@@ -48,26 +47,25 @@ impl<'tcx> MirPass<'tcx> for SanityCheck {
4847

4948
let param_env = tcx.param_env(def_id);
5049
let move_data = MoveData::gather_moves(body, tcx, param_env, |_| true);
51-
let mdpe = MoveDataParamEnv { move_data, param_env };
5250

5351
if has_rustc_mir_with(tcx, def_id, sym::rustc_peek_maybe_init).is_some() {
54-
let flow_inits = MaybeInitializedPlaces::new(tcx, body, &mdpe)
52+
let flow_inits = MaybeInitializedPlaces::new(tcx, body, &move_data)
5553
.into_engine(tcx, body)
5654
.iterate_to_fixpoint();
5755

5856
sanity_check_via_rustc_peek(tcx, flow_inits.into_results_cursor(body));
5957
}
6058

6159
if has_rustc_mir_with(tcx, def_id, sym::rustc_peek_maybe_uninit).is_some() {
62-
let flow_uninits = MaybeUninitializedPlaces::new(tcx, body, &mdpe)
60+
let flow_uninits = MaybeUninitializedPlaces::new(tcx, body, &move_data)
6361
.into_engine(tcx, body)
6462
.iterate_to_fixpoint();
6563

6664
sanity_check_via_rustc_peek(tcx, flow_uninits.into_results_cursor(body));
6765
}
6866

6967
if has_rustc_mir_with(tcx, def_id, sym::rustc_peek_definite_init).is_some() {
70-
let flow_def_inits = DefinitelyInitializedPlaces::new(body, &mdpe)
68+
let flow_def_inits = DefinitelyInitializedPlaces::new(body, &move_data)
7169
.into_engine(tcx, body)
7270
.iterate_to_fixpoint();
7371

compiler/rustc_mir_transform/src/elaborate_drops.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,15 @@ impl<'tcx> MirPass<'tcx> for ElaborateDrops {
6060
let elaborate_patch = {
6161
let env = MoveDataParamEnv { move_data, param_env };
6262

63-
let mut inits = MaybeInitializedPlaces::new(tcx, body, &env)
63+
let mut inits = MaybeInitializedPlaces::new(tcx, body, &env.move_data)
6464
.skipping_unreachable_unwind()
6565
.into_engine(tcx, body)
6666
.pass_name("elaborate_drops")
6767
.iterate_to_fixpoint()
6868
.into_results_cursor(body);
6969
let dead_unwinds = compute_dead_unwinds(body, &mut inits);
7070

71-
let uninits = MaybeUninitializedPlaces::new(tcx, body, &env)
71+
let uninits = MaybeUninitializedPlaces::new(tcx, body, &env.move_data)
7272
.mark_inactive_variants_as_uninit()
7373
.skipping_unreachable_unwind(dead_unwinds)
7474
.into_engine(tcx, body)
@@ -441,9 +441,13 @@ impl<'b, 'mir, 'tcx> ElaborateDropsCtxt<'b, 'mir, 'tcx> {
441441

442442
fn drop_flags_for_args(&mut self) {
443443
let loc = Location::START;
444-
rustc_mir_dataflow::drop_flag_effects_for_function_entry(self.body, self.env, |path, ds| {
445-
self.set_drop_flag(loc, path, ds);
446-
})
444+
rustc_mir_dataflow::drop_flag_effects_for_function_entry(
445+
self.body,
446+
&self.env.move_data,
447+
|path, ds| {
448+
self.set_drop_flag(loc, path, ds);
449+
},
450+
)
447451
}
448452

449453
fn drop_flags_for_locs(&mut self) {
@@ -476,7 +480,7 @@ impl<'b, 'mir, 'tcx> ElaborateDropsCtxt<'b, 'mir, 'tcx> {
476480
let loc = Location { block: bb, statement_index: i };
477481
rustc_mir_dataflow::drop_flag_effects_for_location(
478482
self.body,
479-
self.env,
483+
&self.env.move_data,
480484
loc,
481485
|path, ds| self.set_drop_flag(loc, path, ds),
482486
)

0 commit comments

Comments
 (0)