Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[do not merge] Test performance impact of accessing the HIR map through a query #57024

Closed
wants to merge 2 commits into from
Closed
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
1 change: 1 addition & 0 deletions src/librustc/dep_graph/dep_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,7 @@ define_dep_nodes!( <'tcx>
// table in the tcx (or elsewhere) maps to one of these
// nodes.
[] AssociatedItems(DefId),
[] HirQuery(CrateNum),
[] TypeOfItem(DefId),
[] GenericsOfItem(DefId),
[] PredicatesOfItem(DefId),
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/hir/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ impl<'hir> Entry<'hir> {

/// Stores a crate and any number of inlined items from other crates.
pub struct Forest {
krate: Crate,
pub(crate) krate: Crate,
pub dep_graph: DepGraph,
}

Expand Down
8 changes: 8 additions & 0 deletions src/librustc/ich/impls_hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ use std::mem;
use syntax::ast;
use syntax::attr;

impl<'a> HashStable<StableHashingContext<'a>> for hir::map::Map<'_> {
#[inline]
fn hash_stable<W: StableHasherResult>(&self,
_hcx: &mut StableHashingContext<'a>,
_hasher: &mut StableHasher<W>) {
}
}

impl<'a> HashStable<StableHashingContext<'a>> for DefId {
#[inline]
fn hash_stable<W: StableHasherResult>(&self,
Expand Down
11 changes: 6 additions & 5 deletions src/librustc/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -957,7 +957,7 @@ pub struct GlobalCtxt<'tcx> {
/// Export map produced by name resolution.
export_map: FxHashMap<DefId, Lrc<Vec<Export>>>,

hir_map: hir_map::Map<'tcx>,
pub hir_map: hir_map::Map<'tcx>,

/// A map from DefPathHash -> DefId. Includes DefIds from the local crate
/// as well as all upstream crates. Only populated in incremental mode.
Expand Down Expand Up @@ -1028,7 +1028,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {

#[inline(always)]
pub fn hir(self) -> &'a hir_map::Map<'gcx> {
&self.hir_map
self.hir_query(LOCAL_CRATE)
}

pub fn alloc_generics(self, generics: ty::Generics) -> &'gcx ty::Generics {
Expand Down Expand Up @@ -1334,7 +1334,8 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
#[inline]
pub fn def_path_hash(self, def_id: DefId) -> hir_map::DefPathHash {
if def_id.is_local() {
self.hir().definitions().def_path_hash(def_id.index)
// FIXME: This is used when executing the hir query, can't use hir() here
self.hir_map.definitions().def_path_hash(def_id.index)
} else {
self.cstore.def_path_hash(def_id)
}
Expand Down Expand Up @@ -1373,11 +1374,11 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {

#[inline(always)]
pub fn create_stable_hashing_context(self) -> StableHashingContext<'a> {
// FIXME: This is used when executing the hir query, can't use hir() here
let krate = self.gcx.hir_map.forest.untracked_krate();

StableHashingContext::new(self.sess,
krate,
self.hir().definitions(),
self.hir_map.definitions(),
self.cstore)
}

Expand Down
6 changes: 6 additions & 0 deletions src/librustc/ty/query/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,12 @@ impl<'tcx> QueryDescription<'tcx> for queries::crate_disambiguator<'tcx> {
}
}

impl<'tcx> QueryDescription<'tcx> for queries::hir_query<'tcx> {
fn describe(_tcx: TyCtxt<'_, '_, '_>, _: CrateNum) -> Cow<'static, str> {
"hir_query".into()
}
}

impl<'tcx> QueryDescription<'tcx> for queries::crate_hash<'tcx> {
fn describe(_tcx: TyCtxt<'_, '_, '_>, _: CrateNum) -> Cow<'static, str> {
"looking up the hash a crate".into()
Expand Down
3 changes: 3 additions & 0 deletions src/librustc/ty/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ pub use self::on_disk_cache::OnDiskCache;
// as they will raise an fatal error on query cycles instead.
define_queries! { <'tcx>
Other {
/// Records the type of every item.
[] fn hir_query: HirQuery(CrateNum) -> &'tcx hir::map::Map<'tcx>,

/// Records the type of every item.
[] fn type_of: TypeOfItem(DefId) -> Ty<'tcx>,

Expand Down
1 change: 1 addition & 0 deletions src/librustc/ty/query/plumbing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1263,6 +1263,7 @@ pub fn force_from_dep_node<'a, 'gcx, 'lcx>(tcx: TyCtxt<'a, 'gcx, 'lcx>,
DepKind::MirKeys => { force!(mir_keys, LOCAL_CRATE); }
DepKind::CrateVariances => { force!(crate_variances, LOCAL_CRATE); }
DepKind::AssociatedItems => { force!(associated_item, def_id!()); }
DepKind::HirQuery => { force!(hir_query, LOCAL_CRATE); }
DepKind::TypeOfItem => { force!(type_of, def_id!()); }
DepKind::GenericsOfItem => { force!(generics_of, def_id!()); }
DepKind::PredicatesOfItem => { force!(predicates_of, def_id!()); }
Expand Down
6 changes: 6 additions & 0 deletions src/librustc_typeck/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ pub fn collect_item_types<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {

pub fn provide(providers: &mut Providers) {
*providers = Providers {
hir_query,
type_of,
generics_of,
predicates_of,
Expand Down Expand Up @@ -1111,6 +1112,11 @@ fn report_assoc_ty_on_inherent_impl<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, span:
);
}

fn hir_query<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, _: hir::def_id::CrateNum
) -> &'tcx hir::map::Map<'tcx> {
&tcx.hir_map
}

fn type_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Ty<'tcx> {
use rustc::hir::*;

Expand Down