Skip to content

Commit 6d4c214

Browse files
committed
rustc: use DefId instead of CodeExtent for FreeRegion's scope.
1 parent 72aab7a commit 6d4c214

32 files changed

+149
-234
lines changed

src/librustc/ich/impls_ty.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -409,11 +409,6 @@ impl_stable_hash_for!(enum ::middle::resolve_lifetime::Region {
409409
Free(call_site_scope_data, decl)
410410
});
411411

412-
impl_stable_hash_for!(struct ::middle::region::CallSiteScopeData {
413-
fn_id,
414-
body_id
415-
});
416-
417412
impl_stable_hash_for!(struct ty::DebruijnIndex {
418413
depth
419414
});
@@ -466,7 +461,7 @@ impl_stable_hash_for!(struct ty::adjustment::CoerceUnsizedInfo {
466461
custom_kind
467462
});
468463

469-
impl_stable_hash_for!(struct ty::FreeRegion<'tcx> {
464+
impl_stable_hash_for!(struct ty::FreeRegion {
470465
scope,
471466
bound_region
472467
});

src/librustc/infer/error_reporting/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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())
187+
let node = self.hir.as_local_node_id(fr.scope)
188188
.unwrap_or(DUMMY_NODE_ID);
189189
let unknown;
190190
let tag = match self.hir.find(node) {

src/librustc/infer/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1009,7 +1009,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
10091009
}
10101010

10111011
pub fn add_given(&self,
1012-
sub: ty::FreeRegion<'tcx>,
1012+
sub: ty::FreeRegion,
10131013
sup: ty::RegionVid)
10141014
{
10151015
self.region_vars.add_given(sub, sup);

src/librustc/infer/region_inference/mod.rs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ pub enum UndoLogEntry<'tcx> {
127127
AddVerify(usize),
128128

129129
/// We added the given `given`
130-
AddGiven(ty::FreeRegion<'tcx>, ty::RegionVid),
130+
AddGiven(ty::FreeRegion, ty::RegionVid),
131131

132132
/// We added a GLB/LUB "combinaton variable"
133133
AddCombination(CombineMapType, TwoRegions<'tcx>),
@@ -213,7 +213,7 @@ pub struct RegionVarBindings<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
213213
// record the fact that `'a <= 'b` is implied by the fn signature,
214214
// and then ignore the constraint when solving equations. This is
215215
// a bit of a hack but seems to work.
216-
givens: RefCell<FxHashSet<(ty::FreeRegion<'tcx>, ty::RegionVid)>>,
216+
givens: RefCell<FxHashSet<(ty::FreeRegion, ty::RegionVid)>>,
217217

218218
lubs: RefCell<CombineMap<'tcx>>,
219219
glbs: RefCell<CombineMap<'tcx>>,
@@ -661,7 +661,7 @@ impl<'a, 'gcx, 'tcx> RegionVarBindings<'a, 'gcx, 'tcx> {
661661
}
662662
}
663663

664-
pub fn add_given(&self, sub: ty::FreeRegion<'tcx>, sup: ty::RegionVid) {
664+
pub fn add_given(&self, sub: ty::FreeRegion, sup: ty::RegionVid) {
665665
// cannot add givens once regions are resolved
666666
assert!(self.values_are_none());
667667

@@ -931,19 +931,18 @@ impl<'a, 'gcx, 'tcx> RegionVarBindings<'a, 'gcx, 'tcx> {
931931
b);
932932
}
933933

934-
(&ReFree(fr), &ReScope(s_id)) |
935-
(&ReScope(s_id), &ReFree(fr)) => {
934+
(&ReFree(ref fr), &ReScope(s_id)) |
935+
(&ReScope(s_id), &ReFree(ref fr)) => {
936936
// A "free" region can be interpreted as "some region
937-
// at least as big as the block fr.scope_id". So, we can
937+
// at least as big as fr.scope". So, we can
938938
// reasonably compare free regions and scopes:
939-
if let Some(fr_scope) = fr.scope {
940-
let r_id = region_rels.region_maps.nearest_common_ancestor(fr_scope, s_id);
941-
if r_id == fr_scope {
942-
// if the free region's scope `fr.scope_id` is bigger than
943-
// the scope region `s_id`, then the LUB is the free
944-
// region itself:
945-
return self.tcx.mk_region(ReFree(fr));
946-
}
939+
let fr_scope = region_rels.region_maps.free_extent(self.tcx, fr);
940+
let r_id = region_rels.region_maps.nearest_common_ancestor(fr_scope, s_id);
941+
if r_id == fr_scope {
942+
// if the free region's scope `fr.scope` is bigger than
943+
// the scope region `s_id`, then the LUB is the free
944+
// region itself:
945+
return self.tcx.mk_region(ReFree(*fr));
947946
}
948947

949948
// otherwise, we don't know what the free region is,

src/librustc/middle/free_region.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,9 @@ impl<'a, 'gcx, 'tcx> RegionRelations<'a, 'gcx, 'tcx> {
7171
(&ty::ReScope(sub_scope), &ty::ReScope(super_scope)) =>
7272
self.region_maps.is_subscope_of(sub_scope, super_scope),
7373

74-
(&ty::ReScope(sub_scope), &ty::ReFree(fr)) => {
75-
// 1. It is safe to unwrap `fr.scope` because we
76-
// should only ever wind up comparing against
77-
// `ReScope` in the context of a method or
78-
// body, where `fr.scope` should be `Some`.
79-
self.region_maps.is_subscope_of(sub_scope, fr.scope.unwrap() /*1*/) ||
74+
(&ty::ReScope(sub_scope), &ty::ReFree(ref fr)) => {
75+
let fr_scope = self.region_maps.free_extent(self.tcx, fr);
76+
self.region_maps.is_subscope_of(sub_scope, fr_scope) ||
8077
self.is_static(super_region)
8178
}
8279

src/librustc/middle/liveness.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1440,9 +1440,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
14401440
// within the fn body, late-bound regions are liberated
14411441
// and must outlive the *call-site* of the function.
14421442
let fn_ret =
1443-
self.ir.tcx.liberate_late_bound_regions(
1444-
Some(self.ir.tcx.call_site_extent(id)),
1445-
&fn_ret);
1443+
self.ir.tcx.liberate_late_bound_regions(def_id, &fn_ret);
14461444

14471445
if !fn_ret.is_never() && self.live_on_entry(entry_ln, self.s.no_ret_var).is_some() {
14481446
let param_env = self.ir.tcx.parameter_environment(def_id);

src/librustc/middle/mem_categorization.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
790790
// The environment of a closure is guaranteed to
791791
// outlive any bindings introduced in the body of the
792792
// closure itself.
793-
scope: Some(self.tcx().call_site_extent(upvar_id.closure_expr_id)),
793+
scope: self.tcx().hir.local_def_id(upvar_id.closure_expr_id),
794794
bound_region: ty::BrEnv
795795
}));
796796

src/librustc/middle/region.rs

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -120,23 +120,6 @@ pub enum CodeExtentData {
120120
Remainder(BlockRemainder)
121121
}
122122

123-
/// extent of call-site for a function/method.
124-
#[derive(Clone, PartialEq, PartialOrd, Eq, Ord, Hash, RustcEncodable,
125-
RustcDecodable, Debug, Copy)]
126-
pub struct CallSiteScopeData {
127-
pub fn_id: ast::NodeId, pub body_id: ast::NodeId,
128-
}
129-
130-
impl CallSiteScopeData {
131-
pub fn to_code_extent<'a, 'tcx, 'gcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> CodeExtent<'tcx> {
132-
tcx.intern_code_extent(
133-
match *self {
134-
CallSiteScopeData { fn_id, body_id } =>
135-
CodeExtentData::CallSiteScope { fn_id: fn_id, body_id: body_id },
136-
})
137-
}
138-
}
139-
140123
/// Represents a subscope of `block` for a binding that is introduced
141124
/// by `block.stmts[first_statement_index]`. Such subscopes represent
142125
/// a suffix of the block. Note that each subscope does not include
@@ -612,6 +595,14 @@ impl<'tcx> RegionMaps<'tcx> {
612595
}
613596
}
614597
}
598+
599+
/// Assuming that the provided region was defined within this `RegionMaps`,
600+
/// returns the outermost `CodeExtent` that the region outlives.
601+
pub fn free_extent<'a, 'gcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>, fr: &ty::FreeRegion)
602+
-> CodeExtent<'tcx> {
603+
let scope_id = tcx.hir.as_local_node_id(fr.scope).unwrap();
604+
tcx.call_site_extent(scope_id)
605+
}
615606
}
616607

617608
/// Records the lifetime of a local variable as `cx.var_parent`

src/librustc/middle/resolve_lifetime.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ use hir::map::Map;
1919
use session::Session;
2020
use hir::def::Def;
2121
use hir::def_id::DefId;
22-
use middle::region;
2322
use ty;
2423

2524
use std::cell::Cell;
@@ -42,7 +41,7 @@ pub enum Region {
4241
EarlyBound(/* index */ u32, /* lifetime decl */ ast::NodeId),
4342
LateBound(ty::DebruijnIndex, /* lifetime decl */ ast::NodeId),
4443
LateBoundAnon(ty::DebruijnIndex, /* anon index */ u32),
45-
Free(region::CallSiteScopeData, /* lifetime decl */ ast::NodeId),
44+
Free(DefId, /* lifetime decl */ ast::NodeId),
4645
}
4746

4847
impl Region {
@@ -897,9 +896,6 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
897896
if let Some(mut def) = result {
898897
if let Some(body_id) = outermost_body {
899898
let fn_id = self.hir_map.body_owner(body_id);
900-
let scope_data = region::CallSiteScopeData {
901-
fn_id: fn_id, body_id: body_id.node_id
902-
};
903899
match self.hir_map.get(fn_id) {
904900
hir::map::NodeItem(&hir::Item {
905901
node: hir::ItemFn(..), ..
@@ -910,7 +906,8 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
910906
hir::map::NodeImplItem(&hir::ImplItem {
911907
node: hir::ImplItemKind::Method(..), ..
912908
}) => {
913-
def = Region::Free(scope_data, def.id().unwrap());
909+
let scope = self.hir_map.local_def_id(fn_id);
910+
def = Region::Free(scope, def.id().unwrap());
914911
}
915912
_ => {}
916913
}

src/librustc/traits/object_safety.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
206206
};
207207

208208
// Search for a predicate like `Self : Sized` amongst the trait bounds.
209-
let free_substs = self.construct_free_substs(def_id, None);
209+
let free_substs = self.construct_free_substs(def_id);
210210
let predicates = self.predicates_of(def_id);
211211
let predicates = predicates.instantiate(self, free_substs).predicates;
212212
elaborate_predicates(self, predicates)

0 commit comments

Comments
 (0)