Skip to content

Commit 56f74c5

Browse files
committed
Auto merge of rust-lang#83069 - tgnottingham:simplify-query-cache-iter, r=cjgillot
rustc_query_system: simplify QueryCache::iter Minor cleanup to reduce a small amount of complexity and code bloat. Reduces the number of mono items in rustc_query_impl by 15%.
2 parents 32dce35 + adcbe49 commit 56f74c5

File tree

2 files changed

+17
-22
lines changed

2 files changed

+17
-22
lines changed

compiler/rustc_query_system/src/query/caches.rs

+15-20
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,11 @@ pub trait QueryCache: QueryStorage {
4949
index: DepNodeIndex,
5050
) -> Self::Stored;
5151

52-
fn iter<R, L>(
52+
fn iter<R>(
5353
&self,
54-
shards: &Sharded<L>,
55-
get_shard: impl Fn(&mut L) -> &mut Self::Sharded,
54+
shards: &Sharded<Self::Sharded>,
5655
f: impl for<'a> FnOnce(
57-
Box<dyn Iterator<Item = (&'a Self::Key, &'a Self::Value, DepNodeIndex)> + 'a>,
56+
&'a mut dyn Iterator<Item = (&'a Self::Key, &'a Self::Value, DepNodeIndex)>,
5857
) -> R,
5958
) -> R;
6059
}
@@ -125,16 +124,14 @@ where
125124
value
126125
}
127126

128-
fn iter<R, L>(
127+
fn iter<R>(
129128
&self,
130-
shards: &Sharded<L>,
131-
get_shard: impl Fn(&mut L) -> &mut Self::Sharded,
132-
f: impl for<'a> FnOnce(Box<dyn Iterator<Item = (&'a K, &'a V, DepNodeIndex)> + 'a>) -> R,
129+
shards: &Sharded<Self::Sharded>,
130+
f: impl for<'a> FnOnce(&'a mut dyn Iterator<Item = (&'a K, &'a V, DepNodeIndex)>) -> R,
133131
) -> R {
134-
let mut shards = shards.lock_shards();
135-
let mut shards: Vec<_> = shards.iter_mut().map(|shard| get_shard(shard)).collect();
136-
let results = shards.iter_mut().flat_map(|shard| shard.iter()).map(|(k, v)| (k, &v.0, v.1));
137-
f(Box::new(results))
132+
let shards = shards.lock_shards();
133+
let mut results = shards.iter().flat_map(|shard| shard.iter()).map(|(k, v)| (k, &v.0, v.1));
134+
f(&mut results)
138135
}
139136
}
140137

@@ -210,15 +207,13 @@ where
210207
&value.0
211208
}
212209

213-
fn iter<R, L>(
210+
fn iter<R>(
214211
&self,
215-
shards: &Sharded<L>,
216-
get_shard: impl Fn(&mut L) -> &mut Self::Sharded,
217-
f: impl for<'a> FnOnce(Box<dyn Iterator<Item = (&'a K, &'a V, DepNodeIndex)> + 'a>) -> R,
212+
shards: &Sharded<Self::Sharded>,
213+
f: impl for<'a> FnOnce(&'a mut dyn Iterator<Item = (&'a K, &'a V, DepNodeIndex)>) -> R,
218214
) -> R {
219-
let mut shards = shards.lock_shards();
220-
let mut shards: Vec<_> = shards.iter_mut().map(|shard| get_shard(shard)).collect();
221-
let results = shards.iter_mut().flat_map(|shard| shard.iter()).map(|(k, v)| (k, &v.0, v.1));
222-
f(Box::new(results))
215+
let shards = shards.lock_shards();
216+
let mut results = shards.iter().flat_map(|shard| shard.iter()).map(|(k, v)| (k, &v.0, v.1));
217+
f(&mut results)
223218
}
224219
}

compiler/rustc_query_system/src/query/plumbing.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ impl<C: QueryCache> QueryCacheStore<C> {
7676
pub fn iter_results<R>(
7777
&self,
7878
f: impl for<'a> FnOnce(
79-
Box<dyn Iterator<Item = (&'a C::Key, &'a C::Value, DepNodeIndex)> + 'a>,
79+
&'a mut dyn Iterator<Item = (&'a C::Key, &'a C::Value, DepNodeIndex)>,
8080
) -> R,
8181
) -> R {
82-
self.cache.iter(&self.shards, |shard| &mut *shard, f)
82+
self.cache.iter(&self.shards, f)
8383
}
8484
}
8585

0 commit comments

Comments
 (0)