Skip to content

Commit 45263da

Browse files
committed
Auto merge of #153940 - nnethercote:rename-all-query-fns, r=Zalathar
Rename all-query functions. There are four functions that use `for_each_query_vtable!` to call an "inner" function. They are: - `collect_active_jobs_from_all_queries` -> `gather_active_jobs` - `alloc_self_profile_query_strings` -> `alloc_self_profile_query_strings_for_query_cache` - `encode_all_query_results` -> `encode_query_results` - `query_key_hash_verify_all` -> `query_key_hash_verify` These names are all over the place. This commit renames them as follows: - `collect_active_query_jobs{,_inner}` - `alloc_self_profile_query_strings{,_inner}` - `encode_query_values{,_inner}` - `verify_query_key_hashes{,_inner}` This: - puts the verb at the start - uses `_inner` for all the inners (which makes sense now that the inners are all next to their callers) - uses `_query_` consistently - avoids `all`, because the plurals are enough - uses `values` instead of `results` - removes the `collect`/`gather` distinction, which is no longer important r? @Zalathar
2 parents 5b61449 + a8024fc commit 45263da

File tree

9 files changed

+33
-49
lines changed

9 files changed

+33
-49
lines changed

compiler/rustc_interface/src/util.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use rustc_data_structures::sync;
1818
use rustc_metadata::{DylibError, EncodedMetadata, load_symbol_from_dylib};
1919
use rustc_middle::dep_graph::{WorkProduct, WorkProductId};
2020
use rustc_middle::ty::{CurrentGcx, TyCtxt};
21-
use rustc_query_impl::{CollectActiveJobsKind, collect_active_jobs_from_all_queries};
21+
use rustc_query_impl::{CollectActiveJobsKind, collect_active_query_jobs};
2222
use rustc_session::config::{
2323
Cfg, CrateType, OutFileName, OutputFilenames, OutputTypes, Sysroot, host_tuple,
2424
};
@@ -255,7 +255,7 @@ internal compiler error: query cycle handler thread panicked, aborting process";
255255
// Ensure there were no errors collecting all active jobs.
256256
// We need the complete map to ensure we find a cycle to
257257
// break.
258-
collect_active_jobs_from_all_queries(
258+
collect_active_query_jobs(
259259
tcx,
260260
CollectActiveJobsKind::FullNoContention,
261261
)

compiler/rustc_middle/src/hooks/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ declare_hooks! {
9898
/// Trying to execute a query afterwards would attempt to read the result cache we just dropped.
9999
hook save_dep_graph() -> ();
100100

101-
hook query_key_hash_verify_all() -> ();
101+
hook verify_query_key_hashes() -> ();
102102

103103
/// Ensure the given scalar is valid for the given type.
104104
/// This checks non-recursive runtime validity.
@@ -109,7 +109,7 @@ declare_hooks! {
109109
/// Creates the MIR for a given `DefId`, including unreachable code.
110110
hook build_mir_inner_impl(def: LocalDefId) -> mir::Body<'tcx>;
111111

112-
hook encode_all_query_results(
112+
hook encode_query_values(
113113
encoder: &mut CacheEncoder<'_, 'tcx>,
114114
query_result_index: &mut EncodedDepNodeIndex
115115
) -> ();

compiler/rustc_middle/src/query/on_disk_cache.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,10 +246,10 @@ impl OnDiskCache {
246246
// Encode query results.
247247
let mut query_result_index = EncodedDepNodeIndex::new();
248248

249-
tcx.sess.time("encode_query_results", || {
249+
tcx.sess.time("encode_query_values", || {
250250
let enc = &mut encoder;
251251
let qri = &mut query_result_index;
252-
tcx.encode_all_query_results(enc, qri);
252+
tcx.encode_query_values(enc, qri);
253253
});
254254

255255
// Encode side effects.

compiler/rustc_middle/src/ty/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1678,7 +1678,7 @@ impl<'tcx> TyCtxt<'tcx> {
16781678
self.alloc_self_profile_query_strings();
16791679

16801680
self.save_dep_graph();
1681-
self.query_key_hash_verify_all();
1681+
self.verify_query_key_hashes();
16821682

16831683
if let Err((path, error)) = self.dep_graph.finish_encoding() {
16841684
self.sess.dcx().emit_fatal(crate::error::FailedWritingFile { path: &path, error });

compiler/rustc_query_impl/src/execution.rs

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -47,46 +47,31 @@ pub enum CollectActiveJobsKind {
4747
}
4848

4949
/// Returns a map of currently active query jobs, collected from all queries.
50-
///
51-
/// If `require_complete` is `true`, this function locks all shards of the
52-
/// query results to produce a complete map, which always returns `Ok`.
53-
/// Otherwise, it may return an incomplete map as an error if any shard
54-
/// lock cannot be acquired.
55-
///
56-
/// Prefer passing `false` to `require_complete` to avoid potential deadlocks,
57-
/// especially when called from within a deadlock handler, unless a
58-
/// complete map is needed and no deadlock is possible at this call site.
59-
pub fn collect_active_jobs_from_all_queries<'tcx>(
50+
pub fn collect_active_query_jobs<'tcx>(
6051
tcx: TyCtxt<'tcx>,
6152
collect_kind: CollectActiveJobsKind,
6253
) -> QueryJobMap<'tcx> {
6354
let mut job_map = QueryJobMap::default();
6455

6556
for_each_query_vtable!(ALL, tcx, |query| {
66-
gather_active_jobs(query, collect_kind, &mut job_map);
57+
collect_active_query_jobs_inner(query, collect_kind, &mut job_map);
6758
});
6859

6960
job_map
7061
}
7162

7263
/// Internal plumbing for collecting the set of active jobs for this query.
7364
///
74-
/// Should only be called from `collect_active_jobs_from_all_queries`.
75-
///
76-
/// (We arbitrarily use the word "gather" when collecting the jobs for
77-
/// each individual query, so that we have distinct function names to
78-
/// grep for.)
79-
///
8065
/// Aborts if jobs can't be gathered as specified by `collect_kind`.
81-
fn gather_active_jobs<'tcx, C>(
66+
fn collect_active_query_jobs_inner<'tcx, C>(
8267
query: &'tcx QueryVTable<'tcx, C>,
8368
collect_kind: CollectActiveJobsKind,
8469
job_map: &mut QueryJobMap<'tcx>,
8570
) where
8671
C: QueryCache<Key: QueryKey + DynSend + DynSync>,
8772
QueryVTable<'tcx, C>: DynSync,
8873
{
89-
let mut gather_shard_jobs = |shard: &HashTable<(C::Key, ActiveKeyStatus<'tcx>)>| {
74+
let mut collect_shard_jobs = |shard: &HashTable<(C::Key, ActiveKeyStatus<'tcx>)>| {
9075
for (key, status) in shard.iter() {
9176
if let ActiveKeyStatus::Started(job) = status {
9277
// This function is safe to call with the shard locked because it is very simple.
@@ -99,21 +84,21 @@ fn gather_active_jobs<'tcx, C>(
9984
match collect_kind {
10085
CollectActiveJobsKind::Full => {
10186
for shard in query.state.active.lock_shards() {
102-
gather_shard_jobs(&shard);
87+
collect_shard_jobs(&shard);
10388
}
10489
}
10590
CollectActiveJobsKind::FullNoContention => {
10691
for shard in query.state.active.try_lock_shards() {
10792
match shard {
108-
Some(shard) => gather_shard_jobs(&shard),
93+
Some(shard) => collect_shard_jobs(&shard),
10994
None => panic!("Failed to collect active jobs for query `{}`!", query.name),
11095
}
11196
}
11297
}
11398
CollectActiveJobsKind::PartialAllowed => {
11499
for shard in query.state.active.try_lock_shards() {
115100
match shard {
116-
Some(shard) => gather_shard_jobs(&shard),
101+
Some(shard) => collect_shard_jobs(&shard),
117102
None => warn!("Failed to collect active jobs for query `{}`!", query.name),
118103
}
119104
}
@@ -218,8 +203,7 @@ fn cycle_error<'tcx, C: QueryCache>(
218203
) -> (C::Value, Option<DepNodeIndex>) {
219204
// Ensure there were no errors collecting all active jobs.
220205
// We need the complete map to ensure we find a cycle to break.
221-
let job_map =
222-
collect_active_jobs_from_all_queries(tcx, CollectActiveJobsKind::FullNoContention);
206+
let job_map = collect_active_query_jobs(tcx, CollectActiveJobsKind::FullNoContention);
223207

224208
let error = find_cycle_in_stack(try_execute, job_map, &current_query_job(), span);
225209
(mk_cycle(query, tcx, key, error), None)

compiler/rustc_query_impl/src/job.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ use rustc_middle::query::{
1212
use rustc_middle::ty::TyCtxt;
1313
use rustc_span::{DUMMY_SP, Span, respan};
1414

15-
use crate::{CollectActiveJobsKind, collect_active_jobs_from_all_queries};
15+
use crate::{CollectActiveJobsKind, collect_active_query_jobs};
1616

1717
/// Map from query job IDs to job information collected by
18-
/// `collect_active_jobs_from_all_queries`.
18+
/// `collect_active_query_jobs`.
1919
#[derive(Debug, Default)]
2020
pub struct QueryJobMap<'tcx> {
2121
map: FxHashMap<QueryJobId, QueryJobInfo<'tcx>>,
@@ -24,7 +24,7 @@ pub struct QueryJobMap<'tcx> {
2424
impl<'tcx> QueryJobMap<'tcx> {
2525
/// Adds information about a job ID to the job map.
2626
///
27-
/// Should only be called by `gather_active_jobs`.
27+
/// Should only be called by `collect_active_query_jobs_inner`.
2828
pub(crate) fn insert(&mut self, id: QueryJobId, info: QueryJobInfo<'tcx>) {
2929
self.map.insert(id, info);
3030
}
@@ -407,7 +407,7 @@ pub fn print_query_stack<'tcx>(
407407
let mut count_total = 0;
408408

409409
// Make use of a partial query job map if we fail to take locks collecting active queries.
410-
let job_map = collect_active_jobs_from_all_queries(tcx, CollectActiveJobsKind::PartialAllowed);
410+
let job_map = collect_active_query_jobs(tcx, CollectActiveJobsKind::PartialAllowed);
411411

412412
if let Some(ref mut file) = file {
413413
let _ = writeln!(file, "\n\nquery stack during panic:");

compiler/rustc_query_impl/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use rustc_middle::query::plumbing::{QuerySystem, QueryVTable};
1717
use rustc_middle::ty::TyCtxt;
1818

1919
pub use crate::dep_kind_vtables::make_dep_kind_vtables;
20-
pub use crate::execution::{CollectActiveJobsKind, collect_active_jobs_from_all_queries};
20+
pub use crate::execution::{CollectActiveJobsKind, collect_active_query_jobs};
2121
pub use crate::job::{QueryJobMap, break_query_cycles, print_query_stack};
2222

2323
mod dep_kind_vtables;
@@ -64,6 +64,6 @@ pub fn query_system<'tcx>(
6464
pub fn provide(providers: &mut rustc_middle::util::Providers) {
6565
providers.hooks.alloc_self_profile_query_strings =
6666
profiling_support::alloc_self_profile_query_strings;
67-
providers.hooks.query_key_hash_verify_all = plumbing::query_key_hash_verify_all;
68-
providers.hooks.encode_all_query_results = plumbing::encode_all_query_results;
67+
providers.hooks.verify_query_key_hashes = plumbing::verify_query_key_hashes;
68+
providers.hooks.encode_query_values = plumbing::encode_query_values;
6969
}

compiler/rustc_query_impl/src/plumbing.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ use crate::error::{QueryOverflow, QueryOverflowNote};
2626
use crate::execution::{all_inactive, force_query};
2727
use crate::job::find_dep_kind_root;
2828
use crate::query_impl::for_each_query_vtable;
29-
use crate::{CollectActiveJobsKind, GetQueryVTable, collect_active_jobs_from_all_queries};
29+
use crate::{CollectActiveJobsKind, GetQueryVTable, collect_active_query_jobs};
3030

3131
fn depth_limit_error<'tcx>(tcx: TyCtxt<'tcx>, job: QueryJobId) {
32-
let job_map = collect_active_jobs_from_all_queries(tcx, CollectActiveJobsKind::Full);
32+
let job_map = collect_active_query_jobs(tcx, CollectActiveJobsKind::Full);
3333
let (span, desc, depth) = find_dep_kind_root(tcx, job, job_map);
3434

3535
let suggested_limit = match tcx.recursion_limit() {
@@ -99,17 +99,17 @@ where
9999
}
100100
}
101101

102-
pub(crate) fn encode_all_query_results<'tcx>(
102+
pub(crate) fn encode_query_values<'tcx>(
103103
tcx: TyCtxt<'tcx>,
104104
encoder: &mut CacheEncoder<'_, 'tcx>,
105105
query_result_index: &mut EncodedDepNodeIndex,
106106
) {
107107
for_each_query_vtable!(CACHE_ON_DISK, tcx, |query| {
108-
encode_query_results(tcx, query, encoder, query_result_index)
108+
encode_query_values_inner(tcx, query, encoder, query_result_index)
109109
});
110110
}
111111

112-
fn encode_query_results<'a, 'tcx, C, V>(
112+
fn encode_query_values_inner<'a, 'tcx, C, V>(
113113
tcx: TyCtxt<'tcx>,
114114
query: &'tcx QueryVTable<'tcx, C>,
115115
encoder: &mut CacheEncoder<'a, 'tcx>,
@@ -135,17 +135,17 @@ fn encode_query_results<'a, 'tcx, C, V>(
135135
});
136136
}
137137

138-
pub(crate) fn query_key_hash_verify_all<'tcx>(tcx: TyCtxt<'tcx>) {
138+
pub(crate) fn verify_query_key_hashes<'tcx>(tcx: TyCtxt<'tcx>) {
139139
if tcx.sess.opts.unstable_opts.incremental_verify_ich || cfg!(debug_assertions) {
140-
tcx.sess.time("query_key_hash_verify_all", || {
140+
tcx.sess.time("verify_query_key_hashes", || {
141141
for_each_query_vtable!(ALL, tcx, |query| {
142-
query_key_hash_verify(query, tcx);
142+
verify_query_key_hashes_inner(query, tcx);
143143
});
144144
});
145145
}
146146
}
147147

148-
fn query_key_hash_verify<'tcx, C: QueryCache>(
148+
fn verify_query_key_hashes_inner<'tcx, C: QueryCache>(
149149
query: &'tcx QueryVTable<'tcx, C>,
150150
tcx: TyCtxt<'tcx>,
151151
) {

compiler/rustc_query_impl/src/profiling_support.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ pub(crate) fn alloc_self_profile_query_strings(tcx: TyCtxt<'_>) {
192192
let mut string_cache = QueryKeyStringCache::new();
193193

194194
for_each_query_vtable!(ALL, tcx, |query| {
195-
alloc_self_profile_query_strings_for_query_cache(tcx, query, &mut string_cache);
195+
alloc_self_profile_query_strings_inner(tcx, query, &mut string_cache);
196196
});
197197

198198
tcx.sess.prof.store_query_cache_hits();
@@ -201,7 +201,7 @@ pub(crate) fn alloc_self_profile_query_strings(tcx: TyCtxt<'_>) {
201201
/// Allocate the self-profiling query strings for a single query cache. This
202202
/// method is called from `alloc_self_profile_query_strings` which knows all
203203
/// the queries via macro magic.
204-
fn alloc_self_profile_query_strings_for_query_cache<'tcx, C>(
204+
fn alloc_self_profile_query_strings_inner<'tcx, C>(
205205
tcx: TyCtxt<'tcx>,
206206
query: &'tcx QueryVTable<'tcx, C>,
207207
string_cache: &mut QueryKeyStringCache,

0 commit comments

Comments
 (0)