@@ -23,7 +23,7 @@ use crate::{prelude::*, BackendConfig};
2323struct ModuleCodegenResult {
2424 module_regular : CompiledModule ,
2525 module_global_asm : Option < CompiledModule > ,
26- work_product : Option < ( WorkProductId , WorkProduct ) > ,
26+ existing_work_product : Option < ( WorkProductId , WorkProduct ) > ,
2727}
2828
2929impl < HCX > HashStable < HCX > for ModuleCodegenResult {
@@ -41,16 +41,44 @@ pub(crate) struct OngoingCodegen {
4141}
4242
4343impl OngoingCodegen {
44- pub ( crate ) fn join ( self ) -> ( CodegenResults , FxHashMap < WorkProductId , WorkProduct > ) {
44+ pub ( crate ) fn join (
45+ self ,
46+ sess : & Session ,
47+ backend_config : & BackendConfig ,
48+ ) -> ( CodegenResults , FxHashMap < WorkProductId , WorkProduct > ) {
4549 let mut work_products = FxHashMap :: default ( ) ;
4650 let mut modules = vec ! [ ] ;
4751
4852 for module_codegen_result in self . modules {
49- let ModuleCodegenResult { module_regular, module_global_asm, work_product } =
53+ let ModuleCodegenResult { module_regular, module_global_asm, existing_work_product } =
5054 module_codegen_result;
51- if let Some ( ( work_product_id, work_product) ) = work_product {
55+
56+ if let Some ( ( work_product_id, work_product) ) = existing_work_product {
5257 work_products. insert ( work_product_id, work_product) ;
58+ } else {
59+ let work_product = if backend_config. disable_incr_cache {
60+ None
61+ } else if let Some ( module_global_asm) = & module_global_asm {
62+ rustc_incremental:: copy_cgu_workproduct_to_incr_comp_cache_dir (
63+ sess,
64+ & module_regular. name ,
65+ & [
66+ ( "o" , & module_regular. object . as_ref ( ) . unwrap ( ) ) ,
67+ ( "asm.o" , & module_global_asm. object . as_ref ( ) . unwrap ( ) ) ,
68+ ] ,
69+ )
70+ } else {
71+ rustc_incremental:: copy_cgu_workproduct_to_incr_comp_cache_dir (
72+ sess,
73+ & module_regular. name ,
74+ & [ ( "o" , & module_regular. object . as_ref ( ) . unwrap ( ) ) ] ,
75+ )
76+ } ;
77+ if let Some ( ( work_product_id, work_product) ) = work_product {
78+ work_products. insert ( work_product_id, work_product) ;
79+ }
5380 }
81+
5482 modules. push ( module_regular) ;
5583 if let Some ( module_global_asm) = module_global_asm {
5684 modules. push ( module_global_asm) ;
@@ -84,7 +112,6 @@ fn make_module(sess: &Session, backend_config: &BackendConfig, name: String) ->
84112
85113fn emit_cgu (
86114 tcx : TyCtxt < ' _ > ,
87- backend_config : & BackendConfig ,
88115 name : String ,
89116 module : ObjectModule ,
90117 debug : Option < DebugContext < ' _ > > ,
@@ -101,22 +128,6 @@ fn emit_cgu(
101128
102129 let module_regular = emit_module ( tcx, product. object , ModuleKind :: Regular , name. clone ( ) ) ;
103130
104- let work_product = if backend_config. disable_incr_cache {
105- None
106- } else if let Some ( global_asm_object_file) = & global_asm_object_file {
107- rustc_incremental:: copy_cgu_workproduct_to_incr_comp_cache_dir (
108- tcx. sess ,
109- & name,
110- & [ ( "o" , & module_regular. object . as_ref ( ) . unwrap ( ) ) , ( "asm.o" , global_asm_object_file) ] ,
111- )
112- } else {
113- rustc_incremental:: copy_cgu_workproduct_to_incr_comp_cache_dir (
114- tcx. sess ,
115- & name,
116- & [ ( "o" , & module_regular. object . as_ref ( ) . unwrap ( ) ) ] ,
117- )
118- } ;
119-
120131 ModuleCodegenResult {
121132 module_regular,
122133 module_global_asm : global_asm_object_file. map ( |global_asm_object_file| CompiledModule {
@@ -126,7 +137,7 @@ fn emit_cgu(
126137 dwarf_object : None ,
127138 bytecode : None ,
128139 } ) ,
129- work_product ,
140+ existing_work_product : None ,
130141 }
131142}
132143
@@ -205,7 +216,7 @@ fn reuse_workproduct_for_cgu(tcx: TyCtxt<'_>, cgu: &CodegenUnit<'_>) -> ModuleCo
205216 } else {
206217 None
207218 } ,
208- work_product : Some ( ( cgu. work_product_id ( ) , work_product) ) ,
219+ existing_work_product : Some ( ( cgu. work_product_id ( ) , work_product) ) ,
209220 }
210221}
211222
@@ -271,7 +282,6 @@ fn module_codegen(
271282 let codegen_result = tcx. sess . time ( "write object file" , || {
272283 emit_cgu (
273284 tcx,
274- & backend_config,
275285 cgu. name ( ) . as_str ( ) . to_string ( ) ,
276286 module,
277287 debug_context,
0 commit comments