diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2024-04-16 21:41:26 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-04-16 21:41:26 +0200 |
| commit | 4779115f2b06b9673a6329565304758ef948148f (patch) | |
| tree | 45849ebbf4c01fe5a5d0e6b728e9cebbad5576f4 | |
| parent | f939d1ff4820844595d0f50f94038869f1445d08 (diff) | |
| parent | 780dfb803fe1b0ad139bac9736ce847c75ab1c81 (diff) | |
| download | rust-4779115f2b06b9673a6329565304758ef948148f.tar.gz rust-4779115f2b06b9673a6329565304758ef948148f.zip | |
Rollup merge of #124016 - DaniPopes:dedup-default-providers, r=lcnr
Outline default query and hook provider function implementations The default query and hook provider functions call `bug!` with a decently long message. Due to argument inlining in `format_args!` ([`flatten_format_args`](https://github.com/rust-lang/rust/issues/78356)), this ends up duplicating the message for each query, adding ~90KB to `librustc_driver.so` of unreachable panic messages. To avoid this, we can outline the common `bug!` logic.
| -rw-r--r-- | compiler/rustc_middle/src/hooks/mod.rs | 15 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/query/plumbing.rs | 36 |
2 files changed, 28 insertions, 23 deletions
diff --git a/compiler/rustc_middle/src/hooks/mod.rs b/compiler/rustc_middle/src/hooks/mod.rs index 1872f568907..d35b9fc46e4 100644 --- a/compiler/rustc_middle/src/hooks/mod.rs +++ b/compiler/rustc_middle/src/hooks/mod.rs @@ -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,)*))),* } } } @@ -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 @@ -109,3 +103,10 @@ declare_hooks! { /// Create a list-like THIR representation for debugging. hook thir_flat(key: LocalDefId) -> String; } + +#[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" + ) +} diff --git a/compiler/rustc_middle/src/query/plumbing.rs b/compiler/rustc_middle/src/query/plumbing.rs index 4ce6f7747a5..643861972c4 100644 --- a/compiler/rustc_middle/src/query/plumbing.rs +++ b/compiler/rustc_middle/src/query/plumbing.rs @@ -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)*]) @@ -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)),* } } } @@ -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", + ) +} |
