Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Outline default query and hook provider function implementations #124016

Merged
merged 1 commit into from
Apr 16, 2024
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
15 changes: 8 additions & 7 deletions compiler/rustc_middle/src/hooks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,7 @@ macro_rules! declare_hooks {
impl Default for Providers {
fn default() -> Self {
Providers {
$($name: |_, $($arg,)*| bug!(
"`tcx.{}{:?}` cannot be called as `{}` was never assigned to a provider function.\n",
stringify!($name),
($($arg,)*),
stringify!($name),
),)*
$($name: |_, $($arg,)*| default_hook(stringify!($name), &($($arg,)*))),*
}
}
}
Expand Down Expand Up @@ -84,7 +79,6 @@ declare_hooks! {
/// via `mir_built`
hook build_mir(key: LocalDefId) -> mir::Body<'tcx>;


/// Imports all `SourceFile`s from the given crate into the current session.
/// This normally happens automatically when we decode a `Span` from
/// that crate's metadata - however, the incr comp cache needs
Expand All @@ -103,3 +97,10 @@ declare_hooks! {
/// 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;
}

#[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"
)
}
36 changes: 20 additions & 16 deletions compiler/rustc_middle/src/query/plumbing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,13 +266,7 @@ macro_rules! separate_provide_extern_default {
()
};
([(separate_provide_extern) $($rest:tt)*][$name:ident]) => {
|_, key| bug!(
"`tcx.{}({:?})` unsupported by its crate; \
perhaps the `{}` query was never assigned a provider function",
stringify!($name),
key,
stringify!($name),
)
|_, key| $crate::query::plumbing::default_extern_query(stringify!($name), &key)
};
([$other:tt $($modifiers:tt)*][$($args:tt)*]) => {
separate_provide_extern_default!([$($modifiers)*][$($args)*])
Expand Down Expand Up @@ -462,15 +456,7 @@ macro_rules! define_callbacks {
impl Default for Providers {
fn default() -> Self {
Providers {
$($name: |_, key| bug!(
"`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),
),)*
$($name: |_, key| $crate::query::plumbing::default_query(stringify!($name), &key)),*
}
}
}
Expand Down Expand Up @@ -661,3 +647,21 @@ use super::erase::EraseType;

#[derive(Copy, Clone, Debug, HashStable)]
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",
)
}
Loading