Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions compiler/rustc_interface/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use rustc_data_structures::sync;
use rustc_metadata::{DylibError, EncodedMetadata, load_symbol_from_dylib};
use rustc_middle::dep_graph::{WorkProduct, WorkProductId};
use rustc_middle::ty::{CurrentGcx, TyCtxt};
use rustc_query_impl::{CollectActiveJobsKind, collect_active_jobs_from_all_queries};
use rustc_query_impl::{CollectActiveJobsKind, collect_active_query_jobs};
use rustc_session::config::{
Cfg, CrateType, OutFileName, OutputFilenames, OutputTypes, Sysroot, host_tuple,
};
Expand Down Expand Up @@ -255,7 +255,7 @@ internal compiler error: query cycle handler thread panicked, aborting process";
// Ensure there were no errors collecting all active jobs.
// We need the complete map to ensure we find a cycle to
// break.
collect_active_jobs_from_all_queries(
collect_active_query_jobs(
tcx,
CollectActiveJobsKind::FullNoContention,
)
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_middle/src/hooks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ declare_hooks! {
/// Trying to execute a query afterwards would attempt to read the result cache we just dropped.
hook save_dep_graph() -> ();

hook query_key_hash_verify_all() -> ();
hook verify_query_key_hashes() -> ();

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

hook encode_all_query_results(
hook encode_query_values(
encoder: &mut CacheEncoder<'_, 'tcx>,
query_result_index: &mut EncodedDepNodeIndex
) -> ();
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_middle/src/query/inner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ use rustc_span::{DUMMY_SP, ErrorGuaranteed, Span};
use crate::dep_graph;
use crate::dep_graph::DepNodeKey;
use crate::query::erase::{self, Erasable, Erased};
use crate::query::plumbing::QueryVTable;
use crate::query::{EnsureMode, QueryCache, QueryMode};
use crate::query::{EnsureMode, QueryCache, QueryMode, QueryVTable};
use crate::ty::TyCtxt;

/// Checks whether there is already a value for this key in the in-memory
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/query/job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::sync::Arc;
use parking_lot::{Condvar, Mutex};
use rustc_span::Span;

use crate::query::plumbing::CycleError;
use crate::query::CycleError;
use crate::ty::TyCtxt;

/// A value uniquely identifying an active query job.
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_middle/src/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ pub use self::caches::{DefIdCache, DefaultCache, QueryCache, SingleCache, VecCac
pub use self::job::{QueryJob, QueryJobId, QueryLatch, QueryWaiter};
pub use self::keys::{AsLocalQueryKey, LocalCrate, QueryKey};
pub use self::plumbing::{
ActiveKeyStatus, CycleError, EnsureMode, IntoQueryParam, QueryMode, QueryState, TyCtxtAt,
TyCtxtEnsureDone, TyCtxtEnsureOk, TyCtxtEnsureResult,
ActiveKeyStatus, CycleError, EnsureMode, IntoQueryParam, QueryMode, QueryState, QuerySystem,
QueryVTable, TyCtxtAt, TyCtxtEnsureDone, TyCtxtEnsureOk, TyCtxtEnsureResult,
};
pub use self::stack::QueryStackFrame;
pub use crate::queries::Providers;
Expand All @@ -19,7 +19,7 @@ mod job;
mod keys;
pub(crate) mod modifiers;
pub mod on_disk_cache;
pub mod plumbing;
pub(crate) mod plumbing;
mod stack;

pub fn describe_as_module(def_id: impl Into<LocalDefId>, tcx: TyCtxt<'_>) -> String {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_middle/src/query/on_disk_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,10 +246,10 @@ impl OnDiskCache {
// Encode query results.
let mut query_result_index = EncodedDepNodeIndex::new();

tcx.sess.time("encode_query_results", || {
tcx.sess.time("encode_query_values", || {
let enc = &mut encoder;
let qri = &mut query_result_index;
tcx.encode_all_query_results(enc, qri);
tcx.encode_query_values(enc, qri);
});

// Encode side effects.
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/query/plumbing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ macro_rules! define_callbacks {
/// Holds a `QueryVTable` for each query.
pub struct QueryVTables<'tcx> {
$(
pub $name: ::rustc_middle::query::plumbing::QueryVTable<'tcx, $name::Cache<'tcx>>,
pub $name: crate::query::QueryVTable<'tcx, $name::Cache<'tcx>>,
)*
}

Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_middle/src/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ use crate::middle::codegen_fn_attrs::{CodegenFnAttrs, TargetFeature};
use crate::middle::resolve_bound_vars;
use crate::mir::interpret::{self, Allocation, ConstAllocation};
use crate::mir::{Body, Local, Place, PlaceElem, ProjectionKind, Promoted};
use crate::query::plumbing::QuerySystem;
use crate::query::{IntoQueryParam, LocalCrate, Providers, TyCtxtAt};
use crate::query::{IntoQueryParam, LocalCrate, Providers, QuerySystem, TyCtxtAt};
use crate::thir::Thir;
use crate::traits;
use crate::traits::solve::{ExternalConstraints, ExternalConstraintsData, PredefinedOpaques};
Expand Down Expand Up @@ -1678,7 +1677,7 @@ impl<'tcx> TyCtxt<'tcx> {
self.alloc_self_profile_query_strings();

self.save_dep_graph();
self.query_key_hash_verify_all();
self.verify_query_key_hashes();

if let Err((path, error)) = self.dep_graph.finish_encoding() {
self.sess.dcx().emit_fatal(crate::error::FailedWritingFile { path: &path, error });
Expand Down
35 changes: 9 additions & 26 deletions compiler/rustc_query_impl/src/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ use rustc_data_structures::sync::{DynSend, DynSync};
use rustc_data_structures::{outline, sharded, sync};
use rustc_errors::FatalError;
use rustc_middle::dep_graph::{DepGraphData, DepNodeKey, SerializedDepNodeIndex};
use rustc_middle::query::plumbing::QueryVTable;
use rustc_middle::query::{
ActiveKeyStatus, CycleError, EnsureMode, QueryCache, QueryJob, QueryJobId, QueryKey,
QueryLatch, QueryMode, QueryState,
QueryLatch, QueryMode, QueryState, QueryVTable,
};
use rustc_middle::ty::TyCtxt;
use rustc_middle::verify_ich::incremental_verify_ich;
Expand Down Expand Up @@ -47,46 +46,31 @@ pub enum CollectActiveJobsKind {
}

/// 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>(
pub fn collect_active_query_jobs<'tcx>(
tcx: TyCtxt<'tcx>,
collect_kind: CollectActiveJobsKind,
) -> QueryJobMap<'tcx> {
let mut job_map = QueryJobMap::default();

for_each_query_vtable!(ALL, tcx, |query| {
gather_active_jobs(query, collect_kind, &mut job_map);
collect_active_query_jobs_inner(query, collect_kind, &mut job_map);
});

job_map
}

/// Internal plumbing for collecting the set of active jobs for this query.
///
/// 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.)
///
/// Aborts if jobs can't be gathered as specified by `collect_kind`.
fn gather_active_jobs<'tcx, C>(
fn collect_active_query_jobs_inner<'tcx, C>(
query: &'tcx QueryVTable<'tcx, C>,
collect_kind: CollectActiveJobsKind,
job_map: &mut QueryJobMap<'tcx>,
) where
C: QueryCache<Key: QueryKey + DynSend + DynSync>,
QueryVTable<'tcx, C>: DynSync,
{
let mut gather_shard_jobs = |shard: &HashTable<(C::Key, ActiveKeyStatus<'tcx>)>| {
let mut collect_shard_jobs = |shard: &HashTable<(C::Key, ActiveKeyStatus<'tcx>)>| {
for (key, status) in shard.iter() {
if let ActiveKeyStatus::Started(job) = status {
// This function is safe to call with the shard locked because it is very simple.
Expand All @@ -99,21 +83,21 @@ fn gather_active_jobs<'tcx, C>(
match collect_kind {
CollectActiveJobsKind::Full => {
for shard in query.state.active.lock_shards() {
gather_shard_jobs(&shard);
collect_shard_jobs(&shard);
}
}
CollectActiveJobsKind::FullNoContention => {
for shard in query.state.active.try_lock_shards() {
match shard {
Some(shard) => gather_shard_jobs(&shard),
Some(shard) => collect_shard_jobs(&shard),
None => panic!("Failed to collect active jobs for query `{}`!", query.name),
}
}
}
CollectActiveJobsKind::PartialAllowed => {
for shard in query.state.active.try_lock_shards() {
match shard {
Some(shard) => gather_shard_jobs(&shard),
Some(shard) => collect_shard_jobs(&shard),
None => warn!("Failed to collect active jobs for query `{}`!", query.name),
}
}
Expand Down Expand Up @@ -218,8 +202,7 @@ fn cycle_error<'tcx, C: QueryCache>(
) -> (C::Value, Option<DepNodeIndex>) {
// Ensure there were no errors collecting all active jobs.
// We need the complete map to ensure we find a cycle to break.
let job_map =
collect_active_jobs_from_all_queries(tcx, CollectActiveJobsKind::FullNoContention);
let job_map = collect_active_query_jobs(tcx, CollectActiveJobsKind::FullNoContention);

let error = find_cycle_in_stack(try_execute, job_map, &current_query_job(), span);
(mk_cycle(query, tcx, key, error), None)
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_query_impl/src/job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ use rustc_middle::query::{
use rustc_middle::ty::TyCtxt;
use rustc_span::{DUMMY_SP, Span, respan};

use crate::{CollectActiveJobsKind, collect_active_jobs_from_all_queries};
use crate::{CollectActiveJobsKind, collect_active_query_jobs};

/// Map from query job IDs to job information collected by
/// `collect_active_jobs_from_all_queries`.
/// `collect_active_query_jobs`.
#[derive(Debug, Default)]
pub struct QueryJobMap<'tcx> {
map: FxHashMap<QueryJobId, QueryJobInfo<'tcx>>,
Expand All @@ -24,7 +24,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`.
/// Should only be called by `collect_active_query_jobs_inner`.
pub(crate) fn insert(&mut self, id: QueryJobId, info: QueryJobInfo<'tcx>) {
self.map.insert(id, info);
}
Expand Down Expand Up @@ -407,7 +407,7 @@ pub fn print_query_stack<'tcx>(
let mut count_total = 0;

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

if let Some(ref mut file) = file {
let _ = writeln!(file, "\n\nquery stack during panic:");
Expand Down
9 changes: 4 additions & 5 deletions compiler/rustc_query_impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@
use rustc_data_structures::sync::AtomicU64;
use rustc_middle::dep_graph;
use rustc_middle::queries::{ExternProviders, Providers};
use rustc_middle::query::QueryCache;
use rustc_middle::query::on_disk_cache::OnDiskCache;
use rustc_middle::query::plumbing::{QuerySystem, QueryVTable};
use rustc_middle::query::{QueryCache, QuerySystem, QueryVTable};
use rustc_middle::ty::TyCtxt;

pub use crate::dep_kind_vtables::make_dep_kind_vtables;
pub use crate::execution::{CollectActiveJobsKind, collect_active_jobs_from_all_queries};
pub use crate::execution::{CollectActiveJobsKind, collect_active_query_jobs};
pub use crate::job::{QueryJobMap, break_query_cycles, print_query_stack};

mod dep_kind_vtables;
Expand Down Expand Up @@ -64,6 +63,6 @@ pub fn query_system<'tcx>(
pub fn provide(providers: &mut rustc_middle::util::Providers) {
providers.hooks.alloc_self_profile_query_strings =
profiling_support::alloc_self_profile_query_strings;
providers.hooks.query_key_hash_verify_all = plumbing::query_key_hash_verify_all;
providers.hooks.encode_all_query_results = plumbing::encode_all_query_results;
providers.hooks.verify_query_key_hashes = plumbing::verify_query_key_hashes;
providers.hooks.encode_query_values = plumbing::encode_query_values;
}
23 changes: 12 additions & 11 deletions compiler/rustc_query_impl/src/plumbing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ use rustc_middle::query::erase::{Erasable, Erased};
use rustc_middle::query::on_disk_cache::{
AbsoluteBytePos, CacheDecoder, CacheEncoder, EncodedDepNodeIndex,
};
use rustc_middle::query::plumbing::QueryVTable;
use rustc_middle::query::{QueryCache, QueryJobId, QueryKey, QueryMode, QueryStackFrame, erase};
use rustc_middle::query::{
QueryCache, QueryJobId, QueryKey, QueryMode, QueryStackFrame, QueryVTable, erase,
};
use rustc_middle::ty::TyCtxt;
use rustc_middle::ty::codec::TyEncoder;
use rustc_middle::ty::tls::{self, ImplicitCtxt};
Expand All @@ -26,10 +27,10 @@ use crate::error::{QueryOverflow, QueryOverflowNote};
use crate::execution::{all_inactive, force_query};
use crate::job::find_dep_kind_root;
use crate::query_impl::for_each_query_vtable;
use crate::{CollectActiveJobsKind, GetQueryVTable, collect_active_jobs_from_all_queries};
use crate::{CollectActiveJobsKind, GetQueryVTable, collect_active_query_jobs};

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

let suggested_limit = match tcx.recursion_limit() {
Expand Down Expand Up @@ -99,17 +100,17 @@ where
}
}

pub(crate) fn encode_all_query_results<'tcx>(
pub(crate) fn encode_query_values<'tcx>(
tcx: TyCtxt<'tcx>,
encoder: &mut CacheEncoder<'_, 'tcx>,
query_result_index: &mut EncodedDepNodeIndex,
) {
for_each_query_vtable!(CACHE_ON_DISK, tcx, |query| {
encode_query_results(tcx, query, encoder, query_result_index)
encode_query_values_inner(tcx, query, encoder, query_result_index)
});
}

fn encode_query_results<'a, 'tcx, C, V>(
fn encode_query_values_inner<'a, 'tcx, C, V>(
tcx: TyCtxt<'tcx>,
query: &'tcx QueryVTable<'tcx, C>,
encoder: &mut CacheEncoder<'a, 'tcx>,
Expand All @@ -135,17 +136,17 @@ fn encode_query_results<'a, 'tcx, C, V>(
});
}

pub(crate) fn query_key_hash_verify_all<'tcx>(tcx: TyCtxt<'tcx>) {
pub(crate) fn verify_query_key_hashes<'tcx>(tcx: TyCtxt<'tcx>) {
if tcx.sess.opts.unstable_opts.incremental_verify_ich || cfg!(debug_assertions) {
tcx.sess.time("query_key_hash_verify_all", || {
tcx.sess.time("verify_query_key_hashes", || {
for_each_query_vtable!(ALL, tcx, |query| {
query_key_hash_verify(query, tcx);
verify_query_key_hashes_inner(query, tcx);
});
});
}
}

fn query_key_hash_verify<'tcx, C: QueryCache>(
fn verify_query_key_hashes_inner<'tcx, C: QueryCache>(
query: &'tcx QueryVTable<'tcx, C>,
tcx: TyCtxt<'tcx>,
) {
Expand Down
7 changes: 3 additions & 4 deletions compiler/rustc_query_impl/src/profiling_support.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::profiling::SelfProfiler;
use rustc_hir::def_id::{CrateNum, DefId, DefIndex, LOCAL_CRATE, LocalDefId};
use rustc_hir::definitions::DefPathData;
use rustc_middle::query::QueryCache;
use rustc_middle::query::plumbing::QueryVTable;
use rustc_middle::query::{QueryCache, QueryVTable};
use rustc_middle::ty::TyCtxt;

use crate::query_impl::for_each_query_vtable;
Expand Down Expand Up @@ -192,7 +191,7 @@ pub(crate) fn alloc_self_profile_query_strings(tcx: TyCtxt<'_>) {
let mut string_cache = QueryKeyStringCache::new();

for_each_query_vtable!(ALL, tcx, |query| {
alloc_self_profile_query_strings_for_query_cache(tcx, query, &mut string_cache);
alloc_self_profile_query_strings_inner(tcx, query, &mut string_cache);
});

tcx.sess.prof.store_query_cache_hits();
Expand All @@ -201,7 +200,7 @@ pub(crate) fn alloc_self_profile_query_strings(tcx: TyCtxt<'_>) {
/// Allocate the self-profiling query strings for a single query cache. This
/// method is called from `alloc_self_profile_query_strings` which knows all
/// the queries via macro magic.
fn alloc_self_profile_query_strings_for_query_cache<'tcx, C>(
fn alloc_self_profile_query_strings_inner<'tcx, C>(
tcx: TyCtxt<'tcx>,
query: &'tcx QueryVTable<'tcx, C>,
string_cache: &mut QueryKeyStringCache,
Expand Down
7 changes: 3 additions & 4 deletions compiler/rustc_query_impl/src/query_impl.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use rustc_middle::queries::TaggedQueryKey;
use rustc_middle::query::erase::{self, Erased};
use rustc_middle::query::plumbing::QueryVTable;
use rustc_middle::query::{AsLocalQueryKey, QueryMode};
use rustc_middle::query::{AsLocalQueryKey, QueryMode, QueryVTable};
use rustc_middle::ty::TyCtxt;
use rustc_span::Span;

Expand Down Expand Up @@ -245,7 +244,7 @@ macro_rules! define_queries {
(ALL, $tcx:expr, $closure:expr) => {{
let tcx: rustc_middle::ty::TyCtxt<'_> = $tcx;
$(
let query: &rustc_middle::query::plumbing::QueryVTable<'_, _> =
let query: &rustc_middle::query::QueryVTable<'_, _> =
&tcx.query_system.query_vtables.$name;
$closure(query);
)*
Expand All @@ -260,7 +259,7 @@ macro_rules! define_queries {
$(
#[cfg($cache_on_disk)]
{
let query: &rustc_middle::query::plumbing::QueryVTable<'_, _> =
let query: &rustc_middle::query::QueryVTable<'_, _> =
&tcx.query_system.query_vtables.$name;
$closure(query);
}
Expand Down
Loading