Skip to content

Commit f244b26

Browse files
committed
Rename QueryCache::iter to for_each
Methods that perform internal iteration are typically named `for_each`.
1 parent d956393 commit f244b26

4 files changed

Lines changed: 18 additions & 13 deletions

File tree

compiler/rustc_data_structures/src/vec_cache.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ where
341341
}
342342
}
343343

344-
pub fn iter(&self, f: &mut dyn FnMut(&K, &V, I)) {
344+
pub fn for_each(&self, f: &mut dyn FnMut(&K, &V, I)) {
345345
for idx in 0..self.len.load(Ordering::Acquire) {
346346
let key = SlotIndex::from_index(idx as u32);
347347
match unsafe { key.get(&self.present) } {

compiler/rustc_middle/src/query/caches.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,13 @@ pub trait QueryCache: Sized {
2828
/// value by executing the query or loading a cached value from disk.
2929
fn complete(&self, key: Self::Key, value: Self::Value, index: DepNodeIndex);
3030

31-
fn iter(&self, f: &mut dyn FnMut(&Self::Key, &Self::Value, DepNodeIndex));
31+
/// Calls a closure on each entry in this cache.
32+
fn for_each(&self, f: &mut dyn FnMut(&Self::Key, &Self::Value, DepNodeIndex));
3233

34+
/// Returns the number of entries currently in this cache.
35+
///
36+
/// Useful for reserving capacity in data structures that will hold the
37+
/// output of a call to [`Self::for_each`].
3338
fn len(&self) -> usize;
3439
}
3540

@@ -65,7 +70,7 @@ where
6570
self.cache.insert(key, (value, index));
6671
}
6772

68-
fn iter(&self, f: &mut dyn FnMut(&Self::Key, &Self::Value, DepNodeIndex)) {
73+
fn for_each(&self, f: &mut dyn FnMut(&Self::Key, &Self::Value, DepNodeIndex)) {
6974
for shard in self.cache.lock_shards() {
7075
for (k, v) in shard.iter() {
7176
f(k, &v.0, v.1);
@@ -107,7 +112,7 @@ where
107112
self.cache.set((value, index)).ok();
108113
}
109114

110-
fn iter(&self, f: &mut dyn FnMut(&Self::Key, &Self::Value, DepNodeIndex)) {
115+
fn for_each(&self, f: &mut dyn FnMut(&Self::Key, &Self::Value, DepNodeIndex)) {
111116
if let Some(value) = self.cache.get() {
112117
f(&(), &value.0, value.1)
113118
}
@@ -160,11 +165,11 @@ where
160165
}
161166
}
162167

163-
fn iter(&self, f: &mut dyn FnMut(&Self::Key, &Self::Value, DepNodeIndex)) {
164-
self.local.iter(&mut |key, value, index| {
168+
fn for_each(&self, f: &mut dyn FnMut(&Self::Key, &Self::Value, DepNodeIndex)) {
169+
self.local.for_each(&mut |key, value, index| {
165170
f(&DefId { krate: LOCAL_CRATE, index: *key }, value, index);
166171
});
167-
self.foreign.iter(f);
172+
self.foreign.for_each(f);
168173
}
169174

170175
fn len(&self) -> usize {
@@ -190,8 +195,8 @@ where
190195
self.complete(key, value, index)
191196
}
192197

193-
fn iter(&self, f: &mut dyn FnMut(&Self::Key, &Self::Value, DepNodeIndex)) {
194-
self.iter(f)
198+
fn for_each(&self, f: &mut dyn FnMut(&Self::Key, &Self::Value, DepNodeIndex)) {
199+
self.for_each(f)
195200
}
196201

197202
fn len(&self) -> usize {

compiler/rustc_query_impl/src/plumbing.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ pub(crate) fn encode_query_results<'a, 'tcx, C, V>(
167167
let _timer = tcx.prof.generic_activity_with_arg("encode_query_results_for", query.name);
168168

169169
assert!(all_inactive(&query.state));
170-
query.cache.iter(&mut |key, value, dep_node| {
170+
query.cache.for_each(&mut |key, value, dep_node| {
171171
if query.will_cache_on_disk_for_key(tcx, key) {
172172
let dep_node = SerializedDepNodeIndex::new(dep_node.index());
173173

@@ -189,7 +189,7 @@ pub(crate) fn query_key_hash_verify<'tcx, C: QueryCache>(
189189

190190
let cache = &query.cache;
191191
let mut map = UnordMap::with_capacity(cache.len());
192-
cache.iter(&mut |key, _, _| {
192+
cache.for_each(&mut |key, _, _| {
193193
let node = DepNode::construct(tcx, query.dep_kind, key);
194194
if let Some(other_key) = map.insert(node, *key) {
195195
bug!(

compiler/rustc_query_impl/src/profiling_support.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ pub(crate) fn alloc_self_profile_query_strings_for_query_cache<'tcx, C>(
200200
// locked while doing so. Instead we copy out the
201201
// `(query_key, dep_node_index)` pairs and release the lock again.
202202
let mut query_keys_and_indices = Vec::new();
203-
query_cache.iter(&mut |k, _, i| query_keys_and_indices.push((*k, i)));
203+
query_cache.for_each(&mut |k, _, i| query_keys_and_indices.push((*k, i)));
204204

205205
// Now actually allocate the strings. If allocating the strings
206206
// generates new entries in the query cache, we'll miss them but
@@ -228,7 +228,7 @@ pub(crate) fn alloc_self_profile_query_strings_for_query_cache<'tcx, C>(
228228
// instead of passing the `DepNodeIndex` to `finish_with_query_invocation_id`,
229229
// when recording the event in the first place.
230230
let mut query_invocation_ids = Vec::new();
231-
query_cache.iter(&mut |_, _, i| {
231+
query_cache.for_each(&mut |_, _, i| {
232232
query_invocation_ids.push(i.into());
233233
});
234234

0 commit comments

Comments
 (0)