@@ -102,7 +102,7 @@ use rustc::mir::mono::{CodegenUnit, CodegenUnitNameBuilder, Linkage, Visibility}
102
102
use rustc:: mir:: mono:: { InstantiationMode , MonoItem } ;
103
103
use rustc:: ty:: print:: characteristic_def_id_of_type;
104
104
use rustc:: ty:: query:: Providers ;
105
- use rustc:: ty:: { self , DefIdTree , InstanceDef , TyCtxt } ;
105
+ use rustc:: ty:: { self , DefIdTree , InstanceDef , SymbolName , TyCtxt } ;
106
106
use rustc_data_structures:: fx:: { FxHashMap , FxHashSet } ;
107
107
use rustc_data_structures:: sync:: { self , join} ;
108
108
use rustc_hir:: def:: DefKind ;
@@ -125,15 +125,12 @@ fn fallback_cgu_name(name_builder: &mut CodegenUnitNameBuilder<'_>) -> Symbol {
125
125
name_builder. build_cgu_name ( LOCAL_CRATE , & [ "fallback" ] , Some ( "cgu" ) )
126
126
}
127
127
128
- pub fn partition < ' tcx , I > (
128
+ pub fn partition < ' tcx > (
129
129
tcx : TyCtxt < ' tcx > ,
130
- mono_items : I ,
130
+ mono_items : & [ MonoItem < ' tcx > ] ,
131
131
strategy : PartitioningStrategy ,
132
132
inlining_map : & InliningMap < ' tcx > ,
133
- ) -> Vec < CodegenUnit < ' tcx > >
134
- where
135
- I : Iterator < Item = MonoItem < ' tcx > > + sync:: Send ,
136
- {
133
+ ) -> Vec < CodegenUnit < ' tcx > > {
137
134
let _prof_timer = tcx. prof . generic_activity ( "cgu_partitioning" ) ;
138
135
139
136
// In the first step, we place all regular monomorphizations into their
@@ -210,10 +207,10 @@ struct PostInliningPartitioning<'tcx> {
210
207
internalization_candidates : FxHashSet < MonoItem < ' tcx > > ,
211
208
}
212
209
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 > {
217
214
let is_incremental_build = tcx. sess . opts . incremental . is_some ( ) ;
218
215
219
216
// Determine if monomorphizations instantiated in this crate will be made
@@ -222,8 +219,6 @@ where
222
219
// downstream crates.
223
220
let export_generics = tcx. sess . opts . share_generics ( ) && tcx. local_crate_exports_generics ( ) ;
224
221
225
- let mono_items: Vec < _ > = mono_items. collect ( ) ;
226
-
227
222
let chunks = tcx. prof . generic_activity ( "place_root_mono_items_par" ) . run ( || {
228
223
sync:: par_partition ( & mono_items, 2 , |chunk| {
229
224
let mut roots = Vec :: new ( ) ;
@@ -827,17 +822,23 @@ where
827
822
}
828
823
829
824
#[ 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 > ] ) {
835
826
let _prof_timer = tcx. prof . generic_activity ( "assert_symbols_are_distinct" ) ;
836
827
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 ( ) ;
839
838
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 ) ) ;
841
842
842
843
for pair in symbols. windows ( 2 ) {
843
844
let sym1 = & pair[ 0 ] . 1 ;
@@ -907,6 +908,8 @@ fn collect_and_partition_mono_items(
907
908
908
909
tcx. sess . abort_if_errors ( ) ;
909
910
911
+ let items: Vec < _ > = items. iter ( ) . copied ( ) . collect ( ) ;
912
+
910
913
let ( codegen_units, _) = tcx. sess . time ( "partition_and_assert_distinct_symbols" , || {
911
914
sync:: join (
912
915
|| {
@@ -916,12 +919,12 @@ fn collect_and_partition_mono_items(
916
919
PartitioningStrategy :: FixedUnitCount ( tcx. sess . codegen_units ( ) )
917
920
} ;
918
921
919
- partition ( tcx, items. iter ( ) . cloned ( ) , strategy, & inlining_map)
922
+ partition ( tcx, & items, strategy, & inlining_map)
920
923
. into_iter ( )
921
924
. map ( Arc :: new)
922
925
. collect :: < Vec < _ > > ( )
923
926
} ,
924
- || assert_symbols_are_distinct ( tcx, items. iter ( ) ) ,
927
+ || assert_symbols_are_distinct ( tcx, & items) ,
925
928
)
926
929
} ) ;
927
930
0 commit comments