Skip to content

Commit d59968b

Browse files
committed
Simplify BodyId hashing.
1 parent 20a8a23 commit d59968b

File tree

7 files changed

+6
-69
lines changed

7 files changed

+6
-69
lines changed

compiler/rustc_ast_lowering/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -662,9 +662,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
662662
let (opt_hash_including_bodies, attrs_hash) = if self.tcx.needs_crate_hash() {
663663
self.tcx.with_stable_hashing_context(|mut hcx| {
664664
let mut stable_hasher = StableHasher::new();
665-
hcx.with_hir_bodies(node.def_id(), &bodies, |hcx| {
666-
node.hash_stable(hcx, &mut stable_hasher)
667-
});
665+
node.hash_stable(&mut hcx, &mut stable_hasher);
666+
// Bodies are stored out of line, so we need to pull them explicitly in the hash.
667+
bodies.hash_stable(&mut hcx, &mut stable_hasher);
668668
let h1 = stable_hasher.finish();
669669

670670
let mut stable_hasher = StableHasher::new();

compiler/rustc_hir/src/hir.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1302,7 +1302,7 @@ pub enum UnsafeSource {
13021302
UserProvided,
13031303
}
13041304

1305-
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
1305+
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, HashStable_Generic)]
13061306
pub struct BodyId {
13071307
pub hir_id: HirId,
13081308
}

compiler/rustc_hir/src/stable_hash_impls.rs

-7
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use rustc_span::def_id::DefPathHash;
1212
pub trait HashStableContext:
1313
rustc_ast::HashStableContext + rustc_target::HashStableContext
1414
{
15-
fn hash_body_id(&mut self, _: BodyId, hasher: &mut StableHasher);
1615
}
1716

1817
impl<HirCtx: crate::HashStableContext> ToStableHashKey<HirCtx> for HirId {
@@ -80,12 +79,6 @@ impl<HirCtx: crate::HashStableContext> ToStableHashKey<HirCtx> for ForeignItemId
8079
}
8180
}
8281

83-
impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for BodyId {
84-
fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
85-
hcx.hash_body_id(*self, hasher)
86-
}
87-
}
88-
8982
// The following implementations of HashStable for `ItemId`, `TraitItemId`, and
9083
// `ImplItemId` deserve special attention. Normally we do not hash `NodeId`s within
9184
// the HIR, since they just signify a HIR nodes own path. But `ItemId` et al

compiler/rustc_query_system/src/ich/hcx.rs

-35
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
use crate::ich;
22

33
use rustc_ast as ast;
4-
use rustc_data_structures::sorted_map::SortedMap;
54
use rustc_data_structures::stable_hasher::{HashStable, HashingControls, StableHasher};
65
use rustc_data_structures::sync::Lrc;
7-
use rustc_hir as hir;
86
use rustc_hir::def_id::{DefId, LocalDefId};
97
use rustc_hir::definitions::DefPathHash;
108
use rustc_session::cstore::Untracked;
@@ -23,34 +21,19 @@ pub struct StableHashingContext<'a> {
2321
// The value of `-Z incremental-ignore-spans`.
2422
// This field should only be used by `unstable_opts_incremental_ignore_span`
2523
incremental_ignore_spans: bool,
26-
pub(super) body_resolver: BodyResolver<'a>,
2724
// Very often, we are hashing something that does not need the
2825
// `CachingSourceMapView`, so we initialize it lazily.
2926
raw_source_map: &'a SourceMap,
3027
caching_source_map: Option<CachingSourceMapView<'a>>,
3128
hashing_controls: HashingControls,
3229
}
3330

34-
/// The `BodyResolver` allows mapping a `BodyId` to the corresponding `hir::Body`.
35-
/// We could also just store a plain reference to the `hir::Crate` but we want
36-
/// to avoid that the crate is used to get untracked access to all of the HIR.
37-
#[derive(Clone, Copy)]
38-
pub(super) enum BodyResolver<'tcx> {
39-
Forbidden,
40-
Ignore,
41-
Traverse {
42-
owner: hir::OwnerId,
43-
bodies: &'tcx SortedMap<hir::ItemLocalId, &'tcx hir::Body<'tcx>>,
44-
},
45-
}
46-
4731
impl<'a> StableHashingContext<'a> {
4832
#[inline]
4933
pub fn new(sess: &'a Session, untracked: &'a Untracked) -> Self {
5034
let hash_spans_initial = !sess.opts.unstable_opts.incremental_ignore_spans;
5135

5236
StableHashingContext {
53-
body_resolver: BodyResolver::Forbidden,
5437
untracked,
5538
incremental_ignore_spans: sess.opts.unstable_opts.incremental_ignore_spans,
5639
caching_source_map: None,
@@ -59,24 +42,6 @@ impl<'a> StableHashingContext<'a> {
5942
}
6043
}
6144

62-
#[inline]
63-
pub fn without_hir_bodies(&mut self, f: impl FnOnce(&mut StableHashingContext<'_>)) {
64-
f(&mut StableHashingContext { body_resolver: BodyResolver::Ignore, ..self.clone() });
65-
}
66-
67-
#[inline]
68-
pub fn with_hir_bodies(
69-
&mut self,
70-
owner: hir::OwnerId,
71-
bodies: &SortedMap<hir::ItemLocalId, &hir::Body<'_>>,
72-
f: impl FnOnce(&mut StableHashingContext<'_>),
73-
) {
74-
f(&mut StableHashingContext {
75-
body_resolver: BodyResolver::Traverse { owner, bodies },
76-
..self.clone()
77-
});
78-
}
79-
8045
#[inline]
8146
pub fn while_hashing_spans<F: FnOnce(&mut Self)>(&mut self, hash_spans: bool, f: F) {
8247
let prev_hash_spans = self.hashing_controls.hash_spans;

compiler/rustc_query_system/src/ich/impls_hir.rs

-22
This file was deleted.

compiler/rustc_query_system/src/ich/impls_syntax.rs

+2
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ impl<'ctx> rustc_ast::HashStableContext for StableHashingContext<'ctx> {
5757
}
5858
}
5959

60+
impl<'ctx> rustc_hir::HashStableContext for StableHashingContext<'ctx> {}
61+
6062
impl<'a> HashStable<StableHashingContext<'a>> for SourceFile {
6163
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
6264
let SourceFile {

compiler/rustc_query_system/src/ich/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ pub use self::hcx::StableHashingContext;
44
use rustc_span::symbol::{sym, Symbol};
55

66
mod hcx;
7-
mod impls_hir;
87
mod impls_syntax;
98

109
pub const IGNORED_ATTRIBUTES: &[Symbol] = &[

0 commit comments

Comments
 (0)