Remove NodeIdHashingMode.

This commit is contained in:
Camille GILLOT 2022-04-04 22:19:25 +02:00
parent 341883d051
commit 443333dc1f
16 changed files with 54 additions and 358 deletions

View file

@ -3,7 +3,7 @@
use rustc_data_structures::{
fingerprint::Fingerprint,
fx::FxHashMap,
stable_hasher::{HashStable, NodeIdHashingMode, StableHasher},
stable_hasher::{HashStable, StableHasher},
};
use rustc_middle::{
bug,
@ -94,11 +94,7 @@ pub fn for_vtable_ty(
pub fn generate_unique_id_string(self, tcx: TyCtxt<'tcx>) -> String {
let mut hasher = StableHasher::new();
let mut hcx = tcx.create_stable_hashing_context();
hcx.while_hashing_spans(false, |hcx| {
hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
self.hash_stable(hcx, &mut hasher);
});
});
hcx.while_hashing_spans(false, |hcx| self.hash_stable(hcx, &mut hasher));
hasher.finish::<Fingerprint>().to_hex()
}

View file

@ -19,7 +19,6 @@
use rustc_middle::ty::layout::{IntegerExt, TyAndLayout};
use rustc_middle::ty::subst::{GenericArgKind, SubstsRef};
use rustc_middle::ty::{self, ExistentialProjection, GeneratorSubsts, ParamEnv, Ty, TyCtxt};
use rustc_query_system::ich::NodeIdHashingMode;
use rustc_target::abi::{Integer, TagEncoding, Variants};
use smallvec::SmallVec;
@ -704,11 +703,7 @@ fn push_const_param<'tcx>(tcx: TyCtxt<'tcx>, ct: ty::Const<'tcx>, output: &mut S
// but we get a deterministic, virtually unique value for the constant.
let hcx = &mut tcx.create_stable_hashing_context();
let mut hasher = StableHasher::new();
hcx.while_hashing_spans(false, |hcx| {
hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
ct.val().hash_stable(hcx, &mut hasher);
});
});
hcx.while_hashing_spans(false, |hcx| ct.val().hash_stable(hcx, &mut hasher));
// Let's only emit 64 bits of the hash value. That should be plenty for
// avoiding collisions and will make the emitted type names shorter.
let hash: u64 = hasher.finish();

View file

@ -612,12 +612,6 @@ fn stable_hash_reduce<HCX, I, C, F>(
}
}
#[derive(PartialEq, Eq, Clone, Copy, Hash, Debug)]
pub enum NodeIdHashingMode {
Ignore,
HashDefPath,
}
/// Controls what data we do or not not hash.
/// Whenever a `HashStable` implementation caches its
/// result, it needs to include `HashingControls` as part
@ -628,5 +622,4 @@ pub enum NodeIdHashingMode {
#[derive(Clone, Hash, Eq, PartialEq, Debug)]
pub struct HashingControls {
pub hash_spans: bool,
pub node_id_hashing_mode: NodeIdHashingMode,
}

View file

@ -1265,7 +1265,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>,
@ -2025,7 +2025,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,
}
@ -2042,7 +2042,7 @@ pub fn hir_id(&self) -> HirId {
/// 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,
@ -2088,7 +2088,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,
}
@ -2102,7 +2102,7 @@ pub fn hir_id(&self) -> HirId {
}
/// Represents anything within an `impl` block.
#[derive(Debug)]
#[derive(Debug, HashStable_Generic)]
pub struct ImplItem<'hir> {
pub ident: Ident,
pub def_id: LocalDefId,
@ -2603,7 +2603,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),
@ -2679,7 +2679,7 @@ pub fn ctor_hir_id(&self) -> Option<HirId> {
// 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,
}
@ -2695,7 +2695,7 @@ pub fn hir_id(&self) -> HirId {
/// 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,
@ -2926,7 +2926,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,
}
@ -2952,7 +2952,7 @@ pub struct ForeignItemRef {
pub span: Span,
}
#[derive(Debug)]
#[derive(Debug, HashStable_Generic)]
pub struct ForeignItem<'hir> {
pub ident: Ident,
pub kind: ForeignItemKind<'hir>,
@ -2994,7 +2994,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 @@
/// 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 @@
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 @@ fn to_stable_hash_key(&self, hcx: &HirCtx) -> DefPathHash {
}
}
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 @@ fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
// 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 @@ fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
}
}
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 @@ fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
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)
}
}

View file

@ -5,7 +5,7 @@
use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
use rustc_macros::HashStable;
use rustc_query_system::ich::{NodeIdHashingMode, StableHashingContext};
use rustc_query_system::ich::StableHashingContext;
use rustc_span::def_id::LocalDefId;
use std::hash::Hash;
@ -58,9 +58,7 @@ fn default() -> Self {
impl<'a> HashStable<StableHashingContext<'a>> for AccessLevels {
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
let AccessLevels { ref map } = *self;
map.hash_stable(hcx, hasher);
});
let AccessLevels { ref map } = *self;
map.hash_stable(hcx, hasher);
}
}

View file

@ -12,7 +12,7 @@
use rustc_hir as hir;
use rustc_hir::Node;
use rustc_macros::HashStable;
use rustc_query_system::ich::{NodeIdHashingMode, StableHashingContext};
use rustc_query_system::ich::StableHashingContext;
use rustc_span::{Span, DUMMY_SP};
use std::fmt;
@ -446,10 +446,7 @@ fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHas
ref yield_in_scope,
} = *self;
hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
root_body.hash_stable(hcx, hasher)
});
root_body.hash_stable(hcx, hasher);
body_expr_count.hash_stable(hcx, hasher);
parent_map.hash_stable(hcx, hasher);
var_map.hash_stable(hcx, hasher);

View file

@ -8,7 +8,7 @@
use rustc_hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
use rustc_hir::ItemId;
use rustc_index::vec::Idx;
use rustc_query_system::ich::{NodeIdHashingMode, StableHashingContext};
use rustc_query_system::ich::StableHashingContext;
use rustc_session::config::OptLevel;
use rustc_span::source_map::Span;
use rustc_span::symbol::Symbol;
@ -40,7 +40,7 @@ pub enum InstantiationMode {
LocalCopy,
}
#[derive(PartialEq, Eq, Clone, Copy, Debug, Hash)]
#[derive(PartialEq, Eq, Clone, Copy, Debug, Hash, HashStable)]
pub enum MonoItem<'tcx> {
Fn(Instance<'tcx>),
Static(DefId),
@ -202,26 +202,6 @@ pub fn krate(&self) -> CrateNum {
}
}
impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for MonoItem<'tcx> {
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
::std::mem::discriminant(self).hash_stable(hcx, hasher);
match *self {
MonoItem::Fn(ref instance) => {
instance.hash_stable(hcx, hasher);
}
MonoItem::Static(def_id) => {
def_id.hash_stable(hcx, hasher);
}
MonoItem::GlobalAsm(item_id) => {
hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
item_id.hash_stable(hcx, hasher);
})
}
}
}
}
impl<'tcx> fmt::Display for MonoItem<'tcx> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {

View file

@ -47,7 +47,7 @@
use rustc_index::vec::{Idx, IndexVec};
use rustc_macros::HashStable;
use rustc_middle::mir::FakeReadCause;
use rustc_query_system::ich::{NodeIdHashingMode, StableHashingContext};
use rustc_query_system::ich::StableHashingContext;
use rustc_serialize::opaque::{FileEncodeResult, FileEncoder};
use rustc_session::config::{BorrowckMode, CrateType, OutputFilenames};
use rustc_session::lint::{Level, Lint};
@ -367,7 +367,7 @@ pub struct GeneratorInteriorTypeCause<'tcx> {
pub expr: Option<hir::HirId>,
}
#[derive(TyEncodable, TyDecodable, Debug)]
#[derive(TyEncodable, TyDecodable, Debug, HashStable)]
pub struct TypeckResults<'tcx> {
/// The `HirId::owner` all `ItemLocalId`s in this table are relative to.
pub hir_owner: LocalDefId,
@ -783,62 +783,6 @@ pub fn coercion_casts(&self) -> &ItemLocalSet {
}
}
impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for TypeckResults<'tcx> {
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
let ty::TypeckResults {
hir_owner,
ref type_dependent_defs,
ref field_indices,
ref user_provided_types,
ref user_provided_sigs,
ref node_types,
ref node_substs,
ref adjustments,
ref pat_binding_modes,
ref pat_adjustments,
ref closure_kind_origins,
ref liberated_fn_sigs,
ref fru_field_types,
ref coercion_casts,
ref used_trait_imports,
tainted_by_errors,
ref concrete_opaque_types,
ref closure_min_captures,
ref closure_fake_reads,
ref generator_interior_types,
ref treat_byte_string_as_slice,
ref closure_size_eval,
} = *self;
hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
hcx.local_def_path_hash(hir_owner);
type_dependent_defs.hash_stable(hcx, hasher);
field_indices.hash_stable(hcx, hasher);
user_provided_types.hash_stable(hcx, hasher);
user_provided_sigs.hash_stable(hcx, hasher);
node_types.hash_stable(hcx, hasher);
node_substs.hash_stable(hcx, hasher);
adjustments.hash_stable(hcx, hasher);
pat_binding_modes.hash_stable(hcx, hasher);
pat_adjustments.hash_stable(hcx, hasher);
closure_kind_origins.hash_stable(hcx, hasher);
liberated_fn_sigs.hash_stable(hcx, hasher);
fru_field_types.hash_stable(hcx, hasher);
coercion_casts.hash_stable(hcx, hasher);
used_trait_imports.hash_stable(hcx, hasher);
tainted_by_errors.hash_stable(hcx, hasher);
concrete_opaque_types.hash_stable(hcx, hasher);
closure_min_captures.hash_stable(hcx, hasher);
closure_fake_reads.hash_stable(hcx, hasher);
generator_interior_types.hash_stable(hcx, hasher);
treat_byte_string_as_slice.hash_stable(hcx, hasher);
closure_size_eval.hash_stable(hcx, hasher);
})
}
}
rustc_index::newtype_index! {
pub struct UserTypeAnnotationIndex {
derive [HashStable]

View file

@ -18,7 +18,6 @@
use rustc_hir::def::{CtorOf, DefKind, Res};
use rustc_hir::def_id::DefId;
use rustc_macros::HashStable;
use rustc_query_system::ich::NodeIdHashingMode;
use rustc_span::{sym, DUMMY_SP};
use rustc_target::abi::{Integer, Size, TargetDataLayout};
use smallvec::SmallVec;
@ -136,11 +135,7 @@ pub fn type_id_hash(self, ty: Ty<'tcx>) -> u64 {
// regions, which is desirable too.
let ty = self.erase_regions(ty);
hcx.while_hashing_spans(false, |hcx| {
hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
ty.hash_stable(hcx, &mut hasher);
});
});
hcx.while_hashing_spans(false, |hcx| ty.hash_stable(hcx, &mut hasher));
hasher.finish()
}

View file

@ -2,8 +2,7 @@
use rustc_ast as ast;
use rustc_data_structures::fx::FxHashSet;
use rustc_data_structures::sorted_map::SortedMap;
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
use rustc_data_structures::stable_hasher::{HashingControls, NodeIdHashingMode};
use rustc_data_structures::stable_hasher::{HashStable, HashingControls, StableHasher};
use rustc_data_structures::sync::Lrc;
use rustc_hir as hir;
use rustc_hir::def_id::{DefId, LocalDefId};
@ -69,10 +68,7 @@ fn new_with_or_without_spans(
incremental_ignore_spans: sess.opts.debugging_opts.incremental_ignore_spans,
caching_source_map: None,
raw_source_map: sess.source_map(),
hashing_controls: HashingControls {
hash_spans: hash_spans_initial,
node_id_hashing_mode: NodeIdHashingMode::HashDefPath,
},
hashing_controls: HashingControls { hash_spans: hash_spans_initial },
}
}
@ -138,18 +134,6 @@ pub fn while_hashing_spans<F: FnOnce(&mut Self)>(&mut self, hash_spans: bool, f:
self.hashing_controls.hash_spans = prev_hash_spans;
}
#[inline]
pub fn with_node_id_hashing_mode<F: FnOnce(&mut Self)>(
&mut self,
mode: NodeIdHashingMode,
f: F,
) {
let prev = self.hashing_controls.node_id_hashing_mode;
self.hashing_controls.node_id_hashing_mode = mode;
f(self);
self.hashing_controls.node_id_hashing_mode = prev;
}
#[inline]
pub fn def_path_hash(&self, def_id: DefId) -> DefPathHash {
if let Some(def_id) = def_id.as_local() {
@ -233,9 +217,7 @@ fn hashing_controls(&self) -> HashingControls {
impl<'a> rustc_data_structures::intern::InternedHashingContext for StableHashingContext<'a> {
fn with_def_path_and_no_spans(&mut self, f: impl FnOnce(&mut Self)) {
self.while_hashing_spans(false, |hcx| {
hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| f(hcx))
});
self.while_hashing_spans(false, f);
}
}

View file

@ -2,28 +2,11 @@
//! types in no particular order.
use crate::ich::hcx::BodyResolver;
use crate::ich::{NodeIdHashingMode, StableHashingContext};
use crate::ich::StableHashingContext;
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
use rustc_hir as hir;
use std::mem;
impl<'ctx> rustc_hir::HashStableContext for StableHashingContext<'ctx> {
#[inline]
fn hash_hir_id(&mut self, hir_id: hir::HirId, hasher: &mut StableHasher) {
let hcx = self;
match hcx.hashing_controls.node_id_hashing_mode {
NodeIdHashingMode::Ignore => {
// Don't do anything.
}
NodeIdHashingMode::HashDefPath => {
let hir::HirId { owner, local_id } = hir_id;
hcx.local_def_path_hash(owner).hash_stable(hcx, hasher);
local_id.hash_stable(hcx, hasher);
}
}
}
#[inline]
fn hash_body_id(&mut self, id: hir::BodyId, hasher: &mut StableHasher) {
let hcx = self;
@ -37,19 +20,11 @@ fn hash_body_id(&mut self, id: hir::BodyId, hasher: &mut StableHasher) {
}
}
#[inline]
fn hash_reference_to_item(&mut self, id: hir::HirId, hasher: &mut StableHasher) {
let hcx = self;
hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
id.hash_stable(hcx, hasher);
})
}
fn hash_hir_expr(&mut self, expr: &hir::Expr<'_>, hasher: &mut StableHasher) {
self.while_hashing_hir_bodies(true, |hcx| {
let hir::Expr { hir_id: _, ref span, ref kind } = *expr;
let hir::Expr { hir_id, ref span, ref kind } = *expr;
hir_id.hash_stable(hcx, hasher);
span.hash_stable(hcx, hasher);
kind.hash_stable(hcx, hasher);
})
@ -57,66 +32,11 @@ fn hash_hir_expr(&mut self, expr: &hir::Expr<'_>, hasher: &mut StableHasher) {
fn hash_hir_ty(&mut self, ty: &hir::Ty<'_>, hasher: &mut StableHasher) {
self.while_hashing_hir_bodies(true, |hcx| {
let hir::Ty { hir_id: _, ref kind, ref span } = *ty;
let hir::Ty { hir_id, ref kind, ref span } = *ty;
hir_id.hash_stable(hcx, hasher);
kind.hash_stable(hcx, hasher);
span.hash_stable(hcx, hasher);
})
}
fn hash_hir_visibility_kind(
&mut self,
vis: &hir::VisibilityKind<'_>,
hasher: &mut StableHasher,
) {
let hcx = self;
mem::discriminant(vis).hash_stable(hcx, hasher);
match *vis {
hir::VisibilityKind::Public | hir::VisibilityKind::Inherited => {
// No fields to hash.
}
hir::VisibilityKind::Crate(sugar) => {
sugar.hash_stable(hcx, hasher);
}
hir::VisibilityKind::Restricted { ref path, hir_id } => {
hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
hir_id.hash_stable(hcx, hasher);
});
path.hash_stable(hcx, hasher);
}
}
}
#[inline]
fn hash_hir_item_like<F: FnOnce(&mut Self)>(&mut self, f: F) {
let prev_hash_node_ids = self.hashing_controls.node_id_hashing_mode;
self.hashing_controls.node_id_hashing_mode = NodeIdHashingMode::Ignore;
f(self);
self.hashing_controls.node_id_hashing_mode = prev_hash_node_ids;
}
#[inline]
fn hash_hir_trait_candidate(&mut self, tc: &hir::TraitCandidate, hasher: &mut StableHasher) {
self.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
let hir::TraitCandidate { def_id, import_ids } = tc;
def_id.hash_stable(hcx, hasher);
import_ids.hash_stable(hcx, hasher);
});
}
}
impl<'a> HashStable<StableHashingContext<'a>> for hir::Body<'_> {
#[inline]
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
let hir::Body { params, value, generator_kind } = self;
hcx.with_node_id_hashing_mode(NodeIdHashingMode::Ignore, |hcx| {
params.hash_stable(hcx, hasher);
value.hash_stable(hcx, hasher);
generator_kind.hash_stable(hcx, hasher);
});
}
}

View file

@ -1,7 +1,6 @@
//! ICH - Incremental Compilation Hash
pub use self::hcx::StableHashingContext;
pub use rustc_data_structures::stable_hasher::NodeIdHashingMode;
use rustc_span::symbol::{sym, Symbol};
mod hcx;

View file

@ -117,7 +117,7 @@ fn assert_default_hashing_controls<CTX: HashStableContext>(ctx: &CTX, msg: &str)
// `-Z incremental-ignore-spans` option. Normally, this option is disabled,
// which will cause us to require that this method always be called with `Span` hashing
// enabled.
HashingControls { hash_spans, node_id_hashing_mode: _ }
HashingControls { hash_spans }
if hash_spans == !ctx.debug_opts_incremental_ignore_spans() => {}
other => panic!("Attempted hashing of {msg} with non-default HashingControls: {:?}", other),
}

View file

@ -6,7 +6,6 @@
use rustc_middle::ty::subst::{GenericArg, GenericArgKind};
use rustc_middle::ty::{self, Instance, Ty, TyCtxt, TypeFoldable};
use rustc_middle::util::common::record_time;
use rustc_query_system::ich::NodeIdHashingMode;
use tracing::debug;
@ -111,30 +110,28 @@ fn get_symbol_hash<'tcx>(
// ought to be the same for every reference anyway.
assert!(!item_type.has_erasable_regions());
hcx.while_hashing_spans(false, |hcx| {
hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
item_type.hash_stable(hcx, &mut hasher);
item_type.hash_stable(hcx, &mut hasher);
// If this is a function, we hash the signature as well.
// This is not *strictly* needed, but it may help in some
// situations, see the `run-make/a-b-a-linker-guard` test.
if let ty::FnDef(..) = item_type.kind() {
item_type.fn_sig(tcx).hash_stable(hcx, &mut hasher);
}
// If this is a function, we hash the signature as well.
// This is not *strictly* needed, but it may help in some
// situations, see the `run-make/a-b-a-linker-guard` test.
if let ty::FnDef(..) = item_type.kind() {
item_type.fn_sig(tcx).hash_stable(hcx, &mut hasher);
}
// also include any type parameters (for generic items)
substs.hash_stable(hcx, &mut hasher);
// also include any type parameters (for generic items)
substs.hash_stable(hcx, &mut hasher);
if let Some(instantiating_crate) = instantiating_crate {
tcx.def_path_hash(instantiating_crate.as_def_id())
.stable_crate_id()
.hash_stable(hcx, &mut hasher);
}
if let Some(instantiating_crate) = instantiating_crate {
tcx.def_path_hash(instantiating_crate.as_def_id())
.stable_crate_id()
.hash_stable(hcx, &mut hasher);
}
// We want to avoid accidental collision between different types of instances.
// Especially, `VtableShim`s and `ReifyShim`s may overlap with their original
// instances without this.
discriminant(&instance.def).hash_stable(hcx, &mut hasher);
});
// We want to avoid accidental collision between different types of instances.
// Especially, `VtableShim`s and `ReifyShim`s may overlap with their original
// instances without this.
discriminant(&instance.def).hash_stable(hcx, &mut hasher);
});
});