about summary refs log tree commit diff
path: root/src/librustc_interface
diff options
context:
space:
mode:
authorNicholas Nethercote <nnethercote@mozilla.com>2019-04-26 17:22:36 +1000
committerNicholas Nethercote <nnethercote@mozilla.com>2019-04-30 14:55:10 +1000
commitfaf5eac854f9099b54854145f2307cae3f3aa768 (patch)
tree9d90efdc4c648c5efe111da6fb2f7926f608f170 /src/librustc_interface
parent03122e1bac482b150844ef9664b1ad2438b43072 (diff)
Move metadata encoding earlier.
This commit separates metadata encoding (`tcx.encode_metadata`) from the
creation of the metadata module (which is now handled by
`write_compressed_metadata`, formerly `write_metadata`).

The metadata encoding now occurs slightly earlier in the pipeline, at
the very start of code generation within `start_codegen`.

Metadata *writing* still occurs near the end of compilation; that will
be moved forward in subsequent commits.
Diffstat (limited to 'src/librustc_interface')
-rw-r--r--src/librustc_interface/passes.rs44
1 files changed, 41 insertions, 3 deletions
diff --git a/src/librustc_interface/passes.rs b/src/librustc_interface/passes.rs
index f8b1271b8b5..38d641d2f60 100644
--- a/src/librustc_interface/passes.rs
+++ b/src/librustc_interface/passes.rs
@@ -16,7 +16,7 @@ use rustc::traits;
 use rustc::util::common::{time, ErrorReported};
 use rustc::util::profiling::ProfileCategory;
 use rustc::session::{CompileResult, CrateDisambiguator, Session};
-use rustc::session::config::{self, Input, OutputFilenames, OutputType};
+use rustc::session::config::{self, CrateType, Input, OutputFilenames, OutputType};
 use rustc::session::search_paths::PathKind;
 use rustc_allocator as allocator;
 use rustc_borrowck as borrowck;
@@ -999,6 +999,38 @@ fn analysis<'tcx>(
     Ok(())
 }
 
+fn encode_metadata<'tcx>(tcx: TyCtxt<'_, 'tcx, 'tcx>) -> (middle::cstore::EncodedMetadata, bool) {
+    #[derive(PartialEq, Eq, PartialOrd, Ord)]
+    enum MetadataKind {
+        None,
+        Uncompressed,
+        Compressed
+    }
+
+    let metadata_kind = tcx.sess.crate_types.borrow().iter().map(|ty| {
+        match *ty {
+            CrateType::Executable |
+            CrateType::Staticlib |
+            CrateType::Cdylib => MetadataKind::None,
+
+            CrateType::Rlib => MetadataKind::Uncompressed,
+
+            CrateType::Dylib |
+            CrateType::ProcMacro => MetadataKind::Compressed,
+        }
+    }).max().unwrap_or(MetadataKind::None);
+
+    let need_metadata_module = metadata_kind == MetadataKind::Compressed;
+
+    let metadata = match metadata_kind {
+        MetadataKind::None => middle::cstore::EncodedMetadata::new(),
+        MetadataKind::Uncompressed |
+        MetadataKind::Compressed => tcx.encode_metadata(),
+    };
+
+    (metadata, need_metadata_module)
+}
+
 /// Runs the codegen backend, after which the AST and analysis can
 /// be discarded.
 pub fn start_codegen<'tcx>(
@@ -1013,11 +1045,17 @@ pub fn start_codegen<'tcx>(
     }
 
     time(tcx.sess, "resolving dependency formats", || {
-        ::rustc::middle::dependency_format::calculate(tcx)
+        middle::dependency_format::calculate(tcx)
+    });
+
+    let (metadata, need_metadata_module) = time(tcx.sess, "metadata encoding", || {
+        encode_metadata(tcx)
     });
 
     tcx.sess.profiler(|p| p.start_activity("codegen crate"));
-    let codegen = time(tcx.sess, "codegen", move || codegen_backend.codegen_crate(tcx, rx));
+    let codegen = time(tcx.sess, "codegen", move || {
+        codegen_backend.codegen_crate(tcx, metadata, need_metadata_module, rx)
+    });
     tcx.sess.profiler(|p| p.end_activity("codegen crate"));
 
     if log_enabled!(::log::Level::Info) {