Skip to content

Instantly share code, notes, and snippets.

@davidtwco
Last active July 4, 2022 13:26
Show Gist options
  • Save davidtwco/55273a0401c66ffdb9df246a81368ca2 to your computer and use it in GitHub Desktop.
Save davidtwco/55273a0401c66ffdb9df246a81368ca2 to your computer and use it in GitHub Desktop.
diff --git a/compiler/rustc_codegen_cranelift/src/driver/aot.rs b/compiler/rustc_codegen_cranelift/src/driver/aot.rs
index 05457ce15e9..8cdbbf4f8fe 100644
--- a/compiler/rustc_codegen_cranelift/src/driver/aot.rs
+++ b/compiler/rustc_codegen_cranelift/src/driver/aot.rs
@@ -66,7 +66,9 @@ fn emit_module(
let work_product = if backend_config.disable_incr_cache {
None
} else {
- rustc_incremental::copy_cgu_workproduct_to_incr_comp_cache_dir(tcx.sess, &name, &tmp_file)
+ rustc_incremental::copy_cgu_workproduct_to_incr_comp_cache_dir(
+ tcx.sess, &name, &tmp_file, None,
+ )
};
ModuleCodegenResult(
@@ -82,7 +84,8 @@ fn reuse_workproduct_for_cgu(
) -> CompiledModule {
let work_product = cgu.previous_work_product(tcx);
let obj_out = tcx.output_filenames(()).temp_path(OutputType::Object, Some(cgu.name().as_str()));
- let source_file = rustc_incremental::in_incr_comp_dir_sess(&tcx.sess, &work_product.saved_file);
+ let source_file =
+ rustc_incremental::in_incr_comp_dir_sess(&tcx.sess, &work_product.saved_object_file);
if let Err(err) = rustc_fs_util::link_or_copy(&source_file, &obj_out) {
tcx.sess.err(&format!(
"unable to copy {} to {}: {}",
diff --git a/compiler/rustc_codegen_ssa/src/back/write.rs b/compiler/rustc_codegen_ssa/src/back/write.rs
index 632f07c5c2d..251d3b20a19 100644
--- a/compiler/rustc_codegen_ssa/src/back/write.rs
+++ b/compiler/rustc_codegen_ssa/src/back/write.rs
@@ -494,10 +494,13 @@ fn copy_all_cgu_workproducts_to_incr_comp_cache_dir(
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) {
- if let Some(path) = &module.object {
- if let Some((id, product)) =
- copy_cgu_workproduct_to_incr_comp_cache_dir(sess, &module.name, path)
- {
+ if let Some(object_file_path) = &module.object {
+ if let Some((id, product)) = copy_cgu_workproduct_to_incr_comp_cache_dir(
+ sess,
+ &module.name,
+ object_file_path,
+ module.dwarf_object.as_deref(),
+ ) {
work_products.insert(id, product);
}
}
@@ -856,29 +859,50 @@ fn execute_copy_from_cache_work_item<B: ExtraBackendMethods>(
assert!(module_config.emit_obj != EmitObj::None);
let incr_comp_session_dir = cgcx.incr_comp_session_dir.as_ref().unwrap();
- let obj_out = cgcx.output_filenames.temp_path(OutputType::Object, Some(&module.name));
- let source_file = in_incr_comp_dir(&incr_comp_session_dir, &module.source.saved_file);
- debug!(
- "copying pre-existing module `{}` from {:?} to {}",
- module.name,
- source_file,
- obj_out.display()
+
+ let load_from_incr_comp_dir = |output_path: PathBuf, saved_path: &str| {
+ let source_file = in_incr_comp_dir(&incr_comp_session_dir, saved_path);
+ debug!(
+ "copying pre-existing module `{}` from {:?} to {}",
+ module.name,
+ source_file,
+ output_path.display()
+ );
+ match link_or_copy(&source_file, &output_path) {
+ Ok(_) => Some(output_path),
+ Err(err) => {
+ let diag_handler = cgcx.create_diag_handler();
+ diag_handler.err(&format!(
+ "unable to copy {} to {}: {}",
+ source_file.display(),
+ output_path.display(),
+ err
+ ));
+ None
+ }
+ }
+ };
+
+ let object = load_from_incr_comp_dir(
+ cgcx.output_filenames.temp_path(OutputType::Object, Some(&module.name)),
+ &module.source.saved_object_file,
);
- if let Err(err) = link_or_copy(&source_file, &obj_out) {
- let diag_handler = cgcx.create_diag_handler();
- diag_handler.err(&format!(
- "unable to copy {} to {}: {}",
- source_file.display(),
- obj_out.display(),
- err
- ));
- }
+ let dwarf_object =
+ module.source.saved_dwarf_object_file.as_ref().and_then(|saved_dwarf_object_file| {
+ let dwarf_obj_out = cgcx
+ .output_filenames
+ .split_dwarf_path(cgcx.split_debuginfo, cgcx.split_dwarf_kind, Some(&module.name))
+ .expect(
+ "saved dwarf object in work product but `split_dwarf_path` returned `None`",
+ );
+ load_from_incr_comp_dir(dwarf_obj_out, &saved_dwarf_object_file)
+ });
WorkItemResult::Compiled(CompiledModule {
name: module.name,
kind: ModuleKind::Regular,
- object: Some(obj_out),
- dwarf_object: None,
+ object,
+ dwarf_object,
bytecode: None,
})
}
diff --git a/compiler/rustc_incremental/src/persist/load.rs b/compiler/rustc_incremental/src/persist/load.rs
index 9c325faae80..85205051b07 100644
--- a/compiler/rustc_incremental/src/persist/load.rs
+++ b/compiler/rustc_incremental/src/persist/load.rs
@@ -162,8 +162,17 @@ pub fn load_dep_graph(sess: &Session) -> DepGraphFuture {
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() {
+ let object_file_exists =
+ in_incr_comp_dir_sess(sess, &swp.work_product.saved_object_file).exists();
+ let dwarf_object_file_exists = swp
+ .work_product
+ .saved_dwarf_object_file
+ .as_ref()
+ .map(|saved_dwarf_object_file| {
+ in_incr_comp_dir_sess(sess, saved_dwarf_object_file).exists()
+ })
+ .unwrap_or(true);
+ if !object_file_exists || !dwarf_object_file_exists {
all_files_exist = false;
if sess.opts.debugging_opts.incremental_info {
diff --git a/compiler/rustc_incremental/src/persist/save.rs b/compiler/rustc_incremental/src/persist/save.rs
index 79836d66011..f16a528d0f8 100644
--- a/compiler/rustc_incremental/src/persist/save.rs
+++ b/compiler/rustc_incremental/src/persist/save.rs
@@ -108,7 +108,13 @@ 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!(!in_incr_comp_dir_sess(sess, &wp.saved_object_file).exists());
+ debug_assert!(
+ !wp.saved_dwarf_object_file
+ .as_ref()
+ .map(|file| !in_incr_comp_dir_sess(sess, file).exists())
+ .unwrap_or(false)
+ );
}
}
@@ -116,9 +122,17 @@ pub fn save_work_product_index(
debug_assert!({
new_work_products
.iter()
- .map(|(_, wp)| in_incr_comp_dir_sess(sess, &wp.saved_file))
+ .map(|(_, wp)| in_incr_comp_dir_sess(sess, &wp.saved_object_file))
.all(|path| path.exists())
});
+ debug_assert!({
+ new_work_products
+ .iter()
+ .map(|(_, wp)| {
+ wp.saved_dwarf_object_file.as_ref().map(|path| in_incr_comp_dir_sess(sess, path))
+ })
+ .all(|path| path.map(|path| path.exists()).unwrap_or(true))
+ });
}
fn encode_work_product_index(
diff --git a/compiler/rustc_incremental/src/persist/work_product.rs b/compiler/rustc_incremental/src/persist/work_product.rs
index 4789c0f581f..642a1a6843d 100644
--- a/compiler/rustc_incremental/src/persist/work_product.rs
+++ b/compiler/rustc_incremental/src/persist/work_product.rs
@@ -13,27 +13,35 @@
pub fn copy_cgu_workproduct_to_incr_comp_cache_dir(
sess: &Session,
cgu_name: &str,
- path: &Path,
+ object_file_path: &Path,
+ dwarf_object_file_path: Option<&Path>,
) -> Option<(WorkProductId, WorkProduct)> {
- debug!("copy_cgu_workproduct_to_incr_comp_cache_dir({:?},{:?})", cgu_name, path);
+ debug!(?cgu_name, ?object_file_path, ?dwarf_object_file_path);
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 save_in_incr_comp_dir = |path: &Path, ext: &'static str| {
+ 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(_) => 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;
+ }
}
};
- let work_product = WorkProduct { cgu_name: cgu_name.to_string(), saved_file };
+ let saved_object_file = save_in_incr_comp_dir(object_file_path, "o")?;
+ let saved_dwarf_object_file =
+ dwarf_object_file_path.and_then(|path| save_in_incr_comp_dir(path, "dwo"));
+
+ let work_product =
+ WorkProduct { cgu_name: cgu_name.to_string(), saved_object_file, saved_dwarf_object_file };
let work_product_id = WorkProductId::from_cgu_name(cgu_name);
Some((work_product_id, work_product))
@@ -41,15 +49,22 @@ pub fn copy_cgu_workproduct_to_incr_comp_cache_dir(
/// 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) => {
- sess.warn(&format!(
- "file-system error deleting outdated file `{}`: {}",
- path.display(),
- err
- ));
+ let delete_workproduct_file = |path: &str| {
+ let path = in_incr_comp_dir_sess(sess, path);
+ match std_fs::remove_file(&path) {
+ Ok(()) => {}
+ Err(err) => {
+ sess.warn(&format!(
+ "file-system error deleting outdated file `{}`: {}",
+ path.display(),
+ err
+ ));
+ }
}
+ };
+
+ delete_workproduct_file(&work_product.saved_object_file);
+ if let Some(saved_dwarf_object_file) = &work_product.saved_dwarf_object_file {
+ delete_workproduct_file(saved_dwarf_object_file);
}
}
diff --git a/compiler/rustc_query_system/src/dep_graph/graph.rs b/compiler/rustc_query_system/src/dep_graph/graph.rs
index 341cf8f827b..8fcde1f9b98 100644
--- a/compiler/rustc_query_system/src/dep_graph/graph.rs
+++ b/compiler/rustc_query_system/src/dep_graph/graph.rs
@@ -886,8 +886,10 @@ pub(crate) fn next_virtual_depnode_index(&self) -> DepNodeIndex {
#[derive(Clone, Debug, Encodable, Decodable)]
pub struct WorkProduct {
pub cgu_name: String,
- /// Saved file associated with this CGU.
- pub saved_file: String,
+ /// Saved `.o` file associated with this CGU.
+ pub saved_object_file: String,
+ /// Saved `.dwo` file associated with this CGU.
+ pub saved_dwarf_object_file: Option<String>,
}
// Index type for `DepNodeData`'s edges.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment