From 7b53e4ec120e5254db8eef9cc569cf3b5c5f69b6 Mon Sep 17 00:00:00 2001 From: Matyas Susits Date: Fri, 16 Oct 2026 13:01:30 +0200 Subject: [PATCH 1/4] fix until rustc-middle --- compiler/rustc_ast/src/format.rs | 6 +-- compiler/rustc_ast/src/visit.rs | 2 +- compiler/rustc_data_structures/src/fx.rs | 7 +++ compiler/rustc_data_structures/src/unord.rs | 2 +- compiler/rustc_hir_id/src/lib.rs | 2 +- compiler/rustc_middle/src/arena.rs | 9 ++-- compiler/rustc_middle/src/dep_graph/graph.rs | 4 +- .../rustc_middle/src/query/on_disk_cache.rs | 47 ++++++++-------- .../src/traits/specialization_graph.rs | 6 +-- compiler/rustc_middle/src/ty/closure.rs | 3 +- compiler/rustc_middle/src/ty/generics.rs | 10 ++-- .../rustc_middle/src/ty/typeck_results.rs | 33 ++++++------ compiler/rustc_serialize/src/serialize.rs | 53 +------------------ 13 files changed, 66 insertions(+), 118 deletions(-) diff --git a/compiler/rustc_ast/src/format.rs b/compiler/rustc_ast/src/format.rs index c423bce35f78d..dbf370788a1ab 100644 --- a/compiler/rustc_ast/src/format.rs +++ b/compiler/rustc_ast/src/format.rs @@ -1,4 +1,4 @@ -use rustc_data_structures::fx::FxHashMap; +use rustc_data_structures::fx::FxIndexMap; use rustc_macros::{Decodable, Encodable, Walkable}; use rustc_span::{Ident, Span, Symbol}; @@ -78,14 +78,14 @@ pub struct FormatArguments { arguments: Vec, num_unnamed_args: usize, num_explicit_args: usize, - names: FxHashMap, + names: FxIndexMap, } impl FormatArguments { pub fn new() -> Self { Self { arguments: Vec::new(), - names: FxHashMap::default(), + names: FxIndexMap::default(), num_unnamed_args: 0, num_explicit_args: 0, } diff --git a/compiler/rustc_ast/src/visit.rs b/compiler/rustc_ast/src/visit.rs index e4813b9588409..310db941f740c 100644 --- a/compiler/rustc_ast/src/visit.rs +++ b/compiler/rustc_ast/src/visit.rs @@ -446,7 +446,7 @@ macro_rules! common_visitor_and_walkers { crate::token::LitKind, crate::tokenstream::LazyAttrTokenStream, crate::tokenstream::TokenStream, - rustc_data_structures::fx::FxHashMap, + rustc_data_structures::fx::FxIndexMap, rustc_span::ByteSymbol, rustc_span::ErrorGuaranteed, std::borrow::Cow<'_, str>, diff --git a/compiler/rustc_data_structures/src/fx.rs b/compiler/rustc_data_structures/src/fx.rs index 76b2c428ec84d..752c3ed797c1f 100644 --- a/compiler/rustc_data_structures/src/fx.rs +++ b/compiler/rustc_data_structures/src/fx.rs @@ -16,6 +16,13 @@ macro_rules! define_id_collections { pub type $set_name = $crate::unord::UnordSet<$key>; pub type $entry_name<'a, T> = $crate::fx::StdEntry<'a, $key, T>; }; + ($map_name:ident, $set_name:ident, $entry_name:ident, $key:ty, $index_map_name:ident, $index_set_name:ident) => { + pub type $map_name = $crate::unord::UnordMap<$key, T>; + pub type $set_name = $crate::unord::UnordSet<$key>; + pub type $entry_name<'a, T> = $crate::fx::StdEntry<'a, $key, T>; + pub type $index_map_name = $crate::fx::FxIndexMap<$key, T>; + pub type $index_set_name = $crate::fx::FxIndexSet<$key>; + }; } #[macro_export] diff --git a/compiler/rustc_data_structures/src/unord.rs b/compiler/rustc_data_structures/src/unord.rs index 42dbe37db7951..aee1a15be5585 100644 --- a/compiler/rustc_data_structures/src/unord.rs +++ b/compiler/rustc_data_structures/src/unord.rs @@ -449,7 +449,7 @@ impl StableHash for UnordSet { /// /// See [MCP 533](https://github.com/rust-lang/compiler-team/issues/533) /// for more information. -#[derive(Debug, Eq, PartialEq, Clone, Encodable_NoContext, Decodable_NoContext)] +#[derive(Debug, Eq, PartialEq, Clone)] pub struct UnordMap { inner: FxHashMap, } diff --git a/compiler/rustc_hir_id/src/lib.rs b/compiler/rustc_hir_id/src/lib.rs index 0e01600f9cb3d..115baf9d64950 100644 --- a/compiler/rustc_hir_id/src/lib.rs +++ b/compiler/rustc_hir_id/src/lib.rs @@ -154,7 +154,7 @@ impl From for HirId { } rustc_data_structures::define_stable_id_collections!(HirIdMap, HirIdSet, HirIdMapEntry, HirId); -rustc_data_structures::define_id_collections!( +rustc_data_structures::define_stable_id_collections!( ItemLocalMap, ItemLocalSet, ItemLocalMapEntry, diff --git a/compiler/rustc_middle/src/arena.rs b/compiler/rustc_middle/src/arena.rs index d2e6c4bbe2466..be0b99f65a298 100644 --- a/compiler/rustc_middle/src/arena.rs +++ b/compiler/rustc_middle/src/arena.rs @@ -108,7 +108,6 @@ rustc_arena::declare_arena! { dyn_compatibility_violations: rustc_middle::traits::DynCompatibilityViolation, codegen_unit: rustc_middle::mono::CodegenUnit<'tcx>, attribute: rustc_attr_ir::Attribute, - name_set: rustc_data_structures::unord::UnordSet, autodiff_item: rustc_attr_ir::AutoDiffItem, ordered_name_set: rustc_data_structures::fx::FxIndexSet, stable_order_of_exportable_impls: @@ -118,14 +117,14 @@ rustc_arena::declare_arena! { // since we need to allocate this type on both the `rustc_hir` arena // (during lowering) and the `rustc_middle` arena (for decoding MIR) asm_template: rustc_ast::InlineAsmTemplatePiece, - used_trait_imports: rustc_data_structures::unord::UnordSet, + used_trait_imports: rustc_data_structures::fx::FxIndexSet, is_late_bound_map: rustc_data_structures::fx::FxIndexSet, impl_source: rustc_middle::traits::ImplSource<'tcx, ()>, dep_kind_vtable: rustc_middle::dep_graph::DepKindVTable<'tcx>, trait_impl_trait_tys: - rustc_data_structures::unord::UnordMap< + rustc_data_structures::fx::FxIndexMap< rustc_hir::def_id::DefId, rustc_middle::ty::EarlyBinder<'tcx, Ty<'tcx>> >, @@ -205,8 +204,8 @@ impl_ref_decodable_into_arena! { rustc_ast::InlineAsmTemplatePiece, rustc_ast::tokenstream::TokenStream, rustc_attr_ir::Attribute, - rustc_data_structures::unord::UnordMap>>, - rustc_data_structures::unord::UnordSet, + rustc_data_structures::fx::FxIndexMap>>, + rustc_data_structures::fx::FxIndexSet, rustc_index::IndexVec>, rustc_middle::middle::deduced_param_attrs::DeducedParamAttrs, rustc_middle::mir::Body<'tcx>, diff --git a/compiler/rustc_middle/src/dep_graph/graph.rs b/compiler/rustc_middle/src/dep_graph/graph.rs index dcb5775f20595..b8865549004d4 100644 --- a/compiler/rustc_middle/src/dep_graph/graph.rs +++ b/compiler/rustc_middle/src/dep_graph/graph.rs @@ -6,7 +6,7 @@ use std::sync::Arc; use std::sync::atomic::{AtomicU32, Ordering}; use rustc_data_structures::fingerprint::{Fingerprint, PackedFingerprint}; -use rustc_data_structures::fx::FxHashSet; +use rustc_data_structures::fx::{FxHashSet, FxIndexMap}; use rustc_data_structures::profiling::QueryInvocationId; use rustc_data_structures::sharded::ShardedHashMap; use rustc_data_structures::stable_hash::{StableHash, StableHasher}; @@ -1140,7 +1140,7 @@ pub struct WorkProduct { /// /// By convention, file extensions are currently used as identifiers, i.e. the key "o" maps to /// the object file's path, and "dwo" to the dwarf object file's path. - pub saved_files: UnordMap, + pub saved_files: FxIndexMap, } impl WorkProduct { diff --git a/compiler/rustc_middle/src/query/on_disk_cache.rs b/compiler/rustc_middle/src/query/on_disk_cache.rs index 7383ad23273be..81b94cd285f3a 100644 --- a/compiler/rustc_middle/src/query/on_disk_cache.rs +++ b/compiler/rustc_middle/src/query/on_disk_cache.rs @@ -4,11 +4,10 @@ use std::rc::Rc; use std::sync::Arc; use std::{fmt, mem}; -use rustc_data_structures::fx::{FxHashMap, FxIndexSet}; +use rustc_data_structures::fx::{FxHashMap, FxIndexMap, FxIndexSet}; use rustc_data_structures::memmap::Mmap; use rustc_data_structures::sync::{HashMapExt, Lock, RwLock}; -use rustc_data_structures::unhash::UnhashMap; -use rustc_data_structures::unord::{UnordMap, UnordSet}; +use rustc_data_structures::unhash::UnindexMap; use rustc_hir::def_id::{CrateNum, DefId, DefIndex, LOCAL_CRATE, LocalDefId, StableCrateId}; use rustc_hir::definitions::DefPathHash; use rustc_index::IndexVec; @@ -56,7 +55,7 @@ pub struct OnDiskCache { // The complete cache data in serialized form. serialized_data: RwLock>, - file_index_to_stable_id: FxHashMap, + file_index_to_stable_id: FxIndexMap, // Caches that are populated lazily during decoding. file_index_to_file: Lock>>, @@ -76,7 +75,7 @@ pub struct OnDiskCache { // to represent the fact that we are storing *encoded* ids. When we decode // a `SyntaxContext`, a new id will be allocated from the global `HygieneData`, // which will almost certainly be different than the serialized id. - syntax_contexts: FxHashMap, + syntax_contexts: FxIndexMap, // A map from the `DefPathHash` of an `ExpnId` to the position // of their associated `ExpnData`. Ideally, we would store a `DefId`, // but we need to decode this before we've constructed a `TyCtxt` (which @@ -86,20 +85,20 @@ pub struct OnDiskCache { // `ExpnData` (e.g `ExpnData.krate` may not be `LOCAL_CRATE`). Alternatively, // we could look up the `ExpnData` from the metadata of foreign crates, // but it seemed easier to have `OnDiskCache` be independent of the `CStore`. - expn_data: UnhashMap, + expn_data: UnindexMap, // Additional information used when decoding hygiene data. hygiene_context: HygieneDecodeContext, // Maps `ExpnHash`es to their raw value from the *previous* // compilation session. This is used as an initial 'guess' when // we try to map an `ExpnHash` to its value in the current // compilation session. - foreign_expn_data: UnhashMap, + foreign_expn_data: UnindexMap, } // This type is used only for serialization and deserialization. #[derive(Encodable, Decodable)] struct Footer { - file_index_to_stable_id: FxHashMap, + file_index_to_stable_id: FxIndexMap, query_values_index: Vec<(SerializedDepNodeIndex, AbsoluteBytePos)>, side_effects_index: Vec<(SerializedDepNodeIndex, AbsoluteBytePos)>, // The location of all allocations. @@ -107,10 +106,10 @@ struct Footer { // without measurable overhead. This permits larger const allocations without ICEing. interpret_alloc_index: Vec, // See `OnDiskCache.syntax_contexts` - syntax_contexts: FxHashMap, + syntax_contexts: FxIndexMap, // See `OnDiskCache.expn_data` - expn_data: UnhashMap, - foreign_expn_data: UnhashMap, + expn_data: UnindexMap, + foreign_expn_data: UnindexMap, } #[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, Encodable, Decodable)] @@ -189,9 +188,9 @@ impl OnDiskCache { query_values_index: Default::default(), side_effects_index: Default::default(), alloc_decoding_state: AllocDecodingState::new(Vec::new()), - syntax_contexts: FxHashMap::default(), - expn_data: UnhashMap::default(), - foreign_expn_data: UnhashMap::default(), + syntax_contexts: Default::default(), + expn_data: Default::default(), + foreign_expn_data: Default::default(), hygiene_context: Default::default(), } } @@ -213,7 +212,7 @@ impl OnDiskCache { let mut file_to_file_index = FxHashMap::with_capacity_and_hasher(files.len(), Default::default()); let mut file_index_to_stable_id = - FxHashMap::with_capacity_and_hasher(files.len(), Default::default()); + FxIndexMap::with_capacity_and_hasher(files.len(), Default::default()); for (index, file) in files.iter().enumerate() { let index = SourceFileIndex(index as u32); @@ -273,9 +272,9 @@ impl OnDiskCache { interpret_alloc_index }; - let mut syntax_contexts = FxHashMap::default(); - let mut expn_data = UnhashMap::default(); - let mut foreign_expn_data = UnhashMap::default(); + let mut syntax_contexts = FxIndexMap::default(); + let mut expn_data = UnindexMap::default(); + let mut foreign_expn_data = UnindexMap::default(); // Encode all hygiene data (`SyntaxContextData` and `ExpnData`) from the current // session. @@ -400,11 +399,11 @@ pub struct CacheDecoder<'a, 'tcx> { tcx: TyCtxt<'tcx>, opaque: MemDecoder<'a>, file_index_to_file: &'a Lock>>, - file_index_to_stable_id: &'a FxHashMap, + file_index_to_stable_id: &'a FxIndexMap, alloc_decoding_session: AllocDecodingSession<'a>, - syntax_contexts: &'a FxHashMap, - expn_data: &'a UnhashMap, - foreign_expn_data: &'a UnhashMap, + syntax_contexts: &'a FxIndexMap, + expn_data: &'a UnindexMap, + foreign_expn_data: &'a UnindexMap, hygiene_context: &'a HygieneDecodeContext, source_span_cache: SourceSpanCache, } @@ -726,8 +725,8 @@ macro_rules! impl_decodable_via_ref_decodable_for_foreign_types { impl_decodable_via_ref_decodable_for_foreign_types! { // tidy-alphabetical-start &'tcx IndexVec>, - &'tcx UnordMap>>, - &'tcx UnordSet, + &'tcx FxIndexMap>>, + &'tcx FxIndexSet, &'tcx [( rustc_middle::middle::exported_symbols::ExportedSymbol<'tcx>, rustc_middle::middle::exported_symbols::SymbolExportInfo, diff --git a/compiler/rustc_middle/src/traits/specialization_graph.rs b/compiler/rustc_middle/src/traits/specialization_graph.rs index b13af2705c736..1d4ddd406364b 100644 --- a/compiler/rustc_middle/src/traits/specialization_graph.rs +++ b/compiler/rustc_middle/src/traits/specialization_graph.rs @@ -1,7 +1,7 @@ use rustc_attr_ir::find_attr; use rustc_data_structures::fx::FxIndexMap; use rustc_errors::ErrorGuaranteed; -use rustc_hir::def_id::{DefId, DefIdMap}; +use rustc_hir::def_id::DefId; use rustc_macros::{StableHash, TyDecodable, TyEncodable}; use crate::diagnostics::StrictCoherenceNeedsNegativeCoherence; @@ -27,10 +27,10 @@ use crate::ty::{self, TyCtxt, TypeVisitableExt}; pub struct Graph { /// All impls have a parent; the "root" impls have as their parent the `def_id` /// of the trait. - pub parent: DefIdMap, + pub parent: FxIndexMap, /// The "root" impls are found by looking up the trait's def_id. - pub children: DefIdMap, + pub children: FxIndexMap, } impl Graph { diff --git a/compiler/rustc_middle/src/ty/closure.rs b/compiler/rustc_middle/src/ty/closure.rs index 4b410b3259bff..3cb74f8ce5a74 100644 --- a/compiler/rustc_middle/src/ty/closure.rs +++ b/compiler/rustc_middle/src/ty/closure.rs @@ -6,7 +6,6 @@ use rustc_hir as hir; use rustc_hir::HirId; use rustc_hir::def_id::LocalDefId; use rustc_macros::{StableHash, TyDecodable, TyEncodable, TypeFoldable, TypeVisitable}; -use rustc_span::def_id::LocalDefIdMap; use rustc_span::{Ident, Span, Symbol, bug}; use super::TyCtxt; @@ -77,7 +76,7 @@ impl PartialOrd for UpvarCapture { /// Given the closure DefId this map provides a map of root variables to minimum /// set of `CapturedPlace`s that need to be tracked to support all captures of that closure. -pub type MinCaptureInformationMap<'tcx> = LocalDefIdMap>; +pub type MinCaptureInformationMap<'tcx> = FxIndexMap>; /// Part of `MinCaptureInformationMap`; Maps a root variable to the list of `CapturedPlace`. /// Used to track the minimum set of `Place`s that need to be captured to support all diff --git a/compiler/rustc_middle/src/ty/generics.rs b/compiler/rustc_middle/src/ty/generics.rs index edddd7043077c..792d7aa076dd3 100644 --- a/compiler/rustc_middle/src/ty/generics.rs +++ b/compiler/rustc_middle/src/ty/generics.rs @@ -1,7 +1,7 @@ use std::ops::ControlFlow; use rustc_ast as ast; -use rustc_data_structures::fx::FxHashMap; +use rustc_data_structures::fx::FxIndexMap; use rustc_hir::def_id::DefId; use rustc_macros::{StableHash, TyDecodable, TyEncodable}; use rustc_span::{Span, Symbol, bug, kw}; @@ -142,7 +142,7 @@ pub struct Generics { /// Reverse map to the `index` field of each `GenericParamDef`. #[stable_hash(ignore)] - pub param_def_id_to_index: FxHashMap, + pub param_def_id_to_index: FxIndexMap, pub has_self: bool, pub has_arg_pos_consts: bool, @@ -151,15 +151,11 @@ pub struct Generics { impl std::fmt::Debug for Generics { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> { - // ironically, we get this warning because of what we're trying to fix. - #[expect(rustc::potential_query_instability)] - let mut stabilized_hashmap = self.param_def_id_to_index.iter().collect::>(); - stabilized_hashmap.sort_by_key(|(_, v)| **v); f.debug_struct("Generics") .field("parent", &self.parent) .field("parent_count", &self.parent_count) .field("own_params", &self.own_params) - .field("param_def_id_to_index", &stabilized_hashmap) + .field("param_def_id_to_index", &self.param_def_id_to_index) .field("has_self", &self.has_self) .field("has_late_bound_regions", &self.has_late_bound_regions) .finish() diff --git a/compiler/rustc_middle/src/ty/typeck_results.rs b/compiler/rustc_middle/src/ty/typeck_results.rs index 509ff98741731..4fd944b798206 100644 --- a/compiler/rustc_middle/src/ty/typeck_results.rs +++ b/compiler/rustc_middle/src/ty/typeck_results.rs @@ -1,13 +1,13 @@ -use std::collections::hash_map::Entry; use std::hash::Hash; use std::iter; use rustc_abi::{FieldIdx, VariantIdx}; use rustc_data_structures::fx::{FxIndexMap, FxIndexSet}; -use rustc_data_structures::unord::{ExtendUnord, UnordItems, UnordSet}; +use rustc_data_structures::indexmap::map::Entry; +use rustc_data_structures::stable_hash::StableCompare; use rustc_errors::ErrorGuaranteed; use rustc_hir::def::{DefKind, Res}; -use rustc_hir::def_id::{DefId, LocalDefId, LocalDefIdMap}; +use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::{ self as hir, BindingMode, ByRef, HirId, ItemLocalId, ItemLocalMap, ItemLocalSet, Mutability, OwnerId, @@ -69,7 +69,7 @@ pub struct TypeckResults<'tcx> { /// Stores the canonicalized types provided by the user. See also /// `AscribeUserType` statement in MIR. - pub user_provided_sigs: LocalDefIdMap>, + pub user_provided_sigs: FxIndexMap>, adjustments: ItemLocalMap>>, @@ -160,7 +160,7 @@ pub struct TypeckResults<'tcx> { /// Set of trait imports actually used in the method resolution. /// This is used for warning unused imports. - pub used_trait_imports: UnordSet, + pub used_trait_imports: FxIndexSet, /// If any errors occurred while type-checking this body, /// this field will be set to `Some(ErrorGuaranteed)`. @@ -198,7 +198,7 @@ pub struct TypeckResults<'tcx> { /// we never capture `t`. This becomes an issue when we build MIR as we require /// information on `t` in order to create place `t.0` and `t.1`. We can solve this /// issue by fake reading `t`. - pub closure_fake_reads: LocalDefIdMap, FakeReadCause, HirId)>>, + pub closure_fake_reads: FxIndexMap, FakeReadCause, HirId)>>, /// Stores the predicates that apply on coroutine witness types. /// formatting modified file tests/ui/coroutine/retain-resume-ref.rs @@ -216,7 +216,7 @@ pub struct TypeckResults<'tcx> { /// Contains the data for evaluating the effect of feature `capture_disjoint_fields` /// on closure size. - pub closure_size_eval: LocalDefIdMap>, + pub closure_size_eval: FxIndexMap>, /// Stores the types involved in calls to `transmute` intrinsic. These are meant to be checked /// outside of typeck and borrowck to avoid cycles with opaque types and coroutine layout @@ -700,15 +700,14 @@ impl<'a, V> LocalTableInContext<'a, V> { self.data.get(&id.local_id) } - pub fn items( - &self, - ) -> UnordItems<(hir::ItemLocalId, &'a V), impl Iterator> - { - self.data.items().map(|(id, value)| (*id, value)) + pub fn items(&self) -> impl Iterator { + self.data.iter().map(|(id, value)| (*id, value)) } pub fn items_in_stable_order(&self) -> Vec<(ItemLocalId, &'a V)> { - self.data.items().map(|(&k, v)| (k, v)).into_sorted_stable_ord_by_key(|(k, _)| k) + let mut v: Vec<_> = self.data.iter().map(|(&k, v)| (k, v)).collect(); + v.sort_by(|(k1, _), (k2, _)| k1.stable_cmp(k2)); + v } } @@ -750,11 +749,11 @@ impl<'a, V> LocalTableInContextMut<'a, V> { pub fn remove(&mut self, id: HirId) -> Option { validate_hir_id_for_typeck_results(self.hir_owner, id); - self.data.remove(&id.local_id) + self.data.swap_remove(&id.local_id) } - pub fn extend(&mut self, items: UnordItems<(HirId, V), impl Iterator>) { - self.data.extend_unord(items.map(|(id, value)| { + pub fn extend(&mut self, items: impl Iterator) { + self.data.extend(items.map(|(id, value)| { validate_hir_id_for_typeck_results(self.hir_owner, id); (id.local_id, value) })) @@ -800,7 +799,7 @@ impl<'a> LocalSetInContextMut<'a> { pub fn remove(&mut self, id: hir::HirId) -> bool { validate_hir_id_for_typeck_results(self.hir_owner, id); - self.data.remove(&id.local_id) + self.data.swap_remove(&id.local_id) } } diff --git a/compiler/rustc_serialize/src/serialize.rs b/compiler/rustc_serialize/src/serialize.rs index 32a301a28ae8e..20e1359c49ca9 100644 --- a/compiler/rustc_serialize/src/serialize.rs +++ b/compiler/rustc_serialize/src/serialize.rs @@ -2,7 +2,7 @@ use std::borrow::Cow; use std::cell::{Cell, RefCell}; -use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet, VecDeque}; +use std::collections::{BTreeMap, BTreeSet, VecDeque}; use std::hash::{BuildHasher, Hash}; use std::marker::{PhantomData, PointeeSized}; use std::num::{NonZero, ZeroablePrimitive}; @@ -606,57 +606,6 @@ where } } -impl Encodable for HashMap -where - K: Encodable + Eq, - V: Encodable, - S: BuildHasher, -{ - fn encode(&self, e: &mut E) { - e.emit_usize(self.len()); - for (key, val) in self { - key.encode(e); - val.encode(e); - } - } -} - -impl Decodable for HashMap -where - K: Decodable + Hash + Eq, - V: Decodable, - S: BuildHasher + Default, -{ - fn decode(d: &mut D) -> HashMap { - let len = d.read_usize(); - (0..len).map(|_| (Decodable::decode(d), Decodable::decode(d))).collect() - } -} - -impl Encodable for HashSet -where - T: Encodable + Eq, - S: BuildHasher, -{ - fn encode(&self, s: &mut E) { - s.emit_usize(self.len()); - for e in self { - e.encode(s); - } - } -} - -impl Decodable for HashSet -where - T: Decodable + Hash + Eq, - S: BuildHasher + Default, -{ - fn decode(d: &mut D) -> HashSet { - let len = d.read_usize(); - (0..len).map(|_| Decodable::decode(d)).collect() - } -} - impl Encodable for indexmap::IndexMap where K: Encodable + Hash + Eq, From 11d8efb22a6f15cf0304a0919edf24cbd34be63f Mon Sep 17 00:00:00 2001 From: Matyas Susits Date: Fri, 16 Oct 2026 14:13:12 +0200 Subject: [PATCH 2/4] progress --- compiler/rustc_codegen_ssa/src/back/link.rs | 7 ++----- .../src/back/symbol_export.rs | 16 +++++++--------- compiler/rustc_codegen_ssa/src/base.rs | 5 ++--- compiler/rustc_codegen_ssa/src/lib.rs | 12 ++++++------ .../src/check/compare_impl_item/refine.rs | 2 +- compiler/rustc_incremental/src/persist/load.rs | 2 +- compiler/rustc_incremental/src/persist/save.rs | 2 +- .../src/persist/work_product.rs | 4 ++-- compiler/rustc_metadata/src/rmeta/encoder.rs | 7 +++---- compiler/rustc_metadata/src/rmeta/mod.rs | 6 +++--- .../rustc_metadata/src/rmeta/parameterized.rs | 6 +++--- compiler/rustc_middle/src/queries.rs | 18 +++++++++--------- compiler/rustc_passes/src/reachable.rs | 5 +++-- compiler/rustc_passes/src/stability.rs | 17 ++++++++--------- compiler/rustc_ty_utils/src/assoc.rs | 3 ++- 15 files changed, 53 insertions(+), 59 deletions(-) diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs index a7540e294ec37..55141e0bf6e4b 100644 --- a/compiler/rustc_codegen_ssa/src/back/link.rs +++ b/compiler/rustc_codegen_ssa/src/back/link.rs @@ -976,11 +976,8 @@ fn link_dwarf_object( } // Input rlibs contain .o/.dwo files from dependencies. - let input_rlibs = crate_info - .used_crate_source - .items() - .filter_map(|(_, csource)| csource.rlib.as_ref()) - .into_sorted_stable_ord(); + let input_rlibs = + crate_info.used_crate_source.iter().filter_map(|(_, csource)| csource.rlib.as_ref()); for input_rlib in input_rlibs { debug!(?input_rlib); diff --git a/compiler/rustc_codegen_ssa/src/back/symbol_export.rs b/compiler/rustc_codegen_ssa/src/back/symbol_export.rs index bda08821c9f22..d66aabab6a63e 100644 --- a/compiler/rustc_codegen_ssa/src/back/symbol_export.rs +++ b/compiler/rustc_codegen_ssa/src/back/symbol_export.rs @@ -1,11 +1,9 @@ -use std::collections::hash_map::Entry::*; - use object::pe; use rustc_abi::{CanonAbi, X86Call}; use rustc_ast::expand::allocator::{AllocatorKind, NO_ALLOC_SHIM_IS_UNSTABLE, global_fn_name}; use rustc_crate_store::CrateDepKind; -use rustc_data_structures::fx::FxHashSet; -use rustc_data_structures::unord::UnordMap; +use rustc_data_structures::fx::{FxHashSet, FxIndexMap}; +use rustc_data_structures::indexmap::map::Entry::*; use rustc_hir as hir; use rustc_hir::def::DefKind; use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LOCAL_CRATE, LocalDefId}; @@ -66,7 +64,7 @@ pub fn reachable_non_generics_helper(tcx: TyCtxt<'_>) -> DefIdMap = tcx .reachable_set(()) - .items() + .iter() .filter_map(|&def_id| { // We want to ignore some FFI functions that are not exposed from // this crate. Reachable FFI functions can be lumped into two @@ -150,7 +148,7 @@ pub fn reachable_non_generics_helper(tcx: TyCtxt<'_>) -> DefIdMap( fn upstream_monomorphizations_provider( tcx: TyCtxt<'_>, (): (), -) -> DefIdMap, CrateNum>> { +) -> DefIdMap, CrateNum>> { let cnums = tcx.crates(()); - let mut instances: DefIdMap> = Default::default(); + let mut instances: DefIdMap> = Default::default(); let drop_glue_fn_def_id = tcx.lang_items().drop_glue_fn(); let async_drop_in_place_fn_def_id = tcx.lang_items().async_drop_in_place_fn(); @@ -560,7 +558,7 @@ fn upstream_monomorphizations_provider( fn upstream_monomorphizations_for_provider( tcx: TyCtxt<'_>, def_id: DefId, -) -> Option<&UnordMap, CrateNum>> { +) -> Option<&FxIndexMap, CrateNum>> { assert!(!def_id.is_local()); tcx.upstream_monomorphizations(()).get(&def_id) } diff --git a/compiler/rustc_codegen_ssa/src/base.rs b/compiler/rustc_codegen_ssa/src/base.rs index 14e07a9c89395..e540dd3222b70 100644 --- a/compiler/rustc_codegen_ssa/src/base.rs +++ b/compiler/rustc_codegen_ssa/src/base.rs @@ -15,7 +15,6 @@ use rustc_attr_ir::{DebuggerVisualizerType, EiiDecl, EiiImpl, OptimizeAttr, find use rustc_data_structures::fx::{FxHashMap, FxIndexMap, FxIndexSet}; use rustc_data_structures::profiling::{get_resident_set_size, print_time_passes_entry}; use rustc_data_structures::sync::{IntoDynSyncSend, par_map}; -use rustc_data_structures::unord::UnordMap; use rustc_hir as hir; use rustc_hir::def_id::{CrateNum, DefId, LOCAL_CRATE}; use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrs; @@ -1073,9 +1072,9 @@ impl CrateInfo { is_no_builtins: Default::default(), native_libraries: Default::default(), used_libraries: tcx.native_libraries(LOCAL_CRATE).iter().map(Into::into).collect(), - crate_name: UnordMap::with_capacity(n_crates), + crate_name: FxIndexMap::with_capacity_and_hasher(n_crates, Default::default()), used_crates, - used_crate_source: UnordMap::with_capacity(n_crates), + used_crate_source: FxIndexMap::with_capacity_and_hasher(n_crates, Default::default()), dependency_formats, eii_linkage, windows_subsystem, diff --git a/compiler/rustc_codegen_ssa/src/lib.rs b/compiler/rustc_codegen_ssa/src/lib.rs index 1ac9564db0149..0141247310401 100644 --- a/compiler/rustc_codegen_ssa/src/lib.rs +++ b/compiler/rustc_codegen_ssa/src/lib.rs @@ -20,8 +20,8 @@ use std::sync::Arc; use rustc_abi::Size; use rustc_attr_ir::{CfgEntry, WindowsSubsystemKind}; use rustc_crate_store::{self as cstore, CrateSource}; -use rustc_data_structures::fx::{FxHashSet, FxIndexMap}; -use rustc_data_structures::unord::{UnordMap, UnordSet}; +use rustc_data_structures::fx::{FxIndexMap, FxIndexSet}; +use rustc_data_structures::unord::UnordSet; use rustc_hir::CRATE_HIR_ID; use rustc_hir::def_id::CrateNum; use rustc_lint_defs::builtin::{LINKER_INFO, LINKER_MESSAGES}; @@ -267,16 +267,16 @@ pub struct CrateInfo { pub target_cpu: String, pub target_features: Vec, pub crate_types: Vec, - pub exported_symbols: UnordMap>, + pub exported_symbols: FxIndexMap>, pub linked_symbols: FxIndexMap>, pub local_crate_name: Symbol, pub compiler_builtins: Option, pub profiler_runtime: Option, - pub is_no_builtins: FxHashSet, + pub is_no_builtins: FxIndexSet, pub native_libraries: FxIndexMap>, - pub crate_name: UnordMap, + pub crate_name: FxIndexMap, pub used_libraries: Vec, - pub used_crate_source: UnordMap>, + pub used_crate_source: FxIndexMap>, pub used_crates: Vec, pub dependency_formats: Arc, /// EII implementations used by the link-time duplicate check, so `-Zno-link` can serialize the data needed by a diff --git a/compiler/rustc_hir_analysis/src/check/compare_impl_item/refine.rs b/compiler/rustc_hir_analysis/src/check/compare_impl_item/refine.rs index aa170a364b5b8..7ced007599c09 100644 --- a/compiler/rustc_hir_analysis/src/check/compare_impl_item/refine.rs +++ b/compiler/rustc_hir_analysis/src/check/compare_impl_item/refine.rs @@ -67,7 +67,7 @@ pub(crate) fn check_refining_return_position_impl_trait_in_trait<'tcx>( return; }; - if hidden_tys.items().any(|(_, &ty)| ty.skip_binder().references_error()) { + if hidden_tys.iter().any(|(_, &ty)| ty.skip_binder().references_error()) { return; } diff --git a/compiler/rustc_incremental/src/persist/load.rs b/compiler/rustc_incremental/src/persist/load.rs index 76e0bf92c6f0f..4c70a818b42c9 100644 --- a/compiler/rustc_incremental/src/persist/load.rs +++ b/compiler/rustc_incremental/src/persist/load.rs @@ -62,7 +62,7 @@ fn load_dep_graph(sess: &Session, incr_comp_session: &IncrCompSession) -> LoadRe Decodable::decode(&mut work_product_decoder); for swp in work_products { - let all_files_exist = swp.work_product.saved_files.items().all(|(_, path)| { + let all_files_exist = swp.work_product.saved_files.iter().all(|(_, path)| { let exists = in_old_incr_comp_dir_sess(incr_comp_session, path).unwrap().exists(); if !exists && sess.opts.unstable_opts.incremental_info { eprintln!("incremental: could not find file for work product: {path}",); diff --git a/compiler/rustc_incremental/src/persist/save.rs b/compiler/rustc_incremental/src/persist/save.rs index 46f47d6c8623c..7f001a1957113 100644 --- a/compiler/rustc_incremental/src/persist/save.rs +++ b/compiler/rustc_incremental/src/persist/save.rs @@ -116,7 +116,7 @@ pub fn save_work_product_index( debug_assert!({ new_work_products.items().all(|(_, wp)| { wp.saved_files - .items() + .iter() .all(|(_, path)| in_incr_comp_dir_sess(incr_comp_session.unwrap(), path).exists()) }) }); diff --git a/compiler/rustc_incremental/src/persist/work_product.rs b/compiler/rustc_incremental/src/persist/work_product.rs index 0aaa9aa8e96c2..7b6acbfcb6029 100644 --- a/compiler/rustc_incremental/src/persist/work_product.rs +++ b/compiler/rustc_incremental/src/persist/work_product.rs @@ -4,7 +4,7 @@ use std::path::Path; -use rustc_data_structures::unord::UnordMap; +use rustc_data_structures::fx::FxIndexMap; use rustc_fs_util::link_or_copy; use rustc_middle::dep_graph::{WorkProduct, WorkProductId}; use rustc_session::{IncrCompSession, Session}; @@ -26,7 +26,7 @@ pub fn copy_cgu_workproduct_to_incr_comp_cache_dir( debug!(?cgu_name, ?files); assert!(sess.opts.incremental.is_some()); - let mut saved_files = UnordMap::default(); + let mut saved_files = FxIndexMap::default(); for (ext, path) in files { let file_name = format!("{cgu_name}.{ext}"); let path_in_incr_dir = in_incr_comp_dir_sess(incr_comp_session, &file_name); diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index f9f4c52b79d3b..f6f907bff6dc7 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -18,7 +18,7 @@ use rustc_data_structures::sync::{par_for_each_in, par_join}; use rustc_data_structures::temp_dir::MaybeTempDir; use rustc_data_structures::thousands::usize_with_underscores; use rustc_hir as hir; -use rustc_hir::def_id::{CRATE_DEF_ID, LOCAL_CRATE, LocalDefId, LocalDefIdSet}; +use rustc_hir::def_id::{CRATE_DEF_ID, LOCAL_CRATE, LocalDefId}; use rustc_hir::definitions::DefPathData; use rustc_hir_pretty::id_to_string; use rustc_index::IndexVec; @@ -1180,7 +1180,7 @@ fn should_encode_stability(def_kind: DefKind) -> bool { /// ``` fn should_encode_mir( tcx: TyCtxt<'_>, - reachable_set: &LocalDefIdSet, + reachable_set: &FxIndexSet, def_id: LocalDefId, ) -> (bool, bool) { match tcx.def_kind(def_id) { @@ -2230,8 +2230,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { empty_proc_macro!(self); let tcx = self.tcx; let implications = tcx.stability_implications(LOCAL_CRATE); - let sorted = implications.to_sorted_stable_ord(); - self.lazy_array(sorted.into_iter().map(|(k, v)| (*k, *v))) + self.lazy_array(implications.into_iter().map(|(k, v)| (*k, *v))) } fn encode_canonical_symbols(&mut self) -> LazyArray<(Symbol, LocalDefId)> { diff --git a/compiler/rustc_metadata/src/rmeta/mod.rs b/compiler/rustc_metadata/src/rmeta/mod.rs index eef513382b57e..6fcf70d2671e2 100644 --- a/compiler/rustc_metadata/src/rmeta/mod.rs +++ b/compiler/rustc_metadata/src/rmeta/mod.rs @@ -16,7 +16,7 @@ use rustc_attr_ir::{ }; use rustc_crate_store::{CrateDepKind, ForeignModule, LinkagePreference, NativeLib}; use rustc_data_structures::fingerprint::Fingerprint; -use rustc_data_structures::fx::FxHashMap; +use rustc_data_structures::fx::{FxHashMap, FxIndexMap}; use rustc_data_structures::svh::Svh; use rustc_hir as hir; use rustc_hir::PreciseCapturingArgKind; @@ -509,14 +509,14 @@ define_tables! { assoc_container: Table>, macro_definition: Table>, deduced_param_attrs: Table>, - collect_return_position_impl_trait_in_trait_tys: Table>>>>, + collect_return_position_impl_trait_in_trait_tys: Table>>>>, doc_link_resolutions: Table>, doc_link_traits_in_scope: Table>, assumed_wf_types_for_rpitit: Table, Span)>>, opaque_ty_origin: Table>>, anon_const_kind: Table>, const_of_item: Table>>>>, - associated_types_for_impl_traits_in_trait_or_impl: Table>>>, + associated_types_for_impl_traits_in_trait_or_impl: Table>>>, live_args_for_alias_from_outlives_bounds: Table>>, args_known_to_outlive_alias_params: Table)>>>, mut_restriction: Table>, diff --git a/compiler/rustc_metadata/src/rmeta/parameterized.rs b/compiler/rustc_metadata/src/rmeta/parameterized.rs index 24177e4f83de8..ad673fcf81ea8 100644 --- a/compiler/rustc_metadata/src/rmeta/parameterized.rs +++ b/compiler/rustc_metadata/src/rmeta/parameterized.rs @@ -1,6 +1,6 @@ use std::hash::Hash; -use rustc_data_structures::unord::UnordMap; +use rustc_data_structures::fx::FxIndexMap; use rustc_index::{Idx, IndexVec}; use rustc_middle::ty::{Binder, EarlyBinder, GenericArg, Region}; use rustc_span::Symbol; @@ -27,8 +27,8 @@ impl ParameterizedOverTcx for IndexVe type Value<'tcx> = IndexVec>; } -impl ParameterizedOverTcx for UnordMap { - type Value<'tcx> = UnordMap>; +impl ParameterizedOverTcx for FxIndexMap { + type Value<'tcx> = FxIndexMap>; } impl ParameterizedOverTcx for Binder<'static, T> { diff --git a/compiler/rustc_middle/src/queries.rs b/compiler/rustc_middle/src/queries.rs index d0429df43d1dd..2dea87f2728d2 100644 --- a/compiler/rustc_middle/src/queries.rs +++ b/compiler/rustc_middle/src/queries.rs @@ -67,7 +67,7 @@ use rustc_data_structures::unord::{UnordMap, UnordSet}; use rustc_errors::{ErrorGuaranteed, catch_fatal_errors}; use rustc_hir as hir; use rustc_hir::def::DefKind; -use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LocalDefId, LocalDefIdSet, LocalModId}; +use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LocalDefId, LocalModId}; use rustc_hir::{ItemLocalId, PreciseCapturingArgKind}; use rustc_index::{IndexSlice, IndexVec}; use rustc_lint_defs::{LintId, StableLintExpectationId}; @@ -379,7 +379,7 @@ rustc_queries! { } query collect_return_position_impl_trait_in_trait_tys(key: DefId) - -> Result<&'tcx DefIdMap>>, ErrorGuaranteed> + -> Result<&'tcx FxIndexMap>>, ErrorGuaranteed> { desc { "comparing an impl and trait method signature, inferring any hidden `impl Trait` types in the process" } cache_on_disk @@ -1115,7 +1115,7 @@ rustc_queries! { /// Given the `item_def_id` of a trait or impl, return a mapping from associated fn def id /// to its associated type items that correspond to the RPITITs in its signature. - query associated_types_for_impl_traits_in_trait_or_impl(item_def_id: DefId) -> &'tcx DefIdMap> { + query associated_types_for_impl_traits_in_trait_or_impl(item_def_id: DefId) -> &'tcx FxIndexMap> { arena_cache desc { "synthesizing RPITIT items for the opaque types for methods in `{}`", tcx.def_path_str(item_def_id) } separate_provide_extern @@ -1254,7 +1254,7 @@ rustc_queries! { cache_on_disk } - query used_trait_imports(key: LocalDefId) -> &'tcx UnordSet { + query used_trait_imports(key: LocalDefId) -> &'tcx FxIndexSet { desc { "finding used_trait_imports `{}`", tcx.def_path_str(key) } cache_on_disk } @@ -1316,7 +1316,7 @@ rustc_queries! { /// Return the set of (transitive) callees that may result in a recursive call to `key`, /// if we were able to walk all callees. - query mir_callgraph_cyclic(key: LocalDefId) -> Option<&'tcx UnordSet> { + query mir_callgraph_cyclic(key: LocalDefId) -> Option<&'tcx FxIndexSet> { desc { "computing (transitive) callees of `{}` that may recurse", tcx.def_path_str(key), @@ -1431,7 +1431,7 @@ rustc_queries! { } } - query reachable_set(_: ()) -> &'tcx LocalDefIdSet { + query reachable_set(_: ()) -> &'tcx FxIndexSet { arena_cache desc { "reachability" } cache_on_disk @@ -1966,7 +1966,7 @@ rustc_queries! { /// crate. Instead use the narrower `upstream_monomorphizations_for`, /// `upstream_drop_glue_for`, `upstream_async_drop_glue_for`, or, /// even better, `Instance::upstream_monomorphization()`. - query upstream_monomorphizations(_: ()) -> &'tcx DefIdMap, CrateNum>> { + query upstream_monomorphizations(_: ()) -> &'tcx DefIdMap, CrateNum>> { arena_cache desc { "collecting available upstream monomorphizations" } } @@ -1979,7 +1979,7 @@ rustc_queries! { /// You likely want to call `Instance::upstream_monomorphization()` /// instead of invoking this query directly. query upstream_monomorphizations_for(def_id: DefId) - -> Option<&'tcx UnordMap, CrateNum>> + -> Option<&'tcx FxIndexMap, CrateNum>> { desc { "collecting available upstream monomorphizations for `{}`", @@ -2282,7 +2282,7 @@ rustc_queries! { /// to know that the feature implies another feature. If it were reversed, and the `#[stable]` /// attribute had an `implies` meta item, then a map would be necessary when avoiding a "use of /// unstable feature" error for a feature that was implied. - query stability_implications(_: CrateNum) -> &'tcx UnordMap { + query stability_implications(_: CrateNum) -> &'tcx FxIndexMap { arena_cache desc { "calculating the implications between `#[unstable]` features defined in a crate" } separate_provide_extern diff --git a/compiler/rustc_passes/src/reachable.rs b/compiler/rustc_passes/src/reachable.rs index 1bd2ca7792e7e..2c9e9108b5f91 100644 --- a/compiler/rustc_passes/src/reachable.rs +++ b/compiler/rustc_passes/src/reachable.rs @@ -23,6 +23,7 @@ //! considering here as at that point, everything is monomorphic. use hir::def_id::LocalDefIdSet; +use rustc_data_structures::fx::FxIndexSet; use rustc_hir as hir; use rustc_hir::Node; use rustc_hir::def::{DefKind, Res}; @@ -52,7 +53,7 @@ struct ReachableContext<'tcx> { tcx: TyCtxt<'tcx>, maybe_typeck_results: Option<&'tcx ty::TypeckResults<'tcx>>, // The set of items which must be exported in the linkage sense. - reachable_symbols: LocalDefIdSet, + reachable_symbols: FxIndexSet, // A worklist of item IDs. Each item ID in this worklist will be inlined // and will be scanned for further references. // FIXME(eddyb) benchmark if this would be faster as a `VecDeque`. @@ -458,7 +459,7 @@ fn has_custom_linkage(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool { } /// See module-level doc comment above. -fn reachable_set(tcx: TyCtxt<'_>, (): ()) -> LocalDefIdSet { +fn reachable_set(tcx: TyCtxt<'_>, (): ()) -> FxIndexSet { let effective_visibilities = &tcx.effective_visibilities(()); let any_library = tcx.crate_types().iter().any(|ty| { diff --git a/compiler/rustc_passes/src/stability.rs b/compiler/rustc_passes/src/stability.rs index 162914c95c0e5..62cac3b892896 100644 --- a/compiler/rustc_passes/src/stability.rs +++ b/compiler/rustc_passes/src/stability.rs @@ -9,7 +9,7 @@ use rustc_attr_ir::{ StabilityLevel, StableSince, UnstableReason, VERSION_PLACEHOLDER, find_attr, }; use rustc_data_structures::fx::FxIndexMap; -use rustc_data_structures::unord::{ExtendUnord, UnordMap, UnordSet}; +use rustc_data_structures::unord::UnordSet; use rustc_feature::{EnabledLangFeature, EnabledLibFeature, UNSTABLE_LANG_FEATURES}; use rustc_hir::def::{DefKind, Res}; use rustc_hir::def_id::{CRATE_DEF_ID, LOCAL_CRATE, LocalDefId, LocalModId}; @@ -265,8 +265,8 @@ fn lookup_const_stability(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option, LocalCrate: LocalCrate) -> UnordMap { - let mut implications = UnordMap::default(); +fn stability_implications(tcx: TyCtxt<'_>, LocalCrate: LocalCrate) -> FxIndexMap { + let mut implications = FxIndexMap::default(); let mut register_implication = |def_id| { if let Some(stability) = tcx.lookup_stability(def_id) @@ -1215,9 +1215,9 @@ pub fn check_unused_or_stable_features(tcx: TyCtxt<'_>) { fn check_features<'tcx>( tcx: TyCtxt<'tcx>, remaining_lib_features: &mut FxIndexMap, - remaining_implications: &mut UnordMap, + remaining_implications: &mut FxIndexMap, defined_features: &LibFeatures, - all_implications: &UnordMap, + all_implications: &FxIndexMap, ) { for (feature, stability) in defined_features.to_sorted_vec() { if let FeatureStability::AcceptedSince(since) = stability @@ -1240,7 +1240,7 @@ pub fn check_unused_or_stable_features(tcx: TyCtxt<'_>) { // the attribute that establishes this relationship. `implied_by` is guaranteed to be a // feature defined in the local crate because `remaining_implications` is only the // implications from this crate. - remaining_implications.remove(&feature); + remaining_implications.swap_remove(&feature); if let FeatureStability::Unstable { old_name: Some(alias) } = stability && let Some(span) = remaining_lib_features.swap_remove(&alias) @@ -1268,8 +1268,7 @@ pub fn check_unused_or_stable_features(tcx: TyCtxt<'_>) { // `remaining_lib_features`. let mut all_implications = remaining_implications.clone(); for &cnum in crates { - all_implications - .extend_unord(tcx.stability_implications(cnum).items().map(|(k, v)| (*k, *v))); + all_implications.extend(tcx.stability_implications(cnum).iter().map(|(k, v)| (*k, *v))); } check_features( @@ -1336,7 +1335,7 @@ pub fn check_unused_or_stable_features(tcx: TyCtxt<'_>) { } } - for (&implied_by, &feature) in remaining_implications.to_sorted_stable_ord() { + for (implied_by, feature) in remaining_implications { let local_defined_features = tcx.lib_features(LOCAL_CRATE); let span = local_defined_features .stability diff --git a/compiler/rustc_ty_utils/src/assoc.rs b/compiler/rustc_ty_utils/src/assoc.rs index bff2f1e6804af..009357ff1e220 100644 --- a/compiler/rustc_ty_utils/src/assoc.rs +++ b/compiler/rustc_ty_utils/src/assoc.rs @@ -1,3 +1,4 @@ +use rustc_data_structures::fx::FxIndexMap; use rustc_hir::def::DefKind; use rustc_hir::def_id::{DefId, DefIdMap, LocalDefId}; use rustc_hir::definitions::{DefPathData, PerParentDisambiguatorState}; @@ -142,7 +143,7 @@ impl<'tcx> Visitor<'tcx> for RPITVisitor<'_, 'tcx> { fn associated_types_for_impl_traits_in_trait_or_impl<'tcx>( tcx: TyCtxt<'tcx>, def_id: LocalDefId, -) -> DefIdMap> { +) -> FxIndexMap> { let item = tcx.hir_expect_item(def_id); let disambiguator = &mut PerParentDisambiguatorState::new(def_id); match item.kind { From bc988fa95a6a133cb5bff25c37c4933fd90b7e81 Mon Sep 17 00:00:00 2001 From: Matyas Susits Date: Fri, 16 Oct 2026 14:34:35 +0200 Subject: [PATCH 3/4] finish --- .../src/check/compare_impl_item.rs | 6 +- .../rustc_hir_analysis/src/check_unused.rs | 4 +- .../rustc_hir_typeck/src/fn_ctxt/_impl.rs | 2 +- compiler/rustc_hir_typeck/src/lib.rs | 4 +- compiler/rustc_hir_typeck/src/upvar.rs | 2 +- compiler/rustc_hir_typeck/src/writeback.rs | 119 ++++++++---------- .../rustc_mir_transform/src/inline/cycle.rs | 11 +- src/librustdoc/core.rs | 6 +- .../clippy_lints/src/pass_by_ref_or_value.rs | 3 +- 9 files changed, 72 insertions(+), 85 deletions(-) diff --git a/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs b/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs index 8a7ad70f8ebb1..ed28e26e7eb0a 100644 --- a/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs +++ b/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs @@ -3,7 +3,7 @@ use std::borrow::Cow; use std::cmp::Ordering; use std::iter; -use hir::def_id::{DefId, DefIdMap, LocalDefId}; +use hir::def_id::{DefId, LocalDefId}; use rustc_data_structures::fx::{FxIndexMap, FxIndexSet}; use rustc_errors::codes::*; use rustc_errors::{Applicability, ErrorGuaranteed, MultiSpan, pluralize, struct_span_code_err}; @@ -458,7 +458,7 @@ impl<'tcx> TypeFolder> for RemapLateParam<'tcx> { pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>( tcx: TyCtxt<'tcx>, impl_m_def_id: LocalDefId, -) -> Result<&'tcx DefIdMap>>, ErrorGuaranteed> { +) -> Result<&'tcx FxIndexMap>>, ErrorGuaranteed> { let impl_m = tcx.associated_item(impl_m_def_id.to_def_id()); let trait_m = tcx.associated_item(impl_m.expect_trait_impl()?); let impl_trait_ref = tcx @@ -706,7 +706,7 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>( // lifetime parameters. ocx.resolve_regions_and_report_errors(impl_m_def_id, param_env, wf_tys)?; - let mut remapped_types = DefIdMap::default(); + let mut remapped_types = FxIndexMap::default(); for (def_id, (ty, args)) in collected_types { match infcx.deeply_resolve_via_region_graph(ty) { Ok(ty) => { diff --git a/compiler/rustc_hir_analysis/src/check_unused.rs b/compiler/rustc_hir_analysis/src/check_unused.rs index d8dafd509cf24..6caf9d5c01f4c 100644 --- a/compiler/rustc_hir_analysis/src/check_unused.rs +++ b/compiler/rustc_hir_analysis/src/check_unused.rs @@ -1,4 +1,4 @@ -use rustc_data_structures::unord::{ExtendUnord, UnordSet}; +use rustc_data_structures::unord::UnordSet; use rustc_errors::{Diag, DiagCtxtHandle, Diagnostic, Level}; use rustc_hir::def::DefKind; use rustc_hir::def_id::LocalDefId; @@ -33,7 +33,7 @@ pub(super) fn check_unused_traits(tcx: TyCtxt<'_>, (): ()) { for item_def_id in tcx.hir_body_owners() { let imports = tcx.used_trait_imports(item_def_id); debug!("GatherVisitor: item_def_id={:?} with imports {:#?}", item_def_id, imports); - used_trait_imports.extend_unord(imports.items().copied()); + used_trait_imports.extend(imports.iter().copied()); } for &id in tcx.resolutions(()).maybe_unused_trait_imports.iter() { diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs index 9e3e3d810345e..9884fbedfcf82 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs @@ -1,9 +1,9 @@ -use std::collections::hash_map::Entry; use std::slice; use rustc_abi::FieldIdx; use rustc_attr_ir::lang_items::LangItem; use rustc_data_structures::fx::FxHashSet; +use rustc_data_structures::indexmap::map::Entry; use rustc_data_structures::thin_vec::ThinVec; use rustc_errors::{ Applicability, Diag, DiagCtxtHandle, Diagnostic, ErrorGuaranteed, Level, MultiSpan, diff --git a/compiler/rustc_hir_typeck/src/lib.rs b/compiler/rustc_hir_typeck/src/lib.rs index 67a4c63da4f93..ab1ddcf8905bc 100644 --- a/compiler/rustc_hir_typeck/src/lib.rs +++ b/compiler/rustc_hir_typeck/src/lib.rs @@ -39,7 +39,7 @@ mod writeback; pub use coercion::can_coerce; use fn_ctxt::FnCtxt; -use rustc_data_structures::unord::UnordSet; +use rustc_data_structures::fx::FxIndexSet; use rustc_errors::codes::*; use rustc_errors::{Applicability, Diag, ErrorGuaranteed, struct_span_code_err}; use rustc_hir as hir; @@ -77,7 +77,7 @@ macro_rules! type_error_struct { }) } -fn used_trait_imports(tcx: TyCtxt<'_>, def_id: LocalDefId) -> &UnordSet { +fn used_trait_imports(tcx: TyCtxt<'_>, def_id: LocalDefId) -> &FxIndexSet { &tcx.typeck(def_id).used_trait_imports } diff --git a/compiler/rustc_hir_typeck/src/upvar.rs b/compiler/rustc_hir_typeck/src/upvar.rs index 630951f791915..c78e80bc2af97 100644 --- a/compiler/rustc_hir_typeck/src/upvar.rs +++ b/compiler/rustc_hir_typeck/src/upvar.rs @@ -889,7 +889,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let mut typeck_results = self.typeck_results.borrow_mut(); let mut root_var_min_capture_list = - typeck_results.closure_min_captures.remove(&closure_def_id).unwrap_or_default(); + typeck_results.closure_min_captures.swap_remove(&closure_def_id).unwrap_or_default(); for (mut place, capture_info) in capture_information.into_iter() { let var_hir_id = match place.base { diff --git a/compiler/rustc_hir_typeck/src/writeback.rs b/compiler/rustc_hir_typeck/src/writeback.rs index 923c0d49936c8..178ad1c019289 100644 --- a/compiler/rustc_hir_typeck/src/writeback.rs +++ b/compiler/rustc_hir_typeck/src/writeback.rs @@ -13,7 +13,6 @@ use std::ops::ControlFlow; use rustc_attr_ir::find_attr; use rustc_data_structures::fx::{FxHashSet, FxIndexMap}; -use rustc_data_structures::unord::ExtendUnord; use rustc_errors::{E0720, ErrorGuaranteed}; use rustc_hir::def_id::LocalDefId; use rustc_hir::intravisit::{self, InferKind, Visitor}; @@ -377,75 +376,66 @@ impl<'cx, 'tcx> Visitor<'tcx> for WritebackCx<'cx, 'tcx> { impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> { fn eval_closure_size(&mut self) { - self.tcx().with_stable_hashing_context(|mut hcx| { - let fcx_typeck_results = self.fcx.typeck_results.borrow(); + let fcx_typeck_results = self.fcx.typeck_results.borrow(); - self.typeck_results.closure_size_eval = fcx_typeck_results - .closure_size_eval - .to_sorted(&mut hcx, false) - .into_iter() - .map(|(&closure_def_id, data)| { - let closure_hir_id = self.tcx().local_def_id_to_hir_id(closure_def_id); - let data = self.resolve(*data, &closure_hir_id); - (closure_def_id, data) - }) - .collect(); - }) + self.typeck_results.closure_size_eval = fcx_typeck_results + .closure_size_eval + .iter() + .map(|(&closure_def_id, data)| { + let closure_hir_id = self.tcx().local_def_id_to_hir_id(closure_def_id); + let data = self.resolve(*data, &closure_hir_id); + (closure_def_id, data) + }) + .collect(); } fn visit_min_capture_map(&mut self) { - self.tcx().with_stable_hashing_context(|mut hcx| { - let fcx_typeck_results = self.fcx.typeck_results.borrow(); + let fcx_typeck_results = self.fcx.typeck_results.borrow(); - self.typeck_results.closure_min_captures = fcx_typeck_results - .closure_min_captures - .to_sorted(&mut hcx, false) - .into_iter() - .map(|(&closure_def_id, root_min_captures)| { - let root_var_map_wb = root_min_captures - .iter() - .map(|(var_hir_id, min_list)| { - let min_list_wb = min_list - .iter() - .map(|captured_place| { - let locatable = - captured_place.info.path_expr_id.unwrap_or_else(|| { - self.tcx().local_def_id_to_hir_id(closure_def_id) - }); - self.resolve(captured_place.clone(), &locatable) - }) - .collect(); - (*var_hir_id, min_list_wb) - }) - .collect(); - (closure_def_id, root_var_map_wb) - }) - .collect(); - }) + self.typeck_results.closure_min_captures = fcx_typeck_results + .closure_min_captures + .iter() + .map(|(&closure_def_id, root_min_captures)| { + let root_var_map_wb = root_min_captures + .iter() + .map(|(var_hir_id, min_list)| { + let min_list_wb = min_list + .iter() + .map(|captured_place| { + let locatable = + captured_place.info.path_expr_id.unwrap_or_else(|| { + self.tcx().local_def_id_to_hir_id(closure_def_id) + }); + self.resolve(captured_place.clone(), &locatable) + }) + .collect(); + (*var_hir_id, min_list_wb) + }) + .collect(); + (closure_def_id, root_var_map_wb) + }) + .collect(); } fn visit_fake_reads_map(&mut self) { - self.tcx().with_stable_hashing_context(move |mut hcx| { - let fcx_typeck_results = self.fcx.typeck_results.borrow(); + let fcx_typeck_results = self.fcx.typeck_results.borrow(); - self.typeck_results.closure_fake_reads = fcx_typeck_results - .closure_fake_reads - .to_sorted(&mut hcx, true) - .into_iter() - .map(|(&closure_def_id, fake_reads)| { - let resolved_fake_reads = fake_reads - .iter() - .map(|(place, cause, hir_id)| { - let locatable = self.tcx().local_def_id_to_hir_id(closure_def_id); - let resolved_fake_read = self.resolve(place.clone(), &locatable); - (resolved_fake_read, *cause, *hir_id) - }) - .collect(); - - (closure_def_id, resolved_fake_reads) - }) - .collect(); - }); + self.typeck_results.closure_fake_reads = fcx_typeck_results + .closure_fake_reads + .iter() + .map(|(&closure_def_id, fake_reads)| { + let resolved_fake_reads = fake_reads + .iter() + .map(|(place, cause, hir_id)| { + let locatable = self.tcx().local_def_id_to_hir_id(closure_def_id); + let resolved_fake_read = self.resolve(place.clone(), &locatable); + (resolved_fake_read, *cause, *hir_id) + }) + .collect(); + + (closure_def_id, resolved_fake_reads) + }) + .collect(); } fn visit_closures(&mut self) { @@ -469,8 +459,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> { assert_eq!(fcx_typeck_results.hir_owner, self.typeck_results.hir_owner); - let fcx_coercion_casts = fcx_typeck_results.coercion_casts().to_sorted_stable_ord(); - for &local_id in fcx_coercion_casts { + for &local_id in fcx_typeck_results.coercion_casts() { self.typeck_results.set_coercion_cast(local_id); } } @@ -519,8 +508,8 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> { let fcx_typeck_results = self.fcx.typeck_results.borrow(); assert_eq!(fcx_typeck_results.hir_owner, self.typeck_results.hir_owner); - self.typeck_results.user_provided_sigs.extend_unord( - fcx_typeck_results.user_provided_sigs.items().map(|(def_id, c_sig)| (*def_id, *c_sig)), + self.typeck_results.user_provided_sigs.extend( + fcx_typeck_results.user_provided_sigs.iter().map(|(def_id, c_sig)| (*def_id, *c_sig)), ); } diff --git a/compiler/rustc_mir_transform/src/inline/cycle.rs b/compiler/rustc_mir_transform/src/inline/cycle.rs index c7115035e4121..09986dfd2a0eb 100644 --- a/compiler/rustc_mir_transform/src/inline/cycle.rs +++ b/compiler/rustc_mir_transform/src/inline/cycle.rs @@ -1,5 +1,4 @@ -use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexSet}; -use rustc_data_structures::unord::UnordSet; +use rustc_data_structures::fx::{FxHashMap, FxIndexSet}; use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_middle::mir::TerminatorKind; use rustc_middle::ty::{self, GenericArgsRef, InstanceKind, ShimKind, TyCtxt, TypeVisitableExt}; @@ -68,7 +67,7 @@ fn process<'tcx>( caller: ty::Instance<'tcx>, target: LocalDefId, seen: &mut FxHashMap, bool>, - involved: &mut FxHashSet, + involved: &mut FxIndexSet, recursion_limiter: &mut FxHashMap, recursion_limit: Limit, ) -> Option { @@ -152,7 +151,7 @@ fn process<'tcx>( pub(crate) fn mir_callgraph_cyclic<'tcx>( tcx: TyCtxt<'tcx>, root: LocalDefId, -) -> Option<&'tcx UnordSet> { +) -> Option<&'tcx FxIndexSet> { assert!( !tcx.is_constructor(root.to_def_id()), "you should not call `mir_callgraph_reachable` on enum/struct constructor functions" @@ -166,13 +165,13 @@ pub(crate) fn mir_callgraph_cyclic<'tcx>( // the default recursion limits are quite generous for us. If we need to recurse 64 times // into the call graph, we're probably not going to find any useful MIR inlining. let recursion_limit = tcx.recursion_limit() / 8; - let mut involved = FxHashSet::default(); + let mut involved = FxIndexSet::default(); let typing_env = ty::TypingEnv::post_analysis(tcx, root); let root_instance = ty::Instance::new_raw(root.to_def_id(), ty::GenericArgs::identity_for_item(tcx, root)); if !should_recurse(tcx, root_instance) { trace!("cannot walk, skipping"); - return Some(tcx.arena.alloc(involved.into())); + return Some(tcx.arena.alloc(involved)); } match process( tcx, diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index caf3fb9887c3e..f6cc02b643d92 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -1,8 +1,7 @@ use std::sync::{Arc, LazyLock}; use std::{io, mem}; -use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap}; -use rustc_data_structures::unord::UnordSet; +use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap, FxIndexSet}; use rustc_driver::USING_INTERNAL_FEATURES; use rustc_errors::TerminalUrl; use rustc_errors::annotate_snippet_emitter_writer::AnnotateSnippetEmitter; @@ -322,7 +321,8 @@ pub(crate) fn create_config( |tcx, module_def_id| late_lint_mod(tcx, module_def_id, MissingDoc); // hack so that `used_trait_imports` won't try to call typeck providers.queries.used_trait_imports = |_, _| { - static EMPTY_SET: LazyLock> = LazyLock::new(UnordSet::default); + static EMPTY_SET: LazyLock> = + LazyLock::new(FxIndexSet::default); &EMPTY_SET }; // In case typeck does end up being called, don't ICE in case there were name resolution errors diff --git a/src/tools/clippy/clippy_lints/src/pass_by_ref_or_value.rs b/src/tools/clippy/clippy_lints/src/pass_by_ref_or_value.rs index 4c541ead3d395..465a1da5cf471 100644 --- a/src/tools/clippy/clippy_lints/src/pass_by_ref_or_value.rs +++ b/src/tools/clippy/clippy_lints/src/pass_by_ref_or_value.rs @@ -7,7 +7,6 @@ use core::ops::ControlFlow; use rustc_abi::ExternAbi; use rustc_attr_ir::{InlineAttr, find_attr}; use rustc_data_structures::fx::FxHashSet; -use rustc_data_structures::unord::UnordItems; use rustc_errors::Applicability; use rustc_hir as hir; use rustc_hir::intravisit::FnKind; @@ -181,7 +180,7 @@ impl PassByRefOrValue { || typeck .adjustments() .items() - .flat_map(|(_, a)| UnordItems::new(a.iter())) + .flat_map(|(_, a)| a) .any(|a| matches!(a.kind, Adjust::Pointer(PointerCoercion::UnsafeFnPointer)))) { continue; From f4069cb66477f3bfa1c2367a3f0c565f53c655d9 Mon Sep 17 00:00:00 2001 From: Matyas Susits Date: Fri, 16 Oct 2026 14:37:16 +0200 Subject: [PATCH 4/4] fixes --- compiler/rustc_middle/src/query/on_disk_cache.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_middle/src/query/on_disk_cache.rs b/compiler/rustc_middle/src/query/on_disk_cache.rs index 81b94cd285f3a..06d1fbfe39330 100644 --- a/compiler/rustc_middle/src/query/on_disk_cache.rs +++ b/compiler/rustc_middle/src/query/on_disk_cache.rs @@ -724,9 +724,9 @@ macro_rules! impl_decodable_via_ref_decodable_for_foreign_types { impl_decodable_via_ref_decodable_for_foreign_types! { // tidy-alphabetical-start - &'tcx IndexVec>, &'tcx FxIndexMap>>, &'tcx FxIndexSet, + &'tcx IndexVec>, &'tcx [( rustc_middle::middle::exported_symbols::ExportedSymbol<'tcx>, rustc_middle::middle::exported_symbols::SymbolExportInfo,