mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
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.
This commit is contained in:
@@ -16,11 +16,10 @@
|
||||
use rustc_middle::verify_ich::incremental_verify_ich;
|
||||
use rustc_span::{DUMMY_SP, Span};
|
||||
|
||||
use crate::collect_active_jobs_from_all_queries;
|
||||
use crate::dep_graph::{DepNode, DepNodeIndex};
|
||||
use crate::job::{QueryJobInfo, QueryJobMap, find_cycle_in_stack, report_cycle};
|
||||
use crate::plumbing::{
|
||||
collect_active_jobs_from_all_queries, current_query_job, next_job_id, start_query,
|
||||
};
|
||||
use crate::plumbing::{current_query_job, next_job_id, start_query};
|
||||
|
||||
#[inline]
|
||||
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 {
|
||||
|
||||
/// Internal plumbing for collecting the set of active jobs for this query.
|
||||
///
|
||||
/// Should only be called from `gather_active_jobs`.
|
||||
pub(crate) fn gather_active_jobs_inner<'tcx, C>(
|
||||
/// Should only be called from `collect_active_jobs_from_all_queries`.
|
||||
///
|
||||
/// (We arbitrarily use the word "gather" when collecting the jobs for
|
||||
/// each individual query, so that we have distinct function names to
|
||||
/// grep for.)
|
||||
pub(crate) fn gather_active_jobs<'tcx, C>(
|
||||
query: &'tcx QueryVTable<'tcx, C>,
|
||||
tcx: TyCtxt<'tcx>,
|
||||
require_complete: bool,
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
use rustc_session::Session;
|
||||
use rustc_span::{DUMMY_SP, Span};
|
||||
|
||||
use crate::plumbing::collect_active_jobs_from_all_queries;
|
||||
use crate::collect_active_jobs_from_all_queries;
|
||||
|
||||
/// Map from query job IDs to job information collected by
|
||||
/// `collect_active_jobs_from_all_queries`.
|
||||
@@ -26,7 +26,7 @@ pub struct QueryJobMap<'tcx> {
|
||||
impl<'tcx> QueryJobMap<'tcx> {
|
||||
/// Adds information about a job ID to the job map.
|
||||
///
|
||||
/// Should only be called by `gather_active_jobs_inner`.
|
||||
/// Should only be called by `gather_active_jobs`.
|
||||
pub(crate) fn insert(&mut self, id: QueryJobId, info: QueryJobInfo<'tcx>) {
|
||||
self.map.insert(id, info);
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
|
||||
pub use crate::dep_kind_vtables::make_dep_kind_vtables;
|
||||
pub use crate::job::{QueryJobMap, break_query_cycles, print_query_stack};
|
||||
pub use crate::plumbing::collect_active_jobs_from_all_queries;
|
||||
use crate::plumbing::{encode_all_query_results, try_mark_green};
|
||||
use crate::profiling_support::QueryKeyStringCache;
|
||||
pub use crate::profiling_support::alloc_self_profile_query_strings;
|
||||
|
||||
@@ -29,9 +29,10 @@
|
||||
use rustc_serialize::{Decodable, Encodable};
|
||||
use rustc_span::def_id::LOCAL_CRATE;
|
||||
|
||||
use crate::collect_active_jobs_from_all_queries;
|
||||
use crate::error::{QueryOverflow, QueryOverflowNote};
|
||||
use crate::execution::{all_inactive, force_query};
|
||||
use crate::job::{QueryJobMap, find_dep_kind_root};
|
||||
use crate::job::find_dep_kind_root;
|
||||
|
||||
fn depth_limit_error<'tcx>(tcx: TyCtxt<'tcx>, job: QueryJobId) {
|
||||
let job_map =
|
||||
@@ -94,32 +95,6 @@ pub(crate) fn start_query<'tcx, R>(
|
||||
})
|
||||
}
|
||||
|
||||
/// Returns a map of currently active query jobs, collected from all queries.
|
||||
///
|
||||
/// If `require_complete` is `true`, this function locks all shards of the
|
||||
/// query results to produce a complete map, which always returns `Ok`.
|
||||
/// Otherwise, it may return an incomplete map as an error if any shard
|
||||
/// lock cannot be acquired.
|
||||
///
|
||||
/// Prefer passing `false` to `require_complete` to avoid potential deadlocks,
|
||||
/// especially when called from within a deadlock handler, unless a
|
||||
/// complete map is needed and no deadlock is possible at this call site.
|
||||
pub fn collect_active_jobs_from_all_queries<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
require_complete: bool,
|
||||
) -> Result<QueryJobMap<'tcx>, QueryJobMap<'tcx>> {
|
||||
let mut job_map_out = QueryJobMap::default();
|
||||
let mut complete = true;
|
||||
|
||||
for gather_fn in crate::PER_QUERY_GATHER_ACTIVE_JOBS_FNS.iter() {
|
||||
if gather_fn(tcx, require_complete, &mut job_map_out).is_none() {
|
||||
complete = false;
|
||||
}
|
||||
}
|
||||
|
||||
if complete { Ok(job_map_out) } else { Err(job_map_out) }
|
||||
}
|
||||
|
||||
pub(super) fn try_mark_green<'tcx>(tcx: TyCtxt<'tcx>, dep_node: &DepNode) -> bool {
|
||||
tcx.dep_graph.try_mark_green(tcx, dep_node).is_some()
|
||||
}
|
||||
@@ -618,22 +593,6 @@ fn query_vtable(tcx: TyCtxt<'tcx>) -> &'tcx QueryVTable<'tcx, Self::Cache> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Internal per-query plumbing for collecting the set of active jobs for this query.
|
||||
///
|
||||
/// Should only be called through `PER_QUERY_GATHER_ACTIVE_JOBS_FNS`.
|
||||
pub(crate) fn gather_active_jobs<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
require_complete: bool,
|
||||
job_map_out: &mut QueryJobMap<'tcx>,
|
||||
) -> Option<()> {
|
||||
crate::execution::gather_active_jobs_inner(
|
||||
&tcx.query_system.query_vtables.$name,
|
||||
tcx,
|
||||
require_complete,
|
||||
job_map_out,
|
||||
)
|
||||
}
|
||||
|
||||
pub(crate) fn alloc_self_profile_query_strings<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
string_cache: &mut QueryKeyStringCache
|
||||
@@ -672,21 +631,37 @@ pub fn make_query_vtables<'tcx>(incremental: bool) -> queries::QueryVTables<'tcx
|
||||
|
||||
// These arrays are used for iteration and can't be indexed by `DepKind`.
|
||||
|
||||
/// Used by `collect_active_jobs_from_all_queries` to iterate over all
|
||||
/// queries, and gather the active jobs for each query.
|
||||
/// Returns a map of currently active query jobs, collected from all queries.
|
||||
///
|
||||
/// (We arbitrarily use the word "gather" when collecting the jobs for
|
||||
/// each individual query, so that we have distinct function names to
|
||||
/// grep for.)
|
||||
const PER_QUERY_GATHER_ACTIVE_JOBS_FNS: &[
|
||||
for<'tcx> fn(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
require_complete: bool,
|
||||
job_map_out: &mut QueryJobMap<'tcx>,
|
||||
) -> Option<()>
|
||||
] = &[
|
||||
$( $crate::query_impl::$name::gather_active_jobs ),*
|
||||
];
|
||||
/// If `require_complete` is `true`, this function locks all shards of the
|
||||
/// query results to produce a complete map, which always returns `Ok`.
|
||||
/// Otherwise, it may return an incomplete map as an error if any shard
|
||||
/// lock cannot be acquired.
|
||||
///
|
||||
/// Prefer passing `false` to `require_complete` to avoid potential deadlocks,
|
||||
/// especially when called from within a deadlock handler, unless a
|
||||
/// complete map is needed and no deadlock is possible at this call site.
|
||||
pub fn collect_active_jobs_from_all_queries<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
require_complete: bool,
|
||||
) -> Result<QueryJobMap<'tcx>, QueryJobMap<'tcx>> {
|
||||
let mut job_map_out = QueryJobMap::default();
|
||||
let mut complete = true;
|
||||
|
||||
$(
|
||||
let res = crate::execution::gather_active_jobs(
|
||||
&tcx.query_system.query_vtables.$name,
|
||||
tcx,
|
||||
require_complete,
|
||||
&mut job_map_out,
|
||||
);
|
||||
if res.is_none() {
|
||||
complete = false;
|
||||
}
|
||||
)*
|
||||
|
||||
if complete { Ok(job_map_out) } else { Err(job_map_out) }
|
||||
}
|
||||
|
||||
const ALLOC_SELF_PROFILE_QUERY_STRINGS: &[
|
||||
for<'tcx> fn(TyCtxt<'tcx>, &mut QueryKeyStringCache)
|
||||
|
||||
Reference in New Issue
Block a user