about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAntoni Boucher <bouanto@zoho.com>2024-06-28 14:00:45 -0400
committerAntoni Boucher <bouanto@zoho.com>2024-07-02 12:27:31 -0400
commitbbc765b49b7c0d57a30476c2550303d46c75ade3 (patch)
treeaf86511acb982d6e9d57a2f301e03eb1a25dcb92
parent21b1b11981b1c679c32e723cefcc1eb76b0b9a62 (diff)
downloadrust-bbc765b49b7c0d57a30476c2550303d46c75ade3.tar.gz
rust-bbc765b49b7c0d57a30476c2550303d46c75ade3.zip
Fix clippy warnings
-rw-r--r--src/back/lto.rs14
-rw-r--r--src/base.rs4
-rw-r--r--src/lib.rs30
3 files changed, 34 insertions, 14 deletions
diff --git a/src/back/lto.rs b/src/back/lto.rs
index 5b6eec85550..4b31bfac5dd 100644
--- a/src/back/lto.rs
+++ b/src/back/lto.rs
@@ -39,7 +39,7 @@ use tempfile::{tempdir, TempDir};
 
 use crate::back::write::save_temp_bitcode;
 use crate::errors::{DynamicLinkingWithLTO, LtoBitcodeFromRlib, LtoDisallowed, LtoDylib};
-use crate::{to_gcc_opt_level, GccCodegenBackend, GccContext};
+use crate::{to_gcc_opt_level, GccCodegenBackend, GccContext, SyncContext};
 
 /// We keep track of the computed LTO cache keys from the previous
 /// session to determine which CGUs we can reuse.
@@ -485,9 +485,9 @@ fn thin_lto(
         });*/
 
         match module {
-            SerializedModule::Local(ref module_buffer) => {
-                let path = module_buffer.0.to_str().expect("path");
-                let my_path = PathBuf::from(path);
+            SerializedModule::Local(_) => {
+                //let path = module_buffer.0.to_str().expect("path");
+                //let my_path = PathBuf::from(path);
                 //let exists = my_path.exists();
                 //println!("Path: {:?}: {}", path, exists);
                 /*module.module_llvm.should_combine_object_files = true;
@@ -644,7 +644,7 @@ pub unsafe fn optimize_thin_module(
                     unimplemented!("from uncompressed file")
                 }
             }
-            Arc::new(context)
+            Arc::new(SyncContext::new(context))
         }
     };
     let module = ModuleCodegen {
@@ -718,7 +718,7 @@ pub unsafe fn optimize_thin_module(
 }
 
 pub struct ThinBuffer {
-    context: Arc<Context<'static>>,
+    context: Arc<SyncContext>,
 }
 
 // TODO: check if this makes sense to make ThinBuffer Send and Sync.
@@ -726,7 +726,7 @@ unsafe impl Send for ThinBuffer {}
 unsafe impl Sync for ThinBuffer {}
 
 impl ThinBuffer {
-    pub fn new(context: &Arc<Context<'static>>) -> Self {
+    pub(crate) fn new(context: &Arc<SyncContext>) -> Self {
         Self { context: Arc::clone(context) }
     }
 }
diff --git a/src/base.rs b/src/base.rs
index b2cf6fe51df..488757c4484 100644
--- a/src/base.rs
+++ b/src/base.rs
@@ -19,8 +19,8 @@ use rustc_target::spec::PanicStrategy;
 
 use crate::builder::Builder;
 use crate::context::CodegenCx;
-use crate::GccContext;
 use crate::{gcc_util, new_context, LockedTargetInfo};
+use crate::{GccContext, SyncContext};
 
 #[cfg(feature = "master")]
 pub fn visibility_to_gcc(linkage: Visibility) -> gccjit::Visibility {
@@ -207,7 +207,7 @@ pub fn compile_codegen_unit(
         ModuleCodegen {
             name: cgu_name.to_string(),
             module_llvm: GccContext {
-                context: Arc::new(context),
+                context: Arc::new(SyncContext::new(context)),
                 should_combine_object_files: false,
                 temp_dir: None,
             },
diff --git a/src/lib.rs b/src/lib.rs
index 3df48f96e8c..ce781b3f3ff 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -73,6 +73,7 @@ mod type_of;
 
 use std::any::Any;
 use std::fmt::Debug;
+use std::ops::Deref;
 #[cfg(not(feature = "master"))]
 use std::sync::atomic::AtomicBool;
 #[cfg(not(feature = "master"))]
@@ -294,7 +295,7 @@ impl ExtraBackendMethods for GccCodegenBackend {
         alloc_error_handler_kind: AllocatorKind,
     ) -> Self::Module {
         let mut mods = GccContext {
-            context: Arc::new(new_context(tcx)),
+            context: Arc::new(SyncContext::new(new_context(tcx))),
             should_combine_object_files: false,
             temp_dir: None,
         };
@@ -325,15 +326,34 @@ impl ExtraBackendMethods for GccCodegenBackend {
 }
 
 pub struct GccContext {
-    context: Arc<Context<'static>>,
+    context: Arc<SyncContext>,
     should_combine_object_files: bool,
     // Temporary directory used by LTO. We keep it here so that it's not removed before linking.
     temp_dir: Option<TempDir>,
 }
 
-unsafe impl Send for GccContext {}
-// FIXME(antoyo): that shouldn't be Sync. Parallel compilation is currently disabled with "-Zno-parallel-llvm". Try to disable it here.
-unsafe impl Sync for GccContext {}
+struct SyncContext {
+    context: Context<'static>,
+}
+
+impl SyncContext {
+    fn new(context: Context<'static>) -> Self {
+        Self { context }
+    }
+}
+
+impl Deref for SyncContext {
+    type Target = Context<'static>;
+
+    fn deref(&self) -> &Self::Target {
+        &self.context
+    }
+}
+
+unsafe impl Send for SyncContext {}
+// FIXME(antoyo): that shouldn't be Sync. Parallel compilation is currently disabled with "-Zno-parallel-llvm".
+// TODO: disable it here by returing false in CodegenBackend::supports_parallel().
+unsafe impl Sync for SyncContext {}
 
 impl WriteBackendMethods for GccCodegenBackend {
     type Module = GccContext;