1
Fork 0

incr: cache dwarf objects in work products

Cache DWARF objects alongside object files in work products when those
exist so that DWARF object files are available for thorin in packed mode
in incremental scenarios.

Signed-off-by: David Wood <david.wood@huawei.com>
This commit is contained in:
David Wood 2022-07-04 14:38:42 +01:00
parent 5b8cf49c51
commit 8371a036ea
7 changed files with 128 additions and 66 deletions

View file

@ -161,19 +161,13 @@ pub fn load_dep_graph(sess: &Session) -> DepGraphFuture {
Decodable::decode(&mut work_product_decoder);
for swp in work_products {
let mut all_files_exist = true;
let path = in_incr_comp_dir_sess(sess, &swp.work_product.saved_file);
if !path.exists() {
all_files_exist = false;
if sess.opts.debugging_opts.incremental_info {
eprintln!(
"incremental: could not find file for work \
product: {}",
path.display()
);
let all_files_exist = swp.work_product.saved_files.iter().all(|(_, path)| {
let exists = in_incr_comp_dir_sess(sess, path).exists();
if !exists && sess.opts.debugging_opts.incremental_info {
eprintln!("incremental: could not find file for work product: {path}",);
}
}
exists
});
if all_files_exist {
debug!("reconcile_work_products: all files for {:?} exist", swp);

View file

@ -108,16 +108,17 @@ pub fn save_work_product_index(
for (id, wp) in previous_work_products.iter() {
if !new_work_products.contains_key(id) {
work_product::delete_workproduct_files(sess, wp);
debug_assert!(!in_incr_comp_dir_sess(sess, &wp.saved_file).exists());
debug_assert!(
!wp.saved_files.iter().all(|(_, path)| in_incr_comp_dir_sess(sess, path).exists())
);
}
}
// Check that we did not delete one of the current work-products:
debug_assert!({
new_work_products
.iter()
.map(|(_, wp)| in_incr_comp_dir_sess(sess, &wp.saved_file))
.all(|path| path.exists())
new_work_products.iter().all(|(_, wp)| {
wp.saved_files.iter().all(|(_, path)| in_incr_comp_dir_sess(sess, path).exists())
})
});
}

View file

@ -3,6 +3,7 @@
//! [work products]: WorkProduct
use crate::persist::fs::*;
use rustc_data_structures::stable_map::FxHashMap;
use rustc_fs_util::link_or_copy;
use rustc_middle::dep_graph::{WorkProduct, WorkProductId};
use rustc_session::Session;
@ -13,38 +14,41 @@ use std::path::Path;
pub fn copy_cgu_workproduct_to_incr_comp_cache_dir(
sess: &Session,
cgu_name: &str,
path: &Path,
files: &[(&'static str, &Path)],
) -> Option<(WorkProductId, WorkProduct)> {
debug!("copy_cgu_workproduct_to_incr_comp_cache_dir({:?},{:?})", cgu_name, path);
debug!(?cgu_name, ?files);
sess.opts.incremental.as_ref()?;
let file_name = format!("{}.o", cgu_name);
let path_in_incr_dir = in_incr_comp_dir_sess(sess, &file_name);
let saved_file = match link_or_copy(path, &path_in_incr_dir) {
Ok(_) => 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;
let mut saved_files = FxHashMap::default();
for (ext, path) in files {
let file_name = format!("{cgu_name}.{ext}");
let path_in_incr_dir = in_incr_comp_dir_sess(sess, &file_name);
match link_or_copy(path, &path_in_incr_dir) {
Ok(_) => {
let _ = saved_files.insert(ext.to_string(), file_name);
}
Err(err) => {
sess.warn(&format!(
"error copying object file `{}` to incremental directory as `{}`: {}",
path.display(),
path_in_incr_dir.display(),
err
));
}
}
};
let work_product = WorkProduct { cgu_name: cgu_name.to_string(), saved_file };
}
let work_product = WorkProduct { cgu_name: cgu_name.to_string(), saved_files };
debug!(?work_product);
let work_product_id = WorkProductId::from_cgu_name(cgu_name);
Some((work_product_id, work_product))
}
/// Removes files for a given work product.
pub fn delete_workproduct_files(sess: &Session, work_product: &WorkProduct) {
let path = in_incr_comp_dir_sess(sess, &work_product.saved_file);
match std_fs::remove_file(&path) {
Ok(()) => {}
Err(err) => {
for (_, path) in &work_product.saved_files {
let path = in_incr_comp_dir_sess(sess, path);
if let Err(err) = std_fs::remove_file(&path) {
sess.warn(&format!(
"file-system error deleting outdated file `{}`: {}",
path.display(),