Skip to content

Commit 129b133

Browse files
committed
tmp: quantify liveness optimization gain
1 parent acf4842 commit 129b133

File tree

3 files changed

+68
-72
lines changed

3 files changed

+68
-72
lines changed

compiler/rustc_borrowck/src/constraints/graph.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub(crate) struct ConstraintGraph<D: ConstraintGraphDirection> {
1818

1919
pub(crate) type NormalConstraintGraph = ConstraintGraph<Normal>;
2020

21-
pub(crate) type ReverseConstraintGraph = ConstraintGraph<Reverse>;
21+
// pub(crate) type ReverseConstraintGraph = ConstraintGraph<Reverse>;
2222

2323
/// Marker trait that controls whether a `R1: R2` constraint
2424
/// represents an edge `R1 -> R2` or `R2 -> R1`.
@@ -49,26 +49,26 @@ impl ConstraintGraphDirection for Normal {
4949
}
5050
}
5151

52-
/// In reverse mode, a `R1: R2` constraint results in an edge `R2 ->
53-
/// R1`. We use this for optimizing liveness computation, because then
54-
/// we wish to iterate from a region (e.g., R2) to all the regions
55-
/// that will outlive it (e.g., R1).
56-
#[derive(Copy, Clone, Debug)]
57-
pub(crate) struct Reverse;
58-
59-
impl ConstraintGraphDirection for Reverse {
60-
fn start_region(c: &OutlivesConstraint<'_>) -> RegionVid {
61-
c.sub
62-
}
63-
64-
fn end_region(c: &OutlivesConstraint<'_>) -> RegionVid {
65-
c.sup
66-
}
67-
68-
fn is_normal() -> bool {
69-
false
70-
}
71-
}
52+
// /// In reverse mode, a `R1: R2` constraint results in an edge `R2 ->
53+
// /// R1`. We use this for optimizing liveness computation, because then
54+
// /// we wish to iterate from a region (e.g., R2) to all the regions
55+
// /// that will outlive it (e.g., R1).
56+
// #[derive(Copy, Clone, Debug)]
57+
// pub(crate) struct Reverse;
58+
59+
// impl ConstraintGraphDirection for Reverse {
60+
// fn start_region(c: &OutlivesConstraint<'_>) -> RegionVid {
61+
// c.sub
62+
// }
63+
64+
// fn end_region(c: &OutlivesConstraint<'_>) -> RegionVid {
65+
// c.sup
66+
// }
67+
68+
// fn is_normal() -> bool {
69+
// false
70+
// }
71+
// }
7272

7373
impl<D: ConstraintGraphDirection> ConstraintGraph<D> {
7474
/// Creates a "dependency graph" where each region constraint `R1:

compiler/rustc_borrowck/src/constraints/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ impl<'tcx> OutlivesConstraintSet<'tcx> {
4242
graph::ConstraintGraph::new(graph::Normal, self, num_region_vars)
4343
}
4444

45-
/// Like `graph`, but constraints a reverse graph where `R1: R2`
46-
/// represents an edge `R2 -> R1`.
47-
pub(crate) fn reverse_graph(&self, num_region_vars: usize) -> graph::ReverseConstraintGraph {
48-
graph::ConstraintGraph::new(graph::Reverse, self, num_region_vars)
49-
}
45+
// /// Like `graph`, but constraints a reverse graph where `R1: R2`
46+
// /// represents an edge `R2 -> R1`.
47+
// pub(crate) fn reverse_graph(&self, num_region_vars: usize) -> graph::ReverseConstraintGraph {
48+
// graph::ConstraintGraph::new(graph::Reverse, self, num_region_vars)
49+
// }
5050

5151
pub(crate) fn outlives(
5252
&self,

compiler/rustc_borrowck/src/type_check/liveness/mod.rs

Lines changed: 42 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ use rustc_mir_dataflow::points::DenseLocationMap;
1212
use tracing::debug;
1313

1414
use super::TypeChecker;
15-
use crate::constraints::OutlivesConstraintSet;
15+
// use crate::constraints::OutlivesConstraintSet;
1616
use crate::region_infer::values::LivenessValues;
17-
use crate::universal_regions::UniversalRegions;
17+
// use crate::universal_regions::UniversalRegions;
1818

1919
mod local_use_map;
2020
mod polonius;
@@ -37,11 +37,7 @@ pub(super) fn generate<'a, 'tcx>(
3737
) {
3838
debug!("liveness::generate");
3939

40-
let free_regions = regions_that_outlive_free_regions(
41-
typeck.infcx.num_region_vars(),
42-
&typeck.universal_regions,
43-
&typeck.constraints.outlives_constraints,
44-
);
40+
let free_regions = typeck.universal_regions.universal_regions_iter().collect();
4541
let (relevant_live_locals, boring_locals) =
4642
compute_relevant_live_locals(typeck.tcx(), &free_regions, body);
4743

@@ -88,45 +84,45 @@ fn compute_relevant_live_locals<'tcx>(
8884
(relevant_live_locals, boring_locals)
8985
}
9086

91-
/// Computes all regions that are (currently) known to outlive free
92-
/// regions. For these regions, we do not need to compute
93-
/// liveness, since the outlives constraints will ensure that they
94-
/// are live over the whole fn body anyhow.
95-
fn regions_that_outlive_free_regions<'tcx>(
96-
num_region_vars: usize,
97-
universal_regions: &UniversalRegions<'tcx>,
98-
constraint_set: &OutlivesConstraintSet<'tcx>,
99-
) -> FxHashSet<RegionVid> {
100-
// Build a graph of the outlives constraints thus far. This is
101-
// a reverse graph, so for each constraint `R1: R2` we have an
102-
// edge `R2 -> R1`. Therefore, if we find all regions
103-
// reachable from each free region, we will have all the
104-
// regions that are forced to outlive some free region.
105-
let rev_constraint_graph = constraint_set.reverse_graph(num_region_vars);
106-
let fr_static = universal_regions.fr_static;
107-
let rev_region_graph = rev_constraint_graph.region_graph(constraint_set, fr_static);
108-
109-
// Stack for the depth-first search. Start out with all the free regions.
110-
let mut stack: Vec<_> = universal_regions.universal_regions_iter().collect();
111-
112-
// Set of all free regions, plus anything that outlives them. Initially
113-
// just contains the free regions.
114-
let mut outlives_free_region: FxHashSet<_> = stack.iter().cloned().collect();
115-
116-
// Do the DFS -- for each thing in the stack, find all things
117-
// that outlive it and add them to the set. If they are not,
118-
// push them onto the stack for later.
119-
while let Some(sub_region) = stack.pop() {
120-
stack.extend(
121-
rev_region_graph
122-
.outgoing_regions(sub_region)
123-
.filter(|&r| outlives_free_region.insert(r)),
124-
);
125-
}
126-
127-
// Return the final set of things we visited.
128-
outlives_free_region
129-
}
87+
// /// Computes all regions that are (currently) known to outlive free
88+
// /// regions. For these regions, we do not need to compute
89+
// /// liveness, since the outlives constraints will ensure that they
90+
// /// are live over the whole fn body anyhow.
91+
// fn regions_that_outlive_free_regions<'tcx>(
92+
// num_region_vars: usize,
93+
// universal_regions: &UniversalRegions<'tcx>,
94+
// constraint_set: &OutlivesConstraintSet<'tcx>,
95+
// ) -> FxHashSet<RegionVid> {
96+
// // Build a graph of the outlives constraints thus far. This is
97+
// // a reverse graph, so for each constraint `R1: R2` we have an
98+
// // edge `R2 -> R1`. Therefore, if we find all regions
99+
// // reachable from each free region, we will have all the
100+
// // regions that are forced to outlive some free region.
101+
// let rev_constraint_graph = constraint_set.reverse_graph(num_region_vars);
102+
// let fr_static = universal_regions.fr_static;
103+
// let rev_region_graph = rev_constraint_graph.region_graph(constraint_set, fr_static);
104+
105+
// // Stack for the depth-first search. Start out with all the free regions.
106+
// let mut stack: Vec<_> = universal_regions.universal_regions_iter().collect();
107+
108+
// // Set of all free regions, plus anything that outlives them. Initially
109+
// // just contains the free regions.
110+
// let mut outlives_free_region: FxHashSet<_> = stack.iter().cloned().collect();
111+
112+
// // Do the DFS -- for each thing in the stack, find all things
113+
// // that outlive it and add them to the set. If they are not,
114+
// // push them onto the stack for later.
115+
// while let Some(sub_region) = stack.pop() {
116+
// stack.extend(
117+
// rev_region_graph
118+
// .outgoing_regions(sub_region)
119+
// .filter(|&r| outlives_free_region.insert(r)),
120+
// );
121+
// }
122+
123+
// // Return the final set of things we visited.
124+
// outlives_free_region
125+
// }
130126

131127
/// Some variables are "regular live" at `location` -- i.e., they may be used later. This means that
132128
/// all regions appearing in their type must be live at `location`.

0 commit comments

Comments
 (0)