Skip to content

Commit ea49b7e

Browse files
Restore HIR crate hashing
1 parent 2f8df61 commit ea49b7e

6 files changed

Lines changed: 23 additions & 26 deletions

File tree

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ use rustc_attr_parsing::{AttributeParser, OmitDoc, Recovery, ShouldEmit};
4545
use rustc_data_structures::fingerprint::Fingerprint;
4646
use rustc_data_structures::fx::FxIndexSet;
4747
use rustc_data_structures::sorted_map::SortedMap;
48+
use rustc_data_structures::stable_hasher::{StableHash, StableHasher};
4849
use rustc_data_structures::steal::Steal;
4950
use rustc_data_structures::tagged_ptr::TaggedRef;
5051
use rustc_errors::{DiagArgFromDisplay, DiagCtxtHandle};
@@ -560,11 +561,8 @@ pub fn lower_to_hir(tcx: TyCtxt<'_>, (): ()) -> mid_hir::Crate<'_> {
560561
}
561562

562563
// Don't hash unless necessary, because it's expensive.
563-
let opt_hir_hash = if tcx.needs_crate_hash() && !tcx.needs_metadata() {
564-
Some(compute_hir_hash(tcx, &owners))
565-
} else {
566-
None
567-
};
564+
let opt_hir_hash =
565+
if tcx.needs_crate_hash() { Some(compute_hir_hash(tcx, &owners)) } else { None };
568566

569567
let delayed_resolver = Steal::new((resolver, krate));
570568
mid_hir::Crate::new(owners, delayed_ids, delayed_resolver, opt_hir_hash)

compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::mem;
33
use std::sync::Arc;
44

55
use rustc_data_structures::fingerprint::Fingerprint;
6-
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
6+
use rustc_data_structures::stable_hasher::{StableHash, StableHasher};
77
use rustc_data_structures::svh::Svh;
88
use rustc_hir::attrs::Deprecation;
99
use rustc_hir::def::{CtorKind, DefKind};
@@ -807,10 +807,10 @@ pub(super) fn crate_hash(tcx: TyCtxt<'_>) -> Svh {
807807

808808
let crate_hash: Fingerprint = tcx.with_stable_hashing_context(|mut hcx| {
809809
let mut stable_hasher = StableHasher::new();
810-
hir_body_hash.hash_stable(&mut hcx, &mut stable_hasher);
811-
upstream_crates.hash_stable(&mut hcx, &mut stable_hasher);
812-
//source_file_names.hash_stable(&mut hcx, &mut stable_hasher);
813-
//debugger_visualizers.hash_stable(&mut hcx, &mut stable_hasher);
810+
hir_body_hash.stable_hash(&mut hcx, &mut stable_hasher);
811+
upstream_crates.stable_hash(&mut hcx, &mut stable_hasher);
812+
//source_file_names.stable_hash(&mut hcx, &mut stable_hasher);
813+
//debugger_visualizers.stable_hash(&mut hcx, &mut stable_hasher);
814814
if tcx.sess.opts.incremental.is_some() {
815815
let definitions = tcx.untracked().definitions.freeze();
816816
let mut owner_spans: Vec<_> = tcx
@@ -824,17 +824,17 @@ pub(super) fn crate_hash(tcx: TyCtxt<'_>) -> Svh {
824824
})
825825
.collect();
826826
owner_spans.sort_unstable_by_key(|bn| bn.0);
827-
owner_spans.hash_stable(&mut hcx, &mut stable_hasher);
827+
owner_spans.stable_hash(&mut hcx, &mut stable_hasher);
828828
}
829-
tcx.sess.opts.dep_tracking_hash(true).hash_stable(&mut hcx, &mut stable_hasher);
830-
tcx.stable_crate_id(LOCAL_CRATE).hash_stable(&mut hcx, &mut stable_hasher);
829+
tcx.sess.opts.dep_tracking_hash(true).stable_hash(&mut hcx, &mut stable_hasher);
830+
tcx.stable_crate_id(LOCAL_CRATE).stable_hash(&mut hcx, &mut stable_hasher);
831831
// Hash visibility information since it does not appear in HIR.
832832
// FIXME: Figure out how to remove `visibilities_for_hashing` by hashing visibilities on
833833
// the fly in the resolver, storing only their accumulated hash in `ResolverGlobalCtxt`,
834834
// and combining it with other hashes here.
835-
//resolutions.visibilities_for_hashing.hash_stable(&mut hcx, &mut stable_hasher);
835+
//resolutions.visibilities_for_hashing.stable_hash(&mut hcx, &mut stable_hasher);
836836
/*with_metavar_spans(|mspans| {
837-
mspans.freeze_and_get_read_spans().hash_stable(&mut hcx, &mut stable_hasher);
837+
mspans.freeze_and_get_read_spans().stable_hash(&mut hcx, &mut stable_hasher);
838838
});*/
839839
stable_hasher.finish()
840840
});

compiler/rustc_metadata/src/rmeta/encoder.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use std::sync::Arc;
1111
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
1212
use rustc_data_structures::memmap::{Mmap, MmapMut};
1313
use rustc_data_structures::owned_slice::slice_owned;
14-
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
14+
use rustc_data_structures::stable_hasher::{StableHash, StableHasher};
1515
use rustc_data_structures::sync::{par_for_each_in, par_join};
1616
use rustc_data_structures::temp_dir::MaybeTempDir;
1717
use rustc_data_structures::thousands::usize_with_underscores;
@@ -96,7 +96,7 @@ macro_rules! context_encoder_methods {
9696
($($name:ident($ty:ty);)*) => {
9797
#[inline]
9898
$(fn $name(&mut self, value: $ty) {
99-
//value.hash_stable(&mut self.hcx, &mut self.stable_hasher);
99+
//value.stable_hash(&mut self.hcx, &mut self.stable_hasher);
100100
self.opaque.$name(value)
101101
})*
102102
}
@@ -129,7 +129,7 @@ impl<'a> ContextEncoder<'a> {
129129

130130
#[inline]
131131
pub(super) fn write_m_with<const N: usize>(&mut self, b: &[u8; N], m: usize) {
132-
//(b[..m]).hash_stable(&mut self.hcx, &mut self.stable_hasher);
132+
//(b[..m]).stable_hash(&mut self.hcx, &mut self.stable_hasher);
133133
self.opaque.write_with(|dest| {
134134
*dest = *b;
135135
m
@@ -775,7 +775,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
775775
/*tcx.sess
776776
.opts
777777
.dep_tracking_hash(true)
778-
.hash_stable(&mut self.encoder.hcx, &mut self.encoder.stable_hasher)*/
778+
.stable_hash(&mut self.encoder.hcx, &mut self.encoder.stable_hasher)*/
779779
let new_hash = Svh::new(self.encoder.opaque.hash());
780780

781781
/*eprintln!("crate: {:?}", tcx.crate_name(LOCAL_CRATE));
@@ -2667,7 +2667,7 @@ fn with_encode_metadata_header(
26672667
) {
26682668
tcx.with_stable_hashing_context(|mut hcx| {
26692669
let mut stable_hasher = StableHasher::new();
2670-
tcx.sess.opts.dep_tracking_hash(true).hash_stable(&mut hcx, &mut stable_hasher);
2670+
tcx.sess.opts.dep_tracking_hash(true).stable_hash(&mut hcx, &mut stable_hasher);
26712671
let mut encoder = opaque::FileEncoder::new(path, hcx, &mut stable_hasher)
26722672
.unwrap_or_else(|err| tcx.dcx().emit_fatal(FailCreateFileEncoder { err }));
26732673
encoder.emit_raw_bytes(METADATA_HEADER);

compiler/rustc_metadata/src/rmeta/table.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use rustc_hir::def::CtorOf;
22
use rustc_index::Idx;
33

4-
use crate::rmeta::decoder::{MetaBlob, Metadata};
4+
use crate::rmeta::decoder::MetaBlob;
55
use crate::rmeta::encoder::ContextEncoder;
66
use crate::rmeta::*;
77

compiler/rustc_middle/src/hir/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ use rustc_ast::{self as ast};
1212
use rustc_data_structures::fingerprint::Fingerprint;
1313
use rustc_data_structures::fx::FxIndexSet;
1414
use rustc_data_structures::sorted_map::SortedMap;
15-
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
15+
use rustc_data_structures::stable_hasher::{StableHash, StableHashCtxt, StableHasher};
1616
use rustc_data_structures::steal::Steal;
1717
use rustc_data_structures::sync::{DynSend, DynSync, try_par_for_each_in};
1818
use rustc_hir::def::{DefKind, Res};
1919
use rustc_hir::def_id::{DefId, LocalDefId, LocalModDefId};
2020
use rustc_hir::*;
2121
use rustc_index::IndexVec;
22-
use rustc_macros::{Decodable, Encodable, HashStable};
22+
use rustc_macros::{Decodable, Encodable, StableHash};
2323
use rustc_span::{ErrorGuaranteed, ExpnId, Span};
2424

2525
use crate::query::Providers;
@@ -76,12 +76,12 @@ impl<'hir> Crate<'hir> {
7676
}
7777
}
7878

79-
/*impl StableHash for Crate<'_> {
79+
impl StableHash for Crate<'_> {
8080
fn stable_hash<Hcx: StableHashCtxt>(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
8181
let Crate { opt_hir_hash, .. } = self;
8282
opt_hir_hash.unwrap().stable_hash(hcx, hasher)
8383
}
84-
}*/
84+
}
8585

8686
/// Gather the LocalDefId for each item-like within a module, including items contained within
8787
/// bodies. The Ids are in visitor order. This is used to partition a pass between modules.

compiler/rustc_middle/src/queries.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,6 @@ rustc_queries! {
208208
query hir_crate(key: ()) -> &'tcx Crate<'tcx> {
209209
arena_cache
210210
eval_always
211-
no_hash
212211
desc { "getting the crate HIR" }
213212
}
214213

0 commit comments

Comments
 (0)