about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorNiko Matsakis <niko@alum.mit.edu>2018-07-02 10:57:52 -0400
committerNiko Matsakis <niko@alum.mit.edu>2018-07-12 00:38:40 -0400
commit862c0dd85153aea02ae284a87cb88e9c0de715a2 (patch)
treecac9010abc7367c553cf6051c813b237ecf2cf78 /src
parent0052ddd8aec0701aa8444ad780fa4ebb123301ff (diff)
downloadrust-862c0dd85153aea02ae284a87cb88e9c0de715a2.tar.gz
rust-862c0dd85153aea02ae284a87cb88e9c0de715a2.zip
make `RegionValues` generic over its domain
We used to store one value per RegionVid; we will soon be storing one
value per SCC.
Diffstat (limited to 'src')
-rw-r--r--src/librustc_mir/borrow_check/nll/region_infer/mod.rs6
-rw-r--r--src/librustc_mir/borrow_check/nll/region_infer/values.rs24
2 files changed, 15 insertions, 15 deletions
diff --git a/src/librustc_mir/borrow_check/nll/region_infer/mod.rs b/src/librustc_mir/borrow_check/nll/region_infer/mod.rs
index e4426ff3869..221da10e8e8 100644
--- a/src/librustc_mir/borrow_check/nll/region_infer/mod.rs
+++ b/src/librustc_mir/borrow_check/nll/region_infer/mod.rs
@@ -53,11 +53,11 @@ pub struct RegionInferenceContext<'tcx> {
     /// regions, these start out empty and steadily grow, though for
     /// each universally quantified region R they start out containing
     /// the entire CFG and `end(R)`.
-    liveness_constraints: RegionValues,
+    liveness_constraints: RegionValues<RegionVid>,
 
     /// The final inferred values of the inference variables; `None`
     /// until `solve` is invoked.
-    inferred_values: Option<RegionValues>,
+    inferred_values: Option<RegionValues<RegionVid>>,
 
     /// The constraints we have accumulated and used during solving.
     constraints: ConstraintSet,
@@ -394,7 +394,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
         self.inferred_values = Some(inferred_values);
     }
 
-    fn compute_region_values(&self, _mir: &Mir<'tcx>) -> RegionValues {
+    fn compute_region_values(&self, _mir: &Mir<'tcx>) -> RegionValues<RegionVid> {
         debug!("compute_region_values()");
         debug!("compute_region_values: constraints={:#?}", {
             let mut constraints: Vec<_> = self.constraints.iter().collect();
diff --git a/src/librustc_mir/borrow_check/nll/region_infer/values.rs b/src/librustc_mir/borrow_check/nll/region_infer/values.rs
index 1039e6d7b97..bb4fa73ebb0 100644
--- a/src/librustc_mir/borrow_check/nll/region_infer/values.rs
+++ b/src/librustc_mir/borrow_check/nll/region_infer/values.rs
@@ -179,12 +179,12 @@ impl ToElementIndex for RegionElementIndex {
 /// variable. The columns consist of either universal regions or
 /// points in the CFG.
 #[derive(Clone)]
-pub(super) struct RegionValues {
+pub(super) struct RegionValues<N: Idx> {
     elements: Rc<RegionValueElements>,
-    matrix: SparseBitMatrix<RegionVid, RegionElementIndex>,
+    matrix: SparseBitMatrix<N, RegionElementIndex>,
 }
 
-impl RegionValues {
+impl<N: Idx> RegionValues<N> {
     /// Creates a new set of "region values" that tracks causal information.
     /// Each of the regions in num_region_variables will be initialized with an
     /// empty set of points and no causal information.
@@ -197,7 +197,7 @@ impl RegionValues {
         Self {
             elements: elements.clone(),
             matrix: SparseBitMatrix::new(
-                RegionVid::new(num_region_variables),
+                N::new(num_region_variables),
                 RegionElementIndex::new(elements.num_elements()),
             ),
         }
@@ -205,7 +205,7 @@ impl RegionValues {
 
     /// Adds the given element to the value for the given region. Returns true if
     /// the element is newly added (i.e., was not already present).
-    pub(super) fn add_element<E: ToElementIndex>(&mut self, r: RegionVid, elem: E) -> bool {
+    pub(super) fn add_element<E: ToElementIndex>(&mut self, r: N, elem: E) -> bool {
         let i = self.elements.index(elem);
         debug!("add(r={:?}, elem={:?})", r, elem);
         self.matrix.add(r, i)
@@ -213,19 +213,19 @@ impl RegionValues {
 
     /// Add all elements in `r_from` to `r_to` (because e.g. `r_to:
     /// r_from`).
-    pub(super) fn add_region(&mut self, r_to: RegionVid, r_from: RegionVid) -> bool {
+    pub(super) fn add_region(&mut self, r_to: N, r_from: N) -> bool {
         self.matrix.merge(r_from, r_to)
     }
 
     /// True if the region `r` contains the given element.
-    pub(super) fn contains<E: ToElementIndex>(&self, r: RegionVid, elem: E) -> bool {
+    pub(super) fn contains<E: ToElementIndex>(&self, r: N, elem: E) -> bool {
         let i = self.elements.index(elem);
         self.matrix.contains(r, i)
     }
 
     /// True if `sup_region` contains all the CFG points that
     /// `sub_region` contains. Ignores universal regions.
-    pub(super) fn contains_points(&self, sup_region: RegionVid, sub_region: RegionVid) -> bool {
+    pub(super) fn contains_points(&self, sup_region: N, sub_region: N) -> bool {
         // This could be done faster by comparing the bitsets. But I
         // am lazy.
         self.element_indices_contained_in(sub_region)
@@ -238,7 +238,7 @@ impl RegionValues {
     /// `elements_contained_in`.
     pub(super) fn element_indices_contained_in<'a>(
         &'a self,
-        r: RegionVid,
+        r: N,
     ) -> impl Iterator<Item = RegionElementIndex> + 'a {
         self.matrix.iter(r).map(move |i| i)
     }
@@ -246,7 +246,7 @@ impl RegionValues {
     /// Returns just the universal regions that are contained in a given region's value.
     pub(super) fn universal_regions_outlived_by<'a>(
         &'a self,
-        r: RegionVid,
+        r: N,
     ) -> impl Iterator<Item = RegionVid> + 'a {
         self.element_indices_contained_in(r)
             .map(move |i| self.elements.to_universal_region(i))
@@ -257,14 +257,14 @@ impl RegionValues {
     /// Returns all the elements contained in a given region's value.
     pub(super) fn elements_contained_in<'a>(
         &'a self,
-        r: RegionVid,
+        r: N,
     ) -> impl Iterator<Item = RegionElement> + 'a {
         self.element_indices_contained_in(r)
             .map(move |r| self.elements.to_element(r))
     }
 
     /// Returns a "pretty" string value of the region. Meant for debugging.
-    pub(super) fn region_value_str(&self, r: RegionVid) -> String {
+    pub(super) fn region_value_str(&self, r: N) -> String {
         let mut result = String::new();
         result.push_str("{");