about summary refs log tree commit diff
path: root/compiler/rustc_middle
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/rustc_middle')
-rw-r--r--compiler/rustc_middle/src/hooks/mod.rs27
-rw-r--r--compiler/rustc_middle/src/query/on_disk_cache.rs11
-rw-r--r--compiler/rustc_middle/src/ty/context.rs6
3 files changed, 26 insertions, 18 deletions
diff --git a/compiler/rustc_middle/src/hooks/mod.rs b/compiler/rustc_middle/src/hooks/mod.rs
index aa2cddad093..f7ce15d0a8d 100644
--- a/compiler/rustc_middle/src/hooks/mod.rs
+++ b/compiler/rustc_middle/src/hooks/mod.rs
@@ -6,8 +6,10 @@
 use crate::mir;
 use crate::query::TyCtxtAt;
 use crate::ty::{Ty, TyCtxt};
-use rustc_span::def_id::LocalDefId;
-use rustc_span::DUMMY_SP;
+use rustc_hir::def_id::{DefId, DefPathHash};
+use rustc_session::StableCrateId;
+use rustc_span::def_id::{CrateNum, LocalDefId};
+use rustc_span::{ExpnHash, ExpnId, DUMMY_SP};
 
 macro_rules! declare_hooks {
     ($($(#[$attr:meta])*hook $name:ident($($arg:ident: $K:ty),*) -> $V:ty;)*) => {
@@ -16,7 +18,6 @@ macro_rules! declare_hooks {
             $(
             $(#[$attr])*
             #[inline(always)]
-            #[must_use]
             pub fn $name(self, $($arg: $K,)*) -> $V
             {
                 self.at(DUMMY_SP).$name($($arg,)*)
@@ -28,7 +29,6 @@ macro_rules! declare_hooks {
             $(
             $(#[$attr])*
             #[inline(always)]
-            #[must_use]
             #[instrument(level = "debug", skip(self), ret)]
             pub fn $name(self, $($arg: $K,)*) -> $V
             {
@@ -83,4 +83,23 @@ declare_hooks! {
     /// You do not want to call this yourself, instead use the cached version
     /// via `mir_built`
     hook build_mir(key: LocalDefId) -> mir::Body<'tcx>;
+
+
+    /// Imports all `SourceFile`s from the given crate into the current session.
+    /// This normally happens automatically when we decode a `Span` from
+    /// that crate's metadata - however, the incr comp cache needs
+    /// to trigger this manually when decoding a foreign `Span`
+    hook import_source_files(key: CrateNum) -> ();
+
+    hook expn_hash_to_expn_id(
+        cnum: CrateNum,
+        index_guess: u32,
+        hash: ExpnHash
+    ) -> ExpnId;
+
+    /// 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`.
+    /// Will fetch a DefId from a DefPathHash for a foreign crate.
+    hook def_path_hash_to_def_id_extern(hash: DefPathHash, stable_crate_id: StableCrateId) -> DefId;
 }
diff --git a/compiler/rustc_middle/src/query/on_disk_cache.rs b/compiler/rustc_middle/src/query/on_disk_cache.rs
index 8f02b3121ac..db1b5a74f0a 100644
--- a/compiler/rustc_middle/src/query/on_disk_cache.rs
+++ b/compiler/rustc_middle/src/query/on_disk_cache.rs
@@ -492,9 +492,7 @@ impl<'a, 'tcx> CacheDecoder<'a, 'tcx> {
                 // expansion, so we use `import_source_files` to ensure that the foreign
                 // source files are actually imported before we call `source_file_by_stable_id`.
                 if source_file_cnum != LOCAL_CRATE {
-                    self.tcx
-                        .cstore_untracked()
-                        .import_source_files(self.tcx.sess, source_file_cnum);
+                    self.tcx.import_source_files(source_file_cnum);
                 }
 
                 source_map
@@ -634,12 +632,7 @@ impl<'a, 'tcx> SpanDecoder for CacheDecoder<'a, 'tcx> {
             expn_id
         } else {
             let index_guess = self.foreign_expn_data[&hash];
-            self.tcx.cstore_untracked().expn_hash_to_expn_id(
-                self.tcx.sess,
-                krate,
-                index_guess,
-                hash,
-            )
+            self.tcx.expn_hash_to_expn_id(krate, index_guess, hash)
         };
 
         debug_assert_eq!(expn_id.krate, krate);
diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs
index e1a8adca9da..0daf83162db 100644
--- a/compiler/rustc_middle/src/ty/context.rs
+++ b/compiler/rustc_middle/src/ty/context.rs
@@ -1165,11 +1165,7 @@ impl<'tcx> TyCtxt<'tcx> {
                 .local_def_path_hash_to_def_id(hash, err_msg)
                 .to_def_id()
         } else {
-            // If this is a DefPathHash from an upstream crate, let the CrateStore map
-            // it to a DefId.
-            let cstore = &*self.cstore_untracked();
-            let cnum = cstore.stable_crate_id_to_crate_num(stable_crate_id);
-            cstore.def_path_hash_to_def_id(cnum, hash)
+            self.def_path_hash_to_def_id_extern(hash, stable_crate_id)
         }
     }