@@ -15,6 +15,7 @@ use rustc_codegen_ssa::errors as ssa_errors;
15
15
use rustc_codegen_ssa:: { CodegenResults , CompiledModule , CrateInfo , ModuleKind } ;
16
16
use rustc_data_structures:: profiling:: SelfProfilerRef ;
17
17
use rustc_data_structures:: stable_hasher:: { HashStable , StableHasher } ;
18
+ use rustc_data_structures:: sync:: { par_map, IntoDynSyncSend } ;
18
19
use rustc_metadata:: fs:: copy_to_stdout;
19
20
use rustc_metadata:: EncodedMetadata ;
20
21
use rustc_middle:: dep_graph:: { WorkProduct , WorkProductId } ;
@@ -611,34 +612,33 @@ pub(crate) fn run_aot(
611
612
CguReuse :: PreLto | CguReuse :: PostLto => false ,
612
613
} ) ;
613
614
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
641
634
} ) ;
635
+ modules. extend (
636
+ done_cgus
637
+ . into_iter ( )
638
+ . map ( |( _, cgu) | OngoingModuleCodegen :: Sync ( reuse_workproduct_for_cgu ( tcx, cgu) ) ) ,
639
+ ) ;
640
+ modules
641
+ } ) ;
642
642
643
643
let mut allocator_module = make_module ( tcx. sess , & backend_config, "allocator_shim" . to_string ( ) ) ;
644
644
let mut allocator_unwind_context = UnwindContext :: new ( allocator_module. isa ( ) , true ) ;
@@ -706,6 +706,6 @@ pub(crate) fn run_aot(
706
706
metadata_module,
707
707
metadata,
708
708
crate_info : CrateInfo :: new ( tcx, target_cpu) ,
709
- concurrency_limiter,
709
+ concurrency_limiter : concurrency_limiter . 0 ,
710
710
} )
711
711
}
0 commit comments