Skip to content

Commit 4c6074f

Browse files
try to cache region_scope_tree as a query
1 parent b2eba05 commit 4c6074f

File tree

16 files changed

+30
-42
lines changed

16 files changed

+30
-42
lines changed

compiler/rustc_middle/src/arena.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ macro_rules! arena_types {
3131
[decode] unsafety_check_result: rustc_middle::mir::UnsafetyCheckResult,
3232
[decode] code_region: rustc_middle::mir::coverage::CodeRegion,
3333
[] const_allocs: rustc_middle::mir::interpret::Allocation,
34+
[] region_scope_tree: rustc_middle::middle::region::ScopeTree,
3435
// Required for the incremental on-disk cache
3536
[] mir_keys: rustc_hir::def_id::DefIdSet,
3637
[] dropck_outlives:

compiler/rustc_middle/src/query/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,6 +1048,12 @@ rustc_queries! {
10481048
desc { "reachability" }
10491049
}
10501050

1051+
/// Per-body `region::ScopeTree`. The `DefId` should be the owner `DefId` for the body;
1052+
/// in the case of closures, this will be redirected to the enclosing function.
1053+
query region_scope_tree(def_id: DefId) -> &'tcx crate::middle::region::ScopeTree {
1054+
desc { |tcx| "computing drop scopes for `{}`", tcx.def_path_str(def_id) }
1055+
}
1056+
10511057
/// Generates a MIR body for the shim.
10521058
query mir_shims(key: ty::InstanceDef<'tcx>) -> mir::Body<'tcx> {
10531059
storage(ArenaCacheSelector<'tcx>)

compiler/rustc_middle/src/ty/context.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use crate::hir::place::Place as HirPlace;
66
use crate::infer::canonical::{Canonical, CanonicalVarInfo, CanonicalVarInfos};
77
use crate::lint::{struct_lint_level, LintDiagnosticBuilder, LintLevelSource};
88
use crate::middle::codegen_fn_attrs::CodegenFnAttrs;
9-
use crate::middle::region::ScopeTree;
109
use crate::middle::resolve_lifetime::{self, LifetimeScopeForPath};
1110
use crate::middle::stability;
1211
use crate::mir::interpret::{self, Allocation, ConstAllocation, ConstValue, Scalar};
@@ -538,12 +537,6 @@ pub struct TypeckResults<'tcx> {
538537
/// issue by fake reading `t`.
539538
pub closure_fake_reads: FxHashMap<DefId, Vec<(HirPlace<'tcx>, FakeReadCause, hir::HirId)>>,
540539

541-
/// Tracks critical information about regions in a body.
542-
/// This includes containment relationship between regions,
543-
/// liveness relationship between variables and regions and
544-
/// information about yield points.
545-
pub region_scope_tree: ScopeTree,
546-
547540
/// Tracks the rvalue scoping rules which defines finer scoping for rvalue expressions
548541
/// by applying extended parameter rules.
549542
/// Details may be find in `rustc_typeck::check::rvalue_scopes`.
@@ -586,7 +579,6 @@ impl<'tcx> TypeckResults<'tcx> {
586579
concrete_opaque_types: Default::default(),
587580
closure_min_captures: Default::default(),
588581
closure_fake_reads: Default::default(),
589-
region_scope_tree: Default::default(),
590582
rvalue_scopes: Default::default(),
591583
generator_interior_types: ty::Binder::dummy(Default::default()),
592584
treat_byte_string_as_slice: Default::default(),

compiler/rustc_mir_build/src/build/block.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
108108
let_scope_stack.push(remainder_scope);
109109

110110
// Declare the bindings, which may create a source scope.
111-
let remainder_span =
112-
remainder_scope.span(this.tcx, &this.typeck_results.region_scope_tree);
111+
let remainder_span = remainder_scope.span(this.tcx, this.region_scope_tree);
113112

114113
let visibility_scope =
115114
Some(this.new_source_scope(remainder_span, LintLevel::Inherited, None));

compiler/rustc_mir_build/src/build/matches/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
700700
self.cfg.push(block, Statement { source_info, kind: StatementKind::StorageLive(local_id) });
701701
// Altough there is almost always scope for given variable in corner cases
702702
// like #92893 we might get variable with no scope.
703-
if let Some(region_scope) = self.typeck_results.region_scope_tree.var_scope(var.local_id) && schedule_drop{
703+
if let Some(region_scope) = self.region_scope_tree.var_scope(var.local_id) && schedule_drop{
704704
self.schedule_drop(span, region_scope, local_id, DropKind::Storage);
705705
}
706706
Place::from(local_id)
@@ -713,7 +713,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
713713
for_guard: ForGuard,
714714
) {
715715
let local_id = self.var_local_id(var, for_guard);
716-
if let Some(region_scope) = self.typeck_results.region_scope_tree.var_scope(var.local_id) {
716+
if let Some(region_scope) = self.region_scope_tree.var_scope(var.local_id) {
717717
self.schedule_drop(span, region_scope, local_id, DropKind::Value);
718718
}
719719
}

compiler/rustc_mir_build/src/build/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,7 @@ struct Builder<'a, 'tcx> {
398398
tcx: TyCtxt<'tcx>,
399399
infcx: &'a InferCtxt<'a, 'tcx>,
400400
typeck_results: &'tcx TypeckResults<'tcx>,
401+
region_scope_tree: &'tcx region::ScopeTree,
401402
param_env: ty::ParamEnv<'tcx>,
402403

403404
thir: &'a Thir<'tcx>,
@@ -880,6 +881,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
880881
tcx,
881882
infcx,
882883
typeck_results: tcx.typeck_opt_const_arg(def),
884+
region_scope_tree: tcx.region_scope_tree(def.did),
883885
param_env,
884886
def_id: def.did.to_def_id(),
885887
hir_id,

compiler/rustc_mir_build/src/build/scope.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -916,8 +916,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
916916
}
917917

918918
if scope.region_scope == region_scope {
919-
let region_scope_span =
920-
region_scope.span(self.tcx, &self.typeck_results.region_scope_tree);
919+
let region_scope_span = region_scope.span(self.tcx, &self.region_scope_tree);
921920
// Attribute scope exit drops to scope's closing brace.
922921
let scope_end = self.tcx.sess.source_map().end_point(region_scope_span);
923922

compiler/rustc_mir_build/src/thir/cx/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ impl<'tcx> Cx<'tcx> {
7272
tcx,
7373
thir: Thir::new(),
7474
param_env: tcx.param_env(def.did),
75-
region_scope_tree: &typeck_results.region_scope_tree,
75+
region_scope_tree: tcx.region_scope_tree(def.did),
7676
typeck_results,
7777
rvalue_scopes: &typeck_results.rvalue_scopes,
7878
body_owner: def.did.to_def_id(),

compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::astconv::{
44
};
55
use crate::check::callee::{self, DeferredCallResolution};
66
use crate::check::method::{self, MethodCallee, SelfSource};
7-
use crate::check::{region, rvalue_scopes};
7+
use crate::check::rvalue_scopes;
88
use crate::check::{BreakableCtxt, Diverges, Expectation, FnCtxt, LocalTy};
99

1010
use rustc_data_structures::captures::Captures;
@@ -622,10 +622,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
622622
}
623623

624624
pub(in super::super) fn resolve_rvalue_scopes(&self, def_id: DefId) {
625-
let scope_tree = region::region_scope_tree(self.tcx, def_id);
625+
let scope_tree = self.tcx.region_scope_tree(def_id);
626626
let rvalue_scopes = { rvalue_scopes::resolve_rvalue_scopes(self, &scope_tree, def_id) };
627627
let mut typeck_results = self.inh.typeck_results.borrow_mut();
628-
typeck_results.region_scope_tree = scope_tree;
629628
typeck_results.rvalue_scopes = rvalue_scopes;
630629
}
631630

compiler/rustc_typeck/src/check/generator_interior.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ pub fn resolve_interior<'a, 'tcx>(
184184
let mut visitor = InteriorVisitor {
185185
fcx,
186186
types: FxIndexSet::default(),
187-
region_scope_tree: &typeck_results.region_scope_tree,
187+
region_scope_tree: fcx.tcx.region_scope_tree(def_id),
188188
rvalue_scopes: &typeck_results.rvalue_scopes,
189189
expr_count: 0,
190190
kind,
@@ -195,7 +195,7 @@ pub fn resolve_interior<'a, 'tcx>(
195195
intravisit::walk_body(&mut visitor, body);
196196

197197
// Check that we visited the same amount of expressions as the RegionResolutionVisitor
198-
let region_expr_count = typeck_results.region_scope_tree.body_expr_count(body_id).unwrap();
198+
let region_expr_count = fcx.tcx.region_scope_tree(def_id).body_expr_count(body_id).unwrap();
199199
assert_eq!(region_expr_count, visitor.expr_count);
200200

201201
// The types are already kept in insertion order.

0 commit comments

Comments
 (0)