]> git.lizzy.rs Git - rust.git/commitdiff
Make Session.has_global_allocator thread-safe
authorJohn Kåre Alsaker <john.kare.alsaker@gmail.com>
Sun, 1 Apr 2018 06:24:46 +0000 (08:24 +0200)
committerJohn Kåre Alsaker <john.kare.alsaker@gmail.com>
Tue, 10 Apr 2018 12:40:25 +0000 (14:40 +0200)
src/librustc/session/mod.rs
src/librustc_metadata/creader.rs
src/librustc_metadata/encoder.rs

index 731e4feefa0fe1577828d83ddc7b38d8c23cf5b3..1c11c52357d1ce8b7f6b065f48574b83c2d0384a 100644 (file)
@@ -161,7 +161,7 @@ pub struct Session {
     pub jobserver_from_env: Option<Client>,
 
     /// Metadata about the allocators for the current crate being compiled
-    pub has_global_allocator: Cell<bool>,
+    pub has_global_allocator: Once<bool>,
 }
 
 pub struct PerfStats {
@@ -1142,7 +1142,7 @@ pub fn build_session_(
             });
             (*GLOBAL_JOBSERVER).clone()
         },
-        has_global_allocator: Cell::new(false),
+        has_global_allocator: Once::new(),
     };
 
     sess
index 86f495c5fac3a2782e245ed06bc2364d0184f2ad..5b54994b9ceab5d2ba917ee053541aabd9055990 100644 (file)
@@ -812,9 +812,7 @@ fn inject_profiler_runtime(&mut self) {
 
     fn inject_allocator_crate(&mut self, krate: &ast::Crate) {
         let has_global_allocator = has_global_allocator(krate);
-        if has_global_allocator {
-            self.sess.has_global_allocator.set(true);
-        }
+        self.sess.has_global_allocator.set(has_global_allocator);
 
         // Check to see if we actually need an allocator. This desire comes
         // about through the `#![needs_allocator]` attribute and is typically
index 1b208a512e2a46c6a977b5c272aef67f8a7e95a7..66071f242fb951ff31bf514dedc06e24fb332374 100644 (file)
@@ -459,7 +459,7 @@ fn encode_crate_root(&mut self) -> Lazy<CrateRoot> {
         let is_proc_macro = tcx.sess.crate_types.borrow().contains(&CrateTypeProcMacro);
         let has_default_lib_allocator =
             attr::contains_name(tcx.hir.krate_attrs(), "default_lib_allocator");
-        let has_global_allocator = tcx.sess.has_global_allocator.get();
+        let has_global_allocator = *tcx.sess.has_global_allocator.get();
         let root = self.lazy(&CrateRoot {
             name: tcx.crate_name(LOCAL_CRATE),
             extra_filename: tcx.sess.opts.cg.extra_filename.clone(),