make RegionValues
generic over its domain
We used to store one value per RegionVid; we will soon be storing one value per SCC.
This commit is contained in:
parent
0052ddd8ae
commit
862c0dd851
@ -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();
|
||||
|
@ -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("{");
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user