Skip to content

Fix parallel rustc not being reproducible due to unstable sorts of items #144886

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions compiler/rustc_middle/src/mir/mono.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use rustc_hashes::Hash128;
use rustc_hir::ItemId;
use rustc_hir::attrs::InlineAttr;
use rustc_hir::def_id::{CrateNum, DefId, DefIdSet, LOCAL_CRATE};
use rustc_index::Idx;
use rustc_macros::{HashStable, TyDecodable, TyEncodable};
use rustc_query_system::ich::StableHashingContext;
use rustc_session::config::OptLevel;
Expand Down Expand Up @@ -526,9 +525,9 @@ impl<'tcx> CodegenUnit<'tcx> {
tcx: TyCtxt<'tcx>,
) -> Vec<(MonoItem<'tcx>, MonoItemData)> {
// The codegen tests rely on items being process in the same order as
// they appear in the file, so for local items, we sort by node_id first
// they appear in the file, so for local items, we sort by span first
#[derive(PartialEq, Eq, PartialOrd, Ord)]
struct ItemSortKey<'tcx>(Option<usize>, SymbolName<'tcx>);
struct ItemSortKey<'tcx>(Option<Span>, SymbolName<'tcx>);

fn item_sort_key<'tcx>(tcx: TyCtxt<'tcx>, item: MonoItem<'tcx>) -> ItemSortKey<'tcx> {
ItemSortKey(
Expand All @@ -539,7 +538,10 @@ impl<'tcx> CodegenUnit<'tcx> {
// instances into account. The others don't matter for
// the codegen tests and can even make item order
// unstable.
InstanceKind::Item(def) => def.as_local().map(Idx::index),
InstanceKind::Item(def) => def
.as_local()
.map(|_| tcx.def_span(def).find_ancestor_not_from_macro())
.flatten(),
InstanceKind::VTableShim(..)
| InstanceKind::ReifyShim(..)
| InstanceKind::Intrinsic(..)
Expand All @@ -556,8 +558,13 @@ impl<'tcx> CodegenUnit<'tcx> {
| InstanceKind::AsyncDropGlueCtorShim(..) => None,
}
}
MonoItem::Static(def_id) => def_id.as_local().map(Idx::index),
MonoItem::GlobalAsm(item_id) => Some(item_id.owner_id.def_id.index()),
MonoItem::Static(def_id) => def_id
.as_local()
.map(|_| tcx.def_span(def_id).find_ancestor_not_from_macro())
.flatten(),
MonoItem::GlobalAsm(item_id) => {
tcx.def_span(item_id.owner_id.def_id).find_ancestor_not_from_macro()
}
},
item.symbol_name(tcx),
)
Expand Down
Loading