about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJohn Kåre Alsaker <john.kare.alsaker@gmail.com>2018-04-01 08:27:46 +0200
committerJohn Kåre Alsaker <john.kare.alsaker@gmail.com>2018-04-10 14:40:26 +0200
commit006f9b2f5616ad970cb0f5102ec50e02ef2dd379 (patch)
tree90965ebb939774a823c1646bb1d3ec9de3e829a7
parentdacf9ba00fb8d6b7202a1ed5f06febe3fd2cf9b4 (diff)
downloadrust-006f9b2f5616ad970cb0f5102ec50e02ef2dd379.tar.gz
rust-006f9b2f5616ad970cb0f5102ec50e02ef2dd379.zip
Make Session.injected_panic_runtime thread-safe
-rw-r--r--src/librustc/middle/dependency_format.rs4
-rw-r--r--src/librustc/session/mod.rs4
-rw-r--r--src/librustc_metadata/creader.rs2
3 files changed, 6 insertions, 4 deletions
diff --git a/src/librustc/middle/dependency_format.rs b/src/librustc/middle/dependency_format.rs
index f7dfc3c33c0..e7fc8d633c8 100644
--- a/src/librustc/middle/dependency_format.rs
+++ b/src/librustc/middle/dependency_format.rs
@@ -223,7 +223,7 @@ fn calculate_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
     //
     // 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(*sess.injected_panic_runtime.get(), &mut ret,
                           &|cnum| tcx.is_panic_runtime(cnum));
     activate_injected_allocator(sess, &mut ret);
 
@@ -302,7 +302,7 @@ fn attempt_static<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> Option<DependencyLis
     // 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(*sess.injected_panic_runtime.get(), &mut ret,
                           &|cnum| tcx.is_panic_runtime(cnum));
     activate_injected_allocator(sess, &mut ret);
 
diff --git a/src/librustc/session/mod.rs b/src/librustc/session/mod.rs
index a92a2c916b2..8f2043fdfc6 100644
--- a/src/librustc/session/mod.rs
+++ b/src/librustc/session/mod.rs
@@ -120,7 +120,7 @@ pub struct Session {
     /// injected.
     pub injected_allocator: Once<Option<CrateNum>>,
     pub allocator_kind: Once<Option<AllocatorKind>>,
-    pub injected_panic_runtime: Cell<Option<CrateNum>>,
+    pub injected_panic_runtime: Once<Option<CrateNum>>,
 
     /// Map from imported macro spans (which consist of
     /// the localized span for the macro body) to the
@@ -1107,7 +1107,7 @@ pub fn build_session_(
         next_node_id: OneThread::new(Cell::new(NodeId::new(1))),
         injected_allocator: Once::new(),
         allocator_kind: Once::new(),
-        injected_panic_runtime: Cell::new(None),
+        injected_panic_runtime: Once::new(),
         imported_macro_spans: OneThread::new(RefCell::new(HashMap::new())),
         incr_comp_session: OneThread::new(RefCell::new(IncrCompSession::NotInitialized)),
         ignored_attr_names: ich::compute_ignored_attr_names(),
diff --git a/src/librustc_metadata/creader.rs b/src/librustc_metadata/creader.rs
index 06baea53cd5..34d9f47bac3 100644
--- a/src/librustc_metadata/creader.rs
+++ b/src/librustc_metadata/creader.rs
@@ -614,6 +614,7 @@ impl<'a> CrateLoader<'a> {
         });
         if !any_non_rlib {
             info!("panic runtime injection skipped, only generating rlib");
+            self.sess.injected_panic_runtime.set(None);
             return
         }
 
@@ -646,6 +647,7 @@ impl<'a> CrateLoader<'a> {
         // 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);
             return
         }