Skip to content

Commit b9765c0

Browse files
trans: Exit earlier from base::trans_crate() when compiling rmeta crates.
1 parent 74c42ac commit b9765c0

File tree

2 files changed

+20
-18
lines changed

2 files changed

+20
-18
lines changed

src/librustc_trans/back/write.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,8 @@ pub fn run_passes(sess: &Session,
667667

668668
// Sanity check
669669
assert!(trans.modules.len() == sess.opts.cg.codegen_units ||
670-
sess.opts.debugging_opts.incremental.is_some());
670+
sess.opts.debugging_opts.incremental.is_some() ||
671+
!sess.opts.output_types.should_trans());
671672

672673
let tm = create_target_machine(sess);
673674

@@ -756,7 +757,7 @@ pub fn run_passes(sess: &Session,
756757
// the compiler decides the number of codegen units (and will
757758
// potentially create hundreds of them).
758759
let num_workers = work_items.len() - 1;
759-
if num_workers == 1 {
760+
if num_workers <= 1 {
760761
run_work_singlethreaded(sess, &trans.exported_symbols, work_items);
761762
} else {
762763
run_work_multithreaded(sess, work_items, num_workers);

src/librustc_trans/base.rs

+17-16
Original file line numberDiff line numberDiff line change
@@ -1145,6 +1145,23 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
11451145
};
11461146
let no_builtins = attr::contains_name(&krate.attrs, "no_builtins");
11471147

1148+
// Skip crate items and just output metadata in -Z no-trans mode.
1149+
if tcx.sess.opts.debugging_opts.no_trans ||
1150+
!tcx.sess.opts.output_types.should_trans() {
1151+
let empty_exported_symbols = ExportedSymbols::empty();
1152+
let linker_info = LinkerInfo::new(&shared_ccx, &empty_exported_symbols);
1153+
return CrateTranslation {
1154+
modules: vec![],
1155+
metadata_module: metadata_module,
1156+
link: link_meta,
1157+
metadata: metadata,
1158+
exported_symbols: empty_exported_symbols,
1159+
no_builtins: no_builtins,
1160+
linker_info: linker_info,
1161+
windows_subsystem: None,
1162+
};
1163+
}
1164+
11481165
// Run the translation item collector and partition the collected items into
11491166
// codegen units.
11501167
let (codegen_units, symbol_map) = collect_and_partition_translation_items(&shared_ccx);
@@ -1181,22 +1198,6 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
11811198

11821199
assert_module_sources::assert_module_sources(tcx, &modules);
11831200

1184-
// Skip crate items and just output metadata in -Z no-trans mode.
1185-
if tcx.sess.opts.debugging_opts.no_trans ||
1186-
tcx.sess.opts.output_types.contains_key(&config::OutputType::Metadata) {
1187-
let linker_info = LinkerInfo::new(&shared_ccx, &ExportedSymbols::empty());
1188-
return CrateTranslation {
1189-
modules: modules,
1190-
metadata_module: metadata_module,
1191-
link: link_meta,
1192-
metadata: metadata,
1193-
exported_symbols: ExportedSymbols::empty(),
1194-
no_builtins: no_builtins,
1195-
linker_info: linker_info,
1196-
windows_subsystem: None,
1197-
};
1198-
}
1199-
12001201
// Instantiate translation items without filling out definitions yet...
12011202
for ccx in crate_context_list.iter_need_trans() {
12021203
let cgu = ccx.codegen_unit();

0 commit comments

Comments
 (0)