Skip to content

Commit 6b0beec

Browse files
committed
Remove PER_QUERY_GATHER_ACTIVE_JOBS_FNS.
And also `gather_active_jobs` for each query. This is done by generating `collect_active_jobs_from_all_queries` and having it do things more directly.
1 parent 65cf5d7 commit 6b0beec

4 files changed

Lines changed: 42 additions & 65 deletions

File tree

compiler/rustc_query_impl/src/execution.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,10 @@ use rustc_middle::ty::TyCtxt;
1616
use rustc_middle::verify_ich::incremental_verify_ich;
1717
use rustc_span::{DUMMY_SP, Span};
1818

19+
use crate::collect_active_jobs_from_all_queries;
1920
use crate::dep_graph::{DepNode, DepNodeIndex};
2021
use crate::job::{QueryJobInfo, QueryJobMap, find_cycle_in_stack, report_cycle};
21-
use crate::plumbing::{
22-
collect_active_jobs_from_all_queries, current_query_job, next_job_id, start_query,
23-
};
22+
use crate::plumbing::{current_query_job, next_job_id, start_query};
2423

2524
#[inline]
2625
fn equivalent_key<K: Eq, V>(k: &K) -> impl Fn(&(K, V)) -> bool + '_ {
@@ -44,8 +43,12 @@ pub(crate) fn all_inactive<'tcx, K>(state: &QueryState<'tcx, K>) -> bool {
4443

4544
/// Internal plumbing for collecting the set of active jobs for this query.
4645
///
47-
/// Should only be called from `gather_active_jobs`.
48-
pub(crate) fn gather_active_jobs_inner<'tcx, C>(
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>(
4952
query: &'tcx QueryVTable<'tcx, C>,
5053
tcx: TyCtxt<'tcx>,
5154
require_complete: bool,

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: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ 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;
2322
use crate::plumbing::{encode_all_query_results, try_mark_green};
2423
use crate::profiling_support::QueryKeyStringCache;
2524
pub use crate::profiling_support::alloc_self_profile_query_strings;

compiler/rustc_query_impl/src/plumbing.rs

Lines changed: 32 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@ use rustc_middle::ty::{self, TyCtxt};
2929
use rustc_serialize::{Decodable, Encodable};
3030
use rustc_span::def_id::LOCAL_CRATE;
3131

32+
use crate::collect_active_jobs_from_all_queries;
3233
use crate::error::{QueryOverflow, QueryOverflowNote};
3334
use crate::execution::{all_inactive, force_query};
34-
use crate::job::{QueryJobMap, find_dep_kind_root};
35+
use crate::job::find_dep_kind_root;
3536

3637
fn depth_limit_error<'tcx>(tcx: TyCtxt<'tcx>, job: QueryJobId) {
3738
let job_map =
@@ -94,32 +95,6 @@ pub(crate) fn start_query<'tcx, R>(
9495
})
9596
}
9697

97-
/// Returns a map of currently active query jobs, collected from all queries.
98-
///
99-
/// If `require_complete` is `true`, this function locks all shards of the
100-
/// query results to produce a complete map, which always returns `Ok`.
101-
/// Otherwise, it may return an incomplete map as an error if any shard
102-
/// lock cannot be acquired.
103-
///
104-
/// Prefer passing `false` to `require_complete` to avoid potential deadlocks,
105-
/// especially when called from within a deadlock handler, unless a
106-
/// complete map is needed and no deadlock is possible at this call site.
107-
pub fn collect_active_jobs_from_all_queries<'tcx>(
108-
tcx: TyCtxt<'tcx>,
109-
require_complete: bool,
110-
) -> Result<QueryJobMap<'tcx>, QueryJobMap<'tcx>> {
111-
let mut job_map_out = QueryJobMap::default();
112-
let mut complete = true;
113-
114-
for gather_fn in crate::PER_QUERY_GATHER_ACTIVE_JOBS_FNS.iter() {
115-
if gather_fn(tcx, require_complete, &mut job_map_out).is_none() {
116-
complete = false;
117-
}
118-
}
119-
120-
if complete { Ok(job_map_out) } else { Err(job_map_out) }
121-
}
122-
12398
pub(super) fn try_mark_green<'tcx>(tcx: TyCtxt<'tcx>, dep_node: &DepNode) -> bool {
12499
tcx.dep_graph.try_mark_green(tcx, dep_node).is_some()
125100
}
@@ -618,22 +593,6 @@ macro_rules! define_queries {
618593
}
619594
}
620595

621-
/// Internal per-query plumbing for collecting the set of active jobs for this query.
622-
///
623-
/// Should only be called through `PER_QUERY_GATHER_ACTIVE_JOBS_FNS`.
624-
pub(crate) fn gather_active_jobs<'tcx>(
625-
tcx: TyCtxt<'tcx>,
626-
require_complete: bool,
627-
job_map_out: &mut QueryJobMap<'tcx>,
628-
) -> Option<()> {
629-
crate::execution::gather_active_jobs_inner(
630-
&tcx.query_system.query_vtables.$name,
631-
tcx,
632-
require_complete,
633-
job_map_out,
634-
)
635-
}
636-
637596
pub(crate) fn alloc_self_profile_query_strings<'tcx>(
638597
tcx: TyCtxt<'tcx>,
639598
string_cache: &mut QueryKeyStringCache
@@ -672,21 +631,37 @@ macro_rules! define_queries {
672631

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

675-
/// Used by `collect_active_jobs_from_all_queries` to iterate over all
676-
/// queries, and gather the active jobs for each query.
634+
/// Returns a map of currently active query jobs, collected from all queries.
677635
///
678-
/// (We arbitrarily use the word "gather" when collecting the jobs for
679-
/// each individual query, so that we have distinct function names to
680-
/// grep for.)
681-
const PER_QUERY_GATHER_ACTIVE_JOBS_FNS: &[
682-
for<'tcx> fn(
683-
tcx: TyCtxt<'tcx>,
684-
require_complete: bool,
685-
job_map_out: &mut QueryJobMap<'tcx>,
686-
) -> Option<()>
687-
] = &[
688-
$( $crate::query_impl::$name::gather_active_jobs ),*
689-
];
636+
/// If `require_complete` is `true`, this function locks all shards of the
637+
/// query results to produce a complete map, which always returns `Ok`.
638+
/// Otherwise, it may return an incomplete map as an error if any shard
639+
/// lock cannot be acquired.
640+
///
641+
/// Prefer passing `false` to `require_complete` to avoid potential deadlocks,
642+
/// especially when called from within a deadlock handler, unless a
643+
/// complete map is needed and no deadlock is possible at this call site.
644+
pub fn collect_active_jobs_from_all_queries<'tcx>(
645+
tcx: TyCtxt<'tcx>,
646+
require_complete: bool,
647+
) -> Result<QueryJobMap<'tcx>, QueryJobMap<'tcx>> {
648+
let mut job_map_out = QueryJobMap::default();
649+
let mut complete = true;
650+
651+
$(
652+
let res = crate::execution::gather_active_jobs(
653+
&tcx.query_system.query_vtables.$name,
654+
tcx,
655+
require_complete,
656+
&mut job_map_out,
657+
);
658+
if res.is_none() {
659+
complete = false;
660+
}
661+
)*
662+
663+
if complete { Ok(job_map_out) } else { Err(job_map_out) }
664+
}
690665

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

0 commit comments

Comments
 (0)