Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c4cda32

Browse files
committedNov 14, 2019
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 4e6dc22 commit c4cda32

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
@@ -167,12 +167,10 @@ fn do_mir_borrowck<'a, 'tcx>(
167167
param_env,
168168
};
169169

170-
let dead_unwinds = BitSet::new_empty(body.basic_blocks().len());
171170
let flow_inits = MaybeInitializedPlaces::new(tcx, body, &mdpe);
172-
let mut flow_inits =
173-
dataflow::generic::Engine::new_gen_kill(tcx, body, def_id, &dead_unwinds, flow_inits)
174-
.iterate_to_fixpoint()
175-
.into_cursor(body);
171+
let mut flow_inits = dataflow::generic::Engine::new_gen_kill(tcx, body, def_id, flow_inits)
172+
.iterate_to_fixpoint()
173+
.into_cursor(body);
176174

177175
let locals_are_invalidated_at_exit = tcx.hir().body_owner_kind(id).is_fn_or_closure();
178176
let borrow_set = Rc::new(BorrowSet::build(
@@ -201,6 +199,7 @@ fn do_mir_borrowck<'a, 'tcx>(
201199

202200
let regioncx = Rc::new(regioncx);
203201

202+
let dead_unwinds = BitSet::new_empty(body.basic_blocks().len());
204203
let flow_borrows = FlowAtLocation::new(do_dataflow(
205204
tcx,
206205
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
@@ -38,11 +38,10 @@ impl<Q: Qualif> QualifCursor<'a, 'mir, 'tcx, Q> {
3838
pub fn new(
3939
q: Q,
4040
item: &'a Item<'mir, 'tcx>,
41-
dead_unwinds: &BitSet<BasicBlock>,
4241
) -> Self {
4342
let analysis = FlowSensitiveAnalysis::new(q, item);
4443
let results =
45-
dataflow::Engine::new_generic(item.tcx, item.body, item.def_id, dead_unwinds, analysis)
44+
dataflow::Engine::new_generic(item.tcx, item.body, item.def_id, analysis)
4645
.iterate_to_fixpoint();
4746
let cursor = dataflow::ResultsCursor::new(item.body, results);
4847

@@ -133,20 +132,17 @@ impl Validator<'a, 'mir, 'tcx> {
133132
pub fn new(
134133
item: &'a Item<'mir, 'tcx>,
135134
) -> Self {
136-
let dead_unwinds = BitSet::new_empty(item.body.basic_blocks().len());
137-
138135
let needs_drop = QualifCursor::new(
139136
NeedsDrop,
140137
item,
141-
&dead_unwinds,
142138
);
143139

144140
let has_mut_interior = QualifCursor::new(
145141
HasMutInterior,
146142
item,
147-
&dead_unwinds,
148143
);
149144

145+
let dead_unwinds = BitSet::new_empty(item.body.basic_blocks().len());
150146
let indirectly_mutable = old_dataflow::do_dataflow(
151147
item.tcx,
152148
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)
Please sign in to comment.