diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2022-01-20 23:37:38 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-01-20 23:37:38 +0100 |
| commit | e901b24310d05dedd8d5f6d20285fd91a6d86714 (patch) | |
| tree | 374c6a78c844e0408d6834df8683d6dec570b01b | |
| parent | 6cdd2e510c4d8aefa4a31ca21e8092da2768d894 (diff) | |
| parent | 70d36a05bc79667578a3c7b2b4926e21a9a5d013 (diff) | |
| download | rust-e901b24310d05dedd8d5f6d20285fd91a6d86714.tar.gz rust-e901b24310d05dedd8d5f6d20285fd91a6d86714.zip | |
Rollup merge of #93098 - Aaron1011:def-path-hash-debug, r=oli-obk
Show a more informative panic message when `DefPathHash` does not exist This should hopefully make it easier to debug incremental compilation bugs like #93096 without affecting performance.
| -rw-r--r-- | compiler/rustc_hir/src/definitions.rs | 8 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/dep_graph/dep_node.rs | 4 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/ty/context.rs | 7 | ||||
| -rw-r--r-- | compiler/rustc_query_impl/src/on_disk_cache.rs | 4 |
4 files changed, 17 insertions, 6 deletions
diff --git a/compiler/rustc_hir/src/definitions.rs b/compiler/rustc_hir/src/definitions.rs index d813c887eee..e839f7fc777 100644 --- a/compiler/rustc_hir/src/definitions.rs +++ b/compiler/rustc_hir/src/definitions.rs @@ -449,13 +449,17 @@ impl Definitions { } #[inline(always)] - pub fn local_def_path_hash_to_def_id(&self, hash: DefPathHash) -> LocalDefId { + pub fn local_def_path_hash_to_def_id( + &self, + hash: DefPathHash, + err: &mut dyn FnMut() -> !, + ) -> LocalDefId { debug_assert!(hash.stable_crate_id() == self.stable_crate_id); self.table .def_path_hash_to_index .get(&hash) .map(|local_def_index| LocalDefId { local_def_index }) - .unwrap() + .unwrap_or_else(|| err()) } pub fn def_path_hash_to_def_index_map(&self) -> &DefPathHashMap { diff --git a/compiler/rustc_middle/src/dep_graph/dep_node.rs b/compiler/rustc_middle/src/dep_graph/dep_node.rs index 5c7cdbe4c2b..d20be0a34d2 100644 --- a/compiler/rustc_middle/src/dep_graph/dep_node.rs +++ b/compiler/rustc_middle/src/dep_graph/dep_node.rs @@ -266,7 +266,9 @@ impl DepNodeExt for DepNode { /// has been removed. fn extract_def_id<'tcx>(&self, tcx: TyCtxt<'tcx>) -> Option<DefId> { if self.kind.fingerprint_style(tcx) == FingerprintStyle::DefPathHash { - Some(tcx.def_path_hash_to_def_id(DefPathHash(self.hash.into()))) + Some(tcx.def_path_hash_to_def_id(DefPathHash(self.hash.into()), &mut || { + panic!("Failed to extract DefId: {:?} {}", self.kind, self.hash) + })) } else { None } diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index e7b99995ca4..b493ff16203 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -1308,7 +1308,7 @@ impl<'tcx> TyCtxt<'tcx> { /// Converts a `DefPathHash` to its corresponding `DefId` in the current compilation /// session, if it still exists. This is used during incremental compilation to /// turn a deserialized `DefPathHash` into its current `DefId`. - pub fn def_path_hash_to_def_id(self, hash: DefPathHash) -> DefId { + pub fn def_path_hash_to_def_id(self, hash: DefPathHash, err: &mut dyn FnMut() -> !) -> DefId { debug!("def_path_hash_to_def_id({:?})", hash); let stable_crate_id = hash.stable_crate_id(); @@ -1316,7 +1316,10 @@ impl<'tcx> TyCtxt<'tcx> { // If this is a DefPathHash from the local crate, we can look up the // DefId in the tcx's `Definitions`. if stable_crate_id == self.sess.local_stable_crate_id() { - self.untracked_resolutions.definitions.local_def_path_hash_to_def_id(hash).to_def_id() + self.untracked_resolutions + .definitions + .local_def_path_hash_to_def_id(hash, err) + .to_def_id() } else { // If this is a DefPathHash from an upstream crate, let the CrateStore map // it to a DefId. diff --git a/compiler/rustc_query_impl/src/on_disk_cache.rs b/compiler/rustc_query_impl/src/on_disk_cache.rs index 6a88e123537..5f6d9b050b2 100644 --- a/compiler/rustc_query_impl/src/on_disk_cache.rs +++ b/compiler/rustc_query_impl/src/on_disk_cache.rs @@ -761,7 +761,9 @@ 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().def_path_hash_to_def_id(def_path_hash)) + Ok(d.tcx().def_path_hash_to_def_id(def_path_hash, &mut || { + panic!("Failed to convert DefPathHash {:?}", def_path_hash) + })) } } |
