diff --git a/Cargo.lock b/Cargo.lock index 2c9dc442663f8..653473b9e38c4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1627,7 +1627,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1033caf0b349c518623b5396bfb2cf0bddf44f0306d543a250e5743297aafd10" dependencies = [ "fnv", - "hashbrown", + "hashbrown 0.17.1 (registry+https://github.com/rust-lang/crates.io-index)", "indexmap", "stable_deref_trait", ] @@ -1688,6 +1688,14 @@ dependencies = [ "serde_core", ] +[[package]] +name = "hashbrown" +version = "0.17.1" +source = "git+https://github.com/Zoxc/hashbrown.git?branch=linear-probes#dc5066465f34332634fadf2abb0da9d095da2348" +dependencies = [ + "foldhash 0.2.0", +] + [[package]] name = "heck" version = "0.5.0" @@ -1977,7 +1985,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d466e9454f08e4a911e14806c24e16fba1b4c121d1ea474396f396069cf949d9" dependencies = [ "equivalent", - "hashbrown", + "hashbrown 0.17.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde", "serde_core", ] @@ -2783,7 +2791,7 @@ checksum = "2e5a6c098c7a3b6547378093f5cc30bc54fd361ce711e05293a5cc589562739b" dependencies = [ "crc32fast", "flate2", - "hashbrown", + "hashbrown 0.17.1 (registry+https://github.com/rust-lang/crates.io-index)", "indexmap", "memchr", "ruzstd", @@ -3456,7 +3464,7 @@ checksum = "d9776093b7ca170454ab1406954f7b7d97a57c51dc6c0642957fb2ef25c2d399" dependencies = [ "bytecheck", "bytes", - "hashbrown", + "hashbrown 0.17.1 (registry+https://github.com/rust-lang/crates.io-index)", "indexmap", "munge", "ptr_meta", @@ -3915,7 +3923,7 @@ dependencies = [ "either", "elsa", "ena", - "hashbrown", + "hashbrown 0.17.1 (git+https://github.com/Zoxc/hashbrown.git?branch=linear-probes)", "indexmap", "jobserver", "libc", @@ -4760,6 +4768,7 @@ dependencies = [ name = "rustc_serialize" version = "0.0.0" dependencies = [ + "hashbrown 0.17.1 (git+https://github.com/Zoxc/hashbrown.git?branch=linear-probes)", "indexmap", "rustc_hashes", "rustc_macros", @@ -4983,6 +4992,7 @@ dependencies = [ "bitflags", "derive-where", "ena", + "hashbrown 0.17.1 (git+https://github.com/Zoxc/hashbrown.git?branch=linear-probes)", "indexmap", "rustc-hash 2.1.1", "rustc_abi", @@ -5718,7 +5728,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b5938a79ecf9cb8198d525ddb37cd8841f66ab98073f6a123af7ed7cdcbb73ae" dependencies = [ "gimli 0.34.0", - "hashbrown", + "hashbrown 0.17.1 (registry+https://github.com/rust-lang/crates.io-index)", "itertools", "object 0.39.1", "tracing", @@ -6464,7 +6474,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d92fc335fb6d48f46bda1d8b26b69e28320c15ac3272208333833d6e217e2b4a" dependencies = [ "bitflags", - "hashbrown", + "hashbrown 0.17.1 (registry+https://github.com/rust-lang/crates.io-index)", "indexmap", "semver", "serde", @@ -6883,7 +6893,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6f815340f0bb65d9775ae21e56b503b496683557b9b627b195d2766c25fb24ae" dependencies = [ "anyhow", - "hashbrown", + "hashbrown 0.17.1 (registry+https://github.com/rust-lang/crates.io-index)", "id-arena", "indexmap", "log", diff --git a/compiler/rustc_ast_lowering/src/asm.rs b/compiler/rustc_ast_lowering/src/asm.rs index fd3a00d56fe0b..d0413e5758426 100644 --- a/compiler/rustc_ast_lowering/src/asm.rs +++ b/compiler/rustc_ast_lowering/src/asm.rs @@ -1,7 +1,6 @@ -use std::collections::hash_map::Entry; - use rustc_ast::*; use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap}; +use rustc_data_structures::hash_map::Entry; use rustc_errors::msg; use rustc_hir as hir; use rustc_hir::def::{DefKind, Res}; @@ -452,7 +451,7 @@ impl<'hir> LoweringContext<'_, 'hir> { overlapping_with.push(reg); }); let output_used = - overlapping_with.iter().any(|reg| used_output_regs.contains_key(®)); + overlapping_with.iter().any(|reg| used_output_regs.contains_key(reg)); if !output_used { operands.push(( diff --git a/compiler/rustc_borrowck/src/borrow_set.rs b/compiler/rustc_borrowck/src/borrow_set.rs index def165ea8da7f..fd99bc51d79f4 100644 --- a/compiler/rustc_borrowck/src/borrow_set.rs +++ b/compiler/rustc_borrowck/src/borrow_set.rs @@ -1,8 +1,8 @@ -use std::collections::hash_map::Entry; use std::fmt; use std::ops::Index; use rustc_data_structures::fx::{FxHashMap, FxIndexMap, FxIndexSet}; +use rustc_data_structures::hash_map::Entry; use rustc_hir::Mutability; use rustc_index::IndexVec; use rustc_index::bit_set::DenseBitSet; @@ -102,7 +102,7 @@ impl<'tcx> BorrowSet<'tcx> { // Public method to support Creusot. pub fn activations_at_location(&self, location: &Location) -> &[BorrowIndex] { - self.activation_map.get(&location).map_or(&[], |activations| &activations[..]) + self.activation_map.get(location).map_or(&[], |activations| &activations[..]) } // Public method to support Creusot. diff --git a/compiler/rustc_codegen_cranelift/src/pretty_clif.rs b/compiler/rustc_codegen_cranelift/src/pretty_clif.rs index fee3562c7bede..f903ddc920f98 100644 --- a/compiler/rustc_codegen_cranelift/src/pretty_clif.rs +++ b/compiler/rustc_codegen_cranelift/src/pretty_clif.rs @@ -124,7 +124,7 @@ impl CommentWriter { ) { debug_assert!(self.enabled); - use std::collections::hash_map::Entry; + use rustc_data_structures::hash_map::Entry; match self.entity_comments.entry(entity.into()) { Entry::Occupied(mut occ) => { occ.get_mut().push('\n'); @@ -143,7 +143,7 @@ impl CommentWriter { ) { debug_assert!(self.enabled); - use std::collections::hash_map::Entry; + use rustc_data_structures::hash_map::Entry; match self.inst_post_comments.entry(entity) { Entry::Occupied(mut occ) => { occ.get_mut().push('\n'); @@ -210,7 +210,7 @@ impl FuncWriter for &'_ CommentWriter { inst: Inst, indent: usize, ) -> fmt::Result { - if let Some(comment) = self.entity_comments.get(&inst.into()) { + if let Some(comment) = self.entity_comments.get::(&inst.into()) { writeln!(w, "; {}", comment.replace('\n', "\n; "))?; } PlainWriter.write_instruction(w, func, aliases, inst, indent)?; diff --git a/compiler/rustc_codegen_ssa/src/back/symbol_export.rs b/compiler/rustc_codegen_ssa/src/back/symbol_export.rs index f30ba43b0b0ba..54bcdd232f554 100644 --- a/compiler/rustc_codegen_ssa/src/back/symbol_export.rs +++ b/compiler/rustc_codegen_ssa/src/back/symbol_export.rs @@ -1,9 +1,8 @@ -use std::collections::hash_map::Entry::*; - 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::hash_map::Entry::*; use rustc_data_structures::unord::UnordMap; use rustc_hir as hir; use rustc_hir::def::DefKind; diff --git a/compiler/rustc_codegen_ssa/src/mir/debuginfo.rs b/compiler/rustc_codegen_ssa/src/mir/debuginfo.rs index 77b2c9c73f69f..2031db546f06f 100644 --- a/compiler/rustc_codegen_ssa/src/mir/debuginfo.rs +++ b/compiler/rustc_codegen_ssa/src/mir/debuginfo.rs @@ -1,9 +1,9 @@ -use std::collections::hash_map::Entry; use std::marker::PhantomData; use std::ops::Range; use rustc_abi::{BackendRepr, FieldIdx, FieldsShape, Size, VariantIdx}; use rustc_data_structures::fx::FxHashMap; +use rustc_data_structures::hash_map::Entry; use rustc_index::IndexVec; use rustc_index::bit_set::DenseBitSet; use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags; diff --git a/compiler/rustc_codegen_ssa/src/target_features.rs b/compiler/rustc_codegen_ssa/src/target_features.rs index 7dad0cc1732dd..cbce1a3a84cdc 100644 --- a/compiler/rustc_codegen_ssa/src/target_features.rs +++ b/compiler/rustc_codegen_ssa/src/target_features.rs @@ -538,7 +538,7 @@ pub(crate) fn provide(providers: &mut Providers) { // hope that this doesn't cause issues anywhere else in the compiler... let mut result: UnordMap = Default::default(); for (name, stability) in rustc_target::target_features::all_rust_features() { - use std::collections::hash_map::Entry; + use rustc_data_structures::hash_map::Entry; match result.entry(name.to_owned()) { Entry::Vacant(vacant_entry) => { vacant_entry.insert(stability); diff --git a/compiler/rustc_const_eval/src/interpret/eval_context.rs b/compiler/rustc_const_eval/src/interpret/eval_context.rs index 8fa028df9455f..18e62ff110a16 100644 --- a/compiler/rustc_const_eval/src/interpret/eval_context.rs +++ b/compiler/rustc_const_eval/src/interpret/eval_context.rs @@ -1,9 +1,9 @@ use std::cell::RefCell; -use std::collections::hash_map::Entry; use either::{Left, Right}; use rustc_abi::{Align, HasDataLayout, Size, TargetDataLayout}; use rustc_data_structures::fx::FxHashMap; +use rustc_data_structures::hash_map::Entry; use rustc_hir::def_id::DefId; use rustc_middle::mir::interpret::{ErrorHandled, InvalidMetaKind, ReportedErrorInfo}; use rustc_middle::query::TyCtxtAt; diff --git a/compiler/rustc_data_structures/Cargo.toml b/compiler/rustc_data_structures/Cargo.toml index daae72a9b358a..a96d13844ba63 100644 --- a/compiler/rustc_data_structures/Cargo.toml +++ b/compiler/rustc_data_structures/Cargo.toml @@ -34,7 +34,8 @@ tracing = "0.1" # tidy-alphabetical-end [dependencies.hashbrown] -version = "0.17.0" +git = "https://github.com/Zoxc/hashbrown.git" +branch = "linear-probes" default-features = false features = ["nightly"] # for may_dangle diff --git a/compiler/rustc_data_structures/src/fx.rs b/compiler/rustc_data_structures/src/fx.rs index cad775cc98641..d65a7acaecfaa 100644 --- a/compiler/rustc_data_structures/src/fx.rs +++ b/compiler/rustc_data_structures/src/fx.rs @@ -1,6 +1,14 @@ -pub use rustc_hash::{FxBuildHasher, FxHashMap, FxHashSet, FxHasher}; +pub use rustc_hash::{FxBuildHasher, FxHasher}; -pub type StdEntry<'a, K, V> = std::collections::hash_map::Entry<'a, K, V>; +// These are `hashbrown`'s hash map and set rather than the standard library's, even though the +// standard library's are themselves a thin wrapper around `hashbrown`. Depending on `hashbrown` +// directly means the compiler uses the version this workspace resolves, rather than whichever copy +// happens to be baked into the standard library it is compiled against. [LLM-generated] +pub type FxHashMap = hashbrown::HashMap; +pub type FxHashSet = hashbrown::HashSet; + +pub type MapEntry<'a, K, V> = hashbrown::hash_map::Entry<'a, K, V, FxBuildHasher>; +pub type MapOccupiedError<'a, K, V> = hashbrown::hash_map::OccupiedError<'a, K, V, FxBuildHasher>; pub type FxIndexMap = indexmap::IndexMap; pub type FxIndexSet = indexmap::IndexSet; @@ -14,7 +22,7 @@ macro_rules! define_id_collections { ($map_name:ident, $set_name:ident, $entry_name:ident, $key:ty) => { 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 $entry_name<'a, T> = $crate::fx::MapEntry<'a, $key, T>; }; } diff --git a/compiler/rustc_data_structures/src/lib.rs b/compiler/rustc_data_structures/src/lib.rs index ab30806bd2a59..ada4e3953fcc1 100644 --- a/compiler/rustc_data_structures/src/lib.rs +++ b/compiler/rustc_data_structures/src/lib.rs @@ -22,7 +22,6 @@ #![feature(dropck_eyepatch)] #![feature(extend_one)] #![feature(file_buffered)] -#![feature(map_try_insert)] #![feature(min_specialization)] #![feature(negative_impls)] #![feature(nonzero_internals)] @@ -44,10 +43,10 @@ use std::fmt; pub use atomic_ref::AtomicRef; pub use ena::{snapshot_vec, undo_log, unify}; -// Re-export `hashbrown::hash_table`, because it's part of our API -// (via `ShardedHashMap`), and because it lets other compiler crates use the -// lower-level `HashTable` API without a tricky `hashbrown` dependency. -pub use hashbrown::hash_table; +// Re-export `hashbrown`'s map, set and table modules, because they are part of our API +// (via `FxHashMap`, `FxHashSet` and `ShardedHashMap`), and because it lets other compiler crates +// use the lower-level `HashTable` API without a tricky `hashbrown` dependency. +pub use hashbrown::{hash_map, hash_set, hash_table}; pub use rustc_index::static_assert_size; // Re-export some data-structure crates which are part of our public API. pub use {either, indexmap, smallvec, thin_vec}; diff --git a/compiler/rustc_data_structures/src/marker.rs b/compiler/rustc_data_structures/src/marker.rs index 505a7a4c9d465..84194eed6ba08 100644 --- a/compiler/rustc_data_structures/src/marker.rs +++ b/compiler/rustc_data_structures/src/marker.rs @@ -92,6 +92,8 @@ impl_dyn_send!( [crate::tagged_ptr::TaggedRef<'a, P, T> where 'a, P: Sync, T: Send + crate::tagged_ptr::Tag] [rustc_arena::TypedArena where T: DynSend] [hashbrown::HashTable where T: DynSend] + [hashbrown::HashSet where K: DynSend, S: DynSend] + [hashbrown::HashMap where K: DynSend, V: DynSend, S: DynSend] [indexmap::IndexSet where V: DynSend, S: DynSend] [indexmap::IndexMap where K: DynSend, V: DynSend, S: DynSend] [thin_vec::ThinVec where T: DynSend] @@ -178,6 +180,8 @@ impl_dyn_sync!( [parking_lot::lock_api::Mutex where R: DynSync, T: ?Sized + DynSend] [parking_lot::lock_api::RwLock where R: DynSync, T: ?Sized + DynSend + DynSync] [hashbrown::HashTable where T: DynSync] + [hashbrown::HashSet where K: DynSync, S: DynSync] + [hashbrown::HashMap where K: DynSync, V: DynSync, S: DynSync] [indexmap::IndexSet where V: DynSync, S: DynSync] [indexmap::IndexMap where K: DynSync, V: DynSync, S: DynSync] [smallvec::SmallVec where A: smallvec::Array + DynSync] diff --git a/compiler/rustc_data_structures/src/obligation_forest/mod.rs b/compiler/rustc_data_structures/src/obligation_forest/mod.rs index 83cfa027cc3df..e9a9494eadca4 100644 --- a/compiler/rustc_data_structures/src/obligation_forest/mod.rs +++ b/compiler/rustc_data_structures/src/obligation_forest/mod.rs @@ -70,11 +70,11 @@ //! aren't needed anymore. use std::cell::Cell; -use std::collections::hash_map::Entry; use std::fmt::Debug; use std::hash; use std::marker::PhantomData; +use hashbrown::hash_map::Entry; use thin_vec::ThinVec; use tracing::debug; diff --git a/compiler/rustc_data_structures/src/profiling.rs b/compiler/rustc_data_structures/src/profiling.rs index 00fb424cadfd1..c5d255eb96d17 100644 --- a/compiler/rustc_data_structures/src/profiling.rs +++ b/compiler/rustc_data_structures/src/profiling.rs @@ -82,7 +82,6 @@ //! [mm]: https://github.com/rust-lang/measureme/ use std::borrow::Borrow; -use std::collections::hash_map::Entry; use std::error::Error; use std::fmt::Display; use std::path::Path; @@ -91,6 +90,7 @@ use std::sync::atomic::Ordering; use std::time::{Duration, Instant}; use std::{fs, hint, process}; +use hashbrown::hash_map::Entry; pub use measureme::EventId; use measureme::{EventIdBuilder, Profiler, SerializableString, StringId}; use parking_lot::RwLock; diff --git a/compiler/rustc_data_structures/src/sync.rs b/compiler/rustc_data_structures/src/sync.rs index 85e030c8aa0c5..7cab7ccdba05b 100644 --- a/compiler/rustc_data_structures/src/sync.rs +++ b/compiler/rustc_data_structures/src/sync.rs @@ -22,7 +22,6 @@ //! | | | `parking_lot::Mutex` | //! | `RwLock` | `parking_lot::RwLock` | `parking_lot::RwLock` | -use std::collections::HashMap; use std::hash::{BuildHasher, Hash}; pub use parking_lot::{ @@ -163,7 +162,7 @@ pub trait HashMapExt { fn insert_same(&mut self, key: K, value: V); } -impl HashMapExt for HashMap { +impl HashMapExt for hashbrown::HashMap { fn insert_same(&mut self, key: K, value: V) { self.entry(key).and_modify(|old| assert!(*old == value)).or_insert(value); } diff --git a/compiler/rustc_data_structures/src/unord.rs b/compiler/rustc_data_structures/src/unord.rs index 42dbe37db7951..57608458772ed 100644 --- a/compiler/rustc_data_structures/src/unord.rs +++ b/compiler/rustc_data_structures/src/unord.rs @@ -3,7 +3,6 @@ //! as required by the query system. use std::borrow::{Borrow, BorrowMut}; -use std::collections::hash_map::{Entry, OccupiedError}; use std::hash::Hash; use std::iter::{Product, Sum}; use std::ops::Index; @@ -11,7 +10,7 @@ use std::ops::Index; use rustc_macros::{Decodable_NoContext, Encodable_NoContext}; use crate::fingerprint::Fingerprint; -use crate::fx::{FxBuildHasher, FxHashMap, FxHashSet}; +use crate::fx::{FxBuildHasher, FxHashMap, FxHashSet, MapEntry, MapOccupiedError}; use crate::stable_hash::{ StableCompare, StableHash, StableHashCtxt, StableHasher, ToStableHashKey, }; @@ -501,7 +500,7 @@ impl UnordMap { } #[inline] - pub fn try_insert(&mut self, k: K, v: V) -> Result<&mut V, OccupiedError<'_, K, V>> { + pub fn try_insert(&mut self, k: K, v: V) -> Result<&mut V, MapOccupiedError<'_, K, V>> { self.inner.try_insert(k, v) } @@ -520,7 +519,7 @@ impl UnordMap { } #[inline] - pub fn entry(&mut self, key: K) -> Entry<'_, K, V> { + pub fn entry(&mut self, key: K) -> MapEntry<'_, K, V> { self.inner.entry(key) } diff --git a/compiler/rustc_expand/src/mbe/diagnostics.rs b/compiler/rustc_expand/src/mbe/diagnostics.rs index 89b4aac3299fc..7dec1bcd66f55 100644 --- a/compiler/rustc_expand/src/mbe/diagnostics.rs +++ b/compiler/rustc_expand/src/mbe/diagnostics.rs @@ -293,7 +293,7 @@ impl<'dcx, 'matcher> Tracker<'matcher> for CollectTrackerAndEmitter<'dcx, 'match bug!("`Self::prepare()` was not called to initialize context"); }; - #[expect( + #[allow( rustc::potential_query_instability, reason = "sorting the results deterministically afterwards" )] diff --git a/compiler/rustc_expand/src/mbe/macro_rules.rs b/compiler/rustc_expand/src/mbe/macro_rules.rs index b268b8b767327..a11032d698f79 100644 --- a/compiler/rustc_expand/src/mbe/macro_rules.rs +++ b/compiler/rustc_expand/src/mbe/macro_rules.rs @@ -1,5 +1,4 @@ use std::borrow::Cow; -use std::collections::hash_map::Entry; use std::sync::Arc; use std::{mem, slice}; @@ -13,6 +12,7 @@ use rustc_ast_pretty::pprust; use rustc_attr_ir::diagnostic::Directive; use rustc_attr_ir::{self as attrs, find_attr}; use rustc_data_structures::fx::{FxHashMap, FxIndexMap}; +use rustc_data_structures::hash_map::Entry; use rustc_errors::{Applicability, Diag, ErrorGuaranteed, MultiSpan}; use rustc_feature::Features; use rustc_hir::def::MacroKinds; diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs index 651b4ca33be99..14ac8fef6d32b 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs @@ -1,8 +1,8 @@ -use std::collections::hash_map::Entry; use std::slice; use rustc_abi::FieldIdx; use rustc_data_structures::fx::FxHashSet; +use rustc_data_structures::hash_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/pat.rs b/compiler/rustc_hir_typeck/src/pat.rs index 7413215b15ba1..e48ee67211fcb 100644 --- a/compiler/rustc_hir_typeck/src/pat.rs +++ b/compiler/rustc_hir_typeck/src/pat.rs @@ -1,9 +1,9 @@ -use std::collections::hash_map::Entry::{Occupied, Vacant}; use std::{assert_matches, cmp}; use rustc_abi::FieldIdx; use rustc_ast as ast; use rustc_data_structures::fx::FxHashMap; +use rustc_data_structures::hash_map::Entry::{Occupied, Vacant}; use rustc_errors::codes::*; use rustc_errors::{ Applicability, Diag, DiagCtxtHandle, Diagnostic, ErrorGuaranteed, Level, MultiSpan, pluralize, diff --git a/compiler/rustc_infer/src/infer/freshen.rs b/compiler/rustc_infer/src/infer/freshen.rs index f0fd46e6cac74..40b5638199198 100644 --- a/compiler/rustc_infer/src/infer/freshen.rs +++ b/compiler/rustc_infer/src/infer/freshen.rs @@ -31,9 +31,8 @@ //! variable only once, and it does so as soon as it can, so it is reasonable to ask what the type //! inferencer knows "so far". -use std::collections::hash_map::Entry; - use rustc_data_structures::fx::FxHashMap; +use rustc_data_structures::hash_map::Entry; use rustc_middle::bug; use rustc_middle::ty::{ self, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperFoldable, TypeVisitableExt, diff --git a/compiler/rustc_infer/src/infer/outlives/test_type_match.rs b/compiler/rustc_infer/src/infer/outlives/test_type_match.rs index de42736ce2b06..f6b74fa10778f 100644 --- a/compiler/rustc_infer/src/infer/outlives/test_type_match.rs +++ b/compiler/rustc_infer/src/infer/outlives/test_type_match.rs @@ -1,6 +1,5 @@ -use std::collections::hash_map::Entry; - use rustc_data_structures::fx::FxHashMap; +use rustc_data_structures::hash_map::Entry; use rustc_hir::def_id::DefId; use rustc_middle::ty::error::TypeError; use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitableExt}; diff --git a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs index 8fe1d6561d135..0dd27580508e1 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs @@ -461,9 +461,10 @@ pub(in crate::rmeta) fn provide(providers: &mut Providers) { // sufficiently visible parent (considering modules that re-export the // external item to be parents). visible_parent_map: |tcx, ()| { - use std::collections::hash_map::Entry; use std::collections::vec_deque::VecDeque; + use rustc_data_structures::hash_map::Entry; + let mut visible_parent_map: DefIdMap = Default::default(); // This is a secondary visible_parent_map, storing the DefId of // parents that re-export the child as `_`, module parents diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index 1d9dade66a544..71a22accc9d9d 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -1,11 +1,11 @@ use std::borrow::Borrow; -use std::collections::hash_map::Entry; use std::fs::File; use std::io::{Read, Seek, Write}; use std::path::{Path, PathBuf}; use std::sync::Arc; use rustc_data_structures::fx::{FxIndexMap, FxIndexSet}; +use rustc_data_structures::hash_map::Entry; use rustc_data_structures::memmap::{Mmap, MmapMut}; use rustc_data_structures::sync::{par_for_each_in, par_join}; use rustc_data_structures::temp_dir::MaybeTempDir; diff --git a/compiler/rustc_middle/src/infer/canonical.rs b/compiler/rustc_middle/src/infer/canonical.rs index 46429f7adfb12..da14a5e141a10 100644 --- a/compiler/rustc_middle/src/infer/canonical.rs +++ b/compiler/rustc_middle/src/infer/canonical.rs @@ -21,9 +21,8 @@ //! //! [c]: https://rust-lang.github.io/chalk/book/canonical_queries/canonicalization.html -use std::collections::hash_map::Entry; - use rustc_data_structures::fx::FxHashMap; +use rustc_data_structures::hash_map::Entry; use rustc_data_structures::sync::Lock; use rustc_macros::{StableHash, TypeFoldable, TypeVisitable}; pub use rustc_type_ir as ir; diff --git a/compiler/rustc_middle/src/query/on_disk_cache.rs b/compiler/rustc_middle/src/query/on_disk_cache.rs index d743c5dcc7e43..27811cda9684a 100644 --- a/compiler/rustc_middle/src/query/on_disk_cache.rs +++ b/compiler/rustc_middle/src/query/on_disk_cache.rs @@ -1,8 +1,8 @@ -use std::collections::hash_map::Entry; use std::sync::Arc; use std::{fmt, mem}; use rustc_data_structures::fx::{FxHashMap, FxIndexSet}; +use rustc_data_structures::hash_map::Entry; use rustc_data_structures::memmap::Mmap; use rustc_data_structures::sync::{HashMapExt, Lock, RwLock}; use rustc_data_structures::unhash::UnhashMap; diff --git a/compiler/rustc_middle/src/ty/generics.rs b/compiler/rustc_middle/src/ty/generics.rs index bfdb89dc409f6..752d99d0371d7 100644 --- a/compiler/rustc_middle/src/ty/generics.rs +++ b/compiler/rustc_middle/src/ty/generics.rs @@ -134,7 +134,7 @@ 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)] + #[allow(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") diff --git a/compiler/rustc_middle/src/ty/opaque_types.rs b/compiler/rustc_middle/src/ty/opaque_types.rs index 8d835a3d2153a..b09c4d8b45bc2 100644 --- a/compiler/rustc_middle/src/ty/opaque_types.rs +++ b/compiler/rustc_middle/src/ty/opaque_types.rs @@ -121,7 +121,7 @@ impl<'tcx> TypeFolder> for ReverseMapper<'tcx> { } } - match self.map.get(&r.into()).map(|arg| arg.kind()) { + match self.map.get::>(&r.into()).map(|arg| arg.kind()) { Some(GenericArgKind::Lifetime(r1)) => r1, Some(u) => panic!("region mapped to unexpected kind: {u:?}"), None if self.do_not_error => self.tcx.lifetimes.re_static, @@ -163,7 +163,7 @@ impl<'tcx> TypeFolder> for ReverseMapper<'tcx> { ty::Param(param) => { // Look it up in the generic parameters list. - match self.map.get(&ty.into()).map(|arg| arg.kind()) { + match self.map.get::>(&ty.into()).map(|arg| arg.kind()) { // Found it in the generic parameters list; replace with the parameter from the // opaque type. Some(GenericArgKind::Type(t1)) => t1, @@ -196,7 +196,7 @@ impl<'tcx> TypeFolder> for ReverseMapper<'tcx> { match ct.kind() { ty::ConstKind::Param(..) => { // Look it up in the generic parameters list. - match self.map.get(&ct.into()).map(|arg| arg.kind()) { + match self.map.get::>(&ct.into()).map(|arg| arg.kind()) { // Found it in the generic parameters list, replace with the parameter from the // opaque type. Some(GenericArgKind::Const(c1)) => c1, diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index f055051580e81..637aa40202389 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -3566,7 +3566,7 @@ pub fn trimmed_def_paths(tcx: TyCtxt<'_>, (): ()) -> DefIdMap { // Put the symbol from all the unique namespace+symbol pairs into `map`. let mut map: DefIdMap = Default::default(); for ((_, symbol), opt_def_id) in unique_symbols_rev.drain(..) { - use std::collections::hash_map::Entry::{Occupied, Vacant}; + use rustc_data_structures::hash_map::Entry::{Occupied, Vacant}; if let Some(def_id) = opt_def_id { match map.entry(def_id) { diff --git a/compiler/rustc_middle/src/ty/typeck_results.rs b/compiler/rustc_middle/src/ty/typeck_results.rs index ff7cef3613437..8ebf237e8e587 100644 --- a/compiler/rustc_middle/src/ty/typeck_results.rs +++ b/compiler/rustc_middle/src/ty/typeck_results.rs @@ -1,4 +1,3 @@ -use std::collections::hash_map::Entry; use std::hash::Hash; use std::iter; @@ -9,8 +8,8 @@ use rustc_errors::ErrorGuaranteed; use rustc_hir::def::{DefKind, Res}; use rustc_hir::def_id::{DefId, LocalDefId, LocalDefIdMap}; use rustc_hir::{ - self as hir, BindingMode, ByRef, HirId, ItemLocalId, ItemLocalMap, ItemLocalSet, Mutability, - OwnerId, + self as hir, BindingMode, ByRef, HirId, ItemLocalId, ItemLocalMap, ItemLocalMapEntry, + ItemLocalSet, Mutability, OwnerId, }; use rustc_index::IndexVec; use rustc_macros::{Lift, StableHash, TyDecodable, TyEncodable, TypeFoldable, TypeVisitable}; @@ -738,7 +737,7 @@ impl<'a, V> LocalTableInContextMut<'a, V> { self.data.get(&id.local_id) } - pub fn entry(&mut self, id: HirId) -> Entry<'_, hir::ItemLocalId, V> { + pub fn entry(&mut self, id: HirId) -> ItemLocalMapEntry<'_, V> { validate_hir_id_for_typeck_results(self.hir_owner, id); self.data.entry(id.local_id) } diff --git a/compiler/rustc_mir_build/src/builder/coverageinfo.rs b/compiler/rustc_mir_build/src/builder/coverageinfo.rs index 0898d9f117ae1..024eff5baf04f 100644 --- a/compiler/rustc_mir_build/src/builder/coverageinfo.rs +++ b/compiler/rustc_mir_build/src/builder/coverageinfo.rs @@ -1,7 +1,7 @@ use std::assert_matches; -use std::collections::hash_map::Entry; use rustc_data_structures::fx::FxHashMap; +use rustc_data_structures::hash_map::Entry; use rustc_middle::mir::coverage::{BlockMarkerId, BranchSpan, CoverageEarlyInfo, CoverageKind}; use rustc_middle::mir::{self, BasicBlock, SourceInfo, UnOp}; use rustc_middle::thir::{ExprId, ExprKind, Pat, Thir}; diff --git a/compiler/rustc_mir_dataflow/src/value_analysis.rs b/compiler/rustc_mir_dataflow/src/value_analysis.rs index 3b5884f5bc5fb..32941125d56ac 100644 --- a/compiler/rustc_mir_dataflow/src/value_analysis.rs +++ b/compiler/rustc_mir_dataflow/src/value_analysis.rs @@ -3,7 +3,7 @@ use std::fmt::{Debug, Formatter}; use std::ops::Range; use rustc_abi::{FieldIdx, VariantIdx}; -use rustc_data_structures::fx::{FxHashMap, FxIndexSet, StdEntry}; +use rustc_data_structures::fx::{FxHashMap, FxIndexSet, MapEntry}; use rustc_index::IndexVec; use rustc_index::bit_set::DenseBitSet; use rustc_middle::mir::visit::{PlaceContext, Visitor}; @@ -69,11 +69,11 @@ impl JoinSemiLattice for StateData { #[allow(rustc::potential_query_instability)] for (i, v) in other.map.iter() { match self.map.entry(*i) { - StdEntry::Vacant(e) => { + MapEntry::Vacant(e) => { e.insert(v.clone()); changed = true } - StdEntry::Occupied(e) => changed |= e.into_mut().join(v), + MapEntry::Occupied(e) => changed |= e.into_mut().join(v), } } changed diff --git a/compiler/rustc_mir_transform/src/lint_tail_expr_drop_order.rs b/compiler/rustc_mir_transform/src/lint_tail_expr_drop_order.rs index eb6921e438528..b8e5af963264a 100644 --- a/compiler/rustc_mir_transform/src/lint_tail_expr_drop_order.rs +++ b/compiler/rustc_mir_transform/src/lint_tail_expr_drop_order.rs @@ -1,9 +1,9 @@ use std::cell::RefCell; -use std::collections::hash_map; use std::rc::Rc; use itertools::Itertools as _; use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap}; +use rustc_data_structures::hash_map; use rustc_data_structures::unord::{UnordMap, UnordSet}; use rustc_errors::formatting::DiagMessageAddArg; use rustc_errors::{Subdiagnostic, msg}; diff --git a/compiler/rustc_mir_transform/src/pass_manager.rs b/compiler/rustc_mir_transform/src/pass_manager.rs index 798f69d3cc883..0b8040bbb5e7f 100644 --- a/compiler/rustc_mir_transform/src/pass_manager.rs +++ b/compiler/rustc_mir_transform/src/pass_manager.rs @@ -1,8 +1,8 @@ use std::cell::RefCell; -use std::collections::hash_map::Entry; use std::sync::atomic::Ordering; use rustc_data_structures::fx::{FxHashMap, FxIndexSet}; +use rustc_data_structures::hash_map::Entry; use rustc_middle::mir::{Body, MirDumper, MirPhase, RuntimePhase}; use rustc_middle::ty::TyCtxt; use rustc_session::Session; diff --git a/compiler/rustc_monomorphize/src/partitioning.rs b/compiler/rustc_monomorphize/src/partitioning.rs index 29b624afd0614..2c34b1a9ec5dc 100644 --- a/compiler/rustc_monomorphize/src/partitioning.rs +++ b/compiler/rustc_monomorphize/src/partitioning.rs @@ -93,13 +93,13 @@ //! inlining, even when they are not marked `#[inline]`. use std::cmp; -use std::collections::hash_map::Entry; use std::fs::{self, File}; use std::io::Write; use std::path::{Path, PathBuf}; use rustc_data_structures::either::Either; use rustc_data_structures::fx::{FxIndexMap, FxIndexSet}; +use rustc_data_structures::hash_map::Entry; use rustc_data_structures::sync::par_join; use rustc_data_structures::unord::{UnordMap, UnordSet}; use rustc_hir::attrs::lang_items::LangItem; diff --git a/compiler/rustc_next_trait_solver/src/canonical/canonicalizer.rs b/compiler/rustc_next_trait_solver/src/canonical/canonicalizer.rs index cf36b1922b8c1..97f1280cb5eee 100644 --- a/compiler/rustc_next_trait_solver/src/canonical/canonicalizer.rs +++ b/compiler/rustc_next_trait_solver/src/canonical/canonicalizer.rs @@ -1,6 +1,6 @@ -use std::collections::hash_map::Entry; use std::mem; +use rustc_data_structures::hash_map::Entry; use rustc_type_ir::inherent::*; use rustc_type_ir::solve::{Goal, QueryInput}; use rustc_type_ir::{ diff --git a/compiler/rustc_passes/src/dead.rs b/compiler/rustc_passes/src/dead.rs index d6a8b2c2f5eb6..92f047b1ee5a4 100644 --- a/compiler/rustc_passes/src/dead.rs +++ b/compiler/rustc_passes/src/dead.rs @@ -636,7 +636,7 @@ impl<'tcx> MarkSymbolVisitor<'tcx> { items_to_check } - #[expect( + #[allow( rustc::potential_query_instability, reason = "The order of the unsolved items is not important, so we can just collect them into a vector." )] diff --git a/compiler/rustc_query_impl/src/execution.rs b/compiler/rustc_query_impl/src/execution.rs index d220826670729..51f4bc954b384 100644 --- a/compiler/rustc_query_impl/src/execution.rs +++ b/compiler/rustc_query_impl/src/execution.rs @@ -109,7 +109,7 @@ where panic!(); } Ok(occupied) => { - let ((key, status), vacant) = occupied.remove(); + let ((key, status), vacant) = occupied.remove(|(k, _)| sharded::make_hash(k)); if poison { vacant.insert((key, ActiveKeyStatus::Poisoned)); } diff --git a/compiler/rustc_resolve/src/diagnostics/impls.rs b/compiler/rustc_resolve/src/diagnostics/impls.rs index 47a05b3f65d86..2a676f805e1de 100644 --- a/compiler/rustc_resolve/src/diagnostics/impls.rs +++ b/compiler/rustc_resolve/src/diagnostics/impls.rs @@ -1993,7 +1993,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { }); if let Some((def_id, unused_ident)) = unused_macro { - let scope = self.local_macro_def_scopes[&def_id]; + let scope = self.local_macro_def_scopes[def_id]; let parent_nearest = parent_scope.module.nearest_parent_mod(); let unused_macro_kinds = self.local_macro_map[def_id].macro_kinds(); if !unused_macro_kinds.contains(macro_kind.into()) { diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index 396db754f7c96..c58dc93adbecc 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -7,7 +7,6 @@ //! `build_reduced_graph.rs`, `macros.rs` and `imports.rs`. use std::borrow::Cow; -use std::collections::hash_map::Entry; use std::debug_assert_matches; use std::mem::{replace, swap, take}; use std::ops::{ControlFlow, Range}; @@ -18,6 +17,7 @@ use rustc_ast::visit::{ use rustc_ast::*; use rustc_data_structures::either::Either; use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap}; +use rustc_data_structures::hash_map::Entry; use rustc_data_structures::unord::{UnordMap, UnordSet}; use rustc_errors::codes::*; use rustc_errors::{ diff --git a/compiler/rustc_resolve/src/macros.rs b/compiler/rustc_resolve/src/macros.rs index d57f831f3d204..12e1ed0d6ed8f 100644 --- a/compiler/rustc_resolve/src/macros.rs +++ b/compiler/rustc_resolve/src/macros.rs @@ -381,7 +381,7 @@ impl<'ra, 'tcx> ResolverExpand for Resolver<'ra, 'tcx> { if unused_arms.is_empty() { continue; } - let ext = self.local_macro_map[&def_id]; + let ext = self.local_macro_map[def_id]; let SyntaxExtensionKind::MacroRules(ref m) = ext.kind else { continue; }; diff --git a/compiler/rustc_serialize/Cargo.toml b/compiler/rustc_serialize/Cargo.toml index e1b14360f1262..1c5c86652620f 100644 --- a/compiler/rustc_serialize/Cargo.toml +++ b/compiler/rustc_serialize/Cargo.toml @@ -5,6 +5,7 @@ edition = "2024" [dependencies] # tidy-alphabetical-start +hashbrown = { git = "https://github.com/Zoxc/hashbrown.git", branch = "linear-probes", default-features = false } indexmap = "2.0.0" rustc_hashes = { path = "../rustc_hashes" } smallvec = { version = "1.8.1", features = ["union", "may_dangle"] } diff --git a/compiler/rustc_serialize/src/serialize.rs b/compiler/rustc_serialize/src/serialize.rs index 4213d0a4650e9..05e5d48684f34 100644 --- a/compiler/rustc_serialize/src/serialize.rs +++ b/compiler/rustc_serialize/src/serialize.rs @@ -661,6 +661,57 @@ where } } +impl Encodable for hashbrown::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 hashbrown::HashMap +where + K: Decodable + Hash + Eq, + V: Decodable, + S: BuildHasher + Default, +{ + fn decode(d: &mut D) -> hashbrown::HashMap { + let len = d.read_usize(); + (0..len).map(|_| (Decodable::decode(d), Decodable::decode(d))).collect() + } +} + +impl Encodable for hashbrown::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 hashbrown::HashSet +where + T: Decodable + Hash + Eq, + S: BuildHasher + Default, +{ + fn decode(d: &mut D) -> hashbrown::HashSet { + let len = d.read_usize(); + (0..len).map(|_| Decodable::decode(d)).collect() + } +} + impl Encodable for indexmap::IndexMap where K: Encodable + Hash + Eq, diff --git a/compiler/rustc_span/src/lib.rs b/compiler/rustc_span/src/lib.rs index f6ae748560750..261e5b47760e0 100644 --- a/compiler/rustc_span/src/lib.rs +++ b/compiler/rustc_span/src/lib.rs @@ -20,7 +20,6 @@ #![cfg_attr(target_arch = "loongarch64", feature(stdarch_loongarch))] #![feature(core_io_borrowed_buf)] #![feature(diagnostic_on_unknown)] -#![feature(map_try_insert)] #![feature(negative_impls)] #![feature(read_buf)] #![feature(rustc_attrs)] diff --git a/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs b/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs index 1c4f0ca5069df..e2330f77d9174 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs @@ -1,12 +1,12 @@ // ignore-tidy-file-filelength use core::ops::ControlFlow; use std::borrow::Cow; -use std::collections::hash_set; use std::path::PathBuf; use rustc_ast::ast::LitKind; use rustc_ast::{LitIntType, TraitObjectSyntax}; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; +use rustc_data_structures::hash_set; use rustc_data_structures::unord::UnordSet; use rustc_errors::codes::*; use rustc_errors::{ diff --git a/compiler/rustc_trait_selection/src/lib.rs b/compiler/rustc_trait_selection/src/lib.rs index bbaf683f4288a..ee0d78784f65f 100644 --- a/compiler/rustc_trait_selection/src/lib.rs +++ b/compiler/rustc_trait_selection/src/lib.rs @@ -15,7 +15,6 @@ #![feature(associated_type_defaults)] #![feature(default_field_values)] #![feature(deref_patterns)] -#![feature(hash_set_entry)] #![feature(iter_intersperse)] #![feature(iterator_try_reduce)] #![feature(option_into_flat_iter)] diff --git a/compiler/rustc_trait_selection/src/solve/delegate.rs b/compiler/rustc_trait_selection/src/solve/delegate.rs index 818d8e1a4e0c3..62526451587d4 100644 --- a/compiler/rustc_trait_selection/src/solve/delegate.rs +++ b/compiler/rustc_trait_selection/src/solve/delegate.rs @@ -1,9 +1,9 @@ -use std::collections::hash_map::Entry; use std::fmt::Debug; use std::mem; use std::ops::{ControlFlow, Deref}; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; +use rustc_data_structures::hash_map::Entry; use rustc_hir::CRATE_HIR_ID; use rustc_hir::attrs::lang_items::LangItem; use rustc_hir::def::Namespace; diff --git a/compiler/rustc_type_ir/Cargo.toml b/compiler/rustc_type_ir/Cargo.toml index b1c20c235ff36..95c3b8f86f551 100644 --- a/compiler/rustc_type_ir/Cargo.toml +++ b/compiler/rustc_type_ir/Cargo.toml @@ -9,6 +9,7 @@ arrayvec = { version = "0.7", default-features = false } bitflags = "2.4.1" derive-where = "1.6.1" ena = "0.14.4" +hashbrown = { git = "https://github.com/Zoxc/hashbrown.git", branch = "linear-probes", default-features = false } indexmap = "2.0.0" rustc-hash = "2.0.0" rustc_abi = { path = "../rustc_abi", default-features = false } diff --git a/compiler/rustc_type_ir/src/data_structures/mod.rs b/compiler/rustc_type_ir/src/data_structures/mod.rs index 6ffcead67460b..91051b9ef2cbe 100644 --- a/compiler/rustc_type_ir/src/data_structures/mod.rs +++ b/compiler/rustc_type_ir/src/data_structures/mod.rs @@ -1,6 +1,11 @@ pub use ena::unify::{NoError, UnifyKey, UnifyValue}; use rustc_hash::FxBuildHasher; -pub use rustc_hash::{FxHashMap as HashMap, FxHashSet as HashSet}; + +// `hashbrown`'s hash map and set rather than the standard library's, matching +// `rustc_data_structures::fx`. [LLM-generated] +pub type HashMap = hashbrown::HashMap; +pub type HashSet = hashbrown::HashSet; +pub use hashbrown::hash_map; pub type IndexMap = indexmap::IndexMap; pub type IndexSet = indexmap::IndexSet; diff --git a/compiler/rustc_type_ir/src/search_graph/mod.rs b/compiler/rustc_type_ir/src/search_graph/mod.rs index c081898f26f56..0ea69fa60d027 100644 --- a/compiler/rustc_type_ir/src/search_graph/mod.rs +++ b/compiler/rustc_type_ir/src/search_graph/mod.rs @@ -12,7 +12,6 @@ //! The global cache has to be completely unobservable, while the per-cycle cache may impact //! behavior as long as the resulting behavior is still correct. use std::cmp::Ordering; -use std::collections::hash_map::Entry; use std::collections::{BTreeMap, btree_map}; use std::fmt::Debug; use std::hash::Hash; @@ -26,6 +25,8 @@ use rustc_macros::{Decodable_NoContext, Encodable_NoContext, StableHash}; use rustc_type_ir::data_structures::HashMap; use tracing::{debug, instrument, trace}; +use crate::data_structures::hash_map::Entry; + mod stack; use stack::{Stack, StackDepth, StackEntry}; mod global_cache; diff --git a/src/bootstrap/src/core/build_steps/dist.rs b/src/bootstrap/src/core/build_steps/dist.rs index a266fba781e1a..6a14f0cd06e36 100644 --- a/src/bootstrap/src/core/build_steps/dist.rs +++ b/src/bootstrap/src/core/build_steps/dist.rs @@ -31,7 +31,7 @@ use crate::core::build_steps::llvm::{ use crate::core::build_steps::tool::{ self, RustcPrivateCompilers, ToolTargetBuildMode, get_tool_target_compiler, }; -use crate::core::build_steps::vendor::Vendor; +use crate::core::build_steps::vendor::{VENDORING_BROKEN_BY_HASHBROWN_BRANCH, Vendor}; use crate::core::build_steps::{compile, llvm}; use crate::core::builder::{ Builder, CommandLineStep, Kind, RunConfig, ShouldRun, Step, StepMetadata, @@ -675,9 +675,13 @@ impl CommandLineStep for Rustc { generate_target_spec_json_schema(builder, image); // HTML copyright files - let file_list = builder.ensure(super::run::GenerateCopyright); - for file in file_list { - builder.install(&file, &image.join("share/doc/rust"), FileType::Regular); + // + // Generating these vendors the tree, which the `hashbrown` branch breaks. + if !VENDORING_BROKEN_BY_HASHBROWN_BRANCH { + let file_list = builder.ensure(super::run::GenerateCopyright); + for file in file_list { + builder.install(&file, &image.join("share/doc/rust"), FileType::Regular); + } } // README @@ -1396,7 +1400,7 @@ fn prepare_source_tarball<'a>( write_git_info(builder.rust_info().info(), plain_dst_src); write_git_info(builder.cargo_info.info(), &plain_dst_src.join("./src/tools/cargo")); - if builder.config.dist_vendor { + if builder.config.dist_vendor && !VENDORING_BROKEN_BY_HASHBROWN_BRANCH { builder.require_and_update_all_submodules(); // Vendor packages that are required by opt-dist to collect PGO profiles. diff --git a/src/bootstrap/src/core/build_steps/vendor.rs b/src/bootstrap/src/core/build_steps/vendor.rs index 0d8ccc0d5b5c7..ea3793e1f55e6 100644 --- a/src/bootstrap/src/core/build_steps/vendor.rs +++ b/src/bootstrap/src/core/build_steps/vendor.rs @@ -11,6 +11,15 @@ use crate::utils::exec::command; /// The name of the directory where vendored dependencies are stored. pub const VENDOR_DIR: &str = "vendor"; +/// Whether vendoring the compiler workspace is currently broken. +/// +/// `cargo vendor` refuses to vendor two packages with the same name and version from different +/// sources, and the `linear-probes` `hashbrown` branch the compiler builds against (see +/// `compiler/rustc_data_structures/Cargo.toml`) has the same version as the crates.io `hashbrown` +/// the rest of the tree uses. Vendoring the compiler workspace, and the copyright generation which +/// depends on it, are therefore skipped while that branch is in `Cargo.lock`. [LLM-generated] +pub const VENDORING_BROKEN_BY_HASHBROWN_BRANCH: bool = true; + /// Returns the cargo workspaces to vendor for `x vendor` and dist tarballs. /// /// Returns a `Vec` of `(path_to_manifest, submodules_required)` where diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 784a80ef02cd2..6727161e4e524 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1737,7 +1737,9 @@ fn clean_qpath<'tcx>(hir_ty: &hir::Ty<'_>, cx: &mut DocContext<'tcx>) -> Type { if let Some(new_ty) = cx.args.get(&did).and_then(|p| p.as_ty()).cloned() { return new_ty; } - if let Some(bounds) = cx.impl_trait_bounds.remove(&did.into()) { + if let Some(bounds) = + cx.impl_trait_bounds.remove::(&did.into()) + { return ImplTrait(bounds); } } @@ -2342,7 +2344,9 @@ pub(crate) fn clean_middle_ty<'tcx>( } ty::Param(ref p) => { - if let Some(bounds) = cx.impl_trait_bounds.remove(&p.index.into()) { + if let Some(bounds) = + cx.impl_trait_bounds.remove::(&p.index.into()) + { ImplTrait(bounds) } else if p.name == kw::SelfUpper { SelfTy diff --git a/src/librustdoc/html/render/context.rs b/src/librustdoc/html/render/context.rs index 56dd665177a93..e9d3d009d81f9 100644 --- a/src/librustdoc/html/render/context.rs +++ b/src/librustdoc/html/render/context.rs @@ -698,7 +698,12 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> { && !redirections.borrow().is_empty() { let redirect_map_path = self.dst.join(crate_name.as_str()).join("redirect-map.json"); - let paths = serde_json::to_string(&*redirections.borrow()).unwrap(); + // `FxHashMap` is `hashbrown`'s, which is not built with serde support here, so the + // entries go through a `BTreeMap`. That also makes the output deterministic. + // [LLM-generated] + let redirections = redirections.borrow(); + let redirections: BTreeMap<&String, &String> = redirections.iter().collect(); + let paths = serde_json::to_string(&redirections).unwrap(); shared.ensure_dir(&self.dst.join(crate_name.as_str()))?; shared.fs.write(redirect_map_path, paths)?; } diff --git a/src/librustdoc/html/render/search_index.rs b/src/librustdoc/html/render/search_index.rs index 0991778f87d79..3063d3e16caa9 100644 --- a/src/librustdoc/html/render/search_index.rs +++ b/src/librustdoc/html/render/search_index.rs @@ -2,7 +2,6 @@ pub(crate) mod encode; mod serde; use std::collections::BTreeSet; -use std::collections::hash_map::Entry; use std::path::Path; use std::string::FromUtf8Error; use std::{io, iter}; @@ -12,6 +11,7 @@ use ::serde::ser::{SerializeSeq, Serializer}; use ::serde::{Deserialize, Serialize}; use rustc_ast::join_path_syms; use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap}; +use rustc_data_structures::hash_map::Entry; use rustc_data_structures::thin_vec::ThinVec; use rustc_hir::def_id::{CrateNum, DefIndex, LOCAL_CRATE}; use rustc_hir::find_attr; diff --git a/src/librustdoc/passes/stripper.rs b/src/librustdoc/passes/stripper.rs index 4c6d62917ab24..fec6811294407 100644 --- a/src/librustdoc/passes/stripper.rs +++ b/src/librustdoc/passes/stripper.rs @@ -185,7 +185,7 @@ pub(crate) struct ImplStripper<'a, 'tcx> { impl ImplStripper<'_, '_> { #[inline] fn should_keep_impl(&self, item: &Item, for_def_id: DefId) -> bool { - if !for_def_id.is_local() || self.retained.contains(&for_def_id.into()) { + if !for_def_id.is_local() || self.retained.contains::(&for_def_id.into()) { true } else if self.is_json_output { // If the "for" item is exported and the impl block isn't `#[doc(hidden)]`, then we diff --git a/src/tools/clippy/clippy_config/src/de.rs b/src/tools/clippy/clippy_config/src/de.rs index 803e34aefe91d..63328f5ca281d 100644 --- a/src/tools/clippy/clippy_config/src/de.rs +++ b/src/tools/clippy/clippy_config/src/de.rs @@ -2,13 +2,14 @@ use arrayvec::ArrayVec; use core::str::FromStr as _; use itertools::Itertools as _; use rustc_attr_parsing::parse_version; +use rustc_data_structures::hash_map::HashMap; +use rustc_data_structures::hash_set::HashSet; use rustc_errors::{DiagCtxtHandle, DiagMessage}; use rustc_hir::attrs::RustcVersion; use rustc_session::Session; use rustc_session::config::ErrorOutputType; use rustc_span::edit_distance::edit_distance; use rustc_span::{BytePos, Pos as _, Span, Spanned, Symbol}; -use std::collections::{HashMap, HashSet}; use std::fmt::{self, Display, Write as _}; use std::hash::{BuildHasher, Hash}; use std::marker::PhantomData; diff --git a/src/tools/clippy/clippy_lints/src/attrs/duplicated_attributes.rs b/src/tools/clippy/clippy_lints/src/attrs/duplicated_attributes.rs index 33f291e9875e7..1b5c3dc70a3ce 100644 --- a/src/tools/clippy/clippy_lints/src/attrs/duplicated_attributes.rs +++ b/src/tools/clippy/clippy_lints/src/attrs/duplicated_attributes.rs @@ -6,7 +6,7 @@ use rustc_ast_pretty::pprust::path_to_string; use rustc_data_structures::fx::FxHashMap; use rustc_lint::EarlyContext; use rustc_span::{Span, Symbol, sym}; -use std::collections::hash_map::Entry; +use rustc_data_structures::hash_map::Entry; fn emit_if_duplicated( cx: &EarlyContext<'_>, diff --git a/src/tools/clippy/clippy_lints/src/format_args.rs b/src/tools/clippy/clippy_lints/src/format_args.rs index f6f90f5dc36d5..c7565e0ca639d 100644 --- a/src/tools/clippy/clippy_lints/src/format_args.rs +++ b/src/tools/clippy/clippy_lints/src/format_args.rs @@ -1,4 +1,4 @@ -use std::collections::hash_map::Entry; +use rustc_data_structures::hash_map::Entry; use arrayvec::ArrayVec; use clippy_config::Conf; diff --git a/src/tools/clippy/clippy_lints/src/inherent_impl.rs b/src/tools/clippy/clippy_lints/src/inherent_impl.rs index 5790c3cce2606..d523b78fc73be 100644 --- a/src/tools/clippy/clippy_lints/src/inherent_impl.rs +++ b/src/tools/clippy/clippy_lints/src/inherent_impl.rs @@ -7,7 +7,7 @@ use rustc_hir::def_id::{LocalDefId, LocalModId}; use rustc_hir::{Item, ItemKind, Node}; use rustc_lint::{LateContext, LateLintPass, impl_lint_pass}; use rustc_span::{FileName, Span}; -use std::collections::hash_map::Entry; +use rustc_data_structures::hash_map::Entry; declare_clippy_lint! { /// ### What it does diff --git a/src/tools/clippy/clippy_lints/src/manual_let_else.rs b/src/tools/clippy/clippy_lints/src/manual_let_else.rs index 87523cd0e8c81..ad85832e22663 100644 --- a/src/tools/clippy/clippy_lints/src/manual_let_else.rs +++ b/src/tools/clippy/clippy_lints/src/manual_let_else.rs @@ -250,7 +250,7 @@ fn replace_in_pattern( (None, Some(subpt)) => { let subpt = replace_in_pattern(cx, span, ident_map, subpt, app, false); // scanning for a value that matches is not sensitive to order - #[expect(rustc::potential_query_instability)] + #[allow(rustc::potential_query_instability)] if ident_map.values().any(|(other_pat, _)| { if let PatKind::Binding(_, _, other_name, _) = other_pat.kind { other_name == binding_name diff --git a/src/tools/clippy/clippy_lints/src/needless_pass_by_ref_mut.rs b/src/tools/clippy/clippy_lints/src/needless_pass_by_ref_mut.rs index 5c6030d61f5f0..e49c74e22ad3b 100644 --- a/src/tools/clippy/clippy_lints/src/needless_pass_by_ref_mut.rs +++ b/src/tools/clippy/clippy_lints/src/needless_pass_by_ref_mut.rs @@ -260,7 +260,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByRefMut<'tcx> { for (fn_def_id, unused) in self .fn_def_ids_to_maybe_unused_mut .iter() - .filter(|(def_id, _)| !self.used_fn_def_ids.contains(def_id)) + .filter(|(def_id, _)| !self.used_fn_def_ids.contains(*def_id)) { let mut is_cfged = None; for input in unused { diff --git a/src/tools/clippy/clippy_lints/src/non_copy_const.rs b/src/tools/clippy/clippy_lints/src/non_copy_const.rs index 5150220c14738..8108f41b4a7c0 100644 --- a/src/tools/clippy/clippy_lints/src/non_copy_const.rs +++ b/src/tools/clippy/clippy_lints/src/non_copy_const.rs @@ -39,7 +39,7 @@ use rustc_middle::ty::{ TypeckResults, TypingEnv, Unnormalized, }; use rustc_span::DUMMY_SP; -use std::collections::hash_map::Entry; +use rustc_data_structures::hash_map::Entry; declare_clippy_lint! { /// ### What it does diff --git a/src/tools/clippy/clippy_lints/src/nonstandard_macro_braces.rs b/src/tools/clippy/clippy_lints/src/nonstandard_macro_braces.rs index 46a251b7b7278..4ff0e93d32b6a 100644 --- a/src/tools/clippy/clippy_lints/src/nonstandard_macro_braces.rs +++ b/src/tools/clippy/clippy_lints/src/nonstandard_macro_braces.rs @@ -181,7 +181,7 @@ fn macro_braces(conf: &[MacroMatcher]) -> (FxHashMap, usiz braces.insert(it.name.clone(), it.braces); } - #[expect( + #[allow( rustc::potential_query_instability, reason = "iteration order does not matter for `.max()`" )] diff --git a/src/tools/clippy/clippy_lints/src/significant_drop_tightening.rs b/src/tools/clippy/clippy_lints/src/significant_drop_tightening.rs index 064c78d9d1eec..50171ff483c4d 100644 --- a/src/tools/clippy/clippy_lints/src/significant_drop_tightening.rs +++ b/src/tools/clippy/clippy_lints/src/significant_drop_tightening.rs @@ -13,7 +13,7 @@ use rustc_middle::ty::{GenericArgKind, Ty, Unnormalized}; use rustc_span::symbol::Ident; use rustc_span::{DUMMY_SP, Span}; use std::borrow::Cow; -use std::collections::hash_map::Entry; +use rustc_data_structures::hash_map::Entry; declare_clippy_lint! { /// ### What it does diff --git a/src/tools/clippy/clippy_utils/src/lib.rs b/src/tools/clippy/clippy_utils/src/lib.rs index 76313e2fdd7ae..82e9f335e4e45 100644 --- a/src/tools/clippy/clippy_utils/src/lib.rs +++ b/src/tools/clippy/clippy_utils/src/lib.rs @@ -73,7 +73,7 @@ pub use self::hir_utils::{ use core::mem; use core::ops::ControlFlow; -use std::collections::hash_map::Entry; +use rustc_data_structures::hash_map::Entry; use std::iter::{once, repeat_n, zip}; use std::sync::{Mutex, OnceLock}; diff --git a/src/tools/clippy/clippy_utils/src/ty/mod.rs b/src/tools/clippy/clippy_utils/src/ty/mod.rs index ca8b54a6de58b..2ac2861ab7ed0 100644 --- a/src/tools/clippy/clippy_utils/src/ty/mod.rs +++ b/src/tools/clippy/clippy_utils/src/ty/mod.rs @@ -33,7 +33,7 @@ use rustc_span::{DUMMY_SP, Span, Symbol}; use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt as _; use rustc_trait_selection::traits::query::normalize::QueryNormalizeExt as _; use rustc_trait_selection::traits::{Obligation, ObligationCause}; -use std::collections::hash_map::Entry; +use rustc_data_structures::hash_map::Entry; use std::{debug_assert_matches, iter, mem}; use crate::paths::{PathNS, lookup_path_str}; diff --git a/src/tools/miri/src/concurrency/genmc/global_allocations.rs b/src/tools/miri/src/concurrency/genmc/global_allocations.rs index 76be8c3a4c9a8..f36fb1ff8500d 100644 --- a/src/tools/miri/src/concurrency/genmc/global_allocations.rs +++ b/src/tools/miri/src/concurrency/genmc/global_allocations.rs @@ -1,4 +1,4 @@ -use std::collections::hash_map::Entry; +use rustc_data_structures::hash_map::Entry; use std::sync::RwLock; use genmc_sys::{GENMC_GLOBAL_ADDRESSES_MASK, get_global_alloc_static_mask}; diff --git a/src/tools/miri/src/concurrency/sync.rs b/src/tools/miri/src/concurrency/sync.rs index f81408dc1f79b..2261e3b6def6d 100644 --- a/src/tools/miri/src/concurrency/sync.rs +++ b/src/tools/miri/src/concurrency/sync.rs @@ -1,7 +1,7 @@ use std::any::Any; use std::cell::RefCell; use std::collections::VecDeque; -use std::collections::hash_map::Entry; +use rustc_data_structures::hash_map::Entry; use std::default::Default; use std::ops::Not; use std::rc::Rc; diff --git a/src/tools/miri/src/data_structures/mono_hash_map.rs b/src/tools/miri/src/data_structures/mono_hash_map.rs index 63edfdac9d605..9cbdd7a5d7d9c 100644 --- a/src/tools/miri/src/data_structures/mono_hash_map.rs +++ b/src/tools/miri/src/data_structures/mono_hash_map.rs @@ -7,7 +7,7 @@ use std::borrow::Borrow; use std::cell::RefCell; -use std::collections::hash_map::Entry; +use rustc_data_structures::hash_map::Entry; use std::hash::Hash; use rustc_data_structures::fx::FxHashMap; diff --git a/src/tools/miri/src/shims/foreign_items.rs b/src/tools/miri/src/shims/foreign_items.rs index 9eaadffb55922..9d13c723cd336 100644 --- a/src/tools/miri/src/shims/foreign_items.rs +++ b/src/tools/miri/src/shims/foreign_items.rs @@ -1,4 +1,4 @@ -use std::collections::hash_map::Entry; +use rustc_data_structures::hash_map::Entry; use std::io::Write; use std::path::Path; diff --git a/src/tools/tidy/src/extdeps.rs b/src/tools/tidy/src/extdeps.rs index 79b562270f7ce..9abfd1c2f2e95 100644 --- a/src/tools/tidy/src/extdeps.rs +++ b/src/tools/tidy/src/extdeps.rs @@ -11,6 +11,9 @@ const ALLOWED_SOURCES: &[&str] = &[ r#""registry+https://github.com/rust-lang/crates.io-index""#, // This is `rust_team_data` used by `site` in src/tools/rustc-perf, r#""git+https://github.com/rust-lang/team#db2c1ed9fbc0216e533db954cd249045c01c7406""#, + // This is the `hashbrown` branch the compiler's own hash maps are built against, see + // `compiler/rustc_data_structures/Cargo.toml`. + r#""git+https://github.com/Zoxc/hashbrown.git?branch=linear-probes#dc5066465f34332634fadf2abb0da9d095da2348""#, ]; /// Checks for external package sources. `root` is the path to the directory that contains the