2020-03-19 14:24:21 +01:00
|
|
|
//! The implementation of the query system itself. This defines the macros that
|
|
|
|
//! generate the actual methods on tcx which find and execute the provider,
|
|
|
|
//! manage the caches, and so forth.
|
|
|
|
|
|
|
|
use crate::dep_graph::DepGraph;
|
|
|
|
use crate::ty::query::Query;
|
|
|
|
use crate::ty::tls::{self, ImplicitCtxt};
|
|
|
|
use crate::ty::{self, TyCtxt};
|
|
|
|
use rustc_query_system::query::QueryContext;
|
|
|
|
use rustc_query_system::query::{CycleError, QueryJobId, QueryJobInfo};
|
|
|
|
|
|
|
|
use rustc_data_structures::fx::FxHashMap;
|
|
|
|
use rustc_data_structures::sync::Lock;
|
|
|
|
use rustc_data_structures::thin_vec::ThinVec;
|
|
|
|
use rustc_errors::{struct_span_err, Diagnostic, DiagnosticBuilder, Handler, Level};
|
|
|
|
use rustc_span::def_id::DefId;
|
|
|
|
use rustc_span::Span;
|
|
|
|
|
|
|
|
impl QueryContext for TyCtxt<'tcx> {
|
|
|
|
type Query = Query<'tcx>;
|
|
|
|
|
2020-03-25 08:02:27 +01:00
|
|
|
fn incremental_verify_ich(&self) -> bool {
|
|
|
|
self.sess.opts.debugging_opts.incremental_verify_ich
|
|
|
|
}
|
|
|
|
fn verbose(&self) -> bool {
|
|
|
|
self.sess.verbose()
|
2020-03-19 14:24:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
fn def_path_str(&self, def_id: DefId) -> String {
|
|
|
|
TyCtxt::def_path_str(*self, def_id)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn dep_graph(&self) -> &DepGraph {
|
|
|
|
&self.dep_graph
|
|
|
|
}
|
|
|
|
|
2020-03-25 07:52:12 +01:00
|
|
|
fn current_query_job(&self) -> Option<QueryJobId<Self::DepKind>> {
|
|
|
|
tls::with_related_context(*self, |icx| icx.query)
|
2020-03-19 14:24:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
fn try_collect_active_jobs(
|
|
|
|
&self,
|
|
|
|
) -> Option<FxHashMap<QueryJobId<Self::DepKind>, QueryJobInfo<Self>>> {
|
|
|
|
self.queries.try_collect_active_jobs()
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Executes a job by changing the `ImplicitCtxt` to point to the
|
|
|
|
/// new query job while it executes. It returns the diagnostics
|
|
|
|
/// captured during execution and the actual result.
|
|
|
|
#[inline(always)]
|
|
|
|
fn start_query<R>(
|
|
|
|
&self,
|
|
|
|
token: QueryJobId<Self::DepKind>,
|
|
|
|
diagnostics: Option<&Lock<ThinVec<Diagnostic>>>,
|
|
|
|
compute: impl FnOnce(Self) -> R,
|
|
|
|
) -> R {
|
|
|
|
// The `TyCtxt` stored in TLS has the same global interner lifetime
|
|
|
|
// as `self`, so we use `with_related_context` to relate the 'tcx lifetimes
|
|
|
|
// when accessing the `ImplicitCtxt`.
|
|
|
|
tls::with_related_context(*self, move |current_icx| {
|
|
|
|
// Update the `ImplicitCtxt` to point to our new query job.
|
|
|
|
let new_icx = ImplicitCtxt {
|
|
|
|
tcx: *self,
|
|
|
|
query: Some(token),
|
|
|
|
diagnostics,
|
|
|
|
layout_depth: current_icx.layout_depth,
|
|
|
|
task_deps: current_icx.task_deps,
|
|
|
|
};
|
|
|
|
|
|
|
|
// Use the `ImplicitCtxt` while we execute the query.
|
|
|
|
tls::enter_context(&new_icx, |_| compute(*self))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'tcx> TyCtxt<'tcx> {
|
|
|
|
#[inline(never)]
|
|
|
|
#[cold]
|
|
|
|
pub(super) fn report_cycle(
|
|
|
|
self,
|
|
|
|
CycleError { usage, cycle: stack }: CycleError<Query<'tcx>>,
|
|
|
|
) -> DiagnosticBuilder<'tcx> {
|
|
|
|
assert!(!stack.is_empty());
|
|
|
|
|
|
|
|
let fix_span = |span: Span, query: &Query<'tcx>| {
|
|
|
|
self.sess.source_map().guess_head_span(query.default_span(self, span))
|
|
|
|
};
|
|
|
|
|
|
|
|
// Disable naming impls with types in this path, since that
|
|
|
|
// sometimes cycles itself, leading to extra cycle errors.
|
|
|
|
// (And cycle errors around impls tend to occur during the
|
|
|
|
// collect/coherence phases anyhow.)
|
|
|
|
ty::print::with_forced_impl_filename_line(|| {
|
|
|
|
let span = fix_span(stack[1 % stack.len()].span, &stack[0].query);
|
|
|
|
let mut err = struct_span_err!(
|
|
|
|
self.sess,
|
|
|
|
span,
|
|
|
|
E0391,
|
|
|
|
"cycle detected when {}",
|
|
|
|
stack[0].query.describe(self)
|
|
|
|
);
|
|
|
|
|
|
|
|
for i in 1..stack.len() {
|
|
|
|
let query = &stack[i].query;
|
|
|
|
let span = fix_span(stack[(i + 1) % stack.len()].span, query);
|
|
|
|
err.span_note(span, &format!("...which requires {}...", query.describe(self)));
|
|
|
|
}
|
|
|
|
|
|
|
|
err.note(&format!(
|
|
|
|
"...which again requires {}, completing the cycle",
|
|
|
|
stack[0].query.describe(self)
|
|
|
|
));
|
|
|
|
|
|
|
|
if let Some((span, query)) = usage {
|
|
|
|
err.span_note(
|
|
|
|
fix_span(span, &query),
|
|
|
|
&format!("cycle used when {}", query.describe(self)),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
err
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn try_print_query_stack(handler: &Handler) {
|
|
|
|
eprintln!("query stack during panic:");
|
|
|
|
|
|
|
|
// Be careful reyling on global state here: this code is called from
|
|
|
|
// a panic hook, which means that the global `Handler` may be in a weird
|
|
|
|
// state if it was responsible for triggering the panic.
|
|
|
|
ty::tls::with_context_opt(|icx| {
|
|
|
|
if let Some(icx) = icx {
|
|
|
|
let query_map = icx.tcx.queries.try_collect_active_jobs();
|
|
|
|
|
|
|
|
let mut current_query = icx.query;
|
|
|
|
let mut i = 0;
|
|
|
|
|
|
|
|
while let Some(query) = current_query {
|
|
|
|
let query_info =
|
|
|
|
if let Some(info) = query_map.as_ref().and_then(|map| map.get(&query)) {
|
|
|
|
info
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
};
|
|
|
|
let mut diag = Diagnostic::new(
|
|
|
|
Level::FailureNote,
|
|
|
|
&format!(
|
|
|
|
"#{} [{}] {}",
|
|
|
|
i,
|
|
|
|
query_info.info.query.name(),
|
|
|
|
query_info.info.query.describe(icx.tcx)
|
|
|
|
),
|
|
|
|
);
|
2020-03-26 09:40:50 +01:00
|
|
|
diag.span =
|
|
|
|
icx.tcx.sess.source_map().guess_head_span(query_info.info.span).into();
|
2020-03-19 14:24:21 +01:00
|
|
|
handler.force_print_diagnostic(diag);
|
|
|
|
|
|
|
|
current_query = query_info.job.parent;
|
|
|
|
i += 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
eprintln!("end of query stack");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
macro_rules! handle_cycle_error {
|
|
|
|
([][$tcx: expr, $error:expr]) => {{
|
|
|
|
$tcx.report_cycle($error).emit();
|
|
|
|
Value::from_cycle_error($tcx)
|
|
|
|
}};
|
|
|
|
([fatal_cycle $($rest:tt)*][$tcx:expr, $error:expr]) => {{
|
|
|
|
$tcx.report_cycle($error).emit();
|
|
|
|
$tcx.sess.abort_if_errors();
|
|
|
|
unreachable!()
|
|
|
|
}};
|
|
|
|
([cycle_delay_bug $($rest:tt)*][$tcx:expr, $error:expr]) => {{
|
|
|
|
$tcx.report_cycle($error).delay_as_bug();
|
|
|
|
Value::from_cycle_error($tcx)
|
|
|
|
}};
|
|
|
|
([$other:ident $(($($other_args:tt)*))* $(, $($modifiers:tt)*)*][$($args:tt)*]) => {
|
|
|
|
handle_cycle_error!([$($($modifiers)*)*][$($args)*])
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
macro_rules! is_anon {
|
|
|
|
([]) => {{
|
|
|
|
false
|
|
|
|
}};
|
|
|
|
([anon $($rest:tt)*]) => {{
|
|
|
|
true
|
|
|
|
}};
|
|
|
|
([$other:ident $(($($other_args:tt)*))* $(, $($modifiers:tt)*)*]) => {
|
|
|
|
is_anon!([$($($modifiers)*)*])
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
macro_rules! is_eval_always {
|
|
|
|
([]) => {{
|
|
|
|
false
|
|
|
|
}};
|
|
|
|
([eval_always $($rest:tt)*]) => {{
|
|
|
|
true
|
|
|
|
}};
|
|
|
|
([$other:ident $(($($other_args:tt)*))* $(, $($modifiers:tt)*)*]) => {
|
|
|
|
is_eval_always!([$($($modifiers)*)*])
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
macro_rules! query_storage {
|
2020-03-27 07:50:28 +01:00
|
|
|
([][$K:ty, $V:ty]) => {
|
2020-03-24 23:46:47 +01:00
|
|
|
<<$K as Key>::CacheSelector as CacheSelector<$K, $V>>::Cache
|
2020-03-19 14:24:21 +01:00
|
|
|
};
|
2020-03-27 07:50:28 +01:00
|
|
|
([storage($ty:ty) $($rest:tt)*][$K:ty, $V:ty]) => {
|
2020-03-27 18:46:25 +01:00
|
|
|
<$ty as CacheSelector<$K, $V>>::Cache
|
2020-03-19 14:24:21 +01:00
|
|
|
};
|
2020-03-27 07:50:28 +01:00
|
|
|
([$other:ident $(($($other_args:tt)*))* $(, $($modifiers:tt)*)*][$($args:tt)*]) => {
|
|
|
|
query_storage!([$($($modifiers)*)*][$($args)*])
|
2020-03-19 14:24:21 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
macro_rules! hash_result {
|
|
|
|
([][$hcx:expr, $result:expr]) => {{
|
|
|
|
dep_graph::hash_result($hcx, &$result)
|
|
|
|
}};
|
|
|
|
([no_hash $($rest:tt)*][$hcx:expr, $result:expr]) => {{
|
|
|
|
None
|
|
|
|
}};
|
|
|
|
([$other:ident $(($($other_args:tt)*))* $(, $($modifiers:tt)*)*][$($args:tt)*]) => {
|
|
|
|
hash_result!([$($($modifiers)*)*][$($args)*])
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
macro_rules! define_queries {
|
|
|
|
(<$tcx:tt> $($category:tt {
|
2020-04-09 10:29:08 -07:00
|
|
|
$($(#[$attr:meta])* [$($modifiers:tt)*] fn $name:ident: $node:ident($($K:tt)*) -> $V:ty,)*
|
2020-03-19 14:24:21 +01:00
|
|
|
},)*) => {
|
|
|
|
define_queries_inner! { <$tcx>
|
2020-04-09 10:29:08 -07:00
|
|
|
$($( $(#[$attr])* category<$category> [$($modifiers)*] fn $name: $node($($K)*) -> $V,)*)*
|
2020-03-19 14:24:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-10 13:44:15 -07:00
|
|
|
macro_rules! query_helper_param_ty {
|
2020-04-10 13:54:06 -07:00
|
|
|
(DefId) => { impl IntoQueryParam<DefId> };
|
2020-04-10 13:44:15 -07:00
|
|
|
($K:ty) => { $K };
|
2020-04-09 10:29:08 -07:00
|
|
|
}
|
|
|
|
|
2020-03-19 14:24:21 +01:00
|
|
|
macro_rules! define_queries_inner {
|
|
|
|
(<$tcx:tt>
|
|
|
|
$($(#[$attr:meta])* category<$category:tt>
|
2020-04-09 10:29:08 -07:00
|
|
|
[$($modifiers:tt)*] fn $name:ident: $node:ident($($K:tt)*) -> $V:ty,)*) => {
|
2020-03-19 14:24:21 +01:00
|
|
|
|
|
|
|
use std::mem;
|
|
|
|
use crate::{
|
|
|
|
rustc_data_structures::stable_hasher::HashStable,
|
|
|
|
rustc_data_structures::stable_hasher::StableHasher,
|
|
|
|
ich::StableHashingContext
|
|
|
|
};
|
|
|
|
use rustc_data_structures::profiling::ProfileCategory;
|
|
|
|
|
|
|
|
define_queries_struct! {
|
|
|
|
tcx: $tcx,
|
|
|
|
input: ($(([$($modifiers)*] [$($attr)*] [$name]))*)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[allow(nonstandard_style)]
|
|
|
|
#[derive(Clone, Debug)]
|
|
|
|
pub enum Query<$tcx> {
|
2020-04-09 10:29:08 -07:00
|
|
|
$($(#[$attr])* $name($($K)*)),*
|
2020-03-19 14:24:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<$tcx> Query<$tcx> {
|
|
|
|
pub fn name(&self) -> &'static str {
|
|
|
|
match *self {
|
|
|
|
$(Query::$name(_) => stringify!($name),)*
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn describe(&self, tcx: TyCtxt<$tcx>) -> Cow<'static, str> {
|
|
|
|
let (r, name) = match *self {
|
|
|
|
$(Query::$name(key) => {
|
|
|
|
(queries::$name::describe(tcx, key), stringify!($name))
|
|
|
|
})*
|
|
|
|
};
|
|
|
|
if tcx.sess.verbose() {
|
|
|
|
format!("{} [{}]", r, name).into()
|
|
|
|
} else {
|
|
|
|
r
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME(eddyb) Get more valid `Span`s on queries.
|
|
|
|
pub fn default_span(&self, tcx: TyCtxt<$tcx>, span: Span) -> Span {
|
|
|
|
if !span.is_dummy() {
|
|
|
|
return span;
|
|
|
|
}
|
|
|
|
// The `def_span` query is used to calculate `default_span`,
|
|
|
|
// so exit to avoid infinite recursion.
|
|
|
|
if let Query::def_span(..) = *self {
|
|
|
|
return span
|
|
|
|
}
|
|
|
|
match *self {
|
|
|
|
$(Query::$name(key) => key.default_span(tcx),)*
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a, $tcx> HashStable<StableHashingContext<'a>> for Query<$tcx> {
|
|
|
|
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
|
|
|
|
mem::discriminant(self).hash_stable(hcx, hasher);
|
|
|
|
match *self {
|
|
|
|
$(Query::$name(key) => key.hash_stable(hcx, hasher),)*
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub mod queries {
|
|
|
|
use std::marker::PhantomData;
|
|
|
|
|
|
|
|
$(#[allow(nonstandard_style)]
|
|
|
|
pub struct $name<$tcx> {
|
|
|
|
data: PhantomData<&$tcx ()>
|
|
|
|
})*
|
|
|
|
}
|
|
|
|
|
|
|
|
$(impl<$tcx> QueryConfig<TyCtxt<$tcx>> for queries::$name<$tcx> {
|
2020-04-09 10:29:08 -07:00
|
|
|
type Key = $($K)*;
|
2020-03-19 14:24:21 +01:00
|
|
|
type Value = $V;
|
2020-03-27 18:41:13 +01:00
|
|
|
type Stored = <
|
|
|
|
query_storage!([$($modifiers)*][$($K)*, $V])
|
|
|
|
as QueryStorage
|
|
|
|
>::Stored;
|
2020-03-19 14:24:21 +01:00
|
|
|
const NAME: &'static str = stringify!($name);
|
|
|
|
const CATEGORY: ProfileCategory = $category;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<$tcx> QueryAccessors<TyCtxt<$tcx>> for queries::$name<$tcx> {
|
|
|
|
const ANON: bool = is_anon!([$($modifiers)*]);
|
|
|
|
const EVAL_ALWAYS: bool = is_eval_always!([$($modifiers)*]);
|
|
|
|
const DEP_KIND: dep_graph::DepKind = dep_graph::DepKind::$node;
|
|
|
|
|
2020-04-09 10:29:08 -07:00
|
|
|
type Cache = query_storage!([$($modifiers)*][$($K)*, $V]);
|
2020-03-19 14:24:21 +01:00
|
|
|
|
|
|
|
#[inline(always)]
|
|
|
|
fn query_state<'a>(tcx: TyCtxt<$tcx>) -> &'a QueryState<TyCtxt<$tcx>, Self::Cache> {
|
|
|
|
&tcx.queries.$name
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn compute(tcx: TyCtxt<'tcx>, key: Self::Key) -> Self::Value {
|
|
|
|
let provider = tcx.queries.providers.get(key.query_crate())
|
|
|
|
// HACK(eddyb) it's possible crates may be loaded after
|
|
|
|
// the query engine is created, and because crate loading
|
|
|
|
// is not yet integrated with the query engine, such crates
|
|
|
|
// would be missing appropriate entries in `providers`.
|
|
|
|
.unwrap_or(&tcx.queries.fallback_extern_providers)
|
|
|
|
.$name;
|
|
|
|
provider(tcx, key)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn hash_result(
|
|
|
|
_hcx: &mut StableHashingContext<'_>,
|
|
|
|
_result: &Self::Value
|
|
|
|
) -> Option<Fingerprint> {
|
|
|
|
hash_result!([$($modifiers)*][_hcx, _result])
|
|
|
|
}
|
|
|
|
|
|
|
|
fn handle_cycle_error(
|
|
|
|
tcx: TyCtxt<'tcx>,
|
|
|
|
error: CycleError<Query<'tcx>>
|
|
|
|
) -> Self::Value {
|
|
|
|
handle_cycle_error!([$($modifiers)*][tcx, error])
|
|
|
|
}
|
|
|
|
})*
|
|
|
|
|
|
|
|
#[derive(Copy, Clone)]
|
|
|
|
pub struct TyCtxtEnsure<'tcx> {
|
|
|
|
pub tcx: TyCtxt<'tcx>,
|
|
|
|
}
|
|
|
|
|
2020-04-10 13:44:15 -07:00
|
|
|
impl TyCtxtEnsure<$tcx> {
|
|
|
|
$($(#[$attr])*
|
|
|
|
#[inline(always)]
|
|
|
|
pub fn $name(self, key: query_helper_param_ty!($($K)*)) {
|
2020-04-10 13:54:06 -07:00
|
|
|
ensure_query::<queries::$name<'_>, _>(self.tcx, key.into_query_param())
|
2020-04-10 13:44:15 -07:00
|
|
|
})*
|
2020-03-19 14:24:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Copy, Clone)]
|
|
|
|
pub struct TyCtxtAt<'tcx> {
|
|
|
|
pub tcx: TyCtxt<'tcx>,
|
|
|
|
pub span: Span,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Deref for TyCtxtAt<'tcx> {
|
|
|
|
type Target = TyCtxt<'tcx>;
|
|
|
|
#[inline(always)]
|
|
|
|
fn deref(&self) -> &Self::Target {
|
|
|
|
&self.tcx
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl TyCtxt<$tcx> {
|
|
|
|
/// Returns a transparent wrapper for `TyCtxt`, which ensures queries
|
|
|
|
/// are executed instead of just returning their results.
|
|
|
|
#[inline(always)]
|
|
|
|
pub fn ensure(self) -> TyCtxtEnsure<$tcx> {
|
|
|
|
TyCtxtEnsure {
|
|
|
|
tcx: self,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns a transparent wrapper for `TyCtxt` which uses
|
|
|
|
/// `span` as the location of queries performed through it.
|
|
|
|
#[inline(always)]
|
|
|
|
pub fn at(self, span: Span) -> TyCtxtAt<$tcx> {
|
|
|
|
TyCtxtAt {
|
|
|
|
tcx: self,
|
|
|
|
span
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-10 13:44:15 -07:00
|
|
|
$($(#[$attr])*
|
|
|
|
#[inline(always)]
|
2020-03-27 18:41:13 +01:00
|
|
|
pub fn $name(self, key: query_helper_param_ty!($($K)*))
|
|
|
|
-> <queries::$name<$tcx> as QueryConfig<TyCtxt<$tcx>>>::Stored
|
|
|
|
{
|
|
|
|
self.at(DUMMY_SP).$name(key.into_query_param())
|
2020-04-10 13:44:15 -07:00
|
|
|
})*
|
2020-03-19 14:24:21 +01:00
|
|
|
|
|
|
|
/// All self-profiling events generated by the query engine use
|
|
|
|
/// virtual `StringId`s for their `event_id`. This method makes all
|
|
|
|
/// those virtual `StringId`s point to actual strings.
|
|
|
|
///
|
|
|
|
/// If we are recording only summary data, the ids will point to
|
|
|
|
/// just the query names. If we are recording query keys too, we
|
|
|
|
/// allocate the corresponding strings here.
|
|
|
|
pub fn alloc_self_profile_query_strings(self) {
|
|
|
|
use crate::ty::query::profiling_support::{
|
|
|
|
alloc_self_profile_query_strings_for_query_cache,
|
|
|
|
QueryKeyStringCache,
|
|
|
|
};
|
|
|
|
|
|
|
|
if !self.prof.enabled() {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let mut string_cache = QueryKeyStringCache::new();
|
|
|
|
|
|
|
|
$({
|
|
|
|
alloc_self_profile_query_strings_for_query_cache(
|
|
|
|
self,
|
|
|
|
stringify!($name),
|
|
|
|
&self.queries.$name,
|
|
|
|
&mut string_cache,
|
|
|
|
);
|
|
|
|
})*
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl TyCtxtAt<$tcx> {
|
2020-04-10 13:44:15 -07:00
|
|
|
$($(#[$attr])*
|
|
|
|
#[inline(always)]
|
2020-03-27 18:41:13 +01:00
|
|
|
pub fn $name(self, key: query_helper_param_ty!($($K)*))
|
|
|
|
-> <queries::$name<$tcx> as QueryConfig<TyCtxt<$tcx>>>::Stored
|
|
|
|
{
|
2020-04-10 13:54:06 -07:00
|
|
|
get_query::<queries::$name<'_>, _>(self.tcx, self.span, key.into_query_param())
|
2020-04-10 13:44:15 -07:00
|
|
|
})*
|
2020-03-19 14:24:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
define_provider_struct! {
|
|
|
|
tcx: $tcx,
|
2020-04-09 10:29:08 -07:00
|
|
|
input: ($(([$($modifiers)*] [$name] [$($K)*] [$V]))*)
|
2020-03-19 14:24:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<$tcx> Copy for Providers<$tcx> {}
|
|
|
|
impl<$tcx> Clone for Providers<$tcx> {
|
|
|
|
fn clone(&self) -> Self { *self }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
macro_rules! define_queries_struct {
|
|
|
|
(tcx: $tcx:tt,
|
|
|
|
input: ($(([$($modifiers:tt)*] [$($attr:tt)*] [$name:ident]))*)) => {
|
|
|
|
pub struct Queries<$tcx> {
|
|
|
|
/// This provides access to the incrimental comilation on-disk cache for query results.
|
|
|
|
/// Do not access this directly. It is only meant to be used by
|
|
|
|
/// `DepGraph::try_mark_green()` and the query infrastructure.
|
|
|
|
pub(crate) on_disk_cache: OnDiskCache<'tcx>,
|
|
|
|
|
|
|
|
providers: IndexVec<CrateNum, Providers<$tcx>>,
|
|
|
|
fallback_extern_providers: Box<Providers<$tcx>>,
|
|
|
|
|
|
|
|
$($(#[$attr])* $name: QueryState<
|
|
|
|
TyCtxt<$tcx>,
|
|
|
|
<queries::$name<$tcx> as QueryAccessors<TyCtxt<'tcx>>>::Cache,
|
|
|
|
>,)*
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<$tcx> Queries<$tcx> {
|
|
|
|
pub(crate) fn new(
|
|
|
|
providers: IndexVec<CrateNum, Providers<$tcx>>,
|
|
|
|
fallback_extern_providers: Providers<$tcx>,
|
|
|
|
on_disk_cache: OnDiskCache<'tcx>,
|
|
|
|
) -> Self {
|
|
|
|
Queries {
|
|
|
|
providers,
|
|
|
|
fallback_extern_providers: Box::new(fallback_extern_providers),
|
|
|
|
on_disk_cache,
|
|
|
|
$($name: Default::default()),*
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(crate) fn try_collect_active_jobs(
|
|
|
|
&self
|
|
|
|
) -> Option<FxHashMap<QueryJobId<crate::dep_graph::DepKind>, QueryJobInfo<TyCtxt<'tcx>>>> {
|
|
|
|
let mut jobs = FxHashMap::default();
|
|
|
|
|
|
|
|
$(
|
|
|
|
self.$name.try_collect_active_jobs(
|
|
|
|
<queries::$name<'tcx> as QueryAccessors<TyCtxt<'tcx>>>::DEP_KIND,
|
|
|
|
Query::$name,
|
|
|
|
&mut jobs,
|
|
|
|
)?;
|
|
|
|
)*
|
|
|
|
|
|
|
|
Some(jobs)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
macro_rules! define_provider_struct {
|
|
|
|
(tcx: $tcx:tt,
|
|
|
|
input: ($(([$($modifiers:tt)*] [$name:ident] [$K:ty] [$R:ty]))*)) => {
|
|
|
|
pub struct Providers<$tcx> {
|
|
|
|
$(pub $name: fn(TyCtxt<$tcx>, $K) -> $R,)*
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<$tcx> Default for Providers<$tcx> {
|
|
|
|
fn default() -> Self {
|
|
|
|
$(fn $name<$tcx>(_: TyCtxt<$tcx>, key: $K) -> $R {
|
|
|
|
bug!("`tcx.{}({:?})` unsupported by its crate",
|
|
|
|
stringify!($name), key);
|
|
|
|
})*
|
|
|
|
Providers { $($name),* }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|