Skip to content

Commit d47424b

Browse files
committed
Hash spans when interning.
1 parent c42a424 commit d47424b

File tree

3 files changed

+6
-50
lines changed

3 files changed

+6
-50
lines changed

compiler/rustc_data_structures/src/intern.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,6 @@ where
110110
}
111111
}
112112

113-
/// A helper trait so that `Interned` things can cache stable hashes reproducibly.
114-
pub trait InternedHashingContext {
115-
fn with_def_path_and_no_spans(&mut self, f: impl FnOnce(&mut Self));
116-
}
117-
118113
/// A helper type that you can wrap round your own type in order to automatically
119114
/// cache the stable hash on creation and not recompute it whenever the stable hash
120115
/// of the type is computed.
@@ -165,7 +160,7 @@ impl<T: Hash> Hash for WithStableHash<T> {
165160
}
166161
}
167162

168-
impl<T: HashStable<CTX>, CTX: InternedHashingContext> HashStable<CTX> for WithStableHash<T> {
163+
impl<T: HashStable<CTX>, CTX> HashStable<CTX> for WithStableHash<T> {
169164
fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) {
170165
if self.stable_hash == Fingerprint::ZERO || cfg!(debug_assertions) {
171166
// No cached hash available. This can only mean that incremental is disabled.
@@ -176,7 +171,7 @@ impl<T: HashStable<CTX>, CTX: InternedHashingContext> HashStable<CTX> for WithSt
176171
// otherwise the hashes will differ between cached and non-cached mode.
177172
let stable_hash: Fingerprint = {
178173
let mut hasher = StableHasher::new();
179-
hcx.with_def_path_and_no_spans(|hcx| self.internee.hash_stable(hcx, &mut hasher));
174+
self.internee.hash_stable(hcx, &mut hasher);
180175
hasher.finish()
181176
};
182177
if cfg!(debug_assertions) && self.stable_hash != Fingerprint::ZERO {

compiler/rustc_middle/src/ty/context.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -198,12 +198,8 @@ impl<'tcx> CtxtInterners<'tcx> {
198198
Fingerprint::ZERO
199199
} else {
200200
let mut hasher = StableHasher::new();
201-
let mut hcx = StableHashingContext::ignore_spans(
202-
sess,
203-
definitions,
204-
cstore,
205-
source_span,
206-
);
201+
let mut hcx =
202+
StableHashingContext::new(sess, definitions, cstore, source_span);
207203
kind.hash_stable(&mut hcx, &mut hasher);
208204
hasher.finish()
209205
};

compiler/rustc_query_system/src/ich/hcx.rs

+2-37
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,13 @@ pub(super) enum BodyResolver<'tcx> {
4949

5050
impl<'a> StableHashingContext<'a> {
5151
#[inline]
52-
fn new_with_or_without_spans(
52+
pub fn new(
5353
sess: &'a Session,
5454
definitions: &'a Definitions,
5555
cstore: &'a dyn CrateStore,
5656
source_span: &'a IndexVec<LocalDefId, Span>,
57-
always_ignore_spans: bool,
5857
) -> Self {
59-
let hash_spans_initial =
60-
!always_ignore_spans && !sess.opts.unstable_opts.incremental_ignore_spans;
58+
let hash_spans_initial = !sess.opts.unstable_opts.incremental_ignore_spans;
6159

6260
StableHashingContext {
6361
body_resolver: BodyResolver::Forbidden,
@@ -71,33 +69,6 @@ impl<'a> StableHashingContext<'a> {
7169
}
7270
}
7371

74-
#[inline]
75-
pub fn new(
76-
sess: &'a Session,
77-
definitions: &'a Definitions,
78-
cstore: &'a dyn CrateStore,
79-
source_span: &'a IndexVec<LocalDefId, Span>,
80-
) -> Self {
81-
Self::new_with_or_without_spans(
82-
sess,
83-
definitions,
84-
cstore,
85-
source_span,
86-
/*always_ignore_spans=*/ false,
87-
)
88-
}
89-
90-
#[inline]
91-
pub fn ignore_spans(
92-
sess: &'a Session,
93-
definitions: &'a Definitions,
94-
cstore: &'a dyn CrateStore,
95-
source_span: &'a IndexVec<LocalDefId, Span>,
96-
) -> Self {
97-
let always_ignore_spans = true;
98-
Self::new_with_or_without_spans(sess, definitions, cstore, source_span, always_ignore_spans)
99-
}
100-
10172
#[inline]
10273
pub fn without_hir_bodies(&mut self, f: impl FnOnce(&mut StableHashingContext<'_>)) {
10374
f(&mut StableHashingContext { body_resolver: BodyResolver::Ignore, ..self.clone() });
@@ -202,10 +173,4 @@ impl<'a> rustc_span::HashStableContext for StableHashingContext<'a> {
202173
}
203174
}
204175

205-
impl<'a> rustc_data_structures::intern::InternedHashingContext for StableHashingContext<'a> {
206-
fn with_def_path_and_no_spans(&mut self, f: impl FnOnce(&mut Self)) {
207-
self.while_hashing_spans(false, f);
208-
}
209-
}
210-
211176
impl<'a> rustc_session::HashStableContext for StableHashingContext<'a> {}

0 commit comments

Comments
 (0)