@@ -20,6 +20,7 @@ use rustc_errors::{
2020 Style ,
2121} ;
2222use rustc_fs_util:: link_or_copy;
23+ use rustc_fs_util:: LinkOrCopy ;
2324use rustc_hir:: def_id:: { CrateNum , LOCAL_CRATE } ;
2425use rustc_incremental:: {
2526 copy_cgu_workproduct_to_incr_comp_cache_dir, in_incr_comp_dir, in_incr_comp_dir_sess,
@@ -548,9 +549,12 @@ fn copy_all_cgu_workproducts_to_incr_comp_cache_dir(
548549 if let Some ( path) = & module. bytecode {
549550 files. push ( ( OutputType :: Bitcode . extension ( ) , path. as_path ( ) ) ) ;
550551 }
551- if let Some ( ( id, product) ) =
552- copy_cgu_workproduct_to_incr_comp_cache_dir ( sess, & module. name , files. as_slice ( ) )
553- {
552+ if let Some ( ( id, product) ) = copy_cgu_workproduct_to_incr_comp_cache_dir (
553+ sess,
554+ & module. name ,
555+ files. as_slice ( ) ,
556+ & module. links_from_incr_cache ,
557+ ) {
554558 work_products. insert ( id, product) ;
555559 }
556560 }
@@ -942,7 +946,9 @@ fn execute_copy_from_cache_work_item<B: ExtraBackendMethods>(
942946) -> WorkItemResult < B > {
943947 let incr_comp_session_dir = cgcx. incr_comp_session_dir . as_ref ( ) . unwrap ( ) ;
944948
945- let load_from_incr_comp_dir = |output_path : PathBuf , saved_path : & str | {
949+ let mut links_from_incr_cache = Vec :: new ( ) ;
950+
951+ let mut load_from_incr_comp_dir = |output_path : PathBuf , saved_path : & str | {
946952 let source_file = in_incr_comp_dir ( incr_comp_session_dir, saved_path) ;
947953 debug ! (
948954 "copying preexisting module `{}` from {:?} to {}" ,
@@ -951,7 +957,11 @@ fn execute_copy_from_cache_work_item<B: ExtraBackendMethods>(
951957 output_path. display( )
952958 ) ;
953959 match link_or_copy ( & source_file, & output_path) {
954- Ok ( _) => Some ( output_path) ,
960+ Ok ( LinkOrCopy :: Copy ) => Some ( output_path) ,
961+ Ok ( LinkOrCopy :: Link ) => {
962+ links_from_incr_cache. push ( source_file) ;
963+ Some ( output_path)
964+ }
955965 Err ( error) => {
956966 cgcx. create_dcx ( ) . handle ( ) . emit_err ( errors:: CopyPathBuf {
957967 source_file,
@@ -974,7 +984,7 @@ fn execute_copy_from_cache_work_item<B: ExtraBackendMethods>(
974984 load_from_incr_comp_dir ( dwarf_obj_out, saved_dwarf_object_file)
975985 } ) ;
976986
977- let load_from_incr_cache = |perform, output_type : OutputType | {
987+ let mut load_from_incr_cache = |perform, output_type : OutputType | {
978988 if perform {
979989 let saved_file = module. source . saved_files . get ( output_type. extension ( ) ) ?;
980990 let output_path = cgcx. output_filenames . temp_path ( output_type, Some ( & module. name ) ) ;
@@ -994,6 +1004,7 @@ fn execute_copy_from_cache_work_item<B: ExtraBackendMethods>(
9941004 }
9951005
9961006 WorkItemResult :: Finished ( CompiledModule {
1007+ links_from_incr_cache,
9971008 name : module. name ,
9981009 kind : ModuleKind :: Regular ,
9991010 object,
0 commit comments