Skip to content

Commit 056c5b3

Browse files
committed
Make query keys Copy
1 parent f4f5fc3 commit 056c5b3

File tree

3 files changed

+18
-17
lines changed

3 files changed

+18
-17
lines changed

compiler/rustc_query_system/src/query/caches.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub trait QueryStorage {
2121
}
2222

2323
pub trait QueryCache: QueryStorage + Sized {
24-
type Key: Hash + Eq + Clone + Debug;
24+
type Key: Hash + Eq + Copy + Debug;
2525

2626
/// Checks if the query is already computed and in the cache.
2727
/// It returns the shard index and a lock guard to the shard,
@@ -61,7 +61,7 @@ impl<K: Eq + Hash, V: Copy + Debug> QueryStorage for DefaultCache<K, V> {
6161

6262
impl<K, V> QueryCache for DefaultCache<K, V>
6363
where
64-
K: Eq + Hash + Clone + Debug,
64+
K: Eq + Hash + Copy + Debug,
6565
V: Copy + Debug,
6666
{
6767
type Key = K;
@@ -179,7 +179,7 @@ impl<K: Eq + Idx, V: Copy + Debug> QueryStorage for VecCache<K, V> {
179179

180180
impl<K, V> QueryCache for VecCache<K, V>
181181
where
182-
K: Eq + Idx + Clone + Debug,
182+
K: Eq + Idx + Copy + Debug,
183183
V: Copy + Debug,
184184
{
185185
type Key = K;

compiler/rustc_query_system/src/query/config.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ pub type TryLoadFromDisk<Qcx, Q> =
1919
pub trait QueryConfig<Qcx: QueryContext> {
2020
const NAME: &'static str;
2121

22-
type Key: DepNodeParams<Qcx::DepContext> + Eq + Hash + Clone + Debug;
22+
// `Key` and `Value` are `Copy` instead of `Clone` to ensure copying them stays cheap,
23+
// but it isn't necessary.
24+
type Key: DepNodeParams<Qcx::DepContext> + Eq + Hash + Copy + Debug;
2325
type Value: Debug + Copy;
2426

2527
type Cache: QueryCache<Key = Self::Key, Value = Self::Value>;

compiler/rustc_query_system/src/query/plumbing.rs

+12-13
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ enum QueryResult<D: DepKind> {
4949

5050
impl<K, D> QueryState<K, D>
5151
where
52-
K: Eq + Hash + Clone + Debug,
52+
K: Eq + Hash + Copy + Debug,
5353
D: DepKind,
5454
{
5555
pub fn all_inactive(&self) -> bool {
@@ -78,7 +78,7 @@ where
7878
for shard in shards.iter() {
7979
for (k, v) in shard.iter() {
8080
if let QueryResult::Started(ref job) = *v {
81-
let query = make_query(qcx, k.clone());
81+
let query = make_query(qcx, *k);
8282
jobs.insert(job.id, QueryJobInfo { query, job: job.clone() });
8383
}
8484
}
@@ -92,7 +92,7 @@ where
9292
// really hurt much.)
9393
for (k, v) in self.active.try_lock()?.iter() {
9494
if let QueryResult::Started(ref job) = *v {
95-
let query = make_query(qcx, k.clone());
95+
let query = make_query(qcx, *k);
9696
jobs.insert(job.id, QueryJobInfo { query, job: job.clone() });
9797
}
9898
}
@@ -112,7 +112,7 @@ impl<K, D: DepKind> Default for QueryState<K, D> {
112112
/// This will poison the relevant query if dropped.
113113
struct JobOwner<'tcx, K, D: DepKind>
114114
where
115-
K: Eq + Hash + Clone,
115+
K: Eq + Hash + Copy,
116116
{
117117
state: &'tcx QueryState<K, D>,
118118
key: K,
@@ -164,7 +164,7 @@ where
164164

165165
impl<'tcx, K, D: DepKind> JobOwner<'tcx, K, D>
166166
where
167-
K: Eq + Hash + Clone,
167+
K: Eq + Hash + Copy,
168168
{
169169
/// Either gets a `JobOwner` corresponding the query, allowing us to
170170
/// start executing the query, or returns with the result of the query.
@@ -196,7 +196,7 @@ where
196196
let job = qcx.current_query_job();
197197
let job = QueryJob::new(id, span, job);
198198

199-
let key = entry.key().clone();
199+
let key = *entry.key();
200200
entry.insert(QueryResult::Started(job));
201201

202202
let owner = JobOwner { state, id, key };
@@ -275,7 +275,7 @@ where
275275

276276
impl<'tcx, K, D> Drop for JobOwner<'tcx, K, D>
277277
where
278-
K: Eq + Hash + Clone,
278+
K: Eq + Hash + Copy,
279279
D: DepKind,
280280
{
281281
#[inline(never)]
@@ -292,7 +292,7 @@ where
292292
QueryResult::Started(job) => job,
293293
QueryResult::Poisoned => panic!(),
294294
};
295-
shard.insert(self.key.clone(), QueryResult::Poisoned);
295+
shard.insert(self.key, QueryResult::Poisoned);
296296
job
297297
};
298298
// Also signal the completion of the job, so waiters
@@ -311,7 +311,7 @@ pub(crate) struct CycleError<D: DepKind> {
311311
/// The result of `try_start`.
312312
enum TryGetJob<'tcx, K, D>
313313
where
314-
K: Eq + Hash + Clone,
314+
K: Eq + Hash + Copy,
315315
D: DepKind,
316316
{
317317
/// The query is not yet started. Contains a guard to the cache eventually used to start it.
@@ -359,10 +359,9 @@ where
359359
Q: QueryConfig<Qcx>,
360360
Qcx: QueryContext,
361361
{
362-
match JobOwner::<'_, Q::Key, Qcx::DepKind>::try_start(&qcx, state, span, key.clone()) {
362+
match JobOwner::<'_, Q::Key, Qcx::DepKind>::try_start(&qcx, state, span, key) {
363363
TryGetJob::NotYetStarted(job) => {
364-
let (result, dep_node_index) =
365-
execute_job::<Q, Qcx>(qcx, key.clone(), dep_node, job.id);
364+
let (result, dep_node_index) = execute_job::<Q, Qcx>(qcx, key, dep_node, job.id);
366365
if Q::FEEDABLE {
367366
// We may have put a value inside the cache from inside the execution.
368367
// Verify that it has the same hash as what we have now, to ensure consistency.
@@ -547,7 +546,7 @@ where
547546
let prof_timer = qcx.dep_context().profiler().query_provider();
548547

549548
// The dep-graph for this computation is already in-place.
550-
let result = dep_graph.with_ignore(|| Q::compute(qcx, key.clone()));
549+
let result = dep_graph.with_ignore(|| Q::compute(qcx, *key));
551550

552551
prof_timer.finish_with_query_invocation_id(dep_node_index.into());
553552

0 commit comments

Comments
 (0)