Skip to content

Commit 99853c7

Browse files
committed
clean up potential_query_instability with FxIndexMap and UnordMap
1 parent 9aa232e commit 99853c7

File tree

14 files changed

+51
-56
lines changed

14 files changed

+51
-56
lines changed

compiler/rustc_borrowck/src/region_infer/values.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use rustc_data_structures::fx::FxHashSet;
21
use rustc_data_structures::fx::FxIndexSet;
32
use rustc_index::bit_set::SparseBitMatrix;
43
use rustc_index::interval::IntervalSet;
@@ -42,7 +41,7 @@ pub(crate) struct LivenessValues {
4241

4342
/// Which regions are live. This is exclusive with the fine-grained tracking in `points`, and
4443
/// currently only used for validating promoteds (which don't care about more precise tracking).
45-
live_regions: Option<FxHashSet<RegionVid>>,
44+
live_regions: Option<FxIndexSet<RegionVid>>,
4645

4746
/// For each region: the points where it is live.
4847
///
@@ -104,10 +103,6 @@ impl LivenessValues {
104103
self.points.as_ref().expect("use with_specific_points").rows()
105104
}
106105

107-
/// Iterate through each region that has a value in this set.
108-
// We are passing query instability implications to the caller.
109-
#[rustc_lint_query_instability]
110-
#[allow(rustc::potential_query_instability)]
111106
pub(crate) fn live_regions_unordered(&self) -> impl Iterator<Item = RegionVid> + '_ {
112107
self.live_regions.as_ref().unwrap().iter().copied()
113108
}

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,6 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
599599
//
600600
// add_location doesn't care about ordering so not a problem for the live regions to be
601601
// unordered.
602-
#[allow(rustc::potential_query_instability)]
603602
for region in liveness_constraints.live_regions_unordered() {
604603
self.cx
605604
.borrowck_context

compiler/rustc_borrowck/src/universal_regions.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#![allow(rustc::diagnostic_outside_of_impl)]
1616
#![allow(rustc::untranslatable_diagnostic)]
1717

18-
use rustc_data_structures::fx::FxHashMap;
18+
use rustc_data_structures::fx::FxIndexMap;
1919
use rustc_errors::Diagnostic;
2020
use rustc_hir::def_id::{DefId, LocalDefId};
2121
use rustc_hir::lang_items::LangItem;
@@ -180,7 +180,7 @@ struct UniversalRegionIndices<'tcx> {
180180
/// basically equivalent to an `GenericArgs`, except that it also
181181
/// contains an entry for `ReStatic` -- it might be nice to just
182182
/// use an args, and then handle `ReStatic` another way.
183-
indices: FxHashMap<ty::Region<'tcx>, RegionVid>,
183+
indices: FxIndexMap<ty::Region<'tcx>, RegionVid>,
184184

185185
/// The vid assigned to `'static`. Used only for diagnostics.
186186
pub fr_static: RegionVid,
@@ -327,7 +327,6 @@ impl<'tcx> UniversalRegions<'tcx> {
327327
/// Gets an iterator over all the early-bound regions that have names.
328328
/// Iteration order may be unstable, so this should only be used when
329329
/// iteration order doesn't affect anything
330-
#[allow(rustc::potential_query_instability)]
331330
pub fn named_universal_regions<'s>(
332331
&'s self,
333332
) -> impl Iterator<Item = (ty::Region<'tcx>, ty::RegionVid)> + 's {

compiler/rustc_codegen_llvm/src/back/lto.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use rustc_codegen_ssa::traits::*;
1414
use rustc_codegen_ssa::{looks_like_rust_object_file, ModuleCodegen, ModuleKind};
1515
use rustc_data_structures::fx::FxHashMap;
1616
use rustc_data_structures::memmap::Mmap;
17+
use rustc_data_structures::unord::UnordMap;
1718
use rustc_errors::{DiagCtxt, FatalError};
1819
use rustc_hir::def_id::LOCAL_CRATE;
1920
use rustc_middle::bug;
@@ -787,7 +788,7 @@ pub unsafe fn optimize_thin_module(
787788
#[derive(Debug, Default)]
788789
pub struct ThinLTOKeysMap {
789790
// key = llvm name of importing module, value = LLVM cache key
790-
keys: FxHashMap<String, String>,
791+
keys: UnordMap<String, String>,
791792
}
792793

793794
impl ThinLTOKeysMap {
@@ -797,16 +798,15 @@ impl ThinLTOKeysMap {
797798
let mut writer = io::BufWriter::new(file);
798799
// The entries are loaded back into a hash map in `load_from_file()`, so
799800
// the order in which we write them to file here does not matter.
800-
#[allow(rustc::potential_query_instability)]
801-
for (module, key) in &self.keys {
801+
for (module, key) in self.keys.items().into_sorted_stable_ord() {
802802
writeln!(writer, "{module} {key}")?;
803803
}
804804
Ok(())
805805
}
806806

807807
fn load_from_file(path: &Path) -> io::Result<Self> {
808808
use std::io::BufRead;
809-
let mut keys = FxHashMap::default();
809+
let mut keys = UnordMap::default();
810810
let file = File::open(path)?;
811811
for line in io::BufReader::new(file).lines() {
812812
let line = line?;

compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,6 @@ fn codegenned_and_inlined_items(tcx: TyCtxt<'_>) -> DefIdSet {
403403
let mut result = items.clone();
404404

405405
for cgu in cgus {
406-
#[allow(rustc::potential_query_instability)]
407406
for item in cgu.items().keys() {
408407
if let mir::mono::MonoItem::Fn(ref instance) = item {
409408
let did = instance.def_id();

compiler/rustc_codegen_ssa/src/assert_module_sources.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
2626
use crate::errors;
2727
use rustc_ast as ast;
28-
use rustc_data_structures::fx::FxHashMap;
28+
use rustc_data_structures::unord::UnordMap;
2929
use rustc_data_structures::unord::UnordSet;
3030
use rustc_errors::{DiagnosticArgValue, IntoDiagnosticArg};
3131
use rustc_hir::def_id::LOCAL_CRATE;
@@ -218,8 +218,8 @@ pub enum ComparisonKind {
218218
}
219219

220220
struct TrackerData {
221-
actual_reuse: FxHashMap<String, CguReuse>,
222-
expected_reuse: FxHashMap<String, (String, Span, CguReuse, ComparisonKind)>,
221+
actual_reuse: UnordMap<String, CguReuse>,
222+
expected_reuse: UnordMap<String, (String, Span, CguReuse, ComparisonKind)>,
223223
}
224224

225225
pub struct CguReuseTracker {
@@ -267,9 +267,7 @@ impl CguReuseTracker {
267267

268268
fn check_expected_reuse(&self, sess: &Session) {
269269
if let Some(ref data) = self.data {
270-
#[allow(rustc::potential_query_instability)]
271-
let mut keys = data.expected_reuse.keys().collect::<Vec<_>>();
272-
keys.sort_unstable();
270+
let keys = data.expected_reuse.keys().into_sorted_stable_ord();
273271
for cgu_name in keys {
274272
let &(ref cgu_user_name, ref error_span, expected_reuse, comparison_kind) =
275273
data.expected_reuse.get(cgu_name).unwrap();

compiler/rustc_codegen_ssa/src/back/link.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -682,13 +682,14 @@ fn link_dwarf_object<'a>(
682682
}
683683

684684
// Input rlibs contain .o/.dwo files from dependencies.
685-
#[allow(rustc::potential_query_instability)]
686685
let input_rlibs = cg_results
687686
.crate_info
688687
.used_crate_source
689-
.values()
690-
.filter_map(|csource| csource.rlib.as_ref())
691-
.map(|(path, _)| path);
688+
.items()
689+
.filter_map(|(_, csource)| csource.rlib.as_ref())
690+
.map(|(path, _)| path)
691+
.into_sorted_stable_ord();
692+
692693
for input_rlib in input_rlibs {
693694
debug!(?input_rlib);
694695
package.add_input_object(input_rlib)?;

compiler/rustc_codegen_ssa/src/base.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use rustc_attr as attr;
1919
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
2020
use rustc_data_structures::profiling::{get_resident_set_size, print_time_passes_entry};
2121
use rustc_data_structures::sync::par_map;
22+
use rustc_data_structures::unord::UnordMap;
2223
use rustc_hir as hir;
2324
use rustc_hir::def_id::{DefId, LOCAL_CRATE};
2425
use rustc_hir::lang_items::LangItem;
@@ -851,6 +852,8 @@ impl CrateInfo {
851852
// `compiler_builtins` are always placed last to ensure that they're linked correctly.
852853
used_crates.extend(compiler_builtins);
853854

855+
let crates = tcx.crates(());
856+
let n_crates = crates.len();
854857
let mut info = CrateInfo {
855858
target_cpu,
856859
crate_types,
@@ -862,19 +865,15 @@ impl CrateInfo {
862865
is_no_builtins: Default::default(),
863866
native_libraries: Default::default(),
864867
used_libraries: tcx.native_libraries(LOCAL_CRATE).iter().map(Into::into).collect(),
865-
crate_name: Default::default(),
868+
crate_name: UnordMap::with_capacity(n_crates),
866869
used_crates,
867-
used_crate_source: Default::default(),
870+
used_crate_source: UnordMap::with_capacity(n_crates),
868871
dependency_formats: tcx.dependency_formats(()).clone(),
869872
windows_subsystem,
870873
natvis_debugger_visualizers: Default::default(),
871874
};
872-
let crates = tcx.crates(());
873875

874-
let n_crates = crates.len();
875876
info.native_libraries.reserve(n_crates);
876-
info.crate_name.reserve(n_crates);
877-
info.used_crate_source.reserve(n_crates);
878877

879878
for &cnum in crates.iter() {
880879
info.native_libraries

compiler/rustc_codegen_ssa/src/lib.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ extern crate rustc_middle;
2626
use rustc_ast as ast;
2727
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
2828
use rustc_data_structures::sync::Lrc;
29+
use rustc_data_structures::unord::UnordMap;
2930
use rustc_hir::def_id::CrateNum;
3031
use rustc_middle::dep_graph::WorkProduct;
3132
use rustc_middle::middle::debugger_visualizer::DebuggerVisualizerFile;
@@ -152,16 +153,16 @@ impl From<&cstore::NativeLib> for NativeLib {
152153
pub struct CrateInfo {
153154
pub target_cpu: String,
154155
pub crate_types: Vec<CrateType>,
155-
pub exported_symbols: FxHashMap<CrateType, Vec<String>>,
156+
pub exported_symbols: UnordMap<CrateType, Vec<String>>,
156157
pub linked_symbols: FxHashMap<CrateType, Vec<(String, SymbolExportKind)>>,
157158
pub local_crate_name: Symbol,
158159
pub compiler_builtins: Option<CrateNum>,
159160
pub profiler_runtime: Option<CrateNum>,
160161
pub is_no_builtins: FxHashSet<CrateNum>,
161162
pub native_libraries: FxHashMap<CrateNum, Vec<NativeLib>>,
162-
pub crate_name: FxHashMap<CrateNum, Symbol>,
163+
pub crate_name: UnordMap<CrateNum, Symbol>,
163164
pub used_libraries: Vec<NativeLib>,
164-
pub used_crate_source: FxHashMap<CrateNum, Lrc<CrateSource>>,
165+
pub used_crate_source: UnordMap<CrateNum, Lrc<CrateSource>>,
165166
pub used_crates: Vec<CrateNum>,
166167
pub dependency_formats: Lrc<Dependencies>,
167168
pub windows_subsystem: Option<String>,

compiler/rustc_data_structures/src/unord.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,11 @@ impl<K: Eq + Hash, V> UnordMap<K, V> {
524524
UnordItems(self.inner.into_iter())
525525
}
526526

527+
#[inline]
528+
pub fn keys(&self) -> UnordItems<&K, impl Iterator<Item = &K>> {
529+
UnordItems(self.inner.keys())
530+
}
531+
527532
/// Returns the entries of this map in stable sort order (as defined by `ToStableHashKey`).
528533
///
529534
/// The `cache_sort_key` parameter controls if [slice::sort_by_cached_key] or

0 commit comments

Comments
 (0)