Skip to content

Commit 59f269c

Browse files
Experiment: Replace crate-hash with simple timestamp.
1 parent f58d51b commit 59f269c

File tree

6 files changed

+10
-98
lines changed

6 files changed

+10
-98
lines changed

compiler/rustc_ast_lowering/src/lib.rs

+1-24
Original file line numberDiff line numberDiff line change
@@ -461,33 +461,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
461461
hir::OwnerNode::Crate(lctx.arena.alloc(module))
462462
});
463463

464-
let hir_hash = self.compute_hir_hash();
465-
466-
let krate = hir::Crate { owners: self.owners, hir_hash };
464+
let krate = hir::Crate { owners: self.owners };
467465
self.arena.alloc(krate)
468466
}
469467

470-
/// Compute the hash for the HIR of the full crate.
471-
/// This hash will then be part of the crate_hash which is stored in the metadata.
472-
fn compute_hir_hash(&mut self) -> Fingerprint {
473-
let definitions = self.resolver.definitions();
474-
let mut hir_body_nodes: Vec<_> = self
475-
.owners
476-
.iter_enumerated()
477-
.filter_map(|(def_id, info)| {
478-
let info = info.as_owner()?;
479-
let def_path_hash = definitions.def_path_hash(def_id);
480-
Some((def_path_hash, info))
481-
})
482-
.collect();
483-
hir_body_nodes.sort_unstable_by_key(|bn| bn.0);
484-
485-
let mut stable_hasher = StableHasher::new();
486-
let mut hcx = self.resolver.create_stable_hashing_context();
487-
hir_body_nodes.hash_stable(&mut hcx, &mut stable_hasher);
488-
stable_hasher.finish()
489-
}
490-
491468
fn with_hir_id_owner(
492469
&mut self,
493470
owner: NodeId,

compiler/rustc_hir/src/hir.rs

-1
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,6 @@ impl<T> MaybeOwner<T> {
776776
#[derive(Debug)]
777777
pub struct Crate<'hir> {
778778
pub owners: IndexVec<LocalDefId, MaybeOwner<&'hir OwnerInfo<'hir>>>,
779-
pub hir_hash: Fingerprint,
780779
}
781780

782781
/// A block of statements `{ .. }`, which may have a label (in this case the

compiler/rustc_hir/src/stable_hash_impls.rs

+2-9
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, Expr, ForeignItem, ForeignItemId, ImplItem, ImplItemId, Item, ItemId,
5+
OwnerNodes, TraitCandidate, TraitItem, TraitItemId, Ty, VisibilityKind,
66
};
77
use crate::hir_id::{HirId, ItemLocalId};
88
use rustc_span::def_id::DefPathHash;
@@ -229,13 +229,6 @@ impl<'tcx, HirCtx: crate::HashStableContext> HashStable<HirCtx> for AttributeMap
229229
}
230230
}
231231

232-
impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for Crate<'_> {
233-
fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
234-
let Crate { owners: _, hir_hash } = self;
235-
hir_hash.hash_stable(hcx, hasher)
236-
}
237-
}
238-
239232
impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for TraitCandidate {
240233
fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
241234
hcx.hash_hir_trait_candidate(self, hasher)

compiler/rustc_middle/src/hir/map/mod.rs

+5-64
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
use crate::hir::{ModuleItems, Owner};
22
use crate::ty::TyCtxt;
33
use rustc_ast as ast;
4-
use rustc_data_structures::fingerprint::Fingerprint;
5-
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
64
use rustc_data_structures::svh::Svh;
75
use rustc_data_structures::sync::{par_for_each_in, Send, Sync};
86
use rustc_hir::def::{DefKind, Res};
@@ -13,12 +11,12 @@ use rustc_hir::itemlikevisit::ItemLikeVisitor;
1311
use rustc_hir::*;
1412
use rustc_index::vec::Idx;
1513
use rustc_middle::hir::nested_filter;
16-
use rustc_span::def_id::StableCrateId;
1714
use rustc_span::source_map::Spanned;
1815
use rustc_span::symbol::{kw, sym, Ident, Symbol};
1916
use rustc_span::Span;
2017
use rustc_target::spec::abi::Abi;
2118
use std::collections::VecDeque;
19+
use std::time::SystemTime;
2220

2321
fn fn_decl<'hir>(node: Node<'hir>) -> Option<&'hir FnDecl<'hir>> {
2422
match node {
@@ -1088,69 +1086,12 @@ impl<'hir> intravisit::Map<'hir> for Map<'hir> {
10881086
}
10891087
}
10901088

1091-
pub(super) fn crate_hash(tcx: TyCtxt<'_>, crate_num: CrateNum) -> Svh {
1089+
pub(super) fn crate_hash(_: TyCtxt<'_>, crate_num: CrateNum) -> Svh {
10921090
debug_assert_eq!(crate_num, LOCAL_CRATE);
1093-
let krate = tcx.hir_crate(());
1094-
let hir_body_hash = krate.hir_hash;
1095-
1096-
let upstream_crates = upstream_crates(tcx);
1097-
1098-
// We hash the final, remapped names of all local source files so we
1099-
// don't have to include the path prefix remapping commandline args.
1100-
// If we included the full mapping in the SVH, we could only have
1101-
// reproducible builds by compiling from the same directory. So we just
1102-
// hash the result of the mapping instead of the mapping itself.
1103-
let mut source_file_names: Vec<_> = tcx
1104-
.sess
1105-
.source_map()
1106-
.files()
1107-
.iter()
1108-
.filter(|source_file| source_file.cnum == LOCAL_CRATE)
1109-
.map(|source_file| source_file.name_hash)
1110-
.collect();
1111-
1112-
source_file_names.sort_unstable();
1113-
1114-
let mut hcx = tcx.create_stable_hashing_context();
1115-
let mut stable_hasher = StableHasher::new();
1116-
hir_body_hash.hash_stable(&mut hcx, &mut stable_hasher);
1117-
upstream_crates.hash_stable(&mut hcx, &mut stable_hasher);
1118-
source_file_names.hash_stable(&mut hcx, &mut stable_hasher);
1119-
if tcx.sess.opts.debugging_opts.incremental_relative_spans {
1120-
let definitions = &tcx.untracked_resolutions.definitions;
1121-
let mut owner_spans: Vec<_> = krate
1122-
.owners
1123-
.iter_enumerated()
1124-
.filter_map(|(def_id, info)| {
1125-
let _ = info.as_owner()?;
1126-
let def_path_hash = definitions.def_path_hash(def_id);
1127-
let span = definitions.def_span(def_id);
1128-
debug_assert_eq!(span.parent(), None);
1129-
Some((def_path_hash, span))
1130-
})
1131-
.collect();
1132-
owner_spans.sort_unstable_by_key(|bn| bn.0);
1133-
owner_spans.hash_stable(&mut hcx, &mut stable_hasher);
1134-
}
1135-
tcx.sess.opts.dep_tracking_hash(true).hash_stable(&mut hcx, &mut stable_hasher);
1136-
tcx.sess.local_stable_crate_id().hash_stable(&mut hcx, &mut stable_hasher);
11371091

1138-
let crate_hash: Fingerprint = stable_hasher.finish();
1139-
Svh::new(crate_hash.to_smaller_hash())
1140-
}
1141-
1142-
fn upstream_crates(tcx: TyCtxt<'_>) -> Vec<(StableCrateId, Svh)> {
1143-
let mut upstream_crates: Vec<_> = tcx
1144-
.crates(())
1145-
.iter()
1146-
.map(|&cnum| {
1147-
let stable_crate_id = tcx.resolutions(()).cstore.stable_crate_id(cnum);
1148-
let hash = tcx.crate_hash(cnum);
1149-
(stable_crate_id, hash)
1150-
})
1151-
.collect();
1152-
upstream_crates.sort_unstable_by_key(|&(stable_crate_id, _)| stable_crate_id);
1153-
upstream_crates
1092+
// TEST: Turn crate hash into a time-stamp/build-id
1093+
let random = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).unwrap().as_nanos();
1094+
Svh::new((random as u64).wrapping_add((random >> 64) as u64))
11541095
}
11551096

11561097
fn hir_id_to_string(map: Map<'_>, id: HirId) -> String {

compiler/rustc_middle/src/query/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ rustc_queries! {
4242
/// prefer wrappers like `tcx.visit_all_items_in_krate()`.
4343
query hir_crate(key: ()) -> &'tcx Crate<'tcx> {
4444
eval_always
45+
no_hash
4546
desc { "get the crate HIR" }
4647
}
4748

src/test/ui/svh-add-nothing.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// ignore-test
12
// run-pass
23
// note that these aux-build directives must be in this order
34
// aux-build:svh-a-base.rs

0 commit comments

Comments
 (0)