about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEduard-Mihai Burtescu <edy.burt@gmail.com>2018-11-16 13:39:56 +0200
committerEduard-Mihai Burtescu <edy.burt@gmail.com>2018-11-16 15:08:18 +0200
commitd1410ada92bfc80f4e7020336e182670084acd0e (patch)
tree415da9e0a10162e91a854e00b50621ea8bedda30
parent47c84c4234a6e3ee24888bd94daeec13df7dd20d (diff)
downloadrust-d1410ada92bfc80f4e7020336e182670084acd0e.tar.gz
rust-d1410ada92bfc80f4e7020336e182670084acd0e.zip
[eddyb] rustc_codegen_ssa: avoid a `Clone` bound on `TargetMachine`.
-rw-r--r--src/librustc_codegen_llvm/back/lto.rs2
-rw-r--r--src/librustc_codegen_llvm/lib.rs11
-rw-r--r--src/librustc_codegen_ssa/back/write.rs16
-rw-r--r--src/librustc_codegen_ssa/interfaces/write.rs2
4 files changed, 15 insertions, 16 deletions
diff --git a/src/librustc_codegen_llvm/back/lto.rs b/src/librustc_codegen_llvm/back/lto.rs
index a5f07e46e11..2fc8deeec8a 100644
--- a/src/librustc_codegen_llvm/back/lto.rs
+++ b/src/librustc_codegen_llvm/back/lto.rs
@@ -649,7 +649,7 @@ pub unsafe fn optimize_thin_module(
     timeline: &mut Timeline
 ) -> Result<ModuleCodegen<ModuleLlvm>, FatalError> {
     let diag_handler = cgcx.create_diag_handler();
-    let tm = (cgcx.tm_factory)().map_err(|e| {
+    let tm = (cgcx.tm_factory.0)().map_err(|e| {
         write::llvm_err(&diag_handler, &e)
     })?;
 
diff --git a/src/librustc_codegen_llvm/lib.rs b/src/librustc_codegen_llvm/lib.rs
index 29bc3becd7e..9d569a4e28c 100644
--- a/src/librustc_codegen_llvm/lib.rs
+++ b/src/librustc_codegen_llvm/lib.rs
@@ -165,17 +165,6 @@ impl ExtraBackendMethods for LlvmCodegenBackend {
     }
 }
 
-impl Clone for &'static mut llvm::TargetMachine {
-    fn clone(&self) -> Self {
-        // This method should never be called. It is put here because in
-        // rustc_codegen_ssa::back::write::CodegenContext, the TargetMachine is contained in a
-        // closure returned by a function under an Arc. The clone-deriving algorithm works when the
-        // struct contains the original LLVM TargetMachine type but not any more when supplied with
-        // a generic type. Hence this dummy Clone implementation.
-        panic!()
-    }
-}
-
 impl WriteBackendMethods for LlvmCodegenBackend {
     type Module = ModuleLlvm;
     type ModuleBuffer = back::lto::ModuleBuffer;
diff --git a/src/librustc_codegen_ssa/back/write.rs b/src/librustc_codegen_ssa/back/write.rs
index e958b5441f2..e8cf9e7f40a 100644
--- a/src/librustc_codegen_ssa/back/write.rs
+++ b/src/librustc_codegen_ssa/back/write.rs
@@ -178,6 +178,17 @@ pub struct AssemblerCommand {
     cmd: Command,
 }
 
+// HACK(eddyb) work around `#[derive]` producing wrong bounds for `Clone`.
+pub struct TargetMachineFactory<B: WriteBackendMethods>(
+    pub Arc<dyn Fn() -> Result<B::TargetMachine, String> + Send + Sync>,
+);
+
+impl<B: WriteBackendMethods> Clone for TargetMachineFactory<B> {
+    fn clone(&self) -> Self {
+        TargetMachineFactory(self.0.clone())
+    }
+}
+
 /// Additional resources used by optimize_and_codegen (not module specific)
 #[derive(Clone)]
 pub struct CodegenContext<B: WriteBackendMethods> {
@@ -196,8 +207,7 @@ pub struct CodegenContext<B: WriteBackendMethods> {
     pub regular_module_config: Arc<ModuleConfig>,
     pub metadata_module_config: Arc<ModuleConfig>,
     pub allocator_module_config: Arc<ModuleConfig>,
-    pub tm_factory: Arc<dyn Fn()
-        -> Result<B::TargetMachine, String> + Send + Sync>,
+    pub tm_factory: TargetMachineFactory<B>,
     pub msvc_imps_needed: bool,
     pub target_pointer_width: String,
     pub debuginfo: config::DebugInfo,
@@ -962,7 +972,7 @@ fn start_executing_work<B: ExtraBackendMethods>(
         regular_module_config: modules_config,
         metadata_module_config: metadata_config,
         allocator_module_config: allocator_config,
-        tm_factory: backend.target_machine_factory(tcx.sess, false),
+        tm_factory: TargetMachineFactory(backend.target_machine_factory(tcx.sess, false)),
         total_cgus,
         msvc_imps_needed: msvc_imps_needed(tcx),
         target_pointer_width: tcx.sess.target.target.target_pointer_width.clone(),
diff --git a/src/librustc_codegen_ssa/interfaces/write.rs b/src/librustc_codegen_ssa/interfaces/write.rs
index 3419e1c59ed..72522e19af2 100644
--- a/src/librustc_codegen_ssa/interfaces/write.rs
+++ b/src/librustc_codegen_ssa/interfaces/write.rs
@@ -18,7 +18,7 @@ use rustc_errors::{FatalError, Handler};
 
 pub trait WriteBackendMethods: 'static + Sized + Clone {
     type Module: Send + Sync;
-    type TargetMachine: Clone;
+    type TargetMachine;
     type ModuleBuffer: ModuleBufferMethods;
     type Context: ?Sized;
     type ThinData: Send + Sync;