1
Fork 0

Auto merge of #95656 - cjgillot:no-id-hashing-mode, r=Aaron1011

Remove NodeIdHashingMode.

r? `@ghost`
This commit is contained in:
bors 2022-04-13 11:27:17 +00:00
commit f38c5c8e5d
20 changed files with 84 additions and 388 deletions

View file

@ -1299,7 +1299,7 @@ pub struct BodyId {
///
/// All bodies have an **owner**, which can be accessed via the HIR
/// map using `body_owner_def_id()`.
#[derive(Debug)]
#[derive(Debug, HashStable_Generic)]
pub struct Body<'hir> {
pub params: &'hir [Param<'hir>],
pub value: Expr<'hir>,
@ -2059,7 +2059,7 @@ pub struct FnSig<'hir> {
// The bodies for items are stored "out of line", in a separate
// hashmap in the `Crate`. Here we just record the hir-id of the item
// so it can fetched later.
#[derive(Copy, Clone, PartialEq, Eq, Encodable, Debug)]
#[derive(Copy, Clone, PartialEq, Eq, Encodable, Debug, HashStable_Generic)]
pub struct TraitItemId {
pub def_id: LocalDefId,
}
@ -2076,7 +2076,7 @@ impl TraitItemId {
/// possibly including a default implementation. A trait item is
/// either required (meaning it doesn't have an implementation, just a
/// signature) or provided (meaning it has a default implementation).
#[derive(Debug)]
#[derive(Debug, HashStable_Generic)]
pub struct TraitItem<'hir> {
pub ident: Ident,
pub def_id: LocalDefId,
@ -2122,7 +2122,7 @@ pub enum TraitItemKind<'hir> {
// The bodies for items are stored "out of line", in a separate
// hashmap in the `Crate`. Here we just record the hir-id of the item
// so it can fetched later.
#[derive(Copy, Clone, PartialEq, Eq, Encodable, Debug)]
#[derive(Copy, Clone, PartialEq, Eq, Encodable, Debug, HashStable_Generic)]
pub struct ImplItemId {
pub def_id: LocalDefId,
}
@ -2136,7 +2136,7 @@ impl ImplItemId {
}
/// Represents anything within an `impl` block.
#[derive(Debug)]
#[derive(Debug, HashStable_Generic)]
pub struct ImplItem<'hir> {
pub ident: Ident,
pub def_id: LocalDefId,
@ -2637,7 +2637,7 @@ pub struct PolyTraitRef<'hir> {
pub type Visibility<'hir> = Spanned<VisibilityKind<'hir>>;
#[derive(Copy, Clone, Debug)]
#[derive(Copy, Clone, Debug, HashStable_Generic)]
pub enum VisibilityKind<'hir> {
Public,
Crate(CrateSugar),
@ -2713,7 +2713,7 @@ impl<'hir> VariantData<'hir> {
// The bodies for items are stored "out of line", in a separate
// hashmap in the `Crate`. Here we just record the hir-id of the item
// so it can fetched later.
#[derive(Copy, Clone, PartialEq, Eq, Encodable, Debug, Hash)]
#[derive(Copy, Clone, PartialEq, Eq, Encodable, Debug, Hash, HashStable_Generic)]
pub struct ItemId {
pub def_id: LocalDefId,
}
@ -2729,7 +2729,7 @@ impl ItemId {
/// An item
///
/// The name might be a dummy name in case of anonymous items
#[derive(Debug)]
#[derive(Debug, HashStable_Generic)]
pub struct Item<'hir> {
pub ident: Ident,
pub def_id: LocalDefId,
@ -2960,7 +2960,7 @@ pub enum AssocItemKind {
// The bodies for items are stored "out of line", in a separate
// hashmap in the `Crate`. Here we just record the hir-id of the item
// so it can fetched later.
#[derive(Copy, Clone, PartialEq, Eq, Encodable, Debug)]
#[derive(Copy, Clone, PartialEq, Eq, Encodable, Debug, HashStable_Generic)]
pub struct ForeignItemId {
pub def_id: LocalDefId,
}
@ -2986,7 +2986,7 @@ pub struct ForeignItemRef {
pub span: Span,
}
#[derive(Debug)]
#[derive(Debug, HashStable_Generic)]
pub struct ForeignItem<'hir> {
pub ident: Ident,
pub kind: ForeignItemKind<'hir>,
@ -3028,7 +3028,7 @@ pub struct Upvar {
// The TraitCandidate's import_ids is empty if the trait is defined in the same module, and
// has length > 0 if the trait is found through an chain of imports, starting with the
// import/use statement in the scope where the trait is used.
#[derive(Encodable, Decodable, Clone, Debug)]
#[derive(Encodable, Decodable, Clone, Debug, HashStable_Generic)]
pub struct TraitCandidate {
pub def_id: DefId,
pub import_ids: SmallVec<[LocalDefId; 1]>,

View file

@ -12,7 +12,7 @@ use std::fmt;
/// incremental compilation where we have to persist things through changes to
/// the code base.
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
#[derive(Encodable, Decodable)]
#[derive(Encodable, Decodable, HashStable_Generic)]
#[rustc_pass_by_value]
pub struct HirId {
pub owner: LocalDefId,

View file

@ -1,8 +1,8 @@
use rustc_data_structures::stable_hasher::{HashStable, StableHasher, ToStableHashKey};
use crate::hir::{
AttributeMap, BodyId, Crate, Expr, ForeignItem, ForeignItemId, ImplItem, ImplItemId, Item,
ItemId, OwnerNodes, TraitCandidate, TraitItem, TraitItemId, Ty, VisibilityKind,
AttributeMap, BodyId, Crate, Expr, ForeignItemId, ImplItemId, ItemId, OwnerNodes, TraitItemId,
Ty,
};
use crate::hir_id::{HirId, ItemLocalId};
use rustc_span::def_id::DefPathHash;
@ -13,14 +13,9 @@ use rustc_span::def_id::DefPathHash;
pub trait HashStableContext:
rustc_ast::HashStableContext + rustc_target::HashStableContext
{
fn hash_hir_id(&mut self, _: HirId, hasher: &mut StableHasher);
fn hash_body_id(&mut self, _: BodyId, hasher: &mut StableHasher);
fn hash_reference_to_item(&mut self, _: HirId, hasher: &mut StableHasher);
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);
fn hash_hir_trait_candidate(&mut self, _: &TraitCandidate, hasher: &mut StableHasher);
}
impl<HirCtx: crate::HashStableContext> ToStableHashKey<HirCtx> for HirId {
@ -88,12 +83,6 @@ impl<HirCtx: crate::HashStableContext> ToStableHashKey<HirCtx> for ForeignItemId
}
}
impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for HirId {
fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
hcx.hash_hir_id(*self, hasher)
}
}
impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for BodyId {
fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
hcx.hash_body_id(*self, hasher)
@ -107,30 +96,6 @@ impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for BodyId {
// want to pick up on a reference changing its target, so we hash the NodeIds
// in "DefPath Mode".
impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for ItemId {
fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
hcx.hash_reference_to_item(self.hir_id(), hasher)
}
}
impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for ForeignItemId {
fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
hcx.hash_reference_to_item(self.hir_id(), hasher)
}
}
impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for ImplItemId {
fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
hcx.hash_reference_to_item(self.hir_id(), hasher)
}
}
impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for TraitItemId {
fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
hcx.hash_reference_to_item(self.hir_id(), hasher)
}
}
impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for Expr<'_> {
fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
hcx.hash_hir_expr(self, hasher)
@ -143,65 +108,6 @@ impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for Ty<'_> {
}
}
impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for VisibilityKind<'_> {
fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
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 { def_id: _, ident, ref generics, ref kind, span } = *self;
hcx.hash_hir_item_like(|hcx| {
ident.name.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 { def_id: _, ident, ref vis, ref generics, ref kind, span } = *self;
hcx.hash_hir_item_like(|hcx| {
ident.name.hash_stable(hcx, hasher);
vis.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 ForeignItem<'_> {
fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
let ForeignItem { def_id: _, ident, ref kind, span, ref vis } = *self;
hcx.hash_hir_item_like(|hcx| {
ident.name.hash_stable(hcx, hasher);
kind.hash_stable(hcx, hasher);
span.hash_stable(hcx, hasher);
vis.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, def_id: _, ref kind, ref vis, span } = *self;
hcx.hash_hir_item_like(|hcx| {
ident.name.hash_stable(hcx, hasher);
kind.hash_stable(hcx, hasher);
vis.hash_stable(hcx, hasher);
span.hash_stable(hcx, hasher);
});
}
}
impl<'tcx, HirCtx: crate::HashStableContext> HashStable<HirCtx> for OwnerNodes<'tcx> {
fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
// We ignore the `nodes` and `bodies` fields since these refer to information included in
@ -235,9 +141,3 @@ impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for Crate<'_> {
hir_hash.hash_stable(hcx, hasher)
}
}
impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for TraitCandidate {
fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
hcx.hash_hir_trait_candidate(self, hasher)
}
}