about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2017-01-19 15:49:50 -0800
committerAlex Crichton <alex@alexcrichton.com>2017-01-20 08:35:49 -0800
commitc2f1b0296bc4f1d4e8ff8d695ba4a3b567dd1c49 (patch)
treea9acea476748981a68d148e4c196a815ba6aaa36
parent465a0d12b9777dde1e10e758924ce1d4837a4517 (diff)
parentb9765c085faf0b350ce9056856a0a7e188cc4ea9 (diff)
downloadrust-c2f1b0296bc4f1d4e8ff8d695ba4a3b567dd1c49.tar.gz
rust-c2f1b0296bc4f1d4e8ff8d695ba4a3b567dd1c49.zip
Rollup merge of #39184 - michaelwoerister:no-trans-items-for-meta-crates, r=eddyb
trans: Exit earlier from base::trans_crate() when compiling rmeta crates.

Fixes https://github.com/rust-lang/rust/issues/38964.
r? @eddyb
cc @nrc
-rw-r--r--src/librustc_trans/back/write.rs5
-rw-r--r--src/librustc_trans/base.rs33
2 files changed, 20 insertions, 18 deletions
diff --git a/src/librustc_trans/back/write.rs b/src/librustc_trans/back/write.rs
index 96045c6c079..9e5391ebd82 100644
--- a/src/librustc_trans/back/write.rs
+++ b/src/librustc_trans/back/write.rs
@@ -667,7 +667,8 @@ pub fn run_passes(sess: &Session,
 
     // Sanity check
     assert!(trans.modules.len() == sess.opts.cg.codegen_units ||
-            sess.opts.debugging_opts.incremental.is_some());
+            sess.opts.debugging_opts.incremental.is_some() ||
+            !sess.opts.output_types.should_trans());
 
     let tm = create_target_machine(sess);
 
@@ -756,7 +757,7 @@ pub fn run_passes(sess: &Session,
     //       the compiler decides the number of codegen units (and will
     //       potentially create hundreds of them).
     let num_workers = work_items.len() - 1;
-    if num_workers == 1 {
+    if num_workers <= 1 {
         run_work_singlethreaded(sess, &trans.exported_symbols, work_items);
     } else {
         run_work_multithreaded(sess, work_items, num_workers);
diff --git a/src/librustc_trans/base.rs b/src/librustc_trans/base.rs
index 4cdde24ed48..d006dccbccc 100644
--- a/src/librustc_trans/base.rs
+++ b/src/librustc_trans/base.rs
@@ -1145,6 +1145,23 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
     };
     let no_builtins = attr::contains_name(&krate.attrs, "no_builtins");
 
+    // Skip crate items and just output metadata in -Z no-trans mode.
+    if tcx.sess.opts.debugging_opts.no_trans ||
+       !tcx.sess.opts.output_types.should_trans() {
+        let empty_exported_symbols = ExportedSymbols::empty();
+        let linker_info = LinkerInfo::new(&shared_ccx, &empty_exported_symbols);
+        return CrateTranslation {
+            modules: vec![],
+            metadata_module: metadata_module,
+            link: link_meta,
+            metadata: metadata,
+            exported_symbols: empty_exported_symbols,
+            no_builtins: no_builtins,
+            linker_info: linker_info,
+            windows_subsystem: None,
+        };
+    }
+
     // Run the translation item collector and partition the collected items into
     // codegen units.
     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>,
 
     assert_module_sources::assert_module_sources(tcx, &modules);
 
-    // Skip crate items and just output metadata in -Z no-trans mode.
-    if tcx.sess.opts.debugging_opts.no_trans ||
-       tcx.sess.opts.output_types.contains_key(&config::OutputType::Metadata) {
-        let linker_info = LinkerInfo::new(&shared_ccx, &ExportedSymbols::empty());
-        return CrateTranslation {
-            modules: modules,
-            metadata_module: metadata_module,
-            link: link_meta,
-            metadata: metadata,
-            exported_symbols: ExportedSymbols::empty(),
-            no_builtins: no_builtins,
-            linker_info: linker_info,
-            windows_subsystem: None,
-        };
-    }
-
     // Instantiate translation items without filling out definitions yet...
     for ccx in crate_context_list.iter_need_trans() {
         let cgu = ccx.codegen_unit();