@@ -124,15 +124,11 @@ use rustc::hir::map::DefPathData;
124
124
use rustc:: session:: config:: NUMBERED_CODEGEN_UNIT_MARKER ;
125
125
use rustc:: ty:: TyCtxt ;
126
126
use rustc:: ty:: item_path:: characteristic_def_id_of_type;
127
+ use symbol_map:: SymbolMap ;
127
128
use syntax:: parse:: token:: { self , InternedString } ;
128
129
use trans_item:: TransItem ;
129
130
use util:: nodemap:: { FnvHashMap , FnvHashSet , NodeSet } ;
130
131
131
- pub struct CodegenUnit < ' tcx > {
132
- pub name : InternedString ,
133
- pub items : FnvHashMap < TransItem < ' tcx > , llvm:: Linkage > ,
134
- }
135
-
136
132
pub enum PartitioningStrategy {
137
133
/// Generate one codegen unit per source-level module.
138
134
PerModule ,
@@ -141,6 +137,29 @@ pub enum PartitioningStrategy {
141
137
FixedUnitCount ( usize )
142
138
}
143
139
140
+ pub struct CodegenUnit < ' tcx > {
141
+ pub name : InternedString ,
142
+ pub items : FnvHashMap < TransItem < ' tcx > , llvm:: Linkage > ,
143
+ }
144
+
145
+ impl < ' tcx > CodegenUnit < ' tcx > {
146
+ pub fn items_in_deterministic_order ( & self ,
147
+ symbol_map : & SymbolMap )
148
+ -> Vec < ( TransItem < ' tcx > , llvm:: Linkage ) > {
149
+ let mut items: Vec < ( TransItem < ' tcx > , llvm:: Linkage ) > =
150
+ self . items . iter ( ) . map ( |( item, linkage) | ( * item, * linkage) ) . collect ( ) ;
151
+
152
+ items. as_mut_slice ( ) . sort_by ( |& ( trans_item1, _) , & ( trans_item2, _) | {
153
+ let symbol_name1 = symbol_map. get ( trans_item1) . unwrap ( ) ;
154
+ let symbol_name2 = symbol_map. get ( trans_item2) . unwrap ( ) ;
155
+ symbol_name1. cmp ( symbol_name2)
156
+ } ) ;
157
+
158
+ items
159
+ }
160
+ }
161
+
162
+
144
163
// Anything we can't find a proper codegen unit for goes into this.
145
164
const FALLBACK_CODEGEN_UNIT : & ' static str = "__rustc_fallback_codegen_unit" ;
146
165
@@ -184,7 +203,13 @@ pub fn partition<'a, 'tcx, I>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
184
203
185
204
debug_dump ( tcx, "POST INLINING:" , post_inlining. 0 . iter ( ) ) ;
186
205
187
- post_inlining. 0
206
+ // Finally, sort by codegen unit name, so that we get deterministic results
207
+ let mut result = post_inlining. 0 ;
208
+ result. as_mut_slice ( ) . sort_by ( |cgu1, cgu2| {
209
+ ( & cgu1. name [ ..] ) . cmp ( & cgu2. name [ ..] )
210
+ } ) ;
211
+
212
+ result
188
213
}
189
214
190
215
struct PreInliningPartitioning < ' tcx > {
0 commit comments