Skip to content

Commit 5fa2c9e

Browse files
Port MaybeStorageLive to new dataflow framework
1 parent 49c68bd commit 5fa2c9e

File tree

2 files changed

+37
-41
lines changed

2 files changed

+37
-41
lines changed

src/librustc_mir/dataflow/impls/storage_liveness.rs

Lines changed: 31 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,68 @@
11
pub use super::*;
22

3-
use crate::dataflow::generic::{Results, ResultsRefCursor};
4-
use crate::dataflow::BitDenotation;
5-
use crate::dataflow::MaybeBorrowedLocals;
3+
use crate::dataflow::generic::{self as dataflow, GenKill, Results, ResultsRefCursor};
4+
use crate::dataflow::BottomValue;
65
use rustc::mir::visit::{NonMutatingUseContext, PlaceContext, Visitor};
76
use rustc::mir::*;
87
use std::cell::RefCell;
98

109
#[derive(Copy, Clone)]
11-
pub struct MaybeStorageLive<'a, 'tcx> {
12-
body: &'a Body<'tcx>,
13-
}
10+
pub struct MaybeStorageLive;
1411

15-
impl<'a, 'tcx> MaybeStorageLive<'a, 'tcx> {
16-
pub fn new(body: &'a Body<'tcx>) -> Self {
17-
MaybeStorageLive { body }
18-
}
12+
impl dataflow::AnalysisDomain<'tcx> for MaybeStorageLive {
13+
type Idx = Local;
1914

20-
pub fn body(&self) -> &Body<'tcx> {
21-
self.body
22-
}
23-
}
15+
const NAME: &'static str = "maybe_storage_live";
2416

25-
impl<'a, 'tcx> BitDenotation<'tcx> for MaybeStorageLive<'a, 'tcx> {
26-
type Idx = Local;
27-
fn name() -> &'static str {
28-
"maybe_storage_live"
29-
}
30-
fn bits_per_block(&self) -> usize {
31-
self.body.local_decls.len()
17+
fn bits_per_block(&self, body: &mir::Body<'tcx>) -> usize {
18+
body.local_decls.len()
3219
}
3320

34-
fn start_block_effect(&self, on_entry: &mut BitSet<Local>) {
21+
fn initialize_start_block(&self, body: &mir::Body<'tcx>, on_entry: &mut BitSet<Self::Idx>) {
3522
// The resume argument is live on function entry (we don't care about
3623
// the `self` argument)
37-
for arg in self.body.args_iter().skip(1) {
24+
for arg in body.args_iter().skip(1) {
3825
on_entry.insert(arg);
3926
}
4027
}
28+
}
4129

42-
fn statement_effect(&self, trans: &mut GenKillSet<Local>, loc: Location) {
43-
let stmt = &self.body[loc.block].statements[loc.statement_index];
44-
30+
impl dataflow::GenKillAnalysis<'tcx> for MaybeStorageLive {
31+
fn statement_effect(
32+
&self,
33+
trans: &mut impl GenKill<Self::Idx>,
34+
stmt: &mir::Statement<'tcx>,
35+
_: Location,
36+
) {
4537
match stmt.kind {
4638
StatementKind::StorageLive(l) => trans.gen(l),
4739
StatementKind::StorageDead(l) => trans.kill(l),
4840
_ => (),
4941
}
5042
}
5143

52-
fn terminator_effect(&self, _trans: &mut GenKillSet<Local>, _loc: Location) {
44+
fn terminator_effect(
45+
&self,
46+
_trans: &mut impl GenKill<Self::Idx>,
47+
_: &mir::Terminator<'tcx>,
48+
_: Location,
49+
) {
5350
// Terminators have no effect
5451
}
5552

56-
fn propagate_call_return(
53+
fn call_return_effect(
5754
&self,
58-
_in_out: &mut BitSet<Local>,
59-
_call_bb: mir::BasicBlock,
60-
_dest_bb: mir::BasicBlock,
61-
_dest_place: &mir::Place<'tcx>,
55+
_trans: &mut impl GenKill<Self::Idx>,
56+
_block: BasicBlock,
57+
_func: &mir::Operand<'tcx>,
58+
_args: &[mir::Operand<'tcx>],
59+
_return_place: &mir::Place<'tcx>,
6260
) {
6361
// Nothing to do when a call returns successfully
6462
}
6563
}
6664

67-
impl<'a, 'tcx> BottomValue for MaybeStorageLive<'a, 'tcx> {
65+
impl BottomValue for MaybeStorageLive {
6866
/// bottom = dead
6967
const BOTTOM_VALUE: bool = false;
7068
}

src/librustc_mir/transform/generator.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -473,12 +473,10 @@ fn locals_live_across_suspend_points(
473473

474474
// Calculate when MIR locals have live storage. This gives us an upper bound of their
475475
// lifetimes.
476-
let storage_live_analysis = MaybeStorageLive::new(body_ref);
477-
let storage_live_results =
478-
do_dataflow(tcx, body_ref, def_id, &[], &dead_unwinds, storage_live_analysis, |bd, p| {
479-
DebugFormatted::new(&bd.body().local_decls[p])
480-
});
481-
let mut storage_live_cursor = DataflowResultsCursor::new(&storage_live_results, body_ref);
476+
let mut storage_live = MaybeStorageLive
477+
.into_engine(tcx, body_ref, def_id)
478+
.iterate_to_fixpoint()
479+
.into_results_cursor(body_ref);
482480

483481
// Find the MIR locals which do not use StorageLive/StorageDead statements.
484482
// The storage of these locals are always live.
@@ -534,8 +532,8 @@ fn locals_live_across_suspend_points(
534532
liveness.outs[block].union(borrowed_locals_cursor.get());
535533
}
536534

537-
storage_live_cursor.seek(loc);
538-
let storage_liveness = storage_live_cursor.get();
535+
storage_live.seek_before(loc);
536+
let storage_liveness = storage_live.get();
539537

540538
// Store the storage liveness for later use so we can restore the state
541539
// after a suspension point

0 commit comments

Comments
 (0)