Skip to content

Commit 01e27a3

Browse files
committed
Handle rustc_middle cases of rustc::potential_query_instability lint
1 parent 66701c4 commit 01e27a3

File tree

16 files changed

+64
-71
lines changed

16 files changed

+64
-71
lines changed

compiler/rustc_data_structures/src/sharded.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
use std::borrow::Borrow;
2-
use std::collections::hash_map::RawEntryMut;
32
use std::hash::{Hash, Hasher};
43
use std::{iter, mem};
54

65
#[cfg(parallel_compiler)]
76
use either::Either;
7+
use indexmap::map::RawEntryApiV1;
8+
use indexmap::map::raw_entry_v1::RawEntryMut;
89

9-
use crate::fx::{FxHashMap, FxHasher};
10+
use crate::fx::{FxHasher, FxIndexMap};
1011
#[cfg(parallel_compiler)]
1112
use crate::sync::{CacheAligned, is_dyn_thread_safe};
1213
use crate::sync::{Lock, LockGuard, Mode};
@@ -159,15 +160,15 @@ pub fn shards() -> usize {
159160
1
160161
}
161162

162-
pub type ShardedHashMap<K, V> = Sharded<FxHashMap<K, V>>;
163+
pub type ShardedIndexMap<K, V> = Sharded<FxIndexMap<K, V>>;
163164

164-
impl<K: Eq, V> ShardedHashMap<K, V> {
165+
impl<K: Eq, V> ShardedIndexMap<K, V> {
165166
pub fn len(&self) -> usize {
166167
self.lock_shards().map(|shard| shard.len()).sum()
167168
}
168169
}
169170

170-
impl<K: Eq + Hash + Copy> ShardedHashMap<K, ()> {
171+
impl<K: Eq + Hash + Copy> ShardedIndexMap<K, ()> {
171172
#[inline]
172173
pub fn intern_ref<Q: ?Sized>(&self, value: &Q, make: impl FnOnce() -> K) -> K
173174
where
@@ -176,7 +177,7 @@ impl<K: Eq + Hash + Copy> ShardedHashMap<K, ()> {
176177
{
177178
let hash = make_hash(value);
178179
let mut shard = self.lock_shard_by_hash(hash);
179-
let entry = shard.raw_entry_mut().from_key_hashed_nocheck(hash, value);
180+
let entry = shard.raw_entry_mut_v1().from_key_hashed_nocheck(hash, value);
180181

181182
match entry {
182183
RawEntryMut::Occupied(e) => *e.key(),
@@ -196,7 +197,7 @@ impl<K: Eq + Hash + Copy> ShardedHashMap<K, ()> {
196197
{
197198
let hash = make_hash(&value);
198199
let mut shard = self.lock_shard_by_hash(hash);
199-
let entry = shard.raw_entry_mut().from_key_hashed_nocheck(hash, &value);
200+
let entry = shard.raw_entry_mut_v1().from_key_hashed_nocheck(hash, &value);
200201

201202
match entry {
202203
RawEntryMut::Occupied(e) => *e.key(),
@@ -214,12 +215,12 @@ pub trait IntoPointer {
214215
fn into_pointer(&self) -> *const ();
215216
}
216217

217-
impl<K: Eq + Hash + Copy + IntoPointer> ShardedHashMap<K, ()> {
218+
impl<K: Eq + Hash + Copy + IntoPointer> ShardedIndexMap<K, ()> {
218219
pub fn contains_pointer_to<T: Hash + IntoPointer>(&self, value: &T) -> bool {
219220
let hash = make_hash(&value);
220221
let shard = self.lock_shard_by_hash(hash);
221222
let value = value.into_pointer();
222-
shard.raw_entry().from_hash(hash, |entry| entry.into_pointer() == value).is_some()
223+
shard.raw_entry_v1().from_hash(hash, |entry| entry.into_pointer() == value).is_some()
223224
}
224225
}
225226

compiler/rustc_middle/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
// tidy-alphabetical-start
2727
#![allow(internal_features)]
2828
#![allow(rustc::diagnostic_outside_of_impl)]
29-
#![allow(rustc::potential_query_instability)]
3029
#![allow(rustc::untranslatable_diagnostic)]
3130
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
3231
#![doc(rust_logo)]

compiler/rustc_middle/src/query/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1939,7 +1939,7 @@ rustc_queries! {
19391939
query maybe_unused_trait_imports(_: ()) -> &'tcx FxIndexSet<LocalDefId> {
19401940
desc { "fetching potentially unused trait imports" }
19411941
}
1942-
query names_imported_by_glob_use(def_id: LocalDefId) -> &'tcx UnordSet<Symbol> {
1942+
query names_imported_by_glob_use(def_id: LocalDefId) -> &'tcx FxIndexSet<Symbol> {
19431943
desc { |tcx| "finding names imported by glob use for `{}`", tcx.def_path_str(def_id) }
19441944
}
19451945

compiler/rustc_middle/src/query/on_disk_cache.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::collections::hash_map::Entry;
22
use std::mem;
33

4-
use rustc_data_structures::fx::{FxHashMap, FxIndexSet};
4+
use rustc_data_structures::fx::{FxHashMap, FxIndexMap, FxIndexSet};
55
use rustc_data_structures::memmap::Mmap;
66
use rustc_data_structures::sync::{HashMapExt, Lock, Lrc, RwLock};
77
use rustc_data_structures::unhash::UnhashMap;
@@ -54,7 +54,7 @@ pub struct OnDiskCache<'sess> {
5454

5555
// Collects all `QuerySideEffects` created during the current compilation
5656
// session.
57-
current_side_effects: Lock<FxHashMap<DepNodeIndex, QuerySideEffects>>,
57+
current_side_effects: Lock<FxIndexMap<DepNodeIndex, QuerySideEffects>>,
5858

5959
source_map: &'sess SourceMap,
6060
file_index_to_stable_id: FxHashMap<SourceFileIndex, EncodedSourceFileId>,

compiler/rustc_middle/src/ty/context.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,12 @@ use rustc_data_structures::fingerprint::Fingerprint;
1919
use rustc_data_structures::fx::FxHashMap;
2020
use rustc_data_structures::intern::Interned;
2121
use rustc_data_structures::profiling::SelfProfilerRef;
22-
use rustc_data_structures::sharded::{IntoPointer, ShardedHashMap};
22+
use rustc_data_structures::sharded::{IntoPointer, ShardedIndexMap};
2323
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
2424
use rustc_data_structures::steal::Steal;
2525
use rustc_data_structures::sync::{self, FreezeReadGuard, Lock, Lrc, RwLock, WorkerLocal};
2626
#[cfg(parallel_compiler)]
2727
use rustc_data_structures::sync::{DynSend, DynSync};
28-
use rustc_data_structures::unord::UnordSet;
2928
use rustc_errors::{
3029
Applicability, Diag, DiagCtxtHandle, ErrorGuaranteed, LintDiagnostic, MultiSpan,
3130
};
@@ -743,7 +742,7 @@ impl<'tcx> rustc_type_ir::inherent::Span<TyCtxt<'tcx>> for Span {
743742
}
744743
}
745744

746-
type InternedSet<'tcx, T> = ShardedHashMap<InternedInSet<'tcx, T>, ()>;
745+
type InternedSet<'tcx, T> = ShardedIndexMap<InternedInSet<'tcx, T>, ()>;
747746

748747
pub struct CtxtInterners<'tcx> {
749748
/// The arena that types, regions, etc. are allocated from.
@@ -3227,9 +3226,7 @@ pub fn provide(providers: &mut Providers) {
32273226
providers.maybe_unused_trait_imports =
32283227
|tcx, ()| &tcx.resolutions(()).maybe_unused_trait_imports;
32293228
providers.names_imported_by_glob_use = |tcx, id| {
3230-
tcx.arena.alloc(UnordSet::from(
3231-
tcx.resolutions(()).glob_map.get(&id).cloned().unwrap_or_default(),
3232-
))
3229+
tcx.arena.alloc(tcx.resolutions(()).glob_map.get(&id).cloned().unwrap_or_default())
32333230
};
32343231

32353232
providers.extern_mod_stmt_cnum =

compiler/rustc_middle/src/ty/diagnostics.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::borrow::Cow;
44
use std::fmt::Write;
55
use std::ops::ControlFlow;
66

7-
use rustc_data_structures::fx::FxHashMap;
7+
use rustc_data_structures::fx::FxIndexMap;
88
use rustc_errors::{Applicability, Diag, DiagArgValue, IntoDiagArg, into_diag_arg_using_display};
99
use rustc_hir::def::DefKind;
1010
use rustc_hir::def_id::DefId;
@@ -277,7 +277,7 @@ pub fn suggest_constraining_type_params<'a>(
277277
param_names_and_constraints: impl Iterator<Item = (&'a str, &'a str, Option<DefId>)>,
278278
span_to_replace: Option<Span>,
279279
) -> bool {
280-
let mut grouped = FxHashMap::default();
280+
let mut grouped = FxIndexMap::default();
281281
param_names_and_constraints.for_each(|(param_name, constraint, def_id)| {
282282
grouped.entry(param_name).or_insert(Vec::new()).push((constraint, def_id))
283283
});

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ pub struct ResolverGlobalCtxt {
179179
pub extern_crate_map: FxHashMap<LocalDefId, CrateNum>,
180180
pub maybe_unused_trait_imports: FxIndexSet<LocalDefId>,
181181
pub module_children: LocalDefIdMap<Vec<ModChild>>,
182-
pub glob_map: FxHashMap<LocalDefId, FxHashSet<Symbol>>,
182+
pub glob_map: FxIndexMap<LocalDefId, FxIndexSet<Symbol>>,
183183
pub main_def: Option<MainDefinition>,
184184
pub trait_impls: FxIndexMap<DefId, Vec<LocalDefId>>,
185185
/// A list of proc macro LocalDefIds, written out in the order in which

compiler/rustc_middle/src/ty/print/pretty.rs

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::ops::{Deref, DerefMut};
55

66
use rustc_apfloat::Float;
77
use rustc_apfloat::ieee::{Double, Half, Quad, Single};
8-
use rustc_data_structures::fx::{FxHashMap, FxIndexMap};
8+
use rustc_data_structures::fx::{FxIndexMap, IndexEntry};
99
use rustc_data_structures::unord::UnordMap;
1010
use rustc_hir as hir;
1111
use rustc_hir::LangItem;
@@ -3352,8 +3352,8 @@ pub fn trimmed_def_paths(tcx: TyCtxt<'_>, (): ()) -> DefIdMap<Symbol> {
33523352

33533353
// Once constructed, unique namespace+symbol pairs will have a `Some(_)` entry, while
33543354
// non-unique pairs will have a `None` entry.
3355-
let unique_symbols_rev: &mut FxHashMap<(Namespace, Symbol), Option<DefId>> =
3356-
&mut FxHashMap::default();
3355+
let unique_symbols_rev: &mut FxIndexMap<(Namespace, Symbol), Option<DefId>> =
3356+
&mut FxIndexMap::default();
33573357

33583358
for symbol_set in tcx.resolutions(()).glob_map.values() {
33593359
for symbol in symbol_set {
@@ -3363,27 +3363,23 @@ pub fn trimmed_def_paths(tcx: TyCtxt<'_>, (): ()) -> DefIdMap<Symbol> {
33633363
}
33643364
}
33653365

3366-
for_each_def(tcx, |ident, ns, def_id| {
3367-
use std::collections::hash_map::Entry::{Occupied, Vacant};
3368-
3369-
match unique_symbols_rev.entry((ns, ident.name)) {
3370-
Occupied(mut v) => match v.get() {
3371-
None => {}
3372-
Some(existing) => {
3373-
if *existing != def_id {
3374-
v.insert(None);
3375-
}
3366+
for_each_def(tcx, |ident, ns, def_id| match unique_symbols_rev.entry((ns, ident.name)) {
3367+
IndexEntry::Occupied(mut v) => match v.get() {
3368+
None => {}
3369+
Some(existing) => {
3370+
if *existing != def_id {
3371+
v.insert(None);
33763372
}
3377-
},
3378-
Vacant(v) => {
3379-
v.insert(Some(def_id));
33803373
}
3374+
},
3375+
IndexEntry::Vacant(v) => {
3376+
v.insert(Some(def_id));
33813377
}
33823378
});
33833379

33843380
// Put the symbol from all the unique namespace+symbol pairs into `map`.
33853381
let mut map: DefIdMap<Symbol> = Default::default();
3386-
for ((_, symbol), opt_def_id) in unique_symbols_rev.drain() {
3382+
for ((_, symbol), opt_def_id) in unique_symbols_rev.drain(..) {
33873383
use std::collections::hash_map::Entry::{Occupied, Vacant};
33883384

33893385
if let Some(def_id) = opt_def_id {

compiler/rustc_resolve/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1086,7 +1086,7 @@ pub struct Resolver<'ra, 'tcx> {
10861086
empty_disambiguator: u32,
10871087

10881088
/// Maps glob imports to the names of items actually imported.
1089-
glob_map: FxHashMap<LocalDefId, FxHashSet<Symbol>>,
1089+
glob_map: FxIndexMap<LocalDefId, FxIndexSet<Symbol>>,
10901090
glob_error: Option<ErrorGuaranteed>,
10911091
visibilities_for_hashing: Vec<(LocalDefId, ty::Visibility)>,
10921092
used_imports: FxHashSet<NodeId>,

src/tools/clippy/clippy_lints/src/wildcard_imports.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ impl LateLintPass<'_> for WildcardImports {
150150
(span, false)
151151
};
152152

153-
let mut imports = used_imports.items().map(ToString::to_string).into_sorted_stable_ord();
153+
let mut imports: Vec<_> = used_imports.iter().map(ToString::to_string).collect();
154154
let imports_string = if imports.len() == 1 {
155155
imports.pop().unwrap()
156156
} else if braced_glob {

0 commit comments

Comments
 (0)