@@ -27,6 +27,41 @@ impl<HCX> HashStable<HCX> for ModuleCodegenResult {
2727 }
2828}
2929
30+ pub ( crate ) struct OngoingCodegen {
31+ modules : Vec < ModuleCodegenResult > ,
32+ allocator_module : Option < CompiledModule > ,
33+ metadata_module : Option < CompiledModule > ,
34+ metadata : EncodedMetadata ,
35+ crate_info : CrateInfo ,
36+ work_products : FxHashMap < WorkProductId , WorkProduct > ,
37+ }
38+
39+ impl OngoingCodegen {
40+ pub ( crate ) fn join ( self ) -> ( CodegenResults , FxHashMap < WorkProductId , WorkProduct > ) {
41+ let mut work_products = self . work_products ;
42+ let mut modules = vec ! [ ] ;
43+
44+ for module_codegen_result in self . modules {
45+ let ModuleCodegenResult ( module, work_product) = module_codegen_result;
46+ if let Some ( ( work_product_id, work_product) ) = work_product {
47+ work_products. insert ( work_product_id, work_product) ;
48+ }
49+ modules. push ( module) ;
50+ }
51+
52+ (
53+ CodegenResults {
54+ modules,
55+ allocator_module : self . allocator_module ,
56+ metadata_module : self . metadata_module ,
57+ metadata : self . metadata ,
58+ crate_info : self . crate_info ,
59+ } ,
60+ work_products,
61+ )
62+ }
63+ }
64+
3065fn make_module ( sess : & Session , isa : Box < dyn TargetIsa > , name : String ) -> ObjectModule {
3166 let mut builder =
3267 ObjectBuilder :: new ( isa, name + ".o" , cranelift_module:: default_libcall_names ( ) ) . unwrap ( ) ;
@@ -192,9 +227,7 @@ pub(crate) fn run_aot(
192227 backend_config : BackendConfig ,
193228 metadata : EncodedMetadata ,
194229 need_metadata_module : bool ,
195- ) -> Box < ( CodegenResults , FxHashMap < WorkProductId , WorkProduct > ) > {
196- let mut work_products = FxHashMap :: default ( ) ;
197-
230+ ) -> Box < OngoingCodegen > {
198231 let cgus = if tcx. sess . opts . output_types . should_codegen ( ) {
199232 tcx. collect_and_partition_mono_items ( ( ) ) . 1
200233 } else {
@@ -219,7 +252,7 @@ pub(crate) fn run_aot(
219252 } ;
220253 tcx. sess . cgu_reuse_tracker . set_actual_reuse ( cgu. name ( ) . as_str ( ) , cgu_reuse) ;
221254
222- let module_codegen_result = match cgu_reuse {
255+ match cgu_reuse {
223256 CguReuse :: No => {
224257 let dep_node = cgu. codegen_dep_node ( tcx) ;
225258 tcx. dep_graph
@@ -234,21 +267,15 @@ pub(crate) fn run_aot(
234267 }
235268 CguReuse :: PreLto => reuse_workproduct_for_cgu ( tcx, & * cgu) ,
236269 CguReuse :: PostLto => unreachable ! ( ) ,
237- } ;
238-
239- let ModuleCodegenResult ( module, work_product) = module_codegen_result;
240-
241- if let Some ( ( id, product) ) = work_product {
242- work_products. insert ( id, product) ;
243270 }
244-
245- module
246271 } )
247272 . collect :: < Vec < _ > > ( )
248273 } ) ;
249274
250275 tcx. sess . abort_if_errors ( ) ;
251276
277+ let mut work_products = FxHashMap :: default ( ) ;
278+
252279 let isa = crate :: build_isa ( tcx. sess , & backend_config) ;
253280 let mut allocator_module = make_module ( tcx. sess , isa, "allocator_shim" . to_string ( ) ) ;
254281 assert_eq ! ( pointer_ty( tcx) , allocator_module. target_config( ) . pointer_type( ) ) ;
@@ -316,16 +343,14 @@ pub(crate) fn run_aot(
316343 }
317344 . to_owned ( ) ;
318345
319- Box :: new ( (
320- CodegenResults {
321- modules,
322- allocator_module,
323- metadata_module,
324- metadata,
325- crate_info : CrateInfo :: new ( tcx, target_cpu) ,
326- } ,
346+ Box :: new ( OngoingCodegen {
347+ modules,
348+ allocator_module,
349+ metadata_module,
350+ metadata,
351+ crate_info : CrateInfo :: new ( tcx, target_cpu) ,
327352 work_products,
328- ) )
353+ } )
329354}
330355
331356fn codegen_global_asm ( tcx : TyCtxt < ' _ > , cgu_name : & str , global_asm : & str ) {
0 commit comments