about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNicholas Nethercote <nnethercote@mozilla.com>2020-05-12 15:56:02 +1000
committerNicholas Nethercote <nnethercote@mozilla.com>2020-05-12 17:55:07 +1000
commit98d625441501aa23284a1897c4a6511a46a86ce5 (patch)
tree0165f8ff5e09430995d68b77907031bfc2e00128
parent99cb9ccb9ca2067ad6e60508e3d52da77396b2f1 (diff)
downloadrust-98d625441501aa23284a1897c4a6511a46a86ce5.tar.gz
rust-98d625441501aa23284a1897c4a6511a46a86ce5.zip
Change `WorkProduct::saved_files` to an `Option`.
Because there is at most one file.
-rw-r--r--src/librustc_codegen_ssa/back/write.rs14
-rw-r--r--src/librustc_incremental/lib.rs2
-rw-r--r--src/librustc_incremental/persist/load.rs2
-rw-r--r--src/librustc_incremental/persist/mod.rs2
-rw-r--r--src/librustc_incremental/persist/save.rs8
-rw-r--r--src/librustc_incremental/persist/work_product.rs46
-rw-r--r--src/librustc_query_system/dep_graph/graph.rs4
7 files changed, 36 insertions, 42 deletions
diff --git a/src/librustc_codegen_ssa/back/write.rs b/src/librustc_codegen_ssa/back/write.rs
index 6210559251d..46e17d66d61 100644
--- a/src/librustc_codegen_ssa/back/write.rs
+++ b/src/librustc_codegen_ssa/back/write.rs
@@ -21,7 +21,7 @@ use rustc_errors::{DiagnosticId, FatalError, Handler, Level};
 use rustc_fs_util::link_or_copy;
 use rustc_hir::def_id::{CrateNum, LOCAL_CRATE};
 use rustc_incremental::{
-    copy_cgu_workproducts_to_incr_comp_cache_dir, in_incr_comp_dir, in_incr_comp_dir_sess,
+    copy_cgu_workproduct_to_incr_comp_cache_dir, in_incr_comp_dir, in_incr_comp_dir_sess,
 };
 use rustc_middle::dep_graph::{WorkProduct, WorkProductId};
 use rustc_middle::middle::cstore::EncodedMetadata;
@@ -465,17 +465,13 @@ fn copy_all_cgu_workproducts_to_incr_comp_cache_dir(
         return work_products;
     }
 
-    let _timer = sess.timer("incr_comp_copy_cgu_workproducts");
+    let _timer = sess.timer("copy_all_cgu_workproducts_to_incr_comp_cache_dir");
 
     for module in compiled_modules.modules.iter().filter(|m| m.kind == ModuleKind::Regular) {
-        let mut files = vec![];
-
-        if let Some(ref path) = module.object {
-            files.push(path.clone());
-        }
+        let path = module.object.as_ref().map(|path| path.clone());
 
         if let Some((id, product)) =
-            copy_cgu_workproducts_to_incr_comp_cache_dir(sess, &module.name, &files)
+            copy_cgu_workproduct_to_incr_comp_cache_dir(sess, &module.name, &path)
         {
             work_products.insert(id, product);
         }
@@ -817,7 +813,7 @@ fn execute_copy_from_cache_work_item<B: ExtraBackendMethods>(
 ) -> Result<WorkItemResult<B>, FatalError> {
     let incr_comp_session_dir = cgcx.incr_comp_session_dir.as_ref().unwrap();
     let mut object = None;
-    for saved_file in &module.source.saved_files {
+    if let Some(saved_file) = module.source.saved_file {
         let obj_out = cgcx.output_filenames.temp_path(OutputType::Object, Some(&module.name));
         object = Some(obj_out.clone());
         let source_file = in_incr_comp_dir(&incr_comp_session_dir, &saved_file);
diff --git a/src/librustc_incremental/lib.rs b/src/librustc_incremental/lib.rs
index dd715c6c81d..7fd4b3c2554 100644
--- a/src/librustc_incremental/lib.rs
+++ b/src/librustc_incremental/lib.rs
@@ -15,7 +15,7 @@ pub mod assert_module_sources;
 mod persist;
 
 pub use assert_dep_graph::assert_dep_graph;
-pub use persist::copy_cgu_workproducts_to_incr_comp_cache_dir;
+pub use persist::copy_cgu_workproduct_to_incr_comp_cache_dir;
 pub use persist::delete_workproduct_files;
 pub use persist::dep_graph_tcx_init;
 pub use persist::finalize_session_directory;
diff --git a/src/librustc_incremental/persist/load.rs b/src/librustc_incremental/persist/load.rs
index 99c799950c0..966faa9639d 100644
--- a/src/librustc_incremental/persist/load.rs
+++ b/src/librustc_incremental/persist/load.rs
@@ -134,7 +134,7 @@ pub fn load_dep_graph(sess: &Session) -> DepGraphFuture {
 
             for swp in work_products {
                 let mut all_files_exist = true;
-                for file_name in swp.work_product.saved_files.iter() {
+                if let Some(ref file_name) = swp.work_product.saved_file {
                     let path = in_incr_comp_dir_sess(sess, file_name);
                     if !path.exists() {
                         all_files_exist = false;
diff --git a/src/librustc_incremental/persist/mod.rs b/src/librustc_incremental/persist/mod.rs
index 6a03a01430b..7bc3b47e15a 100644
--- a/src/librustc_incremental/persist/mod.rs
+++ b/src/librustc_incremental/persist/mod.rs
@@ -21,5 +21,5 @@ pub use load::LoadResult;
 pub use load::{load_dep_graph, DepGraphFuture};
 pub use save::save_dep_graph;
 pub use save::save_work_product_index;
-pub use work_product::copy_cgu_workproducts_to_incr_comp_cache_dir;
+pub use work_product::copy_cgu_workproduct_to_incr_comp_cache_dir;
 pub use work_product::delete_workproduct_files;
diff --git a/src/librustc_incremental/persist/save.rs b/src/librustc_incremental/persist/save.rs
index 4db6297712c..c43d4ad4049 100644
--- a/src/librustc_incremental/persist/save.rs
+++ b/src/librustc_incremental/persist/save.rs
@@ -74,9 +74,9 @@ pub fn save_work_product_index(
         if !new_work_products.contains_key(id) {
             work_product::delete_workproduct_files(sess, wp);
             debug_assert!(
-                wp.saved_files
-                    .iter()
-                    .all(|file_name| { !in_incr_comp_dir_sess(sess, file_name).exists() })
+                wp.saved_file.as_ref().map_or(true, |file_name| {
+                    !in_incr_comp_dir_sess(sess, &file_name).exists()
+                })
             );
         }
     }
@@ -85,7 +85,7 @@ pub fn save_work_product_index(
     debug_assert!({
         new_work_products
             .iter()
-            .flat_map(|(_, wp)| wp.saved_files.iter())
+            .flat_map(|(_, wp)| wp.saved_file.iter())
             .map(|name| in_incr_comp_dir_sess(sess, name))
             .all(|path| path.exists())
     });
diff --git a/src/librustc_incremental/persist/work_product.rs b/src/librustc_incremental/persist/work_product.rs
index a15ee6d81db..19d64bda56d 100644
--- a/src/librustc_incremental/persist/work_product.rs
+++ b/src/librustc_incremental/persist/work_product.rs
@@ -7,43 +7,41 @@ use rustc_session::Session;
 use std::fs as std_fs;
 use std::path::PathBuf;
 
-pub fn copy_cgu_workproducts_to_incr_comp_cache_dir(
+pub fn copy_cgu_workproduct_to_incr_comp_cache_dir(
     sess: &Session,
     cgu_name: &str,
-    files: &[PathBuf],
+    path: &Option<PathBuf>,
 ) -> Option<(WorkProductId, WorkProduct)> {
-    debug!("copy_cgu_workproducts_to_incr_comp_cache_dir({:?},{:?})", cgu_name, files);
+    debug!("copy_cgu_workproduct_to_incr_comp_cache_dir({:?},{:?})", cgu_name, path);
     sess.opts.incremental.as_ref()?;
 
-    let saved_files = files
-        .iter()
-        .map(|path| {
-            let file_name = format!("{}.o", cgu_name);
-            let path_in_incr_dir = in_incr_comp_dir_sess(sess, &file_name);
-            match link_or_copy(path, &path_in_incr_dir) {
-                Ok(_) => Some(file_name),
-                Err(err) => {
-                    sess.warn(&format!(
-                        "error copying object file `{}` \
-                                             to incremental directory as `{}`: {}",
-                        path.display(),
-                        path_in_incr_dir.display(),
-                        err
-                    ));
-                    None
-                }
+    let saved_file = if let Some(path) = path {
+        let file_name = format!("{}.o", cgu_name);
+        let path_in_incr_dir = in_incr_comp_dir_sess(sess, &file_name);
+        match link_or_copy(path, &path_in_incr_dir) {
+            Ok(_) => Some(file_name),
+            Err(err) => {
+                sess.warn(&format!(
+                    "error copying object file `{}` to incremental directory as `{}`: {}",
+                    path.display(),
+                    path_in_incr_dir.display(),
+                    err
+                ));
+                return None;
             }
-        })
-        .collect::<Option<Vec<_>>>()?;
+        }
+    } else {
+        None
+    };
 
-    let work_product = WorkProduct { cgu_name: cgu_name.to_string(), saved_files };
+    let work_product = WorkProduct { cgu_name: cgu_name.to_string(), saved_file };
 
     let work_product_id = WorkProductId::from_cgu_name(cgu_name);
     Some((work_product_id, work_product))
 }
 
 pub fn delete_workproduct_files(sess: &Session, work_product: &WorkProduct) {
-    for file_name in &work_product.saved_files {
+    if let Some(ref file_name) = work_product.saved_file {
         let path = in_incr_comp_dir_sess(sess, file_name);
         match std_fs::remove_file(&path) {
             Ok(()) => {}
diff --git a/src/librustc_query_system/dep_graph/graph.rs b/src/librustc_query_system/dep_graph/graph.rs
index 5f14a09b24d..04a45090b72 100644
--- a/src/librustc_query_system/dep_graph/graph.rs
+++ b/src/librustc_query_system/dep_graph/graph.rs
@@ -860,8 +860,8 @@ impl<K: DepKind> DepGraph<K> {
 #[derive(Clone, Debug, RustcEncodable, RustcDecodable)]
 pub struct WorkProduct {
     pub cgu_name: String,
-    /// Saved files associated with this CGU.
-    pub saved_files: Vec<String>,
+    /// Saved file associated with this CGU.
+    pub saved_file: Option<String>,
 }
 
 #[derive(Clone)]