Skip to content

Commit 8bf70d1

Browse files
Auto merge of #144886 - ywxt:parallel-reproducibility, r=<try>
Fix parallel rustc not being reproducible due to unstable sorts of items
2 parents e1b9081 + 7f73e8b commit 8bf70d1

File tree

1 file changed

+13
-6
lines changed
  • compiler/rustc_middle/src/mir

1 file changed

+13
-6
lines changed

compiler/rustc_middle/src/mir/mono.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use rustc_hashes::Hash128;
1212
use rustc_hir::ItemId;
1313
use rustc_hir::attrs::InlineAttr;
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,9 +525,9 @@ 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 first
530529
#[derive(PartialEq, Eq, PartialOrd, Ord)]
531-
struct ItemSortKey<'tcx>(Option<usize>, SymbolName<'tcx>);
530+
struct ItemSortKey<'tcx>(Option<Span>, SymbolName<'tcx>);
532531

533532
fn item_sort_key<'tcx>(tcx: TyCtxt<'tcx>, item: MonoItem<'tcx>) -> ItemSortKey<'tcx> {
534533
ItemSortKey(
@@ -539,7 +538,10 @@ impl<'tcx> CodegenUnit<'tcx> {
539538
// instances into account. The others don't matter for
540539
// the codegen tests and can even make item order
541540
// unstable.
542-
InstanceKind::Item(def) => def.as_local().map(Idx::index),
541+
InstanceKind::Item(def) => def
542+
.as_local()
543+
.map(|_| tcx.def_span(def).find_ancestor_not_from_macro())
544+
.flatten(),
543545
InstanceKind::VTableShim(..)
544546
| InstanceKind::ReifyShim(..)
545547
| InstanceKind::Intrinsic(..)
@@ -556,8 +558,13 @@ impl<'tcx> CodegenUnit<'tcx> {
556558
| InstanceKind::AsyncDropGlueCtorShim(..) => None,
557559
}
558560
}
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+
MonoItem::Static(def_id) => def_id
562+
.as_local()
563+
.map(|_| tcx.def_span(def_id).find_ancestor_not_from_macro())
564+
.flatten(),
565+
MonoItem::GlobalAsm(item_id) => {
566+
tcx.def_span(item_id.owner_id.def_id).find_ancestor_not_from_macro()
567+
}
561568
},
562569
item.symbol_name(tcx),
563570
)

0 commit comments

Comments
 (0)