@@ -102,7 +102,7 @@ use rustc::mir::mono::{CodegenUnit, CodegenUnitNameBuilder, Linkage, Visibility}
102102use rustc:: mir:: mono:: { InstantiationMode , MonoItem } ;
103103use rustc:: ty:: print:: characteristic_def_id_of_type;
104104use rustc:: ty:: query:: Providers ;
105- use rustc:: ty:: { self , DefIdTree , InstanceDef , TyCtxt } ;
105+ use rustc:: ty:: { self , DefIdTree , InstanceDef , SymbolName , TyCtxt } ;
106106use rustc_data_structures:: fx:: { FxHashMap , FxHashSet } ;
107107use rustc_data_structures:: sync:: { self , join} ;
108108use rustc_hir:: def:: DefKind ;
@@ -125,15 +125,12 @@ fn fallback_cgu_name(name_builder: &mut CodegenUnitNameBuilder<'_>) -> Symbol {
125125 name_builder. build_cgu_name ( LOCAL_CRATE , & [ "fallback" ] , Some ( "cgu" ) )
126126}
127127
128- pub fn partition < ' tcx , I > (
128+ pub fn partition < ' tcx > (
129129 tcx : TyCtxt < ' tcx > ,
130- mono_items : I ,
130+ mono_items : & [ MonoItem < ' tcx > ] ,
131131 strategy : PartitioningStrategy ,
132132 inlining_map : & InliningMap < ' tcx > ,
133- ) -> Vec < CodegenUnit < ' tcx > >
134- where
135- I : Iterator < Item = MonoItem < ' tcx > > + sync:: Send ,
136- {
133+ ) -> Vec < CodegenUnit < ' tcx > > {
137134 let _prof_timer = tcx. prof . generic_activity ( "cgu_partitioning" ) ;
138135
139136 // In the first step, we place all regular monomorphizations into their
@@ -210,10 +207,10 @@ struct PostInliningPartitioning<'tcx> {
210207 internalization_candidates : FxHashSet < MonoItem < ' tcx > > ,
211208}
212209
213- fn place_root_mono_items < ' tcx , I > ( tcx : TyCtxt < ' tcx > , mono_items : I ) -> PreInliningPartitioning < ' tcx >
214- where
215- I : Iterator < Item = MonoItem < ' tcx > > ,
216- {
210+ fn place_root_mono_items < ' tcx > (
211+ tcx : TyCtxt < ' tcx > ,
212+ mono_items : & [ MonoItem < ' tcx > ] ,
213+ ) -> PreInliningPartitioning < ' tcx > {
217214 let is_incremental_build = tcx. sess . opts . incremental . is_some ( ) ;
218215
219216 // Determine if monomorphizations instantiated in this crate will be made
@@ -222,8 +219,6 @@ where
222219 // downstream crates.
223220 let export_generics = tcx. sess . opts . share_generics ( ) && tcx. local_crate_exports_generics ( ) ;
224221
225- let mono_items: Vec < _ > = mono_items. collect ( ) ;
226-
227222 let chunks = tcx. prof . generic_activity ( "place_root_mono_items_par" ) . run ( || {
228223 sync:: par_partition ( & mono_items, 2 , |chunk| {
229224 let mut roots = Vec :: new ( ) ;
@@ -827,17 +822,23 @@ where
827822}
828823
829824#[ inline( never) ] // give this a place in the profiler
830- fn assert_symbols_are_distinct < ' a , ' tcx , I > ( tcx : TyCtxt < ' tcx > , mono_items : I )
831- where
832- I : Iterator < Item = & ' a MonoItem < ' tcx > > ,
833- ' tcx : ' a ,
834- {
825+ fn assert_symbols_are_distinct < ' tcx > ( tcx : TyCtxt < ' tcx > , mono_items : & [ MonoItem < ' tcx > ] ) {
835826 let _prof_timer = tcx. prof . generic_activity ( "assert_symbols_are_distinct" ) ;
836827
837- let mut symbols: Vec < _ > =
838- mono_items. map ( |mono_item| ( mono_item, mono_item. symbol_name ( tcx) ) ) . collect ( ) ;
828+ let mut symbols: Vec < ( & MonoItem < ' tcx > , SymbolName ) > =
829+ sync:: par_partition ( mono_items, 2 , |chunk| {
830+ chunk
831+ . iter ( )
832+ . map ( |mono_item| ( mono_item, mono_item. symbol_name ( tcx) ) )
833+ . collect :: < Vec < _ > > ( )
834+ } )
835+ . into_iter ( )
836+ . flatten ( )
837+ . collect ( ) ;
839838
840- symbols. sort_by_key ( |sym| sym. 1 ) ;
839+ tcx. prof
840+ . generic_activity ( "assert_symbols_are_distinct_sort" )
841+ . run ( || symbols. sort_by_key ( |sym| sym. 1 ) ) ;
841842
842843 for pair in symbols. windows ( 2 ) {
843844 let sym1 = & pair[ 0 ] . 1 ;
@@ -907,6 +908,8 @@ fn collect_and_partition_mono_items(
907908
908909 tcx. sess . abort_if_errors ( ) ;
909910
911+ let items: Vec < _ > = items. iter ( ) . copied ( ) . collect ( ) ;
912+
910913 let ( codegen_units, _) = tcx. sess . time ( "partition_and_assert_distinct_symbols" , || {
911914 sync:: join (
912915 || {
@@ -916,12 +919,12 @@ fn collect_and_partition_mono_items(
916919 PartitioningStrategy :: FixedUnitCount ( tcx. sess . codegen_units ( ) )
917920 } ;
918921
919- partition ( tcx, items. iter ( ) . cloned ( ) , strategy, & inlining_map)
922+ partition ( tcx, & items, strategy, & inlining_map)
920923 . into_iter ( )
921924 . map ( Arc :: new)
922925 . collect :: < Vec < _ > > ( )
923926 } ,
924- || assert_symbols_are_distinct ( tcx, items. iter ( ) ) ,
927+ || assert_symbols_are_distinct ( tcx, & items) ,
925928 )
926929 } ) ;
927930
0 commit comments