Skip to content

Commit c7dc39d

Browse files
committed
intern CodeExtents
Make a `CodeExtent<'tcx>` be something allocated in an arena instead of an index into the `RegionMaps`.
1 parent 55d6066 commit c7dc39d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+729
-743
lines changed

src/librustc/cfg/construct.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -583,10 +583,10 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
583583
scope_id: ast::NodeId,
584584
to_index: CFGIndex) {
585585
let mut data = CFGEdgeData { exiting_scopes: vec![] };
586-
let mut scope = self.tcx.region_maps().node_extent(from_expr.id);
587-
let target_scope = self.tcx.region_maps().node_extent(scope_id);
586+
let mut scope = self.tcx.node_extent(from_expr.id);
587+
let target_scope = self.tcx.node_extent(scope_id);
588588
while scope != target_scope {
589-
data.exiting_scopes.push(scope.node_id(&self.tcx.region_maps()));
589+
data.exiting_scopes.push(scope.node_id());
590590
scope = self.tcx.region_maps().encl_scope(scope);
591591
}
592592
self.graph.add_edge(from_index, to_index, data);

src/librustc/ich/impls_ty.rs

+2-13
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a, 'tcx>> for ty::subst::Kind<'t
3939
}
4040
}
4141

42-
impl<'a, 'tcx> HashStable<StableHashingContext<'a, 'tcx>> for ty::Region {
42+
impl<'a, 'tcx> HashStable<StableHashingContext<'a, 'tcx>> for ty::RegionKind<'tcx> {
4343
fn hash_stable<W: StableHasherResult>(&self,
4444
hcx: &mut StableHashingContext<'a, 'tcx>,
4545
hasher: &mut StableHasher<W>) {
@@ -432,17 +432,6 @@ impl_stable_hash_for!(enum ty::cast::CastKind {
432432
FnPtrAddrCast
433433
});
434434

435-
impl<'a, 'tcx> HashStable<StableHashingContext<'a, 'tcx>> for ::middle::region::CodeExtent
436-
{
437-
fn hash_stable<W: StableHasherResult>(&self,
438-
hcx: &mut StableHashingContext<'a, 'tcx>,
439-
hasher: &mut StableHasher<W>) {
440-
hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
441-
hcx.tcx().region_maps().code_extent_data(*self).hash_stable(hcx, hasher);
442-
});
443-
}
444-
}
445-
446435
impl<'a, 'tcx> HashStable<StableHashingContext<'a, 'tcx>> for ::middle::region::CodeExtentData
447436
{
448437
fn hash_stable<W: StableHasherResult>(&self,
@@ -477,7 +466,7 @@ impl_stable_hash_for!(struct ty::adjustment::CoerceUnsizedInfo {
477466
custom_kind
478467
});
479468

480-
impl_stable_hash_for!(struct ty::FreeRegion {
469+
impl_stable_hash_for!(struct ty::FreeRegion<'tcx> {
481470
scope,
482471
bound_region
483472
});

src/librustc/infer/combine.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ impl<'cx, 'gcx, 'tcx> ty::fold::TypeFolder<'gcx, 'tcx> for Generalizer<'cx, 'gcx
315315
}
316316
}
317317

318-
fn fold_region(&mut self, r: &'tcx ty::Region) -> &'tcx ty::Region {
318+
fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
319319
match *r {
320320
// Never make variables for regions bound within the type itself,
321321
// nor for erased regions.

src/librustc/infer/equate.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ impl<'combine, 'infcx, 'gcx, 'tcx> TypeRelation<'infcx, 'gcx, 'tcx>
7878
}
7979
}
8080

81-
fn regions(&mut self, a: &'tcx ty::Region, b: &'tcx ty::Region)
82-
-> RelateResult<'tcx, &'tcx ty::Region> {
81+
fn regions(&mut self, a: ty::Region<'tcx>, b: ty::Region<'tcx>)
82+
-> RelateResult<'tcx, ty::Region<'tcx>> {
8383
debug!("{}.regions({:?}, {:?})",
8484
self.tag(),
8585
a,

src/librustc/infer/error_reporting/mod.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
7979
pub fn note_and_explain_region(self,
8080
err: &mut DiagnosticBuilder,
8181
prefix: &str,
82-
region: &'tcx ty::Region,
82+
region: ty::Region<'tcx>,
8383
suffix: &str) {
8484
fn item_scope_tag(item: &hir::Item) -> &'static str {
8585
match item.node {
@@ -124,14 +124,14 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
124124
format!("{}unknown scope: {:?}{}. Please report a bug.",
125125
prefix, scope, suffix)
126126
};
127-
let span = match scope.span(&self.region_maps(), &self.hir) {
127+
let span = match scope.span(&self.hir) {
128128
Some(s) => s,
129129
None => {
130130
err.note(&unknown_scope());
131131
return;
132132
}
133133
};
134-
let tag = match self.hir.find(scope.node_id(&self.region_maps())) {
134+
let tag = match self.hir.find(scope.node_id()) {
135135
Some(hir_map::NodeBlock(_)) => "block",
136136
Some(hir_map::NodeExpr(expr)) => match expr.node {
137137
hir::ExprCall(..) => "call",
@@ -151,7 +151,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
151151
return;
152152
}
153153
};
154-
let scope_decorated_tag = match self.region_maps().code_extent_data(scope) {
154+
let scope_decorated_tag = match *scope {
155155
region::CodeExtentData::Misc(_) => tag,
156156
region::CodeExtentData::CallSiteScope { .. } => {
157157
"scope of call-site for function"
@@ -184,7 +184,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
184184
}
185185
};
186186

187-
let node = fr.scope.map(|s| s.node_id(&self.region_maps()))
187+
let node = fr.scope.map(|s| s.node_id())
188188
.unwrap_or(DUMMY_NODE_ID);
189189
let unknown;
190190
let tag = match self.hir.find(node) {
@@ -517,7 +517,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
517517
values.1.push_normal("<");
518518
}
519519

520-
fn lifetime_display(lifetime: &Region) -> String {
520+
fn lifetime_display(lifetime: Region) -> String {
521521
let s = format!("{}", lifetime);
522522
if s.is_empty() {
523523
"'_".to_string()
@@ -769,7 +769,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
769769
fn report_generic_bound_failure(&self,
770770
origin: SubregionOrigin<'tcx>,
771771
bound_kind: GenericKind<'tcx>,
772-
sub: &'tcx Region)
772+
sub: Region<'tcx>)
773773
{
774774
// FIXME: it would be better to report the first error message
775775
// with the span of the parameter itself, rather than the span
@@ -848,9 +848,9 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
848848
fn report_sub_sup_conflict(&self,
849849
var_origin: RegionVariableOrigin,
850850
sub_origin: SubregionOrigin<'tcx>,
851-
sub_region: &'tcx Region,
851+
sub_region: Region<'tcx>,
852852
sup_origin: SubregionOrigin<'tcx>,
853-
sup_region: &'tcx Region) {
853+
sup_region: Region<'tcx>) {
854854
let mut err = self.report_inference_failure(var_origin);
855855

856856
self.tcx.note_and_explain_region(&mut err,

src/librustc/infer/error_reporting/note.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
146146

147147
pub(super) fn report_concrete_failure(&self,
148148
origin: SubregionOrigin<'tcx>,
149-
sub: &'tcx Region,
150-
sup: &'tcx Region)
149+
sub: Region<'tcx>,
150+
sup: Region<'tcx>)
151151
-> DiagnosticBuilder<'tcx> {
152152
match origin {
153153
infer::Subtype(trace) => {

src/librustc/infer/freshen.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for TypeFreshener<'a, 'gcx, 'tcx> {
8383
self.infcx.tcx
8484
}
8585

86-
fn fold_region(&mut self, r: &'tcx ty::Region) -> &'tcx ty::Region {
86+
fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
8787
match *r {
8888
ty::ReEarlyBound(..) |
8989
ty::ReLateBound(..) => {

src/librustc/infer/fudge.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for RegionFudger<'a, 'gcx, 'tcx> {
147147
}
148148
}
149149

150-
fn fold_region(&mut self, r: &'tcx ty::Region) -> &'tcx ty::Region {
150+
fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
151151
match *r {
152152
ty::ReVar(v) if self.region_vars.contains(&v) => {
153153
self.infcx.next_region_var(self.origin.clone())

src/librustc/infer/glb.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ impl<'combine, 'infcx, 'gcx, 'tcx> TypeRelation<'infcx, 'gcx, 'tcx>
5959
lattice::super_lattice_tys(self, a, b)
6060
}
6161

62-
fn regions(&mut self, a: &'tcx ty::Region, b: &'tcx ty::Region)
63-
-> RelateResult<'tcx, &'tcx ty::Region> {
62+
fn regions(&mut self, a: ty::Region<'tcx>, b: ty::Region<'tcx>)
63+
-> RelateResult<'tcx, ty::Region<'tcx>> {
6464
debug!("{}.regions({:?}, {:?})",
6565
self.tag(),
6666
a,

src/librustc/infer/higher_ranked/mod.rs

+16-16
Original file line numberDiff line numberDiff line change
@@ -269,9 +269,9 @@ impl<'a, 'gcx, 'tcx> CombineFields<'a, 'gcx, 'tcx> {
269269
snapshot: &CombinedSnapshot,
270270
debruijn: ty::DebruijnIndex,
271271
new_vars: &[ty::RegionVid],
272-
a_map: &FxHashMap<ty::BoundRegion, &'tcx ty::Region>,
273-
r0: &'tcx ty::Region)
274-
-> &'tcx ty::Region {
272+
a_map: &FxHashMap<ty::BoundRegion, ty::Region<'tcx>>,
273+
r0: ty::Region<'tcx>)
274+
-> ty::Region<'tcx> {
275275
// Regions that pre-dated the LUB computation stay as they are.
276276
if !is_var_in_set(new_vars, r0) {
277277
assert!(!r0.is_bound());
@@ -284,7 +284,7 @@ impl<'a, 'gcx, 'tcx> CombineFields<'a, 'gcx, 'tcx> {
284284
// Variables created during LUB computation which are
285285
// *related* to regions that pre-date the LUB computation
286286
// stay as they are.
287-
if !tainted.iter().all(|r| is_var_in_set(new_vars, *r)) {
287+
if !tainted.iter().all(|&r| is_var_in_set(new_vars, r)) {
288288
debug!("generalize_region(r0={:?}): \
289289
non-new-variables found in {:?}",
290290
r0, tainted);
@@ -365,11 +365,11 @@ impl<'a, 'gcx, 'tcx> CombineFields<'a, 'gcx, 'tcx> {
365365
snapshot: &CombinedSnapshot,
366366
debruijn: ty::DebruijnIndex,
367367
new_vars: &[ty::RegionVid],
368-
a_map: &FxHashMap<ty::BoundRegion, &'tcx ty::Region>,
368+
a_map: &FxHashMap<ty::BoundRegion, ty::Region<'tcx>>,
369369
a_vars: &[ty::RegionVid],
370370
b_vars: &[ty::RegionVid],
371-
r0: &'tcx ty::Region)
372-
-> &'tcx ty::Region {
371+
r0: ty::Region<'tcx>)
372+
-> ty::Region<'tcx> {
373373
if !is_var_in_set(new_vars, r0) {
374374
assert!(!r0.is_bound());
375375
return r0;
@@ -434,8 +434,8 @@ impl<'a, 'gcx, 'tcx> CombineFields<'a, 'gcx, 'tcx> {
434434

435435
fn rev_lookup<'a, 'gcx, 'tcx>(infcx: &InferCtxt<'a, 'gcx, 'tcx>,
436436
span: Span,
437-
a_map: &FxHashMap<ty::BoundRegion, &'tcx ty::Region>,
438-
r: &'tcx ty::Region) -> &'tcx ty::Region
437+
a_map: &FxHashMap<ty::BoundRegion, ty::Region<'tcx>>,
438+
r: ty::Region<'tcx>) -> ty::Region<'tcx>
439439
{
440440
for (a_br, a_r) in a_map {
441441
if *a_r == r {
@@ -450,14 +450,14 @@ impl<'a, 'gcx, 'tcx> CombineFields<'a, 'gcx, 'tcx> {
450450

451451
fn fresh_bound_variable<'a, 'gcx, 'tcx>(infcx: &InferCtxt<'a, 'gcx, 'tcx>,
452452
debruijn: ty::DebruijnIndex)
453-
-> &'tcx ty::Region {
453+
-> ty::Region<'tcx> {
454454
infcx.region_vars.new_bound(debruijn)
455455
}
456456
}
457457
}
458458

459459
fn var_ids<'a, 'gcx, 'tcx>(fields: &CombineFields<'a, 'gcx, 'tcx>,
460-
map: &FxHashMap<ty::BoundRegion, &'tcx ty::Region>)
460+
map: &FxHashMap<ty::BoundRegion, ty::Region<'tcx>>)
461461
-> Vec<ty::RegionVid> {
462462
map.iter()
463463
.map(|(_, &r)| match *r {
@@ -472,7 +472,7 @@ fn var_ids<'a, 'gcx, 'tcx>(fields: &CombineFields<'a, 'gcx, 'tcx>,
472472
.collect()
473473
}
474474

475-
fn is_var_in_set(new_vars: &[ty::RegionVid], r: &ty::Region) -> bool {
475+
fn is_var_in_set(new_vars: &[ty::RegionVid], r: ty::Region) -> bool {
476476
match *r {
477477
ty::ReVar(ref v) => new_vars.iter().any(|x| x == v),
478478
_ => false
@@ -484,7 +484,7 @@ fn fold_regions_in<'a, 'gcx, 'tcx, T, F>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
484484
mut fldr: F)
485485
-> T
486486
where T: TypeFoldable<'tcx>,
487-
F: FnMut(&'tcx ty::Region, ty::DebruijnIndex) -> &'tcx ty::Region,
487+
F: FnMut(ty::Region<'tcx>, ty::DebruijnIndex) -> ty::Region<'tcx>,
488488
{
489489
tcx.fold_regions(unbound_value, &mut false, |region, current_depth| {
490490
// we should only be encountering "escaping" late-bound regions here,
@@ -502,9 +502,9 @@ fn fold_regions_in<'a, 'gcx, 'tcx, T, F>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
502502
impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
503503
fn tainted_regions(&self,
504504
snapshot: &CombinedSnapshot,
505-
r: &'tcx ty::Region,
505+
r: ty::Region<'tcx>,
506506
directions: TaintDirections)
507-
-> FxHashSet<&'tcx ty::Region> {
507+
-> FxHashSet<ty::Region<'tcx>> {
508508
self.region_vars.tainted(&snapshot.region_vars_snapshot, r, directions)
509509
}
510510

@@ -731,7 +731,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
731731
// region back to the `ty::BoundRegion` that it originally
732732
// represented. Because `leak_check` passed, we know that
733733
// these taint sets are mutually disjoint.
734-
let inv_skol_map: FxHashMap<&'tcx ty::Region, ty::BoundRegion> =
734+
let inv_skol_map: FxHashMap<ty::Region<'tcx>, ty::BoundRegion> =
735735
skol_map
736736
.iter()
737737
.flat_map(|(&skol_br, &skol)| {

src/librustc/infer/lub.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ impl<'combine, 'infcx, 'gcx, 'tcx> TypeRelation<'infcx, 'gcx, 'tcx>
5959
lattice::super_lattice_tys(self, a, b)
6060
}
6161

62-
fn regions(&mut self, a: &'tcx ty::Region, b: &'tcx ty::Region)
63-
-> RelateResult<'tcx, &'tcx ty::Region> {
62+
fn regions(&mut self, a: ty::Region<'tcx>, b: ty::Region<'tcx>)
63+
-> RelateResult<'tcx, ty::Region<'tcx>> {
6464
debug!("{}.regions({:?}, {:?})",
6565
self.tag(),
6666
a,

src/librustc/infer/mod.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ pub struct InferCtxt<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
205205

206206
/// A map returned by `skolemize_late_bound_regions()` indicating the skolemized
207207
/// region that each late-bound region was replaced with.
208-
pub type SkolemizationMap<'tcx> = FxHashMap<ty::BoundRegion, &'tcx ty::Region>;
208+
pub type SkolemizationMap<'tcx> = FxHashMap<ty::BoundRegion, ty::Region<'tcx>>;
209209

210210
/// See `error_reporting` module for more details
211211
#[derive(Clone, Debug)]
@@ -1008,7 +1008,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
10081008
}
10091009

10101010
pub fn add_given(&self,
1011-
sub: ty::FreeRegion,
1011+
sub: ty::FreeRegion<'tcx>,
10121012
sup: ty::RegionVid)
10131013
{
10141014
self.region_vars.add_given(sub, sup);
@@ -1107,8 +1107,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
11071107

11081108
pub fn sub_regions(&self,
11091109
origin: SubregionOrigin<'tcx>,
1110-
a: &'tcx ty::Region,
1111-
b: &'tcx ty::Region) {
1110+
a: ty::Region<'tcx>,
1111+
b: ty::Region<'tcx>) {
11121112
debug!("sub_regions({:?} <: {:?})", a, b);
11131113
self.region_vars.make_subregion(origin, a, b);
11141114
}
@@ -1210,7 +1210,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
12101210
}
12111211

12121212
pub fn next_region_var(&self, origin: RegionVariableOrigin)
1213-
-> &'tcx ty::Region {
1213+
-> ty::Region<'tcx> {
12141214
self.tcx.mk_region(ty::ReVar(self.region_vars.new_region_var(origin)))
12151215
}
12161216

@@ -1219,7 +1219,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
12191219
pub fn region_var_for_def(&self,
12201220
span: Span,
12211221
def: &ty::RegionParameterDef)
1222-
-> &'tcx ty::Region {
1222+
-> ty::Region<'tcx> {
12231223
self.next_region_var(EarlyBoundRegion(span, def.name, def.issue_32330))
12241224
}
12251225

@@ -1270,7 +1270,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
12701270
})
12711271
}
12721272

1273-
pub fn fresh_bound_region(&self, debruijn: ty::DebruijnIndex) -> &'tcx ty::Region {
1273+
pub fn fresh_bound_region(&self, debruijn: ty::DebruijnIndex) -> ty::Region<'tcx> {
12741274
self.region_vars.new_bound(debruijn)
12751275
}
12761276

@@ -1322,7 +1322,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
13221322
}
13231323

13241324
pub fn resolve_regions_and_report_errors(&self,
1325-
free_regions: &FreeRegionMap,
1325+
free_regions: &FreeRegionMap<'tcx>,
13261326
subject_node_id: ast::NodeId) {
13271327
let errors = self.region_vars.resolve_regions(free_regions, subject_node_id);
13281328
if !self.is_tainted_by_errors() {
@@ -1531,7 +1531,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
15311531
span: Span,
15321532
lbrct: LateBoundRegionConversionTime,
15331533
value: &ty::Binder<T>)
1534-
-> (T, FxHashMap<ty::BoundRegion, &'tcx ty::Region>)
1534+
-> (T, FxHashMap<ty::BoundRegion, ty::Region<'tcx>>)
15351535
where T : TypeFoldable<'tcx>
15361536
{
15371537
self.tcx.replace_late_bound_regions(
@@ -1577,7 +1577,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
15771577
pub fn verify_generic_bound(&self,
15781578
origin: SubregionOrigin<'tcx>,
15791579
kind: GenericKind<'tcx>,
1580-
a: &'tcx ty::Region,
1580+
a: ty::Region<'tcx>,
15811581
bound: VerifyBound<'tcx>) {
15821582
debug!("verify_generic_bound({:?}, {:?} <: {:?})",
15831583
kind,

0 commit comments

Comments
 (0)