Skip to content

Commit 765fd2d

Browse files
committed
Auto merge of rust-lang#153114 - nnethercote:rm-query-arrays, r=petrochenkov
Remove query function arrays `define_queries!` produces four arrays of function pointers, which other functions iterate over. These aren't actually necessary. r? @petrochenkov
2 parents c2c6f74 + 90abede commit 765fd2d

File tree

5 files changed

+119
-190
lines changed

5 files changed

+119
-190
lines changed

compiler/rustc_query_impl/src/execution.rs

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,23 @@ use std::mem;
33

44
use rustc_data_structures::hash_table::{Entry, HashTable};
55
use rustc_data_structures::stack::ensure_sufficient_stack;
6+
use rustc_data_structures::sync::{DynSend, DynSync};
67
use rustc_data_structures::{outline, sharded, sync};
78
use rustc_errors::{Diag, FatalError, StashKey};
89
use rustc_middle::dep_graph::{DepGraphData, DepNodeKey, SerializedDepNodeIndex};
910
use rustc_middle::query::plumbing::QueryVTable;
1011
use rustc_middle::query::{
1112
ActiveKeyStatus, CycleError, CycleErrorHandling, EnsureMode, QueryCache, QueryJob, QueryJobId,
12-
QueryLatch, QueryMode, QueryStackDeferred, QueryStackFrame, QueryState,
13+
QueryKey, QueryLatch, QueryMode, QueryState,
1314
};
1415
use rustc_middle::ty::TyCtxt;
1516
use rustc_middle::verify_ich::incremental_verify_ich;
1617
use rustc_span::{DUMMY_SP, Span};
1718

19+
use crate::collect_active_jobs_from_all_queries;
1820
use crate::dep_graph::{DepNode, DepNodeIndex};
1921
use crate::job::{QueryJobInfo, QueryJobMap, find_cycle_in_stack, report_cycle};
20-
use crate::plumbing::{
21-
collect_active_jobs_from_all_queries, current_query_job, next_job_id, start_query,
22-
};
22+
use crate::plumbing::{current_query_job, next_job_id, start_query};
2323

2424
#[inline]
2525
fn equivalent_key<K: Eq, V>(k: &K) -> impl Fn(&(K, V)) -> bool + '_ {
@@ -43,18 +43,25 @@ pub(crate) fn all_inactive<'tcx, K>(state: &QueryState<'tcx, K>) -> bool {
4343

4444
/// Internal plumbing for collecting the set of active jobs for this query.
4545
///
46-
/// Should only be called from `gather_active_jobs`.
47-
pub(crate) fn gather_active_jobs_inner<'tcx, K: Copy>(
48-
state: &QueryState<'tcx, K>,
46+
/// Should only be called from `collect_active_jobs_from_all_queries`.
47+
///
48+
/// (We arbitrarily use the word "gather" when collecting the jobs for
49+
/// each individual query, so that we have distinct function names to
50+
/// grep for.)
51+
pub(crate) fn gather_active_jobs<'tcx, C>(
52+
query: &'tcx QueryVTable<'tcx, C>,
4953
tcx: TyCtxt<'tcx>,
50-
make_frame: fn(TyCtxt<'tcx>, K) -> QueryStackFrame<QueryStackDeferred<'tcx>>,
5154
require_complete: bool,
5255
job_map_out: &mut QueryJobMap<'tcx>, // Out-param; job info is gathered into this map
53-
) -> Option<()> {
56+
) -> Option<()>
57+
where
58+
C: QueryCache<Key: QueryKey + DynSend + DynSync>,
59+
QueryVTable<'tcx, C>: DynSync,
60+
{
5461
let mut active = Vec::new();
5562

5663
// Helper to gather active jobs from a single shard.
57-
let mut gather_shard_jobs = |shard: &HashTable<(K, ActiveKeyStatus<'tcx>)>| {
64+
let mut gather_shard_jobs = |shard: &HashTable<(C::Key, ActiveKeyStatus<'tcx>)>| {
5865
for (k, v) in shard.iter() {
5966
if let ActiveKeyStatus::Started(ref job) = *v {
6067
active.push((*k, job.clone()));
@@ -64,22 +71,33 @@ pub(crate) fn gather_active_jobs_inner<'tcx, K: Copy>(
6471

6572
// Lock shards and gather jobs from each shard.
6673
if require_complete {
67-
for shard in state.active.lock_shards() {
74+
for shard in query.state.active.lock_shards() {
6875
gather_shard_jobs(&shard);
6976
}
7077
} else {
7178
// We use try_lock_shards here since we are called from the
7279
// deadlock handler, and this shouldn't be locked.
73-
for shard in state.active.try_lock_shards() {
74-
let shard = shard?;
75-
gather_shard_jobs(&shard);
80+
for shard in query.state.active.try_lock_shards() {
81+
// This can be called during unwinding, and the function has a `try_`-prefix, so
82+
// don't `unwrap()` here, just manually check for `None` and do best-effort error
83+
// reporting.
84+
match shard {
85+
None => {
86+
tracing::warn!(
87+
"Failed to collect active jobs for query with name `{}`!",
88+
query.name
89+
);
90+
return None;
91+
}
92+
Some(shard) => gather_shard_jobs(&shard),
93+
}
7694
}
7795
}
7896

7997
// Call `make_frame` while we're not holding a `state.active` lock as `make_frame` may call
8098
// queries leading to a deadlock.
8199
for (key, job) in active {
82-
let frame = make_frame(tcx, key);
100+
let frame = crate::plumbing::create_deferred_query_stack_frame(tcx, query, key);
83101
job_map_out.insert(job.id, QueryJobInfo { frame, job });
84102
}
85103

compiler/rustc_query_impl/src/job.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use rustc_middle::ty::TyCtxt;
1414
use rustc_session::Session;
1515
use rustc_span::{DUMMY_SP, Span};
1616

17-
use crate::plumbing::collect_active_jobs_from_all_queries;
17+
use crate::collect_active_jobs_from_all_queries;
1818

1919
/// Map from query job IDs to job information collected by
2020
/// `collect_active_jobs_from_all_queries`.
@@ -26,7 +26,7 @@ pub struct QueryJobMap<'tcx> {
2626
impl<'tcx> QueryJobMap<'tcx> {
2727
/// Adds information about a job ID to the job map.
2828
///
29-
/// Should only be called by `gather_active_jobs_inner`.
29+
/// Should only be called by `gather_active_jobs`.
3030
pub(crate) fn insert(&mut self, id: QueryJobId, info: QueryJobInfo<'tcx>) {
3131
self.map.insert(id, info);
3232
}

compiler/rustc_query_impl/src/lib.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,8 @@ use rustc_span::Span;
1919

2020
pub use crate::dep_kind_vtables::make_dep_kind_vtables;
2121
pub use crate::job::{QueryJobMap, break_query_cycles, print_query_stack};
22-
pub use crate::plumbing::{collect_active_jobs_from_all_queries, query_key_hash_verify_all};
23-
use crate::plumbing::{encode_all_query_results, try_mark_green};
22+
use crate::plumbing::try_mark_green;
2423
use crate::profiling_support::QueryKeyStringCache;
25-
pub use crate::profiling_support::alloc_self_profile_query_strings;
2624
use crate::values::Value;
2725

2826
#[macro_use]

0 commit comments

Comments
 (0)