From 138cfab9f7af26a7871fc0c3cff0888b1a9a7c3a Mon Sep 17 00:00:00 2001 From: Michael Woerister Date: Thu, 21 Dec 2023 11:10:30 +0100 Subject: [PATCH] Make iteration order of crate_inherent_impls query result stable. --- compiler/rustc_metadata/src/rmeta/encoder.rs | 12 +++--------- compiler/rustc_middle/src/ty/mod.rs | 3 ++- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index d761439f4ef..1d12b853b53 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -2,10 +2,8 @@ use crate::errors::{FailCreateFileEncoder, FailWriteFile}; use crate::rmeta::*; use rustc_ast::Attribute; -use rustc_data_structures::fingerprint::Fingerprint; use rustc_data_structures::fx::FxIndexSet; use rustc_data_structures::memmap::{Mmap, MmapMut}; -use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_data_structures::sync::{join, par_for_each_in, Lrc}; use rustc_data_structures::temp_dir::MaybeTempDir; use rustc_hir as hir; @@ -2034,14 +2032,10 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { fn encode_incoherent_impls(&mut self) -> LazyArray { empty_proc_macro!(self); let tcx = self.tcx; - let mut all_impls: Vec<_> = tcx.crate_inherent_impls(()).incoherent_impls.iter().collect(); - tcx.with_stable_hashing_context(|mut ctx| { - all_impls.sort_by_cached_key(|&(&simp, _)| { - let mut hasher = StableHasher::new(); - simp.hash_stable(&mut ctx, &mut hasher); - hasher.finish::() - }) + let all_impls = tcx.with_stable_hashing_context(|hcx| { + tcx.crate_inherent_impls(()).incoherent_impls.to_sorted(&hcx, true) }); + let all_impls: Vec<_> = all_impls .into_iter() .map(|(&simp, impls)| { diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index 757d3337afc..1ba9d56df7c 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -38,6 +38,7 @@ use rustc_data_structures::intern::Interned; use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_data_structures::steal::Steal; use rustc_data_structures::tagged_ptr::CopyTaggedPtr; +use rustc_data_structures::unord::UnordMap; use rustc_errors::{DiagnosticBuilder, ErrorGuaranteed, StashKey}; use rustc_hir as hir; use rustc_hir::def::{CtorKind, CtorOf, DefKind, DocLinkResMap, LifetimeRes, Res}; @@ -2658,7 +2659,7 @@ pub fn provide(providers: &mut Providers) { #[derive(Clone, Debug, Default, HashStable)] pub struct CrateInherentImpls { pub inherent_impls: LocalDefIdMap>, - pub incoherent_impls: FxHashMap>, + pub incoherent_impls: UnordMap>, } #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, TyEncodable, HashStable)]