From d5cb2bee82c8bb8553406a0c98f08fa1bf51aad7 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Fri, 13 May 2022 10:32:03 +0000 Subject: [PATCH 1/4] Rename CodegenUnit::work_product to previous_work_product It returns the previous work product or panics if there is none. This rename makes the purpose of this method clearer. --- src/driver/aot.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/driver/aot.rs b/src/driver/aot.rs index 5e1e1c81d26ea..0faf1221c8399 100644 --- a/src/driver/aot.rs +++ b/src/driver/aot.rs @@ -85,7 +85,7 @@ fn reuse_workproduct_for_cgu( work_products: &mut FxHashMap, ) -> CompiledModule { let mut object = None; - let work_product = cgu.work_product(tcx); + let work_product = cgu.previous_work_product(tcx); if let Some(saved_file) = &work_product.saved_file { let obj_out = tcx.output_filenames(()).temp_path(OutputType::Object, Some(cgu.name().as_str())); From 5a1a111b52c26b4ecda7a81b1db5766c8b8f0a01 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Fri, 13 May 2022 12:18:13 +0000 Subject: [PATCH 2/4] Avoid an unnecessary clone for copy_cgu_workproduct_to_incr_comp_cache_dir calls --- src/driver/aot.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/driver/aot.rs b/src/driver/aot.rs index 0faf1221c8399..ef8fc14a5a00b 100644 --- a/src/driver/aot.rs +++ b/src/driver/aot.rs @@ -69,7 +69,7 @@ fn emit_module( rustc_incremental::copy_cgu_workproduct_to_incr_comp_cache_dir( tcx.sess, &name, - &Some(tmp_file.clone()), + Some(&tmp_file), ) }; From bbb850931fa5ccdb23eaaaead853084f49f9b2c6 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Fri, 13 May 2022 12:20:32 +0000 Subject: [PATCH 3/4] Factor Option out of copy_cgu_workproduct_to_incr_comp_cache_dir call This improves clarity of the code a bit --- src/driver/aot.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/driver/aot.rs b/src/driver/aot.rs index ef8fc14a5a00b..b652b58cb65a8 100644 --- a/src/driver/aot.rs +++ b/src/driver/aot.rs @@ -66,11 +66,7 @@ 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, - Some(&tmp_file), - ) + rustc_incremental::copy_cgu_workproduct_to_incr_comp_cache_dir(tcx.sess, &name, &tmp_file) }; ModuleCodegenResult( From 3d8e8546048cc94b9640c1f9e50ae1a0d75df9ce Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sun, 15 May 2022 11:31:28 +0000 Subject: [PATCH 4/4] Make saved_file field of WorkProduct non-optional A WorkProduct without a saved file is useless --- src/driver/aot.rs | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/src/driver/aot.rs b/src/driver/aot.rs index b652b58cb65a8..05457ce15e9a7 100644 --- a/src/driver/aot.rs +++ b/src/driver/aot.rs @@ -80,21 +80,16 @@ fn reuse_workproduct_for_cgu( cgu: &CodegenUnit<'_>, work_products: &mut FxHashMap, ) -> CompiledModule { - let mut object = None; let work_product = cgu.previous_work_product(tcx); - if let Some(saved_file) = &work_product.saved_file { - let obj_out = - tcx.output_filenames(()).temp_path(OutputType::Object, Some(cgu.name().as_str())); - object = Some(obj_out.clone()); - let source_file = rustc_incremental::in_incr_comp_dir_sess(&tcx.sess, &saved_file); - if let Err(err) = rustc_fs_util::link_or_copy(&source_file, &obj_out) { - tcx.sess.err(&format!( - "unable to copy {} to {}: {}", - source_file.display(), - obj_out.display(), - err - )); - } + 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); + if let Err(err) = rustc_fs_util::link_or_copy(&source_file, &obj_out) { + tcx.sess.err(&format!( + "unable to copy {} to {}: {}", + source_file.display(), + obj_out.display(), + err + )); } work_products.insert(cgu.work_product_id(), work_product); @@ -102,7 +97,7 @@ fn reuse_workproduct_for_cgu( CompiledModule { name: cgu.name().to_string(), kind: ModuleKind::Regular, - object, + object: Some(obj_out), dwarf_object: None, bytecode: None, }