Move def_path_hash_to_def_id to rustc_middle.

This commit is contained in:
Camille GILLOT 2021-10-16 17:13:02 +02:00
parent 88c6d3de95
commit e53404cca6
3 changed files with 23 additions and 28 deletions

View file

@ -358,23 +358,6 @@ impl<'sess> rustc_middle::ty::OnDiskCache<'sess> for OnDiskCache<'sess> {
Ok(())
})
}
fn def_path_hash_to_def_id(&self, tcx: TyCtxt<'tcx>, hash: DefPathHash) -> DefId {
debug!("def_path_hash_to_def_id({:?})", hash);
let stable_crate_id = hash.stable_crate_id();
// If this is a DefPathHash from the local crate, we can look up the
// DefId in the tcx's `Definitions`.
if stable_crate_id == tcx.sess.local_stable_crate_id() {
tcx.definitions_untracked().local_def_path_hash_to_def_id(hash).to_def_id()
} else {
// If this is a DefPathHash from an upstream crate, let the CrateStore map
// it to a DefId.
let cnum = tcx.cstore_untracked().stable_crate_id_to_crate_num(stable_crate_id);
tcx.cstore_untracked().def_path_hash_to_def_id(cnum, hash)
}
}
}
impl<'sess> OnDiskCache<'sess> {
@ -764,7 +747,7 @@ impl<'a, 'tcx> Decodable<CacheDecoder<'a, 'tcx>> for DefId {
// If we get to this point, then all of the query inputs were green,
// which means that the definition with this hash is guaranteed to
// still exist in the current compilation session.
Ok(d.tcx().on_disk_cache.as_ref().unwrap().def_path_hash_to_def_id(d.tcx(), def_path_hash))
Ok(d.tcx().def_path_hash_to_def_id(def_path_hash))
}
}