Skip to content

Commit 65e9bc0

Browse files
Ariel Ben-Yehudaarielb1
authored andcommitted
store the CodeExtent directly in FreeRegion
this makes the code cleaner
1 parent fc30438 commit 65e9bc0

File tree

16 files changed

+36
-55
lines changed

16 files changed

+36
-55
lines changed

src/librustc/metadata/tydecode.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ impl<'a,'tcx> TyDecoder<'a,'tcx> {
225225
}
226226
'f' => {
227227
assert_eq!(self.next(), '[');
228-
let scope = self.parse_destruction_scope_data();
228+
let scope = self.parse_scope();
229229
assert_eq!(self.next(), '|');
230230
let br = self.parse_bound_region();
231231
assert_eq!(self.next(), ']');
@@ -284,11 +284,6 @@ impl<'a,'tcx> TyDecoder<'a,'tcx> {
284284
})
285285
}
286286

287-
fn parse_destruction_scope_data(&mut self) -> region::DestructionScopeData {
288-
let node_id = self.parse_uint() as ast::NodeId;
289-
region::DestructionScopeData::new(node_id)
290-
}
291-
292287
fn parse_opt<T, F>(&mut self, f: F) -> Option<T>
293288
where F: FnOnce(&mut TyDecoder<'a, 'tcx>) -> T,
294289
{

src/librustc/metadata/tyencode.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ pub fn enc_region(w: &mut Encoder, cx: &ctxt, r: ty::Region) {
255255
}
256256
ty::ReFree(ref fr) => {
257257
mywrite!(w, "f[");
258-
enc_destruction_scope_data(w, fr.scope);
258+
enc_scope(w, cx, fr.scope);
259259
mywrite!(w, "|");
260260
enc_bound_region(w, cx, fr.bound_region);
261261
mywrite!(w, "]");
@@ -289,11 +289,6 @@ fn enc_scope(w: &mut Encoder, cx: &ctxt, scope: region::CodeExtent) {
289289
}
290290
}
291291

292-
fn enc_destruction_scope_data(w: &mut Encoder,
293-
d: region::DestructionScopeData) {
294-
mywrite!(w, "{}", d.node_id);
295-
}
296-
297292
fn enc_bound_region(w: &mut Encoder, cx: &ctxt, br: ty::BoundRegion) {
298293
match br {
299294
ty::BrAnon(idx) => {

src/librustc/middle/free_region.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,7 @@ impl FreeRegionMap {
135135
tcx.region_maps.is_subscope_of(sub_scope, super_scope),
136136

137137
(ty::ReScope(sub_scope), ty::ReFree(fr)) =>
138-
tcx.region_maps.is_subscope_of(sub_scope,
139-
fr.scope.to_code_extent(&tcx.region_maps)) ||
138+
tcx.region_maps.is_subscope_of(sub_scope, fr.scope) ||
140139
self.is_static(fr),
141140

142141
(ty::ReFree(sub_fr), ty::ReFree(super_fr)) =>

src/librustc/middle/infer/error_reporting.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ impl<'tcx> ty::ctxt<'tcx> {
172172
}
173173
};
174174

175-
match self.map.find(fr.scope.node_id) {
175+
match self.map.find(fr.scope.node_id(&self.region_maps)) {
176176
Some(ast_map::NodeBlock(ref blk)) => {
177177
let (msg, opt_span) = explain_span(self, "block", blk.span);
178178
(format!("{} {}", prefix, msg), opt_span)
@@ -183,7 +183,8 @@ impl<'tcx> ty::ctxt<'tcx> {
183183
(format!("{} {}", prefix, msg), opt_span)
184184
}
185185
Some(_) | None => {
186-
// this really should not happen
186+
// this really should not happen, but it does:
187+
// FIXME(#27942)
187188
(format!("{} unknown free region bounded by scope {:?}",
188189
prefix, fr.scope), None)
189190
}
@@ -422,7 +423,7 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
422423
return None
423424
}
424425
assert!(fr1.scope == fr2.scope);
425-
(fr1.scope.node_id, fr1, fr2)
426+
(fr1.scope.node_id(&tcx.region_maps), fr1, fr2)
426427
},
427428
_ => return None
428429
};

src/librustc/middle/infer/region_inference/mod.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -790,10 +790,9 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
790790
// A "free" region can be interpreted as "some region
791791
// at least as big as the block fr.scope_id". So, we can
792792
// reasonably compare free regions and scopes:
793-
let fr_scope = fr.scope.to_code_extent(&self.tcx.region_maps);
794-
let r_id = self.tcx.region_maps.nearest_common_ancestor(fr_scope, s_id);
793+
let r_id = self.tcx.region_maps.nearest_common_ancestor(fr.scope, s_id);
795794

796-
if r_id == fr_scope {
795+
if r_id == fr.scope {
797796
// if the free region's scope `fr.scope_id` is bigger than
798797
// the scope region `s_id`, then the LUB is the free
799798
// region itself:
@@ -871,8 +870,7 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
871870
// than the scope `s_id`, then we can say that the GLB
872871
// is the scope `s_id`. Otherwise, as we do not know
873872
// big the free region is precisely, the GLB is undefined.
874-
let fr_scope = fr.scope.to_code_extent(&self.tcx.region_maps);
875-
if self.tcx.region_maps.nearest_common_ancestor(fr_scope, s_id) == fr_scope ||
873+
if self.tcx.region_maps.nearest_common_ancestor(fr.scope, s_id) == fr.scope ||
876874
free_regions.is_static(fr) {
877875
Ok(s)
878876
} else {
@@ -927,8 +925,7 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
927925
Ok(ty::ReFree(*b))
928926
} else {
929927
this.intersect_scopes(ty::ReFree(*a), ty::ReFree(*b),
930-
a.scope.to_code_extent(&this.tcx.region_maps),
931-
b.scope.to_code_extent(&this.tcx.region_maps))
928+
a.scope, b.scope)
932929
}
933930
}
934931
}

src/librustc/middle/liveness.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ use self::VarKind::*;
111111

112112
use middle::def::*;
113113
use middle::pat_util;
114-
use middle::region;
115114
use middle::ty;
116115
use lint;
117116
use util::nodemap::NodeMap;
@@ -1509,7 +1508,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
15091508
// within the fn body, late-bound regions are liberated:
15101509
let fn_ret =
15111510
self.ir.tcx.liberate_late_bound_regions(
1512-
region::DestructionScopeData::new(body.id),
1511+
self.ir.tcx.region_maps.item_extent(body.id),
15131512
&self.fn_ret(id));
15141513

15151514
match fn_ret {

src/librustc/middle/mem_categorization.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ use middle::def_id::DefId;
7777
use middle::infer;
7878
use middle::check_const;
7979
use middle::def;
80-
use middle::region;
8180
use middle::ty::{self, Ty};
8281

8382
use syntax::ast::{MutImmutable, MutMutable};
@@ -749,7 +748,7 @@ impl<'t, 'a,'tcx> MemCategorizationContext<'t, 'a, 'tcx> {
749748
// The environment of a closure is guaranteed to
750749
// outlive any bindings introduced in the body of the
751750
// closure itself.
752-
scope: region::DestructionScopeData::new(fn_body_id),
751+
scope: self.tcx().region_maps.item_extent(fn_body_id),
753752
bound_region: ty::BrEnv
754753
});
755754

src/librustc/middle/region.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,13 @@ impl RegionMaps {
309309
pub fn lookup_code_extent(&self, e: CodeExtentData) -> CodeExtent {
310310
self.code_extent_interner.borrow()[&e]
311311
}
312+
pub fn node_extent(&self, n: ast::NodeId) -> CodeExtent {
313+
self.lookup_code_extent(CodeExtentData::Misc(n))
314+
}
315+
// Returns the code extent for an item - the destruction scope.
316+
pub fn item_extent(&self, n: ast::NodeId) -> CodeExtent {
317+
self.lookup_code_extent(CodeExtentData::DestructionScope(n))
318+
}
312319
pub fn intern_code_extent(&self,
313320
e: CodeExtentData,
314321
parent: CodeExtent) -> CodeExtent {
@@ -350,9 +357,6 @@ impl RegionMaps {
350357
parent: CodeExtent) -> CodeExtent {
351358
self.intern_code_extent(CodeExtentData::Misc(n), parent)
352359
}
353-
pub fn node_extent(&self, n: ast::NodeId) -> CodeExtent {
354-
self.lookup_code_extent(CodeExtentData::Misc(n))
355-
}
356360
pub fn code_extent_data(&self, e: CodeExtent) -> CodeExtentData {
357361
self.code_extents.borrow()[e.0 as usize]
358362
}

src/librustc/middle/ty.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1679,7 +1679,7 @@ impl Region {
16791679
/// A "free" region `fr` can be interpreted as "some region
16801680
/// at least as big as the scope `fr.scope`".
16811681
pub struct FreeRegion {
1682-
pub scope: region::DestructionScopeData,
1682+
pub scope: region::CodeExtent,
16831683
pub bound_region: BoundRegion
16841684
}
16851685

@@ -6610,7 +6610,7 @@ impl<'tcx> ctxt<'tcx> {
66106610
types.push(def.space, self.mk_param_from_def(def));
66116611
}
66126612

6613-
let free_id_outlive = region::DestructionScopeData::new(free_id);
6613+
let free_id_outlive = self.region_maps.item_extent(free_id);
66146614

66156615
// map bound 'a => free 'a
66166616
let mut regions = VecPerParamSpace::empty();
@@ -6641,7 +6641,7 @@ impl<'tcx> ctxt<'tcx> {
66416641
//
66426642

66436643
let free_substs = self.construct_free_substs(generics, free_id);
6644-
let free_id_outlive = region::DestructionScopeData::new(free_id);
6644+
let free_id_outlive = self.region_maps.item_extent(free_id);
66456645

66466646
//
66476647
// Compute the bounds on Self and the type parameters.
@@ -6673,8 +6673,7 @@ impl<'tcx> ctxt<'tcx> {
66736673
let unnormalized_env = ty::ParameterEnvironment {
66746674
tcx: self,
66756675
free_substs: free_substs,
6676-
implicit_region_bound: ty::ReScope(
6677-
free_id_outlive.to_code_extent(&self.region_maps)),
6676+
implicit_region_bound: ty::ReScope(free_id_outlive),
66786677
caller_bounds: predicates,
66796678
selection_cache: traits::SelectionCache::new(),
66806679
free_id: free_id,
@@ -6838,7 +6837,7 @@ impl<'tcx> ctxt<'tcx> {
68386837
/// Replace any late-bound regions bound in `value` with free variants attached to scope-id
68396838
/// `scope_id`.
68406839
pub fn liberate_late_bound_regions<T>(&self,
6841-
all_outlive_scope: region::DestructionScopeData,
6840+
all_outlive_scope: region::CodeExtent,
68426841
value: &Binder<T>)
68436842
-> T
68446843
where T : TypeFoldable<'tcx>

src/librustc_borrowck/borrowck/gather_loans/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -360,9 +360,7 @@ impl<'a, 'tcx> GatherLoanCtxt<'a, 'tcx> {
360360
let loan_scope = match loan_region {
361361
ty::ReScope(scope) => scope,
362362

363-
ty::ReFree(ref fr) => {
364-
fr.scope.to_code_extent(&self.tcx().region_maps)
365-
}
363+
ty::ReFree(ref fr) => fr.scope,
366364

367365
ty::ReStatic => {
368366
// If we get here, an error must have been

0 commit comments

Comments
 (0)