Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions compiler/rustc_hir_analysis/src/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,15 @@ use rustc_trait_selection::traits::ObligationCtxt;
use tracing::debug;

use self::compare_impl_item::collect_return_position_impl_trait_in_trait_tys;
use self::region::region_scope_tree;
use self::region::region_scope_tree_root;
use crate::{check_c_variadic_abi, errors};

/// Adds query implementations to the [Providers] vtable, see [`rustc_middle::query`]
pub(super) fn provide(providers: &mut Providers) {
*providers = Providers {
adt_destructor,
adt_async_destructor,
region_scope_tree,
region_scope_tree_root,
collect_return_position_impl_trait_in_trait_tys,
compare_impl_item: compare_impl_item::compare_impl_item,
check_coroutine_obligations: check::check_coroutine_obligations,
Expand Down
7 changes: 2 additions & 5 deletions compiler/rustc_hir_analysis/src/check/region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -849,11 +849,8 @@ impl<'tcx> Visitor<'tcx> for ScopeResolutionVisitor<'tcx> {
/// re-use in incremental scenarios. We may sometimes need to rerun the
/// type checker even when the HIR hasn't changed, and in those cases
/// we can avoid reconstructing the region scope tree.
pub(crate) 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 tcx.region_scope_tree(typeck_root_def_id);
}
pub(crate) fn region_scope_tree_root(tcx: TyCtxt<'_>, def_id: DefId) -> &ScopeTree {
assert!(!tcx.is_typeck_child(def_id));

let scope_tree = if let Some(body) = tcx.hir_maybe_body_owned_by(def_id.expect_local()) {
let mut visitor = ScopeResolutionVisitor {
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_middle/src/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1411,9 +1411,9 @@ rustc_queries! {
cache_on_disk_if { true }
}

/// 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.
query region_scope_tree(def_id: DefId) -> &'tcx crate::middle::region::ScopeTree {
/// Do not call directly! It's query implementation for method
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would call it directly in cases where the caller already has a typeck root.

/// [`TyCtxt::region_scope_tree`] which you should use instead.
query region_scope_tree_root(def_id: DefId) -> &'tcx crate::middle::region::ScopeTree {
desc { "computing drop scopes for `{}`", tcx.def_path_str(def_id) }
}

Expand Down
10 changes: 9 additions & 1 deletion compiler/rustc_middle/src/query/plumbing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ use rustc_data_structures::hash_table::HashTable;
use rustc_data_structures::sharded::Sharded;
use rustc_data_structures::sync::{AtomicU64, Lock, WorkerLocal};
use rustc_errors::Diag;
use rustc_hir::def_id::DefId;
use rustc_span::Span;

use crate::dep_graph::{DepKind, DepNodeIndex, QuerySideEffect, SerializedDepNodeIndex};
use crate::ich::StableHashingContext;
use crate::middle::region::ScopeTree;
use crate::queries::{ExternProviders, Providers, QueryArenas, QueryVTables, TaggedQueryKey};
use crate::query::on_disk_cache::OnDiskCache;
use crate::query::{QueryCache, QueryJob, QueryStackFrame};
use crate::query::{IntoQueryKey, QueryCache, QueryJob, QueryStackFrame};
use crate::ty::TyCtxt;

/// For a particular query, keeps track of "active" keys, i.e. keys whose
Expand Down Expand Up @@ -201,6 +203,12 @@ pub struct TyCtxtEnsureDone<'tcx> {
}

impl<'tcx> TyCtxt<'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(self, def_id: impl IntoQueryKey<DefId>) -> &'tcx ScopeTree {
self.region_scope_tree_root(self.typeck_root_def_id(def_id.into_query_key()))
}

/// Returns a transparent wrapper for `TyCtxt` which uses
/// `span` as the location of queries performed through it.
#[inline(always)]
Expand Down
Loading