]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_middle/src/query/mod.rs
Make dead code check a query.
[rust.git] / compiler / rustc_middle / src / query / mod.rs
1 // Each of these queries corresponds to a function pointer field in the
2 // `Providers` struct for requesting a value of that type, and a method
3 // on `tcx: TyCtxt` (and `tcx.at(span)`) for doing that request in a way
4 // which memoizes and does dep-graph tracking, wrapping around the actual
5 // `Providers` that the driver creates (using several `rustc_*` crates).
6 //
7 // The result type of each query must implement `Clone`, and additionally
8 // `ty::query::values::Value`, which produces an appropriate placeholder
9 // (error) value if the query resulted in a query cycle.
10 // Queries marked with `fatal_cycle` do not need the latter implementation,
11 // as they will raise an fatal error on query cycles instead.
12 rustc_queries! {
13     query trigger_delay_span_bug(key: DefId) -> () {
14         desc { "trigger a delay span bug" }
15     }
16
17     query resolutions(_: ()) -> &'tcx ty::ResolverOutputs {
18         eval_always
19         no_hash
20         desc { "get the resolver outputs" }
21     }
22
23     /// Return the span for a definition.
24     /// Contrary to `def_span` below, this query returns the full absolute span of the definition.
25     /// This span is meant for dep-tracking rather than diagnostics. It should not be used outside
26     /// of rustc_middle::hir::source_map.
27     query source_span(key: LocalDefId) -> Span {
28         desc { "get the source span" }
29     }
30
31     /// Represents crate as a whole (as distinct from the top-level crate module).
32     /// If you call `hir_crate` (e.g., indirectly by calling `tcx.hir().krate()`),
33     /// we will have to assume that any change means that you need to be recompiled.
34     /// This is because the `hir_crate` query gives you access to all other items.
35     /// To avoid this fate, do not call `tcx.hir().krate()`; instead,
36     /// prefer wrappers like `tcx.visit_all_items_in_krate()`.
37     query hir_crate(key: ()) -> &'tcx Crate<'tcx> {
38         eval_always
39         desc { "get the crate HIR" }
40     }
41
42     /// The items in a module.
43     ///
44     /// This can be conveniently accessed by `tcx.hir().visit_item_likes_in_module`.
45     /// Avoid calling this query directly.
46     query hir_module_items(key: LocalDefId) -> rustc_middle::hir::ModuleItems {
47         storage(ArenaCacheSelector<'tcx>)
48         desc { |tcx| "HIR module items in `{}`", tcx.def_path_str(key.to_def_id()) }
49     }
50
51     /// Gives access to the HIR node for the HIR owner `key`.
52     ///
53     /// This can be conveniently accessed by methods on `tcx.hir()`.
54     /// Avoid calling this query directly.
55     query hir_owner(key: LocalDefId) -> Option<crate::hir::Owner<'tcx>> {
56         desc { |tcx| "HIR owner of `{}`", tcx.def_path_str(key.to_def_id()) }
57     }
58
59     /// Gives access to the HIR node's parent for the HIR owner `key`.
60     ///
61     /// This can be conveniently accessed by methods on `tcx.hir()`.
62     /// Avoid calling this query directly.
63     query hir_owner_parent(key: LocalDefId) -> hir::HirId {
64         desc { |tcx| "HIR parent of `{}`", tcx.def_path_str(key.to_def_id()) }
65     }
66
67     /// Gives access to the HIR nodes and bodies inside the HIR owner `key`.
68     ///
69     /// This can be conveniently accessed by methods on `tcx.hir()`.
70     /// Avoid calling this query directly.
71     query hir_owner_nodes(key: LocalDefId) -> Option<&'tcx hir::OwnerNodes<'tcx>> {
72         desc { |tcx| "HIR owner items in `{}`", tcx.def_path_str(key.to_def_id()) }
73     }
74
75     /// Gives access to the HIR attributes inside the HIR owner `key`.
76     ///
77     /// This can be conveniently accessed by methods on `tcx.hir()`.
78     /// Avoid calling this query directly.
79     query hir_attrs(key: LocalDefId) -> &'tcx hir::AttributeMap<'tcx> {
80         desc { |tcx| "HIR owner attributes in `{}`", tcx.def_path_str(key.to_def_id()) }
81     }
82
83     /// Computes the `DefId` of the corresponding const parameter in case the `key` is a
84     /// const argument and returns `None` otherwise.
85     ///
86     /// ```ignore (incomplete)
87     /// let a = foo::<7>();
88     /// //            ^ Calling `opt_const_param_of` for this argument,
89     ///
90     /// fn foo<const N: usize>()
91     /// //           ^ returns this `DefId`.
92     ///
93     /// fn bar() {
94     /// // ^ While calling `opt_const_param_of` for other bodies returns `None`.
95     /// }
96     /// ```
97     // It looks like caching this query on disk actually slightly
98     // worsened performance in #74376.
99     //
100     // Once const generics are more prevalently used, we might want to
101     // consider only caching calls returning `Some`.
102     query opt_const_param_of(key: LocalDefId) -> Option<DefId> {
103         desc { |tcx| "computing the optional const parameter of `{}`", tcx.def_path_str(key.to_def_id()) }
104     }
105
106     /// Given the def_id of a const-generic parameter, computes the associated default const
107     /// parameter. e.g. `fn example<const N: usize=3>` called on `N` would return `3`.
108     query const_param_default(param: DefId) -> &'tcx ty::Const<'tcx> {
109         desc { |tcx| "compute const default for a given parameter `{}`", tcx.def_path_str(param)  }
110         separate_provide_extern
111     }
112
113     /// Records the type of every item.
114     query type_of(key: DefId) -> Ty<'tcx> {
115         desc { |tcx|
116             "{action} `{path}`",
117             action = {
118                 use rustc_hir::def::DefKind;
119                 match tcx.def_kind(key) {
120                     DefKind::TyAlias => "expanding type alias",
121                     DefKind::TraitAlias => "expanding trait alias",
122                     _ => "computing type of",
123                 }
124             },
125             path = tcx.def_path_str(key),
126         }
127         cache_on_disk_if { key.is_local() }
128         separate_provide_extern
129     }
130
131     query analysis(key: ()) -> Result<(), ErrorReported> {
132         eval_always
133         desc { "running analysis passes on this crate" }
134     }
135
136     /// Maps from the `DefId` of an item (trait/struct/enum/fn) to its
137     /// associated generics.
138     query generics_of(key: DefId) -> ty::Generics {
139         desc { |tcx| "computing generics of `{}`", tcx.def_path_str(key) }
140         storage(ArenaCacheSelector<'tcx>)
141         cache_on_disk_if { key.is_local() }
142         separate_provide_extern
143     }
144
145     /// Maps from the `DefId` of an item (trait/struct/enum/fn) to the
146     /// predicates (where-clauses) that must be proven true in order
147     /// to reference it. This is almost always the "predicates query"
148     /// that you want.
149     ///
150     /// `predicates_of` builds on `predicates_defined_on` -- in fact,
151     /// it is almost always the same as that query, except for the
152     /// case of traits. For traits, `predicates_of` contains
153     /// an additional `Self: Trait<...>` predicate that users don't
154     /// actually write. This reflects the fact that to invoke the
155     /// trait (e.g., via `Default::default`) you must supply types
156     /// that actually implement the trait. (However, this extra
157     /// predicate gets in the way of some checks, which are intended
158     /// to operate over only the actual where-clauses written by the
159     /// user.)
160     query predicates_of(key: DefId) -> ty::GenericPredicates<'tcx> {
161         desc { |tcx| "computing predicates of `{}`", tcx.def_path_str(key) }
162         cache_on_disk_if { key.is_local() }
163     }
164
165     /// Returns the list of bounds that can be used for
166     /// `SelectionCandidate::ProjectionCandidate(_)` and
167     /// `ProjectionTyCandidate::TraitDef`.
168     /// Specifically this is the bounds written on the trait's type
169     /// definition, or those after the `impl` keyword
170     ///
171     /// ```ignore (incomplete)
172     /// type X: Bound + 'lt
173     /// //      ^^^^^^^^^^^
174     /// impl Debug + Display
175     /// //   ^^^^^^^^^^^^^^^
176     /// ```
177     ///
178     /// `key` is the `DefId` of the associated type or opaque type.
179     ///
180     /// Bounds from the parent (e.g. with nested impl trait) are not included.
181     query explicit_item_bounds(key: DefId) -> &'tcx [(ty::Predicate<'tcx>, Span)] {
182         desc { |tcx| "finding item bounds for `{}`", tcx.def_path_str(key) }
183         separate_provide_extern
184     }
185
186     /// Elaborated version of the predicates from `explicit_item_bounds`.
187     ///
188     /// For example:
189     ///
190     /// ```
191     /// trait MyTrait {
192     ///     type MyAType: Eq + ?Sized;
193     /// }
194     /// ```
195     ///
196     /// `explicit_item_bounds` returns `[<Self as MyTrait>::MyAType: Eq]`,
197     /// and `item_bounds` returns
198     /// ```text
199     /// [
200     ///     <Self as Trait>::MyAType: Eq,
201     ///     <Self as Trait>::MyAType: PartialEq<<Self as Trait>::MyAType>
202     /// ]
203     /// ```
204     ///
205     /// Bounds from the parent (e.g. with nested impl trait) are not included.
206     query item_bounds(key: DefId) -> &'tcx ty::List<ty::Predicate<'tcx>> {
207         desc { |tcx| "elaborating item bounds for `{}`", tcx.def_path_str(key) }
208     }
209
210     query native_libraries(_: CrateNum) -> Lrc<Vec<NativeLib>> {
211         desc { "looking up the native libraries of a linked crate" }
212         separate_provide_extern
213     }
214
215     query lint_levels(_: ()) -> LintLevelMap {
216         storage(ArenaCacheSelector<'tcx>)
217         eval_always
218         desc { "computing the lint levels for items in this crate" }
219     }
220
221     query parent_module_from_def_id(key: LocalDefId) -> LocalDefId {
222         eval_always
223         desc { |tcx| "parent module of `{}`", tcx.def_path_str(key.to_def_id()) }
224     }
225
226     query expn_that_defined(key: DefId) -> rustc_span::ExpnId {
227         // This query reads from untracked data in definitions.
228         eval_always
229         desc { |tcx| "expansion that defined `{}`", tcx.def_path_str(key) }
230         separate_provide_extern
231     }
232
233     query is_panic_runtime(_: CrateNum) -> bool {
234         fatal_cycle
235         desc { "checking if the crate is_panic_runtime" }
236         separate_provide_extern
237     }
238
239     /// Fetch the THIR for a given body. If typeck for that body failed, returns an empty `Thir`.
240     query thir_body(key: ty::WithOptConstParam<LocalDefId>) -> (&'tcx Steal<thir::Thir<'tcx>>, thir::ExprId) {
241         // Perf tests revealed that hashing THIR is inefficient (see #85729).
242         no_hash
243         desc { |tcx| "building THIR for `{}`", tcx.def_path_str(key.did.to_def_id()) }
244     }
245
246     /// Create a THIR tree for debugging.
247     query thir_tree(key: ty::WithOptConstParam<LocalDefId>) -> String {
248         no_hash
249         desc { |tcx| "constructing THIR tree for `{}`", tcx.def_path_str(key.did.to_def_id()) }
250     }
251
252     /// Set of all the `DefId`s in this crate that have MIR associated with
253     /// them. This includes all the body owners, but also things like struct
254     /// constructors.
255     query mir_keys(_: ()) -> rustc_data_structures::fx::FxIndexSet<LocalDefId> {
256         storage(ArenaCacheSelector<'tcx>)
257         desc { "getting a list of all mir_keys" }
258     }
259
260     /// Maps DefId's that have an associated `mir::Body` to the result
261     /// of the MIR const-checking pass. This is the set of qualifs in
262     /// the final value of a `const`.
263     query mir_const_qualif(key: DefId) -> mir::ConstQualifs {
264         desc { |tcx| "const checking `{}`", tcx.def_path_str(key) }
265         cache_on_disk_if { key.is_local() }
266         separate_provide_extern
267     }
268     query mir_const_qualif_const_arg(
269         key: (LocalDefId, DefId)
270     ) -> mir::ConstQualifs {
271         desc {
272             |tcx| "const checking the const argument `{}`",
273             tcx.def_path_str(key.0.to_def_id())
274         }
275     }
276
277     /// Fetch the MIR for a given `DefId` right after it's built - this includes
278     /// unreachable code.
279     query mir_built(key: ty::WithOptConstParam<LocalDefId>) -> &'tcx Steal<mir::Body<'tcx>> {
280         desc { |tcx| "building MIR for `{}`", tcx.def_path_str(key.did.to_def_id()) }
281     }
282
283     /// Fetch the MIR for a given `DefId` up till the point where it is
284     /// ready for const qualification.
285     ///
286     /// See the README for the `mir` module for details.
287     query mir_const(key: ty::WithOptConstParam<LocalDefId>) -> &'tcx Steal<mir::Body<'tcx>> {
288         desc {
289             |tcx| "processing MIR for {}`{}`",
290             if key.const_param_did.is_some() { "the const argument " } else { "" },
291             tcx.def_path_str(key.did.to_def_id()),
292         }
293         no_hash
294     }
295
296     /// Try to build an abstract representation of the given constant.
297     query thir_abstract_const(
298         key: DefId
299     ) -> Result<Option<&'tcx [thir::abstract_const::Node<'tcx>]>, ErrorReported> {
300         desc {
301             |tcx| "building an abstract representation for {}", tcx.def_path_str(key),
302         }
303         separate_provide_extern
304     }
305     /// Try to build an abstract representation of the given constant.
306     query thir_abstract_const_of_const_arg(
307         key: (LocalDefId, DefId)
308     ) -> Result<Option<&'tcx [thir::abstract_const::Node<'tcx>]>, ErrorReported> {
309         desc {
310             |tcx|
311             "building an abstract representation for the const argument {}",
312             tcx.def_path_str(key.0.to_def_id()),
313         }
314     }
315
316     query try_unify_abstract_consts(key: (
317         ty::Unevaluated<'tcx, ()>, ty::Unevaluated<'tcx, ()>
318     )) -> bool {
319         desc {
320             |tcx| "trying to unify the generic constants {} and {}",
321             tcx.def_path_str(key.0.def.did), tcx.def_path_str(key.1.def.did)
322         }
323     }
324
325     query mir_drops_elaborated_and_const_checked(
326         key: ty::WithOptConstParam<LocalDefId>
327     ) -> &'tcx Steal<mir::Body<'tcx>> {
328         no_hash
329         desc { |tcx| "elaborating drops for `{}`", tcx.def_path_str(key.did.to_def_id()) }
330     }
331
332     query mir_for_ctfe(
333         key: DefId
334     ) -> &'tcx mir::Body<'tcx> {
335         desc { |tcx| "caching mir of `{}` for CTFE", tcx.def_path_str(key) }
336         cache_on_disk_if { key.is_local() }
337         separate_provide_extern
338     }
339
340     query mir_for_ctfe_of_const_arg(key: (LocalDefId, DefId)) -> &'tcx mir::Body<'tcx> {
341         desc {
342             |tcx| "MIR for CTFE of the const argument `{}`",
343             tcx.def_path_str(key.0.to_def_id())
344         }
345     }
346
347     query mir_promoted(key: ty::WithOptConstParam<LocalDefId>) ->
348         (
349             &'tcx Steal<mir::Body<'tcx>>,
350             &'tcx Steal<IndexVec<mir::Promoted, mir::Body<'tcx>>>
351         ) {
352         no_hash
353         desc {
354             |tcx| "processing {}`{}`",
355             if key.const_param_did.is_some() { "the const argument " } else { "" },
356             tcx.def_path_str(key.did.to_def_id()),
357         }
358     }
359
360     query symbols_for_closure_captures(
361         key: (LocalDefId, DefId)
362     ) -> Vec<rustc_span::Symbol> {
363         desc {
364             |tcx| "symbols for captures of closure `{}` in `{}`",
365             tcx.def_path_str(key.1),
366             tcx.def_path_str(key.0.to_def_id())
367         }
368     }
369
370     /// MIR after our optimization passes have run. This is MIR that is ready
371     /// for codegen. This is also the only query that can fetch non-local MIR, at present.
372     query optimized_mir(key: DefId) -> &'tcx mir::Body<'tcx> {
373         desc { |tcx| "optimizing MIR for `{}`", tcx.def_path_str(key) }
374         cache_on_disk_if { key.is_local() }
375         separate_provide_extern
376     }
377
378     /// Returns coverage summary info for a function, after executing the `InstrumentCoverage`
379     /// MIR pass (assuming the -Zinstrument-coverage option is enabled).
380     query coverageinfo(key: ty::InstanceDef<'tcx>) -> mir::CoverageInfo {
381         desc { |tcx| "retrieving coverage info from MIR for `{}`", tcx.def_path_str(key.def_id()) }
382         storage(ArenaCacheSelector<'tcx>)
383     }
384
385     /// Returns the `CodeRegions` for a function that has instrumented coverage, in case the
386     /// function was optimized out before codegen, and before being added to the Coverage Map.
387     query covered_code_regions(key: DefId) -> Vec<&'tcx mir::coverage::CodeRegion> {
388         desc {
389             |tcx| "retrieving the covered `CodeRegion`s, if instrumented, for `{}`",
390             tcx.def_path_str(key)
391         }
392         storage(ArenaCacheSelector<'tcx>)
393         cache_on_disk_if { key.is_local() }
394     }
395
396     /// The `DefId` is the `DefId` of the containing MIR body. Promoteds do not have their own
397     /// `DefId`. This function returns all promoteds in the specified body. The body references
398     /// promoteds by the `DefId` and the `mir::Promoted` index. This is necessary, because
399     /// after inlining a body may refer to promoteds from other bodies. In that case you still
400     /// need to use the `DefId` of the original body.
401     query promoted_mir(key: DefId) -> &'tcx IndexVec<mir::Promoted, mir::Body<'tcx>> {
402         desc { |tcx| "optimizing promoted MIR for `{}`", tcx.def_path_str(key) }
403         cache_on_disk_if { key.is_local() }
404         separate_provide_extern
405     }
406     query promoted_mir_of_const_arg(
407         key: (LocalDefId, DefId)
408     ) -> &'tcx IndexVec<mir::Promoted, mir::Body<'tcx>> {
409         desc {
410             |tcx| "optimizing promoted MIR for the const argument `{}`",
411             tcx.def_path_str(key.0.to_def_id()),
412         }
413     }
414
415     /// Erases regions from `ty` to yield a new type.
416     /// Normally you would just use `tcx.erase_regions(value)`,
417     /// however, which uses this query as a kind of cache.
418     query erase_regions_ty(ty: Ty<'tcx>) -> Ty<'tcx> {
419         // This query is not expected to have input -- as a result, it
420         // is not a good candidates for "replay" because it is essentially a
421         // pure function of its input (and hence the expectation is that
422         // no caller would be green **apart** from just these
423         // queries). Making it anonymous avoids hashing the result, which
424         // may save a bit of time.
425         anon
426         desc { "erasing regions from `{:?}`", ty }
427     }
428
429     query wasm_import_module_map(_: CrateNum) -> FxHashMap<DefId, String> {
430         storage(ArenaCacheSelector<'tcx>)
431         desc { "wasm import module map" }
432     }
433
434     /// Maps from the `DefId` of an item (trait/struct/enum/fn) to the
435     /// predicates (where-clauses) directly defined on it. This is
436     /// equal to the `explicit_predicates_of` predicates plus the
437     /// `inferred_outlives_of` predicates.
438     query predicates_defined_on(key: DefId) -> ty::GenericPredicates<'tcx> {
439         desc { |tcx| "computing predicates of `{}`", tcx.def_path_str(key) }
440     }
441
442     /// Returns everything that looks like a predicate written explicitly
443     /// by the user on a trait item.
444     ///
445     /// Traits are unusual, because predicates on associated types are
446     /// converted into bounds on that type for backwards compatibility:
447     ///
448     /// trait X where Self::U: Copy { type U; }
449     ///
450     /// becomes
451     ///
452     /// trait X { type U: Copy; }
453     ///
454     /// `explicit_predicates_of` and `explicit_item_bounds` will then take
455     /// the appropriate subsets of the predicates here.
456     query trait_explicit_predicates_and_bounds(key: LocalDefId) -> ty::GenericPredicates<'tcx> {
457         desc { |tcx| "computing explicit predicates of trait `{}`", tcx.def_path_str(key.to_def_id()) }
458     }
459
460     /// Returns the predicates written explicitly by the user.
461     query explicit_predicates_of(key: DefId) -> ty::GenericPredicates<'tcx> {
462         desc { |tcx| "computing explicit predicates of `{}`", tcx.def_path_str(key) }
463         separate_provide_extern
464     }
465
466     /// Returns the inferred outlives predicates (e.g., for `struct
467     /// Foo<'a, T> { x: &'a T }`, this would return `T: 'a`).
468     query inferred_outlives_of(key: DefId) -> &'tcx [(ty::Predicate<'tcx>, Span)] {
469         desc { |tcx| "computing inferred outlives predicates of `{}`", tcx.def_path_str(key) }
470         separate_provide_extern
471     }
472
473     /// Maps from the `DefId` of a trait to the list of
474     /// super-predicates. This is a subset of the full list of
475     /// predicates. We store these in a separate map because we must
476     /// evaluate them even during type conversion, often before the
477     /// full predicates are available (note that supertraits have
478     /// additional acyclicity requirements).
479     query super_predicates_of(key: DefId) -> ty::GenericPredicates<'tcx> {
480         desc { |tcx| "computing the super predicates of `{}`", tcx.def_path_str(key) }
481         separate_provide_extern
482     }
483
484     /// The `Option<Ident>` is the name of an associated type. If it is `None`, then this query
485     /// returns the full set of predicates. If `Some<Ident>`, then the query returns only the
486     /// subset of super-predicates that reference traits that define the given associated type.
487     /// This is used to avoid cycles in resolving types like `T::Item`.
488     query super_predicates_that_define_assoc_type(key: (DefId, Option<rustc_span::symbol::Ident>)) -> ty::GenericPredicates<'tcx> {
489         desc { |tcx| "computing the super traits of `{}`{}",
490             tcx.def_path_str(key.0),
491             if let Some(assoc_name) = key.1 { format!(" with associated type name `{}`", assoc_name) } else { "".to_string() },
492         }
493     }
494
495     /// To avoid cycles within the predicates of a single item we compute
496     /// per-type-parameter predicates for resolving `T::AssocTy`.
497     query type_param_predicates(key: (DefId, LocalDefId, rustc_span::symbol::Ident)) -> ty::GenericPredicates<'tcx> {
498         desc { |tcx| "computing the bounds for type parameter `{}`", {
499             let id = tcx.hir().local_def_id_to_hir_id(key.1);
500             tcx.hir().ty_param_name(id)
501         }}
502     }
503
504     query trait_def(key: DefId) -> ty::TraitDef {
505         desc { |tcx| "computing trait definition for `{}`", tcx.def_path_str(key) }
506         storage(ArenaCacheSelector<'tcx>)
507         separate_provide_extern
508     }
509     query adt_def(key: DefId) -> &'tcx ty::AdtDef {
510         desc { |tcx| "computing ADT definition for `{}`", tcx.def_path_str(key) }
511         cache_on_disk_if { key.is_local() }
512         separate_provide_extern
513     }
514     query adt_destructor(key: DefId) -> Option<ty::Destructor> {
515         desc { |tcx| "computing `Drop` impl for `{}`", tcx.def_path_str(key) }
516         separate_provide_extern
517     }
518
519     // The cycle error here should be reported as an error by `check_representable`.
520     // We consider the type as Sized in the meanwhile to avoid
521     // further errors (done in impl Value for AdtSizedConstraint).
522     // Use `cycle_delay_bug` to delay the cycle error here to be emitted later
523     // in case we accidentally otherwise don't emit an error.
524     query adt_sized_constraint(
525         key: DefId
526     ) -> AdtSizedConstraint<'tcx> {
527         desc { |tcx| "computing `Sized` constraints for `{}`", tcx.def_path_str(key) }
528         cycle_delay_bug
529     }
530
531     query adt_dtorck_constraint(
532         key: DefId
533     ) -> Result<DtorckConstraint<'tcx>, NoSolution> {
534         desc { |tcx| "computing drop-check constraints for `{}`", tcx.def_path_str(key) }
535     }
536
537     /// Returns `true` if this is a const fn, use the `is_const_fn` to know whether your crate
538     /// actually sees it as const fn (e.g., the const-fn-ness might be unstable and you might
539     /// not have the feature gate active).
540     ///
541     /// **Do not call this function manually.** It is only meant to cache the base data for the
542     /// `is_const_fn` function.
543     query is_const_fn_raw(key: DefId) -> bool {
544         desc { |tcx| "checking if item is const fn: `{}`", tcx.def_path_str(key) }
545         separate_provide_extern
546     }
547
548     query asyncness(key: DefId) -> hir::IsAsync {
549         desc { |tcx| "checking if the function is async: `{}`", tcx.def_path_str(key) }
550         separate_provide_extern
551     }
552
553     /// Returns `true` if calls to the function may be promoted.
554     ///
555     /// This is either because the function is e.g., a tuple-struct or tuple-variant
556     /// constructor, or because it has the `#[rustc_promotable]` attribute. The attribute should
557     /// be removed in the future in favour of some form of check which figures out whether the
558     /// function does not inspect the bits of any of its arguments (so is essentially just a
559     /// constructor function).
560     query is_promotable_const_fn(key: DefId) -> bool {
561         desc { |tcx| "checking if item is promotable: `{}`", tcx.def_path_str(key) }
562     }
563
564     /// Returns `true` if this is a foreign item (i.e., linked via `extern { ... }`).
565     query is_foreign_item(key: DefId) -> bool {
566         desc { |tcx| "checking if `{}` is a foreign item", tcx.def_path_str(key) }
567         separate_provide_extern
568     }
569
570     /// Returns `Some(mutability)` if the node pointed to by `def_id` is a static item.
571     query static_mutability(def_id: DefId) -> Option<hir::Mutability> {
572         desc { |tcx| "looking up static mutability of `{}`", tcx.def_path_str(def_id) }
573         separate_provide_extern
574     }
575
576     /// Returns `Some(generator_kind)` if the node pointed to by `def_id` is a generator.
577     query generator_kind(def_id: DefId) -> Option<hir::GeneratorKind> {
578         desc { |tcx| "looking up generator kind of `{}`", tcx.def_path_str(def_id) }
579         separate_provide_extern
580     }
581
582     /// Gets a map with the variance of every item; use `item_variance` instead.
583     query crate_variances(_: ()) -> ty::CrateVariancesMap<'tcx> {
584         storage(ArenaCacheSelector<'tcx>)
585         desc { "computing the variances for items in this crate" }
586     }
587
588     /// Maps from the `DefId` of a type or region parameter to its (inferred) variance.
589     query variances_of(def_id: DefId) -> &'tcx [ty::Variance] {
590         desc { |tcx| "computing the variances of `{}`", tcx.def_path_str(def_id) }
591         separate_provide_extern
592     }
593
594     /// Maps from thee `DefId` of a type to its (inferred) outlives.
595     query inferred_outlives_crate(_: ()) -> ty::CratePredicatesMap<'tcx> {
596         storage(ArenaCacheSelector<'tcx>)
597         desc { "computing the inferred outlives predicates for items in this crate" }
598     }
599
600     /// Maps from an impl/trait `DefId` to a list of the `DefId`s of its items.
601     query associated_item_def_ids(key: DefId) -> &'tcx [DefId] {
602         desc { |tcx| "collecting associated items of `{}`", tcx.def_path_str(key) }
603         separate_provide_extern
604     }
605
606     /// Maps from a trait item to the trait item "descriptor".
607     query associated_item(key: DefId) -> ty::AssocItem {
608         desc { |tcx| "computing associated item data for `{}`", tcx.def_path_str(key) }
609         storage(ArenaCacheSelector<'tcx>)
610         separate_provide_extern
611     }
612
613     /// Collects the associated items defined on a trait or impl.
614     query associated_items(key: DefId) -> ty::AssocItems<'tcx> {
615         storage(ArenaCacheSelector<'tcx>)
616         desc { |tcx| "collecting associated items of {}", tcx.def_path_str(key) }
617     }
618
619     /// Maps from associated items on a trait to the corresponding associated
620     /// item on the impl specified by `impl_id`.
621     ///
622     /// For example, with the following code
623     ///
624     /// ```
625     /// struct Type {}
626     ///                         // DefId
627     /// trait Trait {           // trait_id
628     ///     fn f();             // trait_f
629     ///     fn g() {}           // trait_g
630     /// }
631     ///
632     /// impl Trait for Type {   // impl_id
633     ///     fn f() {}           // impl_f
634     ///     fn g() {}           // impl_g
635     /// }
636     /// ```
637     ///
638     /// The map returned for `tcx.impl_item_implementor_ids(impl_id)` would be
639     ///`{ trait_f: impl_f, trait_g: impl_g }`
640     query impl_item_implementor_ids(impl_id: DefId) -> FxHashMap<DefId, DefId> {
641         desc { |tcx| "comparing impl items against trait for {}", tcx.def_path_str(impl_id) }
642         storage(ArenaCacheSelector<'tcx>)
643     }
644
645     /// Given an `impl_id`, return the trait it implements.
646     /// Return `None` if this is an inherent impl.
647     query impl_trait_ref(impl_id: DefId) -> Option<ty::TraitRef<'tcx>> {
648         desc { |tcx| "computing trait implemented by `{}`", tcx.def_path_str(impl_id) }
649         separate_provide_extern
650     }
651     query impl_polarity(impl_id: DefId) -> ty::ImplPolarity {
652         desc { |tcx| "computing implementation polarity of `{}`", tcx.def_path_str(impl_id) }
653         separate_provide_extern
654     }
655
656     query issue33140_self_ty(key: DefId) -> Option<ty::Ty<'tcx>> {
657         desc { |tcx| "computing Self type wrt issue #33140 `{}`", tcx.def_path_str(key) }
658     }
659
660     /// Maps a `DefId` of a type to a list of its inherent impls.
661     /// Contains implementations of methods that are inherent to a type.
662     /// Methods in these implementations don't need to be exported.
663     query inherent_impls(key: DefId) -> &'tcx [DefId] {
664         desc { |tcx| "collecting inherent impls for `{}`", tcx.def_path_str(key) }
665         separate_provide_extern
666     }
667
668     /// The result of unsafety-checking this `LocalDefId`.
669     query unsafety_check_result(key: LocalDefId) -> &'tcx mir::UnsafetyCheckResult {
670         desc { |tcx| "unsafety-checking `{}`", tcx.def_path_str(key.to_def_id()) }
671         cache_on_disk_if { true }
672     }
673     query unsafety_check_result_for_const_arg(key: (LocalDefId, DefId)) -> &'tcx mir::UnsafetyCheckResult {
674         desc {
675             |tcx| "unsafety-checking the const argument `{}`",
676             tcx.def_path_str(key.0.to_def_id())
677         }
678     }
679
680     /// Unsafety-check this `LocalDefId` with THIR unsafeck. This should be
681     /// used with `-Zthir-unsafeck`.
682     query thir_check_unsafety(key: LocalDefId) {
683         desc { |tcx| "unsafety-checking `{}`", tcx.def_path_str(key.to_def_id()) }
684         cache_on_disk_if { true }
685     }
686     query thir_check_unsafety_for_const_arg(key: (LocalDefId, DefId)) {
687         desc {
688             |tcx| "unsafety-checking the const argument `{}`",
689             tcx.def_path_str(key.0.to_def_id())
690         }
691     }
692
693     /// HACK: when evaluated, this reports an "unsafe derive on repr(packed)" error.
694     ///
695     /// Unsafety checking is executed for each method separately, but we only want
696     /// to emit this error once per derive. As there are some impls with multiple
697     /// methods, we use a query for deduplication.
698     query unsafe_derive_on_repr_packed(key: LocalDefId) -> () {
699         desc { |tcx| "processing `{}`", tcx.def_path_str(key.to_def_id()) }
700     }
701
702     /// Computes the signature of the function.
703     query fn_sig(key: DefId) -> ty::PolyFnSig<'tcx> {
704         desc { |tcx| "computing function signature of `{}`", tcx.def_path_str(key) }
705         separate_provide_extern
706     }
707
708     /// Performs lint checking for the module.
709     query lint_mod(key: LocalDefId) -> () {
710         desc { |tcx| "linting {}", describe_as_module(key, tcx) }
711     }
712
713     /// Checks the attributes in the module.
714     query check_mod_attrs(key: LocalDefId) -> () {
715         desc { |tcx| "checking attributes in {}", describe_as_module(key, tcx) }
716     }
717
718     /// Checks for uses of unstable APIs in the module.
719     query check_mod_unstable_api_usage(key: LocalDefId) -> () {
720         desc { |tcx| "checking for unstable API usage in {}", describe_as_module(key, tcx) }
721     }
722
723     /// Checks the const bodies in the module for illegal operations (e.g. `if` or `loop`).
724     query check_mod_const_bodies(key: LocalDefId) -> () {
725         desc { |tcx| "checking consts in {}", describe_as_module(key, tcx) }
726     }
727
728     /// Checks the loops in the module.
729     query check_mod_loops(key: LocalDefId) -> () {
730         desc { |tcx| "checking loops in {}", describe_as_module(key, tcx) }
731     }
732
733     query check_mod_naked_functions(key: LocalDefId) -> () {
734         desc { |tcx| "checking naked functions in {}", describe_as_module(key, tcx) }
735     }
736
737     query check_mod_item_types(key: LocalDefId) -> () {
738         desc { |tcx| "checking item types in {}", describe_as_module(key, tcx) }
739     }
740
741     query check_mod_privacy(key: LocalDefId) -> () {
742         desc { |tcx| "checking privacy in {}", describe_as_module(key, tcx) }
743     }
744
745     query check_mod_intrinsics(key: LocalDefId) -> () {
746         desc { |tcx| "checking intrinsics in {}", describe_as_module(key, tcx) }
747     }
748
749     query check_mod_liveness(key: LocalDefId) -> () {
750         desc { |tcx| "checking liveness of variables in {}", describe_as_module(key, tcx) }
751     }
752
753     /// Return the live symbols in the crate for dead code check.
754     ///
755     /// The second return value maps from ADTs to ignored derived traits (e.g. Debug and Clone) and
756     /// their respective impl (i.e., part of the derive macro)
757     query live_symbols_and_ignored_derived_traits(_: ()) -> (
758         FxHashSet<LocalDefId>,
759         FxHashMap<LocalDefId, Vec<(DefId, DefId)>>
760     ) {
761         storage(ArenaCacheSelector<'tcx>)
762         desc { "find live symbols in crate" }
763     }
764
765     query check_mod_deathness(key: LocalDefId) -> () {
766         desc { |tcx| "checking deathness of variables in {}", describe_as_module(key, tcx) }
767     }
768
769     query check_mod_impl_wf(key: LocalDefId) -> () {
770         desc { |tcx| "checking that impls are well-formed in {}", describe_as_module(key, tcx) }
771     }
772
773     query collect_mod_item_types(key: LocalDefId) -> () {
774         desc { |tcx| "collecting item types in {}", describe_as_module(key, tcx) }
775     }
776
777     /// Caches `CoerceUnsized` kinds for impls on custom types.
778     query coerce_unsized_info(key: DefId) -> ty::adjustment::CoerceUnsizedInfo {
779         desc { |tcx| "computing CoerceUnsized info for `{}`", tcx.def_path_str(key) }
780         separate_provide_extern
781     }
782
783     query typeck_item_bodies(_: ()) -> () {
784         desc { "type-checking all item bodies" }
785     }
786
787     query typeck(key: LocalDefId) -> &'tcx ty::TypeckResults<'tcx> {
788         desc { |tcx| "type-checking `{}`", tcx.def_path_str(key.to_def_id()) }
789         cache_on_disk_if { true }
790     }
791     query typeck_const_arg(
792         key: (LocalDefId, DefId)
793     ) -> &'tcx ty::TypeckResults<'tcx> {
794         desc {
795             |tcx| "type-checking the const argument `{}`",
796             tcx.def_path_str(key.0.to_def_id()),
797         }
798     }
799     query diagnostic_only_typeck(key: LocalDefId) -> &'tcx ty::TypeckResults<'tcx> {
800         desc { |tcx| "type-checking `{}`", tcx.def_path_str(key.to_def_id()) }
801         cache_on_disk_if { true }
802         load_cached(tcx, id) {
803             #[cfg(bootstrap)]
804             {
805                 match match tcx.on_disk_cache().as_ref() {
806                     Some(c) => c.try_load_query_result(*tcx, id),
807                     None => None,
808                 } {
809                     Some(x) => Some(&*tcx.arena.alloc(x)),
810                     None => None,
811                 }
812             }
813             #[cfg(not(bootstrap))]
814             {
815                 let typeck_results: Option<ty::TypeckResults<'tcx>> = tcx
816                     .on_disk_cache().as_ref()
817                     .and_then(|c| c.try_load_query_result(*tcx, id));
818
819                 typeck_results.map(|x| &*tcx.arena.alloc(x))
820             }
821         }
822     }
823
824     query used_trait_imports(key: LocalDefId) -> &'tcx FxHashSet<LocalDefId> {
825         desc { |tcx| "used_trait_imports `{}`", tcx.def_path_str(key.to_def_id()) }
826         cache_on_disk_if { true }
827     }
828
829     query has_typeck_results(def_id: DefId) -> bool {
830         desc { |tcx| "checking whether `{}` has a body", tcx.def_path_str(def_id) }
831     }
832
833     query coherent_trait(def_id: DefId) -> () {
834         desc { |tcx| "coherence checking all impls of trait `{}`", tcx.def_path_str(def_id) }
835     }
836
837     /// Borrow-checks the function body. If this is a closure, returns
838     /// additional requirements that the closure's creator must verify.
839     query mir_borrowck(key: LocalDefId) -> &'tcx mir::BorrowCheckResult<'tcx> {
840         desc { |tcx| "borrow-checking `{}`", tcx.def_path_str(key.to_def_id()) }
841         cache_on_disk_if(tcx) { tcx.is_typeck_child(key.to_def_id()) }
842     }
843     query mir_borrowck_const_arg(key: (LocalDefId, DefId)) -> &'tcx mir::BorrowCheckResult<'tcx> {
844         desc {
845             |tcx| "borrow-checking the const argument`{}`",
846             tcx.def_path_str(key.0.to_def_id())
847         }
848     }
849
850     /// Gets a complete map from all types to their inherent impls.
851     /// Not meant to be used directly outside of coherence.
852     query crate_inherent_impls(k: ()) -> CrateInherentImpls {
853         storage(ArenaCacheSelector<'tcx>)
854         desc { "all inherent impls defined in crate" }
855     }
856
857     /// Checks all types in the crate for overlap in their inherent impls. Reports errors.
858     /// Not meant to be used directly outside of coherence.
859     query crate_inherent_impls_overlap_check(_: ()) -> () {
860         desc { "check for overlap between inherent impls defined in this crate" }
861     }
862
863     /// Checks whether all impls in the crate pass the overlap check, returning
864     /// which impls fail it. If all impls are correct, the returned slice is empty.
865     query orphan_check_crate(_: ()) -> &'tcx [LocalDefId] {
866         desc {
867             "checking whether the immpl in the this crate follow the orphan rules",
868         }
869     }
870
871     /// Check whether the function has any recursion that could cause the inliner to trigger
872     /// a cycle. Returns the call stack causing the cycle. The call stack does not contain the
873     /// current function, just all intermediate functions.
874     query mir_callgraph_reachable(key: (ty::Instance<'tcx>, LocalDefId)) -> bool {
875         fatal_cycle
876         desc { |tcx|
877             "computing if `{}` (transitively) calls `{}`",
878             key.0,
879             tcx.def_path_str(key.1.to_def_id()),
880         }
881     }
882
883     /// Obtain all the calls into other local functions
884     query mir_inliner_callees(key: ty::InstanceDef<'tcx>) -> &'tcx [(DefId, SubstsRef<'tcx>)] {
885         fatal_cycle
886         desc { |tcx|
887             "computing all local function calls in `{}`",
888             tcx.def_path_str(key.def_id()),
889         }
890     }
891
892     /// Evaluates a constant and returns the computed allocation.
893     ///
894     /// **Do not use this** directly, use the `tcx.eval_static_initializer` wrapper.
895     query eval_to_allocation_raw(key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>)
896         -> EvalToAllocationRawResult<'tcx> {
897         desc { |tcx|
898             "const-evaluating + checking `{}`",
899             key.value.display(tcx)
900         }
901         cache_on_disk_if { true }
902     }
903
904     /// Evaluates const items or anonymous constants
905     /// (such as enum variant explicit discriminants or array lengths)
906     /// into a representation suitable for the type system and const generics.
907     ///
908     /// **Do not use this** directly, use one of the following wrappers: `tcx.const_eval_poly`,
909     /// `tcx.const_eval_resolve`, `tcx.const_eval_instance`, or `tcx.const_eval_global_id`.
910     query eval_to_const_value_raw(key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>)
911         -> EvalToConstValueResult<'tcx> {
912         desc { |tcx|
913             "simplifying constant for the type system `{}`",
914             key.value.display(tcx)
915         }
916         cache_on_disk_if { true }
917     }
918
919     /// Convert an evaluated constant to a type level constant or
920     /// return `None` if that is not possible.
921     query const_to_valtree(
922         key: ty::ParamEnvAnd<'tcx, ConstAlloc<'tcx>>
923     ) -> Option<ty::ValTree<'tcx>> {
924         desc { "destructure constant" }
925         remap_env_constness
926     }
927
928     /// Destructure a constant ADT or array into its variant index and its
929     /// field values.
930     query destructure_const(
931         key: ty::ParamEnvAnd<'tcx, &'tcx ty::Const<'tcx>>
932     ) -> mir::DestructuredConst<'tcx> {
933         desc { "destructure constant" }
934         remap_env_constness
935     }
936
937     /// Dereference a constant reference or raw pointer and turn the result into a constant
938     /// again.
939     query deref_const(
940         key: ty::ParamEnvAnd<'tcx, &'tcx ty::Const<'tcx>>
941     ) -> &'tcx ty::Const<'tcx> {
942         desc { "deref constant" }
943         remap_env_constness
944     }
945
946     query const_caller_location(key: (rustc_span::Symbol, u32, u32)) -> ConstValue<'tcx> {
947         desc { "get a &core::panic::Location referring to a span" }
948     }
949
950     query lit_to_const(
951         key: LitToConstInput<'tcx>
952     ) -> Result<&'tcx ty::Const<'tcx>, LitToConstError> {
953         desc { "converting literal to const" }
954     }
955
956     query check_match(key: DefId) {
957         desc { |tcx| "match-checking `{}`", tcx.def_path_str(key) }
958         cache_on_disk_if { key.is_local() }
959     }
960
961     /// Performs part of the privacy check and computes "access levels".
962     query privacy_access_levels(_: ()) -> &'tcx AccessLevels {
963         eval_always
964         desc { "privacy access levels" }
965     }
966     query check_private_in_public(_: ()) -> () {
967         eval_always
968         desc { "checking for private elements in public interfaces" }
969     }
970
971     query reachable_set(_: ()) -> FxHashSet<LocalDefId> {
972         storage(ArenaCacheSelector<'tcx>)
973         desc { "reachability" }
974     }
975
976     /// Per-body `region::ScopeTree`. The `DefId` should be the owner `DefId` for the body;
977     /// in the case of closures, this will be redirected to the enclosing function.
978     query region_scope_tree(def_id: DefId) -> &'tcx region::ScopeTree {
979         desc { |tcx| "computing drop scopes for `{}`", tcx.def_path_str(def_id) }
980     }
981
982     /// Generates a MIR body for the shim.
983     query mir_shims(key: ty::InstanceDef<'tcx>) -> mir::Body<'tcx> {
984         storage(ArenaCacheSelector<'tcx>)
985         desc { |tcx| "generating MIR shim for `{}`", tcx.def_path_str(key.def_id()) }
986     }
987
988     /// The `symbol_name` query provides the symbol name for calling a
989     /// given instance from the local crate. In particular, it will also
990     /// look up the correct symbol name of instances from upstream crates.
991     query symbol_name(key: ty::Instance<'tcx>) -> ty::SymbolName<'tcx> {
992         desc { "computing the symbol for `{}`", key }
993         cache_on_disk_if { true }
994     }
995
996     query opt_def_kind(def_id: DefId) -> Option<DefKind> {
997         desc { |tcx| "looking up definition kind of `{}`", tcx.def_path_str(def_id) }
998         separate_provide_extern
999     }
1000
1001     /// Gets the span for the definition.
1002     query def_span(def_id: DefId) -> Span {
1003         desc { |tcx| "looking up span for `{}`", tcx.def_path_str(def_id) }
1004         separate_provide_extern
1005     }
1006
1007     /// Gets the span for the identifier of the definition.
1008     query def_ident_span(def_id: DefId) -> Option<Span> {
1009         desc { |tcx| "looking up span for `{}`'s identifier", tcx.def_path_str(def_id) }
1010         separate_provide_extern
1011     }
1012
1013     query lookup_stability(def_id: DefId) -> Option<&'tcx attr::Stability> {
1014         desc { |tcx| "looking up stability of `{}`", tcx.def_path_str(def_id) }
1015         separate_provide_extern
1016     }
1017
1018     query lookup_const_stability(def_id: DefId) -> Option<&'tcx attr::ConstStability> {
1019         desc { |tcx| "looking up const stability of `{}`", tcx.def_path_str(def_id) }
1020         separate_provide_extern
1021     }
1022
1023     query should_inherit_track_caller(def_id: DefId) -> bool {
1024         desc { |tcx| "computing should_inherit_track_caller of `{}`", tcx.def_path_str(def_id) }
1025     }
1026
1027     query lookup_deprecation_entry(def_id: DefId) -> Option<DeprecationEntry> {
1028         desc { |tcx| "checking whether `{}` is deprecated", tcx.def_path_str(def_id) }
1029         separate_provide_extern
1030     }
1031
1032     query item_attrs(def_id: DefId) -> &'tcx [ast::Attribute] {
1033         desc { |tcx| "collecting attributes of `{}`", tcx.def_path_str(def_id) }
1034         separate_provide_extern
1035     }
1036
1037     query codegen_fn_attrs(def_id: DefId) -> CodegenFnAttrs {
1038         desc { |tcx| "computing codegen attributes of `{}`", tcx.def_path_str(def_id) }
1039         storage(ArenaCacheSelector<'tcx>)
1040         cache_on_disk_if { true }
1041     }
1042
1043     query fn_arg_names(def_id: DefId) -> &'tcx [rustc_span::symbol::Ident] {
1044         desc { |tcx| "looking up function parameter names for `{}`", tcx.def_path_str(def_id) }
1045         separate_provide_extern
1046     }
1047     /// Gets the rendered value of the specified constant or associated constant.
1048     /// Used by rustdoc.
1049     query rendered_const(def_id: DefId) -> String {
1050         desc { |tcx| "rendering constant intializer of `{}`", tcx.def_path_str(def_id) }
1051         separate_provide_extern
1052     }
1053     query impl_parent(def_id: DefId) -> Option<DefId> {
1054         desc { |tcx| "computing specialization parent impl of `{}`", tcx.def_path_str(def_id) }
1055         separate_provide_extern
1056     }
1057
1058     /// Given an `associated_item`, find the trait it belongs to.
1059     /// Return `None` if the `DefId` is not an associated item.
1060     query trait_of_item(associated_item: DefId) -> Option<DefId> {
1061         desc { |tcx| "finding trait defining `{}`", tcx.def_path_str(associated_item) }
1062         separate_provide_extern
1063     }
1064
1065     query is_ctfe_mir_available(key: DefId) -> bool {
1066         desc { |tcx| "checking if item has ctfe mir available: `{}`", tcx.def_path_str(key) }
1067         separate_provide_extern
1068     }
1069     query is_mir_available(key: DefId) -> bool {
1070         desc { |tcx| "checking if item has mir available: `{}`", tcx.def_path_str(key) }
1071         separate_provide_extern
1072     }
1073
1074     query own_existential_vtable_entries(
1075         key: ty::PolyExistentialTraitRef<'tcx>
1076     ) -> &'tcx [DefId] {
1077         desc { |tcx| "finding all existential vtable entries for trait {}", tcx.def_path_str(key.def_id()) }
1078     }
1079
1080     query vtable_entries(key: ty::PolyTraitRef<'tcx>)
1081                         -> &'tcx [ty::VtblEntry<'tcx>] {
1082         desc { |tcx| "finding all vtable entries for trait {}", tcx.def_path_str(key.def_id()) }
1083     }
1084
1085     query vtable_trait_upcasting_coercion_new_vptr_slot(key: (ty::Ty<'tcx>, ty::Ty<'tcx>)) -> Option<usize> {
1086         desc { |tcx| "finding the slot within vtable for trait object {} vtable ptr during trait upcasting coercion from {} vtable",
1087             key.1, key.0 }
1088     }
1089
1090     query vtable_allocation(key: (Ty<'tcx>, Option<ty::PolyExistentialTraitRef<'tcx>>)) -> mir::interpret::AllocId {
1091         desc { |tcx| "vtable const allocation for <{} as {}>",
1092             key.0,
1093             key.1.map(|trait_ref| format!("{}", trait_ref)).unwrap_or("_".to_owned())
1094         }
1095     }
1096
1097     query codegen_fulfill_obligation(
1098         key: (ty::ParamEnv<'tcx>, ty::PolyTraitRef<'tcx>)
1099     ) -> Result<ImplSource<'tcx, ()>, ErrorReported> {
1100         cache_on_disk_if { true }
1101         desc { |tcx|
1102             "checking if `{}` fulfills its obligations",
1103             tcx.def_path_str(key.1.def_id())
1104         }
1105     }
1106
1107     /// Return all `impl` blocks in the current crate.
1108     query all_local_trait_impls(_: ()) -> &'tcx BTreeMap<DefId, Vec<LocalDefId>> {
1109         desc { "local trait impls" }
1110     }
1111
1112     /// Given a trait `trait_id`, return all known `impl` blocks.
1113     query trait_impls_of(trait_id: DefId) -> ty::trait_def::TraitImpls {
1114         storage(ArenaCacheSelector<'tcx>)
1115         desc { |tcx| "trait impls of `{}`", tcx.def_path_str(trait_id) }
1116     }
1117
1118     query specialization_graph_of(trait_id: DefId) -> specialization_graph::Graph {
1119         storage(ArenaCacheSelector<'tcx>)
1120         desc { |tcx| "building specialization graph of trait `{}`", tcx.def_path_str(trait_id) }
1121         cache_on_disk_if { true }
1122     }
1123     query object_safety_violations(trait_id: DefId) -> &'tcx [traits::ObjectSafetyViolation] {
1124         desc { |tcx| "determine object safety of trait `{}`", tcx.def_path_str(trait_id) }
1125     }
1126
1127     /// Gets the ParameterEnvironment for a given item; this environment
1128     /// will be in "user-facing" mode, meaning that it is suitable for
1129     /// type-checking etc, and it does not normalize specializable
1130     /// associated types. This is almost always what you want,
1131     /// unless you are doing MIR optimizations, in which case you
1132     /// might want to use `reveal_all()` method to change modes.
1133     query param_env(def_id: DefId) -> ty::ParamEnv<'tcx> {
1134         desc { |tcx| "computing normalized predicates of `{}`", tcx.def_path_str(def_id) }
1135     }
1136
1137     /// Like `param_env`, but returns the `ParamEnv` in `Reveal::All` mode.
1138     /// Prefer this over `tcx.param_env(def_id).with_reveal_all_normalized(tcx)`,
1139     /// as this method is more efficient.
1140     query param_env_reveal_all_normalized(def_id: DefId) -> ty::ParamEnv<'tcx> {
1141         desc { |tcx| "computing revealed normalized predicates of `{}`", tcx.def_path_str(def_id) }
1142     }
1143
1144     /// Trait selection queries. These are best used by invoking `ty.is_copy_modulo_regions()`,
1145     /// `ty.is_copy()`, etc, since that will prune the environment where possible.
1146     query is_copy_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1147         desc { "computing whether `{}` is `Copy`", env.value }
1148         remap_env_constness
1149     }
1150     /// Query backing `TyS::is_sized`.
1151     query is_sized_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1152         desc { "computing whether `{}` is `Sized`", env.value }
1153         remap_env_constness
1154     }
1155     /// Query backing `TyS::is_freeze`.
1156     query is_freeze_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1157         desc { "computing whether `{}` is freeze", env.value }
1158         remap_env_constness
1159     }
1160     /// Query backing `TyS::is_unpin`.
1161     query is_unpin_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1162         desc { "computing whether `{}` is `Unpin`", env.value }
1163         remap_env_constness
1164     }
1165     /// Query backing `TyS::needs_drop`.
1166     query needs_drop_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1167         desc { "computing whether `{}` needs drop", env.value }
1168         remap_env_constness
1169     }
1170     /// Query backing `TyS::has_significant_drop_raw`.
1171     query has_significant_drop_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1172         desc { "computing whether `{}` has a significant drop", env.value }
1173         remap_env_constness
1174     }
1175
1176     /// Query backing `TyS::is_structural_eq_shallow`.
1177     ///
1178     /// This is only correct for ADTs. Call `is_structural_eq_shallow` to handle all types
1179     /// correctly.
1180     query has_structural_eq_impls(ty: Ty<'tcx>) -> bool {
1181         desc {
1182             "computing whether `{:?}` implements `PartialStructuralEq` and `StructuralEq`",
1183             ty
1184         }
1185     }
1186
1187     /// A list of types where the ADT requires drop if and only if any of
1188     /// those types require drop. If the ADT is known to always need drop
1189     /// then `Err(AlwaysRequiresDrop)` is returned.
1190     query adt_drop_tys(def_id: DefId) -> Result<&'tcx ty::List<Ty<'tcx>>, AlwaysRequiresDrop> {
1191         desc { |tcx| "computing when `{}` needs drop", tcx.def_path_str(def_id) }
1192         cache_on_disk_if { true }
1193     }
1194
1195     /// A list of types where the ADT requires drop if and only if any of those types
1196     /// has significant drop. A type marked with the attribute `rustc_insignificant_dtor`
1197     /// is considered to not be significant. A drop is significant if it is implemented
1198     /// by the user or does anything that will have any observable behavior (other than
1199     /// freeing up memory). If the ADT is known to have a significant destructor then
1200     /// `Err(AlwaysRequiresDrop)` is returned.
1201     query adt_significant_drop_tys(def_id: DefId) -> Result<&'tcx ty::List<Ty<'tcx>>, AlwaysRequiresDrop> {
1202         desc { |tcx| "computing when `{}` has a significant destructor", tcx.def_path_str(def_id) }
1203         cache_on_disk_if { false }
1204     }
1205
1206     /// Computes the layout of a type. Note that this implicitly
1207     /// executes in "reveal all" mode, and will normalize the input type.
1208     query layout_of(
1209         key: ty::ParamEnvAnd<'tcx, Ty<'tcx>>
1210     ) -> Result<ty::layout::TyAndLayout<'tcx>, ty::layout::LayoutError<'tcx>> {
1211         desc { "computing layout of `{}`", key.value }
1212         remap_env_constness
1213     }
1214
1215     /// Compute a `FnAbi` suitable for indirect calls, i.e. to `fn` pointers.
1216     ///
1217     /// NB: this doesn't handle virtual calls - those should use `fn_abi_of_instance`
1218     /// instead, where the instance is an `InstanceDef::Virtual`.
1219     query fn_abi_of_fn_ptr(
1220         key: ty::ParamEnvAnd<'tcx, (ty::PolyFnSig<'tcx>, &'tcx ty::List<Ty<'tcx>>)>
1221     ) -> Result<&'tcx abi::call::FnAbi<'tcx, Ty<'tcx>>, ty::layout::FnAbiError<'tcx>> {
1222         desc { "computing call ABI of `{}` function pointers", key.value.0 }
1223         remap_env_constness
1224     }
1225
1226     /// Compute a `FnAbi` suitable for declaring/defining an `fn` instance, and for
1227     /// direct calls to an `fn`.
1228     ///
1229     /// NB: that includes virtual calls, which are represented by "direct calls"
1230     /// to an `InstanceDef::Virtual` instance (of `<dyn Trait as Trait>::fn`).
1231     query fn_abi_of_instance(
1232         key: ty::ParamEnvAnd<'tcx, (ty::Instance<'tcx>, &'tcx ty::List<Ty<'tcx>>)>
1233     ) -> Result<&'tcx abi::call::FnAbi<'tcx, Ty<'tcx>>, ty::layout::FnAbiError<'tcx>> {
1234         desc { "computing call ABI of `{}`", key.value.0 }
1235         remap_env_constness
1236     }
1237
1238     query dylib_dependency_formats(_: CrateNum)
1239                                     -> &'tcx [(CrateNum, LinkagePreference)] {
1240         desc { "dylib dependency formats of crate" }
1241         separate_provide_extern
1242     }
1243
1244     query dependency_formats(_: ()) -> Lrc<crate::middle::dependency_format::Dependencies> {
1245         desc { "get the linkage format of all dependencies" }
1246     }
1247
1248     query is_compiler_builtins(_: CrateNum) -> bool {
1249         fatal_cycle
1250         desc { "checking if the crate is_compiler_builtins" }
1251         separate_provide_extern
1252     }
1253     query has_global_allocator(_: CrateNum) -> bool {
1254         // This query depends on untracked global state in CStore
1255         eval_always
1256         fatal_cycle
1257         desc { "checking if the crate has_global_allocator" }
1258         separate_provide_extern
1259     }
1260     query has_panic_handler(_: CrateNum) -> bool {
1261         fatal_cycle
1262         desc { "checking if the crate has_panic_handler" }
1263         separate_provide_extern
1264     }
1265     query is_profiler_runtime(_: CrateNum) -> bool {
1266         fatal_cycle
1267         desc { "query a crate is `#![profiler_runtime]`" }
1268         separate_provide_extern
1269     }
1270     query panic_strategy(_: CrateNum) -> PanicStrategy {
1271         fatal_cycle
1272         desc { "query a crate's configured panic strategy" }
1273         separate_provide_extern
1274     }
1275     query panic_in_drop_strategy(_: CrateNum) -> PanicStrategy {
1276         fatal_cycle
1277         desc { "query a crate's configured panic-in-drop strategy" }
1278         separate_provide_extern
1279     }
1280     query is_no_builtins(_: CrateNum) -> bool {
1281         fatal_cycle
1282         desc { "test whether a crate has `#![no_builtins]`" }
1283         separate_provide_extern
1284     }
1285     query symbol_mangling_version(_: CrateNum) -> SymbolManglingVersion {
1286         fatal_cycle
1287         desc { "query a crate's symbol mangling version" }
1288         separate_provide_extern
1289     }
1290
1291     query extern_crate(def_id: DefId) -> Option<&'tcx ExternCrate> {
1292         eval_always
1293         desc { "getting crate's ExternCrateData" }
1294         separate_provide_extern
1295     }
1296
1297     query specializes(_: (DefId, DefId)) -> bool {
1298         desc { "computing whether impls specialize one another" }
1299     }
1300     query in_scope_traits_map(_: LocalDefId)
1301         -> Option<&'tcx FxHashMap<ItemLocalId, Box<[TraitCandidate]>>> {
1302         desc { "traits in scope at a block" }
1303     }
1304
1305     query module_reexports(def_id: LocalDefId) -> Option<&'tcx [ModChild]> {
1306         desc { |tcx| "looking up reexports of module `{}`", tcx.def_path_str(def_id.to_def_id()) }
1307     }
1308
1309     query impl_defaultness(def_id: DefId) -> hir::Defaultness {
1310         desc { |tcx| "looking up whether `{}` is a default impl", tcx.def_path_str(def_id) }
1311         separate_provide_extern
1312     }
1313
1314     query impl_constness(def_id: DefId) -> hir::Constness {
1315         desc { |tcx| "looking up whether `{}` is a const impl", tcx.def_path_str(def_id) }
1316         separate_provide_extern
1317     }
1318
1319     query check_item_well_formed(key: LocalDefId) -> () {
1320         desc { |tcx| "checking that `{}` is well-formed", tcx.def_path_str(key.to_def_id()) }
1321     }
1322     query check_trait_item_well_formed(key: LocalDefId) -> () {
1323         desc { |tcx| "checking that `{}` is well-formed", tcx.def_path_str(key.to_def_id()) }
1324     }
1325     query check_impl_item_well_formed(key: LocalDefId) -> () {
1326         desc { |tcx| "checking that `{}` is well-formed", tcx.def_path_str(key.to_def_id()) }
1327     }
1328
1329     // The `DefId`s of all non-generic functions and statics in the given crate
1330     // that can be reached from outside the crate.
1331     //
1332     // We expect this items to be available for being linked to.
1333     //
1334     // This query can also be called for `LOCAL_CRATE`. In this case it will
1335     // compute which items will be reachable to other crates, taking into account
1336     // the kind of crate that is currently compiled. Crates with only a
1337     // C interface have fewer reachable things.
1338     //
1339     // Does not include external symbols that don't have a corresponding DefId,
1340     // like the compiler-generated `main` function and so on.
1341     query reachable_non_generics(_: CrateNum)
1342         -> DefIdMap<SymbolExportLevel> {
1343         storage(ArenaCacheSelector<'tcx>)
1344         desc { "looking up the exported symbols of a crate" }
1345         separate_provide_extern
1346     }
1347     query is_reachable_non_generic(def_id: DefId) -> bool {
1348         desc { |tcx| "checking whether `{}` is an exported symbol", tcx.def_path_str(def_id) }
1349         separate_provide_extern
1350     }
1351     query is_unreachable_local_definition(def_id: LocalDefId) -> bool {
1352         desc { |tcx|
1353             "checking whether `{}` is reachable from outside the crate",
1354             tcx.def_path_str(def_id.to_def_id()),
1355         }
1356     }
1357
1358     /// The entire set of monomorphizations the local crate can safely link
1359     /// to because they are exported from upstream crates. Do not depend on
1360     /// this directly, as its value changes anytime a monomorphization gets
1361     /// added or removed in any upstream crate. Instead use the narrower
1362     /// `upstream_monomorphizations_for`, `upstream_drop_glue_for`, or, even
1363     /// better, `Instance::upstream_monomorphization()`.
1364     query upstream_monomorphizations(_: ()) -> DefIdMap<FxHashMap<SubstsRef<'tcx>, CrateNum>> {
1365         storage(ArenaCacheSelector<'tcx>)
1366         desc { "collecting available upstream monomorphizations" }
1367     }
1368
1369     /// Returns the set of upstream monomorphizations available for the
1370     /// generic function identified by the given `def_id`. The query makes
1371     /// sure to make a stable selection if the same monomorphization is
1372     /// available in multiple upstream crates.
1373     ///
1374     /// You likely want to call `Instance::upstream_monomorphization()`
1375     /// instead of invoking this query directly.
1376     query upstream_monomorphizations_for(def_id: DefId)
1377         -> Option<&'tcx FxHashMap<SubstsRef<'tcx>, CrateNum>> {
1378             desc { |tcx|
1379                 "collecting available upstream monomorphizations for `{}`",
1380                 tcx.def_path_str(def_id),
1381             }
1382             separate_provide_extern
1383         }
1384
1385     /// Returns the upstream crate that exports drop-glue for the given
1386     /// type (`substs` is expected to be a single-item list containing the
1387     /// type one wants drop-glue for).
1388     ///
1389     /// This is a subset of `upstream_monomorphizations_for` in order to
1390     /// increase dep-tracking granularity. Otherwise adding or removing any
1391     /// type with drop-glue in any upstream crate would invalidate all
1392     /// functions calling drop-glue of an upstream type.
1393     ///
1394     /// You likely want to call `Instance::upstream_monomorphization()`
1395     /// instead of invoking this query directly.
1396     ///
1397     /// NOTE: This query could easily be extended to also support other
1398     ///       common functions that have are large set of monomorphizations
1399     ///       (like `Clone::clone` for example).
1400     query upstream_drop_glue_for(substs: SubstsRef<'tcx>) -> Option<CrateNum> {
1401         desc { "available upstream drop-glue for `{:?}`", substs }
1402     }
1403
1404     query foreign_modules(_: CrateNum) -> Lrc<FxHashMap<DefId, ForeignModule>> {
1405         desc { "looking up the foreign modules of a linked crate" }
1406         separate_provide_extern
1407     }
1408
1409     /// Identifies the entry-point (e.g., the `main` function) for a given
1410     /// crate, returning `None` if there is no entry point (such as for library crates).
1411     query entry_fn(_: ()) -> Option<(DefId, EntryFnType)> {
1412         desc { "looking up the entry function of a crate" }
1413     }
1414     query proc_macro_decls_static(_: ()) -> Option<LocalDefId> {
1415         desc { "looking up the derive registrar for a crate" }
1416     }
1417     // The macro which defines `rustc_metadata::provide_extern` depends on this query's name.
1418     // Changing the name should cause a compiler error, but in case that changes, be aware.
1419     query crate_hash(_: CrateNum) -> Svh {
1420         eval_always
1421         desc { "looking up the hash a crate" }
1422         separate_provide_extern
1423     }
1424     query crate_host_hash(_: CrateNum) -> Option<Svh> {
1425         eval_always
1426         desc { "looking up the hash of a host version of a crate" }
1427         separate_provide_extern
1428     }
1429     query extra_filename(_: CrateNum) -> String {
1430         eval_always
1431         desc { "looking up the extra filename for a crate" }
1432         separate_provide_extern
1433     }
1434     query crate_extern_paths(_: CrateNum) -> Vec<PathBuf> {
1435         eval_always
1436         desc { "looking up the paths for extern crates" }
1437         separate_provide_extern
1438     }
1439
1440     /// Given a crate and a trait, look up all impls of that trait in the crate.
1441     /// Return `(impl_id, self_ty)`.
1442     query implementations_of_trait(_: (CrateNum, DefId)) -> &'tcx [(DefId, Option<SimplifiedType>)] {
1443         desc { "looking up implementations of a trait in a crate" }
1444         separate_provide_extern
1445     }
1446
1447     query is_dllimport_foreign_item(def_id: DefId) -> bool {
1448         desc { |tcx| "is_dllimport_foreign_item({})", tcx.def_path_str(def_id) }
1449     }
1450     query is_statically_included_foreign_item(def_id: DefId) -> bool {
1451         desc { |tcx| "is_statically_included_foreign_item({})", tcx.def_path_str(def_id) }
1452     }
1453     query native_library_kind(def_id: DefId)
1454         -> Option<NativeLibKind> {
1455         desc { |tcx| "native_library_kind({})", tcx.def_path_str(def_id) }
1456     }
1457
1458     /// Does lifetime resolution, but does not descend into trait items. This
1459     /// should only be used for resolving lifetimes of on trait definitions,
1460     /// and is used to avoid cycles. Importantly, `resolve_lifetimes` still visits
1461     /// the same lifetimes and is responsible for diagnostics.
1462     /// See `rustc_resolve::late::lifetimes for details.
1463     query resolve_lifetimes_trait_definition(_: LocalDefId) -> ResolveLifetimes {
1464         storage(ArenaCacheSelector<'tcx>)
1465         desc { "resolving lifetimes for a trait definition" }
1466     }
1467     /// Does lifetime resolution on items. Importantly, we can't resolve
1468     /// lifetimes directly on things like trait methods, because of trait params.
1469     /// See `rustc_resolve::late::lifetimes for details.
1470     query resolve_lifetimes(_: LocalDefId) -> ResolveLifetimes {
1471         storage(ArenaCacheSelector<'tcx>)
1472         desc { "resolving lifetimes" }
1473     }
1474     query named_region_map(_: LocalDefId) ->
1475         Option<&'tcx FxHashMap<ItemLocalId, Region>> {
1476         desc { "looking up a named region" }
1477     }
1478     query is_late_bound_map(_: LocalDefId) ->
1479         Option<(LocalDefId, &'tcx FxHashSet<ItemLocalId>)> {
1480         desc { "testing if a region is late bound" }
1481     }
1482     /// For a given item (like a struct), gets the default lifetimes to be used
1483     /// for each parameter if a trait object were to be passed for that parameter.
1484     /// For example, for `struct Foo<'a, T, U>`, this would be `['static, 'static]`.
1485     /// For `struct Foo<'a, T: 'a, U>`, this would instead be `['a, 'static]`.
1486     query object_lifetime_defaults_map(_: LocalDefId)
1487         -> Option<Vec<ObjectLifetimeDefault>> {
1488         desc { "looking up lifetime defaults for a region on an item" }
1489     }
1490     query late_bound_vars_map(_: LocalDefId)
1491         -> Option<&'tcx FxHashMap<ItemLocalId, Vec<ty::BoundVariableKind>>> {
1492         desc { "looking up late bound vars" }
1493     }
1494
1495     query lifetime_scope_map(_: LocalDefId) -> Option<FxHashMap<ItemLocalId, LifetimeScopeForPath>> {
1496         desc { "finds the lifetime scope for an HirId of a PathSegment" }
1497     }
1498
1499     query visibility(def_id: DefId) -> ty::Visibility {
1500         desc { |tcx| "computing visibility of `{}`", tcx.def_path_str(def_id) }
1501         separate_provide_extern
1502     }
1503
1504     /// Computes the set of modules from which this type is visibly uninhabited.
1505     /// To check whether a type is uninhabited at all (not just from a given module), you could
1506     /// check whether the forest is empty.
1507     query type_uninhabited_from(
1508         key: ty::ParamEnvAnd<'tcx, Ty<'tcx>>
1509     ) -> ty::inhabitedness::DefIdForest {
1510         desc { "computing the inhabitedness of `{:?}`", key }
1511         remap_env_constness
1512     }
1513
1514     query dep_kind(_: CrateNum) -> CrateDepKind {
1515         eval_always
1516         desc { "fetching what a dependency looks like" }
1517         separate_provide_extern
1518     }
1519
1520     /// Gets the name of the crate.
1521     query crate_name(_: CrateNum) -> Symbol {
1522         eval_always
1523         desc { "fetching what a crate is named" }
1524         separate_provide_extern
1525     }
1526     query module_children(def_id: DefId) -> &'tcx [ModChild] {
1527         desc { |tcx| "collecting child items of module `{}`", tcx.def_path_str(def_id) }
1528         separate_provide_extern
1529     }
1530     query extern_mod_stmt_cnum(def_id: LocalDefId) -> Option<CrateNum> {
1531         desc { |tcx| "computing crate imported by `{}`", tcx.def_path_str(def_id.to_def_id()) }
1532     }
1533
1534     query lib_features(_: ()) -> LibFeatures {
1535         storage(ArenaCacheSelector<'tcx>)
1536         desc { "calculating the lib features map" }
1537     }
1538     query defined_lib_features(_: CrateNum)
1539         -> &'tcx [(Symbol, Option<Symbol>)] {
1540         desc { "calculating the lib features defined in a crate" }
1541         separate_provide_extern
1542     }
1543     /// Returns the lang items defined in another crate by loading it from metadata.
1544     query get_lang_items(_: ()) -> LanguageItems {
1545         storage(ArenaCacheSelector<'tcx>)
1546         eval_always
1547         desc { "calculating the lang items map" }
1548     }
1549
1550     /// Returns all diagnostic items defined in all crates.
1551     query all_diagnostic_items(_: ()) -> rustc_hir::diagnostic_items::DiagnosticItems {
1552         storage(ArenaCacheSelector<'tcx>)
1553         eval_always
1554         desc { "calculating the diagnostic items map" }
1555     }
1556
1557     /// Returns the lang items defined in another crate by loading it from metadata.
1558     query defined_lang_items(_: CrateNum) -> &'tcx [(DefId, usize)] {
1559         desc { "calculating the lang items defined in a crate" }
1560         separate_provide_extern
1561     }
1562
1563     /// Returns the diagnostic items defined in a crate.
1564     query diagnostic_items(_: CrateNum) -> rustc_hir::diagnostic_items::DiagnosticItems {
1565         storage(ArenaCacheSelector<'tcx>)
1566         desc { "calculating the diagnostic items map in a crate" }
1567         separate_provide_extern
1568     }
1569
1570     query missing_lang_items(_: CrateNum) -> &'tcx [LangItem] {
1571         desc { "calculating the missing lang items in a crate" }
1572         separate_provide_extern
1573     }
1574     query visible_parent_map(_: ()) -> Lrc<DefIdMap<DefId>> {
1575         desc { "calculating the visible parent map" }
1576     }
1577     query trimmed_def_paths(_: ()) -> FxHashMap<DefId, Symbol> {
1578         storage(ArenaCacheSelector<'tcx>)
1579         desc { "calculating trimmed def paths" }
1580     }
1581     query missing_extern_crate_item(_: CrateNum) -> bool {
1582         eval_always
1583         desc { "seeing if we're missing an `extern crate` item for this crate" }
1584         separate_provide_extern
1585     }
1586     query used_crate_source(_: CrateNum) -> Lrc<CrateSource> {
1587         eval_always
1588         desc { "looking at the source for a crate" }
1589         separate_provide_extern
1590     }
1591     query postorder_cnums(_: ()) -> &'tcx [CrateNum] {
1592         eval_always
1593         desc { "generating a postorder list of CrateNums" }
1594     }
1595     /// Returns whether or not the crate with CrateNum 'cnum'
1596     /// is marked as a private dependency
1597     query is_private_dep(c: CrateNum) -> bool {
1598         eval_always
1599         desc { "check whether crate {} is a private dependency", c }
1600         separate_provide_extern
1601     }
1602     query allocator_kind(_: ()) -> Option<AllocatorKind> {
1603         eval_always
1604         desc { "allocator kind for the current crate" }
1605     }
1606
1607     query upvars_mentioned(def_id: DefId) -> Option<&'tcx FxIndexMap<hir::HirId, hir::Upvar>> {
1608         desc { |tcx| "collecting upvars mentioned in `{}`", tcx.def_path_str(def_id) }
1609     }
1610     query maybe_unused_trait_import(def_id: LocalDefId) -> bool {
1611         desc { |tcx| "maybe_unused_trait_import for `{}`", tcx.def_path_str(def_id.to_def_id()) }
1612     }
1613     query maybe_unused_extern_crates(_: ()) -> &'tcx [(LocalDefId, Span)] {
1614         desc { "looking up all possibly unused extern crates" }
1615     }
1616     query names_imported_by_glob_use(def_id: LocalDefId) -> &'tcx FxHashSet<Symbol> {
1617         desc { |tcx| "names_imported_by_glob_use for `{}`", tcx.def_path_str(def_id.to_def_id()) }
1618     }
1619
1620     query stability_index(_: ()) -> stability::Index<'tcx> {
1621         storage(ArenaCacheSelector<'tcx>)
1622         eval_always
1623         desc { "calculating the stability index for the local crate" }
1624     }
1625     query crates(_: ()) -> &'tcx [CrateNum] {
1626         eval_always
1627         desc { "fetching all foreign CrateNum instances" }
1628     }
1629
1630     /// A list of all traits in a crate, used by rustdoc and error reporting.
1631     /// NOTE: Not named just `traits` due to a naming conflict.
1632     query traits_in_crate(_: CrateNum) -> &'tcx [DefId] {
1633         desc { "fetching all traits in a crate" }
1634         separate_provide_extern
1635     }
1636
1637     /// The list of symbols exported from the given crate.
1638     ///
1639     /// - All names contained in `exported_symbols(cnum)` are guaranteed to
1640     ///   correspond to a publicly visible symbol in `cnum` machine code.
1641     /// - The `exported_symbols` sets of different crates do not intersect.
1642     query exported_symbols(_: CrateNum)
1643         -> &'tcx [(ExportedSymbol<'tcx>, SymbolExportLevel)] {
1644         desc { "exported_symbols" }
1645         separate_provide_extern
1646     }
1647
1648     query collect_and_partition_mono_items(_: ()) -> (&'tcx DefIdSet, &'tcx [CodegenUnit<'tcx>]) {
1649         eval_always
1650         desc { "collect_and_partition_mono_items" }
1651     }
1652     query is_codegened_item(def_id: DefId) -> bool {
1653         desc { |tcx| "determining whether `{}` needs codegen", tcx.def_path_str(def_id) }
1654     }
1655
1656     /// All items participating in code generation together with items inlined into them.
1657     query codegened_and_inlined_items(_: ()) -> &'tcx DefIdSet {
1658         eval_always
1659        desc { "codegened_and_inlined_items" }
1660     }
1661
1662     query codegen_unit(_: Symbol) -> &'tcx CodegenUnit<'tcx> {
1663         desc { "codegen_unit" }
1664     }
1665     query unused_generic_params(key: ty::InstanceDef<'tcx>) -> FiniteBitSet<u32> {
1666         cache_on_disk_if { key.def_id().is_local() }
1667         desc {
1668             |tcx| "determining which generic parameters are unused by `{}`",
1669                 tcx.def_path_str(key.def_id())
1670         }
1671         separate_provide_extern
1672     }
1673     query backend_optimization_level(_: ()) -> OptLevel {
1674         desc { "optimization level used by backend" }
1675     }
1676
1677     query output_filenames(_: ()) -> Arc<OutputFilenames> {
1678         eval_always
1679         desc { "output_filenames" }
1680     }
1681
1682     /// Do not call this query directly: invoke `normalize` instead.
1683     query normalize_projection_ty(
1684         goal: CanonicalProjectionGoal<'tcx>
1685     ) -> Result<
1686         &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, NormalizationResult<'tcx>>>,
1687         NoSolution,
1688     > {
1689         desc { "normalizing `{:?}`", goal }
1690         remap_env_constness
1691     }
1692
1693     /// Do not call this query directly: invoke `try_normalize_erasing_regions` instead.
1694     query try_normalize_generic_arg_after_erasing_regions(
1695         goal: ParamEnvAnd<'tcx, GenericArg<'tcx>>
1696     ) -> Result<GenericArg<'tcx>, NoSolution> {
1697         desc { "normalizing `{}`", goal.value }
1698         remap_env_constness
1699     }
1700
1701     /// Do not call this query directly: invoke `try_normalize_erasing_regions` instead.
1702     query try_normalize_mir_const_after_erasing_regions(
1703         goal: ParamEnvAnd<'tcx, mir::ConstantKind<'tcx>>
1704     ) -> Result<mir::ConstantKind<'tcx>, NoSolution> {
1705         desc { "normalizing `{}`", goal.value }
1706         remap_env_constness
1707     }
1708
1709     query implied_outlives_bounds(
1710         goal: CanonicalTyGoal<'tcx>
1711     ) -> Result<
1712         &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, Vec<OutlivesBound<'tcx>>>>,
1713         NoSolution,
1714     > {
1715         desc { "computing implied outlives bounds for `{:?}`", goal }
1716         remap_env_constness
1717     }
1718
1719     /// Do not call this query directly: invoke `infcx.at().dropck_outlives()` instead.
1720     query dropck_outlives(
1721         goal: CanonicalTyGoal<'tcx>
1722     ) -> Result<
1723         &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, DropckOutlivesResult<'tcx>>>,
1724         NoSolution,
1725     > {
1726         desc { "computing dropck types for `{:?}`", goal }
1727         remap_env_constness
1728     }
1729
1730     /// Do not call this query directly: invoke `infcx.predicate_may_hold()` or
1731     /// `infcx.predicate_must_hold()` instead.
1732     query evaluate_obligation(
1733         goal: CanonicalPredicateGoal<'tcx>
1734     ) -> Result<traits::EvaluationResult, traits::OverflowError> {
1735         desc { "evaluating trait selection obligation `{}`", goal.value.value }
1736     }
1737
1738     query evaluate_goal(
1739         goal: traits::CanonicalChalkEnvironmentAndGoal<'tcx>
1740     ) -> Result<
1741         &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1742         NoSolution
1743     > {
1744         desc { "evaluating trait selection obligation `{}`", goal.value }
1745     }
1746
1747     /// Do not call this query directly: part of the `Eq` type-op
1748     query type_op_ascribe_user_type(
1749         goal: CanonicalTypeOpAscribeUserTypeGoal<'tcx>
1750     ) -> Result<
1751         &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1752         NoSolution,
1753     > {
1754         desc { "evaluating `type_op_ascribe_user_type` `{:?}`", goal }
1755         remap_env_constness
1756     }
1757
1758     /// Do not call this query directly: part of the `Eq` type-op
1759     query type_op_eq(
1760         goal: CanonicalTypeOpEqGoal<'tcx>
1761     ) -> Result<
1762         &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1763         NoSolution,
1764     > {
1765         desc { "evaluating `type_op_eq` `{:?}`", goal }
1766         remap_env_constness
1767     }
1768
1769     /// Do not call this query directly: part of the `Subtype` type-op
1770     query type_op_subtype(
1771         goal: CanonicalTypeOpSubtypeGoal<'tcx>
1772     ) -> Result<
1773         &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1774         NoSolution,
1775     > {
1776         desc { "evaluating `type_op_subtype` `{:?}`", goal }
1777         remap_env_constness
1778     }
1779
1780     /// Do not call this query directly: part of the `ProvePredicate` type-op
1781     query type_op_prove_predicate(
1782         goal: CanonicalTypeOpProvePredicateGoal<'tcx>
1783     ) -> Result<
1784         &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1785         NoSolution,
1786     > {
1787         desc { "evaluating `type_op_prove_predicate` `{:?}`", goal }
1788     }
1789
1790     /// Do not call this query directly: part of the `Normalize` type-op
1791     query type_op_normalize_ty(
1792         goal: CanonicalTypeOpNormalizeGoal<'tcx, Ty<'tcx>>
1793     ) -> Result<
1794         &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, Ty<'tcx>>>,
1795         NoSolution,
1796     > {
1797         desc { "normalizing `{:?}`", goal }
1798         remap_env_constness
1799     }
1800
1801     /// Do not call this query directly: part of the `Normalize` type-op
1802     query type_op_normalize_predicate(
1803         goal: CanonicalTypeOpNormalizeGoal<'tcx, ty::Predicate<'tcx>>
1804     ) -> Result<
1805         &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ty::Predicate<'tcx>>>,
1806         NoSolution,
1807     > {
1808         desc { "normalizing `{:?}`", goal }
1809         remap_env_constness
1810     }
1811
1812     /// Do not call this query directly: part of the `Normalize` type-op
1813     query type_op_normalize_poly_fn_sig(
1814         goal: CanonicalTypeOpNormalizeGoal<'tcx, ty::PolyFnSig<'tcx>>
1815     ) -> Result<
1816         &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ty::PolyFnSig<'tcx>>>,
1817         NoSolution,
1818     > {
1819         desc { "normalizing `{:?}`", goal }
1820         remap_env_constness
1821     }
1822
1823     /// Do not call this query directly: part of the `Normalize` type-op
1824     query type_op_normalize_fn_sig(
1825         goal: CanonicalTypeOpNormalizeGoal<'tcx, ty::FnSig<'tcx>>
1826     ) -> Result<
1827         &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ty::FnSig<'tcx>>>,
1828         NoSolution,
1829     > {
1830         desc { "normalizing `{:?}`", goal }
1831         remap_env_constness
1832     }
1833
1834     query subst_and_check_impossible_predicates(key: (DefId, SubstsRef<'tcx>)) -> bool {
1835         desc { |tcx|
1836             "impossible substituted predicates:`{}`",
1837             tcx.def_path_str(key.0)
1838         }
1839     }
1840
1841     query method_autoderef_steps(
1842         goal: CanonicalTyGoal<'tcx>
1843     ) -> MethodAutoderefStepsResult<'tcx> {
1844         desc { "computing autoderef types for `{:?}`", goal }
1845         remap_env_constness
1846     }
1847
1848     query supported_target_features(_: CrateNum) -> FxHashMap<String, Option<Symbol>> {
1849         storage(ArenaCacheSelector<'tcx>)
1850         eval_always
1851         desc { "looking up supported target features" }
1852     }
1853
1854     /// Get an estimate of the size of an InstanceDef based on its MIR for CGU partitioning.
1855     query instance_def_size_estimate(def: ty::InstanceDef<'tcx>)
1856         -> usize {
1857         desc { |tcx| "estimating size for `{}`", tcx.def_path_str(def.def_id()) }
1858     }
1859
1860     query features_query(_: ()) -> &'tcx rustc_feature::Features {
1861         eval_always
1862         desc { "looking up enabled feature gates" }
1863     }
1864
1865     /// Attempt to resolve the given `DefId` to an `Instance`, for the
1866     /// given generics args (`SubstsRef`), returning one of:
1867     ///  * `Ok(Some(instance))` on success
1868     ///  * `Ok(None)` when the `SubstsRef` are still too generic,
1869     ///    and therefore don't allow finding the final `Instance`
1870     ///  * `Err(ErrorReported)` when the `Instance` resolution process
1871     ///    couldn't complete due to errors elsewhere - this is distinct
1872     ///    from `Ok(None)` to avoid misleading diagnostics when an error
1873     ///    has already been/will be emitted, for the original cause
1874     query resolve_instance(
1875         key: ty::ParamEnvAnd<'tcx, (DefId, SubstsRef<'tcx>)>
1876     ) -> Result<Option<ty::Instance<'tcx>>, ErrorReported> {
1877         desc { "resolving instance `{}`", ty::Instance::new(key.value.0, key.value.1) }
1878         remap_env_constness
1879     }
1880
1881     query resolve_instance_of_const_arg(
1882         key: ty::ParamEnvAnd<'tcx, (LocalDefId, DefId, SubstsRef<'tcx>)>
1883     ) -> Result<Option<ty::Instance<'tcx>>, ErrorReported> {
1884         desc {
1885             "resolving instance of the const argument `{}`",
1886             ty::Instance::new(key.value.0.to_def_id(), key.value.2),
1887         }
1888         remap_env_constness
1889     }
1890
1891     query normalize_opaque_types(key: &'tcx ty::List<ty::Predicate<'tcx>>) -> &'tcx ty::List<ty::Predicate<'tcx>> {
1892         desc { "normalizing opaque types in {:?}", key }
1893     }
1894
1895     /// Checks whether a type is definitely uninhabited. This is
1896     /// conservative: for some types that are uninhabited we return `false`,
1897     /// but we only return `true` for types that are definitely uninhabited.
1898     /// `ty.conservative_is_privately_uninhabited` implies that any value of type `ty`
1899     /// will be `Abi::Uninhabited`. (Note that uninhabited types may have nonzero
1900     /// size, to account for partial initialisation. See #49298 for details.)
1901     query conservative_is_privately_uninhabited(key: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1902         desc { "conservatively checking if {:?} is privately uninhabited", key }
1903         remap_env_constness
1904     }
1905
1906     query limits(key: ()) -> Limits {
1907         desc { "looking up limits" }
1908     }
1909
1910     /// Performs an HIR-based well-formed check on the item with the given `HirId`. If
1911     /// we get an `Unimplemented` error that matches the provided `Predicate`, return
1912     /// the cause of the newly created obligation.
1913     ///
1914     /// This is only used by error-reporting code to get a better cause (in particular, a better
1915     /// span) for an *existing* error. Therefore, it is best-effort, and may never handle
1916     /// all of the cases that the normal `ty::Ty`-based wfcheck does. This is fine,
1917     /// because the `ty::Ty`-based wfcheck is always run.
1918     query diagnostic_hir_wf_check(key: (ty::Predicate<'tcx>, traits::WellFormedLoc)) -> Option<traits::ObligationCause<'tcx>> {
1919         eval_always
1920         no_hash
1921         desc { "performing HIR wf-checking for predicate {:?} at item {:?}", key.0, key.1 }
1922     }
1923 }