From e2a9cd52970af8cfa8739c7e325e420307fc3f6f Mon Sep 17 00:00:00 2001 From: yukang Date: Sun, 11 Feb 2024 19:50:50 +0800 Subject: [PATCH 1/9] clean up potential_query_instability with FxIndexMap and UnordMap --- .../rustc_borrowck/src/region_infer/values.rs | 7 +----- compiler/rustc_borrowck/src/type_check/mod.rs | 1 - .../rustc_borrowck/src/universal_regions.rs | 7 ++---- compiler/rustc_codegen_llvm/src/back/lto.rs | 8 +++--- .../src/coverageinfo/mapgen.rs | 1 - .../src/assert_module_sources.rs | 10 +++----- .../rustc_codegen_ssa/src/back/archive.rs | 4 +-- compiler/rustc_codegen_ssa/src/back/link.rs | 25 ++++++++----------- .../src/back/symbol_export.rs | 1 - compiler/rustc_codegen_ssa/src/back/write.rs | 4 +-- compiler/rustc_codegen_ssa/src/base.rs | 16 ++++++------ compiler/rustc_codegen_ssa/src/lib.rs | 14 ++++++----- .../rustc_const_eval/src/interpret/memory.rs | 11 ++++---- compiler/rustc_data_structures/src/unord.rs | 5 ++++ compiler/rustc_errors/src/diagnostic.rs | 6 ++--- compiler/rustc_hir_typeck/src/expr.rs | 12 ++++----- compiler/rustc_lint/src/context.rs | 20 +++++++-------- compiler/rustc_middle/src/mir/mono.rs | 9 +++---- .../rustc_monomorphize/src/partitioning.rs | 4 +-- 19 files changed, 75 insertions(+), 90 deletions(-) diff --git a/compiler/rustc_borrowck/src/region_infer/values.rs b/compiler/rustc_borrowck/src/region_infer/values.rs index b1caaa6388186..82b96b3efd542 100644 --- a/compiler/rustc_borrowck/src/region_infer/values.rs +++ b/compiler/rustc_borrowck/src/region_infer/values.rs @@ -1,4 +1,3 @@ -use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::fx::FxIndexSet; use rustc_index::bit_set::SparseBitMatrix; use rustc_index::interval::IntervalSet; @@ -42,7 +41,7 @@ pub(crate) struct LivenessValues { /// Which regions are live. This is exclusive with the fine-grained tracking in `points`, and /// currently only used for validating promoteds (which don't care about more precise tracking). - live_regions: Option>, + live_regions: Option>, /// For each region: the points where it is live. /// @@ -104,10 +103,6 @@ impl LivenessValues { self.points.as_ref().expect("use with_specific_points").rows() } - /// Iterate through each region that has a value in this set. - // We are passing query instability implications to the caller. - #[rustc_lint_query_instability] - #[allow(rustc::potential_query_instability)] pub(crate) fn live_regions_unordered(&self) -> impl Iterator + '_ { self.live_regions.as_ref().unwrap().iter().copied() } diff --git a/compiler/rustc_borrowck/src/type_check/mod.rs b/compiler/rustc_borrowck/src/type_check/mod.rs index cfb46f3ac8a96..ab42f76b48eda 100644 --- a/compiler/rustc_borrowck/src/type_check/mod.rs +++ b/compiler/rustc_borrowck/src/type_check/mod.rs @@ -599,7 +599,6 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> { // // add_location doesn't care about ordering so not a problem for the live regions to be // unordered. - #[allow(rustc::potential_query_instability)] for region in liveness_constraints.live_regions_unordered() { self.cx .borrowck_context diff --git a/compiler/rustc_borrowck/src/universal_regions.rs b/compiler/rustc_borrowck/src/universal_regions.rs index a7bdfa4eae769..90e8f1b93b294 100644 --- a/compiler/rustc_borrowck/src/universal_regions.rs +++ b/compiler/rustc_borrowck/src/universal_regions.rs @@ -15,7 +15,7 @@ #![allow(rustc::diagnostic_outside_of_impl)] #![allow(rustc::untranslatable_diagnostic)] -use rustc_data_structures::fx::FxHashMap; +use rustc_data_structures::fx::FxIndexMap; use rustc_errors::Diagnostic; use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::lang_items::LangItem; @@ -180,7 +180,7 @@ struct UniversalRegionIndices<'tcx> { /// basically equivalent to an `GenericArgs`, except that it also /// contains an entry for `ReStatic` -- it might be nice to just /// use an args, and then handle `ReStatic` another way. - indices: FxHashMap, RegionVid>, + indices: FxIndexMap, RegionVid>, /// The vid assigned to `'static`. Used only for diagnostics. pub fr_static: RegionVid, @@ -325,9 +325,6 @@ impl<'tcx> UniversalRegions<'tcx> { } /// Gets an iterator over all the early-bound regions that have names. - /// Iteration order may be unstable, so this should only be used when - /// iteration order doesn't affect anything - #[allow(rustc::potential_query_instability)] pub fn named_universal_regions<'s>( &'s self, ) -> impl Iterator, ty::RegionVid)> + 's { diff --git a/compiler/rustc_codegen_llvm/src/back/lto.rs b/compiler/rustc_codegen_llvm/src/back/lto.rs index 42bd8687042a1..886d8901c0149 100644 --- a/compiler/rustc_codegen_llvm/src/back/lto.rs +++ b/compiler/rustc_codegen_llvm/src/back/lto.rs @@ -14,6 +14,7 @@ use rustc_codegen_ssa::traits::*; use rustc_codegen_ssa::{looks_like_rust_object_file, ModuleCodegen, ModuleKind}; use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::memmap::Mmap; +use rustc_data_structures::unord::UnordMap; use rustc_errors::{DiagCtxt, FatalError}; use rustc_hir::def_id::LOCAL_CRATE; use rustc_middle::bug; @@ -787,7 +788,7 @@ pub unsafe fn optimize_thin_module( #[derive(Debug, Default)] pub struct ThinLTOKeysMap { // key = llvm name of importing module, value = LLVM cache key - keys: FxHashMap, + keys: UnordMap, } impl ThinLTOKeysMap { @@ -797,8 +798,7 @@ impl ThinLTOKeysMap { let mut writer = io::BufWriter::new(file); // The entries are loaded back into a hash map in `load_from_file()`, so // the order in which we write them to file here does not matter. - #[allow(rustc::potential_query_instability)] - for (module, key) in &self.keys { + for (module, key) in self.keys.items().into_sorted_stable_ord() { writeln!(writer, "{module} {key}")?; } Ok(()) @@ -806,7 +806,7 @@ impl ThinLTOKeysMap { fn load_from_file(path: &Path) -> io::Result { use std::io::BufRead; - let mut keys = FxHashMap::default(); + let mut keys = UnordMap::default(); let file = File::open(path)?; for line in io::BufReader::new(file).lines() { let line = line?; diff --git a/compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs b/compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs index b1ceb1d4dd56d..6116a6fd222b3 100644 --- a/compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs +++ b/compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs @@ -403,7 +403,6 @@ fn codegenned_and_inlined_items(tcx: TyCtxt<'_>) -> DefIdSet { let mut result = items.clone(); for cgu in cgus { - #[allow(rustc::potential_query_instability)] for item in cgu.items().keys() { if let mir::mono::MonoItem::Fn(ref instance) = item { let did = instance.def_id(); diff --git a/compiler/rustc_codegen_ssa/src/assert_module_sources.rs b/compiler/rustc_codegen_ssa/src/assert_module_sources.rs index 3e5a43c6e73a6..344e7dbdf034d 100644 --- a/compiler/rustc_codegen_ssa/src/assert_module_sources.rs +++ b/compiler/rustc_codegen_ssa/src/assert_module_sources.rs @@ -25,7 +25,7 @@ use crate::errors; use rustc_ast as ast; -use rustc_data_structures::fx::FxHashMap; +use rustc_data_structures::unord::UnordMap; use rustc_data_structures::unord::UnordSet; use rustc_errors::{DiagnosticArgValue, IntoDiagnosticArg}; use rustc_hir::def_id::LOCAL_CRATE; @@ -218,8 +218,8 @@ pub enum ComparisonKind { } struct TrackerData { - actual_reuse: FxHashMap, - expected_reuse: FxHashMap, + actual_reuse: UnordMap, + expected_reuse: UnordMap, } pub struct CguReuseTracker { @@ -267,9 +267,7 @@ impl CguReuseTracker { fn check_expected_reuse(&self, sess: &Session) { if let Some(ref data) = self.data { - #[allow(rustc::potential_query_instability)] - let mut keys = data.expected_reuse.keys().collect::>(); - keys.sort_unstable(); + let keys = data.expected_reuse.keys().into_sorted_stable_ord(); for cgu_name in keys { let &(ref cgu_user_name, ref error_span, expected_reuse, comparison_kind) = data.expected_reuse.get(cgu_name).unwrap(); diff --git a/compiler/rustc_codegen_ssa/src/back/archive.rs b/compiler/rustc_codegen_ssa/src/back/archive.rs index 8d7ad24b44698..0dadd047c9a97 100644 --- a/compiler/rustc_codegen_ssa/src/back/archive.rs +++ b/compiler/rustc_codegen_ssa/src/back/archive.rs @@ -1,4 +1,4 @@ -use rustc_data_structures::fx::FxHashSet; +use rustc_data_structures::fx::FxIndexSet; use rustc_data_structures::memmap::Mmap; use rustc_session::cstore::DllImport; use rustc_session::Session; @@ -41,7 +41,7 @@ pub trait ArchiveBuilderBuilder { &'a self, rlib: &'a Path, outdir: &Path, - bundled_lib_file_names: &FxHashSet, + bundled_lib_file_names: &FxIndexSet, ) -> Result<(), ExtractBundledLibsError<'_>> { let archive_map = unsafe { Mmap::map( diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs index b29f71bfb9553..83343cd39bec1 100644 --- a/compiler/rustc_codegen_ssa/src/back/link.rs +++ b/compiler/rustc_codegen_ssa/src/back/link.rs @@ -1,7 +1,7 @@ use rustc_arena::TypedArena; use rustc_ast::CRATE_NODE_ID; -use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::fx::FxIndexMap; +use rustc_data_structures::fx::FxIndexSet; use rustc_data_structures::memmap::Mmap; use rustc_data_structures::temp_dir::MaybeTempDir; use rustc_errors::{DiagCtxt, ErrorGuaranteed}; @@ -534,9 +534,9 @@ fn link_staticlib<'a>( let native_libs = codegen_results.crate_info.native_libraries[&cnum].iter(); let relevant = native_libs.clone().filter(|lib| relevant_lib(sess, lib)); - let relevant_libs: FxHashSet<_> = relevant.filter_map(|lib| lib.filename).collect(); + let relevant_libs: FxIndexSet<_> = relevant.filter_map(|lib| lib.filename).collect(); - let bundled_libs: FxHashSet<_> = native_libs.filter_map(|lib| lib.filename).collect(); + let bundled_libs: FxIndexSet<_> = native_libs.filter_map(|lib| lib.filename).collect(); ab.add_archive( path, Box::new(move |fname: &str| { @@ -564,10 +564,7 @@ fn link_staticlib<'a>( .extract_bundled_libs(path, tempdir.as_ref(), &relevant_libs) .unwrap_or_else(|e| sess.dcx().emit_fatal(e)); - // We sort the libraries below - #[allow(rustc::potential_query_instability)] - let mut relevant_libs: Vec = relevant_libs.into_iter().collect(); - relevant_libs.sort_unstable(); + let relevant_libs: Vec = relevant_libs.into_iter().collect(); for filename in relevant_libs { let joined = tempdir.as_ref().join(filename.as_str()); let path = joined.as_path(); @@ -682,13 +679,14 @@ fn link_dwarf_object<'a>( } // Input rlibs contain .o/.dwo files from dependencies. - #[allow(rustc::potential_query_instability)] let input_rlibs = cg_results .crate_info .used_crate_source - .values() - .filter_map(|csource| csource.rlib.as_ref()) - .map(|(path, _)| path); + .items() + .filter_map(|(_, csource)| csource.rlib.as_ref()) + .map(|(path, _)| path) + .into_sorted_stable_ord(); + for input_rlib in input_rlibs { debug!(?input_rlib); package.add_input_object(input_rlib)?; @@ -2218,7 +2216,6 @@ fn linker_with_args<'a>( .expect("failed to find crate type in dependency format list"); // We sort the libraries below - #[allow(rustc::potential_query_instability)] let mut native_libraries_from_nonstatics = codegen_results .crate_info .native_libraries @@ -2456,7 +2453,7 @@ fn add_native_libs_from_crate( codegen_results: &CodegenResults, tmpdir: &Path, search_paths: &SearchPaths, - bundled_libs: &FxHashSet, + bundled_libs: &FxIndexSet, cnum: CrateNum, link_static: bool, link_dynamic: bool, @@ -2777,7 +2774,7 @@ fn add_static_crate<'a>( codegen_results: &CodegenResults, tmpdir: &Path, cnum: CrateNum, - bundled_lib_file_names: &FxHashSet, + bundled_lib_file_names: &FxIndexSet, ) { let src = &codegen_results.crate_info.used_crate_source[&cnum]; let cratepath = &src.rlib.as_ref().unwrap().0; diff --git a/compiler/rustc_codegen_ssa/src/back/symbol_export.rs b/compiler/rustc_codegen_ssa/src/back/symbol_export.rs index 2dba04e0bb71b..a36bfa2d7e383 100644 --- a/compiler/rustc_codegen_ssa/src/back/symbol_export.rs +++ b/compiler/rustc_codegen_ssa/src/back/symbol_export.rs @@ -320,7 +320,6 @@ fn exported_symbols_provider_local( let (_, cgus) = tcx.collect_and_partition_mono_items(()); // The symbols created in this loop are sorted below it - #[allow(rustc::potential_query_instability)] for (mono_item, data) in cgus.iter().flat_map(|cgu| cgu.items().iter()) { if data.linkage != Linkage::External { // We can only re-use things with external linkage, otherwise diff --git a/compiler/rustc_codegen_ssa/src/back/write.rs b/compiler/rustc_codegen_ssa/src/back/write.rs index a63642d76b976..24fdd01350926 100644 --- a/compiler/rustc_codegen_ssa/src/back/write.rs +++ b/compiler/rustc_codegen_ssa/src/back/write.rs @@ -1001,7 +1001,7 @@ pub struct CguMessage; struct Diagnostic { msgs: Vec<(DiagnosticMessage, Style)>, - args: FxHashMap, + args: FxIndexMap, code: Option, lvl: Level, } @@ -1813,7 +1813,7 @@ impl Translate for SharedEmitter { impl Emitter for SharedEmitter { fn emit_diagnostic(&mut self, diag: rustc_errors::Diagnostic) { - let args: FxHashMap = + let args: FxIndexMap = diag.args().map(|(name, arg)| (name.clone(), arg.clone())).collect(); drop(self.sender.send(SharedEmitterMessage::Diagnostic(Diagnostic { msgs: diag.messages.clone(), diff --git a/compiler/rustc_codegen_ssa/src/base.rs b/compiler/rustc_codegen_ssa/src/base.rs index 098ea1b793ccb..5e99ff9a6c0b5 100644 --- a/compiler/rustc_codegen_ssa/src/base.rs +++ b/compiler/rustc_codegen_ssa/src/base.rs @@ -16,9 +16,10 @@ use crate::{CachedModuleCodegen, CompiledModule, CrateInfo, MemFlags, ModuleCode use rustc_ast::expand::allocator::{global_fn_name, AllocatorKind, ALLOCATOR_METHODS}; use rustc_attr as attr; -use rustc_data_structures::fx::{FxHashMap, FxHashSet}; +use rustc_data_structures::fx::{FxHashMap, FxIndexSet}; use rustc_data_structures::profiling::{get_resident_set_size, print_time_passes_entry}; use rustc_data_structures::sync::par_map; +use rustc_data_structures::unord::UnordMap; use rustc_hir as hir; use rustc_hir::def_id::{DefId, LOCAL_CRATE}; use rustc_hir::lang_items::LangItem; @@ -851,6 +852,8 @@ impl CrateInfo { // `compiler_builtins` are always placed last to ensure that they're linked correctly. used_crates.extend(compiler_builtins); + let crates = tcx.crates(()); + let n_crates = crates.len(); let mut info = CrateInfo { target_cpu, crate_types, @@ -862,19 +865,15 @@ 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: Default::default(), + crate_name: UnordMap::with_capacity(n_crates), used_crates, - used_crate_source: Default::default(), + used_crate_source: UnordMap::with_capacity(n_crates), dependency_formats: tcx.dependency_formats(()).clone(), windows_subsystem, natvis_debugger_visualizers: Default::default(), }; - let crates = tcx.crates(()); - let n_crates = crates.len(); info.native_libraries.reserve(n_crates); - info.crate_name.reserve(n_crates); - info.used_crate_source.reserve(n_crates); for &cnum in crates.iter() { info.native_libraries @@ -901,7 +900,7 @@ impl CrateInfo { // by the compiler, but that's ok because all this stuff is unstable anyway. let target = &tcx.sess.target; if !are_upstream_rust_objects_already_included(tcx.sess) { - let missing_weak_lang_items: FxHashSet = info + let missing_weak_lang_items: FxIndexSet = info .used_crates .iter() .flat_map(|&cnum| tcx.missing_lang_items(cnum)) @@ -915,7 +914,6 @@ impl CrateInfo { // This loop only adds new items to values of the hash map, so the order in which we // iterate over the values is not important. - #[allow(rustc::potential_query_instability)] info.linked_symbols .iter_mut() .filter(|(crate_type, _)| { diff --git a/compiler/rustc_codegen_ssa/src/lib.rs b/compiler/rustc_codegen_ssa/src/lib.rs index 1afc597a7ef01..92f0be541c0b0 100644 --- a/compiler/rustc_codegen_ssa/src/lib.rs +++ b/compiler/rustc_codegen_ssa/src/lib.rs @@ -24,8 +24,10 @@ extern crate tracing; extern crate rustc_middle; use rustc_ast as ast; -use rustc_data_structures::fx::{FxHashMap, FxHashSet}; +use rustc_data_structures::fx::FxHashSet; +use rustc_data_structures::fx::FxIndexMap; use rustc_data_structures::sync::Lrc; +use rustc_data_structures::unord::UnordMap; use rustc_hir::def_id::CrateNum; use rustc_middle::dep_graph::WorkProduct; use rustc_middle::middle::debugger_visualizer::DebuggerVisualizerFile; @@ -152,16 +154,16 @@ impl From<&cstore::NativeLib> for NativeLib { pub struct CrateInfo { pub target_cpu: String, pub crate_types: Vec, - pub exported_symbols: FxHashMap>, - pub linked_symbols: FxHashMap>, + pub exported_symbols: UnordMap>, + pub linked_symbols: FxIndexMap>, pub local_crate_name: Symbol, pub compiler_builtins: Option, pub profiler_runtime: Option, pub is_no_builtins: FxHashSet, - pub native_libraries: FxHashMap>, - pub crate_name: FxHashMap, + pub native_libraries: FxIndexMap>, + pub crate_name: UnordMap, pub used_libraries: Vec, - pub used_crate_source: FxHashMap>, + pub used_crate_source: UnordMap>, pub used_crates: Vec, pub dependency_formats: Lrc, pub windows_subsystem: Option, diff --git a/compiler/rustc_const_eval/src/interpret/memory.rs b/compiler/rustc_const_eval/src/interpret/memory.rs index 4acf4ed893c5e..53253a8906dc5 100644 --- a/compiler/rustc_const_eval/src/interpret/memory.rs +++ b/compiler/rustc_const_eval/src/interpret/memory.rs @@ -13,7 +13,7 @@ use std::fmt; use std::ptr; use rustc_ast::Mutability; -use rustc_data_structures::fx::{FxHashMap, FxHashSet}; +use rustc_data_structures::fx::{FxHashSet, FxIndexMap}; use rustc_middle::mir::display_allocation; use rustc_middle::ty::{self, Instance, ParamEnv, Ty, TyCtxt}; use rustc_target::abi::{Align, HasDataLayout, Size}; @@ -104,13 +104,13 @@ pub struct Memory<'mir, 'tcx, M: Machine<'mir, 'tcx>> { pub(super) alloc_map: M::MemoryMap, /// Map for "extra" function pointers. - extra_fn_ptr_map: FxHashMap, + extra_fn_ptr_map: FxIndexMap, /// To be able to compare pointers with null, and to check alignment for accesses /// to ZSTs (where pointers may dangle), we keep track of the size even for allocations /// that do not exist any more. // FIXME: this should not be public, but interning currently needs access to it - pub(super) dead_alloc_map: FxHashMap, + pub(super) dead_alloc_map: FxIndexMap, } /// A reference to some allocation that was already bounds-checked for the given region @@ -135,8 +135,8 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> { pub fn new() -> Self { Memory { alloc_map: M::MemoryMap::default(), - extra_fn_ptr_map: FxHashMap::default(), - dead_alloc_map: FxHashMap::default(), + extra_fn_ptr_map: FxIndexMap::default(), + dead_alloc_map: FxIndexMap::default(), } } @@ -514,7 +514,6 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { // Unlike all the other GC helpers where we check if an `AllocId` is found in the interpreter or // is live, here all the IDs in the map are for dead allocations so we don't // need to check for liveness. - #[allow(rustc::potential_query_instability)] // Only used from Miri, not queries. self.memory.dead_alloc_map.retain(|id, _| reachable_allocs.contains(id)); } } diff --git a/compiler/rustc_data_structures/src/unord.rs b/compiler/rustc_data_structures/src/unord.rs index 907c866b3edd6..a99e2062039bf 100644 --- a/compiler/rustc_data_structures/src/unord.rs +++ b/compiler/rustc_data_structures/src/unord.rs @@ -524,6 +524,11 @@ impl UnordMap { UnordItems(self.inner.into_iter()) } + #[inline] + pub fn keys(&self) -> UnordItems<&K, impl Iterator> { + UnordItems(self.inner.keys()) + } + /// Returns the entries of this map in stable sort order (as defined by `ToStableHashKey`). /// /// The `cache_sort_key` parameter controls if [slice::sort_by_cached_key] or diff --git a/compiler/rustc_errors/src/diagnostic.rs b/compiler/rustc_errors/src/diagnostic.rs index 2deb18484ec2e..47ca7bac14869 100644 --- a/compiler/rustc_errors/src/diagnostic.rs +++ b/compiler/rustc_errors/src/diagnostic.rs @@ -3,7 +3,7 @@ use crate::{ CodeSuggestion, DiagnosticBuilder, DiagnosticMessage, EmissionGuarantee, ErrCode, Level, MultiSpan, SubdiagnosticMessage, Substitution, SubstitutionPart, SuggestionStyle, }; -use rustc_data_structures::fx::{FxHashMap, FxIndexMap}; +use rustc_data_structures::fx::FxIndexMap; use rustc_error_messages::fluent_value_from_str_list_sep_by_and; use rustc_error_messages::FluentValue; use rustc_lint_defs::{Applicability, LintExpectationId}; @@ -105,7 +105,7 @@ pub struct Diagnostic { pub span: MultiSpan, pub children: Vec, pub suggestions: Result, SuggestionsDisabled>, - args: FxHashMap, + args: FxIndexMap, /// This is not used for highlighting or rendering any error message. Rather, it can be used /// as a sort key to sort a buffer of diagnostics. By default, it is the primary span of @@ -915,7 +915,7 @@ impl Diagnostic { self } - pub fn replace_args(&mut self, args: FxHashMap) { + pub fn replace_args(&mut self, args: FxIndexMap) { self.args = args; } diff --git a/compiler/rustc_hir_typeck/src/expr.rs b/compiler/rustc_hir_typeck/src/expr.rs index 907c1cc313e57..e895e8c2907cc 100644 --- a/compiler/rustc_hir_typeck/src/expr.rs +++ b/compiler/rustc_hir_typeck/src/expr.rs @@ -24,6 +24,7 @@ use crate::{ use rustc_ast as ast; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::stack::ensure_sufficient_stack; +use rustc_data_structures::unord::UnordMap; use rustc_errors::{ codes::*, pluralize, struct_span_code_err, AddToDiagnostic, Applicability, Diagnostic, DiagnosticBuilder, ErrCode, ErrorGuaranteed, StashKey, @@ -1709,7 +1710,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { .fields .iter_enumerated() .map(|(i, field)| (field.ident(tcx).normalize_to_macros_2_0(), (i, field))) - .collect::>(); + .collect::>(); let mut seen_fields = FxHashMap::default(); @@ -1954,18 +1955,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { &self, adt_ty: Ty<'tcx>, span: Span, - remaining_fields: FxHashMap, + remaining_fields: UnordMap, variant: &'tcx ty::VariantDef, ast_fields: &'tcx [hir::ExprField<'tcx>], args: GenericArgsRef<'tcx>, ) { let len = remaining_fields.len(); - #[allow(rustc::potential_query_instability)] - let mut displayable_field_names: Vec<&str> = - remaining_fields.keys().map(|ident| ident.as_str()).collect(); - // sorting &str primitives here, sort_unstable is ok - displayable_field_names.sort_unstable(); + let displayable_field_names: Vec<&str> = + remaining_fields.items().map(|(ident, _)| ident.as_str()).into_sorted_stable_ord(); let mut truncated_fields_error = String::new(); let remaining_fields_names = match &displayable_field_names[..] { diff --git a/compiler/rustc_lint/src/context.rs b/compiler/rustc_lint/src/context.rs index 30f05444d2103..85b3f46723fa7 100644 --- a/compiler/rustc_lint/src/context.rs +++ b/compiler/rustc_lint/src/context.rs @@ -18,8 +18,9 @@ use self::TargetLint::*; use crate::levels::LintLevelsBuilder; use crate::passes::{EarlyLintPassObject, LateLintPassObject}; -use rustc_data_structures::fx::FxHashMap; +use rustc_data_structures::fx::FxIndexMap; use rustc_data_structures::sync; +use rustc_data_structures::unord::UnordMap; use rustc_errors::{DecorateLint, DiagnosticBuilder, DiagnosticMessage, MultiSpan}; use rustc_feature::Features; use rustc_hir as hir; @@ -69,10 +70,10 @@ pub struct LintStore { pub late_module_passes: Vec>, /// Lints indexed by name. - by_name: FxHashMap, + by_name: UnordMap, /// Map of registered lint groups to what lints they expand to. - lint_groups: FxHashMap<&'static str, LintGroup>, + lint_groups: FxIndexMap<&'static str, LintGroup>, } impl LintStoreMarker for LintStore {} @@ -326,9 +327,11 @@ impl LintStore { /// True if this symbol represents a lint group name. pub fn is_lint_group(&self, lint_name: Symbol) -> bool { - #[allow(rustc::potential_query_instability)] - let lint_groups = self.lint_groups.keys().collect::>(); - debug!("is_lint_group(lint_name={:?}, lint_groups={:?})", lint_name, lint_groups); + debug!( + "is_lint_group(lint_name={:?}, lint_groups={:?})", + lint_name, + self.lint_groups.keys().collect::>() + ); let lint_name_str = lint_name.as_str(); self.lint_groups.contains_key(lint_name_str) || { let warnings_name_str = crate::WARNINGS.name_lower(); @@ -372,12 +375,9 @@ impl LintStore { None => { // 1. The tool is currently running, so this lint really doesn't exist. // FIXME: should this handle tools that never register a lint, like rustfmt? - #[allow(rustc::potential_query_instability)] - let lints = self.by_name.keys().collect::>(); - debug!("lints={:?}", lints); + debug!("lints={:?}", self.by_name.keys().into_sorted_stable_ord()); let tool_prefix = format!("{tool_name}::"); - #[allow(rustc::potential_query_instability)] return if self.by_name.keys().any(|lint| lint.starts_with(&tool_prefix)) { self.no_lint_suggestion(&complete_name, tool_name.as_str()) } else { diff --git a/compiler/rustc_middle/src/mir/mono.rs b/compiler/rustc_middle/src/mir/mono.rs index 6937df7bb1897..eef1b2f14b766 100644 --- a/compiler/rustc_middle/src/mir/mono.rs +++ b/compiler/rustc_middle/src/mir/mono.rs @@ -4,6 +4,7 @@ use rustc_attr::InlineAttr; use rustc_data_structures::base_n; use rustc_data_structures::fingerprint::Fingerprint; use rustc_data_structures::fx::FxHashMap; +use rustc_data_structures::fx::FxIndexMap; use rustc_data_structures::stable_hasher::{Hash128, HashStable, StableHasher}; use rustc_hir::def_id::{CrateNum, DefId, LOCAL_CRATE}; use rustc_hir::ItemId; @@ -241,7 +242,7 @@ pub struct CodegenUnit<'tcx> { /// contain something unique to this crate (e.g., a module path) /// as well as the crate name and disambiguator. name: Symbol, - items: FxHashMap, MonoItemData>, + items: FxIndexMap, MonoItemData>, size_estimate: usize, primary: bool, /// True if this is CGU is used to hold code coverage information for dead code, @@ -316,13 +317,11 @@ impl<'tcx> CodegenUnit<'tcx> { self.primary = true; } - /// The order of these items is non-determinstic. - pub fn items(&self) -> &FxHashMap, MonoItemData> { + pub fn items(&self) -> &FxIndexMap, MonoItemData> { &self.items } - /// The order of these items is non-determinstic. - pub fn items_mut(&mut self) -> &mut FxHashMap, MonoItemData> { + pub fn items_mut(&mut self) -> &mut FxIndexMap, MonoItemData> { &mut self.items } diff --git a/compiler/rustc_monomorphize/src/partitioning.rs b/compiler/rustc_monomorphize/src/partitioning.rs index 5cfebcaa5a5f9..8bebc30e4356a 100644 --- a/compiler/rustc_monomorphize/src/partitioning.rs +++ b/compiler/rustc_monomorphize/src/partitioning.rs @@ -368,7 +368,7 @@ fn merge_codegen_units<'tcx>( // Move the items from `cgu_src` to `cgu_dst`. Some of them may be // duplicate inlined items, in which case the destination CGU is // unaffected. Recalculate size estimates afterwards. - cgu_dst.items_mut().extend(cgu_src.items_mut().drain()); + cgu_dst.items_mut().extend(cgu_src.items_mut().drain(..)); cgu_dst.compute_size_estimate(); // Record that `cgu_dst` now contains all the stuff that was in @@ -407,7 +407,7 @@ fn merge_codegen_units<'tcx>( // Move the items from `smallest` to `second_smallest`. Some of them // may be duplicate inlined items, in which case the destination CGU is // unaffected. Recalculate size estimates afterwards. - second_smallest.items_mut().extend(smallest.items_mut().drain()); + second_smallest.items_mut().extend(smallest.items_mut().drain(..)); second_smallest.compute_size_estimate(); // Don't update `cgu_contents`, that's only for incremental builds. From cafc4c4fbdd0faafe7462ffc3945957244745ac2 Mon Sep 17 00:00:00 2001 From: yukang Date: Mon, 12 Feb 2024 10:17:36 +0800 Subject: [PATCH 2/9] replace FxHashMap with FxIndexMap in rustc_hir_analysis and rustc_errors --- compiler/rustc_errors/src/diagnostic.rs | 3 --- compiler/rustc_hir_analysis/src/astconv/bounds.rs | 4 ++-- compiler/rustc_hir_analysis/src/astconv/errors.rs | 4 ++-- compiler/rustc_hir_analysis/src/astconv/mod.rs | 4 ++-- compiler/rustc_hir_analysis/src/check/check.rs | 2 +- .../src/check/compare_impl_item.rs | 14 +++++++------- compiler/rustc_hir_analysis/src/check/mod.rs | 4 ++-- .../src/coherence/inherent_impls_overlap.rs | 14 +++++++------- compiler/rustc_hir_analysis/src/collect.rs | 2 +- .../rustc_hir_analysis/src/outlives/explicit.rs | 6 +++--- .../src/outlives/implicit_infer.rs | 10 +++++----- 11 files changed, 32 insertions(+), 35 deletions(-) diff --git a/compiler/rustc_errors/src/diagnostic.rs b/compiler/rustc_errors/src/diagnostic.rs index 47ca7bac14869..6570ae3bc3851 100644 --- a/compiler/rustc_errors/src/diagnostic.rs +++ b/compiler/rustc_errors/src/diagnostic.rs @@ -899,9 +899,6 @@ impl Diagnostic { self } - // Exact iteration order of diagnostic arguments shouldn't make a difference to output because - // they're only used in interpolation. - #[allow(rustc::potential_query_instability)] pub fn args(&self) -> impl Iterator> { self.args.iter() } diff --git a/compiler/rustc_hir_analysis/src/astconv/bounds.rs b/compiler/rustc_hir_analysis/src/astconv/bounds.rs index 1ae267d1a4059..3f9c783793e0e 100644 --- a/compiler/rustc_hir_analysis/src/astconv/bounds.rs +++ b/compiler/rustc_hir_analysis/src/astconv/bounds.rs @@ -1,4 +1,4 @@ -use rustc_data_structures::fx::FxHashMap; +use rustc_data_structures::fx::FxIndexMap; use rustc_errors::{codes::*, struct_span_code_err}; use rustc_hir as hir; use rustc_hir::def::{DefKind, Res}; @@ -241,7 +241,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { binding: &ConvertedBinding<'_, 'tcx>, bounds: &mut Bounds<'tcx>, speculative: bool, - dup_bindings: &mut FxHashMap, + dup_bindings: &mut FxIndexMap, path_span: Span, only_self_bounds: OnlySelfBounds, ) -> Result<(), ErrorGuaranteed> { diff --git a/compiler/rustc_hir_analysis/src/astconv/errors.rs b/compiler/rustc_hir_analysis/src/astconv/errors.rs index 3c64b102bae8d..ea8d364bba6c1 100644 --- a/compiler/rustc_hir_analysis/src/astconv/errors.rs +++ b/compiler/rustc_hir_analysis/src/astconv/errors.rs @@ -5,7 +5,7 @@ use crate::errors::{ }; use crate::fluent_generated as fluent; use crate::traits::error_reporting::report_object_safety_error; -use rustc_data_structures::fx::{FxHashMap, FxIndexMap, FxIndexSet}; +use rustc_data_structures::fx::{FxIndexMap, FxIndexSet}; use rustc_data_structures::sorted_map::SortedMap; use rustc_data_structures::unord::UnordMap; use rustc_errors::{ @@ -806,7 +806,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { if suggestions.len() != 1 || already_has_generics_args_suggestion { // We don't need this label if there's an inline suggestion, show otherwise. for (span, assoc_items) in &associated_types { - let mut names: FxHashMap<_, usize> = FxHashMap::default(); + let mut names: FxIndexMap<_, usize> = FxIndexMap::default(); for item in assoc_items { types_count += 1; *names.entry(item.name).or_insert(0) += 1; diff --git a/compiler/rustc_hir_analysis/src/astconv/mod.rs b/compiler/rustc_hir_analysis/src/astconv/mod.rs index a643614d33db5..2028c1e45b0d7 100644 --- a/compiler/rustc_hir_analysis/src/astconv/mod.rs +++ b/compiler/rustc_hir_analysis/src/astconv/mod.rs @@ -16,7 +16,7 @@ use crate::errors::AmbiguousLifetimeBound; use crate::middle::resolve_bound_vars as rbv; use crate::require_c_abi_if_c_variadic; use rustc_ast::TraitObjectSyntax; -use rustc_data_structures::fx::{FxHashMap, FxHashSet}; +use rustc_data_structures::fx::{FxHashSet, FxIndexMap}; use rustc_errors::{ codes::*, struct_span_code_err, Applicability, Diagnostic, DiagnosticBuilder, ErrorGuaranteed, FatalError, MultiSpan, @@ -750,7 +750,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { debug!(?poly_trait_ref, ?assoc_bindings); bounds.push_trait_bound(tcx, poly_trait_ref, span, polarity); - let mut dup_bindings = FxHashMap::default(); + let mut dup_bindings = FxIndexMap::default(); for binding in &assoc_bindings { // Don't register additional associated type bounds for negative bounds, // since we should have emitten an error for them earlier, and they will diff --git a/compiler/rustc_hir_analysis/src/check/check.rs b/compiler/rustc_hir_analysis/src/check/check.rs index f55cba2707c5b..787dc3b4d3276 100644 --- a/compiler/rustc_hir_analysis/src/check/check.rs +++ b/compiler/rustc_hir_analysis/src/check/check.rs @@ -1363,7 +1363,7 @@ fn check_type_alias_type_params_are_used<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalD // `Sized` bounds. If they came last for example, this would break `Trait + /*elab*/Sized` // since it would overwrite the span of the user-written bound. This could be fixed by // folding the spans with `Span::to` which requires a bit of effort I think. - .collect::>() + .collect::>() }); let mut params_used = BitSet::new_empty(generics.params.len()); 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 6edd68f1baebe..e257907e40f56 100644 --- a/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs +++ b/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs @@ -1,7 +1,7 @@ use super::potentially_plural_count; use crate::errors::{LifetimesOrBoundsMismatchOnTrait, MethodShouldReturnFuture}; use hir::def_id::{DefId, DefIdMap, LocalDefId}; -use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexSet}; +use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet}; use rustc_errors::{codes::*, pluralize, struct_span_code_err, Applicability, ErrorGuaranteed}; use rustc_hir as hir; use rustc_hir::def::{DefKind, Res}; @@ -392,7 +392,7 @@ fn compare_method_predicate_entailment<'tcx>( struct RemapLateBound<'a, 'tcx> { tcx: TyCtxt<'tcx>, - mapping: &'a FxHashMap, + mapping: &'a FxIndexMap, } impl<'tcx> TypeFolder> for RemapLateBound<'_, 'tcx> { @@ -553,7 +553,7 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>( // prove below that the hidden types are well formed. let universe = infcx.create_next_universe(); let mut idx = 0; - let mapping: FxHashMap<_, _> = collector + let mapping: FxIndexMap<_, _> = collector .types .iter() .map(|(_, &(ty, _))| { @@ -690,7 +690,7 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>( // contains `def_id`'s early-bound regions. let id_args = GenericArgs::identity_for_item(tcx, def_id); debug!(?id_args, ?args); - let map: FxHashMap<_, _> = std::iter::zip(args, id_args) + let map: FxIndexMap<_, _> = std::iter::zip(args, id_args) .skip(tcx.generics_of(trait_m.def_id).count()) .filter_map(|(a, b)| Some((a.as_region()?, b.as_region()?))) .collect(); @@ -766,7 +766,7 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>( struct ImplTraitInTraitCollector<'a, 'tcx> { ocx: &'a ObligationCtxt<'a, 'tcx>, - types: FxHashMap, ty::GenericArgsRef<'tcx>)>, + types: FxIndexMap, ty::GenericArgsRef<'tcx>)>, span: Span, param_env: ty::ParamEnv<'tcx>, body_id: LocalDefId, @@ -779,7 +779,7 @@ impl<'a, 'tcx> ImplTraitInTraitCollector<'a, 'tcx> { param_env: ty::ParamEnv<'tcx>, body_id: LocalDefId, ) -> Self { - ImplTraitInTraitCollector { ocx, types: FxHashMap::default(), span, param_env, body_id } + ImplTraitInTraitCollector { ocx, types: FxIndexMap::default(), span, param_env, body_id } } } @@ -838,7 +838,7 @@ impl<'tcx> TypeFolder> for ImplTraitInTraitCollector<'_, 'tcx> { struct RemapHiddenTyRegions<'tcx> { tcx: TyCtxt<'tcx>, - map: FxHashMap, ty::Region<'tcx>>, + map: FxIndexMap, ty::Region<'tcx>>, num_trait_args: usize, num_impl_args: usize, def_id: DefId, diff --git a/compiler/rustc_hir_analysis/src/check/mod.rs b/compiler/rustc_hir_analysis/src/check/mod.rs index b74431983113a..992b118a003c1 100644 --- a/compiler/rustc_hir_analysis/src/check/mod.rs +++ b/compiler/rustc_hir_analysis/src/check/mod.rs @@ -76,7 +76,7 @@ pub use check::check_abi; use std::num::NonZeroU32; -use rustc_data_structures::fx::{FxHashMap, FxHashSet}; +use rustc_data_structures::fx::{FxHashSet, FxIndexMap}; use rustc_errors::ErrorGuaranteed; use rustc_errors::{pluralize, struct_span_code_err, Diagnostic, DiagnosticBuilder}; use rustc_hir::def_id::{DefId, LocalDefId}; @@ -307,7 +307,7 @@ fn bounds_from_generic_predicates<'tcx>( tcx: TyCtxt<'tcx>, predicates: impl IntoIterator, Span)>, ) -> (String, String) { - let mut types: FxHashMap, Vec> = FxHashMap::default(); + let mut types: FxIndexMap, Vec> = FxIndexMap::default(); let mut projections = vec![]; for (predicate, _) in predicates { debug!("predicate {:?}", predicate); diff --git a/compiler/rustc_hir_analysis/src/coherence/inherent_impls_overlap.rs b/compiler/rustc_hir_analysis/src/coherence/inherent_impls_overlap.rs index 951440d6a2d0b..9e1e884d9769f 100644 --- a/compiler/rustc_hir_analysis/src/coherence/inherent_impls_overlap.rs +++ b/compiler/rustc_hir_analysis/src/coherence/inherent_impls_overlap.rs @@ -1,4 +1,5 @@ -use rustc_data_structures::fx::{FxHashMap, FxHashSet}; +use rustc_data_structures::fx::IndexEntry; +use rustc_data_structures::fx::{FxHashSet, FxIndexMap}; use rustc_errors::{codes::*, struct_span_code_err}; use rustc_hir as hir; use rustc_hir::def::DefKind; @@ -9,7 +10,6 @@ use rustc_middle::ty::{self, TyCtxt}; use rustc_span::{ErrorGuaranteed, Symbol}; use rustc_trait_selection::traits::{self, SkipLeakCheck}; use smallvec::SmallVec; -use std::collections::hash_map::Entry; pub fn crate_inherent_impls_overlap_check(tcx: TyCtxt<'_>, (): ()) -> Result<(), ErrorGuaranteed> { let mut inherent_overlap_checker = InherentOverlapChecker { tcx }; @@ -63,7 +63,7 @@ impl<'tcx> InherentOverlapChecker<'tcx> { fn check_for_duplicate_items_in_impl(&self, impl_: DefId) -> Result<(), ErrorGuaranteed> { let impl_items = self.tcx.associated_items(impl_); - let mut seen_items = FxHashMap::default(); + let mut seen_items = FxIndexMap::default(); let mut res = Ok(()); for impl_item in impl_items.in_definition_order() { let span = self.tcx.def_span(impl_item.def_id); @@ -71,7 +71,7 @@ impl<'tcx> InherentOverlapChecker<'tcx> { let norm_ident = ident.normalize_to_macros_2_0(); match seen_items.entry(norm_ident) { - Entry::Occupied(entry) => { + IndexEntry::Occupied(entry) => { let former = entry.get(); res = Err(struct_span_code_err!( self.tcx.dcx(), @@ -84,7 +84,7 @@ impl<'tcx> InherentOverlapChecker<'tcx> { .with_span_label(*former, format!("other definition for `{ident}`")) .emit()); } - Entry::Vacant(entry) => { + IndexEntry::Vacant(entry) => { entry.insert(span); } } @@ -216,7 +216,7 @@ impl<'tcx> InherentOverlapChecker<'tcx> { } let mut connected_regions: IndexVec = Default::default(); // Reverse map from the Symbol to the connected region id. - let mut connected_region_ids = FxHashMap::default(); + let mut connected_region_ids = FxIndexMap::default(); for (i, &(&_impl_def_id, impl_items)) in impls_items.iter().enumerate() { if impl_items.len() == 0 { @@ -228,7 +228,7 @@ impl<'tcx> InherentOverlapChecker<'tcx> { .in_definition_order() .filter_map(|item| { let entry = connected_region_ids.entry(item.name); - if let Entry::Occupied(e) = &entry { + if let IndexEntry::Occupied(e) = &entry { Some(*e.get()) } else { idents_to_add.push(item.name); diff --git a/compiler/rustc_hir_analysis/src/collect.rs b/compiler/rustc_hir_analysis/src/collect.rs index d92e1a141516d..21515aa3b9f62 100644 --- a/compiler/rustc_hir_analysis/src/collect.rs +++ b/compiler/rustc_hir_analysis/src/collect.rs @@ -15,7 +15,7 @@ //! crate as a kind of pass. This should eventually be factored away. use rustc_data_structures::captures::Captures; -use rustc_data_structures::fx::{FxHashMap, FxHashSet}; +use rustc_data_structures::fx::{FxHashSet, FxIndexMap}; use rustc_data_structures::unord::UnordMap; use rustc_errors::{Applicability, DiagnosticBuilder, ErrorGuaranteed, StashKey}; use rustc_hir as hir; diff --git a/compiler/rustc_hir_analysis/src/outlives/explicit.rs b/compiler/rustc_hir_analysis/src/outlives/explicit.rs index a7fca41f86aca..1de7a0f7bc739 100644 --- a/compiler/rustc_hir_analysis/src/outlives/explicit.rs +++ b/compiler/rustc_hir_analysis/src/outlives/explicit.rs @@ -1,4 +1,4 @@ -use rustc_data_structures::fx::FxHashMap; +use rustc_data_structures::fx::FxIndexMap; use rustc_hir::def_id::DefId; use rustc_middle::ty::{self, OutlivesPredicate, TyCtxt}; @@ -6,12 +6,12 @@ use super::utils::*; #[derive(Debug)] pub struct ExplicitPredicatesMap<'tcx> { - map: FxHashMap>>, + map: FxIndexMap>>, } impl<'tcx> ExplicitPredicatesMap<'tcx> { pub fn new() -> ExplicitPredicatesMap<'tcx> { - ExplicitPredicatesMap { map: FxHashMap::default() } + ExplicitPredicatesMap { map: FxIndexMap::default() } } pub(crate) fn explicit_predicates_of( diff --git a/compiler/rustc_hir_analysis/src/outlives/implicit_infer.rs b/compiler/rustc_hir_analysis/src/outlives/implicit_infer.rs index 0cb38094ceca5..2429becfd1950 100644 --- a/compiler/rustc_hir_analysis/src/outlives/implicit_infer.rs +++ b/compiler/rustc_hir_analysis/src/outlives/implicit_infer.rs @@ -1,4 +1,4 @@ -use rustc_data_structures::fx::FxHashMap; +use rustc_data_structures::fx::FxIndexMap; use rustc_hir::def::DefKind; use rustc_hir::def_id::DefId; use rustc_middle::ty::{self, Ty, TyCtxt}; @@ -15,12 +15,12 @@ use super::utils::*; /// now be filled with inferred predicates. pub(super) fn infer_predicates( tcx: TyCtxt<'_>, -) -> FxHashMap>> { +) -> FxIndexMap>> { debug!("infer_predicates"); let mut explicit_map = ExplicitPredicatesMap::new(); - let mut global_inferred_outlives = FxHashMap::default(); + let mut global_inferred_outlives = FxIndexMap::default(); // If new predicates were added then we need to re-calculate // all crates since there could be new implied predicates. @@ -101,7 +101,7 @@ fn insert_required_predicates_to_be_wf<'tcx>( tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, span: Span, - global_inferred_outlives: &FxHashMap>>, + global_inferred_outlives: &FxIndexMap>>, required_predicates: &mut RequiredPredicates<'tcx>, explicit_map: &mut ExplicitPredicatesMap<'tcx>, ) { @@ -322,7 +322,7 @@ fn check_inferred_predicates<'tcx>( tcx: TyCtxt<'tcx>, def_id: DefId, args: ty::GenericArgsRef<'tcx>, - global_inferred_outlives: &FxHashMap>>, + global_inferred_outlives: &FxIndexMap>>, required_predicates: &mut RequiredPredicates<'tcx>, ) { // Load the current set of inferred and explicit predicates from `global_inferred_outlives` From f10418a94fd69531f4e630a4209b15a8564037b2 Mon Sep 17 00:00:00 2001 From: yukang Date: Mon, 12 Feb 2024 10:21:03 +0800 Subject: [PATCH 3/9] cleanup comments --- compiler/rustc_lint/src/context.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/compiler/rustc_lint/src/context.rs b/compiler/rustc_lint/src/context.rs index 85b3f46723fa7..0a233e8ec721e 100644 --- a/compiler/rustc_lint/src/context.rs +++ b/compiler/rustc_lint/src/context.rs @@ -153,8 +153,6 @@ impl LintStore { pub fn get_lint_groups<'t>( &'t self, ) -> impl Iterator, bool)> + 't { - // This function is not used in a way which observes the order of lints. - #[allow(rustc::potential_query_instability)] self.lint_groups .iter() .filter(|(_, LintGroup { depr, .. })| { From 4710453624291a78d2b12f02c61f057e8bc4b5c7 Mon Sep 17 00:00:00 2001 From: yukang Date: Mon, 12 Feb 2024 10:37:16 +0800 Subject: [PATCH 4/9] more replace FxHashMap with FxIndexMap --- compiler/rustc_interface/src/passes.rs | 6 +----- compiler/rustc_lint/src/context.rs | 2 -- compiler/rustc_lint/src/non_ascii_idents.rs | 7 ------- compiler/rustc_session/src/parse.rs | 23 +++++++++------------ 4 files changed, 11 insertions(+), 27 deletions(-) diff --git a/compiler/rustc_interface/src/passes.rs b/compiler/rustc_interface/src/passes.rs index 50b2bf7da153e..28065b3d6f2e2 100644 --- a/compiler/rustc_interface/src/passes.rs +++ b/compiler/rustc_interface/src/passes.rs @@ -306,10 +306,7 @@ fn early_lint_checks(tcx: TyCtxt<'_>, (): ()) { // Gate identifiers containing invalid Unicode codepoints that were recovered during lexing. sess.parse_sess.bad_unicode_identifiers.with_lock(|identifiers| { - // We will soon sort, so the initial order does not matter. - #[allow(rustc::potential_query_instability)] - let mut identifiers: Vec<_> = identifiers.drain().collect(); - identifiers.sort_by_key(|&(key, _)| key); + let identifiers: Vec<_> = identifiers.drain(..).collect(); for (ident, mut spans) in identifiers.into_iter() { spans.sort(); if ident == sym::ferris { @@ -435,7 +432,6 @@ fn write_out_deps(tcx: TyCtxt<'_>, outputs: &OutputFilenames, out_filenames: &[P // The entries will be used to declare dependencies beween files in a // Makefile-like output, so the iteration order does not matter. - #[allow(rustc::potential_query_instability)] let extra_tracked_files = file_depinfo.iter().map(|path_sym| normalize_path(PathBuf::from(path_sym.as_str()))); files.extend(extra_tracked_files); diff --git a/compiler/rustc_lint/src/context.rs b/compiler/rustc_lint/src/context.rs index 0a233e8ec721e..4f1a97f8017ce 100644 --- a/compiler/rustc_lint/src/context.rs +++ b/compiler/rustc_lint/src/context.rs @@ -431,8 +431,6 @@ impl LintStore { // Note: find_best_match_for_name depends on the sort order of its input vector. // To ensure deterministic output, sort elements of the lint_groups hash map. // Also, never suggest deprecated lint groups. - // We will soon sort, so the initial order does not matter. - #[allow(rustc::potential_query_instability)] let mut groups: Vec<_> = self .lint_groups .iter() diff --git a/compiler/rustc_lint/src/non_ascii_idents.rs b/compiler/rustc_lint/src/non_ascii_idents.rs index f78b32ce5e77b..08ff1352d1129 100644 --- a/compiler/rustc_lint/src/non_ascii_idents.rs +++ b/compiler/rustc_lint/src/non_ascii_idents.rs @@ -175,11 +175,8 @@ impl EarlyLintPass for NonAsciiIdents { // Sort by `Span` so that error messages make sense with respect to the // order of identifier locations in the code. - // We will soon sort, so the initial order does not matter. - #[allow(rustc::potential_query_instability)] let mut symbols: Vec<_> = symbols.iter().collect(); symbols.sort_by_key(|k| k.1); - for (symbol, &sp) in symbols.iter() { let symbol_str = symbol.as_str(); if symbol_str.is_ascii() { @@ -300,8 +297,6 @@ impl EarlyLintPass for NonAsciiIdents { } if has_suspicious { - // The end result is put in `lint_reports` which is sorted. - #[allow(rustc::potential_query_instability)] let verified_augmented_script_sets = script_states .iter() .flat_map(|(k, v)| match v { @@ -314,8 +309,6 @@ impl EarlyLintPass for NonAsciiIdents { let mut lint_reports: BTreeMap<(Span, Vec), AugmentedScriptSet> = BTreeMap::new(); - // The end result is put in `lint_reports` which is sorted. - #[allow(rustc::potential_query_instability)] 'outerloop: for (augment_script_set, usage) in script_states { let ScriptSetUsage::Suspicious(mut ch_list, sp) = usage else { continue }; diff --git a/compiler/rustc_session/src/parse.rs b/compiler/rustc_session/src/parse.rs index 8adb0cbcc9d76..7e73a658221e0 100644 --- a/compiler/rustc_session/src/parse.rs +++ b/compiler/rustc_session/src/parse.rs @@ -11,7 +11,7 @@ use crate::lint::{ }; use crate::Session; use rustc_ast::node_id::NodeId; -use rustc_data_structures::fx::{FxHashMap, FxHashSet}; +use rustc_data_structures::fx::{FxIndexMap, FxIndexSet}; use rustc_data_structures::sync::{AppendOnlyVec, Lock, Lrc}; use rustc_errors::{emitter::SilentEmitter, DiagCtxt}; use rustc_errors::{ @@ -30,7 +30,7 @@ use std::str; /// used and should be feature gated accordingly in `check_crate`. #[derive(Default)] pub struct GatedSpans { - pub spans: Lock>>, + pub spans: Lock>>, } impl GatedSpans { @@ -50,12 +50,9 @@ impl GatedSpans { } /// Prepend the given set of `spans` onto the set in `self`. - pub fn merge(&self, mut spans: FxHashMap>) { + pub fn merge(&self, mut spans: FxIndexMap>) { let mut inner = self.spans.borrow_mut(); - // The entries will be moved to another map so the drain order does not - // matter. - #[allow(rustc::potential_query_instability)] - for (gate, mut gate_spans) in inner.drain() { + for (gate, mut gate_spans) in inner.drain(..) { spans.entry(gate).or_default().append(&mut gate_spans); } *inner = spans; @@ -65,7 +62,7 @@ impl GatedSpans { #[derive(Default)] pub struct SymbolGallery { /// All symbols occurred and their first occurrence span. - pub symbols: Lock>, + pub symbols: Lock>, } impl SymbolGallery { @@ -205,19 +202,19 @@ pub struct ParseSess { /// Places where identifiers that contain invalid Unicode codepoints but that look like they /// should be. Useful to avoid bad tokenization when encountering emoji. We group them to /// provide a single error per unique incorrect identifier. - pub bad_unicode_identifiers: Lock>>, + pub bad_unicode_identifiers: Lock>>, source_map: Lrc, pub buffered_lints: Lock>, /// Contains the spans of block expressions that could have been incomplete based on the /// operation token that followed it, but that the parser cannot identify without further /// analysis. - pub ambiguous_block_expr_parse: Lock>, + pub ambiguous_block_expr_parse: Lock>, pub gated_spans: GatedSpans, pub symbol_gallery: SymbolGallery, /// Environment variables accessed during the build and their values when they exist. - pub env_depinfo: Lock)>>, + pub env_depinfo: Lock)>>, /// File paths accessed during the build. - pub file_depinfo: Lock>, + pub file_depinfo: Lock>, /// Whether cfg(version) should treat the current release as incomplete pub assume_incomplete_release: bool, /// Spans passed to `proc_macro::quote_span`. Each span has a numerical @@ -247,7 +244,7 @@ impl ParseSess { bad_unicode_identifiers: Lock::new(Default::default()), source_map, buffered_lints: Lock::new(vec![]), - ambiguous_block_expr_parse: Lock::new(FxHashMap::default()), + ambiguous_block_expr_parse: Lock::new(Default::default()), gated_spans: GatedSpans::default(), symbol_gallery: SymbolGallery::default(), env_depinfo: Default::default(), From c6cb992c83295c0d7446240ffd320d9c2f1ff35e Mon Sep 17 00:00:00 2001 From: yukang Date: Mon, 12 Feb 2024 11:00:40 +0800 Subject: [PATCH 5/9] bless error messages --- tests/ui/parser/emoji-identifiers.stderr | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/ui/parser/emoji-identifiers.stderr b/tests/ui/parser/emoji-identifiers.stderr index 8250dd1ea2e92..1fc561d32c63d 100644 --- a/tests/ui/parser/emoji-identifiers.stderr +++ b/tests/ui/parser/emoji-identifiers.stderr @@ -9,14 +9,6 @@ help: Unicode character 'โž–' (Heavy Minus Sign) looks like '-' (Minus/Hyphen), LL | let _ = i_like_to_๐Ÿ˜„_a_lot() - 4; | ~ -error: Ferris cannot be used as an identifier - --> $DIR/emoji-identifiers.rs:17:9 - | -LL | let ๐Ÿฆ€ = 1; - | ^^ help: try using their name instead: `ferris` -LL | dbg!(๐Ÿฆ€); - | ^^ - error: identifiers cannot contain emoji: `ABig๐Ÿ‘ฉ๐Ÿ‘ฉ๐Ÿ‘ง๐Ÿ‘งFamily` --> $DIR/emoji-identifiers.rs:1:8 | @@ -64,6 +56,14 @@ error: identifiers cannot contain emoji: `i_like_to_๐Ÿ˜„_a_lot` LL | let _ = i_like_to_๐Ÿ˜„_a_lot() โž– 4; | ^^^^^^^^^^^^^^^^^^ +error: Ferris cannot be used as an identifier + --> $DIR/emoji-identifiers.rs:17:9 + | +LL | let ๐Ÿฆ€ = 1; + | ^^ help: try using their name instead: `ferris` +LL | dbg!(๐Ÿฆ€); + | ^^ + error[E0599]: no function or associated item named `full_ofโœจ` found for struct `๐Ÿ‘€` in the current scope --> $DIR/emoji-identifiers.rs:9:8 | From 44792be9770a57c4725d4886d14e4f5cb1d023ec Mon Sep 17 00:00:00 2001 From: yukang Date: Tue, 13 Feb 2024 05:47:25 +0800 Subject: [PATCH 6/9] fix rebase conflicts --- compiler/rustc_codegen_ssa/src/back/link.rs | 3 +-- compiler/rustc_codegen_ssa/src/base.rs | 2 -- compiler/rustc_hir_analysis/src/collect.rs | 4 ++-- compiler/rustc_lint/src/context.rs | 2 +- 4 files changed, 4 insertions(+), 7 deletions(-) diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs index 83343cd39bec1..f05bcd8e39c8e 100644 --- a/compiler/rustc_codegen_ssa/src/back/link.rs +++ b/compiler/rustc_codegen_ssa/src/back/link.rs @@ -1,7 +1,6 @@ use rustc_arena::TypedArena; use rustc_ast::CRATE_NODE_ID; -use rustc_data_structures::fx::FxIndexMap; -use rustc_data_structures::fx::FxIndexSet; +use rustc_data_structures::fx::{FxIndexMap, FxIndexSet}; use rustc_data_structures::memmap::Mmap; use rustc_data_structures::temp_dir::MaybeTempDir; use rustc_errors::{DiagCtxt, ErrorGuaranteed}; diff --git a/compiler/rustc_codegen_ssa/src/base.rs b/compiler/rustc_codegen_ssa/src/base.rs index 5e99ff9a6c0b5..af87857d96987 100644 --- a/compiler/rustc_codegen_ssa/src/base.rs +++ b/compiler/rustc_codegen_ssa/src/base.rs @@ -912,8 +912,6 @@ impl CrateInfo { .collect(); let prefix = if target.is_like_windows && target.arch == "x86" { "_" } else { "" }; - // This loop only adds new items to values of the hash map, so the order in which we - // iterate over the values is not important. info.linked_symbols .iter_mut() .filter(|(crate_type, _)| { diff --git a/compiler/rustc_hir_analysis/src/collect.rs b/compiler/rustc_hir_analysis/src/collect.rs index 21515aa3b9f62..5346dcccdc71f 100644 --- a/compiler/rustc_hir_analysis/src/collect.rs +++ b/compiler/rustc_hir_analysis/src/collect.rs @@ -835,12 +835,12 @@ impl From for FieldDeclSpan { struct FieldUniquenessCheckContext<'tcx> { tcx: TyCtxt<'tcx>, - seen_fields: FxHashMap, + seen_fields: FxIndexMap, } impl<'tcx> FieldUniquenessCheckContext<'tcx> { fn new(tcx: TyCtxt<'tcx>) -> Self { - Self { tcx, seen_fields: FxHashMap::default() } + Self { tcx, seen_fields: FxIndexMap::default() } } /// Check if a given field `ident` declared at `field_decl` has been declared elsewhere before. diff --git a/compiler/rustc_lint/src/context.rs b/compiler/rustc_lint/src/context.rs index 4f1a97f8017ce..00ed6fa6b6464 100644 --- a/compiler/rustc_lint/src/context.rs +++ b/compiler/rustc_lint/src/context.rs @@ -373,7 +373,7 @@ impl LintStore { None => { // 1. The tool is currently running, so this lint really doesn't exist. // FIXME: should this handle tools that never register a lint, like rustfmt? - debug!("lints={:?}", self.by_name.keys().into_sorted_stable_ord()); + debug!("lints={:?}", self.by_name); let tool_prefix = format!("{tool_name}::"); return if self.by_name.keys().any(|lint| lint.starts_with(&tool_prefix)) { From ced5d6dda480192ef783124a62ece1a50e3e8cbc Mon Sep 17 00:00:00 2001 From: yukang Date: Wed, 14 Feb 2024 10:10:46 +0800 Subject: [PATCH 7/9] remove uncessary collect --- compiler/rustc_borrowck/src/region_infer/values.rs | 8 ++++++-- compiler/rustc_borrowck/src/type_check/mod.rs | 1 + compiler/rustc_codegen_ssa/src/back/link.rs | 4 ++-- .../rustc_codegen_ssa/src/back/symbol_export.rs | 1 + compiler/rustc_codegen_ssa/src/base.rs | 1 + compiler/rustc_const_eval/src/interpret/memory.rs | 1 + compiler/rustc_interface/src/passes.rs | 4 ++-- compiler/rustc_lint/src/non_ascii_idents.rs | 6 ++++++ compiler/rustc_session/src/parse.rs | 13 ++++++++----- 9 files changed, 28 insertions(+), 11 deletions(-) diff --git a/compiler/rustc_borrowck/src/region_infer/values.rs b/compiler/rustc_borrowck/src/region_infer/values.rs index 82b96b3efd542..ca86b1ab13acb 100644 --- a/compiler/rustc_borrowck/src/region_infer/values.rs +++ b/compiler/rustc_borrowck/src/region_infer/values.rs @@ -1,4 +1,4 @@ -use rustc_data_structures::fx::FxIndexSet; +use rustc_data_structures::fx::{FxHashSet, FxIndexSet}; use rustc_index::bit_set::SparseBitMatrix; use rustc_index::interval::IntervalSet; use rustc_index::interval::SparseIntervalMatrix; @@ -41,7 +41,7 @@ pub(crate) struct LivenessValues { /// Which regions are live. This is exclusive with the fine-grained tracking in `points`, and /// currently only used for validating promoteds (which don't care about more precise tracking). - live_regions: Option>, + live_regions: Option>, /// For each region: the points where it is live. /// @@ -103,6 +103,10 @@ impl LivenessValues { self.points.as_ref().expect("use with_specific_points").rows() } + /// Iterate through each region that has a value in this set. + // We are passing query instability implications to the caller. + #[rustc_lint_query_instability] + #[allow(rustc::potential_query_instability)] pub(crate) fn live_regions_unordered(&self) -> impl Iterator + '_ { self.live_regions.as_ref().unwrap().iter().copied() } diff --git a/compiler/rustc_borrowck/src/type_check/mod.rs b/compiler/rustc_borrowck/src/type_check/mod.rs index ab42f76b48eda..cfb46f3ac8a96 100644 --- a/compiler/rustc_borrowck/src/type_check/mod.rs +++ b/compiler/rustc_borrowck/src/type_check/mod.rs @@ -599,6 +599,7 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> { // // add_location doesn't care about ordering so not a problem for the live regions to be // unordered. + #[allow(rustc::potential_query_instability)] for region in liveness_constraints.live_regions_unordered() { self.cx .borrowck_context diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs index f05bcd8e39c8e..435b517e602b1 100644 --- a/compiler/rustc_codegen_ssa/src/back/link.rs +++ b/compiler/rustc_codegen_ssa/src/back/link.rs @@ -563,8 +563,7 @@ fn link_staticlib<'a>( .extract_bundled_libs(path, tempdir.as_ref(), &relevant_libs) .unwrap_or_else(|e| sess.dcx().emit_fatal(e)); - let relevant_libs: Vec = relevant_libs.into_iter().collect(); - for filename in relevant_libs { + for filename in relevant_libs.iter() { let joined = tempdir.as_ref().join(filename.as_str()); let path = joined.as_path(); ab.add_archive(path, Box::new(|_| false)).unwrap(); @@ -2215,6 +2214,7 @@ fn linker_with_args<'a>( .expect("failed to find crate type in dependency format list"); // We sort the libraries below + #[allow(rustc::potential_query_instability)] let mut native_libraries_from_nonstatics = codegen_results .crate_info .native_libraries diff --git a/compiler/rustc_codegen_ssa/src/back/symbol_export.rs b/compiler/rustc_codegen_ssa/src/back/symbol_export.rs index a36bfa2d7e383..2dba04e0bb71b 100644 --- a/compiler/rustc_codegen_ssa/src/back/symbol_export.rs +++ b/compiler/rustc_codegen_ssa/src/back/symbol_export.rs @@ -320,6 +320,7 @@ fn exported_symbols_provider_local( let (_, cgus) = tcx.collect_and_partition_mono_items(()); // The symbols created in this loop are sorted below it + #[allow(rustc::potential_query_instability)] for (mono_item, data) in cgus.iter().flat_map(|cgu| cgu.items().iter()) { if data.linkage != Linkage::External { // We can only re-use things with external linkage, otherwise diff --git a/compiler/rustc_codegen_ssa/src/base.rs b/compiler/rustc_codegen_ssa/src/base.rs index af87857d96987..079c0f6ac1462 100644 --- a/compiler/rustc_codegen_ssa/src/base.rs +++ b/compiler/rustc_codegen_ssa/src/base.rs @@ -912,6 +912,7 @@ impl CrateInfo { .collect(); let prefix = if target.is_like_windows && target.arch == "x86" { "_" } else { "" }; + #[allow(rustc::potential_query_instability)] info.linked_symbols .iter_mut() .filter(|(crate_type, _)| { diff --git a/compiler/rustc_const_eval/src/interpret/memory.rs b/compiler/rustc_const_eval/src/interpret/memory.rs index 53253a8906dc5..a59429bfaacb3 100644 --- a/compiler/rustc_const_eval/src/interpret/memory.rs +++ b/compiler/rustc_const_eval/src/interpret/memory.rs @@ -514,6 +514,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { // Unlike all the other GC helpers where we check if an `AllocId` is found in the interpreter or // is live, here all the IDs in the map are for dead allocations so we don't // need to check for liveness. + #[allow(rustc::potential_query_instability)] // Only used from Miri, not queries. self.memory.dead_alloc_map.retain(|id, _| reachable_allocs.contains(id)); } } diff --git a/compiler/rustc_interface/src/passes.rs b/compiler/rustc_interface/src/passes.rs index 28065b3d6f2e2..33f406631487f 100644 --- a/compiler/rustc_interface/src/passes.rs +++ b/compiler/rustc_interface/src/passes.rs @@ -306,8 +306,7 @@ fn early_lint_checks(tcx: TyCtxt<'_>, (): ()) { // Gate identifiers containing invalid Unicode codepoints that were recovered during lexing. sess.parse_sess.bad_unicode_identifiers.with_lock(|identifiers| { - let identifiers: Vec<_> = identifiers.drain(..).collect(); - for (ident, mut spans) in identifiers.into_iter() { + for (ident, mut spans) in identifiers.drain(..) { spans.sort(); if ident == sym::ferris { let first_span = spans[0]; @@ -437,6 +436,7 @@ fn write_out_deps(tcx: TyCtxt<'_>, outputs: &OutputFilenames, out_filenames: &[P files.extend(extra_tracked_files); // We also need to track used PGO profile files + #[allow(rustc::potential_query_instability)] if let Some(ref profile_instr) = sess.opts.cg.profile_use { files.push(normalize_path(profile_instr.as_path().to_path_buf())); } diff --git a/compiler/rustc_lint/src/non_ascii_idents.rs b/compiler/rustc_lint/src/non_ascii_idents.rs index 08ff1352d1129..e112cd6915c35 100644 --- a/compiler/rustc_lint/src/non_ascii_idents.rs +++ b/compiler/rustc_lint/src/non_ascii_idents.rs @@ -175,6 +175,8 @@ impl EarlyLintPass for NonAsciiIdents { // Sort by `Span` so that error messages make sense with respect to the // order of identifier locations in the code. + // We will soon sort, so the initial order does not matter. + #[allow(rustc::potential_query_instability)] let mut symbols: Vec<_> = symbols.iter().collect(); symbols.sort_by_key(|k| k.1); for (symbol, &sp) in symbols.iter() { @@ -297,6 +299,8 @@ impl EarlyLintPass for NonAsciiIdents { } if has_suspicious { + // The end result is put in `lint_reports` which is sorted. + #[allow(rustc::potential_query_instability)] let verified_augmented_script_sets = script_states .iter() .flat_map(|(k, v)| match v { @@ -309,6 +313,8 @@ impl EarlyLintPass for NonAsciiIdents { let mut lint_reports: BTreeMap<(Span, Vec), AugmentedScriptSet> = BTreeMap::new(); + // The end result is put in `lint_reports` which is sorted. + #[allow(rustc::potential_query_instability)] 'outerloop: for (augment_script_set, usage) in script_states { let ScriptSetUsage::Suspicious(mut ch_list, sp) = usage else { continue }; diff --git a/compiler/rustc_session/src/parse.rs b/compiler/rustc_session/src/parse.rs index 7e73a658221e0..288e0a5ca6f30 100644 --- a/compiler/rustc_session/src/parse.rs +++ b/compiler/rustc_session/src/parse.rs @@ -11,7 +11,7 @@ use crate::lint::{ }; use crate::Session; use rustc_ast::node_id::NodeId; -use rustc_data_structures::fx::{FxIndexMap, FxIndexSet}; +use rustc_data_structures::fx::{FxHashMap, FxIndexMap, FxIndexSet}; use rustc_data_structures::sync::{AppendOnlyVec, Lock, Lrc}; use rustc_errors::{emitter::SilentEmitter, DiagCtxt}; use rustc_errors::{ @@ -30,7 +30,7 @@ use std::str; /// used and should be feature gated accordingly in `check_crate`. #[derive(Default)] pub struct GatedSpans { - pub spans: Lock>>, + pub spans: Lock>>, } impl GatedSpans { @@ -50,9 +50,12 @@ impl GatedSpans { } /// Prepend the given set of `spans` onto the set in `self`. - pub fn merge(&self, mut spans: FxIndexMap>) { + pub fn merge(&self, mut spans: FxHashMap>) { let mut inner = self.spans.borrow_mut(); - for (gate, mut gate_spans) in inner.drain(..) { + // The entries will be moved to another map so the drain order does not + // matter. + #[allow(rustc::potential_query_instability)] + for (gate, mut gate_spans) in inner.drain() { spans.entry(gate).or_default().append(&mut gate_spans); } *inner = spans; @@ -62,7 +65,7 @@ impl GatedSpans { #[derive(Default)] pub struct SymbolGallery { /// All symbols occurred and their first occurrence span. - pub symbols: Lock>, + pub symbols: Lock>, } impl SymbolGallery { From dd327f527ce57a905150bf74026176eb82e490ee Mon Sep 17 00:00:00 2001 From: yukang Date: Wed, 14 Feb 2024 10:43:01 +0800 Subject: [PATCH 8/9] rollback comments --- compiler/rustc_interface/src/passes.rs | 2 +- compiler/rustc_lint/src/context.rs | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_interface/src/passes.rs b/compiler/rustc_interface/src/passes.rs index 33f406631487f..60d13f02ad7b5 100644 --- a/compiler/rustc_interface/src/passes.rs +++ b/compiler/rustc_interface/src/passes.rs @@ -431,12 +431,12 @@ fn write_out_deps(tcx: TyCtxt<'_>, outputs: &OutputFilenames, out_filenames: &[P // The entries will be used to declare dependencies beween files in a // Makefile-like output, so the iteration order does not matter. + #[allow(rustc::potential_query_instability)] let extra_tracked_files = file_depinfo.iter().map(|path_sym| normalize_path(PathBuf::from(path_sym.as_str()))); files.extend(extra_tracked_files); // We also need to track used PGO profile files - #[allow(rustc::potential_query_instability)] if let Some(ref profile_instr) = sess.opts.cg.profile_use { files.push(normalize_path(profile_instr.as_path().to_path_buf())); } diff --git a/compiler/rustc_lint/src/context.rs b/compiler/rustc_lint/src/context.rs index 00ed6fa6b6464..5e27a0ed81884 100644 --- a/compiler/rustc_lint/src/context.rs +++ b/compiler/rustc_lint/src/context.rs @@ -431,6 +431,8 @@ impl LintStore { // Note: find_best_match_for_name depends on the sort order of its input vector. // To ensure deterministic output, sort elements of the lint_groups hash map. // Also, never suggest deprecated lint groups. + // We will soon sort, so the initial order does not matter. + #[allow(rustc::potential_query_instability)] let mut groups: Vec<_> = self .lint_groups .iter() From 1e32922b5bd3862252dc995f92ff04e578d6a3dc Mon Sep 17 00:00:00 2001 From: yukang Date: Wed, 14 Feb 2024 10:49:51 +0800 Subject: [PATCH 9/9] use BTreeMap --- compiler/rustc_borrowck/src/region_infer/values.rs | 3 ++- compiler/rustc_codegen_llvm/src/back/lto.rs | 8 ++++---- compiler/rustc_codegen_ssa/src/base.rs | 2 ++ 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_borrowck/src/region_infer/values.rs b/compiler/rustc_borrowck/src/region_infer/values.rs index ca86b1ab13acb..b1caaa6388186 100644 --- a/compiler/rustc_borrowck/src/region_infer/values.rs +++ b/compiler/rustc_borrowck/src/region_infer/values.rs @@ -1,4 +1,5 @@ -use rustc_data_structures::fx::{FxHashSet, FxIndexSet}; +use rustc_data_structures::fx::FxHashSet; +use rustc_data_structures::fx::FxIndexSet; use rustc_index::bit_set::SparseBitMatrix; use rustc_index::interval::IntervalSet; use rustc_index::interval::SparseIntervalMatrix; diff --git a/compiler/rustc_codegen_llvm/src/back/lto.rs b/compiler/rustc_codegen_llvm/src/back/lto.rs index 886d8901c0149..06a681c24e697 100644 --- a/compiler/rustc_codegen_llvm/src/back/lto.rs +++ b/compiler/rustc_codegen_llvm/src/back/lto.rs @@ -14,7 +14,6 @@ use rustc_codegen_ssa::traits::*; use rustc_codegen_ssa::{looks_like_rust_object_file, ModuleCodegen, ModuleKind}; use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::memmap::Mmap; -use rustc_data_structures::unord::UnordMap; use rustc_errors::{DiagCtxt, FatalError}; use rustc_hir::def_id::LOCAL_CRATE; use rustc_middle::bug; @@ -22,6 +21,7 @@ use rustc_middle::dep_graph::WorkProduct; use rustc_middle::middle::exported_symbols::{SymbolExportInfo, SymbolExportLevel}; use rustc_session::config::{self, CrateType, Lto}; +use std::collections::BTreeMap; use std::ffi::{CStr, CString}; use std::fs::File; use std::io; @@ -788,7 +788,7 @@ pub unsafe fn optimize_thin_module( #[derive(Debug, Default)] pub struct ThinLTOKeysMap { // key = llvm name of importing module, value = LLVM cache key - keys: UnordMap, + keys: BTreeMap, } impl ThinLTOKeysMap { @@ -798,7 +798,7 @@ impl ThinLTOKeysMap { let mut writer = io::BufWriter::new(file); // The entries are loaded back into a hash map in `load_from_file()`, so // the order in which we write them to file here does not matter. - for (module, key) in self.keys.items().into_sorted_stable_ord() { + for (module, key) in &self.keys { writeln!(writer, "{module} {key}")?; } Ok(()) @@ -806,7 +806,7 @@ impl ThinLTOKeysMap { fn load_from_file(path: &Path) -> io::Result { use std::io::BufRead; - let mut keys = UnordMap::default(); + let mut keys = BTreeMap::default(); let file = File::open(path)?; for line in io::BufReader::new(file).lines() { let line = line?; diff --git a/compiler/rustc_codegen_ssa/src/base.rs b/compiler/rustc_codegen_ssa/src/base.rs index 079c0f6ac1462..760b3f30ee51e 100644 --- a/compiler/rustc_codegen_ssa/src/base.rs +++ b/compiler/rustc_codegen_ssa/src/base.rs @@ -912,6 +912,8 @@ impl CrateInfo { .collect(); let prefix = if target.is_like_windows && target.arch == "x86" { "_" } else { "" }; + // This loop only adds new items to values of the hash map, so the order in which we + // iterate over the values is not important. #[allow(rustc::potential_query_instability)] info.linked_symbols .iter_mut()