@@ -18,7 +18,7 @@ use rustc_errors::{
1818 Diag , DiagArgMap , DiagCtxt , DiagMessage , ErrCode , FatalError , FluentBundle , Level , MultiSpan ,
1919 Style ,
2020} ;
21- use rustc_fs_util:: link_or_copy;
21+ use rustc_fs_util:: { link_or_copy, LinkOrCopy } ;
2222use rustc_hir:: def_id:: { CrateNum , LOCAL_CRATE } ;
2323use rustc_incremental:: {
2424 copy_cgu_workproduct_to_incr_comp_cache_dir, in_incr_comp_dir, in_incr_comp_dir_sess,
@@ -546,9 +546,12 @@ fn copy_all_cgu_workproducts_to_incr_comp_cache_dir(
546546 if let Some ( path) = & module. bytecode {
547547 files. push ( ( OutputType :: Bitcode . extension ( ) , path. as_path ( ) ) ) ;
548548 }
549- if let Some ( ( id, product) ) =
550- copy_cgu_workproduct_to_incr_comp_cache_dir ( sess, & module. name , files. as_slice ( ) )
551- {
549+ if let Some ( ( id, product) ) = copy_cgu_workproduct_to_incr_comp_cache_dir (
550+ sess,
551+ & module. name ,
552+ files. as_slice ( ) ,
553+ & module. links_from_incr_cache ,
554+ ) {
552555 work_products. insert ( id, product) ;
553556 }
554557 }
@@ -940,7 +943,9 @@ fn execute_copy_from_cache_work_item<B: ExtraBackendMethods>(
940943) -> WorkItemResult < B > {
941944 let incr_comp_session_dir = cgcx. incr_comp_session_dir . as_ref ( ) . unwrap ( ) ;
942945
943- let load_from_incr_comp_dir = |output_path : PathBuf , saved_path : & str | {
946+ let mut links_from_incr_cache = Vec :: new ( ) ;
947+
948+ let mut load_from_incr_comp_dir = |output_path : PathBuf , saved_path : & str | {
944949 let source_file = in_incr_comp_dir ( incr_comp_session_dir, saved_path) ;
945950 debug ! (
946951 "copying preexisting module `{}` from {:?} to {}" ,
@@ -949,7 +954,11 @@ fn execute_copy_from_cache_work_item<B: ExtraBackendMethods>(
949954 output_path. display( )
950955 ) ;
951956 match link_or_copy ( & source_file, & output_path) {
952- Ok ( _) => Some ( output_path) ,
957+ Ok ( LinkOrCopy :: Copy ) => Some ( output_path) ,
958+ Ok ( LinkOrCopy :: Link ) => {
959+ links_from_incr_cache. push ( source_file) ;
960+ Some ( output_path)
961+ }
953962 Err ( error) => {
954963 cgcx. create_dcx ( ) . handle ( ) . emit_err ( errors:: CopyPathBuf {
955964 source_file,
@@ -972,7 +981,7 @@ fn execute_copy_from_cache_work_item<B: ExtraBackendMethods>(
972981 load_from_incr_comp_dir ( dwarf_obj_out, saved_dwarf_object_file)
973982 } ) ;
974983
975- let load_from_incr_cache = |perform, output_type : OutputType | {
984+ let mut load_from_incr_cache = |perform, output_type : OutputType | {
976985 if perform {
977986 let saved_file = module. source . saved_files . get ( output_type. extension ( ) ) ?;
978987 let output_path = cgcx. output_filenames . temp_path ( output_type, Some ( & module. name ) ) ;
@@ -992,6 +1001,7 @@ fn execute_copy_from_cache_work_item<B: ExtraBackendMethods>(
9921001 }
9931002
9941003 WorkItemResult :: Finished ( CompiledModule {
1004+ links_from_incr_cache,
9951005 name : module. name ,
9961006 kind : ModuleKind :: Regular ,
9971007 object,
0 commit comments