Skip to content

Commit e53404c

Browse files
committed
Move def_path_hash_to_def_id to rustc_middle.
1 parent 88c6d3d commit e53404c

File tree

3 files changed

+23
-28
lines changed

3 files changed

+23
-28
lines changed

compiler/rustc_middle/src/dep_graph/dep_node.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -338,11 +338,7 @@ impl DepNodeExt for DepNode {
338338
/// has been removed.
339339
fn extract_def_id(&self, tcx: TyCtxt<'tcx>) -> Option<DefId> {
340340
if self.kind.fingerprint_style() == FingerprintStyle::DefPathHash {
341-
Some(
342-
tcx.on_disk_cache
343-
.as_ref()?
344-
.def_path_hash_to_def_id(tcx, DefPathHash(self.hash.into())),
345-
)
341+
Some(tcx.def_path_hash_to_def_id(DefPathHash(self.hash.into())))
346342
} else {
347343
None
348344
}

compiler/rustc_middle/src/ty/context.rs

+21-5
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,6 @@ pub trait OnDiskCache<'tcx>: rustc_data_structures::sync::Sync {
7979
where
8080
Self: Sized;
8181

82-
/// Converts a `DefPathHash` to its corresponding `DefId` in the current compilation
83-
/// session, if it still exists. This is used during incremental compilation to
84-
/// turn a deserialized `DefPathHash` into its current `DefId`.
85-
fn def_path_hash_to_def_id(&self, tcx: TyCtxt<'tcx>, def_path_hash: DefPathHash) -> DefId;
86-
8782
fn drop_serialized_data(&self, tcx: TyCtxt<'tcx>);
8883

8984
fn serialize(&self, tcx: TyCtxt<'tcx>, encoder: &mut FileEncoder) -> FileEncodeResult;
@@ -1301,6 +1296,27 @@ impl<'tcx> TyCtxt<'tcx> {
13011296
}
13021297
}
13031298

1299+
/// Converts a `DefPathHash` to its corresponding `DefId` in the current compilation
1300+
/// session, if it still exists. This is used during incremental compilation to
1301+
/// turn a deserialized `DefPathHash` into its current `DefId`.
1302+
pub fn def_path_hash_to_def_id(self, hash: DefPathHash) -> DefId {
1303+
debug!("def_path_hash_to_def_id({:?})", hash);
1304+
1305+
let stable_crate_id = hash.stable_crate_id();
1306+
1307+
// If this is a DefPathHash from the local crate, we can look up the
1308+
// DefId in the tcx's `Definitions`.
1309+
if stable_crate_id == self.sess.local_stable_crate_id() {
1310+
self.untracked_resolutions.definitions.local_def_path_hash_to_def_id(hash).to_def_id()
1311+
} else {
1312+
// If this is a DefPathHash from an upstream crate, let the CrateStore map
1313+
// it to a DefId.
1314+
let cstore = &self.untracked_resolutions.cstore;
1315+
let cnum = cstore.stable_crate_id_to_crate_num(stable_crate_id);
1316+
cstore.def_path_hash_to_def_id(cnum, hash)
1317+
}
1318+
}
1319+
13041320
pub fn def_path_debug_str(self, def_id: DefId) -> String {
13051321
// We are explicitly not going through queries here in order to get
13061322
// crate name and stable crate id since this code is called from debug!()

compiler/rustc_query_impl/src/on_disk_cache.rs

+1-18
Original file line numberDiff line numberDiff line change
@@ -358,23 +358,6 @@ impl<'sess> rustc_middle::ty::OnDiskCache<'sess> for OnDiskCache<'sess> {
358358
Ok(())
359359
})
360360
}
361-
362-
fn def_path_hash_to_def_id(&self, tcx: TyCtxt<'tcx>, hash: DefPathHash) -> DefId {
363-
debug!("def_path_hash_to_def_id({:?})", hash);
364-
365-
let stable_crate_id = hash.stable_crate_id();
366-
367-
// If this is a DefPathHash from the local crate, we can look up the
368-
// DefId in the tcx's `Definitions`.
369-
if stable_crate_id == tcx.sess.local_stable_crate_id() {
370-
tcx.definitions_untracked().local_def_path_hash_to_def_id(hash).to_def_id()
371-
} else {
372-
// If this is a DefPathHash from an upstream crate, let the CrateStore map
373-
// it to a DefId.
374-
let cnum = tcx.cstore_untracked().stable_crate_id_to_crate_num(stable_crate_id);
375-
tcx.cstore_untracked().def_path_hash_to_def_id(cnum, hash)
376-
}
377-
}
378361
}
379362

380363
impl<'sess> OnDiskCache<'sess> {
@@ -764,7 +747,7 @@ impl<'a, 'tcx> Decodable<CacheDecoder<'a, 'tcx>> for DefId {
764747
// If we get to this point, then all of the query inputs were green,
765748
// which means that the definition with this hash is guaranteed to
766749
// still exist in the current compilation session.
767-
Ok(d.tcx().on_disk_cache.as_ref().unwrap().def_path_hash_to_def_id(d.tcx(), def_path_hash))
750+
Ok(d.tcx().def_path_hash_to_def_id(def_path_hash))
768751
}
769752
}
770753

0 commit comments

Comments
 (0)