Skip to content

Commit

Permalink
make RegionValues generic over its domain
Browse files Browse the repository at this point in the history
We used to store one value per RegionVid; we will soon be storing one
value per SCC.
  • Loading branch information
nikomatsakis committed Jul 12, 2018
1 parent 0052ddd commit 862c0dd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
6 changes: 3 additions & 3 deletions src/librustc_mir/borrow_check/nll/region_infer/mod.rs
Expand Up @@ -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,
Expand Down Expand Up @@ -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();
Expand Down
24 changes: 12 additions & 12 deletions src/librustc_mir/borrow_check/nll/region_infer/values.rs
Expand Up @@ -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.
Expand All @@ -197,35 +197,35 @@ impl RegionValues {
Self {
elements: elements.clone(),
matrix: SparseBitMatrix::new(
RegionVid::new(num_region_variables),
N::new(num_region_variables),
RegionElementIndex::new(elements.num_elements()),
),
}
}

/// 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)
}

/// 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)
Expand All @@ -238,15 +238,15 @@ 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)
}

/// 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))
Expand All @@ -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("{");

Expand Down

0 comments on commit 862c0dd

Please sign in to comment.