@@ -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 } ;
@@ -604,39 +605,39 @@ pub(crate) fn run_aot(
604
605
605
606
let global_asm_config = Arc :: new ( crate :: global_asm:: GlobalAsmConfig :: new ( tcx) ) ;
606
607
607
- let mut concurrency_limiter = ConcurrencyLimiter :: new ( tcx. sess , cgus. len ( ) ) ;
608
+ let ( todo_cgus, done_cgus) =
609
+ cgus. into_iter ( ) . enumerate ( ) . partition :: < Vec < _ > , _ > ( |& ( i, _) | match cgu_reuse[ i] {
610
+ _ if backend_config. disable_incr_cache => true ,
611
+ CguReuse :: No => true ,
612
+ CguReuse :: PreLto | CguReuse :: PostLto => false ,
613
+ } ) ;
614
+
615
+ let concurrency_limiter = IntoDynSyncSend ( ConcurrencyLimiter :: new ( tcx. sess , todo_cgus. len ( ) ) ) ;
608
616
609
617
let modules = tcx. sess . time ( "codegen mono items" , || {
610
- cgus. iter ( )
611
- . enumerate ( )
612
- . map ( |( i, cgu) | {
613
- let cgu_reuse =
614
- if backend_config. disable_incr_cache { CguReuse :: No } else { cgu_reuse[ i] } ;
615
- match cgu_reuse {
616
- CguReuse :: No => {
617
- let dep_node = cgu. codegen_dep_node ( tcx) ;
618
- tcx. dep_graph
619
- . with_task (
620
- dep_node,
621
- tcx,
622
- (
623
- backend_config. clone ( ) ,
624
- global_asm_config. clone ( ) ,
625
- cgu. name ( ) ,
626
- concurrency_limiter. acquire ( tcx. dcx ( ) ) ,
627
- ) ,
628
- module_codegen,
629
- Some ( rustc_middle:: dep_graph:: hash_result) ,
630
- )
631
- . 0
632
- }
633
- CguReuse :: PreLto | CguReuse :: PostLto => {
634
- concurrency_limiter. job_already_done ( ) ;
635
- OngoingModuleCodegen :: Sync ( reuse_workproduct_for_cgu ( tcx, cgu) )
636
- }
637
- }
638
- } )
639
- . collect :: < Vec < _ > > ( )
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
634
+ } ) ;
635
+ modules. extend (
636
+ done_cgus
637
+ . into_iter ( )
638
+ . map ( |( _, cgu) | OngoingModuleCodegen :: Sync ( reuse_workproduct_for_cgu ( tcx, cgu) ) ) ,
639
+ ) ;
640
+ modules
640
641
} ) ;
641
642
642
643
let mut allocator_module = make_module ( tcx. sess , & backend_config, "allocator_shim" . to_string ( ) ) ;
@@ -705,6 +706,6 @@ pub(crate) fn run_aot(
705
706
metadata_module,
706
707
metadata,
707
708
crate_info : CrateInfo :: new ( tcx, target_cpu) ,
708
- concurrency_limiter,
709
+ concurrency_limiter : concurrency_limiter . 0 ,
709
710
} )
710
711
}
0 commit comments