Skip to content

Commit 798caf9

Browse files
Use new dataflow framework for borrowck
1 parent e341dd4 commit 798caf9

File tree

3 files changed

+124
-154
lines changed

3 files changed

+124
-154
lines changed

src/librustc_mir/borrow_check/flows.rs

Lines changed: 17 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,34 @@
33
//! FIXME: this might be better as a "generic" fixed-point combinator,
44
//! but is not as ugly as it is right now.
55
6-
use rustc::mir::{BasicBlock, Location};
7-
use rustc_index::bit_set::BitIter;
8-
96
use crate::borrow_check::location::LocationIndex;
107

118
use crate::borrow_check::nll::PoloniusOutput;
129

10+
use crate::dataflow::generic::ResultsCursor;
1311
use crate::dataflow::indexes::BorrowIndex;
1412
use crate::dataflow::move_paths::HasMoveData;
1513
use crate::dataflow::Borrows;
1614
use crate::dataflow::EverInitializedPlaces;
1715
use crate::dataflow::MaybeUninitializedPlaces;
18-
use crate::dataflow::{FlowAtLocation, FlowsAtLocation};
1916
use either::Either;
2017
use std::fmt;
2118
use std::rc::Rc;
2219

2320
crate struct Flows<'b, 'tcx> {
24-
borrows: FlowAtLocation<'tcx, Borrows<'b, 'tcx>>,
25-
pub uninits: FlowAtLocation<'tcx, MaybeUninitializedPlaces<'b, 'tcx>>,
26-
pub ever_inits: FlowAtLocation<'tcx, EverInitializedPlaces<'b, 'tcx>>,
21+
pub borrows: ResultsCursor<'b, 'tcx, Borrows<'b, 'tcx>>,
22+
pub uninits: ResultsCursor<'b, 'tcx, MaybeUninitializedPlaces<'b, 'tcx>>,
23+
pub ever_inits: ResultsCursor<'b, 'tcx, EverInitializedPlaces<'b, 'tcx>>,
2724

2825
/// Polonius Output
2926
pub polonius_output: Option<Rc<PoloniusOutput>>,
3027
}
3128

3229
impl<'b, 'tcx> Flows<'b, 'tcx> {
3330
crate fn new(
34-
borrows: FlowAtLocation<'tcx, Borrows<'b, 'tcx>>,
35-
uninits: FlowAtLocation<'tcx, MaybeUninitializedPlaces<'b, 'tcx>>,
36-
ever_inits: FlowAtLocation<'tcx, EverInitializedPlaces<'b, 'tcx>>,
31+
borrows: ResultsCursor<'b, 'tcx, Borrows<'b, 'tcx>>,
32+
uninits: ResultsCursor<'b, 'tcx, MaybeUninitializedPlaces<'b, 'tcx>>,
33+
ever_inits: ResultsCursor<'b, 'tcx, EverInitializedPlaces<'b, 'tcx>>,
3734
polonius_output: Option<Rc<PoloniusOutput>>,
3835
) -> Self {
3936
Flows { borrows, uninits, ever_inits, polonius_output }
@@ -46,43 +43,9 @@ impl<'b, 'tcx> Flows<'b, 'tcx> {
4643
if let Some(ref polonius) = self.polonius_output {
4744
Either::Left(polonius.errors_at(location).iter().cloned())
4845
} else {
49-
Either::Right(self.borrows.iter_incoming())
46+
Either::Right(self.borrows.get().iter())
5047
}
5148
}
52-
53-
crate fn with_outgoing_borrows(&self, op: impl FnOnce(BitIter<'_, BorrowIndex>)) {
54-
self.borrows.with_iter_outgoing(op)
55-
}
56-
}
57-
58-
macro_rules! each_flow {
59-
($this:ident, $meth:ident($arg:ident)) => {
60-
FlowAtLocation::$meth(&mut $this.borrows, $arg);
61-
FlowAtLocation::$meth(&mut $this.uninits, $arg);
62-
FlowAtLocation::$meth(&mut $this.ever_inits, $arg);
63-
};
64-
}
65-
66-
impl<'b, 'tcx> FlowsAtLocation for Flows<'b, 'tcx> {
67-
fn reset_to_entry_of(&mut self, bb: BasicBlock) {
68-
each_flow!(self, reset_to_entry_of(bb));
69-
}
70-
71-
fn reset_to_exit_of(&mut self, bb: BasicBlock) {
72-
each_flow!(self, reset_to_exit_of(bb));
73-
}
74-
75-
fn reconstruct_statement_effect(&mut self, location: Location) {
76-
each_flow!(self, reconstruct_statement_effect(location));
77-
}
78-
79-
fn reconstruct_terminator_effect(&mut self, location: Location) {
80-
each_flow!(self, reconstruct_terminator_effect(location));
81-
}
82-
83-
fn apply_local_effect(&mut self, location: Location) {
84-
each_flow!(self, apply_local_effect(location));
85-
}
8649
}
8750

8851
impl<'b, 'tcx> fmt::Display for Flows<'b, 'tcx> {
@@ -91,48 +54,50 @@ impl<'b, 'tcx> fmt::Display for Flows<'b, 'tcx> {
9154

9255
s.push_str("borrows in effect: [");
9356
let mut saw_one = false;
94-
self.borrows.each_state_bit(|borrow| {
57+
self.borrows.get().iter().for_each(|borrow| {
9558
if saw_one {
9659
s.push_str(", ");
9760
};
9861
saw_one = true;
99-
let borrow_data = &self.borrows.operator().borrows()[borrow];
62+
let borrow_data = &self.borrows.analysis().borrows()[borrow];
10063
s.push_str(&borrow_data.to_string());
10164
});
10265
s.push_str("] ");
10366

67+
/*
10468
s.push_str("borrows generated: [");
10569
let mut saw_one = false;
10670
self.borrows.each_gen_bit(|borrow| {
10771
if saw_one {
10872
s.push_str(", ");
10973
};
11074
saw_one = true;
111-
let borrow_data = &self.borrows.operator().borrows()[borrow];
75+
let borrow_data = &self.borrows.analysis().borrows()[borrow];
11276
s.push_str(&borrow_data.to_string());
11377
});
11478
s.push_str("] ");
79+
*/
11580

11681
s.push_str("uninits: [");
11782
let mut saw_one = false;
118-
self.uninits.each_state_bit(|mpi_uninit| {
83+
self.uninits.get().iter().for_each(|mpi_uninit| {
11984
if saw_one {
12085
s.push_str(", ");
12186
};
12287
saw_one = true;
123-
let move_path = &self.uninits.operator().move_data().move_paths[mpi_uninit];
88+
let move_path = &self.uninits.analysis().move_data().move_paths[mpi_uninit];
12489
s.push_str(&move_path.to_string());
12590
});
12691
s.push_str("] ");
12792

12893
s.push_str("ever_init: [");
12994
let mut saw_one = false;
130-
self.ever_inits.each_state_bit(|mpi_ever_init| {
95+
self.ever_inits.get().iter().for_each(|mpi_ever_init| {
13196
if saw_one {
13297
s.push_str(", ");
13398
};
13499
saw_one = true;
135-
let ever_init = &self.ever_inits.operator().move_data().inits[mpi_ever_init];
100+
let ever_init = &self.ever_inits.analysis().move_data().inits[mpi_ever_init];
136101
s.push_str(&format!("{:?}", ever_init));
137102
});
138103
s.push_str("]");

0 commit comments

Comments
 (0)