1
Fork 0

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.
This commit is contained in:
Niko Matsakis 2017-11-06 04:33:15 -05:00
parent a87d1bbb93
commit 109c9a79ed
3 changed files with 6 additions and 13 deletions

View file

@ -41,7 +41,7 @@ pub fn compute_regions<'a, 'gcx, 'tcx>(
let free_regions = &free_regions::free_regions(infcx, def_id); let free_regions = &free_regions::free_regions(infcx, def_id);
// Replace all regions with fresh inference variables. // 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. // Compute what is live where.
let liveness = &LivenessResults { let liveness = &LivenessResults {
@ -64,7 +64,7 @@ pub fn compute_regions<'a, 'gcx, 'tcx>(
// Create the region inference context, generate the constraints, // Create the region inference context, generate the constraints,
// and then solve them. // 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); let param_env = infcx.tcx.param_env(def_id);
constraint_generation::generate_constraints(infcx, &mut regioncx, &mir, param_env, liveness); constraint_generation::generate_constraints(infcx, &mut regioncx, &mir, param_env, liveness);
regioncx.solve(infcx, &mir); regioncx.solve(infcx, &mir);

View file

@ -113,14 +113,12 @@ impl<'a, 'gcx, 'tcx> RegionInferenceContext<'tcx> {
/// of those will be constant regions representing the free /// of those will be constant regions representing the free
/// regions defined in `free_regions`. /// regions defined in `free_regions`.
pub fn new( pub fn new(
infcx: &InferCtxt<'_, '_, 'tcx>,
free_regions: &FreeRegions<'tcx>, free_regions: &FreeRegions<'tcx>,
num_region_variables: usize,
mir: &Mir<'tcx>, mir: &Mir<'tcx>,
) -> Self { ) -> Self {
let mut result = Self { let mut result = Self {
definitions: (0..num_region_variables) definitions: infcx.all_region_vars().map(|_| RegionDefinition::default()).collect(),
.map(|_| RegionDefinition::default())
.collect(),
constraints: Vec::new(), constraints: Vec::new(),
free_regions: Vec::new(), free_regions: Vec::new(),
}; };

View file

@ -25,7 +25,7 @@ pub fn renumber_mir<'a, 'gcx, 'tcx>(
infcx: &InferCtxt<'a, 'gcx, 'tcx>, infcx: &InferCtxt<'a, 'gcx, 'tcx>,
free_regions: &FreeRegions<'tcx>, free_regions: &FreeRegions<'tcx>,
mir: &mut Mir<'tcx>, mir: &mut Mir<'tcx>,
) -> usize { ) {
// Create inference variables for each of the free regions // Create inference variables for each of the free regions
// declared on the function signature. // declared on the function signature.
let free_region_inference_vars = (0..free_regions.indices.len()) 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 { let mut visitor = NLLVisitor {
infcx, infcx,
lookup_map: HashMap::new(), lookup_map: HashMap::new(),
num_region_variables: free_regions.indices.len(),
free_regions, free_regions,
free_region_inference_vars, free_region_inference_vars,
arg_count: mir.arg_count, arg_count: mir.arg_count,
}; };
visitor.visit_mir(mir); visitor.visit_mir(mir);
visitor.num_region_variables
} }
struct NLLVisitor<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> { struct NLLVisitor<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> {
lookup_map: HashMap<RegionVid, TyContext>, lookup_map: HashMap<RegionVid, TyContext>,
num_region_variables: usize,
infcx: &'a InferCtxt<'a, 'gcx, 'tcx>, infcx: &'a InferCtxt<'a, 'gcx, 'tcx>,
free_regions: &'a FreeRegions<'tcx>, free_regions: &'a FreeRegions<'tcx>,
free_region_inference_vars: IndexVec<RegionVid, ty::Region<'tcx>>, free_region_inference_vars: IndexVec<RegionVid, ty::Region<'tcx>>,
@ -66,9 +63,7 @@ impl<'a, 'gcx, 'tcx> NLLVisitor<'a, 'gcx, 'tcx> {
self.infcx self.infcx
.tcx .tcx
.fold_regions(value, &mut false, |_region, _depth| { .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))
}) })
} }