Skip to content

Commit 0000613

Browse files
committed
Handle rustc_middle cases of rustc::potential_query_instability lint
1 parent 11ee3a8 commit 0000613

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
@@ -1920,7 +1920,7 @@ rustc_queries! {
19201920
query maybe_unused_trait_imports(_: ()) -> &'tcx FxIndexSet<LocalDefId> {
19211921
desc { "fetching potentially unused trait imports" }
19221922
}
1923-
query names_imported_by_glob_use(def_id: LocalDefId) -> &'tcx UnordSet<Symbol> {
1923+
query names_imported_by_glob_use(def_id: LocalDefId) -> &'tcx FxIndexSet<Symbol> {
19241924
desc { |tcx| "finding names imported by glob use for `{}`", tcx.def_path_str(def_id) }
19251925
}
19261926

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
@@ -18,13 +18,12 @@ use rustc_data_structures::fingerprint::Fingerprint;
1818
use rustc_data_structures::fx::FxHashMap;
1919
use rustc_data_structures::intern::Interned;
2020
use rustc_data_structures::profiling::SelfProfilerRef;
21-
use rustc_data_structures::sharded::{IntoPointer, ShardedHashMap};
21+
use rustc_data_structures::sharded::{IntoPointer, ShardedIndexMap};
2222
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
2323
use rustc_data_structures::steal::Steal;
2424
use rustc_data_structures::sync::{self, FreezeReadGuard, Lock, Lrc, RwLock, WorkerLocal};
2525
#[cfg(parallel_compiler)]
2626
use rustc_data_structures::sync::{DynSend, DynSync};
27-
use rustc_data_structures::unord::UnordSet;
2827
use rustc_errors::{
2928
Applicability, Diag, DiagCtxtHandle, ErrorGuaranteed, LintDiagnostic, MultiSpan,
3029
};
@@ -698,7 +697,7 @@ impl<'tcx> rustc_type_ir::inherent::Features<TyCtxt<'tcx>> for &'tcx rustc_featu
698697
}
699698
}
700699

701-
type InternedSet<'tcx, T> = ShardedHashMap<InternedInSet<'tcx, T>, ()>;
700+
type InternedSet<'tcx, T> = ShardedIndexMap<InternedInSet<'tcx, T>, ()>;
702701

703702
pub struct CtxtInterners<'tcx> {
704703
/// The arena that types, regions, etc. are allocated from.
@@ -3207,9 +3206,7 @@ pub fn provide(providers: &mut Providers) {
32073206
providers.maybe_unused_trait_imports =
32083207
|tcx, ()| &tcx.resolutions(()).maybe_unused_trait_imports;
32093208
providers.names_imported_by_glob_use = |tcx, id| {
3210-
tcx.arena.alloc(UnordSet::from(
3211-
tcx.resolutions(()).glob_map.get(&id).cloned().unwrap_or_default(),
3212-
))
3209+
tcx.arena.alloc(tcx.resolutions(()).glob_map.get(&id).cloned().unwrap_or_default())
32133210
};
32143211

32153212
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;
@@ -276,7 +276,7 @@ pub fn suggest_constraining_type_params<'a>(
276276
param_names_and_constraints: impl Iterator<Item = (&'a str, &'a str, Option<DefId>)>,
277277
span_to_replace: Option<Span>,
278278
) -> bool {
279-
let mut grouped = FxHashMap::default();
279+
let mut grouped = FxIndexMap::default();
280280
param_names_and_constraints.for_each(|(param_name, constraint, def_id)| {
281281
grouped.entry(param_name).or_insert(Vec::new()).push((constraint, def_id))
282282
});

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ pub struct ResolverGlobalCtxt {
178178
pub extern_crate_map: FxHashMap<LocalDefId, CrateNum>,
179179
pub maybe_unused_trait_imports: FxIndexSet<LocalDefId>,
180180
pub module_children: LocalDefIdMap<Vec<ModChild>>,
181-
pub glob_map: FxHashMap<LocalDefId, FxHashSet<Symbol>>,
181+
pub glob_map: FxIndexMap<LocalDefId, FxIndexSet<Symbol>>,
182182
pub main_def: Option<MainDefinition>,
183183
pub trait_impls: FxIndexMap<DefId, Vec<LocalDefId>>,
184184
/// 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;
@@ -3338,8 +3338,8 @@ pub fn trimmed_def_paths(tcx: TyCtxt<'_>, (): ()) -> DefIdMap<Symbol> {
33383338

33393339
// Once constructed, unique namespace+symbol pairs will have a `Some(_)` entry, while
33403340
// non-unique pairs will have a `None` entry.
3341-
let unique_symbols_rev: &mut FxHashMap<(Namespace, Symbol), Option<DefId>> =
3342-
&mut FxHashMap::default();
3341+
let unique_symbols_rev: &mut FxIndexMap<(Namespace, Symbol), Option<DefId>> =
3342+
&mut FxIndexMap::default();
33433343

33443344
for symbol_set in tcx.resolutions(()).glob_map.values() {
33453345
for symbol in symbol_set {
@@ -3349,27 +3349,23 @@ pub fn trimmed_def_paths(tcx: TyCtxt<'_>, (): ()) -> DefIdMap<Symbol> {
33493349
}
33503350
}
33513351

3352-
for_each_def(tcx, |ident, ns, def_id| {
3353-
use std::collections::hash_map::Entry::{Occupied, Vacant};
3354-
3355-
match unique_symbols_rev.entry((ns, ident.name)) {
3356-
Occupied(mut v) => match v.get() {
3357-
None => {}
3358-
Some(existing) => {
3359-
if *existing != def_id {
3360-
v.insert(None);
3361-
}
3352+
for_each_def(tcx, |ident, ns, def_id| match unique_symbols_rev.entry((ns, ident.name)) {
3353+
IndexEntry::Occupied(mut v) => match v.get() {
3354+
None => {}
3355+
Some(existing) => {
3356+
if *existing != def_id {
3357+
v.insert(None);
33623358
}
3363-
},
3364-
Vacant(v) => {
3365-
v.insert(Some(def_id));
33663359
}
3360+
},
3361+
IndexEntry::Vacant(v) => {
3362+
v.insert(Some(def_id));
33673363
}
33683364
});
33693365

33703366
// Put the symbol from all the unique namespace+symbol pairs into `map`.
33713367
let mut map: DefIdMap<Symbol> = Default::default();
3372-
for ((_, symbol), opt_def_id) in unique_symbols_rev.drain() {
3368+
for ((_, symbol), opt_def_id) in unique_symbols_rev.drain(..) {
33733369
use std::collections::hash_map::Entry::{Occupied, Vacant};
33743370

33753371
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)