|
1 | 1 | use std::borrow::Cow;
|
| 2 | +use std::cmp::Ordering; |
2 | 3 | use std::fmt;
|
3 | 4 | use std::hash::Hash;
|
4 | 5 |
|
@@ -527,44 +528,52 @@ impl<'tcx> CodegenUnit<'tcx> {
|
527 | 528 | ) -> Vec<(MonoItem<'tcx>, MonoItemData)> {
|
528 | 529 | // The codegen tests rely on items being process in the same order as
|
529 | 530 | // they appear in the file, so for local items, we sort by node_id first
|
530 |
| - #[derive(PartialEq, Eq, PartialOrd, Ord)] |
531 |
| - struct ItemSortKey<'tcx>(Option<usize>, SymbolName<'tcx>); |
532 |
| - |
533 |
| - fn item_sort_key<'tcx>(tcx: TyCtxt<'tcx>, item: MonoItem<'tcx>) -> ItemSortKey<'tcx> { |
534 |
| - ItemSortKey( |
535 |
| - match item { |
536 |
| - MonoItem::Fn(ref instance) => { |
537 |
| - match instance.def { |
538 |
| - // We only want to take HirIds of user-defined |
539 |
| - // instances into account. The others don't matter for |
540 |
| - // the codegen tests and can even make item order |
541 |
| - // unstable. |
542 |
| - InstanceKind::Item(def) => def.as_local().map(Idx::index), |
543 |
| - InstanceKind::VTableShim(..) |
544 |
| - | InstanceKind::ReifyShim(..) |
545 |
| - | InstanceKind::Intrinsic(..) |
546 |
| - | InstanceKind::FnPtrShim(..) |
547 |
| - | InstanceKind::Virtual(..) |
548 |
| - | InstanceKind::ClosureOnceShim { .. } |
549 |
| - | InstanceKind::ConstructCoroutineInClosureShim { .. } |
550 |
| - | InstanceKind::DropGlue(..) |
551 |
| - | InstanceKind::CloneShim(..) |
552 |
| - | InstanceKind::ThreadLocalShim(..) |
553 |
| - | InstanceKind::FnPtrAddrShim(..) |
554 |
| - | InstanceKind::AsyncDropGlue(..) |
555 |
| - | InstanceKind::FutureDropPollShim(..) |
556 |
| - | InstanceKind::AsyncDropGlueCtorShim(..) => None, |
557 |
| - } |
| 531 | + // #[derive(PartialEq, Eq, PartialOrd, Ord)] |
| 532 | + // struct ItemSortKey<'tcx>(Option<usize>, SymbolName<'tcx>); |
| 533 | + // |
| 534 | + // fn item_sort_key<'tcx>(tcx: TyCtxt<'tcx>, item: MonoItem<'tcx>) -> ItemSortKey<'tcx> { |
| 535 | + // ItemSortKey( |
| 536 | + // , |
| 537 | + // item.symbol_name(tcx), |
| 538 | + // ) |
| 539 | + // } |
| 540 | + |
| 541 | + fn foo<'tcx>(item: &MonoItem<'tcx>) -> Option<usize> { |
| 542 | + match item { |
| 543 | + MonoItem::Fn(instance) => { |
| 544 | + match instance.def { |
| 545 | + // We only want to take HirIds of user-defined |
| 546 | + // instances into account. The others don't matter for |
| 547 | + // the codegen tests and can even make item order |
| 548 | + // unstable. |
| 549 | + InstanceKind::Item(def) => def.as_local().map(Idx::index), |
| 550 | + InstanceKind::VTableShim(..) |
| 551 | + | InstanceKind::ReifyShim(..) |
| 552 | + | InstanceKind::Intrinsic(..) |
| 553 | + | InstanceKind::FnPtrShim(..) |
| 554 | + | InstanceKind::Virtual(..) |
| 555 | + | InstanceKind::ClosureOnceShim { .. } |
| 556 | + | InstanceKind::ConstructCoroutineInClosureShim { .. } |
| 557 | + | InstanceKind::DropGlue(..) |
| 558 | + | InstanceKind::CloneShim(..) |
| 559 | + | InstanceKind::ThreadLocalShim(..) |
| 560 | + | InstanceKind::FnPtrAddrShim(..) |
| 561 | + | InstanceKind::AsyncDropGlue(..) |
| 562 | + | InstanceKind::FutureDropPollShim(..) |
| 563 | + | InstanceKind::AsyncDropGlueCtorShim(..) => None, |
558 | 564 | }
|
559 |
| - MonoItem::Static(def_id) => def_id.as_local().map(Idx::index), |
560 |
| - MonoItem::GlobalAsm(item_id) => Some(item_id.owner_id.def_id.index()), |
561 |
| - }, |
562 |
| - item.symbol_name(tcx), |
563 |
| - ) |
| 565 | + } |
| 566 | + MonoItem::Static(def_id) => def_id.as_local().map(Idx::index), |
| 567 | + MonoItem::GlobalAsm(item_id) => Some(item_id.owner_id.def_id.index()), |
| 568 | + } |
564 | 569 | }
|
565 | 570 |
|
566 | 571 | let mut items: Vec<_> = self.items().iter().map(|(&i, &data)| (i, data)).collect();
|
567 |
| - items.sort_by_cached_key(|&(i, _)| item_sort_key(tcx, i)); |
| 572 | + items.sort_by(|(i1, _), (i2, _)| match foo(i1).cmp(&foo(i2)) { |
| 573 | + Ordering::Less => Ordering::Less, |
| 574 | + Ordering::Greater => Ordering::Greater, |
| 575 | + Ordering::Equal => i1.symbol_name(tcx).cmp(&i2.symbol_name(tcx)), |
| 576 | + }); |
568 | 577 | items
|
569 | 578 | }
|
570 | 579 |
|
|
0 commit comments