Skip to content

Commit

Permalink
Allow to hash HIR for coverage.
Browse files Browse the repository at this point in the history
  • Loading branch information
cjgillot committed Oct 14, 2021
1 parent 7a209bb commit 394f719
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions compiler/rustc_mir_transform/src/coverage/mod.rs
Expand Up @@ -14,7 +14,6 @@ use spans::{CoverageSpan, CoverageSpans};

use crate::MirPass;

use rustc_data_structures::fingerprint::Fingerprint;
use rustc_data_structures::graph::WithNumNodes;
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
use rustc_data_structures::sync::Lrc;
Expand All @@ -29,7 +28,6 @@ use rustc_middle::mir::{
TerminatorKind,
};
use rustc_middle::ty::TyCtxt;
use rustc_query_system::ich::StableHashingContext;
use rustc_span::def_id::DefId;
use rustc_span::source_map::SourceMap;
use rustc_span::{CharPos, ExpnKind, Pos, SourceFile, Span, Symbol};
Expand Down Expand Up @@ -574,15 +572,13 @@ fn get_body_span<'tcx>(
}

fn hash_mir_source<'tcx>(tcx: TyCtxt<'tcx>, hir_body: &'tcx rustc_hir::Body<'tcx>) -> u64 {
// FIXME(cjgillot) Stop hashing HIR manually here.
let mut hcx = tcx.create_no_span_stable_hashing_context();
hash(&mut hcx, &hir_body.value).to_smaller_hash()
}

fn hash(
hcx: &mut StableHashingContext<'tcx>,
node: &impl HashStable<StableHashingContext<'tcx>>,
) -> Fingerprint {
let mut stable_hasher = StableHasher::new();
node.hash_stable(hcx, &mut stable_hasher);
let owner = hir_body.id().hir_id.owner;
let bodies = &tcx.hir_owner_nodes(owner).as_ref().unwrap().bodies;
hcx.with_hir_bodies(false, owner, bodies, |hcx| {
hir_body.value.hash_stable(hcx, &mut stable_hasher)
});
stable_hasher.finish()
}

0 comments on commit 394f719

Please sign in to comment.