diff options
| author | Niko Matsakis <niko@alum.mit.edu> | 2017-11-06 04:15:38 -0500 |
|---|---|---|
| committer | Niko Matsakis <niko@alum.mit.edu> | 2017-11-16 05:57:45 -0500 |
| commit | 72675d82d7147c7de54f17e59b654d2f046d1cbd (patch) | |
| tree | c7db2a49919ebdd30350a83b4504fcdb84341d0b | |
| parent | 89c1b6009bf99fab4882492c6b9677030227b045 (diff) | |
| download | rust-72675d82d7147c7de54f17e59b654d2f046d1cbd.tar.gz rust-72675d82d7147c7de54f17e59b654d2f046d1cbd.zip | |
replace `RegionIndex` with `RegionVid` (which now impls Idx)
| -rw-r--r-- | src/librustc_mir/dataflow/impls/borrows.rs | 4 | ||||
| -rw-r--r-- | src/librustc_mir/transform/nll/constraint_generation.rs | 12 | ||||
| -rw-r--r-- | src/librustc_mir/transform/nll/free_regions.rs | 10 | ||||
| -rw-r--r-- | src/librustc_mir/transform/nll/mod.rs | 25 | ||||
| -rw-r--r-- | src/librustc_mir/transform/nll/region_infer.rs | 31 | ||||
| -rw-r--r-- | src/librustc_mir/transform/nll/renumber.rs | 3 | ||||
| -rw-r--r-- | src/librustc_mir/transform/nll/subtype.rs | 13 |
7 files changed, 44 insertions, 54 deletions
diff --git a/src/librustc_mir/dataflow/impls/borrows.rs b/src/librustc_mir/dataflow/impls/borrows.rs index 928c07b7fbc..2e4dddc212b 100644 --- a/src/librustc_mir/dataflow/impls/borrows.rs +++ b/src/librustc_mir/dataflow/impls/borrows.rs @@ -22,7 +22,7 @@ use rustc_data_structures::indexed_vec::{IndexVec}; 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; @@ -145,7 +145,7 @@ impl<'a, 'gcx, 'tcx> Borrows<'a, 'gcx, 'tcx> { 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 diff --git a/src/librustc_mir/transform/nll/constraint_generation.rs b/src/librustc_mir/transform/nll/constraint_generation.rs index b095a198d8f..627bc7a8324 100644 --- a/src/librustc_mir/transform/nll/constraint_generation.rs +++ b/src/librustc_mir/transform/nll/constraint_generation.rs @@ -23,7 +23,7 @@ use syntax::codemap::DUMMY_SP; 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>( @@ -102,7 +102,7 @@ impl<'cx, 'gcx, 'tcx> ConstraintGeneration<'cx, '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); }); } @@ -197,8 +197,8 @@ impl<'cx, 'gcx, 'tcx> ConstraintGeneration<'cx, 'gcx, 'tcx> { }; 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()); } @@ -227,8 +227,8 @@ impl<'cx, 'gcx, 'tcx> ConstraintGeneration<'cx, 'gcx, 'tcx> { 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()); } } diff --git a/src/librustc_mir/transform/nll/free_regions.rs b/src/librustc_mir/transform/nll/free_regions.rs index 36c14b55568..101fed3cfa6 100644 --- a/src/librustc_mir/transform/nll/free_regions.rs +++ b/src/librustc_mir/transform/nll/free_regions.rs @@ -25,20 +25,18 @@ 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>, @@ -81,9 +79,9 @@ pub fn free_regions<'a, 'gcx, '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); } diff --git a/src/librustc_mir/transform/nll/mod.rs b/src/librustc_mir/transform/nll/mod.rs index f27d0a8da16..f3e24e92589 100644 --- a/src/librustc_mir/transform/nll/mod.rs +++ b/src/librustc_mir/transform/nll/mod.rs @@ -11,9 +11,8 @@ 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}; @@ -152,23 +151,19 @@ fn dump_mir_results<'a, 'gcx, 'tcx>( }); } -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) } diff --git a/src/librustc_mir/transform/nll/region_infer.rs b/src/librustc_mir/transform/nll/region_infer.rs index f5731255449..add48a9600a 100644 --- a/src/librustc_mir/transform/nll/region_infer.rs +++ b/src/librustc_mir/transform/nll/region_infer.rs @@ -8,11 +8,10 @@ // 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; @@ -21,10 +20,10 @@ use syntax_pos::Span; 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 @@ -35,7 +34,7 @@ pub struct RegionInferenceContext<'tcx> { /// /// 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>, @@ -66,7 +65,7 @@ struct RegionDefinition<'tcx> { #[derive(Clone, Default, PartialEq, Eq)] struct Region { points: BTreeSet<Location>, - free_regions: BTreeSet<RegionIndex>, + free_regions: BTreeSet<RegionVid>, } impl fmt::Debug for Region { @@ -84,7 +83,7 @@ impl 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) } @@ -99,10 +98,10 @@ pub struct Constraint { 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, @@ -198,24 +197,24 @@ impl<'a, 'gcx, 'tcx> RegionInferenceContext<'tcx> { } /// 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 { @@ -231,8 +230,8 @@ impl<'a, 'gcx, 'tcx> RegionInferenceContext<'tcx> { 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); @@ -268,7 +267,7 @@ impl<'a, 'gcx, 'tcx> RegionInferenceContext<'tcx> { 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(); diff --git a/src/librustc_mir/transform/nll/renumber.rs b/src/librustc_mir/transform/nll/renumber.rs index c0d6e0cbe65..7cdcb106c8c 100644 --- a/src/librustc_mir/transform/nll/renumber.rs +++ b/src/librustc_mir/transform/nll/renumber.rs @@ -17,7 +17,6 @@ use rustc::infer::{self as rustc_infer, InferCtxt}; 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 @@ -52,7 +51,7 @@ struct NLLVisitor<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> { 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, } diff --git a/src/librustc_mir/transform/nll/subtype.rs b/src/librustc_mir/transform/nll/subtype.rs index 953fc0eb733..bb41477dcbf 100644 --- a/src/librustc_mir/transform/nll/subtype.rs +++ b/src/librustc_mir/transform/nll/subtype.rs @@ -8,15 +8,14 @@ // 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) { @@ -28,7 +27,7 @@ pub fn outlives_pairs<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>, 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, } @@ -67,8 +66,8 @@ impl<'a, 'gcx, 'tcx> TypeRelation<'a, 'gcx, 'tcx> for Subtype<'a, 'gcx, 'tcx> { 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 => { |
