Skip to content

Commit f990239

Browse files
Stop using MoveDataParamEnv for places that don't need a param-env
1 parent 4db3d12 commit f990239

File tree

6 files changed

+53
-64
lines changed

6 files changed

+53
-64
lines changed

compiler/rustc_borrowck/src/lib.rs

+7-9
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ use rustc_mir_dataflow::impls::{
4545
use rustc_mir_dataflow::move_paths::{
4646
InitIndex, InitLocation, LookupResult, MoveData, MoveOutIndex, MovePathIndex,
4747
};
48-
use rustc_mir_dataflow::{Analysis, MoveDataParamEnv};
48+
use rustc_mir_dataflow::Analysis;
4949
use rustc_session::lint::builtin::UNUSED_MUT;
5050
use rustc_span::{Span, Symbol};
5151
use rustc_target::abi::FieldIdx;
@@ -194,17 +194,15 @@ fn do_mir_borrowck<'tcx>(
194194
.iter_enumerated()
195195
.map(|(idx, body)| (idx, MoveData::gather_moves(body, tcx, param_env, |_| true)));
196196

197-
let mdpe = MoveDataParamEnv { move_data, param_env };
198-
199-
let mut flow_inits = MaybeInitializedPlaces::new(tcx, body, &mdpe)
197+
let mut flow_inits = MaybeInitializedPlaces::new(tcx, body, &move_data)
200198
.into_engine(tcx, body)
201199
.pass_name("borrowck")
202200
.iterate_to_fixpoint()
203201
.into_results_cursor(body);
204202

205203
let locals_are_invalidated_at_exit = tcx.hir().body_owner_kind(def).is_fn_or_closure();
206204
let borrow_set =
207-
Rc::new(BorrowSet::build(tcx, body, locals_are_invalidated_at_exit, &mdpe.move_data));
205+
Rc::new(BorrowSet::build(tcx, body, locals_are_invalidated_at_exit, &move_data));
208206

209207
// Compute non-lexical lifetimes.
210208
let nll::NllOutput {
@@ -222,7 +220,7 @@ fn do_mir_borrowck<'tcx>(
222220
&location_table,
223221
param_env,
224222
&mut flow_inits,
225-
&mdpe.move_data,
223+
&move_data,
226224
&borrow_set,
227225
tcx.closure_captures(def),
228226
consumer_options,
@@ -254,11 +252,11 @@ fn do_mir_borrowck<'tcx>(
254252
.into_engine(tcx, body)
255253
.pass_name("borrowck")
256254
.iterate_to_fixpoint();
257-
let flow_uninits = MaybeUninitializedPlaces::new(tcx, body, &mdpe)
255+
let flow_uninits = MaybeUninitializedPlaces::new(tcx, body, &move_data)
258256
.into_engine(tcx, body)
259257
.pass_name("borrowck")
260258
.iterate_to_fixpoint();
261-
let flow_ever_inits = EverInitializedPlaces::new(body, &mdpe)
259+
let flow_ever_inits = EverInitializedPlaces::new(body, &move_data)
262260
.into_engine(tcx, body)
263261
.pass_name("borrowck")
264262
.iterate_to_fixpoint();
@@ -324,7 +322,7 @@ fn do_mir_borrowck<'tcx>(
324322
infcx: &infcx,
325323
param_env,
326324
body,
327-
move_data: &mdpe.move_data,
325+
move_data: &move_data,
328326
location_table: &location_table,
329327
movable_coroutine,
330328
locals_are_invalidated_at_exit,

compiler/rustc_mir_dataflow/src/drop_flag_effects.rs

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

55
use super::move_paths::{InitKind, LookupResult, MoveData, MovePathIndex};
6-
use super::MoveDataParamEnv;
76
use crate::elaborate_drops::DropFlagState;
87

98
pub fn move_path_children_matching<'tcx, F>(
@@ -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

+26-34
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::move_paths::{HasMoveData, InitIndex, InitKind, LookupResult, MoveData
1111
use crate::{
1212
drop_flag_effects, drop_flag_effects_for_function_entry, drop_flag_effects_for_location,
1313
lattice, on_all_children_bits, on_lookup_result_bits, AnalysisDomain, GenKill, GenKillAnalysis,
14-
MaybeReachable, MoveDataParamEnv,
14+
MaybeReachable,
1515
};
1616

1717
/// `MaybeInitializedPlaces` tracks all places that might be
@@ -52,17 +52,13 @@ use crate::{
5252
pub struct MaybeInitializedPlaces<'a, 'mir, 'tcx> {
5353
tcx: TyCtxt<'tcx>,
5454
body: &'mir Body<'tcx>,
55-
mdpe: &'a MoveDataParamEnv<'tcx>,
55+
move_data: &'a MoveData<'tcx>,
5656
skip_unreachable_unwind: bool,
5757
}
5858

5959
impl<'a, 'mir, 'tcx> MaybeInitializedPlaces<'a, 'mir, 'tcx> {
60-
pub fn new(
61-
tcx: TyCtxt<'tcx>,
62-
body: &'mir Body<'tcx>,
63-
mdpe: &'a MoveDataParamEnv<'tcx>,
64-
) -> Self {
65-
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 }
6662
}
6763

6864
pub fn skipping_unreachable_unwind(mut self) -> Self {
@@ -89,7 +85,7 @@ impl<'a, 'mir, 'tcx> MaybeInitializedPlaces<'a, 'mir, 'tcx> {
8985

9086
impl<'a, 'mir, 'tcx> HasMoveData<'tcx> for MaybeInitializedPlaces<'a, 'mir, 'tcx> {
9187
fn move_data(&self) -> &MoveData<'tcx> {
92-
&self.mdpe.move_data
88+
self.move_data
9389
}
9490
}
9591

@@ -131,22 +127,18 @@ impl<'a, 'mir, 'tcx> HasMoveData<'tcx> for MaybeInitializedPlaces<'a, 'mir, 'tcx
131127
pub struct MaybeUninitializedPlaces<'a, 'mir, 'tcx> {
132128
tcx: TyCtxt<'tcx>,
133129
body: &'mir Body<'tcx>,
134-
mdpe: &'a MoveDataParamEnv<'tcx>,
130+
move_data: &'a MoveData<'tcx>,
135131

136132
mark_inactive_variants_as_uninit: bool,
137133
skip_unreachable_unwind: BitSet<mir::BasicBlock>,
138134
}
139135

140136
impl<'a, 'mir, 'tcx> MaybeUninitializedPlaces<'a, 'mir, 'tcx> {
141-
pub fn new(
142-
tcx: TyCtxt<'tcx>,
143-
body: &'mir Body<'tcx>,
144-
mdpe: &'a MoveDataParamEnv<'tcx>,
145-
) -> Self {
137+
pub fn new(tcx: TyCtxt<'tcx>, body: &'mir Body<'tcx>, move_data: &'a MoveData<'tcx>) -> Self {
146138
MaybeUninitializedPlaces {
147139
tcx,
148140
body,
149-
mdpe,
141+
move_data,
150142
mark_inactive_variants_as_uninit: false,
151143
skip_unreachable_unwind: BitSet::new_empty(body.basic_blocks.len()),
152144
}
@@ -173,7 +165,7 @@ impl<'a, 'mir, 'tcx> MaybeUninitializedPlaces<'a, 'mir, 'tcx> {
173165

174166
impl<'a, 'tcx> HasMoveData<'tcx> for MaybeUninitializedPlaces<'a, '_, 'tcx> {
175167
fn move_data(&self) -> &MoveData<'tcx> {
176-
&self.mdpe.move_data
168+
self.move_data
177169
}
178170
}
179171

@@ -213,18 +205,18 @@ impl<'a, 'tcx> HasMoveData<'tcx> for MaybeUninitializedPlaces<'a, '_, 'tcx> {
213205
/// that would require a dynamic drop-flag at that statement.
214206
pub struct DefinitelyInitializedPlaces<'a, 'tcx> {
215207
body: &'a Body<'tcx>,
216-
mdpe: &'a MoveDataParamEnv<'tcx>,
208+
move_data: &'a MoveData<'tcx>,
217209
}
218210

219211
impl<'a, 'tcx> DefinitelyInitializedPlaces<'a, 'tcx> {
220-
pub fn new(body: &'a Body<'tcx>, mdpe: &'a MoveDataParamEnv<'tcx>) -> Self {
221-
DefinitelyInitializedPlaces { body, mdpe }
212+
pub fn new(body: &'a Body<'tcx>, move_data: &'a MoveData<'tcx>) -> Self {
213+
DefinitelyInitializedPlaces { body, move_data }
222214
}
223215
}
224216

225217
impl<'a, 'tcx> HasMoveData<'tcx> for DefinitelyInitializedPlaces<'a, 'tcx> {
226218
fn move_data(&self) -> &MoveData<'tcx> {
227-
&self.mdpe.move_data
219+
self.move_data
228220
}
229221
}
230222

@@ -259,18 +251,18 @@ impl<'a, 'tcx> HasMoveData<'tcx> for DefinitelyInitializedPlaces<'a, 'tcx> {
259251
/// ```
260252
pub struct EverInitializedPlaces<'a, 'mir, 'tcx> {
261253
body: &'mir Body<'tcx>,
262-
mdpe: &'a MoveDataParamEnv<'tcx>,
254+
move_data: &'a MoveData<'tcx>,
263255
}
264256

265257
impl<'a, 'mir, 'tcx> EverInitializedPlaces<'a, 'mir, 'tcx> {
266-
pub fn new(body: &'mir Body<'tcx>, mdpe: &'a MoveDataParamEnv<'tcx>) -> Self {
267-
EverInitializedPlaces { body, mdpe }
258+
pub fn new(body: &'mir Body<'tcx>, move_data: &'a MoveData<'tcx>) -> Self {
259+
EverInitializedPlaces { body, move_data }
268260
}
269261
}
270262

271263
impl<'a, 'tcx> HasMoveData<'tcx> for EverInitializedPlaces<'a, '_, 'tcx> {
272264
fn move_data(&self) -> &MoveData<'tcx> {
273-
&self.mdpe.move_data
265+
self.move_data
274266
}
275267
}
276268

@@ -328,7 +320,7 @@ impl<'tcx> AnalysisDomain<'tcx> for MaybeInitializedPlaces<'_, '_, 'tcx> {
328320
fn initialize_start_block(&self, _: &mir::Body<'tcx>, state: &mut Self::Domain) {
329321
*state =
330322
MaybeReachable::Reachable(ChunkedBitSet::new_empty(self.move_data().move_paths.len()));
331-
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| {
332324
assert!(s == DropFlagState::Present);
333325
state.gen_(path);
334326
});
@@ -348,7 +340,7 @@ impl<'tcx> GenKillAnalysis<'tcx> for MaybeInitializedPlaces<'_, '_, 'tcx> {
348340
statement: &mir::Statement<'tcx>,
349341
location: Location,
350342
) {
351-
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| {
352344
Self::update_bits(trans, path, s)
353345
});
354346

@@ -380,7 +372,7 @@ impl<'tcx> GenKillAnalysis<'tcx> for MaybeInitializedPlaces<'_, '_, 'tcx> {
380372
{
381373
edges = TerminatorEdges::Single(target);
382374
}
383-
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| {
384376
Self::update_bits(state, path, s)
385377
});
386378
edges
@@ -465,7 +457,7 @@ impl<'tcx> AnalysisDomain<'tcx> for MaybeUninitializedPlaces<'_, '_, 'tcx> {
465457
// set all bits to 1 (uninit) before gathering counter-evidence
466458
state.insert_all();
467459

468-
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| {
469461
assert!(s == DropFlagState::Present);
470462
state.remove(path);
471463
});
@@ -485,7 +477,7 @@ impl<'tcx> GenKillAnalysis<'tcx> for MaybeUninitializedPlaces<'_, '_, 'tcx> {
485477
_statement: &mir::Statement<'tcx>,
486478
location: Location,
487479
) {
488-
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| {
489481
Self::update_bits(trans, path, s)
490482
});
491483

@@ -499,7 +491,7 @@ impl<'tcx> GenKillAnalysis<'tcx> for MaybeUninitializedPlaces<'_, '_, 'tcx> {
499491
terminator: &'mir mir::Terminator<'tcx>,
500492
location: Location,
501493
) -> TerminatorEdges<'mir, 'tcx> {
502-
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| {
503495
Self::update_bits(trans, path, s)
504496
});
505497
if self.skip_unreachable_unwind.contains(location.block) {
@@ -592,7 +584,7 @@ impl<'a, 'tcx> AnalysisDomain<'tcx> for DefinitelyInitializedPlaces<'a, 'tcx> {
592584
fn initialize_start_block(&self, _: &mir::Body<'tcx>, state: &mut Self::Domain) {
593585
state.0.clear();
594586

595-
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| {
596588
assert!(s == DropFlagState::Present);
597589
state.0.insert(path);
598590
});
@@ -612,7 +604,7 @@ impl<'tcx> GenKillAnalysis<'tcx> for DefinitelyInitializedPlaces<'_, 'tcx> {
612604
_statement: &mir::Statement<'tcx>,
613605
location: Location,
614606
) {
615-
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| {
616608
Self::update_bits(trans, path, s)
617609
})
618610
}
@@ -623,7 +615,7 @@ impl<'tcx> GenKillAnalysis<'tcx> for DefinitelyInitializedPlaces<'_, 'tcx> {
623615
terminator: &'mir mir::Terminator<'tcx>,
624616
location: Location,
625617
) -> TerminatorEdges<'mir, 'tcx> {
626-
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| {
627619
Self::update_bits(trans, path, s)
628620
});
629621
terminator.edges()

compiler/rustc_mir_dataflow/src/rustc_peek.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use crate::impls::{
1616
DefinitelyInitializedPlaces, MaybeInitializedPlaces, MaybeLiveLocals, MaybeUninitializedPlaces,
1717
};
1818
use crate::move_paths::{HasMoveData, LookupResult, MoveData, MovePathIndex};
19-
use crate::{Analysis, JoinSemiLattice, MoveDataParamEnv, ResultsCursor};
19+
use crate::{Analysis, JoinSemiLattice, ResultsCursor};
2020

2121
pub struct SanityCheck;
2222

@@ -46,26 +46,25 @@ impl<'tcx> MirPass<'tcx> for SanityCheck {
4646

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

5150
if has_rustc_mir_with(tcx, def_id, sym::rustc_peek_maybe_init).is_some() {
52-
let flow_inits = MaybeInitializedPlaces::new(tcx, body, &mdpe)
51+
let flow_inits = MaybeInitializedPlaces::new(tcx, body, &move_data)
5352
.into_engine(tcx, body)
5453
.iterate_to_fixpoint();
5554

5655
sanity_check_via_rustc_peek(tcx, flow_inits.into_results_cursor(body));
5756
}
5857

5958
if has_rustc_mir_with(tcx, def_id, sym::rustc_peek_maybe_uninit).is_some() {
60-
let flow_uninits = MaybeUninitializedPlaces::new(tcx, body, &mdpe)
59+
let flow_uninits = MaybeUninitializedPlaces::new(tcx, body, &move_data)
6160
.into_engine(tcx, body)
6261
.iterate_to_fixpoint();
6362

6463
sanity_check_via_rustc_peek(tcx, flow_uninits.into_results_cursor(body));
6564
}
6665

6766
if has_rustc_mir_with(tcx, def_id, sym::rustc_peek_definite_init).is_some() {
68-
let flow_def_inits = DefinitelyInitializedPlaces::new(body, &mdpe)
67+
let flow_def_inits = DefinitelyInitializedPlaces::new(body, &move_data)
6968
.into_engine(tcx, body)
7069
.iterate_to_fixpoint();
7170

compiler/rustc_mir_transform/src/elaborate_drops.rs

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

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

73-
let uninits = MaybeUninitializedPlaces::new(tcx, body, &env)
73+
let uninits = MaybeUninitializedPlaces::new(tcx, body, &env.move_data)
7474
.mark_inactive_variants_as_uninit()
7575
.skipping_unreachable_unwind(dead_unwinds)
7676
.into_engine(tcx, body)
@@ -443,9 +443,13 @@ impl<'b, 'mir, 'tcx> ElaborateDropsCtxt<'b, 'mir, 'tcx> {
443443

444444
fn drop_flags_for_args(&mut self) {
445445
let loc = Location::START;
446-
rustc_mir_dataflow::drop_flag_effects_for_function_entry(self.body, self.env, |path, ds| {
447-
self.set_drop_flag(loc, path, ds);
448-
})
446+
rustc_mir_dataflow::drop_flag_effects_for_function_entry(
447+
self.body,
448+
&self.env.move_data,
449+
|path, ds| {
450+
self.set_drop_flag(loc, path, ds);
451+
},
452+
)
449453
}
450454

451455
fn drop_flags_for_locs(&mut self) {
@@ -478,7 +482,7 @@ impl<'b, 'mir, 'tcx> ElaborateDropsCtxt<'b, 'mir, 'tcx> {
478482
let loc = Location { block: bb, statement_index: i };
479483
rustc_mir_dataflow::drop_flag_effects_for_location(
480484
self.body,
481-
self.env,
485+
&self.env.move_data,
482486
loc,
483487
|path, ds| self.set_drop_flag(loc, path, ds),
484488
)

0 commit comments

Comments
 (0)