Skip to content

Commit 96caa25

Browse files
authored
Rollup merge of #72126 - nnethercote:change-WorkProduct-saved_files, r=alexcrichton
Change `WorkProduct::saved_files` to an `Option`. Because there is at most one file. r? @bjorn3
2 parents 2e65f7b + 98d6254 commit 96caa25

File tree

7 files changed

+36
-42
lines changed

7 files changed

+36
-42
lines changed

src/librustc_codegen_ssa/back/write.rs

+5-9
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use rustc_errors::{DiagnosticId, FatalError, Handler, Level};
2121
use rustc_fs_util::link_or_copy;
2222
use rustc_hir::def_id::{CrateNum, LOCAL_CRATE};
2323
use rustc_incremental::{
24-
copy_cgu_workproducts_to_incr_comp_cache_dir, in_incr_comp_dir, in_incr_comp_dir_sess,
24+
copy_cgu_workproduct_to_incr_comp_cache_dir, in_incr_comp_dir, in_incr_comp_dir_sess,
2525
};
2626
use rustc_middle::dep_graph::{WorkProduct, WorkProductId};
2727
use rustc_middle::middle::cstore::EncodedMetadata;
@@ -465,17 +465,13 @@ fn copy_all_cgu_workproducts_to_incr_comp_cache_dir(
465465
return work_products;
466466
}
467467

468-
let _timer = sess.timer("incr_comp_copy_cgu_workproducts");
468+
let _timer = sess.timer("copy_all_cgu_workproducts_to_incr_comp_cache_dir");
469469

470470
for module in compiled_modules.modules.iter().filter(|m| m.kind == ModuleKind::Regular) {
471-
let mut files = vec![];
472-
473-
if let Some(ref path) = module.object {
474-
files.push(path.clone());
475-
}
471+
let path = module.object.as_ref().map(|path| path.clone());
476472

477473
if let Some((id, product)) =
478-
copy_cgu_workproducts_to_incr_comp_cache_dir(sess, &module.name, &files)
474+
copy_cgu_workproduct_to_incr_comp_cache_dir(sess, &module.name, &path)
479475
{
480476
work_products.insert(id, product);
481477
}
@@ -817,7 +813,7 @@ fn execute_copy_from_cache_work_item<B: ExtraBackendMethods>(
817813
) -> Result<WorkItemResult<B>, FatalError> {
818814
let incr_comp_session_dir = cgcx.incr_comp_session_dir.as_ref().unwrap();
819815
let mut object = None;
820-
for saved_file in &module.source.saved_files {
816+
if let Some(saved_file) = module.source.saved_file {
821817
let obj_out = cgcx.output_filenames.temp_path(OutputType::Object, Some(&module.name));
822818
object = Some(obj_out.clone());
823819
let source_file = in_incr_comp_dir(&incr_comp_session_dir, &saved_file);

src/librustc_incremental/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub mod assert_module_sources;
1515
mod persist;
1616

1717
pub use assert_dep_graph::assert_dep_graph;
18-
pub use persist::copy_cgu_workproducts_to_incr_comp_cache_dir;
18+
pub use persist::copy_cgu_workproduct_to_incr_comp_cache_dir;
1919
pub use persist::delete_workproduct_files;
2020
pub use persist::dep_graph_tcx_init;
2121
pub use persist::finalize_session_directory;

src/librustc_incremental/persist/load.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ pub fn load_dep_graph(sess: &Session) -> DepGraphFuture {
134134

135135
for swp in work_products {
136136
let mut all_files_exist = true;
137-
for file_name in swp.work_product.saved_files.iter() {
137+
if let Some(ref file_name) = swp.work_product.saved_file {
138138
let path = in_incr_comp_dir_sess(sess, file_name);
139139
if !path.exists() {
140140
all_files_exist = false;

src/librustc_incremental/persist/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ pub use load::LoadResult;
2121
pub use load::{load_dep_graph, DepGraphFuture};
2222
pub use save::save_dep_graph;
2323
pub use save::save_work_product_index;
24-
pub use work_product::copy_cgu_workproducts_to_incr_comp_cache_dir;
24+
pub use work_product::copy_cgu_workproduct_to_incr_comp_cache_dir;
2525
pub use work_product::delete_workproduct_files;

src/librustc_incremental/persist/save.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ pub fn save_work_product_index(
7474
if !new_work_products.contains_key(id) {
7575
work_product::delete_workproduct_files(sess, wp);
7676
debug_assert!(
77-
wp.saved_files
78-
.iter()
79-
.all(|file_name| { !in_incr_comp_dir_sess(sess, file_name).exists() })
77+
wp.saved_file.as_ref().map_or(true, |file_name| {
78+
!in_incr_comp_dir_sess(sess, &file_name).exists()
79+
})
8080
);
8181
}
8282
}
@@ -85,7 +85,7 @@ pub fn save_work_product_index(
8585
debug_assert!({
8686
new_work_products
8787
.iter()
88-
.flat_map(|(_, wp)| wp.saved_files.iter())
88+
.flat_map(|(_, wp)| wp.saved_file.iter())
8989
.map(|name| in_incr_comp_dir_sess(sess, name))
9090
.all(|path| path.exists())
9191
});

src/librustc_incremental/persist/work_product.rs

+22-24
Original file line numberDiff line numberDiff line change
@@ -7,43 +7,41 @@ use rustc_session::Session;
77
use std::fs as std_fs;
88
use std::path::PathBuf;
99

10-
pub fn copy_cgu_workproducts_to_incr_comp_cache_dir(
10+
pub fn copy_cgu_workproduct_to_incr_comp_cache_dir(
1111
sess: &Session,
1212
cgu_name: &str,
13-
files: &[PathBuf],
13+
path: &Option<PathBuf>,
1414
) -> Option<(WorkProductId, WorkProduct)> {
15-
debug!("copy_cgu_workproducts_to_incr_comp_cache_dir({:?},{:?})", cgu_name, files);
15+
debug!("copy_cgu_workproduct_to_incr_comp_cache_dir({:?},{:?})", cgu_name, path);
1616
sess.opts.incremental.as_ref()?;
1717

18-
let saved_files = files
19-
.iter()
20-
.map(|path| {
21-
let file_name = format!("{}.o", cgu_name);
22-
let path_in_incr_dir = in_incr_comp_dir_sess(sess, &file_name);
23-
match link_or_copy(path, &path_in_incr_dir) {
24-
Ok(_) => Some(file_name),
25-
Err(err) => {
26-
sess.warn(&format!(
27-
"error copying object file `{}` \
28-
to incremental directory as `{}`: {}",
29-
path.display(),
30-
path_in_incr_dir.display(),
31-
err
32-
));
33-
None
34-
}
18+
let saved_file = if let Some(path) = path {
19+
let file_name = format!("{}.o", cgu_name);
20+
let path_in_incr_dir = in_incr_comp_dir_sess(sess, &file_name);
21+
match link_or_copy(path, &path_in_incr_dir) {
22+
Ok(_) => Some(file_name),
23+
Err(err) => {
24+
sess.warn(&format!(
25+
"error copying object file `{}` to incremental directory as `{}`: {}",
26+
path.display(),
27+
path_in_incr_dir.display(),
28+
err
29+
));
30+
return None;
3531
}
36-
})
37-
.collect::<Option<Vec<_>>>()?;
32+
}
33+
} else {
34+
None
35+
};
3836

39-
let work_product = WorkProduct { cgu_name: cgu_name.to_string(), saved_files };
37+
let work_product = WorkProduct { cgu_name: cgu_name.to_string(), saved_file };
4038

4139
let work_product_id = WorkProductId::from_cgu_name(cgu_name);
4240
Some((work_product_id, work_product))
4341
}
4442

4543
pub fn delete_workproduct_files(sess: &Session, work_product: &WorkProduct) {
46-
for file_name in &work_product.saved_files {
44+
if let Some(ref file_name) = work_product.saved_file {
4745
let path = in_incr_comp_dir_sess(sess, file_name);
4846
match std_fs::remove_file(&path) {
4947
Ok(()) => {}

src/librustc_query_system/dep_graph/graph.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -860,8 +860,8 @@ impl<K: DepKind> DepGraph<K> {
860860
#[derive(Clone, Debug, RustcEncodable, RustcDecodable)]
861861
pub struct WorkProduct {
862862
pub cgu_name: String,
863-
/// Saved files associated with this CGU.
864-
pub saved_files: Vec<String>,
863+
/// Saved file associated with this CGU.
864+
pub saved_file: Option<String>,
865865
}
866866

867867
#[derive(Clone)]

0 commit comments

Comments
 (0)