Skip to content

Commit 72675d8

Browse files
committed
replace RegionIndex with RegionVid (which now impls Idx)
1 parent 89c1b60 commit 72675d8

File tree

7 files changed

+44
-54
lines changed

7 files changed

+44
-54
lines changed

src/librustc_mir/dataflow/impls/borrows.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use rustc_data_structures::indexed_vec::{IndexVec};
2222
use dataflow::{BitDenotation, BlockSets, DataflowOperator};
2323
pub use dataflow::indexes::BorrowIndex;
2424
use transform::nll::region_infer::RegionInferenceContext;
25-
use transform::nll::ToRegionIndex;
25+
use transform::nll::ToRegionVid;
2626

2727
use syntax_pos::Span;
2828

@@ -145,7 +145,7 @@ impl<'a, 'gcx, 'tcx> Borrows<'a, 'gcx, 'tcx> {
145145
location: Location) {
146146
if let Some(regioncx) = self.nonlexical_regioncx {
147147
for (borrow_index, borrow_data) in self.borrows.iter_enumerated() {
148-
let borrow_region = borrow_data.region.to_region_index();
148+
let borrow_region = borrow_data.region.to_region_vid();
149149
if !regioncx.region_contains_point(borrow_region, location) {
150150
// The region checker really considers the borrow
151151
// to start at the point **after** the location of

src/librustc_mir/transform/nll/constraint_generation.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use syntax::codemap::DUMMY_SP;
2323

2424
use super::subtype;
2525
use super::LivenessResults;
26-
use super::ToRegionIndex;
26+
use super::ToRegionVid;
2727
use super::region_infer::RegionInferenceContext;
2828

2929
pub(super) fn generate_constraints<'a, 'gcx, 'tcx>(
@@ -102,7 +102,7 @@ impl<'cx, 'gcx, 'tcx> ConstraintGeneration<'cx, 'gcx, 'tcx> {
102102
self.infcx
103103
.tcx
104104
.for_each_free_region(&live_ty, |live_region| {
105-
let vid = live_region.to_region_index();
105+
let vid = live_region.to_region_vid();
106106
self.regioncx.add_live_point(vid, location);
107107
});
108108
}
@@ -197,8 +197,8 @@ impl<'cx, 'gcx, 'tcx> ConstraintGeneration<'cx, 'gcx, 'tcx> {
197197
};
198198

199199
self.regioncx.add_outlives(span,
200-
borrow_region.to_region_index(),
201-
destination_region.to_region_index(),
200+
borrow_region.to_region_vid(),
201+
destination_region.to_region_vid(),
202202
location.successor_within_block());
203203
}
204204

@@ -227,8 +227,8 @@ impl<'cx, 'gcx, 'tcx> ConstraintGeneration<'cx, 'gcx, 'tcx> {
227227

228228
let span = self.mir.source_info(location).span;
229229
self.regioncx.add_outlives(span,
230-
base_region.to_region_index(),
231-
borrow_region.to_region_index(),
230+
base_region.to_region_vid(),
231+
borrow_region.to_region_vid(),
232232
location.successor_within_block());
233233
}
234234
}

src/librustc_mir/transform/nll/free_regions.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,18 @@
2525
use rustc::hir::def_id::DefId;
2626
use rustc::infer::InferCtxt;
2727
use rustc::middle::free_region::FreeRegionMap;
28-
use rustc::ty;
28+
use rustc::ty::{self, RegionVid};
2929
use rustc::ty::subst::Substs;
3030
use rustc::util::nodemap::FxHashMap;
3131
use rustc_data_structures::indexed_vec::Idx;
3232

33-
use super::RegionIndex;
34-
3533
#[derive(Debug)]
3634
pub struct FreeRegions<'tcx> {
3735
/// Given a free region defined on this function (either early- or
3836
/// late-bound), this maps it to its internal region index. When
3937
/// the region context is created, the first N variables will be
4038
/// created based on these indices.
41-
pub indices: FxHashMap<ty::Region<'tcx>, RegionIndex>,
39+
pub indices: FxHashMap<ty::Region<'tcx>, RegionVid>,
4240

4341
/// The map from the typeck tables telling us how to relate free regions.
4442
pub free_region_map: &'tcx FreeRegionMap<'tcx>,
@@ -81,9 +79,9 @@ pub fn free_regions<'a, 'gcx, 'tcx>(
8179
}
8280

8381
fn insert_free_region<'tcx>(
84-
free_regions: &mut FxHashMap<ty::Region<'tcx>, RegionIndex>,
82+
free_regions: &mut FxHashMap<ty::Region<'tcx>, RegionVid>,
8583
region: ty::Region<'tcx>,
8684
) {
87-
let next = RegionIndex::new(free_regions.len());
85+
let next = RegionVid::new(free_regions.len());
8886
free_regions.entry(region).or_insert(next);
8987
}

src/librustc_mir/transform/nll/mod.rs

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@
1111
use rustc::hir::def_id::DefId;
1212
use rustc::mir::Mir;
1313
use rustc::infer::InferCtxt;
14-
use rustc::ty::{self, RegionKind};
14+
use rustc::ty::{self, RegionKind, RegionVid};
1515
use rustc::util::nodemap::FxHashMap;
16-
use rustc_data_structures::indexed_vec::Idx;
1716
use std::collections::BTreeSet;
1817
use transform::MirSource;
1918
use util::liveness::{self, LivenessMode, LivenessResult, LocalSet};
@@ -152,23 +151,19 @@ fn dump_mir_results<'a, 'gcx, 'tcx>(
152151
});
153152
}
154153

155-
newtype_index!(RegionIndex {
156-
DEBUG_FORMAT = "'_#{}r",
157-
});
158-
159154
/// Right now, we piggy back on the `ReVar` to store our NLL inference
160-
/// regions. These are indexed with `RegionIndex`. This method will
161-
/// assert that the region is a `ReVar` and convert the internal index
162-
/// into a `RegionIndex`. This is reasonable because in our MIR we
163-
/// replace all free regions with inference variables.
164-
pub trait ToRegionIndex {
165-
fn to_region_index(&self) -> RegionIndex;
155+
/// regions. These are indexed with `RegionVid`. This method will
156+
/// assert that the region is a `ReVar` and extract its interal index.
157+
/// This is reasonable because in our MIR we replace all free regions
158+
/// with inference variables.
159+
pub trait ToRegionVid {
160+
fn to_region_vid(&self) -> RegionVid;
166161
}
167162

168-
impl ToRegionIndex for RegionKind {
169-
fn to_region_index(&self) -> RegionIndex {
163+
impl ToRegionVid for RegionKind {
164+
fn to_region_vid(&self) -> RegionVid {
170165
if let &ty::ReVar(vid) = self {
171-
RegionIndex::new(vid.index as usize)
166+
vid
172167
} else {
173168
bug!("region is not an ReVar: {:?}", self)
174169
}

src/librustc_mir/transform/nll/region_infer.rs

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use super::RegionIndex;
1211
use super::free_regions::FreeRegions;
1312
use rustc::infer::InferCtxt;
1413
use rustc::mir::{Location, Mir};
15-
use rustc::ty;
14+
use rustc::ty::{self, RegionVid};
1615
use rustc_data_structures::indexed_vec::IndexVec;
1716
use rustc_data_structures::fx::FxHashSet;
1817
use std::collections::BTreeSet;
@@ -21,10 +20,10 @@ use syntax_pos::Span;
2120

2221
pub struct RegionInferenceContext<'tcx> {
2322
/// Contains the definition for every region variable. Region
24-
/// variables are identified by their index (`RegionIndex`). The
23+
/// variables are identified by their index (`RegionVid`). The
2524
/// definition contains information about where the region came
2625
/// from as well as its final inferred value.
27-
definitions: IndexVec<RegionIndex, RegionDefinition<'tcx>>,
26+
definitions: IndexVec<RegionVid, RegionDefinition<'tcx>>,
2827

2928
/// The indices of all "free regions" in scope. These are the
3029
/// lifetime parameters (anonymous and named) declared in the
@@ -35,7 +34,7 @@ pub struct RegionInferenceContext<'tcx> {
3534
///
3635
/// These indices will be from 0..N, as it happens, but we collect
3736
/// them into a vector for convenience.
38-
free_regions: Vec<RegionIndex>,
37+
free_regions: Vec<RegionVid>,
3938

4039
/// The constraints we have accumulated and used during solving.
4140
constraints: Vec<Constraint>,
@@ -66,7 +65,7 @@ struct RegionDefinition<'tcx> {
6665
#[derive(Clone, Default, PartialEq, Eq)]
6766
struct Region {
6867
points: BTreeSet<Location>,
69-
free_regions: BTreeSet<RegionIndex>,
68+
free_regions: BTreeSet<RegionVid>,
7069
}
7170

7271
impl fmt::Debug for Region {
@@ -84,7 +83,7 @@ impl Region {
8483
self.points.insert(point)
8584
}
8685

87-
fn add_free_region(&mut self, region: RegionIndex) -> bool {
86+
fn add_free_region(&mut self, region: RegionVid) -> bool {
8887
self.free_regions.insert(region)
8988
}
9089

@@ -99,10 +98,10 @@ pub struct Constraint {
9998
span: Span,
10099

101100
/// The region SUP must outlive SUB...
102-
sup: RegionIndex,
101+
sup: RegionVid,
103102

104103
/// Region that must be outlived.
105-
sub: RegionIndex,
104+
sub: RegionVid,
106105

107106
/// At this location.
108107
point: Location,
@@ -198,24 +197,24 @@ impl<'a, 'gcx, 'tcx> RegionInferenceContext<'tcx> {
198197
}
199198

200199
/// Returns an iterator over all the region indices.
201-
pub fn regions(&self) -> impl Iterator<Item = RegionIndex> {
200+
pub fn regions(&self) -> impl Iterator<Item = RegionVid> {
202201
self.definitions.indices()
203202
}
204203

205204
/// Returns true if the region `r` contains the point `p`.
206205
///
207206
/// Until `solve()` executes, this value is not particularly meaningful.
208-
pub fn region_contains_point(&self, r: RegionIndex, p: Location) -> bool {
207+
pub fn region_contains_point(&self, r: RegionVid, p: Location) -> bool {
209208
self.definitions[r].value.contains_point(p)
210209
}
211210

212211
/// Returns access to the value of `r` for debugging purposes.
213-
pub(super) fn region_value(&self, r: RegionIndex) -> &fmt::Debug {
212+
pub(super) fn region_value(&self, r: RegionVid) -> &fmt::Debug {
214213
&self.definitions[r].value
215214
}
216215

217216
/// Indicates that the region variable `v` is live at the point `point`.
218-
pub(super) fn add_live_point(&mut self, v: RegionIndex, point: Location) {
217+
pub(super) fn add_live_point(&mut self, v: RegionVid, point: Location) {
219218
debug!("add_live_point({:?}, {:?})", v, point);
220219
let definition = &mut self.definitions[v];
221220
if !definition.constant {
@@ -231,8 +230,8 @@ impl<'a, 'gcx, 'tcx> RegionInferenceContext<'tcx> {
231230
pub(super) fn add_outlives(
232231
&mut self,
233232
span: Span,
234-
sup: RegionIndex,
235-
sub: RegionIndex,
233+
sup: RegionVid,
234+
sub: RegionVid,
236235
point: Location,
237236
) {
238237
debug!("add_outlives({:?}: {:?} @ {:?}", sup, sub, point);
@@ -268,7 +267,7 @@ impl<'a, 'gcx, 'tcx> RegionInferenceContext<'tcx> {
268267
fn propagate_constraints(
269268
&mut self,
270269
mir: &Mir<'tcx>,
271-
) -> Vec<(RegionIndex, Span, RegionIndex)> {
270+
) -> Vec<(RegionVid, Span, RegionVid)> {
272271
let mut changed = true;
273272
let mut dfs = Dfs::new(mir);
274273
let mut error_regions = FxHashSet();

src/librustc_mir/transform/nll/renumber.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ use rustc::infer::{self as rustc_infer, InferCtxt};
1717
use syntax_pos::DUMMY_SP;
1818
use std::collections::HashMap;
1919

20-
use super::RegionIndex;
2120
use super::free_regions::FreeRegions;
2221

2322
/// Replaces all free regions appearing in the MIR with fresh
@@ -52,7 +51,7 @@ struct NLLVisitor<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> {
5251
num_region_variables: usize,
5352
infcx: &'a InferCtxt<'a, 'gcx, 'tcx>,
5453
free_regions: &'a FreeRegions<'tcx>,
55-
free_region_inference_vars: IndexVec<RegionIndex, ty::Region<'tcx>>,
54+
free_region_inference_vars: IndexVec<RegionVid, ty::Region<'tcx>>,
5655
arg_count: usize,
5756
}
5857

src/librustc_mir/transform/nll/subtype.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,14 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use super::RegionIndex;
12-
use transform::nll::ToRegionIndex;
13-
use rustc::ty::{self, Ty, TyCtxt};
11+
use transform::nll::ToRegionVid;
12+
use rustc::ty::{self, Ty, TyCtxt, RegionVid};
1413
use rustc::ty::relate::{self, Relate, RelateResult, TypeRelation};
1514

1615
pub fn outlives_pairs<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
1716
a: Ty<'tcx>,
1817
b: Ty<'tcx>)
19-
-> Vec<(RegionIndex, RegionIndex)>
18+
-> Vec<(RegionVid, RegionVid)>
2019
{
2120
let mut subtype = Subtype::new(tcx);
2221
match subtype.relate(&a, &b) {
@@ -28,7 +27,7 @@ pub fn outlives_pairs<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
2827

2928
struct Subtype<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
3029
tcx: TyCtxt<'a, 'gcx, 'tcx>,
31-
outlives_pairs: Vec<(RegionIndex, RegionIndex)>,
30+
outlives_pairs: Vec<(RegionVid, RegionVid)>,
3231
ambient_variance: ty::Variance,
3332
}
3433

@@ -67,8 +66,8 @@ impl<'a, 'gcx, 'tcx> TypeRelation<'a, 'gcx, 'tcx> for Subtype<'a, 'gcx, 'tcx> {
6766

6867
fn regions(&mut self, r_a: ty::Region<'tcx>, r_b: ty::Region<'tcx>)
6968
-> RelateResult<'tcx, ty::Region<'tcx>> {
70-
let a = r_a.to_region_index();
71-
let b = r_b.to_region_index();
69+
let a = r_a.to_region_vid();
70+
let b = r_b.to_region_vid();
7271

7372
match self.ambient_variance {
7473
ty::Covariant => {

0 commit comments

Comments
 (0)