Skip to content

Commit 9fe0dee

Browse files
committed
Rename several parts of active-query-job collection
1 parent 57d2fb1 commit 9fe0dee

6 files changed

Lines changed: 140 additions & 107 deletions

File tree

compiler/rustc_interface/src/util.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,12 +244,12 @@ pub(crate) fn run_in_thread_pool_with_globals<
244244
tls::with(|tcx| {
245245
// Accessing session globals is sound as they outlive `GlobalCtxt`.
246246
// They are needed to hash query keys containing spans or symbols.
247-
let query_map = rustc_span::set_session_globals_then(unsafe { &*(session_globals as *const SessionGlobals) }, || {
247+
let job_map = rustc_span::set_session_globals_then(unsafe { &*(session_globals as *const SessionGlobals) }, || {
248248
// Ensure there was no errors collecting all active jobs.
249249
// We need the complete map to ensure we find a cycle to break.
250-
QueryCtxt::new(tcx).collect_active_jobs(false).expect("failed to collect active queries in deadlock handler")
250+
QueryCtxt::new(tcx).collect_active_jobs_from_all_queries(false).expect("failed to collect active queries in deadlock handler")
251251
});
252-
break_query_cycles(query_map, &registry);
252+
break_query_cycles(job_map, &registry);
253253
})
254254
})
255255
});

compiler/rustc_query_impl/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use rustc_query_system::Value;
2020
use rustc_query_system::dep_graph::SerializedDepNodeIndex;
2121
use rustc_query_system::ich::StableHashingContext;
2222
use rustc_query_system::query::{
23-
CycleError, CycleErrorHandling, HashResult, QueryCache, QueryDispatcher, QueryMap, QueryMode,
23+
CycleError, CycleErrorHandling, HashResult, JobMap, QueryCache, QueryDispatcher, QueryMode,
2424
QueryState, get_query_incr, get_query_non_incr,
2525
};
2626
use rustc_span::{ErrorGuaranteed, Span};

compiler/rustc_query_impl/src/plumbing.rs

Lines changed: 45 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use rustc_middle::ty::{self, TyCtxt};
2727
use rustc_query_system::dep_graph::{DepNodeParams, HasDepContext};
2828
use rustc_query_system::ich::StableHashingContext;
2929
use rustc_query_system::query::{
30-
QueryCache, QueryContext, QueryDispatcher, QueryJobId, QueryMap, QuerySideEffect,
30+
JobMap, QueryCache, QueryContext, QueryDispatcher, QueryJobId, QuerySideEffect,
3131
QueryStackDeferred, QueryStackFrame, QueryStackFrameExtra, force_query,
3232
};
3333
use rustc_query_system::{QueryOverflow, QueryOverflowNote};
@@ -81,7 +81,7 @@ impl<'tcx> QueryContext<'tcx> for QueryCtxt<'tcx> {
8181
tls::with_related_context(self.tcx, |icx| icx.query)
8282
}
8383

84-
/// Returns a map of currently active query jobs.
84+
/// Returns a map of currently active query jobs, collected from all queries.
8585
///
8686
/// If `require_complete` is `true`, this function locks all shards of the
8787
/// query results to produce a complete map, which always returns `Ok`.
@@ -91,17 +91,20 @@ impl<'tcx> QueryContext<'tcx> for QueryCtxt<'tcx> {
9191
/// Prefer passing `false` to `require_complete` to avoid potential deadlocks,
9292
/// especially when called from within a deadlock handler, unless a
9393
/// complete map is needed and no deadlock is possible at this call site.
94-
fn collect_active_jobs(self, require_complete: bool) -> Result<QueryMap<'tcx>, QueryMap<'tcx>> {
95-
let mut jobs = QueryMap::default();
94+
fn collect_active_jobs_from_all_queries(
95+
self,
96+
require_complete: bool,
97+
) -> Result<JobMap<'tcx>, JobMap<'tcx>> {
98+
let mut job_map = JobMap::default();
9699
let mut complete = true;
97100

98-
for collect in super::COLLECT_ACTIVE_JOBS.iter() {
99-
if collect(self.tcx, &mut jobs, require_complete).is_none() {
101+
for gather_fn in crate::PER_QUERY_GATHER_ACTIVE_JOBS_FNS.iter() {
102+
if gather_fn(self.tcx, &mut job_map, require_complete).is_none() {
100103
complete = false;
101104
}
102105
}
103106

104-
if complete { Ok(jobs) } else { Err(jobs) }
107+
if complete { Ok(job_map) } else { Err(job_map) }
105108
}
106109

107110
fn lift_query_info(
@@ -164,18 +167,20 @@ impl<'tcx> QueryContext<'tcx> for QueryCtxt<'tcx> {
164167
}
165168

166169
fn depth_limit_error(self, job: QueryJobId) {
167-
let query_map = self.collect_active_jobs(true).expect("failed to collect active queries");
168-
let (info, depth) = job.find_dep_kind_root(query_map);
170+
let job_map = self
171+
.collect_active_jobs_from_all_queries(true)
172+
.expect("failed to collect active queries");
173+
let (job_info, depth) = job.find_dep_kind_root(job_map);
169174

170175
let suggested_limit = match self.tcx.recursion_limit() {
171176
Limit(0) => Limit(2),
172177
limit => limit * 2,
173178
};
174179

175180
self.tcx.sess.dcx().emit_fatal(QueryOverflow {
176-
span: info.job.span,
181+
span: job_info.job.span,
177182
note: QueryOverflowNote {
178-
desc: self.lift_query_info(&info.query.info).description,
183+
desc: self.lift_query_info(&job_info.deferred_frame.info).description,
179184
depth,
180185
},
181186
suggested_limit,
@@ -356,7 +361,7 @@ fn mk_query_stack_frame_extra<'tcx, K: Key + Copy + 'tcx>(
356361
QueryStackFrameExtra::new(description, span, def_kind)
357362
}
358363

359-
pub(crate) fn create_query_frame<
364+
pub(crate) fn mk_deferred_query_stack_frame<
360365
'tcx,
361366
K: Copy + DynSend + DynSync + Key + for<'a> HashStable<StableHashingContext<'a>> + 'tcx,
362367
>(
@@ -733,20 +738,28 @@ macro_rules! define_queries {
733738
}
734739
}
735740

736-
pub(crate) fn collect_active_jobs<'tcx>(
741+
/// Internal per-query plumbing for collecting the set of active jobs for this query.
742+
///
743+
/// Should only be called through `PER_QUERY_GATHER_ACTIVE_JOBS_FNS`.
744+
pub(crate) fn gather_active_jobs_outer<'tcx>(
737745
tcx: TyCtxt<'tcx>,
738-
qmap: &mut QueryMap<'tcx>,
746+
job_map: &mut JobMap<'tcx>,
739747
require_complete: bool,
740748
) -> Option<()> {
741-
let make_query = |tcx, key| {
742-
let kind = rustc_middle::dep_graph::dep_kinds::$name;
743-
let name = stringify!($name);
744-
$crate::plumbing::create_query_frame(tcx, rustc_middle::query::descs::$name, key, kind, name)
749+
let mk_deferred_frame_fn = |tcx, key| {
750+
$crate::plumbing::mk_deferred_query_stack_frame(
751+
tcx,
752+
rustc_middle::query::descs::$name,
753+
key,
754+
rustc_middle::dep_graph::dep_kinds::$name,
755+
stringify!($name),
756+
)
745757
};
746-
let res = tcx.query_system.states.$name.collect_active_jobs(
758+
// We can call `gather_active_jobs_inner` here.
759+
let res = tcx.query_system.states.$name.gather_active_jobs_inner(
747760
tcx,
748-
make_query,
749-
qmap,
761+
mk_deferred_frame_fn,
762+
job_map,
750763
require_complete,
751764
);
752765
// this can be called during unwinding, and the function has a `try_`-prefix, so
@@ -818,10 +831,17 @@ macro_rules! define_queries {
818831

819832
// These arrays are used for iteration and can't be indexed by `DepKind`.
820833

821-
const COLLECT_ACTIVE_JOBS: &[
822-
for<'tcx> fn(TyCtxt<'tcx>, &mut QueryMap<'tcx>, bool) -> Option<()>
823-
] =
824-
&[$(query_impl::$name::collect_active_jobs),*];
834+
/// Used by [`QueryCtxt::collect_active_jobs_from_all_queries`] to iterate over all
835+
/// queries, and gather the active jobs for each query.
836+
///
837+
/// (We arbitrarily use the word "gather" when collecting the jobs for
838+
/// each individual query, so that we have distinct function names to
839+
/// grep for.)
840+
const PER_QUERY_GATHER_ACTIVE_JOBS_FNS: &[
841+
for<'tcx> fn(TyCtxt<'tcx>, &mut JobMap<'tcx>, require_complete: bool) -> Option<()>
842+
] = &[
843+
$(query_impl::$name::gather_active_jobs_outer),*
844+
];
825845

826846
const ALLOC_SELF_PROFILE_QUERY_STRINGS: &[
827847
for<'tcx> fn(TyCtxt<'tcx>, &mut QueryKeyStringCache)

0 commit comments

Comments
 (0)