store the CodeExtent directly in FreeRegion

this makes the code cleaner
This commit is contained in:
Ariel Ben-Yehuda 2015-08-22 17:39:21 +03:00 committed by Ariel Ben-Yehuda
parent fc304384e6
commit 65e9bc0c93
16 changed files with 36 additions and 55 deletions

View file

@ -225,7 +225,7 @@ impl<'a,'tcx> TyDecoder<'a,'tcx> {
}
'f' => {
assert_eq!(self.next(), '[');
let scope = self.parse_destruction_scope_data();
let scope = self.parse_scope();
assert_eq!(self.next(), '|');
let br = self.parse_bound_region();
assert_eq!(self.next(), ']');
@ -284,11 +284,6 @@ impl<'a,'tcx> TyDecoder<'a,'tcx> {
})
}
fn parse_destruction_scope_data(&mut self) -> region::DestructionScopeData {
let node_id = self.parse_uint() as ast::NodeId;
region::DestructionScopeData::new(node_id)
}
fn parse_opt<T, F>(&mut self, f: F) -> Option<T>
where F: FnOnce(&mut TyDecoder<'a, 'tcx>) -> T,
{

View file

@ -255,7 +255,7 @@ pub fn enc_region(w: &mut Encoder, cx: &ctxt, r: ty::Region) {
}
ty::ReFree(ref fr) => {
mywrite!(w, "f[");
enc_destruction_scope_data(w, fr.scope);
enc_scope(w, cx, fr.scope);
mywrite!(w, "|");
enc_bound_region(w, cx, fr.bound_region);
mywrite!(w, "]");
@ -289,11 +289,6 @@ fn enc_scope(w: &mut Encoder, cx: &ctxt, scope: region::CodeExtent) {
}
}
fn enc_destruction_scope_data(w: &mut Encoder,
d: region::DestructionScopeData) {
mywrite!(w, "{}", d.node_id);
}
fn enc_bound_region(w: &mut Encoder, cx: &ctxt, br: ty::BoundRegion) {
match br {
ty::BrAnon(idx) => {

View file

@ -135,8 +135,7 @@ impl FreeRegionMap {
tcx.region_maps.is_subscope_of(sub_scope, super_scope),
(ty::ReScope(sub_scope), ty::ReFree(fr)) =>
tcx.region_maps.is_subscope_of(sub_scope,
fr.scope.to_code_extent(&tcx.region_maps)) ||
tcx.region_maps.is_subscope_of(sub_scope, fr.scope) ||
self.is_static(fr),
(ty::ReFree(sub_fr), ty::ReFree(super_fr)) =>

View file

@ -172,7 +172,7 @@ impl<'tcx> ty::ctxt<'tcx> {
}
};
match self.map.find(fr.scope.node_id) {
match self.map.find(fr.scope.node_id(&self.region_maps)) {
Some(ast_map::NodeBlock(ref blk)) => {
let (msg, opt_span) = explain_span(self, "block", blk.span);
(format!("{} {}", prefix, msg), opt_span)
@ -183,7 +183,8 @@ impl<'tcx> ty::ctxt<'tcx> {
(format!("{} {}", prefix, msg), opt_span)
}
Some(_) | None => {
// this really should not happen
// this really should not happen, but it does:
// FIXME(#27942)
(format!("{} unknown free region bounded by scope {:?}",
prefix, fr.scope), None)
}
@ -422,7 +423,7 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
return None
}
assert!(fr1.scope == fr2.scope);
(fr1.scope.node_id, fr1, fr2)
(fr1.scope.node_id(&tcx.region_maps), fr1, fr2)
},
_ => return None
};

View file

@ -790,10 +790,9 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
// A "free" region can be interpreted as "some region
// at least as big as the block fr.scope_id". So, we can
// reasonably compare free regions and scopes:
let fr_scope = fr.scope.to_code_extent(&self.tcx.region_maps);
let r_id = self.tcx.region_maps.nearest_common_ancestor(fr_scope, s_id);
let r_id = self.tcx.region_maps.nearest_common_ancestor(fr.scope, s_id);
if r_id == fr_scope {
if r_id == fr.scope {
// if the free region's scope `fr.scope_id` is bigger than
// the scope region `s_id`, then the LUB is the free
// region itself:
@ -871,8 +870,7 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
// than the scope `s_id`, then we can say that the GLB
// is the scope `s_id`. Otherwise, as we do not know
// big the free region is precisely, the GLB is undefined.
let fr_scope = fr.scope.to_code_extent(&self.tcx.region_maps);
if self.tcx.region_maps.nearest_common_ancestor(fr_scope, s_id) == fr_scope ||
if self.tcx.region_maps.nearest_common_ancestor(fr.scope, s_id) == fr.scope ||
free_regions.is_static(fr) {
Ok(s)
} else {
@ -927,8 +925,7 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
Ok(ty::ReFree(*b))
} else {
this.intersect_scopes(ty::ReFree(*a), ty::ReFree(*b),
a.scope.to_code_extent(&this.tcx.region_maps),
b.scope.to_code_extent(&this.tcx.region_maps))
a.scope, b.scope)
}
}
}

View file

@ -111,7 +111,6 @@ use self::VarKind::*;
use middle::def::*;
use middle::pat_util;
use middle::region;
use middle::ty;
use lint;
use util::nodemap::NodeMap;
@ -1509,7 +1508,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
// within the fn body, late-bound regions are liberated:
let fn_ret =
self.ir.tcx.liberate_late_bound_regions(
region::DestructionScopeData::new(body.id),
self.ir.tcx.region_maps.item_extent(body.id),
&self.fn_ret(id));
match fn_ret {

View file

@ -77,7 +77,6 @@ use middle::def_id::DefId;
use middle::infer;
use middle::check_const;
use middle::def;
use middle::region;
use middle::ty::{self, Ty};
use syntax::ast::{MutImmutable, MutMutable};
@ -749,7 +748,7 @@ impl<'t, 'a,'tcx> MemCategorizationContext<'t, 'a, 'tcx> {
// The environment of a closure is guaranteed to
// outlive any bindings introduced in the body of the
// closure itself.
scope: region::DestructionScopeData::new(fn_body_id),
scope: self.tcx().region_maps.item_extent(fn_body_id),
bound_region: ty::BrEnv
});

View file

@ -309,6 +309,13 @@ impl RegionMaps {
pub fn lookup_code_extent(&self, e: CodeExtentData) -> CodeExtent {
self.code_extent_interner.borrow()[&e]
}
pub fn node_extent(&self, n: ast::NodeId) -> CodeExtent {
self.lookup_code_extent(CodeExtentData::Misc(n))
}
// Returns the code extent for an item - the destruction scope.
pub fn item_extent(&self, n: ast::NodeId) -> CodeExtent {
self.lookup_code_extent(CodeExtentData::DestructionScope(n))
}
pub fn intern_code_extent(&self,
e: CodeExtentData,
parent: CodeExtent) -> CodeExtent {
@ -350,9 +357,6 @@ impl RegionMaps {
parent: CodeExtent) -> CodeExtent {
self.intern_code_extent(CodeExtentData::Misc(n), parent)
}
pub fn node_extent(&self, n: ast::NodeId) -> CodeExtent {
self.lookup_code_extent(CodeExtentData::Misc(n))
}
pub fn code_extent_data(&self, e: CodeExtent) -> CodeExtentData {
self.code_extents.borrow()[e.0 as usize]
}

View file

@ -1679,7 +1679,7 @@ impl Region {
/// A "free" region `fr` can be interpreted as "some region
/// at least as big as the scope `fr.scope`".
pub struct FreeRegion {
pub scope: region::DestructionScopeData,
pub scope: region::CodeExtent,
pub bound_region: BoundRegion
}
@ -6610,7 +6610,7 @@ impl<'tcx> ctxt<'tcx> {
types.push(def.space, self.mk_param_from_def(def));
}
let free_id_outlive = region::DestructionScopeData::new(free_id);
let free_id_outlive = self.region_maps.item_extent(free_id);
// map bound 'a => free 'a
let mut regions = VecPerParamSpace::empty();
@ -6641,7 +6641,7 @@ impl<'tcx> ctxt<'tcx> {
//
let free_substs = self.construct_free_substs(generics, free_id);
let free_id_outlive = region::DestructionScopeData::new(free_id);
let free_id_outlive = self.region_maps.item_extent(free_id);
//
// Compute the bounds on Self and the type parameters.
@ -6673,8 +6673,7 @@ impl<'tcx> ctxt<'tcx> {
let unnormalized_env = ty::ParameterEnvironment {
tcx: self,
free_substs: free_substs,
implicit_region_bound: ty::ReScope(
free_id_outlive.to_code_extent(&self.region_maps)),
implicit_region_bound: ty::ReScope(free_id_outlive),
caller_bounds: predicates,
selection_cache: traits::SelectionCache::new(),
free_id: free_id,
@ -6838,7 +6837,7 @@ impl<'tcx> ctxt<'tcx> {
/// Replace any late-bound regions bound in `value` with free variants attached to scope-id
/// `scope_id`.
pub fn liberate_late_bound_regions<T>(&self,
all_outlive_scope: region::DestructionScopeData,
all_outlive_scope: region::CodeExtent,
value: &Binder<T>)
-> T
where T : TypeFoldable<'tcx>

View file

@ -360,9 +360,7 @@ impl<'a, 'tcx> GatherLoanCtxt<'a, 'tcx> {
let loan_scope = match loan_region {
ty::ReScope(scope) => scope,
ty::ReFree(ref fr) => {
fr.scope.to_code_extent(&self.tcx().region_maps)
}
ty::ReFree(ref fr) => fr.scope,
ty::ReStatic => {
// If we get here, an error must have been

View file

@ -179,7 +179,7 @@ pub fn ast_region_to_region(tcx: &ty::ctxt, lifetime: &ast::Lifetime)
Some(&rl::DefFreeRegion(scope, id)) => {
ty::ReFree(ty::FreeRegion {
scope: scope,
scope: tcx.region_maps.item_extent(scope.node_id),
bound_region: ty::BrNamed(DefId::local(id),
lifetime.name)
})

View file

@ -14,7 +14,6 @@ use super::{check_fn, Expectation, FnCtxt};
use astconv;
use middle::def_id::DefId;
use middle::region;
use middle::subst;
use middle::ty::{self, ToPolyTraitRef, Ty};
use std::cmp;
@ -77,7 +76,7 @@ fn check_closure<'a,'tcx>(fcx: &FnCtxt<'a,'tcx>,
fcx.write_ty(expr.id, closure_type);
let fn_sig = fcx.tcx().liberate_late_bound_regions(
region::DestructionScopeData::new(body.id), &fn_ty.sig);
fcx.tcx().region_maps.item_extent(body.id), &fn_ty.sig);
check_fn(fcx.ccx,
ast::Unsafety::Normal,

View file

@ -91,7 +91,6 @@ use middle::infer;
use middle::infer::type_variable;
use middle::pat_util::{self, pat_id_map};
use middle::privacy::{AllPublic, LastMod};
use middle::region::{self};
use middle::subst::{self, Subst, Substs, VecPerParamSpace, ParamSpace, TypeSpace};
use middle::traits::{self, report_fulfillment_errors};
use middle::ty::{FnSig, GenericPredicates, TypeScheme};
@ -455,11 +454,11 @@ fn check_bare_fn<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
let inh = Inherited::new(ccx.tcx, &tables, param_env);
// Compute the fty from point of view of inside fn.
let fn_scope = ccx.tcx.region_maps.item_extent(body.id);
let fn_sig =
fn_ty.sig.subst(ccx.tcx, &inh.infcx.parameter_environment.free_substs);
let fn_sig =
ccx.tcx.liberate_late_bound_regions(region::DestructionScopeData::new(body.id),
&fn_sig);
ccx.tcx.liberate_late_bound_regions(fn_scope, &fn_sig);
let fn_sig =
inh.normalize_associated_types_in(body.span,
body.id,

View file

@ -466,10 +466,7 @@ pub struct BoundsChecker<'cx,'tcx:'cx> {
fcx: &'cx FnCtxt<'cx,'tcx>,
span: Span,
// This field is often attached to item impls; it is not clear
// that `CodeExtent` is well-defined for such nodes, so pnkfelix
// has left it as a NodeId rather than porting to CodeExtent.
scope: ast::NodeId,
scope: region::CodeExtent,
binding_count: usize,
cache: Option<&'cx mut HashSet<Ty<'tcx>>>,
@ -480,6 +477,7 @@ impl<'cx,'tcx> BoundsChecker<'cx,'tcx> {
scope: ast::NodeId,
cache: Option<&'cx mut HashSet<Ty<'tcx>>>)
-> BoundsChecker<'cx,'tcx> {
let scope = fcx.tcx().region_maps.item_extent(scope);
BoundsChecker { fcx: fcx, span: DUMMY_SP, scope: scope,
cache: cache, binding_count: 0 }
}
@ -532,7 +530,7 @@ impl<'cx,'tcx> TypeFolder<'tcx> for BoundsChecker<'cx,'tcx> {
{
self.binding_count += 1;
let value = self.fcx.tcx().liberate_late_bound_regions(
region::DestructionScopeData::new(self.scope),
self.scope,
binder);
debug!("BoundsChecker::fold_binder: late-bound regions replaced: {:?} at scope: {:?}",
value, self.scope);

View file

@ -13,7 +13,6 @@ use check::{FnCtxt, Inherited, blank_fn_ctxt, regionck};
use constrained_type_params::{identify_constrained_type_params, Parameter};
use CrateCtxt;
use middle::def_id::DefId;
use middle::region::DestructionScopeData;
use middle::subst::{self, TypeSpace, FnSpace, ParamSpace, SelfSpace};
use middle::traits;
use middle::ty::{self, Ty};
@ -362,7 +361,7 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> {
{
let free_substs = &fcx.inh.infcx.parameter_environment.free_substs;
let fty = fcx.instantiate_type_scheme(span, free_substs, fty);
let free_id_outlive = DestructionScopeData::new(free_id);
let free_id_outlive = fcx.tcx().region_maps.item_extent(free_id);
let sig = fcx.tcx().liberate_late_bound_regions(free_id_outlive, &fty.sig);
for &input_ty in &sig.inputs {

View file

@ -2311,7 +2311,7 @@ fn check_method_self_type<'a, 'tcx, RS:RegionScope>(
_ => typ,
};
let body_scope = region::DestructionScopeData::new(body_id);
let body_scope = tcx.region_maps.item_extent(body_id);
// "Required type" comes from the trait definition. It may
// contain late-bound regions from the method, but not the
@ -2363,7 +2363,7 @@ fn check_method_self_type<'a, 'tcx, RS:RegionScope>(
fn liberate_early_bound_regions<'tcx,T>(
tcx: &ty::ctxt<'tcx>,
scope: region::DestructionScopeData,
scope: region::CodeExtent,
value: &T)
-> T
where T : TypeFoldable<'tcx>