Hash spans when interning.
This commit is contained in:
parent
c42a4245cc
commit
d47424b833
3 changed files with 6 additions and 50 deletions
|
@ -110,11 +110,6 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A helper trait so that `Interned` things can cache stable hashes reproducibly.
|
|
||||||
pub trait InternedHashingContext {
|
|
||||||
fn with_def_path_and_no_spans(&mut self, f: impl FnOnce(&mut Self));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A helper type that you can wrap round your own type in order to automatically
|
/// A helper type that you can wrap round your own type in order to automatically
|
||||||
/// cache the stable hash on creation and not recompute it whenever the stable hash
|
/// cache the stable hash on creation and not recompute it whenever the stable hash
|
||||||
/// of the type is computed.
|
/// of the type is computed.
|
||||||
|
@ -165,7 +160,7 @@ impl<T: Hash> Hash for WithStableHash<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: HashStable<CTX>, CTX: InternedHashingContext> HashStable<CTX> for WithStableHash<T> {
|
impl<T: HashStable<CTX>, CTX> HashStable<CTX> for WithStableHash<T> {
|
||||||
fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) {
|
fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) {
|
||||||
if self.stable_hash == Fingerprint::ZERO || cfg!(debug_assertions) {
|
if self.stable_hash == Fingerprint::ZERO || cfg!(debug_assertions) {
|
||||||
// No cached hash available. This can only mean that incremental is disabled.
|
// 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
|
||||||
// otherwise the hashes will differ between cached and non-cached mode.
|
// otherwise the hashes will differ between cached and non-cached mode.
|
||||||
let stable_hash: Fingerprint = {
|
let stable_hash: Fingerprint = {
|
||||||
let mut hasher = StableHasher::new();
|
let mut hasher = StableHasher::new();
|
||||||
hcx.with_def_path_and_no_spans(|hcx| self.internee.hash_stable(hcx, &mut hasher));
|
self.internee.hash_stable(hcx, &mut hasher);
|
||||||
hasher.finish()
|
hasher.finish()
|
||||||
};
|
};
|
||||||
if cfg!(debug_assertions) && self.stable_hash != Fingerprint::ZERO {
|
if cfg!(debug_assertions) && self.stable_hash != Fingerprint::ZERO {
|
||||||
|
|
|
@ -198,12 +198,8 @@ impl<'tcx> CtxtInterners<'tcx> {
|
||||||
Fingerprint::ZERO
|
Fingerprint::ZERO
|
||||||
} else {
|
} else {
|
||||||
let mut hasher = StableHasher::new();
|
let mut hasher = StableHasher::new();
|
||||||
let mut hcx = StableHashingContext::ignore_spans(
|
let mut hcx =
|
||||||
sess,
|
StableHashingContext::new(sess, definitions, cstore, source_span);
|
||||||
definitions,
|
|
||||||
cstore,
|
|
||||||
source_span,
|
|
||||||
);
|
|
||||||
kind.hash_stable(&mut hcx, &mut hasher);
|
kind.hash_stable(&mut hcx, &mut hasher);
|
||||||
hasher.finish()
|
hasher.finish()
|
||||||
};
|
};
|
||||||
|
|
|
@ -49,15 +49,13 @@ pub(super) enum BodyResolver<'tcx> {
|
||||||
|
|
||||||
impl<'a> StableHashingContext<'a> {
|
impl<'a> StableHashingContext<'a> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn new_with_or_without_spans(
|
pub fn new(
|
||||||
sess: &'a Session,
|
sess: &'a Session,
|
||||||
definitions: &'a Definitions,
|
definitions: &'a Definitions,
|
||||||
cstore: &'a dyn CrateStore,
|
cstore: &'a dyn CrateStore,
|
||||||
source_span: &'a IndexVec<LocalDefId, Span>,
|
source_span: &'a IndexVec<LocalDefId, Span>,
|
||||||
always_ignore_spans: bool,
|
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let hash_spans_initial =
|
let hash_spans_initial = !sess.opts.unstable_opts.incremental_ignore_spans;
|
||||||
!always_ignore_spans && !sess.opts.unstable_opts.incremental_ignore_spans;
|
|
||||||
|
|
||||||
StableHashingContext {
|
StableHashingContext {
|
||||||
body_resolver: BodyResolver::Forbidden,
|
body_resolver: BodyResolver::Forbidden,
|
||||||
|
@ -71,33 +69,6 @@ impl<'a> StableHashingContext<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn new(
|
|
||||||
sess: &'a Session,
|
|
||||||
definitions: &'a Definitions,
|
|
||||||
cstore: &'a dyn CrateStore,
|
|
||||||
source_span: &'a IndexVec<LocalDefId, Span>,
|
|
||||||
) -> Self {
|
|
||||||
Self::new_with_or_without_spans(
|
|
||||||
sess,
|
|
||||||
definitions,
|
|
||||||
cstore,
|
|
||||||
source_span,
|
|
||||||
/*always_ignore_spans=*/ false,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn ignore_spans(
|
|
||||||
sess: &'a Session,
|
|
||||||
definitions: &'a Definitions,
|
|
||||||
cstore: &'a dyn CrateStore,
|
|
||||||
source_span: &'a IndexVec<LocalDefId, Span>,
|
|
||||||
) -> Self {
|
|
||||||
let always_ignore_spans = true;
|
|
||||||
Self::new_with_or_without_spans(sess, definitions, cstore, source_span, always_ignore_spans)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn without_hir_bodies(&mut self, f: impl FnOnce(&mut StableHashingContext<'_>)) {
|
pub fn without_hir_bodies(&mut self, f: impl FnOnce(&mut StableHashingContext<'_>)) {
|
||||||
f(&mut StableHashingContext { body_resolver: BodyResolver::Ignore, ..self.clone() });
|
f(&mut StableHashingContext { body_resolver: BodyResolver::Ignore, ..self.clone() });
|
||||||
|
@ -202,10 +173,4 @@ impl<'a> rustc_span::HashStableContext for StableHashingContext<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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, f);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> rustc_session::HashStableContext for StableHashingContext<'a> {}
|
impl<'a> rustc_session::HashStableContext for StableHashingContext<'a> {}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue