]> git.lizzy.rs Git - rust.git/commitdiff
Move injected_panic_runtime to CrateStore
authorMark Rousskov <mark.simulacrum@gmail.com>
Mon, 11 Nov 2019 19:50:26 +0000 (14:50 -0500)
committerMark Rousskov <mark.simulacrum@gmail.com>
Mon, 11 Nov 2019 19:50:26 +0000 (14:50 -0500)
This was essentially a "query" previously (with no key, just always run
once when resolving the crate dependencies), and remains so, just now in
a way that isn't on Session. This removes the need for the `Once` as
well.

src/librustc/middle/cstore.rs
src/librustc/session/mod.rs
src/librustc/ty/context.rs
src/librustc_metadata/creader.rs
src/librustc_metadata/cstore.rs
src/librustc_metadata/dependency_format.rs
src/librustc_metadata/rmeta/decoder/cstore_impl.rs

index 1f4086227327e2af7111e594112e3b17a363b43b..f644853ebce8ab7628e23988b1a5feb1895b73af 100644 (file)
@@ -227,6 +227,7 @@ pub trait CrateStore {
     // utility functions
     fn encode_metadata(&self, tcx: TyCtxt<'_>) -> EncodedMetadata;
     fn metadata_encoding_version(&self) -> &[u8];
+    fn injected_panic_runtime(&self) -> Option<CrateNum>;
 }
 
 pub type CrateStoreDyn = dyn CrateStore + sync::Sync;
index 92e8e92d02a74e4cb737b5ba96c1998343307c2e..752a82f3115f029e5ac51d5317b03f7090663d66 100644 (file)
@@ -2,7 +2,6 @@
 use self::code_stats::CodeStats;
 
 use crate::dep_graph::cgu_reuse_tracker::CguReuseTracker;
-use crate::hir::def_id::CrateNum;
 use rustc_data_structures::fingerprint::Fingerprint;
 
 use crate::lint;
@@ -105,7 +104,6 @@ pub struct Session {
     /// dependency if it didn't already find one, and this tracks what was
     /// injected.
     pub allocator_kind: Once<Option<AllocatorKind>>,
-    pub injected_panic_runtime: Once<Option<CrateNum>>,
 
     /// Map from imported macro spans (which consist of
     /// the localized span for the macro body) to the
@@ -1182,7 +1180,6 @@ fn build_session_(
         type_length_limit: Once::new(),
         const_eval_stack_frame_limit: 100,
         allocator_kind: Once::new(),
-        injected_panic_runtime: Once::new(),
         imported_macro_spans: OneThread::new(RefCell::new(FxHashMap::default())),
         incr_comp_session: OneThread::new(RefCell::new(IncrCompSession::NotInitialized)),
         cgu_reuse_tracker,
index 04e0f6f4b56d71856434c6e71f905b07f306d4fd..d26b4012015522d8ef71e89c61ba2161ef194c1c 100644 (file)
@@ -1338,6 +1338,10 @@ pub fn crates(self) -> &'tcx [CrateNum] {
         self.all_crate_nums(LOCAL_CRATE)
     }
 
+    pub fn injected_panic_runtime(self) -> Option<CrateNum> {
+        self.cstore.injected_panic_runtime()
+    }
+
     pub fn features(self) -> &'tcx feature_gate::Features {
         self.features_query(LOCAL_CRATE)
     }
index 05e3ee3322e59d031b96bb805fcde3a50c2cbbcd..9c17b5b36e3bef0df4ea1c844a72683cdbd1542a 100644 (file)
@@ -531,7 +531,7 @@ fn inject_panic_runtime(&mut self, krate: &ast::Crate) {
         });
         if !any_non_rlib {
             info!("panic runtime injection skipped, only generating rlib");
-            self.sess.injected_panic_runtime.set(None);
+            self.cstore.injected_panic_runtime = None;
             return
         }
 
@@ -563,7 +563,7 @@ fn inject_panic_runtime(&mut self, krate: &ast::Crate) {
         // we just don't need one at all, then we're done here and there's
         // nothing else to do.
         if !needs_panic_runtime || runtime_found {
-            self.sess.injected_panic_runtime.set(None);
+            self.cstore.injected_panic_runtime = None;
             return
         }
 
@@ -600,7 +600,7 @@ fn inject_panic_runtime(&mut self, krate: &ast::Crate) {
                                    name, desired_strategy.desc()));
         }
 
-        self.sess.injected_panic_runtime.set(Some(cnum));
+        self.cstore.injected_panic_runtime = Some(cnum);
         self.inject_dependency_if(cnum, "a panic runtime",
                                   &|data| data.root.needs_panic_runtime);
     }
index c6c8ee575a98abdda0849974ef1cb4227c89eb45..456596be83ff54f9c0a22fe4e3b367e40ed31051 100644 (file)
 #[derive(Clone)]
 pub struct CStore {
     metas: IndexVec<CrateNum, Option<Lrc<CrateMetadata>>>,
+    pub(crate) injected_panic_runtime: Option<CrateNum>,
 }
 
 pub enum LoadedMacro {
@@ -116,6 +117,7 @@ fn default() -> Self {
             // corresponding `CrateNum`. This first entry will always remain
             // `None`.
             metas: IndexVec::from_elem_n(None, 1),
+            injected_panic_runtime: None,
         }
     }
 }
index 7f76a9730e198392cde7ac039bef100cc77ad373..dbf7fede1469f7d71da81a4db565d495aaa85249 100644 (file)
@@ -184,7 +184,7 @@ fn calculate_type(tcx: TyCtxt<'_>, ty: config::CrateType) -> DependencyList {
     //
     // Things like allocators and panic runtimes may not have been activated
     // quite yet, so do so here.
-    activate_injected_dep(*sess.injected_panic_runtime.get(), &mut ret,
+    activate_injected_dep(tcx.injected_panic_runtime(), &mut ret,
                           &|cnum| tcx.is_panic_runtime(cnum));
 
     // When dylib B links to dylib A, then when using B we must also link to A.
@@ -244,7 +244,6 @@ fn add_library(
 }
 
 fn attempt_static(tcx: TyCtxt<'_>) -> Option<DependencyList> {
-    let sess = &tcx.sess;
     let crates = cstore::used_crates(tcx, RequireStatic);
     if !crates.iter().by_ref().all(|&(_, ref p)| p.is_some()) {
         return None
@@ -264,7 +263,7 @@ fn attempt_static(tcx: TyCtxt<'_>) -> Option<DependencyList> {
     // Our allocator/panic runtime may not have been linked above if it wasn't
     // explicitly linked, which is the case for any injected dependency. Handle
     // that here and activate them.
-    activate_injected_dep(*sess.injected_panic_runtime.get(), &mut ret,
+    activate_injected_dep(tcx.injected_panic_runtime(), &mut ret,
                           &|cnum| tcx.is_panic_runtime(cnum));
 
     Some(ret)
index 015866548cd3846d3c3e191b647fc7113ab50c83..dc11a5aa196b72fcd5bda896d0ed4b67e9c77ad2 100644 (file)
@@ -527,4 +527,8 @@ fn metadata_encoding_version(&self) -> &[u8]
     {
         rmeta::METADATA_HEADER
     }
+
+    fn injected_panic_runtime(&self) -> Option<CrateNum> {
+        self.injected_panic_runtime
+    }
 }