#![feature(core_intrinsics)]
#![feature(decl_macro)]
#![feature(i128_type)]
+#![feature(match_default_bindings)]
#![feature(rustc_diagnostic_macros)]
#![feature(placement_in_syntax)]
#![feature(collection_placement)]
use rustc::ty;
use rustc::ty::subst::Substs;
use rustc::util::nodemap::FxHashMap;
+use rustc_data_structures::indexed_vec::Idx;
+
+use super::RegionIndex;
#[derive(Debug)]
pub struct FreeRegions<'tcx> {
/// Given a free region defined on this function (either early- or
- /// late-bound), this maps it to its internal region index. The
- /// corresponding variable will be "capped" so that it cannot
- /// grow.
- pub indices: FxHashMap<ty::Region<'tcx>, usize>,
+ /// late-bound), this maps it to its internal region index. When
+ /// the region context is created, the first N variables will be
+ /// created based on these indices.
+ pub indices: FxHashMap<ty::Region<'tcx>, RegionIndex>,
/// The map from the typeck tables telling us how to relate free regions.
pub free_region_map: &'tcx FreeRegionMap<'tcx>,
}
fn insert_free_region<'tcx>(
- free_regions: &mut FxHashMap<ty::Region<'tcx>, usize>,
+ free_regions: &mut FxHashMap<ty::Region<'tcx>, RegionIndex>,
region: ty::Region<'tcx>,
) {
- let len = free_regions.len();
- free_regions.entry(region).or_insert(len);
+ let next = RegionIndex::new(free_regions.len());
+ free_regions.entry(region).or_insert(next);
}
use rustc::infer::InferCtxt;
use rustc::mir::{Location, Mir};
use rustc::ty;
-use rustc_data_structures::indexed_vec::{Idx, IndexVec};
+use rustc_data_structures::indexed_vec::IndexVec;
use rustc_data_structures::fx::FxHashSet;
use std::collections::BTreeSet;
use std::fmt;
/// is just itself. R1 (`'b`) in contrast also outlives `'a` and
/// hence contains R0 and R1.
fn init_free_regions(&mut self, free_regions: &FreeRegions<'tcx>, mir: &Mir<'tcx>) {
- let &FreeRegions {
- ref indices,
- ref free_region_map,
+ let FreeRegions {
+ indices,
+ free_region_map,
} = free_regions;
// For each free region X:
- for (free_region, index) in indices {
- let variable = RegionIndex::new(*index);
-
+ for (free_region, &variable) in indices {
self.free_regions.push(variable);
// Initialize the name and a few other details.
// Go through each region Y that outlives X (i.e., where
// Y: X is true). Add `end(X)` into the set for `Y`.
for superregion in free_region_map.regions_that_outlive(&free_region) {
- let superregion_index = RegionIndex::new(indices[superregion]);
+ let superregion_index = indices[superregion];
self.definitions[superregion_index]
.value
.add_free_region(variable);
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-use rustc_data_structures::indexed_vec::Idx;
+use rustc_data_structures::indexed_vec::{Idx, IndexVec};
use rustc::ty::subst::{Kind, Substs};
use rustc::ty::{self, ClosureSubsts, RegionKind, RegionVid, Ty, TypeFoldable};
use rustc::mir::{BasicBlock, Local, Location, Mir, Rvalue, Statement, StatementKind};
use syntax_pos::DUMMY_SP;
use std::collections::HashMap;
+use super::RegionIndex;
use super::free_regions::FreeRegions;
/// Replaces all free regions appearing in the MIR with fresh
num_region_variables: usize,
infcx: &'a InferCtxt<'a, 'gcx, 'tcx>,
free_regions: &'a FreeRegions<'tcx>,
- free_region_inference_vars: Vec<ty::Region<'tcx>>,
+ free_region_inference_vars: IndexVec<RegionIndex, ty::Region<'tcx>>,
arg_count: usize,
}