Skip to content

Commit 0f12da1

Browse files
committed
Remove unused arguments from on_all_children_bits.
`on_all_children_bits` has two arguments that are unused: `tcx` and `body`. This was not detected by the compiler because it's a recursive function. This commit removes them, and removes lots of other arguments and fields that are no longer necessary.
1 parent 118308e commit 0f12da1

File tree

4 files changed

+42
-90
lines changed

4 files changed

+42
-90
lines changed

compiler/rustc_mir_dataflow/src/drop_flag_effects.rs

+11-31
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use crate::elaborate_drops::DropFlagState;
22
use rustc_middle::mir::{self, Body, Location, Terminator, TerminatorKind};
3-
use rustc_middle::ty::TyCtxt;
43
use rustc_target::abi::VariantIdx;
54

65
use super::move_paths::{InitKind, LookupResult, MoveData, MovePathIndex};
@@ -29,8 +28,6 @@ where
2928
}
3029

3130
pub fn on_lookup_result_bits<'tcx, F>(
32-
tcx: TyCtxt<'tcx>,
33-
body: &Body<'tcx>,
3431
move_data: &MoveData<'tcx>,
3532
lookup_result: LookupResult,
3633
each_child: F,
@@ -41,22 +38,18 @@ pub fn on_lookup_result_bits<'tcx, F>(
4138
LookupResult::Parent(..) => {
4239
// access to untracked value - do not touch children
4340
}
44-
LookupResult::Exact(e) => on_all_children_bits(tcx, body, move_data, e, each_child),
41+
LookupResult::Exact(e) => on_all_children_bits(move_data, e, each_child),
4542
}
4643
}
4744

4845
pub fn on_all_children_bits<'tcx, F>(
49-
tcx: TyCtxt<'tcx>,
50-
body: &Body<'tcx>,
5146
move_data: &MoveData<'tcx>,
5247
move_path_index: MovePathIndex,
5348
mut each_child: F,
5449
) where
5550
F: FnMut(MovePathIndex),
5651
{
5752
fn on_all_children_bits<'tcx, F>(
58-
tcx: TyCtxt<'tcx>,
59-
body: &Body<'tcx>,
6053
move_data: &MoveData<'tcx>,
6154
move_path_index: MovePathIndex,
6255
each_child: &mut F,
@@ -67,15 +60,14 @@ pub fn on_all_children_bits<'tcx, F>(
6760

6861
let mut next_child_index = move_data.move_paths[move_path_index].first_child;
6962
while let Some(child_index) = next_child_index {
70-
on_all_children_bits(tcx, body, move_data, child_index, each_child);
63+
on_all_children_bits(move_data, child_index, each_child);
7164
next_child_index = move_data.move_paths[child_index].next_sibling;
7265
}
7366
}
74-
on_all_children_bits(tcx, body, move_data, move_path_index, &mut each_child);
67+
on_all_children_bits(move_data, move_path_index, &mut each_child);
7568
}
7669

7770
pub fn drop_flag_effects_for_function_entry<'tcx, F>(
78-
tcx: TyCtxt<'tcx>,
7971
body: &Body<'tcx>,
8072
ctxt: &MoveDataParamEnv<'tcx>,
8173
mut callback: F,
@@ -86,14 +78,13 @@ pub fn drop_flag_effects_for_function_entry<'tcx, F>(
8678
for arg in body.args_iter() {
8779
let place = mir::Place::from(arg);
8880
let lookup_result = move_data.rev_lookup.find(place.as_ref());
89-
on_lookup_result_bits(tcx, body, move_data, lookup_result, |mpi| {
81+
on_lookup_result_bits(move_data, lookup_result, |mpi| {
9082
callback(mpi, DropFlagState::Present)
9183
});
9284
}
9385
}
9486

9587
pub fn drop_flag_effects_for_location<'tcx, F>(
96-
tcx: TyCtxt<'tcx>,
9788
body: &Body<'tcx>,
9889
ctxt: &MoveDataParamEnv<'tcx>,
9990
loc: Location,
@@ -109,32 +100,25 @@ pub fn drop_flag_effects_for_location<'tcx, F>(
109100
let path = mi.move_path_index(move_data);
110101
debug!("moving out of path {:?}", move_data.move_paths[path]);
111102

112-
on_all_children_bits(tcx, body, move_data, path, |mpi| callback(mpi, DropFlagState::Absent))
103+
on_all_children_bits(move_data, path, |mpi| callback(mpi, DropFlagState::Absent))
113104
}
114105

115106
// Drop does not count as a move but we should still consider the variable uninitialized.
116107
if let Some(Terminator { kind: TerminatorKind::Drop { place, .. }, .. }) =
117108
body.stmt_at(loc).right()
118109
{
119110
if let LookupResult::Exact(mpi) = move_data.rev_lookup.find(place.as_ref()) {
120-
on_all_children_bits(tcx, body, move_data, mpi, |mpi| {
121-
callback(mpi, DropFlagState::Absent)
122-
})
111+
on_all_children_bits(move_data, mpi, |mpi| callback(mpi, DropFlagState::Absent))
123112
}
124113
}
125114

126115
debug!("drop_flag_effects: assignment for location({:?})", loc);
127116

128-
for_location_inits(tcx, body, move_data, loc, |mpi| callback(mpi, DropFlagState::Present));
117+
for_location_inits(move_data, loc, |mpi| callback(mpi, DropFlagState::Present));
129118
}
130119

131-
fn for_location_inits<'tcx, F>(
132-
tcx: TyCtxt<'tcx>,
133-
body: &Body<'tcx>,
134-
move_data: &MoveData<'tcx>,
135-
loc: Location,
136-
mut callback: F,
137-
) where
120+
fn for_location_inits<'tcx, F>(move_data: &MoveData<'tcx>, loc: Location, mut callback: F)
121+
where
138122
F: FnMut(MovePathIndex),
139123
{
140124
for ii in &move_data.init_loc_map[loc] {
@@ -143,7 +127,7 @@ fn for_location_inits<'tcx, F>(
143127
InitKind::Deep => {
144128
let path = init.path;
145129

146-
on_all_children_bits(tcx, body, move_data, path, &mut callback)
130+
on_all_children_bits(move_data, path, &mut callback)
147131
}
148132
InitKind::Shallow => {
149133
let mpi = init.path;
@@ -160,8 +144,6 @@ fn for_location_inits<'tcx, F>(
160144
/// NOTE: If there are no move paths corresponding to an inactive variant,
161145
/// `handle_inactive_variant` will not be called for that variant.
162146
pub(crate) fn on_all_inactive_variants<'tcx>(
163-
tcx: TyCtxt<'tcx>,
164-
body: &mir::Body<'tcx>,
165147
move_data: &MoveData<'tcx>,
166148
enum_place: mir::Place<'tcx>,
167149
active_variant: VariantIdx,
@@ -184,9 +166,7 @@ pub(crate) fn on_all_inactive_variants<'tcx>(
184166
};
185167

186168
if variant_idx != active_variant {
187-
on_all_children_bits(tcx, body, move_data, variant_mpi, |mpi| {
188-
handle_inactive_variant(mpi)
189-
});
169+
on_all_children_bits(move_data, variant_mpi, |mpi| handle_inactive_variant(mpi));
190170
}
191171
}
192172
}

compiler/rustc_mir_dataflow/src/impls/initialized.rs

+13-24
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ impl<'a, 'tcx> MaybeInitializedPlaces<'a, 'tcx> {
7272
) -> bool {
7373
if let LookupResult::Exact(path) = self.move_data().rev_lookup.find(place.as_ref()) {
7474
let mut maybe_live = false;
75-
on_all_children_bits(self.tcx, self.body, self.move_data(), path, |child| {
75+
on_all_children_bits(self.move_data(), path, |child| {
7676
maybe_live |= state.contains(child);
7777
});
7878
!maybe_live
@@ -203,14 +203,13 @@ impl<'a, 'tcx> HasMoveData<'tcx> for MaybeUninitializedPlaces<'a, 'tcx> {
203203
/// this data and `MaybeInitializedPlaces` yields the set of places
204204
/// that would require a dynamic drop-flag at that statement.
205205
pub struct DefinitelyInitializedPlaces<'a, 'tcx> {
206-
tcx: TyCtxt<'tcx>,
207206
body: &'a Body<'tcx>,
208207
mdpe: &'a MoveDataParamEnv<'tcx>,
209208
}
210209

211210
impl<'a, 'tcx> DefinitelyInitializedPlaces<'a, 'tcx> {
212-
pub fn new(tcx: TyCtxt<'tcx>, body: &'a Body<'tcx>, mdpe: &'a MoveDataParamEnv<'tcx>) -> Self {
213-
DefinitelyInitializedPlaces { tcx, body, mdpe }
211+
pub fn new(body: &'a Body<'tcx>, mdpe: &'a MoveDataParamEnv<'tcx>) -> Self {
212+
DefinitelyInitializedPlaces { body, mdpe }
214213
}
215214
}
216215

@@ -317,7 +316,7 @@ impl<'tcx> AnalysisDomain<'tcx> for MaybeInitializedPlaces<'_, 'tcx> {
317316
fn initialize_start_block(&self, _: &mir::Body<'tcx>, state: &mut Self::Domain) {
318317
*state =
319318
MaybeReachable::Reachable(ChunkedBitSet::new_empty(self.move_data().move_paths.len()));
320-
drop_flag_effects_for_function_entry(self.tcx, self.body, self.mdpe, |path, s| {
319+
drop_flag_effects_for_function_entry(self.body, self.mdpe, |path, s| {
321320
assert!(s == DropFlagState::Present);
322321
state.gen(path);
323322
});
@@ -337,7 +336,7 @@ impl<'tcx> GenKillAnalysis<'tcx> for MaybeInitializedPlaces<'_, 'tcx> {
337336
statement: &mir::Statement<'tcx>,
338337
location: Location,
339338
) {
340-
drop_flag_effects_for_location(self.tcx, self.body, self.mdpe, location, |path, s| {
339+
drop_flag_effects_for_location(self.body, self.mdpe, location, |path, s| {
341340
Self::update_bits(trans, path, s)
342341
});
343342

@@ -349,7 +348,7 @@ impl<'tcx> GenKillAnalysis<'tcx> for MaybeInitializedPlaces<'_, 'tcx> {
349348
| mir::Rvalue::AddressOf(_, place) = rvalue
350349
&& let LookupResult::Exact(mpi) = self.move_data().rev_lookup.find(place.as_ref())
351350
{
352-
on_all_children_bits(self.tcx, self.body, self.move_data(), mpi, |child| {
351+
on_all_children_bits(self.move_data(), mpi, |child| {
353352
trans.gen(child);
354353
})
355354
}
@@ -369,7 +368,7 @@ impl<'tcx> GenKillAnalysis<'tcx> for MaybeInitializedPlaces<'_, 'tcx> {
369368
{
370369
edges = TerminatorEdges::Single(target);
371370
}
372-
drop_flag_effects_for_location(self.tcx, self.body, self.mdpe, location, |path, s| {
371+
drop_flag_effects_for_location(self.body, self.mdpe, location, |path, s| {
373372
Self::update_bits(state, path, s)
374373
});
375374
edges
@@ -385,8 +384,6 @@ impl<'tcx> GenKillAnalysis<'tcx> for MaybeInitializedPlaces<'_, 'tcx> {
385384
// when a call returns successfully, that means we need to set
386385
// the bits for that dest_place to 1 (initialized).
387386
on_lookup_result_bits(
388-
self.tcx,
389-
self.body,
390387
self.move_data(),
391388
self.move_data().rev_lookup.find(place.as_ref()),
392389
|mpi| {
@@ -430,8 +427,6 @@ impl<'tcx> GenKillAnalysis<'tcx> for MaybeInitializedPlaces<'_, 'tcx> {
430427
// Kill all move paths that correspond to variants we know to be inactive along this
431428
// particular outgoing edge of a `SwitchInt`.
432429
drop_flag_effects::on_all_inactive_variants(
433-
self.tcx,
434-
self.body,
435430
self.move_data(),
436431
enum_place,
437432
variant,
@@ -456,7 +451,7 @@ impl<'tcx> AnalysisDomain<'tcx> for MaybeUninitializedPlaces<'_, 'tcx> {
456451
// set all bits to 1 (uninit) before gathering counter-evidence
457452
state.insert_all();
458453

459-
drop_flag_effects_for_function_entry(self.tcx, self.body, self.mdpe, |path, s| {
454+
drop_flag_effects_for_function_entry(self.body, self.mdpe, |path, s| {
460455
assert!(s == DropFlagState::Present);
461456
state.remove(path);
462457
});
@@ -476,7 +471,7 @@ impl<'tcx> GenKillAnalysis<'tcx> for MaybeUninitializedPlaces<'_, 'tcx> {
476471
_statement: &mir::Statement<'tcx>,
477472
location: Location,
478473
) {
479-
drop_flag_effects_for_location(self.tcx, self.body, self.mdpe, location, |path, s| {
474+
drop_flag_effects_for_location(self.body, self.mdpe, location, |path, s| {
480475
Self::update_bits(trans, path, s)
481476
});
482477

@@ -490,7 +485,7 @@ impl<'tcx> GenKillAnalysis<'tcx> for MaybeUninitializedPlaces<'_, 'tcx> {
490485
terminator: &'mir mir::Terminator<'tcx>,
491486
location: Location,
492487
) -> TerminatorEdges<'mir, 'tcx> {
493-
drop_flag_effects_for_location(self.tcx, self.body, self.mdpe, location, |path, s| {
488+
drop_flag_effects_for_location(self.body, self.mdpe, location, |path, s| {
494489
Self::update_bits(trans, path, s)
495490
});
496491
if self.skip_unreachable_unwind.contains(location.block) {
@@ -512,8 +507,6 @@ impl<'tcx> GenKillAnalysis<'tcx> for MaybeUninitializedPlaces<'_, 'tcx> {
512507
// when a call returns successfully, that means we need to set
513508
// the bits for that dest_place to 0 (initialized).
514509
on_lookup_result_bits(
515-
self.tcx,
516-
self.body,
517510
self.move_data(),
518511
self.move_data().rev_lookup.find(place.as_ref()),
519512
|mpi| {
@@ -561,8 +554,6 @@ impl<'tcx> GenKillAnalysis<'tcx> for MaybeUninitializedPlaces<'_, 'tcx> {
561554
// Mark all move paths that correspond to variants other than this one as maybe
562555
// uninitialized (in reality, they are *definitely* uninitialized).
563556
drop_flag_effects::on_all_inactive_variants(
564-
self.tcx,
565-
self.body,
566557
self.move_data(),
567558
enum_place,
568559
variant,
@@ -587,7 +578,7 @@ impl<'a, 'tcx> AnalysisDomain<'tcx> for DefinitelyInitializedPlaces<'a, 'tcx> {
587578
fn initialize_start_block(&self, _: &mir::Body<'tcx>, state: &mut Self::Domain) {
588579
state.0.clear();
589580

590-
drop_flag_effects_for_function_entry(self.tcx, self.body, self.mdpe, |path, s| {
581+
drop_flag_effects_for_function_entry(self.body, self.mdpe, |path, s| {
591582
assert!(s == DropFlagState::Present);
592583
state.0.insert(path);
593584
});
@@ -607,7 +598,7 @@ impl<'tcx> GenKillAnalysis<'tcx> for DefinitelyInitializedPlaces<'_, 'tcx> {
607598
_statement: &mir::Statement<'tcx>,
608599
location: Location,
609600
) {
610-
drop_flag_effects_for_location(self.tcx, self.body, self.mdpe, location, |path, s| {
601+
drop_flag_effects_for_location(self.body, self.mdpe, location, |path, s| {
611602
Self::update_bits(trans, path, s)
612603
})
613604
}
@@ -618,7 +609,7 @@ impl<'tcx> GenKillAnalysis<'tcx> for DefinitelyInitializedPlaces<'_, 'tcx> {
618609
terminator: &'mir mir::Terminator<'tcx>,
619610
location: Location,
620611
) -> TerminatorEdges<'mir, 'tcx> {
621-
drop_flag_effects_for_location(self.tcx, self.body, self.mdpe, location, |path, s| {
612+
drop_flag_effects_for_location(self.body, self.mdpe, location, |path, s| {
622613
Self::update_bits(trans, path, s)
623614
});
624615
terminator.edges()
@@ -634,8 +625,6 @@ impl<'tcx> GenKillAnalysis<'tcx> for DefinitelyInitializedPlaces<'_, 'tcx> {
634625
// when a call returns successfully, that means we need to set
635626
// the bits for that dest_place to 1 (initialized).
636627
on_lookup_result_bits(
637-
self.tcx,
638-
self.body,
639628
self.move_data(),
640629
self.move_data().rev_lookup.find(place.as_ref()),
641630
|mpi| {

compiler/rustc_mir_dataflow/src/rustc_peek.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ impl<'tcx> MirPass<'tcx> for SanityCheck {
6666
}
6767

6868
if has_rustc_mir_with(tcx, def_id, sym::rustc_peek_definite_init).is_some() {
69-
let flow_def_inits = DefinitelyInitializedPlaces::new(tcx, body, &mdpe)
69+
let flow_def_inits = DefinitelyInitializedPlaces::new(body, &mdpe)
7070
.into_engine(tcx, body)
7171
.iterate_to_fixpoint();
7272

0 commit comments

Comments
 (0)