Skip to content

Commit 138cfab

Browse files
Make iteration order of crate_inherent_impls query result stable.
1 parent db132c5 commit 138cfab

File tree

2 files changed

+5
-10
lines changed

2 files changed

+5
-10
lines changed

compiler/rustc_metadata/src/rmeta/encoder.rs

+3-9
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@ use crate::errors::{FailCreateFileEncoder, FailWriteFile};
22
use crate::rmeta::*;
33

44
use rustc_ast::Attribute;
5-
use rustc_data_structures::fingerprint::Fingerprint;
65
use rustc_data_structures::fx::FxIndexSet;
76
use rustc_data_structures::memmap::{Mmap, MmapMut};
8-
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
97
use rustc_data_structures::sync::{join, par_for_each_in, Lrc};
108
use rustc_data_structures::temp_dir::MaybeTempDir;
119
use rustc_hir as hir;
@@ -2034,14 +2032,10 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
20342032
fn encode_incoherent_impls(&mut self) -> LazyArray<IncoherentImpls> {
20352033
empty_proc_macro!(self);
20362034
let tcx = self.tcx;
2037-
let mut all_impls: Vec<_> = tcx.crate_inherent_impls(()).incoherent_impls.iter().collect();
2038-
tcx.with_stable_hashing_context(|mut ctx| {
2039-
all_impls.sort_by_cached_key(|&(&simp, _)| {
2040-
let mut hasher = StableHasher::new();
2041-
simp.hash_stable(&mut ctx, &mut hasher);
2042-
hasher.finish::<Fingerprint>()
2043-
})
2035+
let all_impls = tcx.with_stable_hashing_context(|hcx| {
2036+
tcx.crate_inherent_impls(()).incoherent_impls.to_sorted(&hcx, true)
20442037
});
2038+
20452039
let all_impls: Vec<_> = all_impls
20462040
.into_iter()
20472041
.map(|(&simp, impls)| {

compiler/rustc_middle/src/ty/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ use rustc_data_structures::intern::Interned;
3838
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
3939
use rustc_data_structures::steal::Steal;
4040
use rustc_data_structures::tagged_ptr::CopyTaggedPtr;
41+
use rustc_data_structures::unord::UnordMap;
4142
use rustc_errors::{DiagnosticBuilder, ErrorGuaranteed, StashKey};
4243
use rustc_hir as hir;
4344
use rustc_hir::def::{CtorKind, CtorOf, DefKind, DocLinkResMap, LifetimeRes, Res};
@@ -2658,7 +2659,7 @@ pub fn provide(providers: &mut Providers) {
26582659
#[derive(Clone, Debug, Default, HashStable)]
26592660
pub struct CrateInherentImpls {
26602661
pub inherent_impls: LocalDefIdMap<Vec<DefId>>,
2661-
pub incoherent_impls: FxHashMap<SimplifiedType, Vec<LocalDefId>>,
2662+
pub incoherent_impls: UnordMap<SimplifiedType, Vec<LocalDefId>>,
26622663
}
26632664

26642665
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, TyEncodable, HashStable)]

0 commit comments

Comments
 (0)