Skip to content

Commit a62a464

Browse files
committed
Sort MonoItems by span instead of definition index.
1 parent 55f4641 commit a62a464

File tree

1 file changed

+23
-26
lines changed
  • compiler/rustc_middle/src/mir

1 file changed

+23
-26
lines changed

compiler/rustc_middle/src/mir/mono.rs

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use rustc_data_structures::fx::FxHashMap;
77
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
88
use rustc_hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
99
use rustc_hir::ItemId;
10-
use rustc_index::vec::Idx;
1110
use rustc_query_system::ich::StableHashingContext;
1211
use rustc_session::config::OptLevel;
1312
use rustc_span::source_map::Span;
@@ -348,35 +347,33 @@ impl<'tcx> CodegenUnit<'tcx> {
348347
tcx: TyCtxt<'tcx>,
349348
) -> Vec<(MonoItem<'tcx>, (Linkage, Visibility))> {
350349
// The codegen tests rely on items being process in the same order as
351-
// they appear in the file, so for local items, we sort by node_id first
350+
// they appear in the file, so for local items, we sort by span first
352351
#[derive(PartialEq, Eq, PartialOrd, Ord)]
353-
pub struct ItemSortKey<'tcx>(Option<usize>, SymbolName<'tcx>);
352+
pub struct ItemSortKey<'tcx>(Option<Span>, SymbolName<'tcx>);
354353

355354
fn item_sort_key<'tcx>(tcx: TyCtxt<'tcx>, item: MonoItem<'tcx>) -> ItemSortKey<'tcx> {
356-
ItemSortKey(
357-
match item {
358-
MonoItem::Fn(ref instance) => {
359-
match instance.def {
360-
// We only want to take HirIds of user-defined
361-
// instances into account. The others don't matter for
362-
// the codegen tests and can even make item order
363-
// unstable.
364-
InstanceDef::Item(def) => def.did.as_local().map(Idx::index),
365-
InstanceDef::VTableShim(..)
366-
| InstanceDef::ReifyShim(..)
367-
| InstanceDef::Intrinsic(..)
368-
| InstanceDef::FnPtrShim(..)
369-
| InstanceDef::Virtual(..)
370-
| InstanceDef::ClosureOnceShim { .. }
371-
| InstanceDef::DropGlue(..)
372-
| InstanceDef::CloneShim(..) => None,
373-
}
355+
let span = match item {
356+
MonoItem::Fn(ref instance) => {
357+
match instance.def {
358+
// We only want to take HirIds of user-defined
359+
// instances into account. The others don't matter for
360+
// the codegen tests and can even make item order
361+
// unstable.
362+
InstanceDef::Item(def) => tcx.hir().span_if_local(def.did),
363+
InstanceDef::VTableShim(..)
364+
| InstanceDef::ReifyShim(..)
365+
| InstanceDef::Intrinsic(..)
366+
| InstanceDef::FnPtrShim(..)
367+
| InstanceDef::Virtual(..)
368+
| InstanceDef::ClosureOnceShim { .. }
369+
| InstanceDef::DropGlue(..)
370+
| InstanceDef::CloneShim(..) => None,
374371
}
375-
MonoItem::Static(def_id) => def_id.as_local().map(Idx::index),
376-
MonoItem::GlobalAsm(item_id) => Some(item_id.def_id.index()),
377-
},
378-
item.symbol_name(tcx),
379-
)
372+
}
373+
MonoItem::Static(def_id) => tcx.hir().span_if_local(def_id),
374+
MonoItem::GlobalAsm(item_id) => Some(tcx.def_span(item_id.def_id)),
375+
};
376+
ItemSortKey(span, item.symbol_name(tcx))
380377
}
381378

382379
let mut items: Vec<_> = self.items().iter().map(|(&i, &l)| (i, l)).collect();

0 commit comments

Comments
 (0)