use dataflow::{BitDenotation, BlockSets, DataflowOperator};
pub use dataflow::indexes::BorrowIndex;
use transform::nll::region_infer::RegionInferenceContext;
-use transform::nll::ToRegionIndex;
+use transform::nll::ToRegionVid;
use syntax_pos::Span;
location: Location) {
if let Some(regioncx) = self.nonlexical_regioncx {
for (borrow_index, borrow_data) in self.borrows.iter_enumerated() {
- let borrow_region = borrow_data.region.to_region_index();
+ let borrow_region = borrow_data.region.to_region_vid();
if !regioncx.region_contains_point(borrow_region, location) {
// The region checker really considers the borrow
// to start at the point **after** the location of
use super::subtype;
use super::LivenessResults;
-use super::ToRegionIndex;
+use super::ToRegionVid;
use super::region_infer::RegionInferenceContext;
pub(super) fn generate_constraints<'a, 'gcx, 'tcx>(
self.infcx
.tcx
.for_each_free_region(&live_ty, |live_region| {
- let vid = live_region.to_region_index();
+ let vid = live_region.to_region_vid();
self.regioncx.add_live_point(vid, location);
});
}
};
self.regioncx.add_outlives(span,
- borrow_region.to_region_index(),
- destination_region.to_region_index(),
+ borrow_region.to_region_vid(),
+ destination_region.to_region_vid(),
location.successor_within_block());
}
let span = self.mir.source_info(location).span;
self.regioncx.add_outlives(span,
- base_region.to_region_index(),
- borrow_region.to_region_index(),
+ base_region.to_region_vid(),
+ borrow_region.to_region_vid(),
location.successor_within_block());
}
}
use rustc::hir::def_id::DefId;
use rustc::infer::InferCtxt;
use rustc::middle::free_region::FreeRegionMap;
-use rustc::ty;
+use rustc::ty::{self, RegionVid};
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. When
/// the region context is created, the first N variables will be
/// created based on these indices.
- pub indices: FxHashMap<ty::Region<'tcx>, RegionIndex>,
+ pub indices: FxHashMap<ty::Region<'tcx>, RegionVid>,
/// 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>, RegionIndex>,
+ free_regions: &mut FxHashMap<ty::Region<'tcx>, RegionVid>,
region: ty::Region<'tcx>,
) {
- let next = RegionIndex::new(free_regions.len());
+ let next = RegionVid::new(free_regions.len());
free_regions.entry(region).or_insert(next);
}
use rustc::hir::def_id::DefId;
use rustc::mir::Mir;
use rustc::infer::InferCtxt;
-use rustc::ty::{self, RegionKind};
+use rustc::ty::{self, RegionKind, RegionVid};
use rustc::util::nodemap::FxHashMap;
-use rustc_data_structures::indexed_vec::Idx;
use std::collections::BTreeSet;
use transform::MirSource;
use util::liveness::{self, LivenessMode, LivenessResult, LocalSet};
});
}
-newtype_index!(RegionIndex {
- DEBUG_FORMAT = "'_#{}r",
-});
-
/// Right now, we piggy back on the `ReVar` to store our NLL inference
-/// regions. These are indexed with `RegionIndex`. This method will
-/// assert that the region is a `ReVar` and convert the internal index
-/// into a `RegionIndex`. This is reasonable because in our MIR we
-/// replace all free regions with inference variables.
-pub trait ToRegionIndex {
- fn to_region_index(&self) -> RegionIndex;
+/// regions. These are indexed with `RegionVid`. This method will
+/// assert that the region is a `ReVar` and extract its interal index.
+/// This is reasonable because in our MIR we replace all free regions
+/// with inference variables.
+pub trait ToRegionVid {
+ fn to_region_vid(&self) -> RegionVid;
}
-impl ToRegionIndex for RegionKind {
- fn to_region_index(&self) -> RegionIndex {
+impl ToRegionVid for RegionKind {
+ fn to_region_vid(&self) -> RegionVid {
if let &ty::ReVar(vid) = self {
- RegionIndex::new(vid.index as usize)
+ vid
} else {
bug!("region is not an ReVar: {:?}", self)
}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-use super::RegionIndex;
use super::free_regions::FreeRegions;
use rustc::infer::InferCtxt;
use rustc::mir::{Location, Mir};
-use rustc::ty;
+use rustc::ty::{self, RegionVid};
use rustc_data_structures::indexed_vec::IndexVec;
use rustc_data_structures::fx::FxHashSet;
use std::collections::BTreeSet;
pub struct RegionInferenceContext<'tcx> {
/// Contains the definition for every region variable. Region
- /// variables are identified by their index (`RegionIndex`). The
+ /// variables are identified by their index (`RegionVid`). The
/// definition contains information about where the region came
/// from as well as its final inferred value.
- definitions: IndexVec<RegionIndex, RegionDefinition<'tcx>>,
+ definitions: IndexVec<RegionVid, RegionDefinition<'tcx>>,
/// The indices of all "free regions" in scope. These are the
/// lifetime parameters (anonymous and named) declared in the
///
/// These indices will be from 0..N, as it happens, but we collect
/// them into a vector for convenience.
- free_regions: Vec<RegionIndex>,
+ free_regions: Vec<RegionVid>,
/// The constraints we have accumulated and used during solving.
constraints: Vec<Constraint>,
#[derive(Clone, Default, PartialEq, Eq)]
struct Region {
points: BTreeSet<Location>,
- free_regions: BTreeSet<RegionIndex>,
+ free_regions: BTreeSet<RegionVid>,
}
impl fmt::Debug for Region {
self.points.insert(point)
}
- fn add_free_region(&mut self, region: RegionIndex) -> bool {
+ fn add_free_region(&mut self, region: RegionVid) -> bool {
self.free_regions.insert(region)
}
span: Span,
/// The region SUP must outlive SUB...
- sup: RegionIndex,
+ sup: RegionVid,
/// Region that must be outlived.
- sub: RegionIndex,
+ sub: RegionVid,
/// At this location.
point: Location,
}
/// Returns an iterator over all the region indices.
- pub fn regions(&self) -> impl Iterator<Item = RegionIndex> {
+ pub fn regions(&self) -> impl Iterator<Item = RegionVid> {
self.definitions.indices()
}
/// Returns true if the region `r` contains the point `p`.
///
/// Until `solve()` executes, this value is not particularly meaningful.
- pub fn region_contains_point(&self, r: RegionIndex, p: Location) -> bool {
+ pub fn region_contains_point(&self, r: RegionVid, p: Location) -> bool {
self.definitions[r].value.contains_point(p)
}
/// Returns access to the value of `r` for debugging purposes.
- pub(super) fn region_value(&self, r: RegionIndex) -> &fmt::Debug {
+ pub(super) fn region_value(&self, r: RegionVid) -> &fmt::Debug {
&self.definitions[r].value
}
/// Indicates that the region variable `v` is live at the point `point`.
- pub(super) fn add_live_point(&mut self, v: RegionIndex, point: Location) {
+ pub(super) fn add_live_point(&mut self, v: RegionVid, point: Location) {
debug!("add_live_point({:?}, {:?})", v, point);
let definition = &mut self.definitions[v];
if !definition.constant {
pub(super) fn add_outlives(
&mut self,
span: Span,
- sup: RegionIndex,
- sub: RegionIndex,
+ sup: RegionVid,
+ sub: RegionVid,
point: Location,
) {
debug!("add_outlives({:?}: {:?} @ {:?}", sup, sub, point);
fn propagate_constraints(
&mut self,
mir: &Mir<'tcx>,
- ) -> Vec<(RegionIndex, Span, RegionIndex)> {
+ ) -> Vec<(RegionVid, Span, RegionVid)> {
let mut changed = true;
let mut dfs = Dfs::new(mir);
let mut error_regions = FxHashSet();
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: IndexVec<RegionIndex, ty::Region<'tcx>>,
+ free_region_inference_vars: IndexVec<RegionVid, ty::Region<'tcx>>,
arg_count: usize,
}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-use super::RegionIndex;
-use transform::nll::ToRegionIndex;
-use rustc::ty::{self, Ty, TyCtxt};
+use transform::nll::ToRegionVid;
+use rustc::ty::{self, Ty, TyCtxt, RegionVid};
use rustc::ty::relate::{self, Relate, RelateResult, TypeRelation};
pub fn outlives_pairs<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
a: Ty<'tcx>,
b: Ty<'tcx>)
- -> Vec<(RegionIndex, RegionIndex)>
+ -> Vec<(RegionVid, RegionVid)>
{
let mut subtype = Subtype::new(tcx);
match subtype.relate(&a, &b) {
struct Subtype<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
tcx: TyCtxt<'a, 'gcx, 'tcx>,
- outlives_pairs: Vec<(RegionIndex, RegionIndex)>,
+ outlives_pairs: Vec<(RegionVid, RegionVid)>,
ambient_variance: ty::Variance,
}
fn regions(&mut self, r_a: ty::Region<'tcx>, r_b: ty::Region<'tcx>)
-> RelateResult<'tcx, ty::Region<'tcx>> {
- let a = r_a.to_region_index();
- let b = r_b.to_region_index();
+ let a = r_a.to_region_vid();
+ let b = r_b.to_region_vid();
match self.ambient_variance {
ty::Covariant => {