Skip to content

Commit f5481f1

Browse files
committed
Sort mono items by symbol name
1 parent 350d0ef commit f5481f1

File tree

1 file changed

+9
-3
lines changed
  • compiler/rustc_middle/src/mir

1 file changed

+9
-3
lines changed

compiler/rustc_middle/src/mir/mono.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -566,10 +566,16 @@ impl<'tcx> CodegenUnit<'tcx> {
566566

567567
let mut items: Vec<_> = self.items().iter().map(|(&i, &data)| (i, data)).collect();
568568
if !tcx.sess.opts.unstable_opts.codegen_source_order {
569-
// It's already deterministic, so we can just use it.
570-
return items;
569+
// The input item list is already produced in a deterministic matter, so we can just
570+
// use it.
571+
// However, it seems that actually moving related things (probably mainly different
572+
// monomorphizations of the same item) close to one another is actually beneficial for
573+
// perf.
574+
// Sorting by symbol name should not incur any non-determinism.
575+
items.sort_by_cached_key(|&(i, _)| i.symbol_name(tcx));
576+
} else {
577+
items.sort_by_cached_key(|&(i, _)| item_sort_key(tcx, i));
571578
}
572-
items.sort_by_cached_key(|&(i, _)| item_sort_key(tcx, i));
573579
items
574580
}
575581

0 commit comments

Comments
 (0)