Skip to content

Commit e2e978f

Browse files
committed
Auto merge of rust-lang#118203 - nnethercote:rustc_mir_dataflow, r=cjgillot
Minor `rustc_mir_dataflow` cleanups r? `@cjgillot`
2 parents b2e73e9 + 912eb1f commit e2e978f

File tree

16 files changed

+132
-227
lines changed

16 files changed

+132
-227
lines changed

compiler/rustc_borrowck/src/dataflow.rs

+17-17
Original file line numberDiff line numberDiff line change
@@ -121,24 +121,24 @@ rustc_index::newtype_index! {
121121
/// `BorrowIndex`, and maps each such index to a `BorrowData`
122122
/// describing the borrow. These indexes are used for representing the
123123
/// borrows in compact bitvectors.
124-
pub struct Borrows<'a, 'tcx> {
124+
pub struct Borrows<'mir, 'tcx> {
125125
tcx: TyCtxt<'tcx>,
126-
body: &'a Body<'tcx>,
126+
body: &'mir Body<'tcx>,
127127

128-
borrow_set: &'a BorrowSet<'tcx>,
128+
borrow_set: &'mir BorrowSet<'tcx>,
129129
borrows_out_of_scope_at_location: FxIndexMap<Location, Vec<BorrowIndex>>,
130130
}
131131

132-
struct OutOfScopePrecomputer<'a, 'tcx> {
132+
struct OutOfScopePrecomputer<'mir, 'tcx> {
133133
visited: BitSet<mir::BasicBlock>,
134134
visit_stack: Vec<mir::BasicBlock>,
135-
body: &'a Body<'tcx>,
136-
regioncx: &'a RegionInferenceContext<'tcx>,
135+
body: &'mir Body<'tcx>,
136+
regioncx: &'mir RegionInferenceContext<'tcx>,
137137
borrows_out_of_scope_at_location: FxIndexMap<Location, Vec<BorrowIndex>>,
138138
}
139139

140-
impl<'a, 'tcx> OutOfScopePrecomputer<'a, 'tcx> {
141-
fn new(body: &'a Body<'tcx>, regioncx: &'a RegionInferenceContext<'tcx>) -> Self {
140+
impl<'mir, 'tcx> OutOfScopePrecomputer<'mir, 'tcx> {
141+
fn new(body: &'mir Body<'tcx>, regioncx: &'mir RegionInferenceContext<'tcx>) -> Self {
142142
OutOfScopePrecomputer {
143143
visited: BitSet::new_empty(body.basic_blocks.len()),
144144
visit_stack: vec![],
@@ -241,17 +241,17 @@ pub fn calculate_borrows_out_of_scope_at_location<'tcx>(
241241
prec.borrows_out_of_scope_at_location
242242
}
243243

244-
struct PoloniusOutOfScopePrecomputer<'a, 'tcx> {
244+
struct PoloniusOutOfScopePrecomputer<'mir, 'tcx> {
245245
visited: BitSet<mir::BasicBlock>,
246246
visit_stack: Vec<mir::BasicBlock>,
247-
body: &'a Body<'tcx>,
248-
regioncx: &'a RegionInferenceContext<'tcx>,
247+
body: &'mir Body<'tcx>,
248+
regioncx: &'mir RegionInferenceContext<'tcx>,
249249

250250
loans_out_of_scope_at_location: FxIndexMap<Location, Vec<BorrowIndex>>,
251251
}
252252

253-
impl<'a, 'tcx> PoloniusOutOfScopePrecomputer<'a, 'tcx> {
254-
fn new(body: &'a Body<'tcx>, regioncx: &'a RegionInferenceContext<'tcx>) -> Self {
253+
impl<'mir, 'tcx> PoloniusOutOfScopePrecomputer<'mir, 'tcx> {
254+
fn new(body: &'mir Body<'tcx>, regioncx: &'mir RegionInferenceContext<'tcx>) -> Self {
255255
Self {
256256
visited: BitSet::new_empty(body.basic_blocks.len()),
257257
visit_stack: vec![],
@@ -404,12 +404,12 @@ impl<'tcx> PoloniusOutOfScopePrecomputer<'_, 'tcx> {
404404
}
405405
}
406406

407-
impl<'a, 'tcx> Borrows<'a, 'tcx> {
407+
impl<'mir, 'tcx> Borrows<'mir, 'tcx> {
408408
pub fn new(
409409
tcx: TyCtxt<'tcx>,
410-
body: &'a Body<'tcx>,
411-
regioncx: &'a RegionInferenceContext<'tcx>,
412-
borrow_set: &'a BorrowSet<'tcx>,
410+
body: &'mir Body<'tcx>,
411+
regioncx: &'mir RegionInferenceContext<'tcx>,
412+
borrow_set: &'mir BorrowSet<'tcx>,
413413
) -> Self {
414414
let mut borrows_out_of_scope_at_location =
415415
calculate_borrows_out_of_scope_at_location(body, regioncx, borrow_set);

compiler/rustc_borrowck/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ fn do_mir_borrowck<'tcx>(
288288
.into_engine(tcx, body)
289289
.pass_name("borrowck")
290290
.iterate_to_fixpoint();
291-
let flow_ever_inits = EverInitializedPlaces::new(tcx, body, &mdpe)
291+
let flow_ever_inits = EverInitializedPlaces::new(body, &mdpe)
292292
.into_engine(tcx, body)
293293
.pass_name("borrowck")
294294
.iterate_to_fixpoint();

compiler/rustc_mir_dataflow/src/drop_flag_effects.rs

+12-33
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
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

6-
use super::indexes::MovePathIndex;
7-
use super::move_paths::{InitKind, LookupResult, MoveData};
5+
use super::move_paths::{InitKind, LookupResult, MoveData, MovePathIndex};
86
use super::MoveDataParamEnv;
97

108
pub fn move_path_children_matching<'tcx, F>(
@@ -30,8 +28,6 @@ where
3028
}
3129

3230
pub fn on_lookup_result_bits<'tcx, F>(
33-
tcx: TyCtxt<'tcx>,
34-
body: &Body<'tcx>,
3531
move_data: &MoveData<'tcx>,
3632
lookup_result: LookupResult,
3733
each_child: F,
@@ -42,22 +38,18 @@ pub fn on_lookup_result_bits<'tcx, F>(
4238
LookupResult::Parent(..) => {
4339
// access to untracked value - do not touch children
4440
}
45-
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),
4642
}
4743
}
4844

4945
pub fn on_all_children_bits<'tcx, F>(
50-
tcx: TyCtxt<'tcx>,
51-
body: &Body<'tcx>,
5246
move_data: &MoveData<'tcx>,
5347
move_path_index: MovePathIndex,
5448
mut each_child: F,
5549
) where
5650
F: FnMut(MovePathIndex),
5751
{
5852
fn on_all_children_bits<'tcx, F>(
59-
tcx: TyCtxt<'tcx>,
60-
body: &Body<'tcx>,
6153
move_data: &MoveData<'tcx>,
6254
move_path_index: MovePathIndex,
6355
each_child: &mut F,
@@ -68,15 +60,14 @@ pub fn on_all_children_bits<'tcx, F>(
6860

6961
let mut next_child_index = move_data.move_paths[move_path_index].first_child;
7062
while let Some(child_index) = next_child_index {
71-
on_all_children_bits(tcx, body, move_data, child_index, each_child);
63+
on_all_children_bits(move_data, child_index, each_child);
7264
next_child_index = move_data.move_paths[child_index].next_sibling;
7365
}
7466
}
75-
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);
7668
}
7769

7870
pub fn drop_flag_effects_for_function_entry<'tcx, F>(
79-
tcx: TyCtxt<'tcx>,
8071
body: &Body<'tcx>,
8172
ctxt: &MoveDataParamEnv<'tcx>,
8273
mut callback: F,
@@ -87,14 +78,13 @@ pub fn drop_flag_effects_for_function_entry<'tcx, F>(
8778
for arg in body.args_iter() {
8879
let place = mir::Place::from(arg);
8980
let lookup_result = move_data.rev_lookup.find(place.as_ref());
90-
on_lookup_result_bits(tcx, body, move_data, lookup_result, |mpi| {
81+
on_lookup_result_bits(move_data, lookup_result, |mpi| {
9182
callback(mpi, DropFlagState::Present)
9283
});
9384
}
9485
}
9586

9687
pub fn drop_flag_effects_for_location<'tcx, F>(
97-
tcx: TyCtxt<'tcx>,
9888
body: &Body<'tcx>,
9989
ctxt: &MoveDataParamEnv<'tcx>,
10090
loc: Location,
@@ -110,32 +100,25 @@ pub fn drop_flag_effects_for_location<'tcx, F>(
110100
let path = mi.move_path_index(move_data);
111101
debug!("moving out of path {:?}", move_data.move_paths[path]);
112102

113-
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))
114104
}
115105

116106
// Drop does not count as a move but we should still consider the variable uninitialized.
117107
if let Some(Terminator { kind: TerminatorKind::Drop { place, .. }, .. }) =
118108
body.stmt_at(loc).right()
119109
{
120110
if let LookupResult::Exact(mpi) = move_data.rev_lookup.find(place.as_ref()) {
121-
on_all_children_bits(tcx, body, move_data, mpi, |mpi| {
122-
callback(mpi, DropFlagState::Absent)
123-
})
111+
on_all_children_bits(move_data, mpi, |mpi| callback(mpi, DropFlagState::Absent))
124112
}
125113
}
126114

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

129-
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));
130118
}
131119

132-
pub fn for_location_inits<'tcx, F>(
133-
tcx: TyCtxt<'tcx>,
134-
body: &Body<'tcx>,
135-
move_data: &MoveData<'tcx>,
136-
loc: Location,
137-
mut callback: F,
138-
) where
120+
fn for_location_inits<'tcx, F>(move_data: &MoveData<'tcx>, loc: Location, mut callback: F)
121+
where
139122
F: FnMut(MovePathIndex),
140123
{
141124
for ii in &move_data.init_loc_map[loc] {
@@ -144,7 +127,7 @@ pub fn for_location_inits<'tcx, F>(
144127
InitKind::Deep => {
145128
let path = init.path;
146129

147-
on_all_children_bits(tcx, body, move_data, path, &mut callback)
130+
on_all_children_bits(move_data, path, &mut callback)
148131
}
149132
InitKind::Shallow => {
150133
let mpi = init.path;
@@ -161,8 +144,6 @@ pub fn for_location_inits<'tcx, F>(
161144
/// NOTE: If there are no move paths corresponding to an inactive variant,
162145
/// `handle_inactive_variant` will not be called for that variant.
163146
pub(crate) fn on_all_inactive_variants<'tcx>(
164-
tcx: TyCtxt<'tcx>,
165-
body: &mir::Body<'tcx>,
166147
move_data: &MoveData<'tcx>,
167148
enum_place: mir::Place<'tcx>,
168149
active_variant: VariantIdx,
@@ -185,9 +166,7 @@ pub(crate) fn on_all_inactive_variants<'tcx>(
185166
};
186167

187168
if variant_idx != active_variant {
188-
on_all_children_bits(tcx, body, move_data, variant_mpi, |mpi| {
189-
handle_inactive_variant(mpi)
190-
});
169+
on_all_children_bits(move_data, variant_mpi, |mpi| handle_inactive_variant(mpi));
191170
}
192171
}
193172
}

compiler/rustc_mir_dataflow/src/framework/cursor.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ where
147147
}
148148

149149
/// Returns the underlying `Results`.
150-
pub fn results(&mut self) -> &Results<'tcx, A, R::EntrySets> {
150+
pub fn results(&self) -> &Results<'tcx, A, R::EntrySets> {
151151
self.results.borrow()
152152
}
153153

@@ -166,11 +166,6 @@ where
166166
&mut self.results.borrow_mut().analysis
167167
}
168168

169-
/// Returns both the dataflow state at the current location and the `Analysis`.
170-
pub fn get_with_analysis(&mut self) -> (&A::Domain, &mut A) {
171-
(&self.state, &mut self.results.borrow_mut().analysis)
172-
}
173-
174169
/// Resets the cursor to hold the entry set for the given basic block.
175170
///
176171
/// For forward dataflow analyses, this is the dataflow state prior to the first statement.

compiler/rustc_mir_dataflow/src/framework/direction.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -287,12 +287,12 @@ impl Direction for Backward {
287287
}
288288
}
289289

290-
struct BackwardSwitchIntEdgeEffectsApplier<'a, 'tcx, D, F> {
291-
body: &'a mir::Body<'tcx>,
290+
struct BackwardSwitchIntEdgeEffectsApplier<'mir, 'tcx, D, F> {
291+
body: &'mir mir::Body<'tcx>,
292292
pred: BasicBlock,
293-
exit_state: &'a mut D,
293+
exit_state: &'mir mut D,
294294
bb: BasicBlock,
295-
propagate: &'a mut F,
295+
propagate: &'mir mut F,
296296
effects_applied: bool,
297297
}
298298

@@ -523,9 +523,9 @@ impl Direction for Forward {
523523
}
524524
}
525525

526-
struct ForwardSwitchIntEdgeEffectsApplier<'a, D, F> {
527-
exit_state: &'a mut D,
528-
targets: &'a SwitchTargets,
526+
struct ForwardSwitchIntEdgeEffectsApplier<'mir, D, F> {
527+
exit_state: &'mir mut D,
528+
targets: &'mir SwitchTargets,
529529
propagate: F,
530530

531531
effects_applied: bool,

compiler/rustc_mir_dataflow/src/framework/engine.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,12 @@ where
128128
}
129129

130130
/// A solver for dataflow problems.
131-
pub struct Engine<'a, 'tcx, A>
131+
pub struct Engine<'mir, 'tcx, A>
132132
where
133133
A: Analysis<'tcx>,
134134
{
135135
tcx: TyCtxt<'tcx>,
136-
body: &'a mir::Body<'tcx>,
136+
body: &'mir mir::Body<'tcx>,
137137
entry_sets: IndexVec<BasicBlock, A::Domain>,
138138
pass_name: Option<&'static str>,
139139
analysis: A,
@@ -147,14 +147,14 @@ where
147147
apply_statement_trans_for_block: Option<Box<dyn Fn(BasicBlock, &mut A::Domain)>>,
148148
}
149149

150-
impl<'a, 'tcx, A, D, T> Engine<'a, 'tcx, A>
150+
impl<'mir, 'tcx, A, D, T> Engine<'mir, 'tcx, A>
151151
where
152152
A: GenKillAnalysis<'tcx, Idx = T, Domain = D>,
153153
D: Clone + JoinSemiLattice + GenKill<T> + BitSetExt<T>,
154154
T: Idx,
155155
{
156156
/// Creates a new `Engine` to solve a gen-kill dataflow problem.
157-
pub fn new_gen_kill(tcx: TyCtxt<'tcx>, body: &'a mir::Body<'tcx>, mut analysis: A) -> Self {
157+
pub fn new_gen_kill(tcx: TyCtxt<'tcx>, body: &'mir mir::Body<'tcx>, mut analysis: A) -> Self {
158158
// If there are no back-edges in the control-flow graph, we only ever need to apply the
159159
// transfer function for each block exactly once (assuming that we process blocks in RPO).
160160
//
@@ -186,7 +186,7 @@ where
186186
}
187187
}
188188

189-
impl<'a, 'tcx, A, D> Engine<'a, 'tcx, A>
189+
impl<'mir, 'tcx, A, D> Engine<'mir, 'tcx, A>
190190
where
191191
A: Analysis<'tcx, Domain = D>,
192192
D: Clone + JoinSemiLattice,
@@ -196,13 +196,13 @@ where
196196
///
197197
/// Gen-kill problems should use `new_gen_kill`, which will coalesce transfer functions for
198198
/// better performance.
199-
pub fn new_generic(tcx: TyCtxt<'tcx>, body: &'a mir::Body<'tcx>, analysis: A) -> Self {
199+
pub fn new_generic(tcx: TyCtxt<'tcx>, body: &'mir mir::Body<'tcx>, analysis: A) -> Self {
200200
Self::new(tcx, body, analysis, None)
201201
}
202202

203203
fn new(
204204
tcx: TyCtxt<'tcx>,
205-
body: &'a mir::Body<'tcx>,
205+
body: &'mir mir::Body<'tcx>,
206206
analysis: A,
207207
apply_statement_trans_for_block: Option<Box<dyn Fn(BasicBlock, &mut A::Domain)>>,
208208
) -> Self {
@@ -239,7 +239,6 @@ where
239239
tcx,
240240
apply_statement_trans_for_block,
241241
pass_name,
242-
..
243242
} = self;
244243

245244
let mut dirty_queue: WorkQueue<BasicBlock> = WorkQueue::with_none(body.basic_blocks.len());

compiler/rustc_mir_dataflow/src/framework/graphviz.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use super::fmt::{DebugDiffWithAdapter, DebugWithAdapter, DebugWithContext};
1515
use super::{Analysis, CallReturnPlaces, Direction, Results, ResultsRefCursor, ResultsVisitor};
1616

1717
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
18-
pub enum OutputStyle {
18+
pub(crate) enum OutputStyle {
1919
AfterOnly,
2020
BeforeAndAfter,
2121
}
@@ -29,7 +29,7 @@ impl OutputStyle {
2929
}
3030
}
3131

32-
pub struct Formatter<'res, 'mir, 'tcx, A>
32+
pub(crate) struct Formatter<'res, 'mir, 'tcx, A>
3333
where
3434
A: Analysis<'tcx>,
3535
{
@@ -43,7 +43,7 @@ impl<'res, 'mir, 'tcx, A> Formatter<'res, 'mir, 'tcx, A>
4343
where
4444
A: Analysis<'tcx>,
4545
{
46-
pub fn new(
46+
pub(crate) fn new(
4747
body: &'mir Body<'tcx>,
4848
results: &'res mut Results<'tcx, A>,
4949
style: OutputStyle,
@@ -55,7 +55,7 @@ where
5555

5656
/// A pair of a basic block and an index into that basic blocks `successors`.
5757
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
58-
pub struct CfgEdge {
58+
pub(crate) struct CfgEdge {
5959
source: BasicBlock,
6060
index: usize,
6161
}

compiler/rustc_mir_dataflow/src/framework/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub mod graphviz;
4545
pub mod lattice;
4646
mod visitor;
4747

48-
pub use self::cursor::{AnalysisResults, ResultsClonedCursor, ResultsCursor, ResultsRefCursor};
48+
pub use self::cursor::{ResultsClonedCursor, ResultsCursor, ResultsRefCursor};
4949
pub use self::direction::{Backward, Direction, Forward};
5050
pub use self::engine::{Engine, EntrySets, Results, ResultsCloned};
5151
pub use self::lattice::{JoinSemiLattice, MaybeReachable};

0 commit comments

Comments
 (0)