@@ -124,15 +124,11 @@ use rustc::hir::map::DefPathData;
124124use rustc:: session:: config:: NUMBERED_CODEGEN_UNIT_MARKER ;
125125use rustc:: ty:: TyCtxt ;
126126use rustc:: ty:: item_path:: characteristic_def_id_of_type;
127+ use symbol_map:: SymbolMap ;
127128use syntax:: parse:: token:: { self , InternedString } ;
128129use trans_item:: TransItem ;
129130use util:: nodemap:: { FnvHashMap , FnvHashSet , NodeSet } ;
130131
131- pub struct CodegenUnit < ' tcx > {
132- pub name : InternedString ,
133- pub items : FnvHashMap < TransItem < ' tcx > , llvm:: Linkage > ,
134- }
135-
136132pub enum PartitioningStrategy {
137133 /// Generate one codegen unit per source-level module.
138134 PerModule ,
@@ -141,6 +137,29 @@ pub enum PartitioningStrategy {
141137 FixedUnitCount ( usize )
142138}
143139
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+
144163// Anything we can't find a proper codegen unit for goes into this.
145164const FALLBACK_CODEGEN_UNIT : & ' static str = "__rustc_fallback_codegen_unit" ;
146165
@@ -184,7 +203,13 @@ pub fn partition<'a, 'tcx, I>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
184203
185204 debug_dump ( tcx, "POST INLINING:" , post_inlining. 0 . iter ( ) ) ;
186205
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
188213}
189214
190215struct PreInliningPartitioning < ' tcx > {
0 commit comments