Skip to content

Commit cbc74ff

Browse files
SVH: Don't hash the HIR twice when once is enough.
The SVH (Strict Version Hash) of a crate is currently computed by hashing the ICHes (Incremental Computation Hashes) of the crate's HIR. This is fine, expect that for incr. comp. we compute two ICH values for each HIR item, one for the complete item and one that just includes the item's interface. The two hashes are are needed for dependency tracking but if we are compiling non-incrementally and just need the ICH values for the SVH, one of them is enough, giving us the opportunity to save some work in this case.
1 parent 60cb735 commit cbc74ff

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/librustc_incremental/calculate_svh/mod.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,13 @@ impl<'a, 'tcx: 'a> ComputeItemHashesVisitor<'a, 'tcx> {
9999
item_like: T)
100100
where T: HashStable<StableHashingContext<'a, 'tcx>>
101101
{
102+
if !hash_bodies && !self.hcx.tcx().sess.opts.build_dep_graph() {
103+
// If we just need the hashes in order to compute the SVH, we don't
104+
// need have two hashes per item. Just the one containing also the
105+
// item's body is sufficient.
106+
return
107+
}
108+
102109
let mut hasher = IchHasher::new();
103110
self.hcx.while_hashing_hir_bodies(hash_bodies, |hcx| {
104111
item_like.hash_stable(hcx, &mut hasher);
@@ -143,7 +150,7 @@ impl<'a, 'tcx: 'a> ComputeItemHashesVisitor<'a, 'tcx> {
143150
(item_dep_node, item_hash)
144151
})
145152
.collect();
146-
item_hashes.sort(); // avoid artificial dependencies on item ordering
153+
item_hashes.sort_unstable(); // avoid artificial dependencies on item ordering
147154
item_hashes.hash(&mut crate_state);
148155
}
149156

src/librustc_incremental/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#![feature(staged_api)]
2424
#![feature(rand)]
2525
#![feature(conservative_impl_trait)]
26+
#![feature(sort_unstable)]
2627
#![cfg_attr(stage0,feature(field_init_shorthand))]
2728
#![cfg_attr(stage0, feature(pub_restricted))]
2829

0 commit comments

Comments
 (0)