Skip to content

Commit ef51d1e

Browse files
committed
remove unneeded dataflow engine blocks flag
1 parent 474da0f commit ef51d1e

File tree

13 files changed

+47
-86
lines changed

13 files changed

+47
-86
lines changed

compiler/rustc_borrowck/src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ use rustc_mir_dataflow::impls::{
4848
};
4949
use rustc_mir_dataflow::move_paths::{InitIndex, MoveOutIndex, MovePathIndex};
5050
use rustc_mir_dataflow::move_paths::{InitLocation, LookupResult, MoveData, MoveError};
51+
use rustc_mir_dataflow::Analysis;
5152
use rustc_mir_dataflow::MoveDataParamEnv;
52-
use rustc_mir_dataflow::{Analysis, Blocks};
5353

5454
use crate::session_diagnostics::VarNeedNotMut;
5555

@@ -234,7 +234,7 @@ fn do_mir_borrowck<'tcx>(
234234
let mdpe = MoveDataParamEnv { move_data, param_env };
235235

236236
let mut flow_inits = MaybeInitializedPlaces::new(tcx, &body, &mdpe)
237-
.into_engine(tcx, &body, Blocks::All)
237+
.into_engine(tcx, &body)
238238
.pass_name("borrowck")
239239
.iterate_to_fixpoint()
240240
.into_results_cursor(&body);
@@ -290,15 +290,15 @@ fn do_mir_borrowck<'tcx>(
290290
let regioncx = Rc::new(regioncx);
291291

292292
let flow_borrows = Borrows::new(tcx, body, &regioncx, &borrow_set)
293-
.into_engine(tcx, body, Blocks::All)
293+
.into_engine(tcx, body)
294294
.pass_name("borrowck")
295295
.iterate_to_fixpoint();
296296
let flow_uninits = MaybeUninitializedPlaces::new(tcx, body, &mdpe)
297-
.into_engine(tcx, body, Blocks::All)
297+
.into_engine(tcx, body)
298298
.pass_name("borrowck")
299299
.iterate_to_fixpoint();
300300
let flow_ever_inits = EverInitializedPlaces::new(tcx, body, &mdpe)
301-
.into_engine(tcx, body, Blocks::All)
301+
.into_engine(tcx, body)
302302
.pass_name("borrowck")
303303
.iterate_to_fixpoint();
304304

compiler/rustc_const_eval/src/transform/check_consts/check.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc_middle::mir::*;
1111
use rustc_middle::ty::subst::{GenericArgKind, InternalSubsts};
1212
use rustc_middle::ty::{self, adjustment::PointerCast, Instance, InstanceDef, Ty, TyCtxt};
1313
use rustc_middle::ty::{Binder, TraitRef, TypeVisitable};
14-
use rustc_mir_dataflow::{self, Analysis, Blocks};
14+
use rustc_mir_dataflow::{self, Analysis};
1515
use rustc_span::{sym, Span, Symbol};
1616
use rustc_trait_selection::traits::error_reporting::TypeErrCtxtExt as _;
1717
use rustc_trait_selection::traits::{self, ObligationCauseCode, ObligationCtxt, SelectionContext};
@@ -58,7 +58,7 @@ impl<'mir, 'tcx> Qualifs<'mir, 'tcx> {
5858
let ConstCx { tcx, body, .. } = *ccx;
5959

6060
FlowSensitiveAnalysis::new(NeedsDrop, ccx)
61-
.into_engine(tcx, &body, Blocks::All)
61+
.into_engine(tcx, &body)
6262
.iterate_to_fixpoint()
6363
.into_results_cursor(&body)
6464
});
@@ -85,7 +85,7 @@ impl<'mir, 'tcx> Qualifs<'mir, 'tcx> {
8585
let ConstCx { tcx, body, .. } = *ccx;
8686

8787
FlowSensitiveAnalysis::new(NeedsNonConstDrop, ccx)
88-
.into_engine(tcx, &body, Blocks::All)
88+
.into_engine(tcx, &body)
8989
.iterate_to_fixpoint()
9090
.into_results_cursor(&body)
9191
});
@@ -115,7 +115,7 @@ impl<'mir, 'tcx> Qualifs<'mir, 'tcx> {
115115
let ConstCx { tcx, body, .. } = *ccx;
116116

117117
FlowSensitiveAnalysis::new(HasMutInterior, ccx)
118-
.into_engine(tcx, &body, Blocks::All)
118+
.into_engine(tcx, &body)
119119
.iterate_to_fixpoint()
120120
.into_results_cursor(&body)
121121
});
@@ -163,7 +163,7 @@ impl<'mir, 'tcx> Qualifs<'mir, 'tcx> {
163163

164164
hir::ConstContext::Const | hir::ConstContext::Static(_) => {
165165
let mut cursor = FlowSensitiveAnalysis::new(CustomEq, ccx)
166-
.into_engine(ccx.tcx, &ccx.body, Blocks::All)
166+
.into_engine(ccx.tcx, &ccx.body)
167167
.iterate_to_fixpoint()
168168
.into_results_cursor(&ccx.body);
169169

compiler/rustc_const_eval/src/transform/validate.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use rustc_middle::mir::{
1515
use rustc_middle::ty::{self, InstanceDef, ParamEnv, Ty, TyCtxt, TypeVisitable};
1616
use rustc_mir_dataflow::impls::MaybeStorageLive;
1717
use rustc_mir_dataflow::storage::always_storage_live_locals;
18-
use rustc_mir_dataflow::{Analysis, Blocks, ResultsCursor};
18+
use rustc_mir_dataflow::{Analysis, ResultsCursor};
1919
use rustc_target::abi::{Size, VariantIdx};
2020

2121
#[derive(Copy, Clone, Debug)]
@@ -53,7 +53,7 @@ impl<'tcx> MirPass<'tcx> for Validator {
5353

5454
let always_live_locals = always_storage_live_locals(body);
5555
let storage_liveness = MaybeStorageLive::new(std::borrow::Cow::Owned(always_live_locals))
56-
.into_engine(tcx, body, Blocks::All)
56+
.into_engine(tcx, body)
5757
.iterate_to_fixpoint()
5858
.into_results_cursor(body);
5959

compiler/rustc_mir_dataflow/src/framework/engine.rs

Lines changed: 6 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,6 @@ where
7171
}
7272
}
7373

74-
pub enum Blocks {
75-
/// Consider all MIR blocks
76-
All,
77-
/// Consider only the MIR blocks reachable from the start
78-
Reachable,
79-
}
80-
8174
/// A solver for dataflow problems.
8275
pub struct Engine<'a, 'tcx, A>
8376
where
@@ -97,7 +90,6 @@ where
9790
// performance in practice. I've tried a few ways to avoid this, but they have downsides. See
9891
// the message for the commit that added this FIXME for more information.
9992
apply_trans_for_block: Option<Box<dyn Fn(BasicBlock, &mut A::Domain)>>,
100-
blocks: Blocks,
10193
}
10294

10395
impl<'a, 'tcx, A, D, T> Engine<'a, 'tcx, A>
@@ -107,18 +99,13 @@ where
10799
T: Idx,
108100
{
109101
/// Creates a new `Engine` to solve a gen-kill dataflow problem.
110-
pub fn new_gen_kill(
111-
tcx: TyCtxt<'tcx>,
112-
body: &'a mir::Body<'tcx>,
113-
analysis: A,
114-
blocks: Blocks,
115-
) -> Self {
102+
pub fn new_gen_kill(tcx: TyCtxt<'tcx>, body: &'a mir::Body<'tcx>, analysis: A) -> Self {
116103
// If there are no back-edges in the control-flow graph, we only ever need to apply the
117104
// transfer function for each block exactly once (assuming that we process blocks in RPO).
118105
//
119106
// In this case, there's no need to compute the block transfer functions ahead of time.
120107
if !body.basic_blocks.is_cfg_cyclic() {
121-
return Self::new(tcx, body, analysis, None, blocks);
108+
return Self::new(tcx, body, analysis, None);
122109
}
123110

124111
// Otherwise, compute and store the cumulative transfer function for each block.
@@ -135,7 +122,7 @@ where
135122
trans_for_block[bb].apply(state);
136123
});
137124

138-
Self::new(tcx, body, analysis, Some(apply_trans as Box<_>), blocks)
125+
Self::new(tcx, body, analysis, Some(apply_trans as Box<_>))
139126
}
140127
}
141128

@@ -149,21 +136,15 @@ where
149136
///
150137
/// Gen-kill problems should use `new_gen_kill`, which will coalesce transfer functions for
151138
/// better performance.
152-
pub fn new_generic(
153-
tcx: TyCtxt<'tcx>,
154-
body: &'a mir::Body<'tcx>,
155-
analysis: A,
156-
blocks: Blocks,
157-
) -> Self {
158-
Self::new(tcx, body, analysis, None, blocks)
139+
pub fn new_generic(tcx: TyCtxt<'tcx>, body: &'a mir::Body<'tcx>, analysis: A) -> Self {
140+
Self::new(tcx, body, analysis, None)
159141
}
160142

161143
fn new(
162144
tcx: TyCtxt<'tcx>,
163145
body: &'a mir::Body<'tcx>,
164146
analysis: A,
165147
apply_trans_for_block: Option<Box<dyn Fn(BasicBlock, &mut A::Domain)>>,
166-
blocks: Blocks,
167148
) -> Self {
168149
let bottom_value = analysis.bottom_value(body);
169150
let mut entry_sets = IndexVec::from_elem(bottom_value.clone(), &body.basic_blocks);
@@ -181,7 +162,6 @@ where
181162
pass_name: None,
182163
entry_sets,
183164
apply_trans_for_block,
184-
blocks,
185165
}
186166
}
187167

@@ -217,7 +197,6 @@ where
217197
tcx,
218198
apply_trans_for_block,
219199
pass_name,
220-
blocks,
221200
..
222201
} = self;
223202

@@ -226,23 +205,13 @@ where
226205
let mut visited = BitSet::new_empty(body.basic_blocks.len());
227206

228207
if A::Direction::IS_FORWARD {
229-
match blocks {
230-
Blocks::All => {
231-
for (bb, _) in traversal::reverse_postorder(body) {
232-
dirty_queue.insert(bb);
233-
}
234-
}
235-
Blocks::Reachable => {
236-
dirty_queue.insert(mir::START_BLOCK);
237-
}
238-
}
208+
dirty_queue.insert(mir::START_BLOCK);
239209
} else {
240210
// Reverse post-order on the reverse CFG may generate a better iteration order for
241211
// backward dataflow analyses, but probably not enough to matter.
242212
for (bb, _) in traversal::postorder(body) {
243213
dirty_queue.insert(bb);
244214
}
245-
assert!(matches!(blocks, Blocks::All));
246215
}
247216

248217
// `state` is not actually used between iterations;

compiler/rustc_mir_dataflow/src/framework/mod.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ mod visitor;
4747

4848
pub use self::cursor::{ResultsCursor, ResultsRefCursor};
4949
pub use self::direction::{Backward, Direction, Forward};
50-
pub use self::engine::{Blocks, Engine, Results};
50+
pub use self::engine::{Engine, Results};
5151
pub use self::lattice::{JoinSemiLattice, MeetSemiLattice};
5252
pub use self::visitor::{visit_results, ResultsVisitable, ResultsVisitor};
5353

@@ -261,12 +261,11 @@ pub trait Analysis<'tcx>: AnalysisDomain<'tcx> {
261261
self,
262262
tcx: TyCtxt<'tcx>,
263263
body: &'mir mir::Body<'tcx>,
264-
blocks: Blocks,
265264
) -> Engine<'mir, 'tcx, Self>
266265
where
267266
Self: Sized,
268267
{
269-
Engine::new_generic(tcx, body, self, blocks)
268+
Engine::new_generic(tcx, body, self)
270269
}
271270
}
272271

@@ -420,12 +419,11 @@ where
420419
self,
421420
tcx: TyCtxt<'tcx>,
422421
body: &'mir mir::Body<'tcx>,
423-
blocks: Blocks,
424422
) -> Engine<'mir, 'tcx, Self>
425423
where
426424
Self: Sized,
427425
{
428-
Engine::new_gen_kill(tcx, body, self, blocks)
426+
Engine::new_gen_kill(tcx, body, self)
429427
}
430428
}
431429

compiler/rustc_mir_dataflow/src/lib.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,9 @@ pub use self::drop_flag_effects::{
2525
on_lookup_result_bits,
2626
};
2727
pub use self::framework::{
28-
fmt, graphviz, lattice, visit_results, Analysis, AnalysisDomain, Backward, Blocks,
29-
CallReturnPlaces, Direction, Engine, Forward, GenKill, GenKillAnalysis, JoinSemiLattice,
30-
Results, ResultsCursor, ResultsRefCursor, ResultsVisitable, ResultsVisitor,
31-
SwitchIntEdgeEffects,
28+
fmt, graphviz, lattice, visit_results, Analysis, AnalysisDomain, Backward, CallReturnPlaces,
29+
Direction, Engine, Forward, GenKill, GenKillAnalysis, JoinSemiLattice, Results, ResultsCursor,
30+
ResultsRefCursor, ResultsVisitable, ResultsVisitor, SwitchIntEdgeEffects,
3231
};
3332

3433
use self::move_paths::MoveData;

compiler/rustc_mir_dataflow/src/rustc_peek.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::errors::{
1010
PeekArgumentNotALocal, PeekArgumentUntracked, PeekBitNotSet, PeekMustBeNotTemporary,
1111
PeekMustBePlaceOrRefPlace, StopAfterDataFlowEndedCompilation,
1212
};
13-
use crate::framework::{BitSetExt, Blocks};
13+
use crate::framework::BitSetExt;
1414
use crate::impls::{
1515
DefinitelyInitializedPlaces, MaybeInitializedPlaces, MaybeLiveLocals, MaybeUninitializedPlaces,
1616
};
@@ -39,31 +39,30 @@ impl<'tcx> MirPass<'tcx> for SanityCheck {
3939

4040
if has_rustc_mir_with(tcx, def_id, sym::rustc_peek_maybe_init).is_some() {
4141
let flow_inits = MaybeInitializedPlaces::new(tcx, body, &mdpe)
42-
.into_engine(tcx, body, Blocks::All)
42+
.into_engine(tcx, body)
4343
.iterate_to_fixpoint();
4444

4545
sanity_check_via_rustc_peek(tcx, body, &flow_inits);
4646
}
4747

4848
if has_rustc_mir_with(tcx, def_id, sym::rustc_peek_maybe_uninit).is_some() {
4949
let flow_uninits = MaybeUninitializedPlaces::new(tcx, body, &mdpe)
50-
.into_engine(tcx, body, Blocks::All)
50+
.into_engine(tcx, body)
5151
.iterate_to_fixpoint();
5252

5353
sanity_check_via_rustc_peek(tcx, body, &flow_uninits);
5454
}
5555

5656
if has_rustc_mir_with(tcx, def_id, sym::rustc_peek_definite_init).is_some() {
5757
let flow_def_inits = DefinitelyInitializedPlaces::new(tcx, body, &mdpe)
58-
.into_engine(tcx, body, Blocks::All)
58+
.into_engine(tcx, body)
5959
.iterate_to_fixpoint();
6060

6161
sanity_check_via_rustc_peek(tcx, body, &flow_def_inits);
6262
}
6363

6464
if has_rustc_mir_with(tcx, def_id, sym::rustc_peek_liveness).is_some() {
65-
let flow_liveness =
66-
MaybeLiveLocals.into_engine(tcx, body, Blocks::All).iterate_to_fixpoint();
65+
let flow_liveness = MaybeLiveLocals.into_engine(tcx, body).iterate_to_fixpoint();
6766

6867
sanity_check_via_rustc_peek(tcx, body, &flow_liveness);
6968
}

compiler/rustc_mir_transform/src/dataflow_const_prop.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ use rustc_middle::mir::visit::{MutVisitor, Visitor};
99
use rustc_middle::mir::*;
1010
use rustc_middle::ty::{self, Ty, TyCtxt};
1111
use rustc_mir_dataflow::value_analysis::{Map, State, TrackElem, ValueAnalysis, ValueOrPlace};
12-
use rustc_mir_dataflow::{
13-
lattice::FlatSet, Analysis, Blocks, ResultsVisitor, SwitchIntEdgeEffects,
14-
};
12+
use rustc_mir_dataflow::{lattice::FlatSet, Analysis, ResultsVisitor, SwitchIntEdgeEffects};
1513
use rustc_span::DUMMY_SP;
1614
use rustc_target::abi::Align;
1715

@@ -55,7 +53,7 @@ impl<'tcx> MirPass<'tcx> for DataflowConstProp {
5553
// Perform the actual dataflow analysis.
5654
let analysis = ConstAnalysis::new(tcx, body, map);
5755
let results = debug_span!("analyze")
58-
.in_scope(|| analysis.wrap().into_engine(tcx, body, Blocks::All).iterate_to_fixpoint());
56+
.in_scope(|| analysis.wrap().into_engine(tcx, body).iterate_to_fixpoint());
5957

6058
// Collect results and patch the body afterwards.
6159
let mut visitor = CollectAndPatch::new(tcx, &results.analysis.0.map);

compiler/rustc_mir_transform/src/dead_store_elimination.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ use rustc_index::bit_set::BitSet;
1616
use rustc_middle::mir::*;
1717
use rustc_middle::ty::TyCtxt;
1818
use rustc_mir_dataflow::impls::{borrowed_locals, MaybeTransitiveLiveLocals};
19-
use rustc_mir_dataflow::{Analysis, Blocks};
19+
use rustc_mir_dataflow::Analysis;
2020

2121
/// Performs the optimization on the body
2222
///
2323
/// The `borrowed` set must be a `BitSet` of all the locals that are ever borrowed in this body. It
2424
/// can be generated via the [`borrowed_locals`] function.
2525
pub fn eliminate<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>, borrowed: &BitSet<Local>) {
2626
let mut live = MaybeTransitiveLiveLocals::new(borrowed)
27-
.into_engine(tcx, body, Blocks::All)
27+
.into_engine(tcx, body)
2828
.iterate_to_fixpoint()
2929
.into_results_cursor(body);
3030

compiler/rustc_mir_transform/src/dest_prop.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ use rustc_middle::mir::{
141141
};
142142
use rustc_middle::ty::TyCtxt;
143143
use rustc_mir_dataflow::impls::MaybeLiveLocals;
144-
use rustc_mir_dataflow::{Analysis, Blocks, ResultsCursor};
144+
use rustc_mir_dataflow::{Analysis, ResultsCursor};
145145

146146
pub struct DestinationPropagation;
147147

@@ -189,7 +189,7 @@ impl<'tcx> MirPass<'tcx> for DestinationPropagation {
189189
);
190190
trace!(?candidates);
191191
let mut live = MaybeLiveLocals
192-
.into_engine(tcx, body, Blocks::All)
192+
.into_engine(tcx, body)
193193
.iterate_to_fixpoint()
194194
.into_results_cursor(body);
195195
dest_prop_mir_dump(tcx, body, &mut live, round_count);

0 commit comments

Comments
 (0)