@@ -15,7 +15,9 @@ use rustc_errors::{
1515} ;
1616use rustc_fs_util:: link_or_copy;
1717use rustc_hir:: find_attr;
18- use rustc_incremental:: { copy_cgu_workproduct_to_incr_comp_cache_dir, in_incr_comp_dir_sess} ;
18+ use rustc_incremental:: {
19+ copy_cgu_workproduct_to_incr_comp_cache_dir, in_incr_comp_dir_sess, in_old_incr_comp_dir_sess,
20+ } ;
1921use rustc_macros:: { Decodable , Encodable } ;
2022use rustc_metadata:: fs:: copy_to_stdout;
2123use rustc_middle:: bug;
@@ -349,9 +351,12 @@ pub struct CodegenContext {
349351 /// Directory into which should the LLVM optimization remarks be written.
350352 /// If `None`, they will be written to stderr.
351353 pub remark_dir : Option < PathBuf > ,
354+ /// The previous incremental compilation session directory, or None if we
355+ /// are not compiling incrementally or there is no previous session.
356+ pub old_incr_comp_session_dir : Option < PathBuf > ,
352357 /// The incremental compilation session directory, or None if we are not
353358 /// compiling incrementally
354- pub incr_comp_session_dir : Option < PathBuf > ,
359+ pub new_incr_comp_session_dir : Option < PathBuf > ,
355360 /// `true` if the codegen should be run in parallel.
356361 ///
357362 /// Depends on [`WriteBackendMethods::supports_parallel()`] and `-Zno_parallel_backend`.
@@ -498,7 +503,6 @@ fn copy_all_cgu_workproducts_to_incr_comp_cache_dir(
498503 incr_comp_session. unwrap ( ) ,
499504 & module. name ,
500505 files. as_slice ( ) ,
501- & module. links_from_incr_cache ,
502506 ) ;
503507 work_products. insert ( id, product) ;
504508 }
@@ -840,7 +844,7 @@ fn execute_optimize_work_item<B: WriteBackendMethods>(
840844 // save our module to disk first.
841845 let bitcode = if cgcx. module_config . emit_pre_lto_bc {
842846 let filename = pre_lto_bitcode_filename ( & module. name ) ;
843- cgcx. incr_comp_session_dir . as_ref ( ) . map ( |path| path. join ( & filename) )
847+ cgcx. new_incr_comp_session_dir . as_ref ( ) . map ( |path| path. join ( & filename) )
844848 } else {
845849 None
846850 } ;
@@ -887,11 +891,9 @@ fn execute_copy_from_cache_work_item(
887891 let dcx = DiagCtxt :: new ( Box :: new ( shared_emitter) ) ;
888892 let dcx = dcx. handle ( ) ;
889893
890- let incr_comp_session_dir = cgcx. incr_comp_session_dir . as_ref ( ) . unwrap ( ) ;
891-
892- let mut links_from_incr_cache = Vec :: new ( ) ;
894+ let incr_comp_session_dir = cgcx. old_incr_comp_session_dir . as_ref ( ) . unwrap ( ) ;
893895
894- let mut load_from_incr_comp_dir = |output_path : PathBuf , saved_path : & str | {
896+ let load_from_incr_comp_dir = |output_path : PathBuf , saved_path : & str | {
895897 let source_file_in_incr_comp_dir = incr_comp_session_dir. join ( saved_path) ;
896898 debug ! (
897899 "copying preexisting module `{}` from {:?} to {}" ,
@@ -900,10 +902,7 @@ fn execute_copy_from_cache_work_item(
900902 output_path. display( )
901903 ) ;
902904 match link_or_copy ( & source_file_in_incr_comp_dir, & output_path) {
903- Ok ( _) => {
904- links_from_incr_cache. push ( source_file_in_incr_comp_dir) ;
905- Some ( output_path)
906- }
905+ Ok ( _) => Some ( output_path) ,
907906 Err ( error) => {
908907 dcx. emit_err ( diagnostics:: CopyPathBuf {
909908 source_file : source_file_in_incr_comp_dir,
@@ -926,7 +925,7 @@ fn execute_copy_from_cache_work_item(
926925 load_from_incr_comp_dir ( dwarf_obj_out, saved_dwarf_object_file)
927926 } ) ;
928927
929- let mut load_from_incr_cache = |perform, output_type : OutputType | {
928+ let load_from_incr_cache = |perform, output_type : OutputType | {
930929 if perform {
931930 let saved_file = module. source . saved_files . get ( output_type. extension ( ) ) ?;
932931 let output_path = cgcx. output_filenames . temp_path_for_cgu ( output_type, & module. name ) ;
@@ -954,7 +953,6 @@ fn execute_copy_from_cache_work_item(
954953 }
955954
956955 CompiledModule {
957- links_from_incr_cache,
958956 kind : ModuleKind :: Regular ,
959957 name : module. name ,
960958 object,
@@ -1288,10 +1286,14 @@ fn start_executing_work<B: WriteBackendMethods>(
12881286 time_trace : sess. opts . unstable_opts . llvm_time_trace ,
12891287 remark : sess. opts . cg . remark . clone ( ) ,
12901288 remark_dir,
1291- incr_comp_session_dir : tcx
1289+ old_incr_comp_session_dir : tcx
1290+ . incr_comp_session
1291+ . as_ref ( )
1292+ . and_then ( |incr_comp_session| incr_comp_session. old_session_directory . clone ( ) ) ,
1293+ new_incr_comp_session_dir : tcx
12921294 . incr_comp_session
12931295 . as_ref ( )
1294- . map ( |incr_comp_session| incr_comp_session. session_directory . clone ( ) ) ,
1296+ . map ( |incr_comp_session| incr_comp_session. new_session_directory . clone ( ) ) ,
12951297 output_filenames : Arc :: clone ( tcx. output_filenames ( ( ) ) ) ,
12961298 module_config : regular_config,
12971299 opt_level,
@@ -2262,13 +2264,28 @@ pub(crate) fn submit_pre_lto_module_to_llvm<B: WriteBackendMethods>(
22622264 module : CachedModuleCodegen ,
22632265) {
22642266 let filename = pre_lto_bitcode_filename ( & module. name ) ;
2267+ let old_bitcode_path =
2268+ in_old_incr_comp_dir_sess ( tcx. incr_comp_session . unwrap ( ) , & filename) . unwrap ( ) ;
22652269 let bitcode_path = in_incr_comp_dir_sess ( tcx. incr_comp_session . unwrap ( ) , & filename) ;
2270+
2271+ // FIXME is this necessary?
2272+ // match link_or_copy(&old_bitcode_path, &bitcode_path) {
2273+ // Ok(_) => {}
2274+ // Err(error) => {
2275+ // tcx.sess.dcx().emit_err(diagnostics::CopyPathBuf {
2276+ // source_file: old_bitcode_path,
2277+ // output_path: bitcode_path,
2278+ // error,
2279+ // });
2280+ // return;
2281+ // }
2282+ // }
2283+
22662284 // Schedule the module to be loaded
2267- drop (
2268- coordinator
2269- . sender
2270- . send ( Message :: AddImportOnlyModule :: < B > { bitcode_path, work_product : module. source } ) ,
2271- ) ;
2285+ drop ( coordinator. sender . send ( Message :: AddImportOnlyModule :: < B > {
2286+ bitcode_path : old_bitcode_path,
2287+ work_product : module. source ,
2288+ } ) ) ;
22722289}
22732290
22742291fn pre_lto_bitcode_filename ( module_name : & str ) -> String {
0 commit comments