]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_query_impl/src/plumbing.rs
Add u32 for bound variables to Binder
[rust.git] / compiler / rustc_query_impl / src / plumbing.rs
1 //! The implementation of the query system itself. This defines the macros that
2 //! generate the actual methods on tcx which find and execute the provider,
3 //! manage the caches, and so forth.
4
5 use super::queries;
6 use rustc_middle::dep_graph::{DepKind, DepNode, DepNodeExt, DepNodeIndex, SerializedDepNodeIndex};
7 use rustc_middle::ty::query::on_disk_cache;
8 use rustc_middle::ty::tls::{self, ImplicitCtxt};
9 use rustc_middle::ty::{self, TyCtxt};
10 use rustc_query_system::dep_graph::HasDepContext;
11 use rustc_query_system::query::{QueryContext, QueryDescription, QueryJobId, QueryMap};
12
13 use rustc_data_structures::sync::Lock;
14 use rustc_data_structures::thin_vec::ThinVec;
15 use rustc_errors::Diagnostic;
16 use rustc_serialize::opaque;
17 use rustc_span::def_id::{DefId, LocalDefId};
18
19 #[derive(Copy, Clone)]
20 pub struct QueryCtxt<'tcx> {
21     pub tcx: TyCtxt<'tcx>,
22     pub queries: &'tcx super::Queries<'tcx>,
23 }
24
25 impl<'tcx> std::ops::Deref for QueryCtxt<'tcx> {
26     type Target = TyCtxt<'tcx>;
27
28     fn deref(&self) -> &Self::Target {
29         &self.tcx
30     }
31 }
32
33 impl HasDepContext for QueryCtxt<'tcx> {
34     type DepKind = rustc_middle::dep_graph::DepKind;
35     type StableHashingContext = rustc_middle::ich::StableHashingContext<'tcx>;
36     type DepContext = TyCtxt<'tcx>;
37
38     #[inline]
39     fn dep_context(&self) -> &Self::DepContext {
40         &self.tcx
41     }
42 }
43
44 impl QueryContext for QueryCtxt<'tcx> {
45     fn def_path_str(&self, def_id: DefId) -> String {
46         self.tcx.def_path_str(def_id)
47     }
48
49     fn current_query_job(&self) -> Option<QueryJobId<Self::DepKind>> {
50         tls::with_related_context(**self, |icx| icx.query)
51     }
52
53     fn try_collect_active_jobs(&self) -> Option<QueryMap<Self::DepKind>> {
54         self.queries.try_collect_active_jobs(**self)
55     }
56
57     fn try_load_from_on_disk_cache(&self, dep_node: &DepNode) {
58         let cb = &super::QUERY_CALLBACKS[dep_node.kind as usize];
59         (cb.try_load_from_on_disk_cache)(*self, dep_node)
60     }
61
62     fn try_force_from_dep_node(&self, dep_node: &DepNode) -> bool {
63         // FIXME: This match is just a workaround for incremental bugs and should
64         // be removed. https://github.com/rust-lang/rust/issues/62649 is one such
65         // bug that must be fixed before removing this.
66         match dep_node.kind {
67             DepKind::hir_owner | DepKind::hir_owner_nodes => {
68                 if let Some(def_id) = dep_node.extract_def_id(**self) {
69                     let def_id = def_id.expect_local();
70                     let hir_id = self.tcx.hir().local_def_id_to_hir_id(def_id);
71                     if def_id != hir_id.owner {
72                         // This `DefPath` does not have a
73                         // corresponding `DepNode` (e.g. a
74                         // struct field), and the ` DefPath`
75                         // collided with the `DefPath` of a
76                         // proper item that existed in the
77                         // previous compilation session.
78                         //
79                         // Since the given `DefPath` does not
80                         // denote the item that previously
81                         // existed, we just fail to mark green.
82                         return false;
83                     }
84                 } else {
85                     // If the node does not exist anymore, we
86                     // just fail to mark green.
87                     return false;
88                 }
89             }
90             _ => {
91                 // For other kinds of nodes it's OK to be
92                 // forced.
93             }
94         }
95
96         debug!("try_force_from_dep_node({:?}) --- trying to force", dep_node);
97
98         // We must avoid ever having to call `force_from_dep_node()` for a
99         // `DepNode::codegen_unit`:
100         // Since we cannot reconstruct the query key of a `DepNode::codegen_unit`, we
101         // would always end up having to evaluate the first caller of the
102         // `codegen_unit` query that *is* reconstructible. This might very well be
103         // the `compile_codegen_unit` query, thus re-codegenning the whole CGU just
104         // to re-trigger calling the `codegen_unit` query with the right key. At
105         // that point we would already have re-done all the work we are trying to
106         // avoid doing in the first place.
107         // The solution is simple: Just explicitly call the `codegen_unit` query for
108         // each CGU, right after partitioning. This way `try_mark_green` will always
109         // hit the cache instead of having to go through `force_from_dep_node`.
110         // This assertion makes sure, we actually keep applying the solution above.
111         debug_assert!(
112             dep_node.kind != DepKind::codegen_unit,
113             "calling force_from_dep_node() on DepKind::codegen_unit"
114         );
115
116         let cb = &super::QUERY_CALLBACKS[dep_node.kind as usize];
117         (cb.force_from_dep_node)(*self, dep_node)
118     }
119
120     // Interactions with on_disk_cache
121     fn load_diagnostics(&self, prev_dep_node_index: SerializedDepNodeIndex) -> Vec<Diagnostic> {
122         self.on_disk_cache
123             .as_ref()
124             .map(|c| c.load_diagnostics(**self, prev_dep_node_index))
125             .unwrap_or_default()
126     }
127
128     fn store_diagnostics(&self, dep_node_index: DepNodeIndex, diagnostics: ThinVec<Diagnostic>) {
129         if let Some(c) = self.on_disk_cache.as_ref() {
130             c.store_diagnostics(dep_node_index, diagnostics)
131         }
132     }
133
134     fn store_diagnostics_for_anon_node(
135         &self,
136         dep_node_index: DepNodeIndex,
137         diagnostics: ThinVec<Diagnostic>,
138     ) {
139         if let Some(c) = self.on_disk_cache.as_ref() {
140             c.store_diagnostics_for_anon_node(dep_node_index, diagnostics)
141         }
142     }
143
144     /// Executes a job by changing the `ImplicitCtxt` to point to the
145     /// new query job while it executes. It returns the diagnostics
146     /// captured during execution and the actual result.
147     #[inline(always)]
148     fn start_query<R>(
149         &self,
150         token: QueryJobId<Self::DepKind>,
151         diagnostics: Option<&Lock<ThinVec<Diagnostic>>>,
152         compute: impl FnOnce() -> R,
153     ) -> R {
154         // The `TyCtxt` stored in TLS has the same global interner lifetime
155         // as `self`, so we use `with_related_context` to relate the 'tcx lifetimes
156         // when accessing the `ImplicitCtxt`.
157         tls::with_related_context(**self, move |current_icx| {
158             // Update the `ImplicitCtxt` to point to our new query job.
159             let new_icx = ImplicitCtxt {
160                 tcx: **self,
161                 query: Some(token),
162                 diagnostics,
163                 layout_depth: current_icx.layout_depth,
164                 task_deps: current_icx.task_deps,
165             };
166
167             // Use the `ImplicitCtxt` while we execute the query.
168             tls::enter_context(&new_icx, |_| {
169                 rustc_data_structures::stack::ensure_sufficient_stack(compute)
170             })
171         })
172     }
173 }
174
175 impl<'tcx> QueryCtxt<'tcx> {
176     pub(super) fn encode_query_results(
177         self,
178         encoder: &mut on_disk_cache::CacheEncoder<'a, 'tcx, opaque::FileEncoder>,
179         query_result_index: &mut on_disk_cache::EncodedQueryResultIndex,
180     ) -> opaque::FileEncodeResult {
181         macro_rules! encode_queries {
182             ($($query:ident,)*) => {
183                 $(
184                     on_disk_cache::encode_query_results::<_, super::queries::$query<'_>>(
185                         self,
186                         encoder,
187                         query_result_index
188                     )?;
189                 )*
190             }
191         }
192
193         rustc_cached_queries!(encode_queries!);
194
195         Ok(())
196     }
197 }
198
199 /// This struct stores metadata about each Query.
200 ///
201 /// Information is retrieved by indexing the `QUERIES` array using the integer value
202 /// of the `DepKind`. Overall, this allows to implement `QueryContext` using this manual
203 /// jump table instead of large matches.
204 pub struct QueryStruct {
205     /// The red/green evaluation system will try to mark a specific DepNode in the
206     /// dependency graph as green by recursively trying to mark the dependencies of
207     /// that `DepNode` as green. While doing so, it will sometimes encounter a `DepNode`
208     /// where we don't know if it is red or green and we therefore actually have
209     /// to recompute its value in order to find out. Since the only piece of
210     /// information that we have at that point is the `DepNode` we are trying to
211     /// re-evaluate, we need some way to re-run a query from just that. This is what
212     /// `force_from_dep_node()` implements.
213     ///
214     /// In the general case, a `DepNode` consists of a `DepKind` and an opaque
215     /// GUID/fingerprint that will uniquely identify the node. This GUID/fingerprint
216     /// is usually constructed by computing a stable hash of the query-key that the
217     /// `DepNode` corresponds to. Consequently, it is not in general possible to go
218     /// back from hash to query-key (since hash functions are not reversible). For
219     /// this reason `force_from_dep_node()` is expected to fail from time to time
220     /// because we just cannot find out, from the `DepNode` alone, what the
221     /// corresponding query-key is and therefore cannot re-run the query.
222     ///
223     /// The system deals with this case letting `try_mark_green` fail which forces
224     /// the root query to be re-evaluated.
225     ///
226     /// Now, if `force_from_dep_node()` would always fail, it would be pretty useless.
227     /// Fortunately, we can use some contextual information that will allow us to
228     /// reconstruct query-keys for certain kinds of `DepNode`s. In particular, we
229     /// enforce by construction that the GUID/fingerprint of certain `DepNode`s is a
230     /// valid `DefPathHash`. Since we also always build a huge table that maps every
231     /// `DefPathHash` in the current codebase to the corresponding `DefId`, we have
232     /// everything we need to re-run the query.
233     ///
234     /// Take the `mir_promoted` query as an example. Like many other queries, it
235     /// just has a single parameter: the `DefId` of the item it will compute the
236     /// validated MIR for. Now, when we call `force_from_dep_node()` on a `DepNode`
237     /// with kind `MirValidated`, we know that the GUID/fingerprint of the `DepNode`
238     /// is actually a `DefPathHash`, and can therefore just look up the corresponding
239     /// `DefId` in `tcx.def_path_hash_to_def_id`.
240     ///
241     /// When you implement a new query, it will likely have a corresponding new
242     /// `DepKind`, and you'll have to support it here in `force_from_dep_node()`. As
243     /// a rule of thumb, if your query takes a `DefId` or `LocalDefId` as sole parameter,
244     /// then `force_from_dep_node()` should not fail for it. Otherwise, you can just
245     /// add it to the "We don't have enough information to reconstruct..." group in
246     /// the match below.
247     pub(crate) force_from_dep_node: fn(tcx: QueryCtxt<'_>, dep_node: &DepNode) -> bool,
248
249     /// Invoke a query to put the on-disk cached value in memory.
250     pub(crate) try_load_from_on_disk_cache: fn(QueryCtxt<'_>, &DepNode),
251 }
252
253 macro_rules! handle_cycle_error {
254     ([][$tcx: expr, $error:expr]) => {{
255         $error.emit();
256         Value::from_cycle_error($tcx)
257     }};
258     ([fatal_cycle $($rest:tt)*][$tcx:expr, $error:expr]) => {{
259         $error.emit();
260         $tcx.sess.abort_if_errors();
261         unreachable!()
262     }};
263     ([cycle_delay_bug $($rest:tt)*][$tcx:expr, $error:expr]) => {{
264         $error.delay_as_bug();
265         Value::from_cycle_error($tcx)
266     }};
267     ([$other:ident $(($($other_args:tt)*))* $(, $($modifiers:tt)*)*][$($args:tt)*]) => {
268         handle_cycle_error!([$($($modifiers)*)*][$($args)*])
269     };
270 }
271
272 macro_rules! is_anon {
273     ([]) => {{
274         false
275     }};
276     ([anon $($rest:tt)*]) => {{
277         true
278     }};
279     ([$other:ident $(($($other_args:tt)*))* $(, $($modifiers:tt)*)*]) => {
280         is_anon!([$($($modifiers)*)*])
281     };
282 }
283
284 macro_rules! is_eval_always {
285     ([]) => {{
286         false
287     }};
288     ([eval_always $($rest:tt)*]) => {{
289         true
290     }};
291     ([$other:ident $(($($other_args:tt)*))* $(, $($modifiers:tt)*)*]) => {
292         is_eval_always!([$($($modifiers)*)*])
293     };
294 }
295
296 macro_rules! hash_result {
297     ([][$hcx:expr, $result:expr]) => {{
298         dep_graph::hash_result($hcx, &$result)
299     }};
300     ([no_hash $($rest:tt)*][$hcx:expr, $result:expr]) => {{
301         None
302     }};
303     ([$other:ident $(($($other_args:tt)*))* $(, $($modifiers:tt)*)*][$($args:tt)*]) => {
304         hash_result!([$($($modifiers)*)*][$($args)*])
305     };
306 }
307
308 macro_rules! define_queries {
309     (<$tcx:tt>
310      $($(#[$attr:meta])*
311         [$($modifiers:tt)*] fn $name:ident($($K:tt)*) -> $V:ty,)*) => {
312
313         define_queries_struct! {
314             tcx: $tcx,
315             input: ($(([$($modifiers)*] [$($attr)*] [$name]))*)
316         }
317
318         mod make_query {
319             use super::*;
320
321             // Create an eponymous constructor for each query.
322             $(#[allow(nonstandard_style)] $(#[$attr])*
323             pub fn $name<$tcx>(tcx: QueryCtxt<$tcx>, key: query_keys::$name<$tcx>) -> QueryStackFrame {
324                 let kind = dep_graph::DepKind::$name;
325                 let name = stringify!($name);
326                 let description = ty::print::with_forced_impl_filename_line(
327                     // Force filename-line mode to avoid invoking `type_of` query.
328                     || queries::$name::describe(tcx, key)
329                 );
330                 let description = if tcx.sess.verbose() {
331                     format!("{} [{}]", description, name)
332                 } else {
333                     description
334                 };
335                 let span = if kind == dep_graph::DepKind::def_span {
336                     // The `def_span` query is used to calculate `default_span`,
337                     // so exit to avoid infinite recursion.
338                     None
339                 } else {
340                     Some(key.default_span(*tcx))
341                 };
342                 let hash = || {
343                     let mut hcx = tcx.create_stable_hashing_context();
344                     let mut hasher = StableHasher::new();
345                     std::mem::discriminant(&kind).hash_stable(&mut hcx, &mut hasher);
346                     key.hash_stable(&mut hcx, &mut hasher);
347                     hasher.finish::<u64>()
348                 };
349
350                 QueryStackFrame::new(name, description, span, hash)
351             })*
352         }
353
354         #[allow(nonstandard_style)]
355         pub mod queries {
356             use std::marker::PhantomData;
357
358             $(pub struct $name<$tcx> {
359                 data: PhantomData<&$tcx ()>
360             })*
361         }
362
363         $(impl<$tcx> QueryConfig for queries::$name<$tcx> {
364             type Key = query_keys::$name<$tcx>;
365             type Value = query_values::$name<$tcx>;
366             type Stored = query_stored::$name<$tcx>;
367             const NAME: &'static str = stringify!($name);
368         }
369
370         impl<$tcx> QueryAccessors<QueryCtxt<$tcx>> for queries::$name<$tcx> {
371             const ANON: bool = is_anon!([$($modifiers)*]);
372             const EVAL_ALWAYS: bool = is_eval_always!([$($modifiers)*]);
373             const DEP_KIND: dep_graph::DepKind = dep_graph::DepKind::$name;
374
375             type Cache = query_storage::$name<$tcx>;
376
377             #[inline(always)]
378             fn query_state<'a>(tcx: QueryCtxt<$tcx>) -> &'a QueryState<crate::dep_graph::DepKind, Self::Key>
379                 where QueryCtxt<$tcx>: 'a
380             {
381                 &tcx.queries.$name
382             }
383
384             #[inline(always)]
385             fn query_cache<'a>(tcx: QueryCtxt<$tcx>) -> &'a QueryCacheStore<Self::Cache>
386                 where 'tcx:'a
387             {
388                 &tcx.query_caches.$name
389             }
390
391             #[inline]
392             fn compute(tcx: QueryCtxt<'tcx>, key: Self::Key) -> Self::Value {
393                 let is_local = key.query_crate() == LOCAL_CRATE;
394                 let provider = if is_local {
395                     tcx.queries.local_providers.$name
396                 } else {
397                     tcx.queries.extern_providers.$name
398                 };
399                 provider(*tcx, key)
400             }
401
402             fn hash_result(
403                 _hcx: &mut StableHashingContext<'_>,
404                 _result: &Self::Value
405             ) -> Option<Fingerprint> {
406                 hash_result!([$($modifiers)*][_hcx, _result])
407             }
408
409             fn handle_cycle_error(
410                 tcx: QueryCtxt<'tcx>,
411                 mut error: DiagnosticBuilder<'_>,
412             ) -> Self::Value {
413                 handle_cycle_error!([$($modifiers)*][tcx, error])
414             }
415         })*
416
417         #[allow(non_upper_case_globals)]
418         pub mod query_callbacks {
419             use super::*;
420             use rustc_middle::dep_graph::DepNode;
421             use rustc_middle::ty::query::query_keys;
422             use rustc_query_system::dep_graph::DepNodeParams;
423             use rustc_query_system::query::{force_query, QueryDescription};
424
425             // We use this for most things when incr. comp. is turned off.
426             pub const Null: QueryStruct = QueryStruct {
427                 force_from_dep_node: |_, dep_node| bug!("force_from_dep_node: encountered {:?}", dep_node),
428                 try_load_from_on_disk_cache: |_, _| {},
429             };
430
431             pub const TraitSelect: QueryStruct = QueryStruct {
432                 force_from_dep_node: |_, _| false,
433                 try_load_from_on_disk_cache: |_, _| {},
434             };
435
436             pub const CompileCodegenUnit: QueryStruct = QueryStruct {
437                 force_from_dep_node: |_, _| false,
438                 try_load_from_on_disk_cache: |_, _| {},
439             };
440
441             $(pub const $name: QueryStruct = {
442                 const is_anon: bool = is_anon!([$($modifiers)*]);
443
444                 #[inline(always)]
445                 fn can_reconstruct_query_key() -> bool {
446                     <query_keys::$name<'_> as DepNodeParams<TyCtxt<'_>>>
447                         ::can_reconstruct_query_key()
448                 }
449
450                 fn recover<'tcx>(tcx: TyCtxt<'tcx>, dep_node: &DepNode) -> Option<query_keys::$name<'tcx>> {
451                     <query_keys::$name<'_> as DepNodeParams<TyCtxt<'_>>>::recover(tcx, dep_node)
452                 }
453
454                 fn force_from_dep_node(tcx: QueryCtxt<'_>, dep_node: &DepNode) -> bool {
455                     if is_anon {
456                         return false;
457                     }
458
459                     if !can_reconstruct_query_key() {
460                         return false;
461                     }
462
463                     if let Some(key) = recover(*tcx, dep_node) {
464                         force_query::<queries::$name<'_>, _>(tcx, key, DUMMY_SP, *dep_node);
465                         return true;
466                     }
467
468                     false
469                 }
470
471                 fn try_load_from_on_disk_cache(tcx: QueryCtxt<'_>, dep_node: &DepNode) {
472                     if is_anon {
473                         return
474                     }
475
476                     if !can_reconstruct_query_key() {
477                         return
478                     }
479
480                     debug_assert!(tcx.dep_graph
481                                      .node_color(dep_node)
482                                      .map(|c| c.is_green())
483                                      .unwrap_or(false));
484
485                     let key = recover(*tcx, dep_node).unwrap_or_else(|| panic!("Failed to recover key for {:?} with hash {}", dep_node, dep_node.hash));
486                     if queries::$name::cache_on_disk(tcx, &key, None) {
487                         let _ = tcx.$name(key);
488                     }
489                 }
490
491                 QueryStruct {
492                     force_from_dep_node,
493                     try_load_from_on_disk_cache,
494                 }
495             };)*
496         }
497
498         static QUERY_CALLBACKS: &[QueryStruct] = &make_dep_kind_array!(query_callbacks);
499     }
500 }
501
502 // FIXME(eddyb) this macro (and others?) use `$tcx` and `'tcx` interchangeably.
503 // We should either not take `$tcx` at all and use `'tcx` everywhere, or use
504 // `$tcx` everywhere (even if that isn't necessary due to lack of hygiene).
505 macro_rules! define_queries_struct {
506     (tcx: $tcx:tt,
507      input: ($(([$($modifiers:tt)*] [$($attr:tt)*] [$name:ident]))*)) => {
508         pub struct Queries<$tcx> {
509             local_providers: Box<Providers>,
510             extern_providers: Box<Providers>,
511
512             $($(#[$attr])*  $name: QueryState<
513                 crate::dep_graph::DepKind,
514                 query_keys::$name<$tcx>,
515             >,)*
516         }
517
518         impl<$tcx> Queries<$tcx> {
519             pub fn new(
520                 local_providers: Providers,
521                 extern_providers: Providers,
522             ) -> Self {
523                 Queries {
524                     local_providers: Box::new(local_providers),
525                     extern_providers: Box::new(extern_providers),
526                     $($name: Default::default()),*
527                 }
528             }
529
530             pub(crate) fn try_collect_active_jobs(
531                 &$tcx self,
532                 tcx: TyCtxt<$tcx>,
533             ) -> Option<QueryMap<crate::dep_graph::DepKind>> {
534                 let tcx = QueryCtxt { tcx, queries: self };
535                 let mut jobs = QueryMap::default();
536
537                 $(
538                     self.$name.try_collect_active_jobs(
539                         tcx,
540                         dep_graph::DepKind::$name,
541                         make_query::$name,
542                         &mut jobs,
543                     )?;
544                 )*
545
546                 Some(jobs)
547             }
548         }
549
550         impl QueryEngine<'tcx> for Queries<'tcx> {
551             unsafe fn deadlock(&'tcx self, _tcx: TyCtxt<'tcx>, _registry: &rustc_rayon_core::Registry) {
552                 #[cfg(parallel_compiler)]
553                 {
554                     let tcx = QueryCtxt { tcx: _tcx, queries: self };
555                     rustc_query_system::query::deadlock(tcx, _registry)
556                 }
557             }
558
559             fn encode_query_results(
560                 &'tcx self,
561                 tcx: TyCtxt<'tcx>,
562                 encoder: &mut on_disk_cache::CacheEncoder<'a, 'tcx, opaque::FileEncoder>,
563                 query_result_index: &mut on_disk_cache::EncodedQueryResultIndex,
564             ) -> opaque::FileEncodeResult {
565                 let tcx = QueryCtxt { tcx, queries: self };
566                 tcx.encode_query_results(encoder, query_result_index)
567             }
568
569             fn exec_cache_promotions(&'tcx self, tcx: TyCtxt<'tcx>) {
570                 let tcx = QueryCtxt { tcx, queries: self };
571                 tcx.dep_graph.exec_cache_promotions(tcx)
572             }
573
574             fn try_mark_green(&'tcx self, tcx: TyCtxt<'tcx>, dep_node: &dep_graph::DepNode) -> bool {
575                 let qcx = QueryCtxt { tcx, queries: self };
576                 tcx.dep_graph.try_mark_green(qcx, dep_node).is_some()
577             }
578
579             fn try_print_query_stack(
580                 &'tcx self,
581                 tcx: TyCtxt<'tcx>,
582                 query: Option<QueryJobId<dep_graph::DepKind>>,
583                 handler: &Handler,
584                 num_frames: Option<usize>,
585             ) -> usize {
586                 let qcx = QueryCtxt { tcx, queries: self };
587                 rustc_query_system::query::print_query_stack(qcx, query, handler, num_frames)
588             }
589
590             $($(#[$attr])*
591             #[inline(always)]
592             fn $name(
593                 &'tcx self,
594                 tcx: TyCtxt<$tcx>,
595                 span: Span,
596                 key: query_keys::$name<$tcx>,
597                 lookup: QueryLookup,
598                 mode: QueryMode,
599             ) -> Option<query_stored::$name<$tcx>> {
600                 let qcx = QueryCtxt { tcx, queries: self };
601                 get_query::<queries::$name<$tcx>, _>(qcx, span, key, lookup, mode)
602             })*
603         }
604     };
605 }
606
607 fn describe_as_module(def_id: LocalDefId, tcx: TyCtxt<'_>) -> String {
608     if def_id.is_top_level_module() {
609         "top-level module".to_string()
610     } else {
611         format!("module `{}`", tcx.def_path_str(def_id.to_def_id()))
612     }
613 }
614
615 rustc_query_description! {}