Skip to content

Commit f34e703

Browse files
committed
Handle rustc_query_system cases of rustc::potential_query_instability lint
1 parent 11ee3a8 commit f34e703

File tree

7 files changed

+21
-22
lines changed

7 files changed

+21
-22
lines changed

compiler/rustc_data_structures/src/fx.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::hash::BuildHasherDefault;
22

3+
pub use indexmap::map::RawEntryApiV1 as IndexRawEntryApiV1;
34
pub use rustc_hash::{FxHashMap, FxHashSet, FxHasher};
45

56
pub type StdEntry<'a, K, V> = std::collections::hash_map::Entry<'a, K, V>;

compiler/rustc_query_system/src/dep_graph/graph.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
use std::assert_matches::assert_matches;
2-
use std::collections::hash_map::Entry;
32
use std::fmt::Debug;
43
use std::hash::Hash;
54
use std::marker::PhantomData;
65
use std::sync::Arc;
76
use std::sync::atomic::Ordering;
87

98
use rustc_data_structures::fingerprint::Fingerprint;
10-
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
9+
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap, IndexEntry};
1110
use rustc_data_structures::profiling::{QueryInvocationId, SelfProfilerRef};
1211
use rustc_data_structures::sharded::{self, Sharded};
1312
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
@@ -1054,7 +1053,7 @@ rustc_index::newtype_index! {
10541053
/// first, and `data` second.
10551054
pub(super) struct CurrentDepGraph<D: Deps> {
10561055
encoder: GraphEncoder<D>,
1057-
new_node_to_index: Sharded<FxHashMap<DepNode, DepNodeIndex>>,
1056+
new_node_to_index: Sharded<FxIndexMap<DepNode, DepNodeIndex>>,
10581057
prev_index_to_index: Lock<IndexVec<SerializedDepNodeIndex, Option<DepNodeIndex>>>,
10591058

10601059
/// This is used to verify that fingerprints do not change between the creation of a node
@@ -1124,7 +1123,7 @@ impl<D: Deps> CurrentDepGraph<D> {
11241123
previous,
11251124
),
11261125
new_node_to_index: Sharded::new(|| {
1127-
FxHashMap::with_capacity_and_hasher(
1126+
FxIndexMap::with_capacity_and_hasher(
11281127
new_node_count_estimate / sharded::shards(),
11291128
Default::default(),
11301129
)
@@ -1159,8 +1158,8 @@ impl<D: Deps> CurrentDepGraph<D> {
11591158
current_fingerprint: Fingerprint,
11601159
) -> DepNodeIndex {
11611160
let dep_node_index = match self.new_node_to_index.lock_shard_by_value(&key).entry(key) {
1162-
Entry::Occupied(entry) => *entry.get(),
1163-
Entry::Vacant(entry) => {
1161+
IndexEntry::Occupied(entry) => *entry.get(),
1162+
IndexEntry::Vacant(entry) => {
11641163
let dep_node_index = self.encoder.send(key, current_fingerprint, edges);
11651164
entry.insert(dep_node_index);
11661165
dep_node_index

compiler/rustc_query_system/src/dep_graph/serialized.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ use std::marker::PhantomData;
4040
use std::sync::Arc;
4141

4242
use rustc_data_structures::fingerprint::{Fingerprint, PackedFingerprint};
43-
use rustc_data_structures::fx::FxHashMap;
43+
use rustc_data_structures::fx::FxIndexMap;
4444
use rustc_data_structures::outline;
4545
use rustc_data_structures::profiling::SelfProfilerRef;
4646
use rustc_data_structures::sync::Lock;
@@ -472,7 +472,7 @@ struct EncoderState<D: Deps> {
472472
encoder: FileEncoder,
473473
total_node_count: usize,
474474
total_edge_count: usize,
475-
stats: Option<FxHashMap<DepKind, Stat>>,
475+
stats: Option<FxIndexMap<DepKind, Stat>>,
476476

477477
/// Stores the number of times we've encoded each dep kind.
478478
kind_stats: Vec<u32>,
@@ -486,7 +486,7 @@ impl<D: Deps> EncoderState<D> {
486486
encoder,
487487
total_edge_count: 0,
488488
total_node_count: 0,
489-
stats: record_stats.then(FxHashMap::default),
489+
stats: record_stats.then(FxIndexMap::default),
490490
kind_stats: iter::repeat(0).take(D::DEP_KIND_MAX as usize + 1).collect(),
491491
marker: PhantomData,
492492
}

compiler/rustc_query_system/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// tidy-alphabetical-start
2-
#![allow(rustc::potential_query_instability, internal_features)]
2+
#![allow(internal_features)]
33
#![feature(assert_matches)]
44
#![feature(core_intrinsics)]
55
#![feature(hash_raw_entry)]

compiler/rustc_query_system/src/query/caches.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::fmt::Debug;
22
use std::hash::Hash;
33

4-
use rustc_data_structures::fx::FxHashMap;
4+
use rustc_data_structures::fx::{FxIndexMap, IndexRawEntryApiV1};
55
use rustc_data_structures::sharded::{self, Sharded};
66
use rustc_data_structures::sync::{Lock, OnceLock};
77
use rustc_hir::def_id::LOCAL_CRATE;
@@ -23,7 +23,7 @@ pub trait QueryCache: Sized {
2323
}
2424

2525
pub struct DefaultCache<K, V> {
26-
cache: Sharded<FxHashMap<K, (V, DepNodeIndex)>>,
26+
cache: Sharded<FxIndexMap<K, (V, DepNodeIndex)>>,
2727
}
2828

2929
impl<K, V> Default for DefaultCache<K, V> {
@@ -44,7 +44,7 @@ where
4444
fn lookup(&self, key: &K) -> Option<(V, DepNodeIndex)> {
4545
let key_hash = sharded::make_hash(key);
4646
let lock = self.cache.lock_shard_by_hash(key_hash);
47-
let result = lock.raw_entry().from_key_hashed_nocheck(key_hash, key);
47+
let result = lock.raw_entry_v1().from_key_hashed_nocheck(key_hash, key);
4848

4949
if let Some((_, value)) = result { Some(*value) } else { None }
5050
}

compiler/rustc_query_system/src/query/job.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::hash::Hash;
22
use std::io::Write;
33
use std::num::NonZero;
44

5-
use rustc_data_structures::fx::FxHashMap;
5+
use rustc_data_structures::fx::FxIndexMap;
66
use rustc_errors::{Diag, DiagCtxtHandle};
77
use rustc_hir::def::DefKind;
88
use rustc_session::Session;
@@ -30,7 +30,7 @@ pub struct QueryInfo {
3030
pub query: QueryStackFrame,
3131
}
3232

33-
pub type QueryMap = FxHashMap<QueryJobId, QueryJobInfo>;
33+
pub type QueryMap = FxIndexMap<QueryJobId, QueryJobInfo>;
3434

3535
/// A value uniquely identifying an active query job.
3636
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]

compiler/rustc_query_system/src/query/plumbing.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@
33
//! manage the caches, and so forth.
44
55
use std::cell::Cell;
6-
use std::collections::hash_map::Entry;
76
use std::fmt::Debug;
87
use std::hash::Hash;
98
use std::mem;
109

1110
use rustc_data_structures::fingerprint::Fingerprint;
12-
use rustc_data_structures::fx::FxHashMap;
11+
use rustc_data_structures::fx::{FxIndexMap, IndexEntry};
1312
use rustc_data_structures::sharded::Sharded;
1413
use rustc_data_structures::stack::ensure_sufficient_stack;
1514
use rustc_data_structures::sync::Lock;
@@ -33,7 +32,7 @@ use crate::query::{
3332
};
3433

3534
pub struct QueryState<K> {
36-
active: Sharded<FxHashMap<K, QueryResult>>,
35+
active: Sharded<FxIndexMap<K, QueryResult>>,
3736
}
3837

3938
/// Indicates the state of a query for a given key in a query map.
@@ -187,7 +186,7 @@ where
187186
// since unwinding also wants to look at this map, this can also prevent a double
188187
// panic.
189188
let mut lock = state.active.lock_shard_by_value(&key);
190-
lock.remove(&key)
189+
lock.shift_remove(&key)
191190
};
192191
val.unwrap().expect_job()
193192
};
@@ -207,7 +206,7 @@ where
207206
let state = self.state;
208207
let job = {
209208
let mut shard = state.active.lock_shard_by_value(&self.key);
210-
let job = shard.remove(&self.key).unwrap().expect_job();
209+
let job = shard.shift_remove(&self.key).unwrap().expect_job();
211210

212211
shard.insert(self.key, QueryResult::Poisoned);
213212
job
@@ -344,7 +343,7 @@ where
344343
let current_job_id = qcx.current_query_job();
345344

346345
match state_lock.entry(key) {
347-
Entry::Vacant(entry) => {
346+
IndexEntry::Vacant(entry) => {
348347
// Nothing has computed or is computing the query, so we start a new job and insert it in the
349348
// state map.
350349
let id = qcx.next_job_id();
@@ -356,7 +355,7 @@ where
356355

357356
execute_job::<_, _, INCR>(query, qcx, state, key, id, dep_node)
358357
}
359-
Entry::Occupied(mut entry) => {
358+
IndexEntry::Occupied(mut entry) => {
360359
match entry.get_mut() {
361360
QueryResult::Started(job) => {
362361
#[cfg(parallel_compiler)]

0 commit comments

Comments
 (0)