Skip to content

Commit ee94ff2

Browse files
committed
Let LtoModuleCodegen::optimize take self by value
1 parent 336bb0a commit ee94ff2

File tree

6 files changed

+13
-14
lines changed

6 files changed

+13
-14
lines changed

compiler/rustc_codegen_gcc/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ impl WriteBackendMethods for GccCodegenBackend {
213213
unimplemented!();
214214
}
215215
};
216-
Ok(LtoModuleCodegen::Fat { module: Some(module), _serialized_bitcode: vec![] })
216+
Ok(LtoModuleCodegen::Fat { module, _serialized_bitcode: vec![] })
217217
}
218218

219219
fn run_thin_lto(_cgcx: &CodegenContext<Self>, _modules: Vec<(String, Self::ThinBuffer)>, _cached_modules: Vec<(SerializedModule<Self::ModuleBuffer>, WorkProduct)>) -> Result<(Vec<LtoModuleCodegen<Self>>, Vec<WorkProduct>), FatalError> {
@@ -234,7 +234,7 @@ impl WriteBackendMethods for GccCodegenBackend {
234234
Ok(())
235235
}
236236

237-
unsafe fn optimize_thin(_cgcx: &CodegenContext<Self>, _thin: &mut ThinModule<Self>) -> Result<ModuleCodegen<Self::Module>, FatalError> {
237+
unsafe fn optimize_thin(_cgcx: &CodegenContext<Self>, _thin: ThinModule<Self>) -> Result<ModuleCodegen<Self::Module>, FatalError> {
238238
unimplemented!();
239239
}
240240

compiler/rustc_codegen_llvm/src/back/lto.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ fn fat_lto(
353353
}
354354
}
355355

356-
Ok(LtoModuleCodegen::Fat { module: Some(module), _serialized_bitcode: serialized_bitcode })
356+
Ok(LtoModuleCodegen::Fat { module, _serialized_bitcode: serialized_bitcode })
357357
}
358358

359359
crate struct Linker<'a>(&'a mut llvm::Linker<'a>);
@@ -726,7 +726,7 @@ impl Drop for ThinBuffer {
726726
}
727727

728728
pub unsafe fn optimize_thin_module(
729-
thin_module: &mut ThinModule<LlvmCodegenBackend>,
729+
thin_module: ThinModule<LlvmCodegenBackend>,
730730
cgcx: &CodegenContext<LlvmCodegenBackend>,
731731
) -> Result<ModuleCodegen<ModuleLlvm>, FatalError> {
732732
let diag_handler = cgcx.create_diag_handler();

compiler/rustc_codegen_llvm/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ impl WriteBackendMethods for LlvmCodegenBackend {
220220
}
221221
unsafe fn optimize_thin(
222222
cgcx: &CodegenContext<Self>,
223-
thin: &mut ThinModule<Self>,
223+
thin: ThinModule<Self>,
224224
) -> Result<ModuleCodegen<Self::Module>, FatalError> {
225225
back::lto::optimize_thin_module(thin, cgcx)
226226
}

compiler/rustc_codegen_ssa/src/back/lto.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pub struct ThinShared<B: WriteBackendMethods> {
4242

4343
pub enum LtoModuleCodegen<B: WriteBackendMethods> {
4444
Fat {
45-
module: Option<ModuleCodegen<B::Module>>,
45+
module: ModuleCodegen<B::Module>,
4646
_serialized_bitcode: Vec<SerializedModule<B::ModuleBuffer>>,
4747
},
4848

@@ -64,19 +64,18 @@ impl<B: WriteBackendMethods> LtoModuleCodegen<B> {
6464
/// It's intended that the module returned is immediately code generated and
6565
/// dropped, and then this LTO module is dropped.
6666
pub unsafe fn optimize(
67-
&mut self,
67+
self,
6868
cgcx: &CodegenContext<B>,
6969
) -> Result<ModuleCodegen<B::Module>, FatalError> {
70-
match *self {
71-
LtoModuleCodegen::Fat { ref mut module, .. } => {
72-
let module = module.take().unwrap();
70+
match self {
71+
LtoModuleCodegen::Fat { module, .. } => {
7372
{
7473
let config = cgcx.config(module.kind);
75-
B::run_lto_pass_manager(cgcx, &module, config, false)?;
74+
B::optimize_fat(cgcx, &module, config)?;
7675
}
7776
Ok(module)
7877
}
79-
LtoModuleCodegen::Thin(ref mut thin) => B::optimize_thin(cgcx, thin),
78+
LtoModuleCodegen::Thin(thin) => B::optimize_thin(cgcx, thin),
8079
}
8180
}
8281

compiler/rustc_codegen_ssa/src/back/write.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -889,7 +889,7 @@ fn execute_copy_from_cache_work_item<B: ExtraBackendMethods>(
889889

890890
fn execute_lto_work_item<B: ExtraBackendMethods>(
891891
cgcx: &CodegenContext<B>,
892-
mut module: lto::LtoModuleCodegen<B>,
892+
module: lto::LtoModuleCodegen<B>,
893893
module_config: &ModuleConfig,
894894
) -> Result<WorkItemResult<B>, FatalError> {
895895
let module = unsafe { module.optimize(cgcx)? };

compiler/rustc_codegen_ssa/src/traits/write.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ pub trait WriteBackendMethods: 'static + Sized + Clone {
4848
) -> Result<(), FatalError>;
4949
unsafe fn optimize_thin(
5050
cgcx: &CodegenContext<Self>,
51-
thin: &mut ThinModule<Self>,
51+
thin: ThinModule<Self>,
5252
) -> Result<ModuleCodegen<Self::Module>, FatalError>;
5353
unsafe fn codegen(
5454
cgcx: &CodegenContext<Self>,

0 commit comments

Comments
 (0)