Skip to content

Commit 2e20b9f

Browse files
Auto merge of #144576 - ywxt:parallel-reproducibility, r=<try>
Fix parallel rustc not being reproducible due to unstable sorts of items
2 parents d242a8b + 030a674 commit 2e20b9f

21 files changed

+1553
-1582
lines changed

compiler/rustc_middle/src/mir/mono.rs

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use rustc_data_structures::unord::UnordMap;
1212
use rustc_hashes::Hash128;
1313
use rustc_hir::ItemId;
1414
use rustc_hir::def_id::{CrateNum, DefId, DefIdSet, LOCAL_CRATE};
15-
use rustc_index::Idx;
1615
use rustc_macros::{HashStable, TyDecodable, TyEncodable};
1716
use rustc_query_system::ich::StableHashingContext;
1817
use rustc_session::config::OptLevel;
@@ -526,39 +525,18 @@ impl<'tcx> CodegenUnit<'tcx> {
526525
tcx: TyCtxt<'tcx>,
527526
) -> Vec<(MonoItem<'tcx>, MonoItemData)> {
528527
// The codegen tests rely on items being process in the same order as
529-
// they appear in the file, so for local items, we sort by node_id first
528+
// they appear in the file, so for local items, we sort by span and def_path first
530529
#[derive(PartialEq, Eq, PartialOrd, Ord)]
531-
struct ItemSortKey<'tcx>(Option<usize>, SymbolName<'tcx>);
530+
struct ItemSortKey<'tcx>(Option<Span>, Option<String>, SymbolName<'tcx>);
532531

533532
fn item_sort_key<'tcx>(tcx: TyCtxt<'tcx>, item: MonoItem<'tcx>) -> ItemSortKey<'tcx> {
534533
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-
}
558-
}
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-
},
534+
// For codegen tests purposes, we don't care about non-local items' order,
535+
// so we just sort non-local items by symbol names.
536+
item.local_span(tcx),
537+
item.def_id()
538+
.as_local()
539+
.map(|_| tcx.def_path(item.def_id()).to_string_no_crate_verbose()),
562540
item.symbol_name(tcx),
563541
)
564542
}

tests/assembly-llvm/asm/aarch64-modifiers.rs

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -55,35 +55,17 @@ check!(vreg vreg "add {0}.4s, {0}.4s, {0}.4s");
5555
// CHECK: //NO_APP
5656
check!(vreg_b vreg "ldr {:b}, [x0]");
5757

58-
// CHECK-LABEL: vreg_h:
59-
// CHECK: //APP
60-
// CHECK: ldr h0, [x0]
61-
// CHECK: //NO_APP
62-
check!(vreg_h vreg "ldr {:h}, [x0]");
63-
64-
// CHECK-LABEL: vreg_s:
65-
// CHECK: //APP
66-
// CHECK: ldr s0, [x0]
67-
// CHECK: //NO_APP
68-
check!(vreg_s vreg "ldr {:s}, [x0]");
69-
7058
// CHECK-LABEL: vreg_d:
7159
// CHECK: //APP
7260
// CHECK: ldr d0, [x0]
7361
// CHECK: //NO_APP
7462
check!(vreg_d vreg "ldr {:d}, [x0]");
7563

76-
// CHECK-LABEL: vreg_q:
77-
// CHECK: //APP
78-
// CHECK: ldr q0, [x0]
79-
// CHECK: //NO_APP
80-
check!(vreg_q vreg "ldr {:q}, [x0]");
81-
82-
// CHECK-LABEL: vreg_v:
64+
// CHECK-LABEL: vreg_h:
8365
// CHECK: //APP
84-
// CHECK: add v0.4s, v0.4s, v0.4s
66+
// CHECK: ldr h0, [x0]
8567
// CHECK: //NO_APP
86-
check!(vreg_v vreg "add {0:v}.4s, {0:v}.4s, {0:v}.4s");
68+
check!(vreg_h vreg "ldr {:h}, [x0]");
8769

8870
// CHECK-LABEL: vreg_low16:
8971
// CHECK: //APP
@@ -97,32 +79,50 @@ check!(vreg_low16 vreg_low16 "add {0}.4s, {0}.4s, {0}.4s");
9779
// CHECK: //NO_APP
9880
check!(vreg_low16_b vreg_low16 "ldr {:b}, [x0]");
9981

82+
// CHECK-LABEL: vreg_low16_d:
83+
// CHECK: //APP
84+
// CHECK: ldr d0, [x0]
85+
// CHECK: //NO_APP
86+
check!(vreg_low16_d vreg_low16 "ldr {:d}, [x0]");
87+
10088
// CHECK-LABEL: vreg_low16_h:
10189
// CHECK: //APP
10290
// CHECK: ldr h0, [x0]
10391
// CHECK: //NO_APP
10492
check!(vreg_low16_h vreg_low16 "ldr {:h}, [x0]");
10593

94+
// CHECK-LABEL: vreg_low16_q:
95+
// CHECK: //APP
96+
// CHECK: ldr q0, [x0]
97+
// CHECK: //NO_APP
98+
check!(vreg_low16_q vreg_low16 "ldr {:q}, [x0]");
99+
106100
// CHECK-LABEL: vreg_low16_s:
107101
// CHECK: //APP
108102
// CHECK: ldr s0, [x0]
109103
// CHECK: //NO_APP
110104
check!(vreg_low16_s vreg_low16 "ldr {:s}, [x0]");
111105

112-
// CHECK-LABEL: vreg_low16_d:
106+
// CHECK-LABEL: vreg_low16_v:
113107
// CHECK: //APP
114-
// CHECK: ldr d0, [x0]
108+
// CHECK: add v0.4s, v0.4s, v0.4s
115109
// CHECK: //NO_APP
116-
check!(vreg_low16_d vreg_low16 "ldr {:d}, [x0]");
110+
check!(vreg_low16_v vreg_low16 "add {0:v}.4s, {0:v}.4s, {0:v}.4s");
117111

118-
// CHECK-LABEL: vreg_low16_q:
112+
// CHECK-LABEL: vreg_q:
119113
// CHECK: //APP
120114
// CHECK: ldr q0, [x0]
121115
// CHECK: //NO_APP
122-
check!(vreg_low16_q vreg_low16 "ldr {:q}, [x0]");
116+
check!(vreg_q vreg "ldr {:q}, [x0]");
123117

124-
// CHECK-LABEL: vreg_low16_v:
118+
// CHECK-LABEL: vreg_s:
119+
// CHECK: //APP
120+
// CHECK: ldr s0, [x0]
121+
// CHECK: //NO_APP
122+
check!(vreg_s vreg "ldr {:s}, [x0]");
123+
124+
// CHECK-LABEL: vreg_v:
125125
// CHECK: //APP
126126
// CHECK: add v0.4s, v0.4s, v0.4s
127127
// CHECK: //NO_APP
128-
check!(vreg_low16_v vreg_low16 "add {0:v}.4s, {0:v}.4s, {0:v}.4s");
128+
check!(vreg_v vreg "add {0:v}.4s, {0:v}.4s, {0:v}.4s");

0 commit comments

Comments
 (0)