Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_data_structures/src/vec_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ where
}
}

pub fn iter(&self, f: &mut dyn FnMut(&K, &V, I)) {
pub fn for_each(&self, f: &mut dyn FnMut(&K, &V, I)) {
for idx in 0..self.len.load(Ordering::Acquire) {
let key = SlotIndex::from_index(idx as u32);
match unsafe { key.get(&self.present) } {
Expand Down
21 changes: 13 additions & 8 deletions compiler/rustc_middle/src/query/caches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,13 @@ pub trait QueryCache: Sized {
/// value by executing the query or loading a cached value from disk.
fn complete(&self, key: Self::Key, value: Self::Value, index: DepNodeIndex);

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

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

Expand Down Expand Up @@ -65,7 +70,7 @@ where
self.cache.insert(key, (value, index));
}

fn iter(&self, f: &mut dyn FnMut(&Self::Key, &Self::Value, DepNodeIndex)) {
fn for_each(&self, f: &mut dyn FnMut(&Self::Key, &Self::Value, DepNodeIndex)) {
for shard in self.cache.lock_shards() {
for (k, v) in shard.iter() {
f(k, &v.0, v.1);
Expand Down Expand Up @@ -107,7 +112,7 @@ where
self.cache.set((value, index)).ok();
}

fn iter(&self, f: &mut dyn FnMut(&Self::Key, &Self::Value, DepNodeIndex)) {
fn for_each(&self, f: &mut dyn FnMut(&Self::Key, &Self::Value, DepNodeIndex)) {
if let Some(value) = self.cache.get() {
f(&(), &value.0, value.1)
}
Expand Down Expand Up @@ -160,11 +165,11 @@ where
}
}

fn iter(&self, f: &mut dyn FnMut(&Self::Key, &Self::Value, DepNodeIndex)) {
self.local.iter(&mut |key, value, index| {
fn for_each(&self, f: &mut dyn FnMut(&Self::Key, &Self::Value, DepNodeIndex)) {
self.local.for_each(&mut |key, value, index| {
f(&DefId { krate: LOCAL_CRATE, index: *key }, value, index);
});
self.foreign.iter(f);
self.foreign.for_each(f);
}

fn len(&self) -> usize {
Expand All @@ -190,8 +195,8 @@ where
self.complete(key, value, index)
}

fn iter(&self, f: &mut dyn FnMut(&Self::Key, &Self::Value, DepNodeIndex)) {
self.iter(f)
fn for_each(&self, f: &mut dyn FnMut(&Self::Key, &Self::Value, DepNodeIndex)) {
self.for_each(f)
}

fn len(&self) -> usize {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_query_impl/src/plumbing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ pub(crate) fn encode_query_results<'a, 'tcx, C, V>(
let _timer = tcx.prof.generic_activity_with_arg("encode_query_results_for", query.name);

assert!(all_inactive(&query.state));
query.cache.iter(&mut |key, value, dep_node| {
query.cache.for_each(&mut |key, value, dep_node| {
if (query.will_cache_on_disk_for_key_fn)(tcx, key) {
let dep_node = SerializedDepNodeIndex::new(dep_node.index());

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

let cache = &query.cache;
let mut map = UnordMap::with_capacity(cache.len());
cache.iter(&mut |key, _, _| {
cache.for_each(&mut |key, _, _| {
let node = DepNode::construct(tcx, query.dep_kind, key);
if let Some(other_key) = map.insert(node, *key) {
bug!(
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_query_impl/src/profiling_support.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ pub(crate) fn alloc_self_profile_query_strings_for_query_cache<'tcx, C>(
// locked while doing so. Instead we copy out the
// `(query_key, dep_node_index)` pairs and release the lock again.
let mut query_keys_and_indices = Vec::new();
query_cache.iter(&mut |k, _, i| query_keys_and_indices.push((*k, i)));
query_cache.for_each(&mut |k, _, i| query_keys_and_indices.push((*k, i)));

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

Expand Down
Loading