Skip to content

Commit 2ecf892

Browse files
committed
Fix clippy warnings
1 parent ec46c89 commit 2ecf892

File tree

3 files changed

+36
-14
lines changed

3 files changed

+36
-14
lines changed

src/back/lto.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ use tempfile::{tempdir, TempDir};
3939

4040
use crate::back::write::save_temp_bitcode;
4141
use crate::errors::{DynamicLinkingWithLTO, LtoBitcodeFromRlib, LtoDisallowed, LtoDylib};
42-
use crate::{to_gcc_opt_level, GccCodegenBackend, GccContext};
42+
use crate::{to_gcc_opt_level, GccCodegenBackend, GccContext, SyncContext};
4343

4444
/// We keep track of the computed LTO cache keys from the previous
4545
/// session to determine which CGUs we can reuse.
@@ -483,9 +483,9 @@ fn thin_lto(
483483
});*/
484484

485485
match module {
486-
SerializedModule::Local(ref module_buffer) => {
487-
let path = module_buffer.0.to_str().expect("path");
488-
let my_path = PathBuf::from(path);
486+
SerializedModule::Local(_) => {
487+
//let path = module_buffer.0.to_str().expect("path");
488+
//let my_path = PathBuf::from(path);
489489
//let exists = my_path.exists();
490490
//println!("Path: {:?}: {}", path, exists);
491491
/*module.module_llvm.should_combine_object_files = true;
@@ -642,7 +642,7 @@ pub unsafe fn optimize_thin_module(
642642
unimplemented!("from uncompressed file")
643643
}
644644
}
645-
Arc::new(context)
645+
Arc::new(SyncContext::new(context))
646646
}
647647
};
648648
let module = ModuleCodegen {
@@ -716,15 +716,15 @@ pub unsafe fn optimize_thin_module(
716716
}
717717

718718
pub struct ThinBuffer {
719-
context: Arc<Context<'static>>,
719+
context: Arc<SyncContext>,
720720
}
721721

722722
// TODO: check if this makes sense to make ThinBuffer Send and Sync.
723723
unsafe impl Send for ThinBuffer {}
724724
unsafe impl Sync for ThinBuffer {}
725725

726726
impl ThinBuffer {
727-
pub fn new(context: &Arc<Context<'static>>) -> Self {
727+
pub(crate) fn new(context: &Arc<SyncContext>) -> Self {
728728
Self { context: Arc::clone(context) }
729729
}
730730
}

src/base.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use rustc_target::spec::PanicStrategy;
1919

2020
use crate::builder::Builder;
2121
use crate::context::CodegenCx;
22-
use crate::GccContext;
22+
use crate::{GccContext, SyncContext};
2323
use crate::{gcc_util, new_context, LockedTargetInfo};
2424

2525
#[cfg(feature = "master")]
@@ -207,7 +207,7 @@ pub fn compile_codegen_unit(
207207
ModuleCodegen {
208208
name: cgu_name.to_string(),
209209
module_llvm: GccContext {
210-
context: Arc::new(context),
210+
context: Arc::new(SyncContext::new(context)),
211211
should_combine_object_files: false,
212212
temp_dir: None,
213213
},

src/lib.rs

+27-5
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ mod type_of;
7474

7575
use std::any::Any;
7676
use std::fmt::Debug;
77+
use std::ops::Deref;
7778
#[cfg(not(feature = "master"))]
7879
use std::sync::atomic::AtomicBool;
7980
#[cfg(not(feature = "master"))]
@@ -295,7 +296,7 @@ impl ExtraBackendMethods for GccCodegenBackend {
295296
alloc_error_handler_kind: AllocatorKind,
296297
) -> Self::Module {
297298
let mut mods = GccContext {
298-
context: Arc::new(new_context(tcx)),
299+
context: Arc::new(SyncContext::new(new_context(tcx))),
299300
should_combine_object_files: false,
300301
temp_dir: None,
301302
};
@@ -326,15 +327,36 @@ impl ExtraBackendMethods for GccCodegenBackend {
326327
}
327328

328329
pub struct GccContext {
329-
context: Arc<Context<'static>>,
330+
context: Arc<SyncContext>,
330331
should_combine_object_files: bool,
331332
// Temporary directory used by LTO. We keep it here so that it's not removed before linking.
332333
temp_dir: Option<TempDir>,
333334
}
334335

335-
unsafe impl Send for GccContext {}
336-
// FIXME(antoyo): that shouldn't be Sync. Parallel compilation is currently disabled with "-Zno-parallel-llvm". Try to disable it here.
337-
unsafe impl Sync for GccContext {}
336+
struct SyncContext {
337+
context: Context<'static>,
338+
}
339+
340+
impl SyncContext {
341+
fn new(context: Context<'static>) -> Self {
342+
Self {
343+
context,
344+
}
345+
}
346+
}
347+
348+
impl Deref for SyncContext {
349+
type Target = Context<'static>;
350+
351+
fn deref(&self) -> &Self::Target {
352+
&self.context
353+
}
354+
}
355+
356+
unsafe impl Send for SyncContext {}
357+
// FIXME(antoyo): that shouldn't be Sync. Parallel compilation is currently disabled with "-Zno-parallel-llvm".
358+
// TODO: disable it here by returing false in CodegenBackend::supports_parallel().
359+
unsafe impl Sync for SyncContext {}
338360

339361
impl WriteBackendMethods for GccCodegenBackend {
340362
type Module = GccContext;

0 commit comments

Comments
 (0)