Outline default query and hook provider function implementations

This commit is contained in:
DaniPopes 2024-04-16 15:20:12 +02:00
parent ad18fe08de
commit 780dfb803f
No known key found for this signature in database
GPG Key ID: 0F09640DDB7AC692
2 changed files with 28 additions and 23 deletions

View File

@ -47,12 +47,7 @@ pub struct Providers {
impl Default for Providers { impl Default for Providers {
fn default() -> Self { fn default() -> Self {
Providers { Providers {
$($name: |_, $($arg,)*| bug!( $($name: |_, $($arg,)*| default_hook(stringify!($name), &($($arg,)*))),*
"`tcx.{}{:?}` cannot be called as `{}` was never assigned to a provider function.\n",
stringify!($name),
($($arg,)*),
stringify!($name),
),)*
} }
} }
} }
@ -84,7 +79,6 @@ fn clone(&self) -> Self { *self }
/// via `mir_built` /// via `mir_built`
hook build_mir(key: LocalDefId) -> mir::Body<'tcx>; hook build_mir(key: LocalDefId) -> mir::Body<'tcx>;
/// Imports all `SourceFile`s from the given crate into the current session. /// Imports all `SourceFile`s from the given crate into the current session.
/// This normally happens automatically when we decode a `Span` from /// This normally happens automatically when we decode a `Span` from
/// that crate's metadata - however, the incr comp cache needs /// that crate's metadata - however, the incr comp cache needs
@ -103,3 +97,10 @@ fn clone(&self) -> Self { *self }
/// Will fetch a DefId from a DefPathHash for a foreign crate. /// Will fetch a DefId from a DefPathHash for a foreign crate.
hook def_path_hash_to_def_id_extern(hash: DefPathHash, stable_crate_id: StableCrateId) -> DefId; hook def_path_hash_to_def_id_extern(hash: DefPathHash, stable_crate_id: StableCrateId) -> DefId;
} }
#[cold]
fn default_hook(name: &str, args: &dyn std::fmt::Debug) -> ! {
bug!(
"`tcx.{name}{args:?}` cannot be called as `{name}` was never assigned to a provider function"
)
}

View File

@ -266,13 +266,7 @@ macro_rules! separate_provide_extern_default {
() ()
}; };
([(separate_provide_extern) $($rest:tt)*][$name:ident]) => { ([(separate_provide_extern) $($rest:tt)*][$name:ident]) => {
|_, key| bug!( |_, key| $crate::query::plumbing::default_extern_query(stringify!($name), &key)
"`tcx.{}({:?})` unsupported by its crate; \
perhaps the `{}` query was never assigned a provider function",
stringify!($name),
key,
stringify!($name),
)
}; };
([$other:tt $($modifiers:tt)*][$($args:tt)*]) => { ([$other:tt $($modifiers:tt)*][$($args:tt)*]) => {
separate_provide_extern_default!([$($modifiers)*][$($args)*]) separate_provide_extern_default!([$($modifiers)*][$($args)*])
@ -462,15 +456,7 @@ pub struct ExternProviders {
impl Default for Providers { impl Default for Providers {
fn default() -> Self { fn default() -> Self {
Providers { Providers {
$($name: |_, key| bug!( $($name: |_, key| $crate::query::plumbing::default_query(stringify!($name), &key)),*
"`tcx.{}({:?})` is not supported for this key;\n\
hint: Queries can be either made to the local crate, or the external crate. \
This error means you tried to use it for one that's not supported.\n\
If that's not the case, {} was likely never assigned to a provider function.\n",
stringify!($name),
key,
stringify!($name),
),)*
} }
} }
} }
@ -661,3 +647,21 @@ fn into_query_param(self) -> LocalDefId {
#[derive(Copy, Clone, Debug, HashStable)] #[derive(Copy, Clone, Debug, HashStable)]
pub struct CyclePlaceholder(pub ErrorGuaranteed); pub struct CyclePlaceholder(pub ErrorGuaranteed);
#[cold]
pub(crate) fn default_query(name: &str, key: &dyn std::fmt::Debug) -> ! {
bug!(
"`tcx.{name}({key:?})` is not supported for this key;\n\
hint: Queries can be either made to the local crate, or the external crate. \
This error means you tried to use it for one that's not supported.\n\
If that's not the case, {name} was likely never assigned to a provider function.\n",
)
}
#[cold]
pub(crate) fn default_extern_query(name: &str, key: &dyn std::fmt::Debug) -> ! {
bug!(
"`tcx.{name}({key:?})` unsupported by its crate; \
perhaps the `{name}` query was never assigned a provider function",
)
}