[eddyb] rustc_codegen_ssa: avoid a Clone bound on TargetMachine.
This commit is contained in:
parent
47c84c4234
commit
d1410ada92
4 changed files with 15 additions and 16 deletions
|
|
@ -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)
|
||||
})?;
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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(),
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue