Skip to content

Commit d2f88d4

Browse files
committed
Auto merge of rust-lang#155599 - JonathanBrouwer:rollup-cI1hRiI, r=JonathanBrouwer
Rollup of 4 pull requests Successful merges: - rust-lang#152611 (Modify error message of importing inherent associated items when `#[feature(import_trait_associated_functions)]` is enabled) - rust-lang#155359 (Improperctypes refactor2.2) - rust-lang#155036 (Store a PathBuf rather than SerializedModule for cached modules) - rust-lang#155554 (add warning message when using x fix)
2 parents 3655153 + e150483 commit d2f88d4

12 files changed

Lines changed: 533 additions & 232 deletions

File tree

compiler/rustc_codegen_gcc/src/back/lto.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,12 @@ fn fat_lto(
144144
for module in modules {
145145
match module {
146146
FatLtoInput::InMemory(m) => in_memory.push(m),
147-
FatLtoInput::Serialized { name, buffer } => {
147+
FatLtoInput::Serialized { name, bitcode_path } => {
148148
info!("pushing serialized module {:?}", name);
149-
serialized_modules.push((buffer, CString::new(name).unwrap()));
149+
serialized_modules.push((
150+
SerializedModule::from_file(&bitcode_path),
151+
CString::new(name).unwrap(),
152+
));
150153
}
151154
}
152155
}

compiler/rustc_codegen_llvm/src/back/lto.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,12 @@ fn fat_lto(
223223
for module in modules {
224224
match module {
225225
FatLtoInput::InMemory(m) => in_memory.push(m),
226-
FatLtoInput::Serialized { name, buffer } => {
226+
FatLtoInput::Serialized { name, bitcode_path } => {
227227
info!("pushing serialized module {:?}", name);
228-
serialized_modules.push((buffer, CString::new(name).unwrap()));
228+
serialized_modules.push((
229+
SerializedModule::from_file(&bitcode_path),
230+
CString::new(name).unwrap(),
231+
));
229232
}
230233
}
231234
}
@@ -396,7 +399,9 @@ fn thin_lto(
396399
for (i, module) in modules.into_iter().enumerate() {
397400
let (name, buffer) = match module {
398401
ThinLtoInput::Red { name, buffer } => (name, buffer),
399-
ThinLtoInput::Green { wp, buffer } => (wp.cgu_name, buffer),
402+
ThinLtoInput::Green { wp, bitcode_path } => {
403+
(wp.cgu_name, SerializedModule::from_file(&bitcode_path))
404+
}
400405
};
401406
info!("local module: {} - {}", i, name);
402407
let cname = CString::new(name.as_bytes()).unwrap();

compiler/rustc_codegen_ssa/src/back/lto.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
use std::ffi::CString;
2+
use std::fs;
3+
use std::path::Path;
24
use std::sync::Arc;
35

46
use rustc_data_structures::memmap::Mmap;
@@ -49,6 +51,19 @@ pub enum SerializedModule<M: ModuleBufferMethods> {
4951
}
5052

5153
impl<M: ModuleBufferMethods> SerializedModule<M> {
54+
pub fn from_file(bc_path: &Path) -> Self {
55+
let file = fs::File::open(&bc_path).unwrap_or_else(|e| {
56+
panic!("failed to open LTO bitcode file `{}`: {}", bc_path.display(), e)
57+
});
58+
59+
let mmap = unsafe {
60+
Mmap::map(file).unwrap_or_else(|e| {
61+
panic!("failed to mmap LTO bitcode file `{}`: {}", bc_path.display(), e)
62+
})
63+
};
64+
SerializedModule::FromUncompressedFile(mmap)
65+
}
66+
5267
pub fn data(&self) -> &[u8] {
5368
match *self {
5469
SerializedModule::Local(ref m) => m.data(),

compiler/rustc_codegen_ssa/src/back/write.rs

Lines changed: 23 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use std::{assert_matches, fs, io, mem, str, thread};
88
use rustc_abi::Size;
99
use rustc_data_structures::fx::FxIndexMap;
1010
use rustc_data_structures::jobserver::{self, Acquired};
11-
use rustc_data_structures::memmap::Mmap;
1211
use rustc_data_structures::profiling::{SelfProfilerRef, VerboseTimingGuard};
1312
use rustc_errors::emitter::Emitter;
1413
use rustc_errors::{
@@ -35,9 +34,8 @@ use rustc_span::{FileName, InnerSpan, Span, SpanData};
3534
use rustc_target::spec::{MergeFunctions, SanitizerSet};
3635
use tracing::debug;
3736

38-
use super::link::{self, ensure_removed};
39-
use super::lto::{self, SerializedModule};
40-
use crate::back::lto::check_lto_allowed;
37+
use crate::back::link::{self, ensure_removed};
38+
use crate::back::lto::{self, SerializedModule, check_lto_allowed};
4139
use crate::errors::ErrorCreatingRemarkDir;
4240
use crate::traits::*;
4341
use crate::{
@@ -774,13 +772,13 @@ pub(crate) enum WorkItemResult<B: WriteBackendMethods> {
774772
}
775773

776774
pub enum FatLtoInput<B: WriteBackendMethods> {
777-
Serialized { name: String, buffer: SerializedModule<B::ModuleBuffer> },
775+
Serialized { name: String, bitcode_path: PathBuf },
778776
InMemory(ModuleCodegen<B::Module>),
779777
}
780778

781779
pub enum ThinLtoInput<B: WriteBackendMethods> {
782780
Red { name: String, buffer: SerializedModule<B::ModuleBuffer> },
783-
Green { wp: WorkProduct, buffer: SerializedModule<B::ModuleBuffer> },
781+
Green { wp: WorkProduct, bitcode_path: PathBuf },
784782
}
785783

786784
/// Actual LTO type we end up choosing based on multiple factors.
@@ -866,7 +864,7 @@ fn execute_optimize_work_item<B: WriteBackendMethods>(
866864
});
867865
WorkItemResult::NeedsFatLto(FatLtoInput::Serialized {
868866
name: module.name,
869-
buffer: SerializedModule::Local(buffer),
867+
bitcode_path: path,
870868
})
871869
}
872870
None => WorkItemResult::NeedsFatLto(FatLtoInput::InMemory(module)),
@@ -1166,10 +1164,7 @@ pub(crate) enum Message<B: WriteBackendMethods> {
11661164

11671165
/// Similar to `CodegenDone`, but for reusing a pre-LTO artifact
11681166
/// Sent from the main thread.
1169-
AddImportOnlyModule {
1170-
module_data: SerializedModule<B::ModuleBuffer>,
1171-
work_product: WorkProduct,
1172-
},
1167+
AddImportOnlyModule { bitcode_path: PathBuf, work_product: WorkProduct },
11731168

11741169
/// The frontend has finished generating everything for all codegen units.
11751170
/// Sent from the main thread.
@@ -1729,10 +1724,10 @@ fn start_executing_work<B: ExtraBackendMethods>(
17291724
}
17301725
}
17311726

1732-
Message::AddImportOnlyModule { module_data, work_product } => {
1727+
Message::AddImportOnlyModule { bitcode_path, work_product } => {
17331728
assert_eq!(codegen_state, Ongoing);
17341729
assert_eq!(main_thread_state, MainThreadState::Codegenning);
1735-
lto_import_only_modules.push((module_data, work_product));
1730+
lto_import_only_modules.push((bitcode_path, work_product));
17361731
main_thread_state = MainThreadState::Idle;
17371732
}
17381733
}
@@ -1758,8 +1753,8 @@ fn start_executing_work<B: ExtraBackendMethods>(
17581753
needs_fat_lto.push(FatLtoInput::InMemory(allocator_module));
17591754
}
17601755

1761-
for (module, wp) in lto_import_only_modules {
1762-
needs_fat_lto.push(FatLtoInput::Serialized { name: wp.cgu_name, buffer: module })
1756+
for (bitcode_path, wp) in lto_import_only_modules {
1757+
needs_fat_lto.push(FatLtoInput::Serialized { name: wp.cgu_name, bitcode_path })
17631758
}
17641759

17651760
return Ok(MaybeLtoModules::FatLto {
@@ -1772,8 +1767,8 @@ fn start_executing_work<B: ExtraBackendMethods>(
17721767
assert!(compiled_modules.is_empty());
17731768
assert!(needs_fat_lto.is_empty());
17741769

1775-
for (buffer, wp) in lto_import_only_modules {
1776-
needs_thin_lto.push(ThinLtoInput::Green { wp, buffer })
1770+
for (bitcode_path, wp) in lto_import_only_modules {
1771+
needs_thin_lto.push(ThinLtoInput::Green { wp, bitcode_path })
17771772
}
17781773

17791774
if cgcx.lto == Lto::ThinLocal {
@@ -2133,14 +2128,14 @@ impl<B: WriteBackendMethods> Drop for Coordinator<B> {
21332128
}
21342129

21352130
pub struct OngoingCodegen<B: WriteBackendMethods> {
2136-
pub backend: B,
2137-
pub output_filenames: Arc<OutputFilenames>,
2131+
backend: B,
2132+
output_filenames: Arc<OutputFilenames>,
21382133
// Field order below is intended to terminate the coordinator thread before two fields below
21392134
// drop and prematurely close channels used by coordinator thread. See `Coordinator`'s
21402135
// `Drop` implementation for more info.
2141-
pub coordinator: Coordinator<B>,
2142-
pub codegen_worker_receive: Receiver<CguMessage>,
2143-
pub shared_emitter_main: SharedEmitterMain,
2136+
pub(crate) coordinator: Coordinator<B>,
2137+
codegen_worker_receive: Receiver<CguMessage>,
2138+
shared_emitter_main: SharedEmitterMain,
21442139
}
21452140

21462141
impl<B: WriteBackendMethods> OngoingCodegen<B> {
@@ -2285,20 +2280,13 @@ pub(crate) fn submit_pre_lto_module_to_llvm<B: WriteBackendMethods>(
22852280
module: CachedModuleCodegen,
22862281
) {
22872282
let filename = pre_lto_bitcode_filename(&module.name);
2288-
let bc_path = in_incr_comp_dir_sess(tcx.sess, &filename);
2289-
let file = fs::File::open(&bc_path)
2290-
.unwrap_or_else(|e| panic!("failed to open bitcode file `{}`: {}", bc_path.display(), e));
2291-
2292-
let mmap = unsafe {
2293-
Mmap::map(file).unwrap_or_else(|e| {
2294-
panic!("failed to mmap bitcode file `{}`: {}", bc_path.display(), e)
2295-
})
2296-
};
2283+
let bitcode_path = in_incr_comp_dir_sess(tcx.sess, &filename);
22972284
// Schedule the module to be loaded
2298-
drop(coordinator.sender.send(Message::AddImportOnlyModule::<B> {
2299-
module_data: SerializedModule::FromUncompressedFile(mmap),
2300-
work_product: module.source,
2301-
}));
2285+
drop(
2286+
coordinator
2287+
.sender
2288+
.send(Message::AddImportOnlyModule::<B> { bitcode_path, work_product: module.source }),
2289+
);
23022290
}
23032291

23042292
fn pre_lto_bitcode_filename(module_name: &str) -> String {

0 commit comments

Comments
 (0)