]> git.lizzy.rs Git - rust.git/commitdiff
infer: extract total number of region variables from infcx
authorNiko Matsakis <niko@alum.mit.edu>
Mon, 6 Nov 2017 09:33:15 +0000 (04:33 -0500)
committerNiko Matsakis <niko@alum.mit.edu>
Thu, 16 Nov 2017 10:57:46 +0000 (05:57 -0500)
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.

src/librustc_mir/transform/nll/mod.rs
src/librustc_mir/transform/nll/region_infer.rs
src/librustc_mir/transform/nll/renumber.rs

index f3e24e925890da97dff02992734e44d86e0d924a..a0334ed078f44e8090ba35c186769ac5d235d7da 100644 (file)
@@ -41,7 +41,7 @@ pub fn compute_regions<'a, 'gcx, 'tcx>(
     let free_regions = &free_regions::free_regions(infcx, def_id);
 
     // Replace all regions with fresh inference variables.
-    let num_region_variables = renumber::renumber_mir(infcx, free_regions, mir);
+    renumber::renumber_mir(infcx, free_regions, mir);
 
     // Compute what is live where.
     let liveness = &LivenessResults {
@@ -64,7 +64,7 @@ pub fn compute_regions<'a, 'gcx, 'tcx>(
 
     // Create the region inference context, generate the constraints,
     // and then solve them.
-    let mut regioncx = RegionInferenceContext::new(free_regions, num_region_variables, mir);
+    let mut regioncx = RegionInferenceContext::new(infcx, free_regions, mir);
     let param_env = infcx.tcx.param_env(def_id);
     constraint_generation::generate_constraints(infcx, &mut regioncx, &mir, param_env, liveness);
     regioncx.solve(infcx, &mir);
index add48a9600a510059e30eef8a3d53836b6211e7e..f1160d42155ab56df83556f62823c042a9905f65 100644 (file)
@@ -113,14 +113,12 @@ impl<'a, 'gcx, 'tcx> RegionInferenceContext<'tcx> {
     /// of those will be constant regions representing the free
     /// regions defined in `free_regions`.
     pub fn new(
+        infcx: &InferCtxt<'_, '_, 'tcx>,
         free_regions: &FreeRegions<'tcx>,
-        num_region_variables: usize,
         mir: &Mir<'tcx>,
     ) -> Self {
         let mut result = Self {
-            definitions: (0..num_region_variables)
-                .map(|_| RegionDefinition::default())
-                .collect(),
+            definitions: infcx.all_region_vars().map(|_| RegionDefinition::default()).collect(),
             constraints: Vec::new(),
             free_regions: Vec::new(),
         };
index 7cdcb106c8c246ff8b073d8e3a7586a7ffd103f6..c053dab123d7fff3fe23740d3d522be1470f666d 100644 (file)
@@ -25,7 +25,7 @@ pub fn renumber_mir<'a, 'gcx, 'tcx>(
     infcx: &InferCtxt<'a, 'gcx, 'tcx>,
     free_regions: &FreeRegions<'tcx>,
     mir: &mut Mir<'tcx>,
-) -> usize {
+) {
     // Create inference variables for each of the free regions
     // declared on the function signature.
     let free_region_inference_vars = (0..free_regions.indices.len())
@@ -37,18 +37,15 @@ pub fn renumber_mir<'a, 'gcx, 'tcx>(
     let mut visitor = NLLVisitor {
         infcx,
         lookup_map: HashMap::new(),
-        num_region_variables: free_regions.indices.len(),
         free_regions,
         free_region_inference_vars,
         arg_count: mir.arg_count,
     };
     visitor.visit_mir(mir);
-    visitor.num_region_variables
 }
 
 struct NLLVisitor<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> {
     lookup_map: HashMap<RegionVid, TyContext>,
-    num_region_variables: usize,
     infcx: &'a InferCtxt<'a, 'gcx, 'tcx>,
     free_regions: &'a FreeRegions<'tcx>,
     free_region_inference_vars: IndexVec<RegionVid, ty::Region<'tcx>>,
@@ -66,9 +63,7 @@ fn renumber_regions<T>(&mut self, value: &T) -> T
         self.infcx
             .tcx
             .fold_regions(value, &mut false, |_region, _depth| {
-                self.num_region_variables += 1;
-                self.infcx
-                    .next_region_var(rustc_infer::MiscVariable(DUMMY_SP))
+                self.infcx.next_region_var(rustc_infer::MiscVariable(DUMMY_SP))
             })
     }