@@ -98,8 +98,9 @@ use std::fs::{self, File};
9898use std:: io:: { BufWriter , Write } ;
9999use std:: path:: { Path , PathBuf } ;
100100
101- use rustc_data_structures:: fx:: { FxHashMap , FxHashSet } ;
101+ use rustc_data_structures:: fx:: { FxIndexMap , FxIndexSet } ;
102102use rustc_data_structures:: sync;
103+ use rustc_data_structures:: unord:: { UnordMap , UnordSet } ;
103104use rustc_hir:: def:: DefKind ;
104105use rustc_hir:: def_id:: { DefId , DefIdSet , LOCAL_CRATE } ;
105106use rustc_hir:: definitions:: DefPathDataName ;
@@ -131,7 +132,7 @@ struct PlacedMonoItems<'tcx> {
131132 /// The codegen units, sorted by name to make things deterministic.
132133 codegen_units : Vec < CodegenUnit < ' tcx > > ,
133134
134- internalization_candidates : FxHashSet < MonoItem < ' tcx > > ,
135+ internalization_candidates : UnordSet < MonoItem < ' tcx > > ,
135136}
136137
137138// The output CGUs are sorted by name.
@@ -197,9 +198,9 @@ fn place_mono_items<'tcx, I>(cx: &PartitioningCx<'_, 'tcx>, mono_items: I) -> Pl
197198where
198199 I : Iterator < Item = MonoItem < ' tcx > > ,
199200{
200- let mut codegen_units = FxHashMap :: default ( ) ;
201+ let mut codegen_units = UnordMap :: default ( ) ;
201202 let is_incremental_build = cx. tcx . sess . opts . incremental . is_some ( ) ;
202- let mut internalization_candidates = FxHashSet :: default ( ) ;
203+ let mut internalization_candidates = UnordSet :: default ( ) ;
203204
204205 // Determine if monomorphizations instantiated in this crate will be made
205206 // available to downstream crates. This depends on whether we are in
@@ -209,7 +210,7 @@ where
209210 cx. tcx . sess . opts . share_generics ( ) && cx. tcx . local_crate_exports_generics ( ) ;
210211
211212 let cgu_name_builder = & mut CodegenUnitNameBuilder :: new ( cx. tcx ) ;
212- let cgu_name_cache = & mut FxHashMap :: default ( ) ;
213+ let cgu_name_cache = & mut UnordMap :: default ( ) ;
213214
214215 for mono_item in mono_items {
215216 // Handle only root (GloballyShared) items directly here. Inlined (LocalCopy) items
@@ -260,7 +261,7 @@ where
260261 // going via another root item. This includes drop-glue, functions from
261262 // external crates, and local functions the definition of which is
262263 // marked with `#[inline]`.
263- let mut reachable_inlined_items = FxHashSet :: default ( ) ;
264+ let mut reachable_inlined_items = FxIndexSet :: default ( ) ;
264265 get_reachable_inlined_items ( cx. tcx , mono_item, cx. usage_map , & mut reachable_inlined_items) ;
265266
266267 // Add those inlined items. It's possible an inlined item is reachable
@@ -284,8 +285,9 @@ where
284285 codegen_units. insert ( cgu_name, CodegenUnit :: new ( cgu_name) ) ;
285286 }
286287
287- let mut codegen_units: Vec < _ > = codegen_units. into_values ( ) . collect ( ) ;
288- codegen_units. sort_by ( |a, b| a. name ( ) . as_str ( ) . cmp ( b. name ( ) . as_str ( ) ) ) ;
288+ let mut codegen_units: Vec < _ > = cx. tcx . with_stable_hashing_context ( |ref hcx| {
289+ codegen_units. into_items ( ) . map ( |( _, cgu) | cgu) . collect_sorted ( hcx, true )
290+ } ) ;
289291
290292 for cgu in codegen_units. iter_mut ( ) {
291293 cgu. compute_size_estimate ( ) ;
@@ -297,7 +299,7 @@ where
297299 tcx : TyCtxt < ' tcx > ,
298300 item : MonoItem < ' tcx > ,
299301 usage_map : & UsageMap < ' tcx > ,
300- visited : & mut FxHashSet < MonoItem < ' tcx > > ,
302+ visited : & mut FxIndexSet < MonoItem < ' tcx > > ,
301303 ) {
302304 usage_map. for_each_inlined_used_item ( tcx, item, |inlined_item| {
303305 let is_new = visited. insert ( inlined_item) ;
@@ -320,7 +322,7 @@ fn merge_codegen_units<'tcx>(
320322 assert ! ( codegen_units. is_sorted_by( |a, b| a. name( ) . as_str( ) <= b. name( ) . as_str( ) ) ) ;
321323
322324 // This map keeps track of what got merged into what.
323- let mut cgu_contents: FxHashMap < Symbol , Vec < Symbol > > =
325+ let mut cgu_contents: UnordMap < Symbol , Vec < Symbol > > =
324326 codegen_units. iter ( ) . map ( |cgu| ( cgu. name ( ) , vec ! [ cgu. name( ) ] ) ) . collect ( ) ;
325327
326328 // If N is the maximum number of CGUs, and the CGUs are sorted from largest
@@ -422,22 +424,24 @@ fn merge_codegen_units<'tcx>(
422424 // For CGUs that contain the code of multiple modules because of the
423425 // merging done above, we use a concatenation of the names of all
424426 // contained CGUs.
425- let new_cgu_names: FxHashMap < Symbol , String > = cgu_contents
426- . into_iter ( )
427- // This `filter` makes sure we only update the name of CGUs that
428- // were actually modified by merging.
429- . filter ( |( _, cgu_contents) | cgu_contents. len ( ) > 1 )
430- . map ( |( current_cgu_name, cgu_contents) | {
431- let mut cgu_contents: Vec < & str > = cgu_contents. iter ( ) . map ( |s| s. as_str ( ) ) . collect ( ) ;
432-
433- // Sort the names, so things are deterministic and easy to
434- // predict. We are sorting primitive `&str`s here so we can
435- // use unstable sort.
436- cgu_contents. sort_unstable ( ) ;
437-
438- ( current_cgu_name, cgu_contents. join ( "--" ) )
439- } )
440- . collect ( ) ;
427+ let new_cgu_names = UnordMap :: from (
428+ cgu_contents
429+ . items ( )
430+ // This `filter` makes sure we only update the name of CGUs that
431+ // were actually modified by merging.
432+ . filter ( |( _, cgu_contents) | cgu_contents. len ( ) > 1 )
433+ . map ( |( current_cgu_name, cgu_contents) | {
434+ let mut cgu_contents: Vec < & str > =
435+ cgu_contents. iter ( ) . map ( |s| s. as_str ( ) ) . collect ( ) ;
436+
437+ // Sort the names, so things are deterministic and easy to
438+ // predict. We are sorting primitive `&str`s here so we can
439+ // use unstable sort.
440+ cgu_contents. sort_unstable ( ) ;
441+
442+ ( * current_cgu_name, cgu_contents. join ( "--" ) )
443+ } ) ,
444+ ) ;
441445
442446 for cgu in codegen_units. iter_mut ( ) {
443447 if let Some ( new_cgu_name) = new_cgu_names. get ( & cgu. name ( ) ) {
@@ -511,7 +515,7 @@ fn compute_inlined_overlap<'tcx>(cgu1: &CodegenUnit<'tcx>, cgu2: &CodegenUnit<'t
511515fn internalize_symbols < ' tcx > (
512516 cx : & PartitioningCx < ' _ , ' tcx > ,
513517 codegen_units : & mut [ CodegenUnit < ' tcx > ] ,
514- internalization_candidates : FxHashSet < MonoItem < ' tcx > > ,
518+ internalization_candidates : UnordSet < MonoItem < ' tcx > > ,
515519) {
516520 /// For symbol internalization, we need to know whether a symbol/mono-item
517521 /// is used from outside the codegen unit it is defined in. This type is
@@ -522,7 +526,7 @@ fn internalize_symbols<'tcx>(
522526 MultipleCgus ,
523527 }
524528
525- let mut mono_item_placements = FxHashMap :: default ( ) ;
529+ let mut mono_item_placements = UnordMap :: default ( ) ;
526530 let single_codegen_unit = codegen_units. len ( ) == 1 ;
527531
528532 if !single_codegen_unit {
@@ -739,7 +743,7 @@ fn mono_item_linkage_and_visibility<'tcx>(
739743 ( Linkage :: External , vis)
740744}
741745
742- type CguNameCache = FxHashMap < ( DefId , bool ) , Symbol > ;
746+ type CguNameCache = UnordMap < ( DefId , bool ) , Symbol > ;
743747
744748fn static_visibility < ' tcx > (
745749 tcx : TyCtxt < ' tcx > ,
@@ -932,7 +936,7 @@ fn debug_dump<'a, 'tcx: 'a>(tcx: TyCtxt<'tcx>, label: &str, cgus: &[CodegenUnit<
932936 //
933937 // Also, unreached inlined items won't be counted here. This is fine.
934938
935- let mut inlined_items = FxHashSet :: default ( ) ;
939+ let mut inlined_items = UnordSet :: default ( ) ;
936940
937941 let mut root_items = 0 ;
938942 let mut unique_inlined_items = 0 ;
@@ -1164,7 +1168,7 @@ fn collect_and_partition_mono_items(tcx: TyCtxt<'_>, (): ()) -> (&DefIdSet, &[Co
11641168 }
11651169
11661170 if tcx. sess . opts . unstable_opts . print_mono_items . is_some ( ) {
1167- let mut item_to_cgus: FxHashMap < _ , Vec < _ > > = Default :: default ( ) ;
1171+ let mut item_to_cgus: UnordMap < _ , Vec < _ > > = Default :: default ( ) ;
11681172
11691173 for cgu in codegen_units {
11701174 for ( & mono_item, & data) in cgu. items ( ) {
@@ -1240,7 +1244,7 @@ fn dump_mono_items_stats<'tcx>(
12401244 let mut file = BufWriter :: new ( file) ;
12411245
12421246 // Gather instantiated mono items grouped by def_id
1243- let mut items_per_def_id: FxHashMap < _ , Vec < _ > > = Default :: default ( ) ;
1247+ let mut items_per_def_id: FxIndexMap < _ , Vec < _ > > = Default :: default ( ) ;
12441248 for cgu in codegen_units {
12451249 cgu. items ( )
12461250 . keys ( )
0 commit comments