@@ -15,6 +15,7 @@ use rustc_codegen_ssa::errors as ssa_errors;
1515use rustc_codegen_ssa:: { CodegenResults , CompiledModule , CrateInfo , ModuleKind } ;
1616use rustc_data_structures:: profiling:: SelfProfilerRef ;
1717use rustc_data_structures:: stable_hasher:: { HashStable , StableHasher } ;
18+ use rustc_data_structures:: sync:: { par_map, IntoDynSyncSend } ;
1819use rustc_metadata:: fs:: copy_to_stdout;
1920use rustc_metadata:: EncodedMetadata ;
2021use rustc_middle:: dep_graph:: { WorkProduct , WorkProductId } ;
@@ -611,34 +612,33 @@ pub(crate) fn run_aot(
611612 CguReuse :: PreLto | CguReuse :: PostLto => false ,
612613 } ) ;
613614
614- let mut concurrency_limiter = ConcurrencyLimiter :: new ( tcx. sess , todo_cgus. len ( ) ) ;
615-
616- let modules =
617- tcx. sess . time ( "codegen mono items" , || {
618- todo_cgus
619- . into_iter ( )
620- . map ( |( _, cgu) | {
621- let dep_node = cgu. codegen_dep_node ( tcx) ;
622- tcx. dep_graph
623- . with_task (
624- dep_node,
625- tcx,
626- (
627- backend_config. clone ( ) ,
628- global_asm_config. clone ( ) ,
629- cgu. name ( ) ,
630- concurrency_limiter. acquire ( tcx. dcx ( ) ) ,
631- ) ,
632- module_codegen,
633- Some ( rustc_middle:: dep_graph:: hash_result) ,
634- )
635- . 0
636- } )
637- . chain ( done_cgus. into_iter ( ) . map ( |( _, cgu) | {
638- OngoingModuleCodegen :: Sync ( reuse_workproduct_for_cgu ( tcx, cgu) )
639- } ) )
640- . collect :: < Vec < _ > > ( )
615+ let concurrency_limiter = IntoDynSyncSend ( ConcurrencyLimiter :: new ( tcx. sess , todo_cgus. len ( ) ) ) ;
616+
617+ let modules = tcx. sess . time ( "codegen mono items" , || {
618+ let mut modules: Vec < _ > = par_map ( todo_cgus, |( _, cgu) | {
619+ let dep_node = cgu. codegen_dep_node ( tcx) ;
620+ tcx. dep_graph
621+ . with_task (
622+ dep_node,
623+ tcx,
624+ (
625+ backend_config. clone ( ) ,
626+ global_asm_config. clone ( ) ,
627+ cgu. name ( ) ,
628+ concurrency_limiter. acquire ( tcx. dcx ( ) ) ,
629+ ) ,
630+ module_codegen,
631+ Some ( rustc_middle:: dep_graph:: hash_result) ,
632+ )
633+ . 0
641634 } ) ;
635+ modules. extend (
636+ done_cgus
637+ . into_iter ( )
638+ . map ( |( _, cgu) | OngoingModuleCodegen :: Sync ( reuse_workproduct_for_cgu ( tcx, cgu) ) ) ,
639+ ) ;
640+ modules
641+ } ) ;
642642
643643 let mut allocator_module = make_module ( tcx. sess , & backend_config, "allocator_shim" . to_string ( ) ) ;
644644 let mut allocator_unwind_context = UnwindContext :: new ( allocator_module. isa ( ) , true ) ;
@@ -706,6 +706,6 @@ pub(crate) fn run_aot(
706706 metadata_module,
707707 metadata,
708708 crate_info : CrateInfo :: new ( tcx, target_cpu) ,
709- concurrency_limiter,
709+ concurrency_limiter : concurrency_limiter . 0 ,
710710 } )
711711}
0 commit comments