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:
parent
a87d1bbb93
commit
109c9a79ed
3 changed files with 6 additions and 13 deletions
|
@ -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);
|
||||
|
|
|
@ -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(),
|
||||
};
|
||||
|
|
|
@ -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 @@ impl<'a, 'gcx, 'tcx> NLLVisitor<'a, 'gcx, 'tcx> {
|
|||
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))
|
||||
})
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue