@@ -98,8 +98,9 @@ use std::fs::{self, File};
98
98
use std:: io:: { BufWriter , Write } ;
99
99
use std:: path:: { Path , PathBuf } ;
100
100
101
- use rustc_data_structures:: fx:: { FxHashMap , FxHashSet } ;
101
+ use rustc_data_structures:: fx:: { FxIndexMap , FxIndexSet } ;
102
102
use rustc_data_structures:: sync;
103
+ use rustc_data_structures:: unord:: { UnordMap , UnordSet } ;
103
104
use rustc_hir:: def:: DefKind ;
104
105
use rustc_hir:: def_id:: { DefId , DefIdSet , LOCAL_CRATE } ;
105
106
use rustc_hir:: definitions:: DefPathDataName ;
@@ -131,7 +132,7 @@ struct PlacedMonoItems<'tcx> {
131
132
/// The codegen units, sorted by name to make things deterministic.
132
133
codegen_units : Vec < CodegenUnit < ' tcx > > ,
133
134
134
- internalization_candidates : FxHashSet < MonoItem < ' tcx > > ,
135
+ internalization_candidates : UnordSet < MonoItem < ' tcx > > ,
135
136
}
136
137
137
138
// The output CGUs are sorted by name.
@@ -197,9 +198,9 @@ fn place_mono_items<'tcx, I>(cx: &PartitioningCx<'_, 'tcx>, mono_items: I) -> Pl
197
198
where
198
199
I : Iterator < Item = MonoItem < ' tcx > > ,
199
200
{
200
- let mut codegen_units = FxHashMap :: default ( ) ;
201
+ let mut codegen_units = UnordMap :: default ( ) ;
201
202
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 ( ) ;
203
204
204
205
// Determine if monomorphizations instantiated in this crate will be made
205
206
// available to downstream crates. This depends on whether we are in
@@ -209,7 +210,7 @@ where
209
210
cx. tcx . sess . opts . share_generics ( ) && cx. tcx . local_crate_exports_generics ( ) ;
210
211
211
212
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 ( ) ;
213
214
214
215
for mono_item in mono_items {
215
216
// Handle only root (GloballyShared) items directly here. Inlined (LocalCopy) items
@@ -260,7 +261,7 @@ where
260
261
// going via another root item. This includes drop-glue, functions from
261
262
// external crates, and local functions the definition of which is
262
263
// marked with `#[inline]`.
263
- let mut reachable_inlined_items = FxHashSet :: default ( ) ;
264
+ let mut reachable_inlined_items = FxIndexSet :: default ( ) ;
264
265
get_reachable_inlined_items ( cx. tcx , mono_item, cx. usage_map , & mut reachable_inlined_items) ;
265
266
266
267
// Add those inlined items. It's possible an inlined item is reachable
@@ -284,8 +285,9 @@ where
284
285
codegen_units. insert ( cgu_name, CodegenUnit :: new ( cgu_name) ) ;
285
286
}
286
287
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
+ } ) ;
289
291
290
292
for cgu in codegen_units. iter_mut ( ) {
291
293
cgu. compute_size_estimate ( ) ;
@@ -297,7 +299,7 @@ where
297
299
tcx : TyCtxt < ' tcx > ,
298
300
item : MonoItem < ' tcx > ,
299
301
usage_map : & UsageMap < ' tcx > ,
300
- visited : & mut FxHashSet < MonoItem < ' tcx > > ,
302
+ visited : & mut FxIndexSet < MonoItem < ' tcx > > ,
301
303
) {
302
304
usage_map. for_each_inlined_used_item ( tcx, item, |inlined_item| {
303
305
let is_new = visited. insert ( inlined_item) ;
@@ -320,7 +322,7 @@ fn merge_codegen_units<'tcx>(
320
322
assert ! ( codegen_units. is_sorted_by( |a, b| a. name( ) . as_str( ) <= b. name( ) . as_str( ) ) ) ;
321
323
322
324
// 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 > > =
324
326
codegen_units. iter ( ) . map ( |cgu| ( cgu. name ( ) , vec ! [ cgu. name( ) ] ) ) . collect ( ) ;
325
327
326
328
// If N is the maximum number of CGUs, and the CGUs are sorted from largest
@@ -422,22 +424,24 @@ fn merge_codegen_units<'tcx>(
422
424
// For CGUs that contain the code of multiple modules because of the
423
425
// merging done above, we use a concatenation of the names of all
424
426
// 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
+ ) ;
441
445
442
446
for cgu in codegen_units. iter_mut ( ) {
443
447
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
511
515
fn internalize_symbols < ' tcx > (
512
516
cx : & PartitioningCx < ' _ , ' tcx > ,
513
517
codegen_units : & mut [ CodegenUnit < ' tcx > ] ,
514
- internalization_candidates : FxHashSet < MonoItem < ' tcx > > ,
518
+ internalization_candidates : UnordSet < MonoItem < ' tcx > > ,
515
519
) {
516
520
/// For symbol internalization, we need to know whether a symbol/mono-item
517
521
/// is used from outside the codegen unit it is defined in. This type is
@@ -522,7 +526,7 @@ fn internalize_symbols<'tcx>(
522
526
MultipleCgus ,
523
527
}
524
528
525
- let mut mono_item_placements = FxHashMap :: default ( ) ;
529
+ let mut mono_item_placements = UnordMap :: default ( ) ;
526
530
let single_codegen_unit = codegen_units. len ( ) == 1 ;
527
531
528
532
if !single_codegen_unit {
@@ -739,7 +743,7 @@ fn mono_item_linkage_and_visibility<'tcx>(
739
743
( Linkage :: External , vis)
740
744
}
741
745
742
- type CguNameCache = FxHashMap < ( DefId , bool ) , Symbol > ;
746
+ type CguNameCache = UnordMap < ( DefId , bool ) , Symbol > ;
743
747
744
748
fn static_visibility < ' tcx > (
745
749
tcx : TyCtxt < ' tcx > ,
@@ -932,7 +936,7 @@ fn debug_dump<'a, 'tcx: 'a>(tcx: TyCtxt<'tcx>, label: &str, cgus: &[CodegenUnit<
932
936
//
933
937
// Also, unreached inlined items won't be counted here. This is fine.
934
938
935
- let mut inlined_items = FxHashSet :: default ( ) ;
939
+ let mut inlined_items = UnordSet :: default ( ) ;
936
940
937
941
let mut root_items = 0 ;
938
942
let mut unique_inlined_items = 0 ;
@@ -1164,7 +1168,7 @@ fn collect_and_partition_mono_items(tcx: TyCtxt<'_>, (): ()) -> (&DefIdSet, &[Co
1164
1168
}
1165
1169
1166
1170
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 ( ) ;
1168
1172
1169
1173
for cgu in codegen_units {
1170
1174
for ( & mono_item, & data) in cgu. items ( ) {
@@ -1240,7 +1244,7 @@ fn dump_mono_items_stats<'tcx>(
1240
1244
let mut file = BufWriter :: new ( file) ;
1241
1245
1242
1246
// 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 ( ) ;
1244
1248
for cgu in codegen_units {
1245
1249
cgu. items ( )
1246
1250
. keys ( )
0 commit comments