Skip to content

Commit 7262e64

Browse files
committed
Make FlowAtLocation support borrowing flow data
1 parent 303f77e commit 7262e64

File tree

2 files changed

+24
-14
lines changed

2 files changed

+24
-14
lines changed

src/librustc_mir/dataflow/at_location.rs

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use crate::dataflow::{BitDenotation, DataflowResults, GenKillSet};
88
use crate::dataflow::move_paths::{HasMoveData, MovePathIndex};
99

1010
use std::iter;
11+
use std::borrow::Borrow;
1112

1213
/// A trait for "cartesian products" of multiple FlowAtLocation.
1314
///
@@ -60,18 +61,20 @@ pub trait FlowsAtLocation {
6061
/// (e.g., via `reconstruct_statement_effect` and
6162
/// `reconstruct_terminator_effect`; don't forget to call
6263
/// `apply_local_effect`).
63-
pub struct FlowAtLocation<'tcx, BD>
64+
pub struct FlowAtLocation<'tcx, BD, DR = DataflowResults<'tcx, BD>>
6465
where
6566
BD: BitDenotation<'tcx>,
67+
DR: Borrow<DataflowResults<'tcx, BD>>,
6668
{
67-
base_results: DataflowResults<'tcx, BD>,
69+
base_results: DR,
6870
curr_state: BitSet<BD::Idx>,
6971
stmt_trans: GenKillSet<BD::Idx>,
7072
}
7173

72-
impl<'tcx, BD> FlowAtLocation<'tcx, BD>
74+
impl<'tcx, BD, DR> FlowAtLocation<'tcx, BD, DR>
7375
where
7476
BD: BitDenotation<'tcx>,
77+
DR: Borrow<DataflowResults<'tcx, BD>>,
7578
{
7679
/// Iterate over each bit set in the current state.
7780
pub fn each_state_bit<F>(&self, f: F)
@@ -91,8 +94,8 @@ where
9194
self.stmt_trans.gen_set.iter().for_each(f)
9295
}
9396

94-
pub fn new(results: DataflowResults<'tcx, BD>) -> Self {
95-
let bits_per_block = results.sets().bits_per_block();
97+
pub fn new(results: DR) -> Self {
98+
let bits_per_block = results.borrow().sets().bits_per_block();
9699
let curr_state = BitSet::new_empty(bits_per_block);
97100
let stmt_trans = GenKillSet::from_elem(HybridBitSet::new_empty(bits_per_block));
98101
FlowAtLocation {
@@ -104,7 +107,7 @@ where
104107

105108
/// Access the underlying operator.
106109
pub fn operator(&self) -> &BD {
107-
self.base_results.operator()
110+
self.base_results.borrow().operator()
108111
}
109112

110113
pub fn contains(&self, x: BD::Idx) -> bool {
@@ -134,39 +137,45 @@ where
134137
}
135138
}
136139

137-
impl<'tcx, BD> FlowsAtLocation for FlowAtLocation<'tcx, BD>
138-
where BD: BitDenotation<'tcx>
140+
impl<'tcx, BD, DR> FlowsAtLocation for FlowAtLocation<'tcx, BD, DR>
141+
where
142+
BD: BitDenotation<'tcx>,
143+
DR: Borrow<DataflowResults<'tcx, BD>>,
139144
{
140145
fn reset_to_entry_of(&mut self, bb: BasicBlock) {
141-
self.curr_state.overwrite(self.base_results.sets().entry_set_for(bb.index()));
146+
self.curr_state.overwrite(self.base_results.borrow().sets().entry_set_for(bb.index()));
142147
}
143148

144149
fn reset_to_exit_of(&mut self, bb: BasicBlock) {
145150
self.reset_to_entry_of(bb);
146-
let trans = self.base_results.sets().trans_for(bb.index());
151+
let trans = self.base_results.borrow().sets().trans_for(bb.index());
147152
trans.apply(&mut self.curr_state)
148153
}
149154

150155
fn reconstruct_statement_effect(&mut self, loc: Location) {
151156
self.stmt_trans.clear();
152157
self.base_results
158+
.borrow()
153159
.operator()
154160
.before_statement_effect(&mut self.stmt_trans, loc);
155161
self.stmt_trans.apply(&mut self.curr_state);
156162

157163
self.base_results
164+
.borrow()
158165
.operator()
159166
.statement_effect(&mut self.stmt_trans, loc);
160167
}
161168

162169
fn reconstruct_terminator_effect(&mut self, loc: Location) {
163170
self.stmt_trans.clear();
164171
self.base_results
172+
.borrow()
165173
.operator()
166174
.before_terminator_effect(&mut self.stmt_trans, loc);
167175
self.stmt_trans.apply(&mut self.curr_state);
168176

169177
self.base_results
178+
.borrow()
170179
.operator()
171180
.terminator_effect(&mut self.stmt_trans, loc);
172181
}
@@ -177,9 +186,10 @@ impl<'tcx, BD> FlowsAtLocation for FlowAtLocation<'tcx, BD>
177186
}
178187

179188

180-
impl<'tcx, T> FlowAtLocation<'tcx, T>
189+
impl<'tcx, T, DR> FlowAtLocation<'tcx, T, DR>
181190
where
182191
T: HasMoveData<'tcx> + BitDenotation<'tcx, Idx = MovePathIndex>,
192+
DR: Borrow<DataflowResults<'tcx, T>>,
183193
{
184194
pub fn has_any_child_of(&self, mpi: T::Idx) -> Option<T::Idx> {
185195
// We process `mpi` before the loop below, for two reasons:

src/librustc_mir/transform/generator.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ use std::mem;
6666
use crate::transform::{MirPass, MirSource};
6767
use crate::transform::simplify;
6868
use crate::transform::no_landing_pads::no_landing_pads;
69-
use crate::dataflow::{DataflowResults, DataflowResultsConsumer, FlowAtLocation};
69+
use crate::dataflow::{DataflowResults, DataflowResultsConsumer, FlowAtLocation, FlowAtLocationOwned};
7070
use crate::dataflow::{do_dataflow, DebugFormatted, state_for_location};
7171
use crate::dataflow::{MaybeStorageLive, HaveBeenBorrowedLocals};
7272
use crate::util::dump_mir;
@@ -627,7 +627,7 @@ struct StorageConflictVisitor<'body, 'tcx, 's> {
627627
impl<'body, 'tcx, 's> DataflowResultsConsumer<'body, 'tcx>
628628
for StorageConflictVisitor<'body, 'tcx, 's>
629629
{
630-
type FlowState = FlowAtLocation<'tcx, MaybeStorageLive<'body, 'tcx>>;
630+
type FlowState = FlowAtLocationOwned<'tcx, MaybeStorageLive<'body, 'tcx>>;
631631

632632
fn body(&self) -> &'body Body<'tcx> {
633633
self.body
@@ -657,7 +657,7 @@ impl<'body, 'tcx, 's> DataflowResultsConsumer<'body, 'tcx>
657657

658658
impl<'body, 'tcx, 's> StorageConflictVisitor<'body, 'tcx, 's> {
659659
fn apply_state(&mut self,
660-
flow_state: &FlowAtLocation<'tcx, MaybeStorageLive<'body, 'tcx>>,
660+
flow_state: &FlowAtLocationOwned<'tcx, MaybeStorageLive<'body, 'tcx>>,
661661
loc: Location) {
662662
// Ignore unreachable blocks.
663663
match self.body.basic_blocks()[loc.block].terminator().kind {

0 commit comments

Comments
 (0)