Skip to content

Commit 682bc88

Browse files
committed
Auto merge of #48219 - andjo403:export_symbol, r=<try>
lookup exported symbols only when needed. reduces the time to compile small file with no optimization by half.
2 parents 27a046e + 7041ef3 commit 682bc88

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

Diff for: src/librustc_trans/back/lto.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,9 @@ pub(crate) fn run(cgcx: &CodegenContext,
122122
None
123123
}
124124
};
125-
126-
let mut symbol_white_list = cgcx.exported_symbols[&LOCAL_CRATE]
125+
let exported_symbols = cgcx.exported_symbols
126+
.as_ref().expect("needs exported symbols for LTO");
127+
let mut symbol_white_list = exported_symbols[&LOCAL_CRATE]
127128
.iter()
128129
.filter_map(symbol_filter)
129130
.collect::<Vec<CString>>();
@@ -156,8 +157,10 @@ pub(crate) fn run(cgcx: &CodegenContext,
156157
}
157158

158159
for &(cnum, ref path) in cgcx.each_linked_rlib_for_lto.iter() {
160+
let exported_symbols = cgcx.exported_symbols
161+
.as_ref().expect("needs exported symbols for LTO");
159162
symbol_white_list.extend(
160-
cgcx.exported_symbols[&cnum]
163+
exported_symbols[&cnum]
161164
.iter()
162165
.filter_map(symbol_filter));
163166

Diff for: src/librustc_trans/back/write.rs

+18-7
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ pub struct CodegenContext {
333333
pub no_landing_pads: bool,
334334
pub save_temps: bool,
335335
pub fewer_names: bool,
336-
pub exported_symbols: Arc<ExportedSymbols>,
336+
pub exported_symbols: Option<Arc<ExportedSymbols>>,
337337
pub opts: Arc<config::Options>,
338338
pub crate_types: Vec<config::CrateType>,
339339
pub each_linked_rlib_for_lto: Vec<(CrateNum, PathBuf)>,
@@ -1394,14 +1394,25 @@ fn start_executing_work(tcx: TyCtxt,
13941394
allocator_config: Arc<ModuleConfig>)
13951395
-> thread::JoinHandle<Result<CompiledModules, ()>> {
13961396
let coordinator_send = tcx.tx_to_llvm_workers.clone();
1397-
let mut exported_symbols = FxHashMap();
1398-
exported_symbols.insert(LOCAL_CRATE, tcx.exported_symbols(LOCAL_CRATE));
1399-
for &cnum in tcx.crates().iter() {
1400-
exported_symbols.insert(cnum, tcx.exported_symbols(cnum));
1401-
}
1402-
let exported_symbols = Arc::new(exported_symbols);
14031397
let sess = tcx.sess;
14041398

1399+
let exported_symbols = match sess.lto() {
1400+
Lto::No => None,
1401+
Lto::ThinLocal => {
1402+
let mut exported_symbols = FxHashMap();
1403+
exported_symbols.insert(LOCAL_CRATE, tcx.exported_symbols(LOCAL_CRATE));
1404+
Some(Arc::new(exported_symbols))
1405+
}
1406+
Lto::Yes | Lto::Fat | Lto::Thin => {
1407+
let mut exported_symbols = FxHashMap();
1408+
exported_symbols.insert(LOCAL_CRATE, tcx.exported_symbols(LOCAL_CRATE));
1409+
for &cnum in tcx.crates().iter() {
1410+
exported_symbols.insert(cnum, tcx.exported_symbols(cnum));
1411+
}
1412+
Some(Arc::new(exported_symbols))
1413+
}
1414+
};
1415+
14051416
// First up, convert our jobserver into a helper thread so we can use normal
14061417
// mpsc channels to manage our messages and such.
14071418
// After we've requested tokens then we'll, when we can,

0 commit comments

Comments
 (0)