Skip to content

Commit af10f6e

Browse files
committed
make RegionValues generic over its domain
We used to store one value per RegionVid; we will soon be storing one value per SCC.
1 parent 818d6c9 commit af10f6e

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

src/librustc_mir/borrow_check/nll/region_infer/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ pub struct RegionInferenceContext<'tcx> {
5353
/// regions, these start out empty and steadily grow, though for
5454
/// each universally quantified region R they start out containing
5555
/// the entire CFG and `end(R)`.
56-
liveness_constraints: RegionValues,
56+
liveness_constraints: RegionValues<RegionVid>,
5757

5858
/// The final inferred values of the inference variables; `None`
5959
/// until `solve` is invoked.
60-
inferred_values: Option<RegionValues>,
60+
inferred_values: Option<RegionValues<RegionVid>>,
6161

6262
/// The constraints we have accumulated and used during solving.
6363
constraints: ConstraintSet,
@@ -383,7 +383,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
383383
self.inferred_values = Some(inferred_values);
384384
}
385385

386-
fn compute_region_values(&self, _mir: &Mir<'tcx>) -> RegionValues {
386+
fn compute_region_values(&self, _mir: &Mir<'tcx>) -> RegionValues<RegionVid> {
387387
debug!("compute_region_values()");
388388
debug!("compute_region_values: constraints={:#?}", {
389389
let mut constraints: Vec<_> = self.constraints.iter().collect();

src/librustc_mir/borrow_check/nll/region_infer/values.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -179,12 +179,12 @@ impl ToElementIndex for RegionElementIndex {
179179
/// variable. The columns consist of either universal regions or
180180
/// points in the CFG.
181181
#[derive(Clone)]
182-
pub(super) struct RegionValues {
182+
pub(super) struct RegionValues<N: Idx> {
183183
elements: Rc<RegionValueElements>,
184-
matrix: SparseBitMatrix<RegionVid, RegionElementIndex>,
184+
matrix: SparseBitMatrix<N, RegionElementIndex>,
185185
}
186186

187-
impl RegionValues {
187+
impl<N: Idx> RegionValues<N> {
188188
/// Creates a new set of "region values" that tracks causal information.
189189
/// Each of the regions in num_region_variables will be initialized with an
190190
/// empty set of points and no causal information.
@@ -197,35 +197,35 @@ impl RegionValues {
197197
Self {
198198
elements: elements.clone(),
199199
matrix: SparseBitMatrix::new(
200-
RegionVid::new(num_region_variables),
200+
N::new(num_region_variables),
201201
RegionElementIndex::new(elements.num_elements()),
202202
),
203203
}
204204
}
205205

206206
/// Adds the given element to the value for the given region. Returns true if
207207
/// the element is newly added (i.e., was not already present).
208-
pub(super) fn add_element<E: ToElementIndex>(&mut self, r: RegionVid, elem: E) -> bool {
208+
pub(super) fn add_element<E: ToElementIndex>(&mut self, r: N, elem: E) -> bool {
209209
let i = self.elements.index(elem);
210210
debug!("add(r={:?}, elem={:?})", r, elem);
211211
self.matrix.add(r, i)
212212
}
213213

214214
/// Add all elements in `r_from` to `r_to` (because e.g. `r_to:
215215
/// r_from`).
216-
pub(super) fn add_region(&mut self, r_to: RegionVid, r_from: RegionVid) -> bool {
216+
pub(super) fn add_region(&mut self, r_to: N, r_from: N) -> bool {
217217
self.matrix.merge(r_from, r_to)
218218
}
219219

220220
/// True if the region `r` contains the given element.
221-
pub(super) fn contains<E: ToElementIndex>(&self, r: RegionVid, elem: E) -> bool {
221+
pub(super) fn contains<E: ToElementIndex>(&self, r: N, elem: E) -> bool {
222222
let i = self.elements.index(elem);
223223
self.matrix.contains(r, i)
224224
}
225225

226226
/// True if `sup_region` contains all the CFG points that
227227
/// `sub_region` contains. Ignores universal regions.
228-
pub(super) fn contains_points(&self, sup_region: RegionVid, sub_region: RegionVid) -> bool {
228+
pub(super) fn contains_points(&self, sup_region: N, sub_region: N) -> bool {
229229
// This could be done faster by comparing the bitsets. But I
230230
// am lazy.
231231
self.element_indices_contained_in(sub_region)
@@ -238,15 +238,15 @@ impl RegionValues {
238238
/// `elements_contained_in`.
239239
pub(super) fn element_indices_contained_in<'a>(
240240
&'a self,
241-
r: RegionVid,
241+
r: N,
242242
) -> impl Iterator<Item = RegionElementIndex> + 'a {
243243
self.matrix.iter(r).map(move |i| i)
244244
}
245245

246246
/// Returns just the universal regions that are contained in a given region's value.
247247
pub(super) fn universal_regions_outlived_by<'a>(
248248
&'a self,
249-
r: RegionVid,
249+
r: N,
250250
) -> impl Iterator<Item = RegionVid> + 'a {
251251
self.element_indices_contained_in(r)
252252
.map(move |i| self.elements.to_universal_region(i))
@@ -257,14 +257,14 @@ impl RegionValues {
257257
/// Returns all the elements contained in a given region's value.
258258
pub(super) fn elements_contained_in<'a>(
259259
&'a self,
260-
r: RegionVid,
260+
r: N,
261261
) -> impl Iterator<Item = RegionElement> + 'a {
262262
self.element_indices_contained_in(r)
263263
.map(move |r| self.elements.to_element(r))
264264
}
265265

266266
/// Returns a "pretty" string value of the region. Meant for debugging.
267-
pub(super) fn region_value_str(&self, r: RegionVid) -> String {
267+
pub(super) fn region_value_str(&self, r: N) -> String {
268268
let mut result = String::new();
269269
result.push_str("{");
270270

0 commit comments

Comments
 (0)