On-demandify region mapping

This commit is contained in:
Taylor Cramer 2017-03-27 23:54:41 -07:00 committed by Niko Matsakis
parent 06fb4d2564
commit eff39b73d1
32 changed files with 146 additions and 105 deletions

View File

@ -583,11 +583,11 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
scope_id: ast::NodeId,
to_index: CFGIndex) {
let mut data = CFGEdgeData { exiting_scopes: vec![] };
let mut scope = self.tcx.region_maps.node_extent(from_expr.id);
let target_scope = self.tcx.region_maps.node_extent(scope_id);
let mut scope = self.tcx.region_maps().node_extent(from_expr.id);
let target_scope = self.tcx.region_maps().node_extent(scope_id);
while scope != target_scope {
data.exiting_scopes.push(scope.node_id(&self.tcx.region_maps));
scope = self.tcx.region_maps.encl_scope(scope);
data.exiting_scopes.push(scope.node_id(&self.tcx.region_maps()));
scope = self.tcx.region_maps().encl_scope(scope);
}
self.graph.add_edge(from_index, to_index, data);
}

View File

@ -438,7 +438,7 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a, 'tcx>> for ::middle::region::
hcx: &mut StableHashingContext<'a, 'tcx>,
hasher: &mut StableHasher<W>) {
hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
hcx.tcx().region_maps.code_extent_data(*self).hash_stable(hcx, hasher);
hcx.tcx().region_maps().code_extent_data(*self).hash_stable(hcx, hasher);
});
}
}

View File

@ -123,14 +123,14 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
format!("{}unknown scope: {:?}{}. Please report a bug.",
prefix, scope, suffix)
};
let span = match scope.span(&self.region_maps, &self.hir) {
let span = match scope.span(&self.region_maps(), &self.hir) {
Some(s) => s,
None => {
err.note(&unknown_scope());
return;
}
};
let tag = match self.hir.find(scope.node_id(&self.region_maps)) {
let tag = match self.hir.find(scope.node_id(&self.region_maps())) {
Some(hir_map::NodeBlock(_)) => "block",
Some(hir_map::NodeExpr(expr)) => match expr.node {
hir::ExprCall(..) => "call",
@ -150,7 +150,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
return;
}
};
let scope_decorated_tag = match self.region_maps.code_extent_data(scope) {
let scope_decorated_tag = match self.region_maps().code_extent_data(scope) {
region::CodeExtentData::Misc(_) => tag,
region::CodeExtentData::CallSiteScope { .. } => {
"scope of call-site for function"
@ -183,7 +183,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
}
};
let node = fr.scope.node_id(&self.region_maps);
let node = fr.scope.node_id(&self.region_maps());
let unknown;
let tag = match self.hir.find(node) {
Some(hir_map::NodeBlock(_)) |

View File

@ -159,7 +159,7 @@ impl<'a, 'gcx, 'tcx> ConstraintGraph<'a, 'gcx, 'tcx> {
add_node(n2);
}
tcx.region_maps.each_encl_scope(|sub, sup| {
tcx.region_maps().each_encl_scope(|sub, sup| {
add_node(Node::Region(ty::ReScope(*sub)));
add_node(Node::Region(ty::ReScope(*sup)));
});
@ -245,7 +245,7 @@ impl<'a, 'gcx, 'tcx> dot::GraphWalk<'a> for ConstraintGraph<'a, 'gcx, 'tcx> {
fn edges(&self) -> dot::Edges<Edge<'tcx>> {
debug!("constraint graph has {} edges", self.map.len());
let mut v: Vec<_> = self.map.keys().map(|e| Edge::Constraint(*e)).collect();
self.tcx.region_maps.each_encl_scope(|sub, sup| v.push(Edge::EnclScope(*sub, *sup)));
self.tcx.region_maps().each_encl_scope(|sub, sup| v.push(Edge::EnclScope(*sub, *sup)));
debug!("region graph has {} edges", v.len());
Cow::Owned(v)
}

View File

@ -938,7 +938,7 @@ impl<'a, 'gcx, 'tcx> RegionVarBindings<'a, 'gcx, '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 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 the free region's scope `fr.scope_id` is bigger than
@ -957,7 +957,7 @@ impl<'a, 'gcx, 'tcx> RegionVarBindings<'a, 'gcx, 'tcx> {
// subtype of the region corresponding to an inner
// block.
self.tcx.mk_region(ReScope(
self.tcx.region_maps.nearest_common_ancestor(a_id, b_id)))
self.tcx.region_maps().nearest_common_ancestor(a_id, b_id)))
}
(&ReFree(a_fr), &ReFree(b_fr)) => {

View File

@ -136,10 +136,10 @@ impl FreeRegionMap {
true,
(&ty::ReScope(sub_scope), &ty::ReScope(super_scope)) =>
tcx.region_maps.is_subscope_of(sub_scope, super_scope),
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) ||
tcx.region_maps().is_subscope_of(sub_scope, fr.scope) ||
self.is_static(fr),
(&ty::ReFree(sub_fr), &ty::ReFree(super_fr)) =>

View File

@ -1441,7 +1441,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
// and must outlive the *call-site* of the function.
let fn_ret =
self.ir.tcx.liberate_late_bound_regions(
self.ir.tcx.region_maps.call_site_extent(id, body.value.id),
self.ir.tcx.region_maps().call_site_extent(id, body.value.id),
&fn_ret);
if !fn_ret.is_never() && self.live_on_entry(entry_ln, self.s.no_ret_var).is_some() {

View File

@ -796,7 +796,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
// The environment of a closure is guaranteed to
// outlive any bindings introduced in the body of the
// closure itself.
scope: self.tcx().region_maps.item_extent(fn_body_id),
scope: self.tcx().region_maps().item_extent(fn_body_id),
bound_region: ty::BrEnv
}));
@ -845,7 +845,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
pub fn temporary_scope(&self, id: ast::NodeId) -> (&'tcx ty::Region, &'tcx ty::Region)
{
let (scope, old_scope) =
self.tcx().region_maps.old_and_new_temporary_scope(id);
self.tcx().region_maps().old_and_new_temporary_scope(id);
(self.tcx().mk_region(match scope {
Some(scope) => ty::ReScope(scope),
None => ty::ReStatic

View File

@ -16,7 +16,6 @@
//! Most of the documentation on regions can be found in
//! `middle/infer/region_inference/README.md`
use dep_graph::DepNode;
use hir::map as hir_map;
use session::Session;
use util::nodemap::{FxHashMap, NodeMap, NodeSet};
@ -26,11 +25,15 @@ use std::cell::RefCell;
use std::collections::hash_map::Entry;
use std::fmt;
use std::mem;
use std::rc::Rc;
use syntax::codemap;
use syntax::ast::{self, NodeId};
use syntax_pos::Span;
use ty::TyCtxt;
use ty::maps::Providers;
use hir;
use hir::def_id::{CrateNum, LOCAL_CRATE};
use hir::intravisit::{self, Visitor, FnKind, NestedVisitorMap};
use hir::{Block, Item, FnDecl, Arm, Pat, PatKind, Stmt, Expr, Local};
@ -44,8 +47,13 @@ impl fmt::Debug for CodeExtent {
ty::tls::with_opt(|opt_tcx| {
if let Some(tcx) = opt_tcx {
if let Some(data) = tcx.region_maps.code_extents.borrow().get(self.0 as usize) {
write!(f, "/{:?}", data)?;
let region_maps = tcx.region_maps();
{
let code_extents = &region_maps.code_extents;
if let Some(data) = code_extents.borrow().get(self.0 as usize) {
write!(f, "/{:?}", data)?;
}
mem::drop(code_extents); // FIXME why is this necessary?
}
}
Ok(())
@ -1256,9 +1264,19 @@ impl<'hir, 'a> Visitor<'hir> for RegionResolutionVisitor<'hir, 'a> {
}
}
pub fn resolve_crate(sess: &Session, map: &hir_map::Map) -> RegionMaps {
let _task = map.dep_graph.in_task(DepNode::RegionResolveCrate);
let krate = map.krate();
pub fn resolve_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> Rc<RegionMaps> {
tcx.region_resolve_crate(LOCAL_CRATE)
}
fn region_resolve_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, crate_num: CrateNum)
-> Rc<RegionMaps>
{
debug_assert!(crate_num == LOCAL_CRATE);
let sess = &tcx.sess;
let hir_map = &tcx.hir;
let krate = hir_map.krate();
let maps = RegionMaps {
code_extents: RefCell::new(vec![]),
@ -1279,7 +1297,7 @@ pub fn resolve_crate(sess: &Session, map: &hir_map::Map) -> RegionMaps {
let mut visitor = RegionResolutionVisitor {
sess: sess,
region_maps: &maps,
map: map,
map: hir_map,
cx: Context {
root_id: None,
parent: ROOT_CODE_EXTENT,
@ -1289,5 +1307,12 @@ pub fn resolve_crate(sess: &Session, map: &hir_map::Map) -> RegionMaps {
};
krate.visit_all_item_likes(&mut visitor.as_deep_visitor());
}
return maps;
Rc::new(maps)
}
pub fn provide(providers: &mut Providers) {
*providers = Providers {
region_resolve_crate,
..*providers
};
}

View File

@ -207,7 +207,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
// Search for a predicate like `Self : Sized` amongst the trait bounds.
let free_substs = self.construct_free_substs(def_id,
self.region_maps.node_extent(ast::DUMMY_NODE_ID));
self.region_maps().node_extent(ast::DUMMY_NODE_ID));
let predicates = self.predicates_of(def_id);
let predicates = predicates.instantiate(self, free_substs).predicates;
elaborate_predicates(self, predicates)

View File

@ -51,6 +51,7 @@ use std::mem;
use std::ops::Deref;
use std::iter;
use std::cmp::Ordering;
use std::rc::Rc;
use syntax::abi;
use syntax::ast::{self, Name, NodeId};
use syntax::attr;
@ -439,8 +440,6 @@ pub struct GlobalCtxt<'tcx> {
pub named_region_map: resolve_lifetime::NamedRegionMap,
pub region_maps: RegionMaps,
pub hir: hir_map::Map<'tcx>,
pub maps: maps::Maps<'tcx>,
@ -678,6 +677,10 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
local as usize == global as usize
}
pub fn region_maps(self) -> Rc<RegionMaps> {
self.region_resolve_crate(LOCAL_CRATE)
}
/// Create a type context and call the closure with a `TyCtxt` reference
/// to the context. The closure enforces that the type context and any interned
/// value (types, substs, etc.) can only be used while `ty::tls` has a valid
@ -690,7 +693,6 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
resolutions: ty::Resolutions,
named_region_map: resolve_lifetime::NamedRegionMap,
hir: hir_map::Map<'tcx>,
region_maps: RegionMaps,
lang_items: middle::lang_items::LanguageItems,
stability: stability::Index<'tcx>,
crate_name: &str,
@ -714,7 +716,6 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
dep_graph: dep_graph.clone(),
types: common_types,
named_region_map: named_region_map,
region_maps: region_maps,
variance_computed: Cell::new(false),
trait_map: resolutions.trait_map,
export_map: resolutions.export_map,

View File

@ -14,6 +14,7 @@ use hir::def::Def;
use hir;
use middle::const_val;
use middle::privacy::AccessLevels;
use middle::region::RegionMaps;
use mir;
use session::CompileResult;
use ty::{self, CrateInherentImpls, Ty, TyCtxt};
@ -291,6 +292,12 @@ impl<'tcx> QueryDescription for queries::def_span<'tcx> {
}
}
impl<'tcx> QueryDescription for queries::region_resolve_crate<'tcx> {
fn describe(_: TyCtxt, _: CrateNum) -> String {
format!("resolve crate")
}
}
macro_rules! define_maps {
(<$tcx:tt>
$($(#[$attr:meta])*
@ -571,6 +578,8 @@ define_maps! { <'tcx>
[] reachable_set: reachability_dep_node(CrateNum) -> Rc<NodeSet>,
[] region_resolve_crate: region_resolve_crate_dep_node(CrateNum) -> Rc<RegionMaps>,
[] mir_shims: mir_shim_dep_node(ty::InstanceDef<'tcx>) -> &'tcx RefCell<mir::Mir<'tcx>>,
[] def_symbol_name: SymbolName(DefId) -> ty::SymbolName,
@ -592,6 +601,10 @@ fn reachability_dep_node(_: CrateNum) -> DepNode<DefId> {
DepNode::Reachability
}
fn region_resolve_crate_dep_node(_: CrateNum) -> DepNode<DefId> {
DepNode::RegionResolveCrate
}
fn mir_shim_dep_node(instance: ty::InstanceDef) -> DepNode<DefId> {
instance.dep_node()
}
@ -608,4 +621,4 @@ fn typeck_item_bodies_dep_node(_: CrateNum) -> DepNode<DefId> {
fn const_eval_dep_node((def_id, _): (DefId, &Substs)) -> DepNode<DefId> {
DepNode::ConstEval(def_id)
}
}

View File

@ -1220,13 +1220,13 @@ impl<'a, 'tcx> ParameterEnvironment<'tcx> {
let impl_def_id = tcx.hir.local_def_id(impl_id);
tcx.construct_parameter_environment(impl_item.span,
impl_def_id,
tcx.region_maps.item_extent(id))
tcx.region_maps().item_extent(id))
}
hir::ImplItemKind::Method(_, ref body) => {
tcx.construct_parameter_environment(
impl_item.span,
tcx.hir.local_def_id(id),
tcx.region_maps.call_site_extent(id, body.node_id))
tcx.region_maps().call_site_extent(id, body.node_id))
}
}
}
@ -1239,7 +1239,7 @@ impl<'a, 'tcx> ParameterEnvironment<'tcx> {
let trait_def_id = tcx.hir.local_def_id(trait_id);
tcx.construct_parameter_environment(trait_item.span,
trait_def_id,
tcx.region_maps.item_extent(id))
tcx.region_maps().item_extent(id))
}
hir::TraitItemKind::Method(_, ref body) => {
// Use call-site for extent (unless this is a
@ -1247,10 +1247,10 @@ impl<'a, 'tcx> ParameterEnvironment<'tcx> {
// to the method id).
let extent = if let hir::TraitMethod::Provided(body_id) = *body {
// default impl: use call_site extent as free_id_outlive bound.
tcx.region_maps.call_site_extent(id, body_id.node_id)
tcx.region_maps().call_site_extent(id, body_id.node_id)
} else {
// no default impl: use item extent as free_id_outlive bound.
tcx.region_maps.item_extent(id)
tcx.region_maps().item_extent(id)
};
tcx.construct_parameter_environment(
trait_item.span,
@ -1268,7 +1268,7 @@ impl<'a, 'tcx> ParameterEnvironment<'tcx> {
tcx.construct_parameter_environment(
item.span,
fn_def_id,
tcx.region_maps.call_site_extent(id, body_id.node_id))
tcx.region_maps().call_site_extent(id, body_id.node_id))
}
hir::ItemEnum(..) |
hir::ItemStruct(..) |
@ -1280,13 +1280,13 @@ impl<'a, 'tcx> ParameterEnvironment<'tcx> {
let def_id = tcx.hir.local_def_id(id);
tcx.construct_parameter_environment(item.span,
def_id,
tcx.region_maps.item_extent(id))
tcx.region_maps().item_extent(id))
}
hir::ItemTrait(..) => {
let def_id = tcx.hir.local_def_id(id);
tcx.construct_parameter_environment(item.span,
def_id,
tcx.region_maps.item_extent(id))
tcx.region_maps().item_extent(id))
}
_ => {
span_bug!(item.span,
@ -1304,7 +1304,7 @@ impl<'a, 'tcx> ParameterEnvironment<'tcx> {
tcx.construct_parameter_environment(
expr.span,
base_def_id,
tcx.region_maps.call_site_extent(id, body.node_id))
tcx.region_maps().call_site_extent(id, body.node_id))
} else {
tcx.empty_parameter_environment()
}
@ -2474,7 +2474,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
}
/// See `ParameterEnvironment` struct def'n for details.
/// If you were using `free_id: NodeId`, you might try `self.region_maps.item_extent(free_id)`
/// If you were using `free_id: NodeId`, you might try `self.region_maps().item_extent(free_id)`
/// for the `free_id_outlive` parameter. (But note that this is not always quite right.)
pub fn construct_parameter_environment(self,
span: Span,
@ -2521,12 +2521,13 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
is_freeze_cache: RefCell::new(FxHashMap()),
};
let cause = traits::ObligationCause::misc(span, free_id_outlive.node_id(&self.region_maps));
let cause = traits::ObligationCause::misc(span,
free_id_outlive.node_id(&self.region_maps()));
traits::normalize_param_env_or_error(tcx, unnormalized_env, cause)
}
pub fn node_scope_region(self, id: NodeId) -> &'tcx Region {
self.mk_region(ty::ReScope(self.region_maps.node_extent(id)))
self.mk_region(ty::ReScope(self.region_maps().node_extent(id)))
}
pub fn visit_all_item_likes_in_krate<V,F>(self,

View File

@ -239,8 +239,8 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
//! currently in scope.
let tcx = self.tcx();
self.each_issued_loan(scope.node_id(&tcx.region_maps), |loan| {
if tcx.region_maps.is_subscope_of(scope, loan.kill_scope) {
self.each_issued_loan(scope.node_id(&tcx.region_maps()), |loan| {
if tcx.region_maps().is_subscope_of(scope, loan.kill_scope) {
op(loan)
} else {
true
@ -379,7 +379,7 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
new_loan);
// Should only be called for loans that are in scope at the same time.
assert!(self.tcx().region_maps.scopes_intersect(old_loan.kill_scope,
assert!(self.tcx().region_maps().scopes_intersect(old_loan.kill_scope,
new_loan.kill_scope));
self.report_error_if_loan_conflicts_with_restriction(
@ -460,7 +460,7 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
// 3. Where does old loan expire.
let previous_end_span =
self.tcx().hir.span(old_loan.kill_scope.node_id(&self.tcx().region_maps))
self.tcx().hir.span(old_loan.kill_scope.node_id(&self.tcx().region_maps()))
.end_point();
let mut err = match (new_loan.kind, old_loan.kind) {
@ -710,7 +710,7 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
let mut ret = UseOk;
self.each_in_scope_loan_affecting_path(
self.tcx().region_maps.node_extent(expr_id), use_path, |loan| {
self.tcx().region_maps().node_extent(expr_id), use_path, |loan| {
if !compatible_borrow_kinds(loan.kind, borrow_kind) {
ret = UseWhileBorrowed(loan.loan_path.clone(), loan.span);
false
@ -824,7 +824,7 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
// Check that we don't invalidate any outstanding loans
if let Some(loan_path) = opt_loan_path(&assignee_cmt) {
let scope = self.tcx().region_maps.node_extent(assignment_id);
let scope = self.tcx().region_maps().node_extent(assignment_id);
self.each_in_scope_loan_affecting_path(scope, &loan_path, |loan| {
self.report_illegal_mutation(assignment_span, &loan_path, loan);
false

View File

@ -116,7 +116,7 @@ impl<'a, 'tcx> GuaranteeLifetimeContext<'a, 'tcx> {
}
Categorization::Local(local_id) => {
self.bccx.tcx.mk_region(ty::ReScope(
self.bccx.tcx.region_maps.var_scope(local_id)))
self.bccx.tcx.region_maps().var_scope(local_id)))
}
Categorization::StaticItem |
Categorization::Deref(.., mc::UnsafePtr(..)) => {

View File

@ -45,7 +45,7 @@ pub fn gather_loans_in_fn<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>,
bccx: bccx,
infcx: &infcx,
all_loans: Vec::new(),
item_ub: bccx.tcx.region_maps.node_extent(body.node_id),
item_ub: bccx.tcx.region_maps().node_extent(body.node_id),
move_data: MoveData::new(),
move_error_collector: move_error::MoveErrorCollector::new(),
};
@ -371,7 +371,7 @@ impl<'a, 'tcx> GatherLoanCtxt<'a, 'tcx> {
};
debug!("loan_scope = {:?}", loan_scope);
let borrow_scope = self.tcx().region_maps.node_extent(borrow_id);
let borrow_scope = self.tcx().region_maps().node_extent(borrow_id);
let gen_scope = self.compute_gen_scope(borrow_scope, loan_scope);
debug!("gen_scope = {:?}", gen_scope);
@ -458,7 +458,7 @@ impl<'a, 'tcx> GatherLoanCtxt<'a, 'tcx> {
//! notably method arguments, the loan may be introduced only
//! later, once it comes into scope.
if self.bccx.tcx.region_maps.is_subscope_of(borrow_scope, loan_scope) {
if self.bccx.tcx.region_maps().is_subscope_of(borrow_scope, loan_scope) {
borrow_scope
} else {
loan_scope
@ -489,11 +489,11 @@ impl<'a, 'tcx> GatherLoanCtxt<'a, 'tcx> {
//! do not require restrictions and hence do not cause a loan.
let lexical_scope = lp.kill_scope(self.bccx.tcx);
let rm = &self.bccx.tcx.region_maps;
let rm = &self.bccx.tcx.region_maps();
if rm.is_subscope_of(lexical_scope, loan_scope) {
lexical_scope
} else {
assert!(self.bccx.tcx.region_maps.is_subscope_of(loan_scope, lexical_scope));
assert!(self.bccx.tcx.region_maps().is_subscope_of(loan_scope, lexical_scope));
loan_scope
}
}

View File

@ -141,9 +141,9 @@ fn build_borrowck_dataflow_data<'a, 'tcx>(this: &mut BorrowckCtxt<'a, 'tcx>,
id_range,
all_loans.len());
for (loan_idx, loan) in all_loans.iter().enumerate() {
loan_dfcx.add_gen(loan.gen_scope.node_id(&tcx.region_maps), loan_idx);
loan_dfcx.add_gen(loan.gen_scope.node_id(&tcx.region_maps()), loan_idx);
loan_dfcx.add_kill(KillFrom::ScopeEnd,
loan.kill_scope.node_id(&tcx.region_maps), loan_idx);
loan.kill_scope.node_id(&tcx.region_maps()), loan_idx);
}
loan_dfcx.add_kills_from_flow_exits(cfg);
loan_dfcx.propagate(cfg, body);
@ -314,10 +314,10 @@ pub fn closure_to_block(closure_id: ast::NodeId,
impl<'a, 'tcx> LoanPath<'tcx> {
pub fn kill_scope(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>) -> region::CodeExtent {
match self.kind {
LpVar(local_id) => tcx.region_maps.var_scope(local_id),
LpVar(local_id) => tcx.region_maps().var_scope(local_id),
LpUpvar(upvar_id) => {
let block_id = closure_to_block(upvar_id.closure_expr_id, tcx);
tcx.region_maps.node_extent(block_id)
tcx.region_maps().node_extent(block_id)
}
LpDowncast(ref base, _) |
LpExtend(ref base, ..) => base.kill_scope(tcx),
@ -966,7 +966,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
fn region_end_span(&self, region: &'tcx ty::Region) -> Option<Span> {
match *region {
ty::ReScope(scope) => {
match scope.span(&self.tcx.region_maps, &self.tcx.hir) {
match scope.span(&self.tcx.region_maps(), &self.tcx.hir) {
Some(s) => {
Some(s.end_point())
}
@ -1247,7 +1247,7 @@ before rustc 1.16, this temporary lived longer - see issue #39283 \
fn statement_scope_span(tcx: TyCtxt, region: &ty::Region) -> Option<Span> {
match *region {
ty::ReScope(scope) => {
match tcx.hir.find(scope.node_id(&tcx.region_maps)) {
match tcx.hir.find(scope.node_id(&tcx.region_maps())) {
Some(hir_map::NodeStmt(stmt)) => Some(stmt.span),
_ => None
}

View File

@ -548,7 +548,7 @@ impl<'a, 'tcx> MoveData<'tcx> {
LpVar(..) | LpUpvar(..) | LpDowncast(..) => {
let kill_scope = path.loan_path.kill_scope(tcx);
let path = *self.path_map.borrow().get(&path.loan_path).unwrap();
self.kill_moves(path, kill_scope.node_id(&tcx.region_maps),
self.kill_moves(path, kill_scope.node_id(&tcx.region_maps()),
KillFrom::ScopeEnd, dfcx_moves);
}
LpExtend(..) => {}
@ -563,7 +563,7 @@ impl<'a, 'tcx> MoveData<'tcx> {
LpVar(..) | LpUpvar(..) | LpDowncast(..) => {
let kill_scope = lp.kill_scope(tcx);
dfcx_assign.add_kill(KillFrom::ScopeEnd,
kill_scope.node_id(&tcx.region_maps),
kill_scope.node_id(&tcx.region_maps()),
assignment_index);
}
LpExtend(..) => {

View File

@ -874,10 +874,6 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
}));
sess.derive_registrar_fn.set(derive_registrar::find(&hir_map));
let region_map = time(time_passes,
"region resolution",
|| middle::region::resolve_crate(sess, &hir_map));
time(time_passes,
"loop checking",
|| loops::check_crate(sess, &hir_map));
@ -898,6 +894,7 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
ty::provide(&mut local_providers);
reachable::provide(&mut local_providers);
rustc_const_eval::provide(&mut local_providers);
middle::region::provide(&mut local_providers);
let mut extern_providers = ty::maps::Providers::default();
cstore::provide(&mut extern_providers);
@ -914,7 +911,6 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
resolutions,
named_region_map,
hir_map,
region_map,
lang_items,
index,
name,
@ -923,10 +919,15 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
time(time_passes,
"compute_incremental_hashes_map",
|| rustc_incremental::compute_incremental_hashes_map(tcx));
time(time_passes,
"load_dep_graph",
|| rustc_incremental::load_dep_graph(tcx, &incremental_hashes_map));
time(time_passes,
"region resolution",
|| middle::region::resolve_crate(tcx));
time(time_passes, "stability index", || {
tcx.stability.borrow_mut().build(tcx)
});

View File

@ -83,7 +83,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
let_extent_stack.push(remainder_scope);
// Declare the bindings, which may create a visibility scope.
let remainder_span = remainder_scope.span(&tcx.region_maps, &tcx.hir);
let remainder_span = remainder_scope.span(&tcx.region_maps(), &tcx.hir);
let remainder_span = remainder_span.unwrap_or(span);
let scope = this.declare_bindings(None, remainder_span, &pattern);

View File

@ -202,7 +202,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
pub fn schedule_drop_for_binding(&mut self, var: NodeId, span: Span) {
let local_id = self.var_indices[&var];
let var_ty = self.local_decls[local_id].ty;
let extent = self.hir.tcx().region_maps.var_scope(var);
let extent = self.hir.tcx().region_maps().var_scope(var);
self.schedule_drop(span, extent, &Lvalue::Local(local_id), var_ty);
}

View File

@ -137,10 +137,10 @@ pub fn construct_fn<'a, 'gcx, 'tcx, A>(hir: Cx<'a, 'gcx, 'tcx>,
let mut builder = Builder::new(hir, span, arguments.len(), return_ty);
let call_site_extent =
tcx.region_maps.lookup_code_extent(
tcx.region_maps().lookup_code_extent(
CodeExtentData::CallSiteScope { fn_id: fn_id, body_id: body.value.id });
let arg_extent =
tcx.region_maps.lookup_code_extent(
tcx.region_maps().lookup_code_extent(
CodeExtentData::ParameterScope { fn_id: fn_id, body_id: body.value.id });
let mut block = START_BLOCK;
unpack!(block = builder.in_scope(call_site_extent, block, |builder| {
@ -203,7 +203,7 @@ pub fn construct_const<'a, 'gcx, 'tcx>(hir: Cx<'a, 'gcx, 'tcx>,
let span = tcx.hir.span(tcx.hir.body_owner(body_id));
let mut builder = Builder::new(hir, span, 0, ty);
let extent = tcx.region_maps.temporary_scope(ast_expr.id)
let extent = tcx.region_maps().temporary_scope(ast_expr.id)
.unwrap_or(ROOT_CODE_EXTENT);
let mut block = START_BLOCK;
let _ = builder.in_scope(extent, block, |builder| {

View File

@ -411,7 +411,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
// The outermost scope (`scopes[0]`) will be the `CallSiteScope`.
// We want `scopes[1]`, which is the `ParameterScope`.
assert!(self.scopes.len() >= 2);
assert!(match self.hir.tcx().region_maps.code_extent_data(self.scopes[1].extent) {
assert!(match self.hir.tcx().region_maps().code_extent_data(self.scopes[1].extent) {
CodeExtentData::ParameterScope { .. } => true,
_ => false,
});
@ -499,7 +499,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
scope.needs_cleanup = true;
}
let tcx = self.hir.tcx();
let extent_span = extent.span(&tcx.region_maps, &tcx.hir).unwrap();
let extent_span = extent.span(&tcx.region_maps(), &tcx.hir).unwrap();
// Attribute scope exit drops to scope's closing brace
let scope_end = Span { lo: extent_span.hi, .. extent_span};
scope.drops.push(DropData {

View File

@ -24,7 +24,7 @@ impl<'tcx> Mirror<'tcx> for &'tcx hir::Block {
let stmts = mirror_stmts(cx, self.id, &*self.stmts);
Block {
targeted_by_break: self.targeted_by_break,
extent: cx.tcx.region_maps.node_extent(self.id),
extent: cx.tcx.region_maps().node_extent(self.id),
span: self.span,
stmts: stmts,
expr: self.expr.to_ref(),
@ -44,7 +44,7 @@ fn mirror_stmts<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
result.push(StmtRef::Mirror(Box::new(Stmt {
span: stmt.span,
kind: StmtKind::Expr {
scope: cx.tcx.region_maps.node_extent(id),
scope: cx.tcx.region_maps().node_extent(id),
expr: expr.to_ref(),
},
})))
@ -60,14 +60,14 @@ fn mirror_stmts<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
first_statement_index: index as u32,
});
let remainder_extent =
cx.tcx.region_maps.lookup_code_extent(remainder_extent);
cx.tcx.region_maps().lookup_code_extent(remainder_extent);
let pattern = Pattern::from_hir(cx.tcx, cx.tables(), &local.pat);
result.push(StmtRef::Mirror(Box::new(Stmt {
span: stmt.span,
kind: StmtKind::Let {
remainder_scope: remainder_extent,
init_scope: cx.tcx.region_maps.node_extent(id),
init_scope: cx.tcx.region_maps().node_extent(id),
pattern: pattern,
initializer: local.init.to_ref(),
},
@ -84,7 +84,7 @@ pub fn to_expr_ref<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
block: &'tcx hir::Block)
-> ExprRef<'tcx> {
let block_ty = cx.tables().node_id_to_type(block.id);
let (temp_lifetime, was_shrunk) = cx.tcx.region_maps.temporary_scope2(block.id);
let (temp_lifetime, was_shrunk) = cx.tcx.region_maps().temporary_scope2(block.id);
let expr = Expr {
ty: block_ty,
temp_lifetime: temp_lifetime,

View File

@ -26,8 +26,8 @@ impl<'tcx> Mirror<'tcx> for &'tcx hir::Expr {
type Output = Expr<'tcx>;
fn make_mirror<'a, 'gcx>(self, cx: &mut Cx<'a, 'gcx, 'tcx>) -> Expr<'tcx> {
let (temp_lifetime, was_shrunk) = cx.tcx.region_maps.temporary_scope2(self.id);
let expr_extent = cx.tcx.region_maps.node_extent(self.id);
let (temp_lifetime, was_shrunk) = cx.tcx.region_maps().temporary_scope2(self.id);
let expr_extent = cx.tcx.region_maps().node_extent(self.id);
debug!("Expr::make_mirror(): id={}, span={:?}", self.id, self.span);
@ -216,7 +216,7 @@ impl<'tcx> Mirror<'tcx> for &'tcx hir::Expr {
};
// Finally, create a destruction scope, if any.
if let Some(extent) = cx.tcx.region_maps.opt_destruction_extent(self.id) {
if let Some(extent) = cx.tcx.region_maps().opt_destruction_extent(self.id) {
expr = Expr {
temp_lifetime: temp_lifetime,
temp_lifetime_was_shrunk: was_shrunk,
@ -238,7 +238,7 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
expr: &'tcx hir::Expr)
-> Expr<'tcx> {
let expr_ty = cx.tables().expr_ty(expr);
let (temp_lifetime, was_shrunk) = cx.tcx.region_maps.temporary_scope2(expr.id);
let (temp_lifetime, was_shrunk) = cx.tcx.region_maps().temporary_scope2(expr.id);
let kind = match expr.node {
// Here comes the interesting stuff:
@ -610,7 +610,7 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
match dest.target_id {
hir::ScopeTarget::Block(target_id) |
hir::ScopeTarget::Loop(hir::LoopIdResult::Ok(target_id)) => ExprKind::Break {
label: cx.tcx.region_maps.node_extent(target_id),
label: cx.tcx.region_maps().node_extent(target_id),
value: value.to_ref(),
},
hir::ScopeTarget::Loop(hir::LoopIdResult::Err(err)) =>
@ -621,7 +621,7 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
match dest.target_id {
hir::ScopeTarget::Block(_) => bug!("cannot continue to blocks"),
hir::ScopeTarget::Loop(hir::LoopIdResult::Ok(loop_id)) => ExprKind::Continue {
label: cx.tcx.region_maps.node_extent(loop_id),
label: cx.tcx.region_maps().node_extent(loop_id),
},
hir::ScopeTarget::Loop(hir::LoopIdResult::Err(err)) =>
bug!("invalid loop id for continue: {}", err)
@ -686,7 +686,7 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
hir::ExprBox(ref value) => {
ExprKind::Box {
value: value.to_ref(),
value_extents: cx.tcx.region_maps.node_extent(value.id),
value_extents: cx.tcx.region_maps().node_extent(value.id),
}
}
hir::ExprArray(ref fields) => ExprKind::Array { fields: fields.to_ref() },
@ -707,7 +707,7 @@ fn method_callee<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
method_call: ty::MethodCall)
-> Expr<'tcx> {
let callee = cx.tables().method_map[&method_call];
let (temp_lifetime, was_shrunk) = cx.tcx.region_maps.temporary_scope2(expr.id);
let (temp_lifetime, was_shrunk) = cx.tcx.region_maps().temporary_scope2(expr.id);
Expr {
temp_lifetime: temp_lifetime,
temp_lifetime_was_shrunk: was_shrunk,
@ -791,7 +791,7 @@ fn convert_var<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
expr: &'tcx hir::Expr,
def: Def)
-> ExprKind<'tcx> {
let (temp_lifetime, was_shrunk) = cx.tcx.region_maps.temporary_scope2(expr.id);
let (temp_lifetime, was_shrunk) = cx.tcx.region_maps().temporary_scope2(expr.id);
match def {
Def::Local(def_id) => {
@ -828,7 +828,7 @@ fn convert_var<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
// signature will be &self or &mut self and hence will
// have a bound region with number 0
let region = ty::Region::ReFree(ty::FreeRegion {
scope: cx.tcx.region_maps.node_extent(body_id),
scope: cx.tcx.region_maps().node_extent(body_id),
bound_region: ty::BoundRegion::BrAnon(0),
});
let region = cx.tcx.mk_region(region);
@ -979,7 +979,7 @@ fn overloaded_operator<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
PassArgs::ByRef => {
let region = cx.tcx.node_scope_region(expr.id);
let (temp_lifetime, was_shrunk) =
cx.tcx.region_maps.temporary_scope2(expr.id);
cx.tcx.region_maps().temporary_scope2(expr.id);
argrefs.extend(args.iter()
.map(|arg| {
let arg_ty = cx.tables().expr_ty_adjusted(arg);
@ -1031,7 +1031,7 @@ fn overloaded_lvalue<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
// construct the complete expression `foo()` for the overloaded call,
// which will yield the &T type
let (temp_lifetime, was_shrunk) = cx.tcx.region_maps.temporary_scope2(expr.id);
let (temp_lifetime, was_shrunk) = cx.tcx.region_maps().temporary_scope2(expr.id);
let ref_kind = overloaded_operator(cx, expr, method_call, pass_args, receiver, args);
let ref_expr = Expr {
temp_lifetime: temp_lifetime,
@ -1056,7 +1056,7 @@ fn capture_freevar<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
closure_expr_id: closure_expr.id,
};
let upvar_capture = cx.tables().upvar_capture(upvar_id).unwrap();
let (temp_lifetime, was_shrunk) = cx.tcx.region_maps.temporary_scope2(closure_expr.id);
let (temp_lifetime, was_shrunk) = cx.tcx.region_maps().temporary_scope2(closure_expr.id);
let var_ty = cx.tables().node_id_to_type(id_var);
let captured_var = Expr {
temp_lifetime: temp_lifetime,

View File

@ -253,7 +253,7 @@ fn closure_self_ty<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
let closure_ty = tcx.body_tables(body_id).node_id_to_type(closure_expr_id);
let region = ty::Region::ReFree(ty::FreeRegion {
scope: tcx.region_maps.item_extent(body_id.node_id),
scope: tcx.region_maps().item_extent(body_id.node_id),
bound_region: ty::BoundRegion::BrEnv,
});
let region = tcx.mk_region(region);

View File

@ -133,7 +133,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
Some(&rl::Region::Free(scope, id)) => {
let name = tcx.hir.name(id);
tcx.mk_region(ty::ReFree(ty::FreeRegion {
scope: scope.to_code_extent(&tcx.region_maps),
scope: scope.to_code_extent(&tcx.region_maps()),
bound_region: ty::BrNamed(tcx.hir.local_def_id(id), name)
}))

View File

@ -73,7 +73,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
debug!("check_closure: expr.id={:?} closure_type={:?}", expr.id, closure_type);
let extent = self.tcx.region_maps.call_site_extent(expr.id, body.value.id);
let extent = self.tcx.region_maps().call_site_extent(expr.id, body.value.id);
let fn_sig = self.tcx.liberate_late_bound_regions(extent, &sig);
let fn_sig = self.inh.normalize_associated_types_in(body.value.span,
body.value.id, &fn_sig);

View File

@ -278,7 +278,7 @@ pub fn check_safety_of_destructor_if_necessary<'a, 'gcx, 'tcx>(
ty, scope);
let parent_scope = match rcx.tcx.region_maps.opt_encl_scope(scope) {
let parent_scope = match rcx.tcx.region_maps().opt_encl_scope(scope) {
Some(parent_scope) => parent_scope,
// If no enclosing scope, then it must be the root scope
// which cannot be outlived.

View File

@ -781,7 +781,7 @@ fn typeck_tables_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
check_abi(tcx, span, fn_sig.abi());
// Compute the fty from point of view of inside fn.
let fn_scope = inh.tcx.region_maps.call_site_extent(id, body_id.node_id);
let fn_scope = inh.tcx.region_maps().call_site_extent(id, body_id.node_id);
let fn_sig =
fn_sig.subst(inh.tcx, &inh.parameter_environment.free_substs);
let fn_sig =

View File

@ -276,7 +276,7 @@ impl<'a, 'gcx, 'tcx> RegionCtxt<'a, 'gcx, 'tcx> {
let body_id = body.id();
let call_site = self.tcx.region_maps.lookup_code_extent(
let call_site = self.tcx.region_maps().lookup_code_extent(
region::CodeExtentData::CallSiteScope { fn_id: id, body_id: body_id.node_id });
let old_call_site_scope = self.set_call_site_scope(Some(call_site));
@ -302,7 +302,7 @@ impl<'a, 'gcx, 'tcx> RegionCtxt<'a, 'gcx, 'tcx> {
let old_body_id = self.set_body_id(body_id.node_id);
self.relate_free_regions(&fn_sig_tys[..], body_id.node_id, span);
self.link_fn_args(self.tcx.region_maps.node_extent(body_id.node_id), &body.arguments);
self.link_fn_args(self.tcx.region_maps().node_extent(body_id.node_id), &body.arguments);
self.visit_body(body);
self.visit_region_obligations(body_id.node_id);
@ -450,7 +450,7 @@ impl<'a, 'gcx, 'tcx> RegionCtxt<'a, 'gcx, 'tcx> {
// that the lifetime of any regions that appear in a
// variable's type enclose at least the variable's scope.
let var_scope = tcx.region_maps.var_scope(id);
let var_scope = tcx.region_maps().var_scope(id);
let var_region = self.tcx.mk_region(ty::ReScope(var_scope));
let origin = infer::BindingTypeIsNotValidAtDecl(span);
@ -868,7 +868,7 @@ impl<'a, 'gcx, 'tcx> RegionCtxt<'a, 'gcx, 'tcx> {
// call occurs.
//
// FIXME(#6268) to support nested method calls, should be callee_id
let callee_scope = self.tcx.region_maps.node_extent(call_expr.id);
let callee_scope = self.tcx.region_maps().node_extent(call_expr.id);
let callee_region = self.tcx.mk_region(ty::ReScope(callee_scope));
debug!("callee_region={:?}", callee_region);
@ -1021,7 +1021,7 @@ impl<'a, 'gcx, 'tcx> RegionCtxt<'a, 'gcx, 'tcx> {
debug!("constrain_index(index_expr=?, indexed_ty={}",
self.ty_to_string(indexed_ty));
let r_index_expr = ty::ReScope(self.tcx.region_maps.node_extent(index_expr.id));
let r_index_expr = ty::ReScope(self.tcx.region_maps().node_extent(index_expr.id));
if let ty::TyRef(r_ptr, mt) = indexed_ty.sty {
match mt.ty.sty {
ty::TySlice(_) | ty::TyStr => {

View File

@ -341,7 +341,7 @@ impl<'a, 'gcx> CheckTypeWellFormedVisitor<'a, 'gcx> {
let predicates = fcx.instantiate_bounds(item.span, def_id, free_substs);
let mut implied_bounds = vec![];
let free_id_outlive = fcx.tcx.region_maps.call_site_extent(item.id, body_id.node_id);
let free_id_outlive = fcx.tcx.region_maps().call_site_extent(item.id, body_id.node_id);
this.check_fn_or_method(fcx, item.span, sig, &predicates,
free_id_outlive, &mut implied_bounds);
implied_bounds