try to cache region_scope_tree as a query
This commit is contained in:
parent
b2eba058e6
commit
4c6074fbb0
16 changed files with 30 additions and 42 deletions
|
@ -4,7 +4,7 @@ use crate::astconv::{
|
|||
};
|
||||
use crate::check::callee::{self, DeferredCallResolution};
|
||||
use crate::check::method::{self, MethodCallee, SelfSource};
|
||||
use crate::check::{region, rvalue_scopes};
|
||||
use crate::check::rvalue_scopes;
|
||||
use crate::check::{BreakableCtxt, Diverges, Expectation, FnCtxt, LocalTy};
|
||||
|
||||
use rustc_data_structures::captures::Captures;
|
||||
|
@ -622,10 +622,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
}
|
||||
|
||||
pub(in super::super) fn resolve_rvalue_scopes(&self, def_id: DefId) {
|
||||
let scope_tree = region::region_scope_tree(self.tcx, def_id);
|
||||
let scope_tree = self.tcx.region_scope_tree(def_id);
|
||||
let rvalue_scopes = { rvalue_scopes::resolve_rvalue_scopes(self, &scope_tree, def_id) };
|
||||
let mut typeck_results = self.inh.typeck_results.borrow_mut();
|
||||
typeck_results.region_scope_tree = scope_tree;
|
||||
typeck_results.rvalue_scopes = rvalue_scopes;
|
||||
}
|
||||
|
||||
|
|
|
@ -184,7 +184,7 @@ pub fn resolve_interior<'a, 'tcx>(
|
|||
let mut visitor = InteriorVisitor {
|
||||
fcx,
|
||||
types: FxIndexSet::default(),
|
||||
region_scope_tree: &typeck_results.region_scope_tree,
|
||||
region_scope_tree: fcx.tcx.region_scope_tree(def_id),
|
||||
rvalue_scopes: &typeck_results.rvalue_scopes,
|
||||
expr_count: 0,
|
||||
kind,
|
||||
|
@ -195,7 +195,7 @@ pub fn resolve_interior<'a, 'tcx>(
|
|||
intravisit::walk_body(&mut visitor, body);
|
||||
|
||||
// Check that we visited the same amount of expressions as the RegionResolutionVisitor
|
||||
let region_expr_count = typeck_results.region_scope_tree.body_expr_count(body_id).unwrap();
|
||||
let region_expr_count = fcx.tcx.region_scope_tree(def_id).body_expr_count(body_id).unwrap();
|
||||
assert_eq!(region_expr_count, visitor.expr_count);
|
||||
|
||||
// The types are already kept in insertion order.
|
||||
|
|
|
@ -42,7 +42,7 @@ pub fn compute_drop_ranges<'a, 'tcx>(
|
|||
let consumed_borrowed_places = find_consumed_and_borrowed(fcx, def_id, body);
|
||||
|
||||
let typeck_results = &fcx.typeck_results.borrow();
|
||||
let num_exprs = typeck_results.region_scope_tree.body_expr_count(body.id()).unwrap_or(0);
|
||||
let num_exprs = fcx.tcx.region_scope_tree(def_id).body_expr_count(body.id()).unwrap_or(0);
|
||||
let (mut drop_ranges, borrowed_temporaries) = build_control_flow_graph(
|
||||
fcx.tcx.hir(),
|
||||
fcx.tcx,
|
||||
|
|
|
@ -138,6 +138,7 @@ use crate::require_c_abi_if_c_variadic;
|
|||
use crate::util::common::indenter;
|
||||
|
||||
use self::coercion::DynamicCoerceMany;
|
||||
use self::region::region_scope_tree;
|
||||
pub use self::Expectation::*;
|
||||
|
||||
#[macro_export]
|
||||
|
@ -255,6 +256,7 @@ pub fn provide(providers: &mut Providers) {
|
|||
check_trait_item_well_formed,
|
||||
check_impl_item_well_formed,
|
||||
check_mod_item_types,
|
||||
region_scope_tree,
|
||||
..*providers
|
||||
};
|
||||
}
|
||||
|
|
|
@ -797,14 +797,14 @@ impl<'tcx> Visitor<'tcx> for RegionResolutionVisitor<'tcx> {
|
|||
|
||||
/// Per-body `region::ScopeTree`. The `DefId` should be the owner `DefId` for the body;
|
||||
/// in the case of closures, this will be redirected to the enclosing function.
|
||||
pub fn region_scope_tree(tcx: TyCtxt<'_>, def_id: DefId) -> ScopeTree {
|
||||
pub fn region_scope_tree(tcx: TyCtxt<'_>, def_id: DefId) -> &ScopeTree {
|
||||
let typeck_root_def_id = tcx.typeck_root_def_id(def_id);
|
||||
if typeck_root_def_id != def_id {
|
||||
return region_scope_tree(tcx, typeck_root_def_id);
|
||||
return tcx.region_scope_tree(typeck_root_def_id);
|
||||
}
|
||||
|
||||
let id = tcx.hir().local_def_id_to_hir_id(def_id.expect_local());
|
||||
if let Some(body_id) = tcx.hir().maybe_body_owned_by(id) {
|
||||
let scope_tree = if let Some(body_id) = tcx.hir().maybe_body_owned_by(id) {
|
||||
let mut visitor = RegionResolutionVisitor {
|
||||
tcx,
|
||||
scope_tree: ScopeTree::default(),
|
||||
|
@ -821,5 +821,7 @@ pub fn region_scope_tree(tcx: TyCtxt<'_>, def_id: DefId) -> ScopeTree {
|
|||
visitor.scope_tree
|
||||
} else {
|
||||
ScopeTree::default()
|
||||
}
|
||||
};
|
||||
|
||||
tcx.arena.alloc(scope_tree)
|
||||
}
|
||||
|
|
|
@ -71,8 +71,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
wbcx.visit_user_provided_sigs();
|
||||
wbcx.visit_generator_interior_types();
|
||||
|
||||
wbcx.typeck_results.region_scope_tree =
|
||||
mem::take(&mut self.typeck_results.borrow_mut().region_scope_tree);
|
||||
wbcx.typeck_results.rvalue_scopes =
|
||||
mem::take(&mut self.typeck_results.borrow_mut().rvalue_scopes);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue