Skip to content

Commit f38c5c8

Browse files
committed
Auto merge of #95656 - cjgillot:no-id-hashing-mode, r=Aaron1011
Remove NodeIdHashingMode. r? `@ghost`
2 parents e3c43e6 + 0927a35 commit f38c5c8

File tree

20 files changed

+85
-389
lines changed

20 files changed

+85
-389
lines changed

compiler/rustc_codegen_llvm/src/debuginfo/metadata/type_map.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::cell::RefCell;
33
use rustc_data_structures::{
44
fingerprint::Fingerprint,
55
fx::FxHashMap,
6-
stable_hasher::{HashStable, NodeIdHashingMode, StableHasher},
6+
stable_hasher::{HashStable, StableHasher},
77
};
88
use rustc_middle::{
99
bug,
@@ -94,11 +94,7 @@ impl<'tcx> UniqueTypeId<'tcx> {
9494
pub fn generate_unique_id_string(self, tcx: TyCtxt<'tcx>) -> String {
9595
let mut hasher = StableHasher::new();
9696
let mut hcx = tcx.create_stable_hashing_context();
97-
hcx.while_hashing_spans(false, |hcx| {
98-
hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
99-
self.hash_stable(hcx, &mut hasher);
100-
});
101-
});
97+
hcx.while_hashing_spans(false, |hcx| self.hash_stable(hcx, &mut hasher));
10298
hasher.finish::<Fingerprint>().to_hex()
10399
}
104100

compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ use rustc_hir::{AsyncGeneratorKind, GeneratorKind, Mutability};
1919
use rustc_middle::ty::layout::{IntegerExt, TyAndLayout};
2020
use rustc_middle::ty::subst::{GenericArgKind, SubstsRef};
2121
use rustc_middle::ty::{self, ExistentialProjection, GeneratorSubsts, ParamEnv, Ty, TyCtxt};
22-
use rustc_query_system::ich::NodeIdHashingMode;
2322
use rustc_target::abi::{Integer, TagEncoding, Variants};
2423
use smallvec::SmallVec;
2524

@@ -704,11 +703,7 @@ fn push_const_param<'tcx>(tcx: TyCtxt<'tcx>, ct: ty::Const<'tcx>, output: &mut S
704703
// but we get a deterministic, virtually unique value for the constant.
705704
let hcx = &mut tcx.create_stable_hashing_context();
706705
let mut hasher = StableHasher::new();
707-
hcx.while_hashing_spans(false, |hcx| {
708-
hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
709-
ct.val().hash_stable(hcx, &mut hasher);
710-
});
711-
});
706+
hcx.while_hashing_spans(false, |hcx| ct.val().hash_stable(hcx, &mut hasher));
712707
// Let's only emit 64 bits of the hash value. That should be plenty for
713708
// avoiding collisions and will make the emitted type names shorter.
714709
let hash: u64 = hasher.finish();

compiler/rustc_data_structures/src/stable_hasher.rs

-7
Original file line numberDiff line numberDiff line change
@@ -612,12 +612,6 @@ fn stable_hash_reduce<HCX, I, C, F>(
612612
}
613613
}
614614

615-
#[derive(PartialEq, Eq, Clone, Copy, Hash, Debug)]
616-
pub enum NodeIdHashingMode {
617-
Ignore,
618-
HashDefPath,
619-
}
620-
621615
/// Controls what data we do or not not hash.
622616
/// Whenever a `HashStable` implementation caches its
623617
/// result, it needs to include `HashingControls` as part
@@ -628,5 +622,4 @@ pub enum NodeIdHashingMode {
628622
#[derive(Clone, Hash, Eq, PartialEq, Debug)]
629623
pub struct HashingControls {
630624
pub hash_spans: bool,
631-
pub node_id_hashing_mode: NodeIdHashingMode,
632625
}

compiler/rustc_hir/src/hir.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -1299,7 +1299,7 @@ pub struct BodyId {
12991299
///
13001300
/// All bodies have an **owner**, which can be accessed via the HIR
13011301
/// map using `body_owner_def_id()`.
1302-
#[derive(Debug)]
1302+
#[derive(Debug, HashStable_Generic)]
13031303
pub struct Body<'hir> {
13041304
pub params: &'hir [Param<'hir>],
13051305
pub value: Expr<'hir>,
@@ -2059,7 +2059,7 @@ pub struct FnSig<'hir> {
20592059
// The bodies for items are stored "out of line", in a separate
20602060
// hashmap in the `Crate`. Here we just record the hir-id of the item
20612061
// so it can fetched later.
2062-
#[derive(Copy, Clone, PartialEq, Eq, Encodable, Debug)]
2062+
#[derive(Copy, Clone, PartialEq, Eq, Encodable, Debug, HashStable_Generic)]
20632063
pub struct TraitItemId {
20642064
pub def_id: LocalDefId,
20652065
}
@@ -2076,7 +2076,7 @@ impl TraitItemId {
20762076
/// possibly including a default implementation. A trait item is
20772077
/// either required (meaning it doesn't have an implementation, just a
20782078
/// signature) or provided (meaning it has a default implementation).
2079-
#[derive(Debug)]
2079+
#[derive(Debug, HashStable_Generic)]
20802080
pub struct TraitItem<'hir> {
20812081
pub ident: Ident,
20822082
pub def_id: LocalDefId,
@@ -2122,7 +2122,7 @@ pub enum TraitItemKind<'hir> {
21222122
// The bodies for items are stored "out of line", in a separate
21232123
// hashmap in the `Crate`. Here we just record the hir-id of the item
21242124
// so it can fetched later.
2125-
#[derive(Copy, Clone, PartialEq, Eq, Encodable, Debug)]
2125+
#[derive(Copy, Clone, PartialEq, Eq, Encodable, Debug, HashStable_Generic)]
21262126
pub struct ImplItemId {
21272127
pub def_id: LocalDefId,
21282128
}
@@ -2136,7 +2136,7 @@ impl ImplItemId {
21362136
}
21372137

21382138
/// Represents anything within an `impl` block.
2139-
#[derive(Debug)]
2139+
#[derive(Debug, HashStable_Generic)]
21402140
pub struct ImplItem<'hir> {
21412141
pub ident: Ident,
21422142
pub def_id: LocalDefId,
@@ -2637,7 +2637,7 @@ pub struct PolyTraitRef<'hir> {
26372637

26382638
pub type Visibility<'hir> = Spanned<VisibilityKind<'hir>>;
26392639

2640-
#[derive(Copy, Clone, Debug)]
2640+
#[derive(Copy, Clone, Debug, HashStable_Generic)]
26412641
pub enum VisibilityKind<'hir> {
26422642
Public,
26432643
Crate(CrateSugar),
@@ -2713,7 +2713,7 @@ impl<'hir> VariantData<'hir> {
27132713
// The bodies for items are stored "out of line", in a separate
27142714
// hashmap in the `Crate`. Here we just record the hir-id of the item
27152715
// so it can fetched later.
2716-
#[derive(Copy, Clone, PartialEq, Eq, Encodable, Debug, Hash)]
2716+
#[derive(Copy, Clone, PartialEq, Eq, Encodable, Debug, Hash, HashStable_Generic)]
27172717
pub struct ItemId {
27182718
pub def_id: LocalDefId,
27192719
}
@@ -2729,7 +2729,7 @@ impl ItemId {
27292729
/// An item
27302730
///
27312731
/// The name might be a dummy name in case of anonymous items
2732-
#[derive(Debug)]
2732+
#[derive(Debug, HashStable_Generic)]
27332733
pub struct Item<'hir> {
27342734
pub ident: Ident,
27352735
pub def_id: LocalDefId,
@@ -2960,7 +2960,7 @@ pub enum AssocItemKind {
29602960
// The bodies for items are stored "out of line", in a separate
29612961
// hashmap in the `Crate`. Here we just record the hir-id of the item
29622962
// so it can fetched later.
2963-
#[derive(Copy, Clone, PartialEq, Eq, Encodable, Debug)]
2963+
#[derive(Copy, Clone, PartialEq, Eq, Encodable, Debug, HashStable_Generic)]
29642964
pub struct ForeignItemId {
29652965
pub def_id: LocalDefId,
29662966
}
@@ -2986,7 +2986,7 @@ pub struct ForeignItemRef {
29862986
pub span: Span,
29872987
}
29882988

2989-
#[derive(Debug)]
2989+
#[derive(Debug, HashStable_Generic)]
29902990
pub struct ForeignItem<'hir> {
29912991
pub ident: Ident,
29922992
pub kind: ForeignItemKind<'hir>,
@@ -3028,7 +3028,7 @@ pub struct Upvar {
30283028
// The TraitCandidate's import_ids is empty if the trait is defined in the same module, and
30293029
// has length > 0 if the trait is found through an chain of imports, starting with the
30303030
// import/use statement in the scope where the trait is used.
3031-
#[derive(Encodable, Decodable, Clone, Debug)]
3031+
#[derive(Encodable, Decodable, Clone, Debug, HashStable_Generic)]
30323032
pub struct TraitCandidate {
30333033
pub def_id: DefId,
30343034
pub import_ids: SmallVec<[LocalDefId; 1]>,

compiler/rustc_hir/src/hir_id.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use std::fmt;
1212
/// incremental compilation where we have to persist things through changes to
1313
/// the code base.
1414
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
15-
#[derive(Encodable, Decodable)]
15+
#[derive(Encodable, Decodable, HashStable_Generic)]
1616
#[rustc_pass_by_value]
1717
pub struct HirId {
1818
pub owner: LocalDefId,
+2-102
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use rustc_data_structures::stable_hasher::{HashStable, StableHasher, ToStableHashKey};
22

33
use crate::hir::{
4-
AttributeMap, BodyId, Crate, Expr, ForeignItem, ForeignItemId, ImplItem, ImplItemId, Item,
5-
ItemId, OwnerNodes, TraitCandidate, TraitItem, TraitItemId, Ty, VisibilityKind,
4+
AttributeMap, BodyId, Crate, Expr, ForeignItemId, ImplItemId, ItemId, OwnerNodes, TraitItemId,
5+
Ty,
66
};
77
use crate::hir_id::{HirId, ItemLocalId};
88
use rustc_span::def_id::DefPathHash;
@@ -13,14 +13,9 @@ use rustc_span::def_id::DefPathHash;
1313
pub trait HashStableContext:
1414
rustc_ast::HashStableContext + rustc_target::HashStableContext
1515
{
16-
fn hash_hir_id(&mut self, _: HirId, hasher: &mut StableHasher);
1716
fn hash_body_id(&mut self, _: BodyId, hasher: &mut StableHasher);
18-
fn hash_reference_to_item(&mut self, _: HirId, hasher: &mut StableHasher);
1917
fn hash_hir_expr(&mut self, _: &Expr<'_>, hasher: &mut StableHasher);
2018
fn hash_hir_ty(&mut self, _: &Ty<'_>, hasher: &mut StableHasher);
21-
fn hash_hir_visibility_kind(&mut self, _: &VisibilityKind<'_>, hasher: &mut StableHasher);
22-
fn hash_hir_item_like<F: FnOnce(&mut Self)>(&mut self, f: F);
23-
fn hash_hir_trait_candidate(&mut self, _: &TraitCandidate, hasher: &mut StableHasher);
2419
}
2520

2621
impl<HirCtx: crate::HashStableContext> ToStableHashKey<HirCtx> for HirId {
@@ -88,12 +83,6 @@ impl<HirCtx: crate::HashStableContext> ToStableHashKey<HirCtx> for ForeignItemId
8883
}
8984
}
9085

91-
impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for HirId {
92-
fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
93-
hcx.hash_hir_id(*self, hasher)
94-
}
95-
}
96-
9786
impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for BodyId {
9887
fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
9988
hcx.hash_body_id(*self, hasher)
@@ -107,30 +96,6 @@ impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for BodyId {
10796
// want to pick up on a reference changing its target, so we hash the NodeIds
10897
// in "DefPath Mode".
10998

110-
impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for ItemId {
111-
fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
112-
hcx.hash_reference_to_item(self.hir_id(), hasher)
113-
}
114-
}
115-
116-
impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for ForeignItemId {
117-
fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
118-
hcx.hash_reference_to_item(self.hir_id(), hasher)
119-
}
120-
}
121-
122-
impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for ImplItemId {
123-
fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
124-
hcx.hash_reference_to_item(self.hir_id(), hasher)
125-
}
126-
}
127-
128-
impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for TraitItemId {
129-
fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
130-
hcx.hash_reference_to_item(self.hir_id(), hasher)
131-
}
132-
}
133-
13499
impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for Expr<'_> {
135100
fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
136101
hcx.hash_hir_expr(self, hasher)
@@ -143,65 +108,6 @@ impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for Ty<'_> {
143108
}
144109
}
145110

146-
impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for VisibilityKind<'_> {
147-
fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
148-
hcx.hash_hir_visibility_kind(self, hasher)
149-
}
150-
}
151-
152-
impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for TraitItem<'_> {
153-
fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
154-
let TraitItem { def_id: _, ident, ref generics, ref kind, span } = *self;
155-
156-
hcx.hash_hir_item_like(|hcx| {
157-
ident.name.hash_stable(hcx, hasher);
158-
generics.hash_stable(hcx, hasher);
159-
kind.hash_stable(hcx, hasher);
160-
span.hash_stable(hcx, hasher);
161-
});
162-
}
163-
}
164-
165-
impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for ImplItem<'_> {
166-
fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
167-
let ImplItem { def_id: _, ident, ref vis, ref generics, ref kind, span } = *self;
168-
169-
hcx.hash_hir_item_like(|hcx| {
170-
ident.name.hash_stable(hcx, hasher);
171-
vis.hash_stable(hcx, hasher);
172-
generics.hash_stable(hcx, hasher);
173-
kind.hash_stable(hcx, hasher);
174-
span.hash_stable(hcx, hasher);
175-
});
176-
}
177-
}
178-
179-
impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for ForeignItem<'_> {
180-
fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
181-
let ForeignItem { def_id: _, ident, ref kind, span, ref vis } = *self;
182-
183-
hcx.hash_hir_item_like(|hcx| {
184-
ident.name.hash_stable(hcx, hasher);
185-
kind.hash_stable(hcx, hasher);
186-
span.hash_stable(hcx, hasher);
187-
vis.hash_stable(hcx, hasher);
188-
});
189-
}
190-
}
191-
192-
impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for Item<'_> {
193-
fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
194-
let Item { ident, def_id: _, ref kind, ref vis, span } = *self;
195-
196-
hcx.hash_hir_item_like(|hcx| {
197-
ident.name.hash_stable(hcx, hasher);
198-
kind.hash_stable(hcx, hasher);
199-
vis.hash_stable(hcx, hasher);
200-
span.hash_stable(hcx, hasher);
201-
});
202-
}
203-
}
204-
205111
impl<'tcx, HirCtx: crate::HashStableContext> HashStable<HirCtx> for OwnerNodes<'tcx> {
206112
fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
207113
// 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<'_> {
235141
hir_hash.hash_stable(hcx, hasher)
236142
}
237143
}
238-
239-
impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for TraitCandidate {
240-
fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
241-
hcx.hash_hir_trait_candidate(self, hasher)
242-
}
243-
}

compiler/rustc_middle/src/middle/privacy.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use rustc_data_structures::fx::FxHashMap;
66
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
77
use rustc_macros::HashStable;
8-
use rustc_query_system::ich::{NodeIdHashingMode, StableHashingContext};
8+
use rustc_query_system::ich::StableHashingContext;
99
use rustc_span::def_id::LocalDefId;
1010
use std::hash::Hash;
1111

@@ -58,9 +58,7 @@ impl<Id> Default for AccessLevels<Id> {
5858

5959
impl<'a> HashStable<StableHashingContext<'a>> for AccessLevels {
6060
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
61-
hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
62-
let AccessLevels { ref map } = *self;
63-
map.hash_stable(hcx, hasher);
64-
});
61+
let AccessLevels { ref map } = *self;
62+
map.hash_stable(hcx, hasher);
6563
}
6664
}

compiler/rustc_middle/src/middle/region.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
1212
use rustc_hir as hir;
1313
use rustc_hir::Node;
1414
use rustc_macros::HashStable;
15-
use rustc_query_system::ich::{NodeIdHashingMode, StableHashingContext};
15+
use rustc_query_system::ich::StableHashingContext;
1616
use rustc_span::{Span, DUMMY_SP};
1717

1818
use std::fmt;
@@ -446,10 +446,7 @@ impl<'a> HashStable<StableHashingContext<'a>> for ScopeTree {
446446
ref yield_in_scope,
447447
} = *self;
448448

449-
hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
450-
root_body.hash_stable(hcx, hasher)
451-
});
452-
449+
root_body.hash_stable(hcx, hasher);
453450
body_expr_count.hash_stable(hcx, hasher);
454451
parent_map.hash_stable(hcx, hasher);
455452
var_map.hash_stable(hcx, hasher);

0 commit comments

Comments
 (0)