summary refs log tree commit diff
path: root/src/librustc_codegen_ssa
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2019-09-26 17:55:13 +0200
committerGitHub <noreply@github.com>2019-09-26 17:55:13 +0200
commit01303936f37ef494bfe11012645ff7ca37606fdf (patch)
treea12dba5010e0fb65b0406d176e5caa44ed06a4cb /src/librustc_codegen_ssa
parent3b5fbb6a3616cc530edba496bbca3ddb02e19762 (diff)
parentb8a040fc5f5edc41af0ccb070239898c0c5d5484 (diff)
downloadrust-01303936f37ef494bfe11012645ff7ca37606fdf.tar.gz
rust-01303936f37ef494bfe11012645ff7ca37606fdf.zip
Rollup merge of #64772 - Mark-Simulacrum:no-tyctxt-tx, r=eddyb
Remove tx_to_llvm_workers from TyCtxt

This can be kept within the codegen backend crates entirely -- there's no reason for us to create it outside and attempt to hold it in the (global) context.

Changes here aren't really too easily reviewable I suspect -- not sure if they can be cleaned up by splitting into more commits though, it's just hard to reason about `Box<Any>` in general. If there are thoughts though I'd be happy to hear them.

The primary goal of this PR is to get rid of the field on `rustc_interface::Queries`.
Diffstat (limited to 'src/librustc_codegen_ssa')
-rw-r--r--src/librustc_codegen_ssa/back/write.rs23
-rw-r--r--src/librustc_codegen_ssa/base.rs25
-rw-r--r--src/librustc_codegen_ssa/traits/backend.rs8
3 files changed, 27 insertions, 29 deletions
diff --git a/src/librustc_codegen_ssa/back/write.rs b/src/librustc_codegen_ssa/back/write.rs
index 1a2c23ae0d4..3c5fbfd0f86 100644
--- a/src/librustc_codegen_ssa/back/write.rs
+++ b/src/librustc_codegen_ssa/back/write.rs
@@ -376,9 +376,9 @@ pub fn start_async_codegen<B: ExtraBackendMethods>(
     backend: B,
     tcx: TyCtxt<'_>,
     metadata: EncodedMetadata,
-    coordinator_receive: Receiver<Box<dyn Any + Send>>,
     total_cgus: usize,
 ) -> OngoingCodegen<B> {
+    let (coordinator_send, coordinator_receive) = channel();
     let sess = tcx.sess;
     let crate_name = tcx.crate_name(LOCAL_CRATE);
     let crate_hash = tcx.crate_hash(LOCAL_CRATE);
@@ -500,7 +500,8 @@ pub fn start_async_codegen<B: ExtraBackendMethods>(
                                                   sess.jobserver.clone(),
                                                   Arc::new(modules_config),
                                                   Arc::new(metadata_config),
-                                                  Arc::new(allocator_config));
+                                                  Arc::new(allocator_config),
+                                                  coordinator_send.clone());
 
     OngoingCodegen {
         backend,
@@ -511,7 +512,7 @@ pub fn start_async_codegen<B: ExtraBackendMethods>(
         linker_info,
         crate_info,
 
-        coordinator_send: tcx.tx_to_llvm_workers.lock().clone(),
+        coordinator_send,
         codegen_worker_receive,
         shared_emitter_main,
         future: coordinator_thread,
@@ -1005,8 +1006,9 @@ fn start_executing_work<B: ExtraBackendMethods>(
     modules_config: Arc<ModuleConfig>,
     metadata_config: Arc<ModuleConfig>,
     allocator_config: Arc<ModuleConfig>,
+    tx_to_llvm_workers: Sender<Box<dyn Any + Send>>,
 ) -> thread::JoinHandle<Result<CompiledModules, ()>> {
-    let coordinator_send = tcx.tx_to_llvm_workers.lock().clone();
+    let coordinator_send = tx_to_llvm_workers;
     let sess = tcx.sess;
 
     // Compute the set of symbols we need to retain when doing LTO (if we need to)
@@ -1857,7 +1859,7 @@ impl<B: ExtraBackendMethods> OngoingCodegen<B> {
 
         // These are generally cheap and won't throw off scheduling.
         let cost = 0;
-        submit_codegened_module_to_llvm(&self.backend, tcx, module, cost);
+        submit_codegened_module_to_llvm(&self.backend, &self.coordinator_send, module, cost);
     }
 
     pub fn codegen_finished(&self, tcx: TyCtxt<'_>) {
@@ -1899,12 +1901,12 @@ impl<B: ExtraBackendMethods> OngoingCodegen<B> {
 
 pub fn submit_codegened_module_to_llvm<B: ExtraBackendMethods>(
     _backend: &B,
-    tcx: TyCtxt<'_>,
+    tx_to_llvm_workers: &Sender<Box<dyn Any + Send>>,
     module: ModuleCodegen<B::Module>,
     cost: u64,
 ) {
     let llvm_work_item = WorkItem::Optimize(module);
-    drop(tcx.tx_to_llvm_workers.lock().send(Box::new(Message::CodegenDone::<B> {
+    drop(tx_to_llvm_workers.send(Box::new(Message::CodegenDone::<B> {
         llvm_work_item,
         cost,
     })));
@@ -1912,11 +1914,11 @@ pub fn submit_codegened_module_to_llvm<B: ExtraBackendMethods>(
 
 pub fn submit_post_lto_module_to_llvm<B: ExtraBackendMethods>(
     _backend: &B,
-    tcx: TyCtxt<'_>,
+    tx_to_llvm_workers: &Sender<Box<dyn Any + Send>>,
     module: CachedModuleCodegen,
 ) {
     let llvm_work_item = WorkItem::CopyPostLtoArtifacts(module);
-    drop(tcx.tx_to_llvm_workers.lock().send(Box::new(Message::CodegenDone::<B> {
+    drop(tx_to_llvm_workers.send(Box::new(Message::CodegenDone::<B> {
         llvm_work_item,
         cost: 0,
     })));
@@ -1925,6 +1927,7 @@ pub fn submit_post_lto_module_to_llvm<B: ExtraBackendMethods>(
 pub fn submit_pre_lto_module_to_llvm<B: ExtraBackendMethods>(
     _backend: &B,
     tcx: TyCtxt<'_>,
+    tx_to_llvm_workers: &Sender<Box<dyn Any + Send>>,
     module: CachedModuleCodegen,
 ) {
     let filename = pre_lto_bitcode_filename(&module.name);
@@ -1939,7 +1942,7 @@ pub fn submit_pre_lto_module_to_llvm<B: ExtraBackendMethods>(
         })
     };
     // Schedule the module to be loaded
-    drop(tcx.tx_to_llvm_workers.lock().send(Box::new(Message::AddImportOnlyModule::<B> {
+    drop(tx_to_llvm_workers.send(Box::new(Message::AddImportOnlyModule::<B> {
         module_data: SerializedModule::FromUncompressedFile(mmap),
         work_product: module.source,
     })));
diff --git a/src/librustc_codegen_ssa/base.rs b/src/librustc_codegen_ssa/base.rs
index 8f7f769f6b9..90ed629bbc6 100644
--- a/src/librustc_codegen_ssa/base.rs
+++ b/src/librustc_codegen_ssa/base.rs
@@ -43,11 +43,9 @@ use crate::mir;
 
 use crate::traits::*;
 
-use std::any::Any;
 use std::cmp;
 use std::ops::{Deref, DerefMut};
 use std::time::{Instant, Duration};
-use std::sync::mpsc;
 use syntax_pos::Span;
 use syntax::attr;
 use rustc::hir;
@@ -482,19 +480,13 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
     tcx: TyCtxt<'tcx>,
     metadata: EncodedMetadata,
     need_metadata_module: bool,
-    rx: mpsc::Receiver<Box<dyn Any + Send>>,
 ) -> OngoingCodegen<B> {
     check_for_rustc_errors_attr(tcx);
 
     // Skip crate items and just output metadata in -Z no-codegen mode.
     if tcx.sess.opts.debugging_opts.no_codegen ||
        !tcx.sess.opts.output_types.should_codegen() {
-        let ongoing_codegen = start_async_codegen(
-            backend,
-            tcx,
-            metadata,
-            rx,
-            1);
+        let ongoing_codegen = start_async_codegen(backend, tcx, metadata, 1);
 
         ongoing_codegen.codegen_finished(tcx);
 
@@ -523,12 +515,7 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
         }
     }
 
-    let ongoing_codegen = start_async_codegen(
-        backend.clone(),
-        tcx,
-        metadata,
-        rx,
-        codegen_units.len());
+    let ongoing_codegen = start_async_codegen(backend.clone(), tcx, metadata, codegen_units.len());
     let ongoing_codegen = AbortCodegenOnDrop::<B>(Some(ongoing_codegen));
 
     // Codegen an allocator shim, if necessary.
@@ -614,20 +601,22 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
             CguReuse::No => {
                 tcx.sess.profiler(|p| p.start_activity(format!("codegen {}", cgu.name())));
                 let start_time = Instant::now();
-                backend.compile_codegen_unit(tcx, *cgu.name());
+                backend.compile_codegen_unit(tcx, *cgu.name(), &ongoing_codegen.coordinator_send);
                 total_codegen_time += start_time.elapsed();
                 tcx.sess.profiler(|p| p.end_activity(format!("codegen {}", cgu.name())));
                 false
             }
             CguReuse::PreLto => {
-                submit_pre_lto_module_to_llvm(&backend, tcx, CachedModuleCodegen {
+                submit_pre_lto_module_to_llvm(&backend, tcx, &ongoing_codegen.coordinator_send,
+                CachedModuleCodegen {
                     name: cgu.name().to_string(),
                     source: cgu.work_product(tcx),
                 });
                 true
             }
             CguReuse::PostLto => {
-                submit_post_lto_module_to_llvm(&backend, tcx, CachedModuleCodegen {
+                submit_post_lto_module_to_llvm(&backend, &ongoing_codegen.coordinator_send,
+                CachedModuleCodegen {
                     name: cgu.name().to_string(),
                     source: cgu.work_product(tcx),
                 });
diff --git a/src/librustc_codegen_ssa/traits/backend.rs b/src/librustc_codegen_ssa/traits/backend.rs
index 9fbb44dcc99..cb197f51460 100644
--- a/src/librustc_codegen_ssa/traits/backend.rs
+++ b/src/librustc_codegen_ssa/traits/backend.rs
@@ -8,6 +8,7 @@ use rustc::session::{Session, config};
 use rustc::ty::TyCtxt;
 use rustc_codegen_utils::codegen_backend::CodegenBackend;
 use std::sync::Arc;
+use std::sync::mpsc;
 use syntax::ext::allocator::AllocatorKind;
 use syntax_pos::symbol::InternedString;
 
@@ -44,7 +45,12 @@ pub trait ExtraBackendMethods: CodegenBackend + WriteBackendMethods + Sized + Se
         mods: &mut Self::Module,
         kind: AllocatorKind,
     );
-    fn compile_codegen_unit(&self, tcx: TyCtxt<'_>, cgu_name: InternedString);
+    fn compile_codegen_unit(
+        &self,
+        tcx: TyCtxt<'_>,
+        cgu_name: InternedString,
+        tx_to_llvm_workers: &mpsc::Sender<Box<dyn std::any::Any + Send>>,
+    );
     // If find_features is true this won't access `sess.crate_types` by assuming
     // that `is_pie_binary` is false. When we discover LLVM target features
     // `sess.crate_types` is uninitialized so we cannot access it.