Auto merge of #118203 - nnethercote:rustc_mir_dataflow, r=cjgillot
Minor `rustc_mir_dataflow` cleanups r? `@cjgillot`
This commit is contained in:
commit
e2e978f713
16 changed files with 132 additions and 227 deletions
|
@ -667,36 +667,34 @@ fn locals_live_across_suspend_points<'tcx>(
|
|||
always_live_locals: &BitSet<Local>,
|
||||
movable: bool,
|
||||
) -> LivenessInfo {
|
||||
let body_ref: &Body<'_> = body;
|
||||
|
||||
// Calculate when MIR locals have live storage. This gives us an upper bound of their
|
||||
// lifetimes.
|
||||
let mut storage_live = MaybeStorageLive::new(std::borrow::Cow::Borrowed(always_live_locals))
|
||||
.into_engine(tcx, body_ref)
|
||||
.into_engine(tcx, body)
|
||||
.iterate_to_fixpoint()
|
||||
.into_results_cursor(body_ref);
|
||||
.into_results_cursor(body);
|
||||
|
||||
// Calculate the MIR locals which have been previously
|
||||
// borrowed (even if they are still active).
|
||||
let borrowed_locals_results =
|
||||
MaybeBorrowedLocals.into_engine(tcx, body_ref).pass_name("coroutine").iterate_to_fixpoint();
|
||||
MaybeBorrowedLocals.into_engine(tcx, body).pass_name("coroutine").iterate_to_fixpoint();
|
||||
|
||||
let mut borrowed_locals_cursor = borrowed_locals_results.cloned_results_cursor(body_ref);
|
||||
let mut borrowed_locals_cursor = borrowed_locals_results.cloned_results_cursor(body);
|
||||
|
||||
// Calculate the MIR locals that we actually need to keep storage around
|
||||
// for.
|
||||
let mut requires_storage_results =
|
||||
MaybeRequiresStorage::new(borrowed_locals_results.cloned_results_cursor(body))
|
||||
.into_engine(tcx, body_ref)
|
||||
.into_engine(tcx, body)
|
||||
.iterate_to_fixpoint();
|
||||
let mut requires_storage_cursor = requires_storage_results.as_results_cursor(body_ref);
|
||||
let mut requires_storage_cursor = requires_storage_results.as_results_cursor(body);
|
||||
|
||||
// Calculate the liveness of MIR locals ignoring borrows.
|
||||
let mut liveness = MaybeLiveLocals
|
||||
.into_engine(tcx, body_ref)
|
||||
.into_engine(tcx, body)
|
||||
.pass_name("coroutine")
|
||||
.iterate_to_fixpoint()
|
||||
.into_results_cursor(body_ref);
|
||||
.into_results_cursor(body);
|
||||
|
||||
let mut storage_liveness_map = IndexVec::from_elem(None, &body.basic_blocks);
|
||||
let mut live_locals_at_suspension_points = Vec::new();
|
||||
|
@ -762,7 +760,7 @@ fn locals_live_across_suspend_points<'tcx>(
|
|||
.collect();
|
||||
|
||||
let storage_conflicts = compute_storage_conflicts(
|
||||
body_ref,
|
||||
body,
|
||||
&saved_locals,
|
||||
always_live_locals.clone(),
|
||||
requires_storage_results,
|
||||
|
|
|
@ -172,19 +172,13 @@ impl<'a, 'tcx> DropElaborator<'a, 'tcx> for Elaborator<'a, '_, 'tcx> {
|
|||
let mut some_live = false;
|
||||
let mut some_dead = false;
|
||||
let mut children_count = 0;
|
||||
on_all_children_bits(
|
||||
self.tcx(),
|
||||
self.body(),
|
||||
self.ctxt.move_data(),
|
||||
path,
|
||||
|child| {
|
||||
let (live, dead) = self.ctxt.init_data.maybe_live_dead(child);
|
||||
debug!("elaborate_drop: state({:?}) = {:?}", child, (live, dead));
|
||||
some_live |= live;
|
||||
some_dead |= dead;
|
||||
children_count += 1;
|
||||
},
|
||||
);
|
||||
on_all_children_bits(self.ctxt.move_data(), path, |child| {
|
||||
let (live, dead) = self.ctxt.init_data.maybe_live_dead(child);
|
||||
debug!("elaborate_drop: state({:?}) = {:?}", child, (live, dead));
|
||||
some_live |= live;
|
||||
some_dead |= dead;
|
||||
children_count += 1;
|
||||
});
|
||||
((some_live, some_dead), children_count != 1)
|
||||
}
|
||||
};
|
||||
|
@ -202,13 +196,9 @@ impl<'a, 'tcx> DropElaborator<'a, 'tcx> for Elaborator<'a, '_, 'tcx> {
|
|||
self.ctxt.set_drop_flag(loc, path, DropFlagState::Absent);
|
||||
}
|
||||
DropFlagMode::Deep => {
|
||||
on_all_children_bits(
|
||||
self.tcx(),
|
||||
self.body(),
|
||||
self.ctxt.move_data(),
|
||||
path,
|
||||
|child| self.ctxt.set_drop_flag(loc, child, DropFlagState::Absent),
|
||||
);
|
||||
on_all_children_bits(self.ctxt.move_data(), path, |child| {
|
||||
self.ctxt.set_drop_flag(loc, child, DropFlagState::Absent)
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -268,10 +258,9 @@ impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> {
|
|||
}
|
||||
|
||||
fn create_drop_flag(&mut self, index: MovePathIndex, span: Span) {
|
||||
let tcx = self.tcx;
|
||||
let patch = &mut self.patch;
|
||||
debug!("create_drop_flag({:?})", self.body.span);
|
||||
self.drop_flags[index].get_or_insert_with(|| patch.new_temp(tcx.types.bool, span));
|
||||
self.drop_flags[index].get_or_insert_with(|| patch.new_temp(self.tcx.types.bool, span));
|
||||
}
|
||||
|
||||
fn drop_flag(&mut self, index: MovePathIndex) -> Option<Place<'tcx>> {
|
||||
|
@ -304,7 +293,7 @@ impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> {
|
|||
match path {
|
||||
LookupResult::Exact(path) => {
|
||||
self.init_data.seek_before(self.body.terminator_loc(bb));
|
||||
on_all_children_bits(self.tcx, self.body, self.move_data(), path, |child| {
|
||||
on_all_children_bits(self.move_data(), path, |child| {
|
||||
let (maybe_live, maybe_dead) = self.init_data.maybe_live_dead(child);
|
||||
debug!(
|
||||
"collect_drop_flags: collecting {:?} from {:?}@{:?} - {:?}",
|
||||
|
@ -444,7 +433,7 @@ impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> {
|
|||
|
||||
let loc = Location { block: tgt, statement_index: 0 };
|
||||
let path = self.move_data().rev_lookup.find(destination.as_ref());
|
||||
on_lookup_result_bits(self.tcx, self.body, self.move_data(), path, |child| {
|
||||
on_lookup_result_bits(self.move_data(), path, |child| {
|
||||
self.set_drop_flag(loc, child, DropFlagState::Present)
|
||||
});
|
||||
}
|
||||
|
@ -453,14 +442,9 @@ impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> {
|
|||
|
||||
fn drop_flags_for_args(&mut self) {
|
||||
let loc = Location::START;
|
||||
rustc_mir_dataflow::drop_flag_effects_for_function_entry(
|
||||
self.tcx,
|
||||
self.body,
|
||||
self.env,
|
||||
|path, ds| {
|
||||
self.set_drop_flag(loc, path, ds);
|
||||
},
|
||||
)
|
||||
rustc_mir_dataflow::drop_flag_effects_for_function_entry(self.body, self.env, |path, ds| {
|
||||
self.set_drop_flag(loc, path, ds);
|
||||
})
|
||||
}
|
||||
|
||||
fn drop_flags_for_locs(&mut self) {
|
||||
|
@ -492,7 +476,6 @@ impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> {
|
|||
}
|
||||
let loc = Location { block: bb, statement_index: i };
|
||||
rustc_mir_dataflow::drop_flag_effects_for_location(
|
||||
self.tcx,
|
||||
self.body,
|
||||
self.env,
|
||||
loc,
|
||||
|
@ -515,7 +498,7 @@ impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> {
|
|||
|
||||
let loc = Location { block: bb, statement_index: data.statements.len() };
|
||||
let path = self.move_data().rev_lookup.find(destination.as_ref());
|
||||
on_lookup_result_bits(self.tcx, self.body, self.move_data(), path, |child| {
|
||||
on_lookup_result_bits(self.move_data(), path, |child| {
|
||||
self.set_drop_flag(loc, child, DropFlagState::Present)
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue