Skip to content

Commit ecd67ee

Browse files
Use builder method to set dead_unwinds
`dead_unwinds` is an empty bitset in most places. This saves us from having to construct that empty bitset for every dataflow analysis.
1 parent bc1b6ba commit ecd67ee

File tree

5 files changed

+27
-29
lines changed

5 files changed

+27
-29
lines changed

src/librustc_mir/borrow_check/mod.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -184,12 +184,10 @@ fn do_mir_borrowck<'a, 'tcx>(
184184
param_env,
185185
};
186186

187-
let dead_unwinds = BitSet::new_empty(body.basic_blocks().len());
188187
let flow_inits = MaybeInitializedPlaces::new(tcx, &body, &mdpe);
189-
let mut flow_inits =
190-
dataflow::generic::Engine::new_gen_kill(tcx, &body, def_id, &dead_unwinds, flow_inits)
191-
.iterate_to_fixpoint()
192-
.into_cursor(&body);
188+
let mut flow_inits = dataflow::generic::Engine::new_gen_kill(tcx, &body, def_id, flow_inits)
189+
.iterate_to_fixpoint()
190+
.into_cursor(&body);
193191

194192
let locals_are_invalidated_at_exit = tcx.hir().body_owner_kind(id).is_fn_or_closure();
195193
let borrow_set = Rc::new(BorrowSet::build(
@@ -219,6 +217,7 @@ fn do_mir_borrowck<'a, 'tcx>(
219217

220218
let regioncx = Rc::new(regioncx);
221219

220+
let dead_unwinds = BitSet::new_empty(body.basic_blocks().len());
222221
let flow_borrows = FlowAtLocation::new(do_dataflow(
223222
tcx,
224223
&body,

src/librustc_mir/dataflow/generic/engine.rs

+12-10
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ where
2525
tcx: TyCtxt<'tcx>,
2626
body: &'a mir::Body<'tcx>,
2727
def_id: DefId,
28-
dead_unwinds: &'a BitSet<BasicBlock>,
28+
dead_unwinds: Option<&'a BitSet<BasicBlock>>,
2929
entry_sets: IndexVec<BasicBlock, BitSet<A::Idx>>,
3030
analysis: A,
3131

@@ -42,7 +42,6 @@ where
4242
tcx: TyCtxt<'tcx>,
4343
body: &'a mir::Body<'tcx>,
4444
def_id: DefId,
45-
dead_unwinds: &'a BitSet<BasicBlock>,
4645
analysis: A,
4746
) -> Self {
4847
let bits_per_block = analysis.bits_per_block(body);
@@ -70,7 +69,7 @@ where
7069
}
7170
}
7271

73-
Self::new(tcx, body, def_id, dead_unwinds, analysis, Some(trans_for_block))
72+
Self::new(tcx, body, def_id, analysis, Some(trans_for_block))
7473
}
7574
}
7675

@@ -87,17 +86,15 @@ where
8786
tcx: TyCtxt<'tcx>,
8887
body: &'a mir::Body<'tcx>,
8988
def_id: DefId,
90-
dead_unwinds: &'a BitSet<BasicBlock>,
9189
analysis: A,
9290
) -> Self {
93-
Self::new(tcx, body, def_id, dead_unwinds, analysis, None)
91+
Self::new(tcx, body, def_id, analysis, None)
9492
}
9593

9694
fn new(
9795
tcx: TyCtxt<'tcx>,
9896
body: &'a mir::Body<'tcx>,
9997
def_id: DefId,
100-
dead_unwinds: &'a BitSet<BasicBlock>,
10198
analysis: A,
10299
trans_for_block: Option<IndexVec<BasicBlock, GenKillSet<A::Idx>>>,
103100
) -> Self {
@@ -118,12 +115,17 @@ where
118115
tcx,
119116
body,
120117
def_id,
121-
dead_unwinds,
118+
dead_unwinds: None,
122119
entry_sets,
123120
trans_for_block,
124121
}
125122
}
126123

124+
pub fn dead_unwinds(mut self, dead_unwinds: &'a BitSet<BasicBlock>) -> Self {
125+
self.dead_unwinds = Some(dead_unwinds);
126+
self
127+
}
128+
127129
pub fn iterate_to_fixpoint(mut self) -> Results<'tcx, A> {
128130
let mut temp_state = BitSet::new_empty(self.bits_per_block);
129131

@@ -229,7 +231,7 @@ where
229231
| DropAndReplace { target, value: _, location: _, unwind: Some(unwind) }
230232
=> {
231233
self.propagate_bits_into_entry_set_for(in_out, target, dirty_list);
232-
if !self.dead_unwinds.contains(bb) {
234+
if self.dead_unwinds.map_or(true, |bbs| !bbs.contains(bb)) {
233235
self.propagate_bits_into_entry_set_for(in_out, unwind, dirty_list);
234236
}
235237
}
@@ -242,7 +244,7 @@ where
242244

243245
Call { cleanup, ref destination, ref func, ref args, .. } => {
244246
if let Some(unwind) = cleanup {
245-
if !self.dead_unwinds.contains(bb) {
247+
if self.dead_unwinds.map_or(true, |bbs| !bbs.contains(bb)) {
246248
self.propagate_bits_into_entry_set_for(in_out, unwind, dirty_list);
247249
}
248250
}
@@ -263,7 +265,7 @@ where
263265
FalseUnwind { real_target, unwind } => {
264266
self.propagate_bits_into_entry_set_for(in_out, real_target, dirty_list);
265267
if let Some(unwind) = unwind {
266-
if !self.dead_unwinds.contains(bb) {
268+
if self.dead_unwinds.map_or(true, |bbs| !bbs.contains(bb)) {
267269
self.propagate_bits_into_entry_set_for(in_out, unwind, dirty_list);
268270
}
269271
}

src/librustc_mir/transform/check_consts/validation.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,10 @@ impl<Q: Qualif> QualifCursor<'a, 'mir, 'tcx, Q> {
3434
pub fn new(
3535
q: Q,
3636
item: &'a Item<'mir, 'tcx>,
37-
dead_unwinds: &BitSet<BasicBlock>,
3837
) -> Self {
3938
let analysis = FlowSensitiveAnalysis::new(q, item);
4039
let results =
41-
dataflow::Engine::new_generic(item.tcx, &item.body, item.def_id, dead_unwinds, analysis)
40+
dataflow::Engine::new_generic(item.tcx, &item.body, item.def_id, analysis)
4241
.iterate_to_fixpoint();
4342
let cursor = dataflow::ResultsCursor::new(*item.body, results);
4443

@@ -155,20 +154,17 @@ impl Validator<'a, 'mir, 'tcx> {
155154
pub fn new(
156155
item: &'a Item<'mir, 'tcx>,
157156
) -> Self {
158-
let dead_unwinds = BitSet::new_empty(item.body.basic_blocks().len());
159-
160157
let needs_drop = QualifCursor::new(
161158
NeedsDrop,
162159
item,
163-
&dead_unwinds,
164160
);
165161

166162
let has_mut_interior = QualifCursor::new(
167163
HasMutInterior,
168164
item,
169-
&dead_unwinds,
170165
);
171166

167+
let dead_unwinds = BitSet::new_empty(item.body.basic_blocks().len());
172168
let indirectly_mutable = old_dataflow::do_dataflow(
173169
item.tcx,
174170
&*item.body,

src/librustc_mir/transform/elaborate_drops.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ impl<'tcx> MirPass<'tcx> for ElaborateDrops {
3838
param_env,
3939
};
4040
let dead_unwinds = find_dead_unwinds(tcx, body, def_id, &env);
41-
let flow_inits = dataflow::generic::Engine::new_gen_kill(
42-
tcx, body, def_id, &dead_unwinds,
43-
MaybeInitializedPlaces::new(tcx, body, &env),
44-
).iterate_to_fixpoint();
41+
let flow_inits = MaybeInitializedPlaces::new(tcx, body, &env);
42+
let flow_inits = dataflow::generic::Engine::new_gen_kill(tcx, body, def_id, flow_inits)
43+
.dead_unwinds(&dead_unwinds)
44+
.iterate_to_fixpoint();
4545
let flow_uninits =
4646
do_dataflow(tcx, body, def_id, &[], &dead_unwinds,
4747
MaybeUninitializedPlaces::new(tcx, body, &env),
@@ -74,10 +74,11 @@ fn find_dead_unwinds<'tcx>(
7474
// We only need to do this pass once, because unwind edges can only
7575
// reach cleanup blocks, which can't have unwind edges themselves.
7676
let mut dead_unwinds = BitSet::new_empty(body.basic_blocks().len());
77+
7778
let flow_inits = MaybeInitializedPlaces::new(tcx, body, &env);
78-
let flow_inits =
79-
dataflow::generic::Engine::new_gen_kill(tcx, body, def_id, &dead_unwinds, flow_inits)
80-
.iterate_to_fixpoint();
79+
let flow_inits = dataflow::generic::Engine::new_gen_kill(tcx, body, def_id, flow_inits)
80+
.iterate_to_fixpoint();
81+
8182
for (bb, bb_data) in body.basic_blocks().iter_enumerated() {
8283
let location = match bb_data.terminator().kind {
8384
TerminatorKind::Drop { ref location, unwind: Some(_), .. } |

src/librustc_mir/transform/rustc_peek.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ impl<'tcx> MirPass<'tcx> for SanityCheck {
4242
let dead_unwinds = BitSet::new_empty(body.basic_blocks().len());
4343

4444
let flow_inits = Engine::new_gen_kill(
45-
tcx, body, def_id, &dead_unwinds,
45+
tcx, body, def_id,
4646
MaybeInitializedPlaces::new(tcx, body, &mdpe),
4747
).iterate_to_fixpoint();
4848
let flow_uninits =

0 commit comments

Comments
 (0)