use crate::ty::query::Providers;
use crate::ty::TyCtxt;
+use rustc_data_structures::fx::FxHashMap;
use rustc_hir::def_id::{DefId, LOCAL_CRATE};
use rustc_hir::print;
+use rustc_hir::Body;
use rustc_hir::Crate;
use rustc_hir::HirId;
+use rustc_hir::ItemLocalId;
+use rustc_hir::Node;
+use rustc_index::vec::IndexVec;
use std::ops::Deref;
+#[derive(HashStable)]
+pub struct HirOwner<'tcx> {
+ parent: HirId,
+ node: Node<'tcx>,
+}
+
+#[derive(HashStable)]
+pub struct HirItem<'tcx> {
+ parent: ItemLocalId,
+ node: Node<'tcx>,
+}
+
+#[derive(HashStable)]
+pub struct HirOwnerItems<'tcx> {
+ owner: &'tcx HirOwner<'tcx>,
+ items: IndexVec<ItemLocalId, Option<HirItem<'tcx>>>,
+ bodies: FxHashMap<ItemLocalId, &'tcx Body<'tcx>>,
+}
+
/// A wrapper type which allows you to access HIR.
#[derive(Clone)]
pub struct Hir<'tcx> {
}
IGNORED_ATTRIBUTES.with(|attrs| attrs.contains(&name))
}
-
- pub fn hash_hir_item_like<F: FnOnce(&mut Self)>(&mut self, f: F) {
- let prev_hash_node_ids = self.node_id_hashing_mode;
- self.node_id_hashing_mode = NodeIdHashingMode::Ignore;
-
- f(self);
-
- self.node_id_hashing_mode = prev_hash_node_ids;
- }
}
/// Something that can provide a stable hashing context.
}
}
}
+
+ fn hash_hir_item_like<F: FnOnce(&mut Self)>(&mut self, f: F) {
+ let prev_hash_node_ids = self.node_id_hashing_mode;
+ self.node_id_hashing_mode = NodeIdHashingMode::Ignore;
+
+ f(self);
+
+ self.node_id_hashing_mode = prev_hash_node_ids;
+ }
}
impl<'a> ToStableHashKey<StableHashingContext<'a>> for DefId {
}
}
-impl<'a> HashStable<StableHashingContext<'a>> for hir::TraitItem<'_> {
- fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
- let hir::TraitItem { hir_id: _, ident, ref attrs, ref generics, ref kind, span } = *self;
-
- hcx.hash_hir_item_like(|hcx| {
- ident.name.hash_stable(hcx, hasher);
- attrs.hash_stable(hcx, hasher);
- generics.hash_stable(hcx, hasher);
- kind.hash_stable(hcx, hasher);
- span.hash_stable(hcx, hasher);
- });
- }
-}
-
-impl<'a> HashStable<StableHashingContext<'a>> for hir::ImplItem<'_> {
- fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
- let hir::ImplItem {
- hir_id: _,
- ident,
- ref vis,
- defaultness,
- ref attrs,
- ref generics,
- ref kind,
- span,
- } = *self;
-
- hcx.hash_hir_item_like(|hcx| {
- ident.name.hash_stable(hcx, hasher);
- vis.hash_stable(hcx, hasher);
- defaultness.hash_stable(hcx, hasher);
- attrs.hash_stable(hcx, hasher);
- generics.hash_stable(hcx, hasher);
- kind.hash_stable(hcx, hasher);
- span.hash_stable(hcx, hasher);
- });
- }
-}
-
-impl<'a> HashStable<StableHashingContext<'a>> for hir::Item<'_> {
- fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
- let hir::Item { ident, ref attrs, hir_id: _, ref kind, ref vis, span } = *self;
-
- hcx.hash_hir_item_like(|hcx| {
- ident.name.hash_stable(hcx, hasher);
- attrs.hash_stable(hcx, hasher);
- kind.hash_stable(hcx, hasher);
- vis.hash_stable(hcx, hasher);
- span.hash_stable(hcx, hasher);
- });
- }
-}
-
impl<'a> HashStable<StableHashingContext<'a>> for hir::Body<'_> {
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
let hir::Body { params, value, generator_kind } = self;
desc { "get the crate HIR" }
}
+ query hir_owner(key: DefId) -> &'tcx HirOwner<'tcx> {
+ eval_always
+ }
+
+ query hir_owner_items(key: DefId) -> &'tcx HirOwnerItems<'tcx> {
+ eval_always
+ }
+
/// Records the type of every item.
query type_of(key: DefId) -> Ty<'tcx> {
cache_on_disk_if { key.is_local() }
use crate::dep_graph::{self, DepConstructor, DepNode, DepNodeParams};
use crate::hir::exports::Export;
+use crate::hir::{HirOwner, HirOwnerItems};
use crate::infer::canonical::{self, Canonical};
use crate::lint::LintLevelMap;
use crate::middle::codegen_fn_attrs::CodegenFnAttrs;
// imported.
pub type GlobMap = NodeMap<FxHashSet<Name>>;
-#[derive(Copy, Clone, Debug)]
+#[derive(Copy, Clone, Debug, HashStable_Generic)]
pub enum Node<'hir> {
Param(&'hir Param<'hir>),
Item(&'hir Item<'hir>),
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
-use crate::hir::{BodyId, Expr, ImplItemId, ItemId, Mod, TraitItemId, Ty, VisibilityKind};
+use crate::hir::{
+ BodyId, Expr, ImplItem, ImplItemId, Item, ItemId, Mod, TraitItem, TraitItemId, Ty,
+ VisibilityKind,
+};
use crate::hir_id::HirId;
/// Requirements for a `StableHashingContext` to be used in this crate.
fn hash_hir_expr(&mut self, _: &Expr<'_>, hasher: &mut StableHasher);
fn hash_hir_ty(&mut self, _: &Ty<'_>, hasher: &mut StableHasher);
fn hash_hir_visibility_kind(&mut self, _: &VisibilityKind<'_>, hasher: &mut StableHasher);
+ fn hash_hir_item_like<F: FnOnce(&mut Self)>(&mut self, f: F);
}
impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for HirId {
hcx.hash_hir_visibility_kind(self, hasher)
}
}
+
+impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for TraitItem<'_> {
+ fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
+ let TraitItem { hir_id: _, ident, ref attrs, ref generics, ref kind, span } = *self;
+
+ hcx.hash_hir_item_like(|hcx| {
+ ident.name.hash_stable(hcx, hasher);
+ attrs.hash_stable(hcx, hasher);
+ generics.hash_stable(hcx, hasher);
+ kind.hash_stable(hcx, hasher);
+ span.hash_stable(hcx, hasher);
+ });
+ }
+}
+
+impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for ImplItem<'_> {
+ fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
+ let ImplItem {
+ hir_id: _,
+ ident,
+ ref vis,
+ defaultness,
+ ref attrs,
+ ref generics,
+ ref kind,
+ span,
+ } = *self;
+
+ hcx.hash_hir_item_like(|hcx| {
+ ident.name.hash_stable(hcx, hasher);
+ vis.hash_stable(hcx, hasher);
+ defaultness.hash_stable(hcx, hasher);
+ attrs.hash_stable(hcx, hasher);
+ generics.hash_stable(hcx, hasher);
+ kind.hash_stable(hcx, hasher);
+ span.hash_stable(hcx, hasher);
+ });
+ }
+}
+
+impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for Item<'_> {
+ fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
+ let Item { ident, ref attrs, hir_id: _, ref kind, ref vis, span } = *self;
+
+ hcx.hash_hir_item_like(|hcx| {
+ ident.name.hash_stable(hcx, hasher);
+ attrs.hash_stable(hcx, hasher);
+ kind.hash_stable(hcx, hasher);
+ vis.hash_stable(hcx, hasher);
+ span.hash_stable(hcx, hasher);
+ });
+ }
+}