Skip to content

Commit bbc765b

Browse files
committed
Fix clippy warnings
1 parent 21b1b11 commit bbc765b

File tree

3 files changed

+34
-14
lines changed

3 files changed

+34
-14
lines changed

src/back/lto.rs

Lines changed: 7 additions & 7 deletions
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.
@@ -485,9 +485,9 @@ fn thin_lto(
485485
});*/
486486

487487
match module {
488-
SerializedModule::Local(ref module_buffer) => {
489-
let path = module_buffer.0.to_str().expect("path");
490-
let my_path = PathBuf::from(path);
488+
SerializedModule::Local(_) => {
489+
//let path = module_buffer.0.to_str().expect("path");
490+
//let my_path = PathBuf::from(path);
491491
//let exists = my_path.exists();
492492
//println!("Path: {:?}: {}", path, exists);
493493
/*module.module_llvm.should_combine_object_files = true;
@@ -644,7 +644,7 @@ pub unsafe fn optimize_thin_module(
644644
unimplemented!("from uncompressed file")
645645
}
646646
}
647-
Arc::new(context)
647+
Arc::new(SyncContext::new(context))
648648
}
649649
};
650650
let module = ModuleCodegen {
@@ -718,15 +718,15 @@ pub unsafe fn optimize_thin_module(
718718
}
719719

720720
pub struct ThinBuffer {
721-
context: Arc<Context<'static>>,
721+
context: Arc<SyncContext>,
722722
}
723723

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

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

src/base.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ use rustc_target::spec::PanicStrategy;
1919

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

2525
#[cfg(feature = "master")]
2626
pub fn visibility_to_gcc(linkage: Visibility) -> gccjit::Visibility {
@@ -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

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ mod type_of;
7373

7474
use std::any::Any;
7575
use std::fmt::Debug;
76+
use std::ops::Deref;
7677
#[cfg(not(feature = "master"))]
7778
use std::sync::atomic::AtomicBool;
7879
#[cfg(not(feature = "master"))]
@@ -294,7 +295,7 @@ impl ExtraBackendMethods for GccCodegenBackend {
294295
alloc_error_handler_kind: AllocatorKind,
295296
) -> Self::Module {
296297
let mut mods = GccContext {
297-
context: Arc::new(new_context(tcx)),
298+
context: Arc::new(SyncContext::new(new_context(tcx))),
298299
should_combine_object_files: false,
299300
temp_dir: None,
300301
};
@@ -325,15 +326,34 @@ impl ExtraBackendMethods for GccCodegenBackend {
325326
}
326327

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

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

338358
impl WriteBackendMethods for GccCodegenBackend {
339359
type Module = GccContext;

0 commit comments

Comments
 (0)