Skip to content

Commit 6e516c1

Browse files
committed
Auto merge of #68241 - ecstatic-morse:unified-dataflow-impls, r=<try>
[WIP] Migrate dataflow impls to new framework This uses #65672 to implement the most commonly used dataflow analyses so that the performance of the new framework can be tuned. For now, it's just for perf runs. r? @ghost
2 parents 29b854f + b1081c0 commit 6e516c1

File tree

23 files changed

+2537
-1077
lines changed

23 files changed

+2537
-1077
lines changed

src/librustc/mir/mod.rs

+25
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,31 @@ impl<'tcx> Body<'tcx> {
215215
}
216216
}
217217

218+
/// Returns a partially initialized MIR body containing only a list of basic blocks.
219+
///
220+
/// The returned MIR contains no `LocalDecl`s (even for the return place) or source scopes. It
221+
/// is only useful for testing but cannot be `#[cfg(test)]` because it is used in a different
222+
/// crate.
223+
pub fn new_cfg_only(basic_blocks: IndexVec<BasicBlock, BasicBlockData<'tcx>>) -> Self {
224+
Body {
225+
phase: MirPhase::Build,
226+
basic_blocks,
227+
source_scopes: IndexVec::new(),
228+
yield_ty: None,
229+
generator_drop: None,
230+
generator_layout: None,
231+
local_decls: IndexVec::new(),
232+
user_type_annotations: IndexVec::new(),
233+
arg_count: 0,
234+
spread_arg: None,
235+
span: DUMMY_SP,
236+
control_flow_destroyed: Vec::new(),
237+
generator_kind: None,
238+
var_debug_info: Vec::new(),
239+
ignore_interior_mut_in_const_validation: false,
240+
}
241+
}
242+
218243
#[inline]
219244
pub fn basic_blocks(&self) -> &IndexVec<BasicBlock, BasicBlockData<'tcx>> {
220245
&self.basic_blocks

src/librustc_mir/borrow_check/flows.rs

+18-51
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,36 @@
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;
6+
#![allow(unused)]
87

98
use crate::borrow_check::location::LocationIndex;
109

1110
use crate::borrow_check::nll::PoloniusOutput;
1211

12+
use crate::dataflow::generic::ResultsCursor;
1313
use crate::dataflow::indexes::BorrowIndex;
1414
use crate::dataflow::move_paths::HasMoveData;
1515
use crate::dataflow::Borrows;
1616
use crate::dataflow::EverInitializedPlaces;
1717
use crate::dataflow::MaybeUninitializedPlaces;
18-
use crate::dataflow::{FlowAtLocation, FlowsAtLocation};
1918
use either::Either;
2019
use std::fmt;
2120
use std::rc::Rc;
2221

2322
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>>,
23+
pub borrows: ResultsCursor<'b, 'tcx, Borrows<'b, 'tcx>>,
24+
pub uninits: ResultsCursor<'b, 'tcx, MaybeUninitializedPlaces<'b, 'tcx>>,
25+
pub ever_inits: ResultsCursor<'b, 'tcx, EverInitializedPlaces<'b, 'tcx>>,
2726

2827
/// Polonius Output
2928
pub polonius_output: Option<Rc<PoloniusOutput>>,
3029
}
3130

3231
impl<'b, 'tcx> Flows<'b, 'tcx> {
3332
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>>,
33+
borrows: ResultsCursor<'b, 'tcx, Borrows<'b, 'tcx>>,
34+
uninits: ResultsCursor<'b, 'tcx, MaybeUninitializedPlaces<'b, 'tcx>>,
35+
ever_inits: ResultsCursor<'b, 'tcx, EverInitializedPlaces<'b, 'tcx>>,
3736
polonius_output: Option<Rc<PoloniusOutput>>,
3837
) -> Self {
3938
Flows { borrows, uninits, ever_inits, polonius_output }
@@ -46,43 +45,9 @@ impl<'b, 'tcx> Flows<'b, 'tcx> {
4645
if let Some(ref polonius) = self.polonius_output {
4746
Either::Left(polonius.errors_at(location).iter().cloned())
4847
} else {
49-
Either::Right(self.borrows.iter_incoming())
48+
Either::Right(self.borrows.get().iter())
5049
}
5150
}
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-
}
8651
}
8752

8853
impl<'b, 'tcx> fmt::Display for Flows<'b, 'tcx> {
@@ -91,48 +56,50 @@ impl<'b, 'tcx> fmt::Display for Flows<'b, 'tcx> {
9156

9257
s.push_str("borrows in effect: [");
9358
let mut saw_one = false;
94-
self.borrows.each_state_bit(|borrow| {
59+
self.borrows.get().iter().for_each(|borrow| {
9560
if saw_one {
9661
s.push_str(", ");
9762
};
9863
saw_one = true;
99-
let borrow_data = &self.borrows.operator().borrows()[borrow];
64+
let borrow_data = &self.borrows.analysis().borrows()[borrow];
10065
s.push_str(&borrow_data.to_string());
10166
});
10267
s.push_str("] ");
10368

69+
/*
10470
s.push_str("borrows generated: [");
10571
let mut saw_one = false;
10672
self.borrows.each_gen_bit(|borrow| {
10773
if saw_one {
10874
s.push_str(", ");
10975
};
11076
saw_one = true;
111-
let borrow_data = &self.borrows.operator().borrows()[borrow];
77+
let borrow_data = &self.borrows.analysis().borrows()[borrow];
11278
s.push_str(&borrow_data.to_string());
11379
});
11480
s.push_str("] ");
81+
*/
11582

11683
s.push_str("uninits: [");
11784
let mut saw_one = false;
118-
self.uninits.each_state_bit(|mpi_uninit| {
85+
self.uninits.get().iter().for_each(|mpi_uninit| {
11986
if saw_one {
12087
s.push_str(", ");
12188
};
12289
saw_one = true;
123-
let move_path = &self.uninits.operator().move_data().move_paths[mpi_uninit];
90+
let move_path = &self.uninits.analysis().move_data().move_paths[mpi_uninit];
12491
s.push_str(&move_path.to_string());
12592
});
12693
s.push_str("] ");
12794

12895
s.push_str("ever_init: [");
12996
let mut saw_one = false;
130-
self.ever_inits.each_state_bit(|mpi_ever_init| {
97+
self.ever_inits.get().iter().for_each(|mpi_ever_init| {
13198
if saw_one {
13299
s.push_str(", ");
133100
};
134101
saw_one = true;
135-
let ever_init = &self.ever_inits.operator().move_data().inits[mpi_ever_init];
102+
let ever_init = &self.ever_inits.analysis().move_data().inits[mpi_ever_init];
136103
s.push_str(&format!("{:?}", ever_init));
137104
});
138105
s.push_str("]");

0 commit comments

Comments
 (0)