Skip to content

Commit def0b9a

Browse files
committed
infer: extract total number of region variables from infcx
We are heading towards deeper integration with the region inference system in infcx; in particular, prior to the creation of the `RegionInferenceContext`, it will be the "owner" of the set of region variables.
1 parent 1bdf18a commit def0b9a

File tree

3 files changed

+6
-13
lines changed

3 files changed

+6
-13
lines changed

src/librustc_mir/transform/nll/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pub fn compute_regions<'a, 'gcx, 'tcx>(
4040
let free_regions = &free_regions::free_regions(infcx, source);
4141

4242
// Replace all regions with fresh inference variables.
43-
let num_region_variables = renumber::renumber_mir(infcx, free_regions, mir);
43+
renumber::renumber_mir(infcx, free_regions, mir);
4444

4545
// Compute what is live where.
4646
let liveness = &LivenessResults {
@@ -63,7 +63,7 @@ pub fn compute_regions<'a, 'gcx, 'tcx>(
6363

6464
// Create the region inference context, generate the constraints,
6565
// and then solve them.
66-
let mut regioncx = RegionInferenceContext::new(free_regions, num_region_variables, mir);
66+
let mut regioncx = RegionInferenceContext::new(infcx, free_regions, mir);
6767
constraint_generation::generate_constraints(infcx, &mut regioncx, &mir, source, liveness);
6868
regioncx.solve(infcx, &mir);
6969

src/librustc_mir/transform/nll/region_infer.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,12 @@ impl<'a, 'gcx, 'tcx> RegionInferenceContext<'tcx> {
113113
/// of those will be constant regions representing the free
114114
/// regions defined in `free_regions`.
115115
pub fn new(
116+
infcx: &InferCtxt<'_, '_, 'tcx>,
116117
free_regions: &FreeRegions<'tcx>,
117-
num_region_variables: usize,
118118
mir: &Mir<'tcx>,
119119
) -> Self {
120120
let mut result = Self {
121-
definitions: (0..num_region_variables)
122-
.map(|_| RegionDefinition::default())
123-
.collect(),
121+
definitions: infcx.all_region_vars().map(|_| RegionDefinition::default()).collect(),
124122
constraints: Vec::new(),
125123
free_regions: Vec::new(),
126124
};

src/librustc_mir/transform/nll/renumber.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub fn renumber_mir<'a, 'gcx, 'tcx>(
2525
infcx: &InferCtxt<'a, 'gcx, 'tcx>,
2626
free_regions: &FreeRegions<'tcx>,
2727
mir: &mut Mir<'tcx>,
28-
) -> usize {
28+
) {
2929
// Create inference variables for each of the free regions
3030
// declared on the function signature.
3131
let free_region_inference_vars = (0..free_regions.indices.len())
@@ -37,18 +37,15 @@ pub fn renumber_mir<'a, 'gcx, 'tcx>(
3737
let mut visitor = NLLVisitor {
3838
infcx,
3939
lookup_map: HashMap::new(),
40-
num_region_variables: free_regions.indices.len(),
4140
free_regions,
4241
free_region_inference_vars,
4342
arg_count: mir.arg_count,
4443
};
4544
visitor.visit_mir(mir);
46-
visitor.num_region_variables
4745
}
4846

4947
struct NLLVisitor<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> {
5048
lookup_map: HashMap<RegionVid, TyContext>,
51-
num_region_variables: usize,
5249
infcx: &'a InferCtxt<'a, 'gcx, 'tcx>,
5350
free_regions: &'a FreeRegions<'tcx>,
5451
free_region_inference_vars: IndexVec<RegionVid, ty::Region<'tcx>>,
@@ -66,9 +63,7 @@ impl<'a, 'gcx, 'tcx> NLLVisitor<'a, 'gcx, 'tcx> {
6663
self.infcx
6764
.tcx
6865
.fold_regions(value, &mut false, |_region, _depth| {
69-
self.num_region_variables += 1;
70-
self.infcx
71-
.next_region_var(rustc_infer::MiscVariable(DUMMY_SP))
66+
self.infcx.next_region_var(rustc_infer::MiscVariable(DUMMY_SP))
7267
})
7368
}
7469

0 commit comments

Comments
 (0)