1 //! Defines the various compiler queries.
3 //! For more information on the query system, see
4 //! ["Queries: demand-driven compilation"](https://rustc-dev-guide.rust-lang.org/query.html).
5 //! This chapter includes instructions for adding new queries.
7 use crate::ty::{self, print::describe_as_module, TyCtxt};
8 use rustc_span::def_id::LOCAL_CRATE;
13 // Each of these queries corresponds to a function pointer field in the
14 // `Providers` struct for requesting a value of that type, and a method
15 // on `tcx: TyCtxt` (and `tcx.at(span)`) for doing that request in a way
16 // which memoizes and does dep-graph tracking, wrapping around the actual
17 // `Providers` that the driver creates (using several `rustc_*` crates).
19 // The result type of each query must implement `Clone`, and additionally
20 // `ty::query::values::Value`, which produces an appropriate placeholder
21 // (error) value if the query resulted in a query cycle.
22 // Queries marked with `fatal_cycle` do not need the latter implementation,
23 // as they will raise an fatal error on query cycles instead.
25 query trigger_delay_span_bug(key: DefId) -> () {
26 desc { "triggering a delay span bug" }
29 query resolutions(_: ()) -> &'tcx ty::ResolverGlobalCtxt {
32 desc { "getting the resolver outputs" }
35 query resolver_for_lowering(_: ()) -> &'tcx Steal<(ty::ResolverAstLowering, Lrc<ast::Crate>)> {
38 desc { "getting the resolver for lowering" }
41 /// Return the span for a definition.
42 /// Contrary to `def_span` below, this query returns the full absolute span of the definition.
43 /// This span is meant for dep-tracking rather than diagnostics. It should not be used outside
44 /// of rustc_middle::hir::source_map.
45 query source_span(key: LocalDefId) -> Span {
46 // Accesses untracked data
48 desc { "getting the source span" }
51 /// Represents crate as a whole (as distinct from the top-level crate module).
52 /// If you call `hir_crate` (e.g., indirectly by calling `tcx.hir().krate()`),
53 /// we will have to assume that any change means that you need to be recompiled.
54 /// This is because the `hir_crate` query gives you access to all other items.
55 /// To avoid this fate, do not call `tcx.hir().krate()`; instead,
56 /// prefer wrappers like `tcx.visit_all_items_in_krate()`.
57 query hir_crate(key: ()) -> Crate<'tcx> {
60 desc { "getting the crate HIR" }
63 /// All items in the crate.
64 query hir_crate_items(_: ()) -> rustc_middle::hir::ModuleItems {
67 desc { "getting HIR crate items" }
70 /// The items in a module.
72 /// This can be conveniently accessed by `tcx.hir().visit_item_likes_in_module`.
73 /// Avoid calling this query directly.
74 query hir_module_items(key: LocalDefId) -> rustc_middle::hir::ModuleItems {
76 desc { |tcx| "getting HIR module items in `{}`", tcx.def_path_str(key.to_def_id()) }
77 cache_on_disk_if { true }
80 /// Gives access to the HIR node for the HIR owner `key`.
82 /// This can be conveniently accessed by methods on `tcx.hir()`.
83 /// Avoid calling this query directly.
84 query hir_owner(key: hir::OwnerId) -> Option<crate::hir::Owner<'tcx>> {
85 desc { |tcx| "getting HIR owner of `{}`", tcx.def_path_str(key.to_def_id()) }
88 /// Gives access to the HIR ID for the given `LocalDefId` owner `key`.
90 /// This can be conveniently accessed by methods on `tcx.hir()`.
91 /// Avoid calling this query directly.
92 query local_def_id_to_hir_id(key: LocalDefId) -> hir::HirId {
93 desc { |tcx| "getting HIR ID of `{}`", tcx.def_path_str(key.to_def_id()) }
96 /// Gives access to the HIR node's parent for the HIR owner `key`.
98 /// This can be conveniently accessed by methods on `tcx.hir()`.
99 /// Avoid calling this query directly.
100 query hir_owner_parent(key: hir::OwnerId) -> hir::HirId {
101 desc { |tcx| "getting HIR parent of `{}`", tcx.def_path_str(key.to_def_id()) }
104 /// Gives access to the HIR nodes and bodies inside the HIR owner `key`.
106 /// This can be conveniently accessed by methods on `tcx.hir()`.
107 /// Avoid calling this query directly.
108 query hir_owner_nodes(key: hir::OwnerId) -> hir::MaybeOwner<&'tcx hir::OwnerNodes<'tcx>> {
109 desc { |tcx| "getting HIR owner items in `{}`", tcx.def_path_str(key.to_def_id()) }
112 /// Gives access to the HIR attributes inside the HIR owner `key`.
114 /// This can be conveniently accessed by methods on `tcx.hir()`.
115 /// Avoid calling this query directly.
116 query hir_attrs(key: hir::OwnerId) -> &'tcx hir::AttributeMap<'tcx> {
117 desc { |tcx| "getting HIR owner attributes in `{}`", tcx.def_path_str(key.to_def_id()) }
120 /// Computes the `DefId` of the corresponding const parameter in case the `key` is a
121 /// const argument and returns `None` otherwise.
123 /// ```ignore (incomplete)
124 /// let a = foo::<7>();
125 /// // ^ Calling `opt_const_param_of` for this argument,
127 /// fn foo<const N: usize>()
128 /// // ^ returns this `DefId`.
131 /// // ^ While calling `opt_const_param_of` for other bodies returns `None`.
134 // It looks like caching this query on disk actually slightly
135 // worsened performance in #74376.
137 // Once const generics are more prevalently used, we might want to
138 // consider only caching calls returning `Some`.
139 query opt_const_param_of(key: LocalDefId) -> Option<DefId> {
140 desc { |tcx| "computing the optional const parameter of `{}`", tcx.def_path_str(key.to_def_id()) }
143 /// Given the def_id of a const-generic parameter, computes the associated default const
144 /// parameter. e.g. `fn example<const N: usize=3>` called on `N` would return `3`.
145 query const_param_default(param: DefId) -> ty::EarlyBinder<ty::Const<'tcx>> {
146 desc { |tcx| "computing const default for a given parameter `{}`", tcx.def_path_str(param) }
147 cache_on_disk_if { param.is_local() }
148 separate_provide_extern
151 /// Returns the [`Ty`][rustc_middle::ty::Ty] of the given [`DefId`]. If the [`DefId`] points
152 /// to an alias, it will "skip" this alias to return the aliased type.
154 /// [`DefId`]: rustc_hir::def_id::DefId
155 query type_of(key: DefId) -> Ty<'tcx> {
159 use rustc_hir::def::DefKind;
160 match tcx.def_kind(key) {
161 DefKind::TyAlias => "expanding type alias",
162 DefKind::TraitAlias => "expanding trait alias",
163 _ => "computing type of",
166 path = tcx.def_path_str(key),
168 cache_on_disk_if { key.is_local() }
169 separate_provide_extern
172 query collect_return_position_impl_trait_in_trait_tys(key: DefId)
173 -> Result<&'tcx FxHashMap<DefId, Ty<'tcx>>, ErrorGuaranteed>
175 desc { "comparing an impl and trait method signature, inferring any hidden `impl Trait` types in the process" }
176 cache_on_disk_if { key.is_local() }
177 separate_provide_extern
180 query is_type_alias_impl_trait(key: DefId) -> bool
182 desc { "determine whether the opaque is a type-alias impl trait" }
183 separate_provide_extern
186 query unsizing_params_for_adt(key: DefId) -> rustc_index::bit_set::BitSet<u32>
190 "determining what parameters of `{}` can participate in unsizing",
191 tcx.def_path_str(key),
195 query analysis(key: ()) -> Result<(), ErrorGuaranteed> {
197 desc { "running analysis passes on this crate" }
200 /// This query checks the fulfillment of collected lint expectations.
201 /// All lint emitting queries have to be done before this is executed
202 /// to ensure that all expectations can be fulfilled.
204 /// This is an extra query to enable other drivers (like rustdoc) to
205 /// only execute a small subset of the `analysis` query, while allowing
206 /// lints to be expected. In rustc, this query will be executed as part of
207 /// the `analysis` query and doesn't have to be called a second time.
209 /// Tools can additionally pass in a tool filter. That will restrict the
210 /// expectations to only trigger for lints starting with the listed tool
211 /// name. This is useful for cases were not all linting code from rustc
212 /// was called. With the default `None` all registered lints will also
213 /// be checked for expectation fulfillment.
214 query check_expectations(key: Option<Symbol>) -> () {
216 desc { "checking lint expectations (RFC 2383)" }
219 /// Maps from the `DefId` of an item (trait/struct/enum/fn) to its
220 /// associated generics.
221 query generics_of(key: DefId) -> ty::Generics {
222 desc { |tcx| "computing generics of `{}`", tcx.def_path_str(key) }
224 cache_on_disk_if { key.is_local() }
225 separate_provide_extern
228 /// Maps from the `DefId` of an item (trait/struct/enum/fn) to the
229 /// predicates (where-clauses) that must be proven true in order
230 /// to reference it. This is almost always the "predicates query"
233 /// `predicates_of` builds on `predicates_defined_on` -- in fact,
234 /// it is almost always the same as that query, except for the
235 /// case of traits. For traits, `predicates_of` contains
236 /// an additional `Self: Trait<...>` predicate that users don't
237 /// actually write. This reflects the fact that to invoke the
238 /// trait (e.g., via `Default::default`) you must supply types
239 /// that actually implement the trait. (However, this extra
240 /// predicate gets in the way of some checks, which are intended
241 /// to operate over only the actual where-clauses written by the
243 query predicates_of(key: DefId) -> ty::GenericPredicates<'tcx> {
244 desc { |tcx| "computing predicates of `{}`", tcx.def_path_str(key) }
245 cache_on_disk_if { key.is_local() }
248 /// Returns the list of bounds that can be used for
249 /// `SelectionCandidate::ProjectionCandidate(_)` and
250 /// `ProjectionTyCandidate::TraitDef`.
251 /// Specifically this is the bounds written on the trait's type
252 /// definition, or those after the `impl` keyword
254 /// ```ignore (incomplete)
255 /// type X: Bound + 'lt
257 /// impl Debug + Display
258 /// // ^^^^^^^^^^^^^^^
261 /// `key` is the `DefId` of the associated type or opaque type.
263 /// Bounds from the parent (e.g. with nested impl trait) are not included.
264 query explicit_item_bounds(key: DefId) -> &'tcx [(ty::Predicate<'tcx>, Span)] {
265 desc { |tcx| "finding item bounds for `{}`", tcx.def_path_str(key) }
266 cache_on_disk_if { key.is_local() }
267 separate_provide_extern
270 /// Elaborated version of the predicates from `explicit_item_bounds`.
276 /// type MyAType: Eq + ?Sized;
280 /// `explicit_item_bounds` returns `[<Self as MyTrait>::MyAType: Eq]`,
281 /// and `item_bounds` returns
284 /// <Self as Trait>::MyAType: Eq,
285 /// <Self as Trait>::MyAType: PartialEq<<Self as Trait>::MyAType>
289 /// Bounds from the parent (e.g. with nested impl trait) are not included.
290 query item_bounds(key: DefId) -> ty::EarlyBinder<&'tcx ty::List<ty::Predicate<'tcx>>> {
291 desc { |tcx| "elaborating item bounds for `{}`", tcx.def_path_str(key) }
294 /// Look up all native libraries this crate depends on.
295 /// These are assembled from the following places:
296 /// - `extern` blocks (depending on their `link` attributes)
297 /// - the `libs` (`-l`) option
298 query native_libraries(_: CrateNum) -> Vec<NativeLib> {
300 desc { "looking up the native libraries of a linked crate" }
301 separate_provide_extern
304 query shallow_lint_levels_on(key: hir::OwnerId) -> rustc_middle::lint::ShallowLintLevelMap {
305 eval_always // fetches `resolutions`
307 desc { |tcx| "looking up lint levels for `{}`", tcx.def_path_str(key.to_def_id()) }
310 query lint_expectations(_: ()) -> Vec<(LintExpectationId, LintExpectation)> {
312 desc { "computing `#[expect]`ed lints in this crate" }
315 query parent_module_from_def_id(key: LocalDefId) -> LocalDefId {
317 desc { |tcx| "getting the parent module of `{}`", tcx.def_path_str(key.to_def_id()) }
320 query expn_that_defined(key: DefId) -> rustc_span::ExpnId {
321 desc { |tcx| "getting the expansion that defined `{}`", tcx.def_path_str(key) }
322 separate_provide_extern
325 query is_panic_runtime(_: CrateNum) -> bool {
327 desc { "checking if the crate is_panic_runtime" }
328 separate_provide_extern
331 /// Checks whether a type is representable or infinitely sized
332 query representability(_: LocalDefId) -> rustc_middle::ty::Representability {
333 desc { "checking if `{}` is representable", tcx.def_path_str(key.to_def_id()) }
334 // infinitely sized types will cause a cycle
336 // we don't want recursive representability calls to be forced with
337 // incremental compilation because, if a cycle occurs, we need the
338 // entire cycle to be in memory for diagnostics
342 /// An implementation detail for the `representability` query
343 query representability_adt_ty(_: Ty<'tcx>) -> rustc_middle::ty::Representability {
344 desc { "checking if `{}` is representable", key }
349 /// Set of param indexes for type params that are in the type's representation
350 query params_in_repr(key: DefId) -> rustc_index::bit_set::BitSet<u32> {
351 desc { "finding type parameters in the representation" }
354 separate_provide_extern
357 /// Fetch the THIR for a given body. If typeck for that body failed, returns an empty `Thir`.
358 query thir_body(key: ty::WithOptConstParam<LocalDefId>)
359 -> Result<(&'tcx Steal<thir::Thir<'tcx>>, thir::ExprId), ErrorGuaranteed>
361 // Perf tests revealed that hashing THIR is inefficient (see #85729).
363 desc { |tcx| "building THIR for `{}`", tcx.def_path_str(key.did.to_def_id()) }
366 /// Create a THIR tree for debugging.
367 query thir_tree(key: ty::WithOptConstParam<LocalDefId>) -> String {
370 desc { |tcx| "constructing THIR tree for `{}`", tcx.def_path_str(key.did.to_def_id()) }
373 /// Create a list-like THIR representation for debugging.
374 query thir_flat(key: ty::WithOptConstParam<LocalDefId>) -> String {
377 desc { |tcx| "constructing flat THIR representation for `{}`", tcx.def_path_str(key.did.to_def_id()) }
380 /// Set of all the `DefId`s in this crate that have MIR associated with
381 /// them. This includes all the body owners, but also things like struct
383 query mir_keys(_: ()) -> rustc_data_structures::fx::FxIndexSet<LocalDefId> {
385 desc { "getting a list of all mir_keys" }
388 /// Maps DefId's that have an associated `mir::Body` to the result
389 /// of the MIR const-checking pass. This is the set of qualifs in
390 /// the final value of a `const`.
391 query mir_const_qualif(key: DefId) -> mir::ConstQualifs {
392 desc { |tcx| "const checking `{}`", tcx.def_path_str(key) }
393 cache_on_disk_if { key.is_local() }
394 separate_provide_extern
396 query mir_const_qualif_const_arg(
397 key: (LocalDefId, DefId)
398 ) -> mir::ConstQualifs {
400 |tcx| "const checking the const argument `{}`",
401 tcx.def_path_str(key.0.to_def_id())
405 /// Fetch the MIR for a given `DefId` right after it's built - this includes
406 /// unreachable code.
407 query mir_built(key: ty::WithOptConstParam<LocalDefId>) -> &'tcx Steal<mir::Body<'tcx>> {
408 desc { |tcx| "building MIR for `{}`", tcx.def_path_str(key.did.to_def_id()) }
411 /// Fetch the MIR for a given `DefId` up till the point where it is
412 /// ready for const qualification.
414 /// See the README for the `mir` module for details.
415 query mir_const(key: ty::WithOptConstParam<LocalDefId>) -> &'tcx Steal<mir::Body<'tcx>> {
417 |tcx| "preparing {}`{}` for borrow checking",
418 if key.const_param_did.is_some() { "the const argument " } else { "" },
419 tcx.def_path_str(key.did.to_def_id()),
424 /// Try to build an abstract representation of the given constant.
425 query thir_abstract_const(
427 ) -> Result<Option<ty::Const<'tcx>>, ErrorGuaranteed> {
429 |tcx| "building an abstract representation for `{}`", tcx.def_path_str(key),
431 separate_provide_extern
433 /// Try to build an abstract representation of the given constant.
434 query thir_abstract_const_of_const_arg(
435 key: (LocalDefId, DefId)
436 ) -> Result<Option<ty::Const<'tcx>>, ErrorGuaranteed> {
439 "building an abstract representation for the const argument `{}`",
440 tcx.def_path_str(key.0.to_def_id()),
444 query mir_drops_elaborated_and_const_checked(
445 key: ty::WithOptConstParam<LocalDefId>
446 ) -> &'tcx Steal<mir::Body<'tcx>> {
448 desc { |tcx| "elaborating drops for `{}`", tcx.def_path_str(key.did.to_def_id()) }
453 ) -> &'tcx mir::Body<'tcx> {
454 desc { |tcx| "caching mir of `{}` for CTFE", tcx.def_path_str(key) }
455 cache_on_disk_if { key.is_local() }
456 separate_provide_extern
459 query mir_for_ctfe_of_const_arg(key: (LocalDefId, DefId)) -> &'tcx mir::Body<'tcx> {
461 |tcx| "caching MIR for CTFE of the const argument `{}`",
462 tcx.def_path_str(key.0.to_def_id())
466 query mir_promoted(key: ty::WithOptConstParam<LocalDefId>) ->
468 &'tcx Steal<mir::Body<'tcx>>,
469 &'tcx Steal<IndexVec<mir::Promoted, mir::Body<'tcx>>>
473 |tcx| "processing MIR for {}`{}`",
474 if key.const_param_did.is_some() { "the const argument " } else { "" },
475 tcx.def_path_str(key.did.to_def_id()),
479 query symbols_for_closure_captures(
480 key: (LocalDefId, LocalDefId)
481 ) -> Vec<rustc_span::Symbol> {
484 |tcx| "finding symbols for captures of closure `{}` in `{}`",
485 tcx.def_path_str(key.1.to_def_id()),
486 tcx.def_path_str(key.0.to_def_id())
490 query mir_generator_witnesses(key: DefId) -> mir::GeneratorLayout<'tcx> {
492 desc { |tcx| "generator witness types for `{}`", tcx.def_path_str(key) }
493 cache_on_disk_if { key.is_local() }
494 separate_provide_extern
497 query check_generator_obligations(key: LocalDefId) {
498 desc { |tcx| "verify auto trait bounds for generator interior type `{}`", tcx.def_path_str(key.to_def_id()) }
501 /// MIR after our optimization passes have run. This is MIR that is ready
502 /// for codegen. This is also the only query that can fetch non-local MIR, at present.
503 query optimized_mir(key: DefId) -> &'tcx mir::Body<'tcx> {
504 desc { |tcx| "optimizing MIR for `{}`", tcx.def_path_str(key) }
505 cache_on_disk_if { key.is_local() }
506 separate_provide_extern
509 /// Returns coverage summary info for a function, after executing the `InstrumentCoverage`
510 /// MIR pass (assuming the -Cinstrument-coverage option is enabled).
511 query coverageinfo(key: ty::InstanceDef<'tcx>) -> mir::CoverageInfo {
512 desc { |tcx| "retrieving coverage info from MIR for `{}`", tcx.def_path_str(key.def_id()) }
516 /// Returns the `CodeRegions` for a function that has instrumented coverage, in case the
517 /// function was optimized out before codegen, and before being added to the Coverage Map.
518 query covered_code_regions(key: DefId) -> Vec<&'tcx mir::coverage::CodeRegion> {
520 |tcx| "retrieving the covered `CodeRegion`s, if instrumented, for `{}`",
521 tcx.def_path_str(key)
524 cache_on_disk_if { key.is_local() }
527 /// The `DefId` is the `DefId` of the containing MIR body. Promoteds do not have their own
528 /// `DefId`. This function returns all promoteds in the specified body. The body references
529 /// promoteds by the `DefId` and the `mir::Promoted` index. This is necessary, because
530 /// after inlining a body may refer to promoteds from other bodies. In that case you still
531 /// need to use the `DefId` of the original body.
532 query promoted_mir(key: DefId) -> &'tcx IndexVec<mir::Promoted, mir::Body<'tcx>> {
533 desc { |tcx| "optimizing promoted MIR for `{}`", tcx.def_path_str(key) }
534 cache_on_disk_if { key.is_local() }
535 separate_provide_extern
537 query promoted_mir_of_const_arg(
538 key: (LocalDefId, DefId)
539 ) -> &'tcx IndexVec<mir::Promoted, mir::Body<'tcx>> {
541 |tcx| "optimizing promoted MIR for the const argument `{}`",
542 tcx.def_path_str(key.0.to_def_id()),
546 /// Erases regions from `ty` to yield a new type.
547 /// Normally you would just use `tcx.erase_regions(value)`,
548 /// however, which uses this query as a kind of cache.
549 query erase_regions_ty(ty: Ty<'tcx>) -> Ty<'tcx> {
550 // This query is not expected to have input -- as a result, it
551 // is not a good candidates for "replay" because it is essentially a
552 // pure function of its input (and hence the expectation is that
553 // no caller would be green **apart** from just these
554 // queries). Making it anonymous avoids hashing the result, which
555 // may save a bit of time.
557 desc { "erasing regions from `{}`", ty }
560 query wasm_import_module_map(_: CrateNum) -> FxHashMap<DefId, String> {
562 desc { "getting wasm import module map" }
565 /// Maps from the `DefId` of an item (trait/struct/enum/fn) to the
566 /// predicates (where-clauses) directly defined on it. This is
567 /// equal to the `explicit_predicates_of` predicates plus the
568 /// `inferred_outlives_of` predicates.
569 query predicates_defined_on(key: DefId) -> ty::GenericPredicates<'tcx> {
570 desc { |tcx| "computing predicates of `{}`", tcx.def_path_str(key) }
573 /// Returns everything that looks like a predicate written explicitly
574 /// by the user on a trait item.
576 /// Traits are unusual, because predicates on associated types are
577 /// converted into bounds on that type for backwards compatibility:
579 /// trait X where Self::U: Copy { type U; }
583 /// trait X { type U: Copy; }
585 /// `explicit_predicates_of` and `explicit_item_bounds` will then take
586 /// the appropriate subsets of the predicates here.
587 query trait_explicit_predicates_and_bounds(key: LocalDefId) -> ty::GenericPredicates<'tcx> {
588 desc { |tcx| "computing explicit predicates of trait `{}`", tcx.def_path_str(key.to_def_id()) }
591 /// Returns the predicates written explicitly by the user.
592 query explicit_predicates_of(key: DefId) -> ty::GenericPredicates<'tcx> {
593 desc { |tcx| "computing explicit predicates of `{}`", tcx.def_path_str(key) }
594 cache_on_disk_if { key.is_local() }
595 separate_provide_extern
598 /// Returns the inferred outlives predicates (e.g., for `struct
599 /// Foo<'a, T> { x: &'a T }`, this would return `T: 'a`).
600 query inferred_outlives_of(key: DefId) -> &'tcx [(ty::Clause<'tcx>, Span)] {
601 desc { |tcx| "computing inferred outlives predicates of `{}`", tcx.def_path_str(key) }
602 cache_on_disk_if { key.is_local() }
603 separate_provide_extern
606 /// Maps from the `DefId` of a trait to the list of
607 /// super-predicates. This is a subset of the full list of
608 /// predicates. We store these in a separate map because we must
609 /// evaluate them even during type conversion, often before the
610 /// full predicates are available (note that supertraits have
611 /// additional acyclicity requirements).
612 query super_predicates_of(key: DefId) -> ty::GenericPredicates<'tcx> {
613 desc { |tcx| "computing the super predicates of `{}`", tcx.def_path_str(key) }
614 cache_on_disk_if { key.is_local() }
615 separate_provide_extern
618 /// The `Option<Ident>` is the name of an associated type. If it is `None`, then this query
619 /// returns the full set of predicates. If `Some<Ident>`, then the query returns only the
620 /// subset of super-predicates that reference traits that define the given associated type.
621 /// This is used to avoid cycles in resolving types like `T::Item`.
622 query super_predicates_that_define_assoc_type(key: (DefId, Option<rustc_span::symbol::Ident>)) -> ty::GenericPredicates<'tcx> {
623 desc { |tcx| "computing the super traits of `{}`{}",
624 tcx.def_path_str(key.0),
625 if let Some(assoc_name) = key.1 { format!(" with associated type name `{}`", assoc_name) } else { "".to_string() },
629 /// To avoid cycles within the predicates of a single item we compute
630 /// per-type-parameter predicates for resolving `T::AssocTy`.
631 query type_param_predicates(key: (DefId, LocalDefId, rustc_span::symbol::Ident)) -> ty::GenericPredicates<'tcx> {
632 desc { |tcx| "computing the bounds for type parameter `{}`", tcx.hir().ty_param_name(key.1) }
635 query trait_def(key: DefId) -> ty::TraitDef {
636 desc { |tcx| "computing trait definition for `{}`", tcx.def_path_str(key) }
638 cache_on_disk_if { key.is_local() }
639 separate_provide_extern
641 query adt_def(key: DefId) -> ty::AdtDef<'tcx> {
642 desc { |tcx| "computing ADT definition for `{}`", tcx.def_path_str(key) }
643 cache_on_disk_if { key.is_local() }
644 separate_provide_extern
646 query adt_destructor(key: DefId) -> Option<ty::Destructor> {
647 desc { |tcx| "computing `Drop` impl for `{}`", tcx.def_path_str(key) }
648 cache_on_disk_if { key.is_local() }
649 separate_provide_extern
652 query adt_sized_constraint(key: DefId) -> &'tcx [Ty<'tcx>] {
653 desc { |tcx| "computing `Sized` constraints for `{}`", tcx.def_path_str(key) }
656 query adt_dtorck_constraint(
658 ) -> Result<&'tcx DropckConstraint<'tcx>, NoSolution> {
659 desc { |tcx| "computing drop-check constraints for `{}`", tcx.def_path_str(key) }
662 /// Returns `true` if this is a const fn, use the `is_const_fn` to know whether your crate
663 /// actually sees it as const fn (e.g., the const-fn-ness might be unstable and you might
664 /// not have the feature gate active).
666 /// **Do not call this function manually.** It is only meant to cache the base data for the
667 /// `is_const_fn` function. Consider using `is_const_fn` or `is_const_fn_raw` instead.
668 query constness(key: DefId) -> hir::Constness {
669 desc { |tcx| "checking if item is const: `{}`", tcx.def_path_str(key) }
670 cache_on_disk_if { key.is_local() }
671 separate_provide_extern
674 query asyncness(key: DefId) -> hir::IsAsync {
675 desc { |tcx| "checking if the function is async: `{}`", tcx.def_path_str(key) }
676 cache_on_disk_if { key.is_local() }
677 separate_provide_extern
680 /// Returns `true` if calls to the function may be promoted.
682 /// This is either because the function is e.g., a tuple-struct or tuple-variant
683 /// constructor, or because it has the `#[rustc_promotable]` attribute. The attribute should
684 /// be removed in the future in favour of some form of check which figures out whether the
685 /// function does not inspect the bits of any of its arguments (so is essentially just a
686 /// constructor function).
687 query is_promotable_const_fn(key: DefId) -> bool {
688 desc { |tcx| "checking if item is promotable: `{}`", tcx.def_path_str(key) }
691 /// Returns `true` if this is a foreign item (i.e., linked via `extern { ... }`).
692 query is_foreign_item(key: DefId) -> bool {
693 desc { |tcx| "checking if `{}` is a foreign item", tcx.def_path_str(key) }
694 cache_on_disk_if { key.is_local() }
695 separate_provide_extern
698 /// Returns `Some(generator_kind)` if the node pointed to by `def_id` is a generator.
699 query generator_kind(def_id: DefId) -> Option<hir::GeneratorKind> {
700 desc { |tcx| "looking up generator kind of `{}`", tcx.def_path_str(def_id) }
701 cache_on_disk_if { def_id.is_local() }
702 separate_provide_extern
705 /// Gets a map with the variance of every item; use `item_variance` instead.
706 query crate_variances(_: ()) -> ty::CrateVariancesMap<'tcx> {
708 desc { "computing the variances for items in this crate" }
711 /// Maps from the `DefId` of a type or region parameter to its (inferred) variance.
712 query variances_of(def_id: DefId) -> &'tcx [ty::Variance] {
713 desc { |tcx| "computing the variances of `{}`", tcx.def_path_str(def_id) }
714 cache_on_disk_if { def_id.is_local() }
715 separate_provide_extern
718 /// Maps from thee `DefId` of a type to its (inferred) outlives.
719 query inferred_outlives_crate(_: ()) -> ty::CratePredicatesMap<'tcx> {
721 desc { "computing the inferred outlives predicates for items in this crate" }
724 /// Maps from an impl/trait `DefId` to a list of the `DefId`s of its items.
725 query associated_item_def_ids(key: DefId) -> &'tcx [DefId] {
726 desc { |tcx| "collecting associated items of `{}`", tcx.def_path_str(key) }
727 cache_on_disk_if { key.is_local() }
728 separate_provide_extern
731 /// Maps from a trait item to the trait item "descriptor".
732 query associated_item(key: DefId) -> ty::AssocItem {
733 desc { |tcx| "computing associated item data for `{}`", tcx.def_path_str(key) }
735 cache_on_disk_if { key.is_local() }
736 separate_provide_extern
739 /// Collects the associated items defined on a trait or impl.
740 query associated_items(key: DefId) -> ty::AssocItems<'tcx> {
742 desc { |tcx| "collecting associated items of `{}`", tcx.def_path_str(key) }
745 /// Maps from associated items on a trait to the corresponding associated
746 /// item on the impl specified by `impl_id`.
748 /// For example, with the following code
753 /// trait Trait { // trait_id
754 /// fn f(); // trait_f
755 /// fn g() {} // trait_g
758 /// impl Trait for Type { // impl_id
759 /// fn f() {} // impl_f
760 /// fn g() {} // impl_g
764 /// The map returned for `tcx.impl_item_implementor_ids(impl_id)` would be
765 ///`{ trait_f: impl_f, trait_g: impl_g }`
766 query impl_item_implementor_ids(impl_id: DefId) -> FxHashMap<DefId, DefId> {
768 desc { |tcx| "comparing impl items against trait for `{}`", tcx.def_path_str(impl_id) }
771 /// Given an `impl_id`, return the trait it implements.
772 /// Return `None` if this is an inherent impl.
773 query impl_trait_ref(impl_id: DefId) -> Option<ty::EarlyBinder<ty::TraitRef<'tcx>>> {
774 desc { |tcx| "computing trait implemented by `{}`", tcx.def_path_str(impl_id) }
775 cache_on_disk_if { impl_id.is_local() }
776 separate_provide_extern
778 query impl_polarity(impl_id: DefId) -> ty::ImplPolarity {
779 desc { |tcx| "computing implementation polarity of `{}`", tcx.def_path_str(impl_id) }
780 cache_on_disk_if { impl_id.is_local() }
781 separate_provide_extern
784 query issue33140_self_ty(key: DefId) -> Option<ty::Ty<'tcx>> {
785 desc { |tcx| "computing Self type wrt issue #33140 `{}`", tcx.def_path_str(key) }
788 /// Maps a `DefId` of a type to a list of its inherent impls.
789 /// Contains implementations of methods that are inherent to a type.
790 /// Methods in these implementations don't need to be exported.
791 query inherent_impls(key: DefId) -> &'tcx [DefId] {
792 desc { |tcx| "collecting inherent impls for `{}`", tcx.def_path_str(key) }
793 cache_on_disk_if { key.is_local() }
794 separate_provide_extern
797 query incoherent_impls(key: SimplifiedType) -> &'tcx [DefId] {
798 desc { |tcx| "collecting all inherent impls for `{:?}`", key }
801 /// The result of unsafety-checking this `LocalDefId`.
802 query unsafety_check_result(key: LocalDefId) -> &'tcx mir::UnsafetyCheckResult {
803 desc { |tcx| "unsafety-checking `{}`", tcx.def_path_str(key.to_def_id()) }
804 cache_on_disk_if { true }
806 query unsafety_check_result_for_const_arg(key: (LocalDefId, DefId)) -> &'tcx mir::UnsafetyCheckResult {
808 |tcx| "unsafety-checking the const argument `{}`",
809 tcx.def_path_str(key.0.to_def_id())
813 /// Unsafety-check this `LocalDefId` with THIR unsafeck. This should be
814 /// used with `-Zthir-unsafeck`.
815 query thir_check_unsafety(key: LocalDefId) {
816 desc { |tcx| "unsafety-checking `{}`", tcx.def_path_str(key.to_def_id()) }
817 cache_on_disk_if { true }
819 query thir_check_unsafety_for_const_arg(key: (LocalDefId, DefId)) {
821 |tcx| "unsafety-checking the const argument `{}`",
822 tcx.def_path_str(key.0.to_def_id())
826 /// Returns the types assumed to be well formed while "inside" of the given item.
828 /// Note that we've liberated the late bound regions of function signatures, so
829 /// this can not be used to check whether these types are well formed.
830 query assumed_wf_types(key: DefId) -> &'tcx ty::List<Ty<'tcx>> {
831 desc { |tcx| "computing the implied bounds of `{}`", tcx.def_path_str(key) }
834 /// Computes the signature of the function.
835 query fn_sig(key: DefId) -> ty::EarlyBinder<ty::PolyFnSig<'tcx>> {
836 desc { |tcx| "computing function signature of `{}`", tcx.def_path_str(key) }
837 cache_on_disk_if { key.is_local() }
838 separate_provide_extern
842 /// Performs lint checking for the module.
843 query lint_mod(key: LocalDefId) -> () {
844 desc { |tcx| "linting {}", describe_as_module(key, tcx) }
847 /// Checks the attributes in the module.
848 query check_mod_attrs(key: LocalDefId) -> () {
849 desc { |tcx| "checking attributes in {}", describe_as_module(key, tcx) }
852 /// Checks for uses of unstable APIs in the module.
853 query check_mod_unstable_api_usage(key: LocalDefId) -> () {
854 desc { |tcx| "checking for unstable API usage in {}", describe_as_module(key, tcx) }
857 /// Checks the const bodies in the module for illegal operations (e.g. `if` or `loop`).
858 query check_mod_const_bodies(key: LocalDefId) -> () {
859 desc { |tcx| "checking consts in {}", describe_as_module(key, tcx) }
862 /// Checks the loops in the module.
863 query check_mod_loops(key: LocalDefId) -> () {
864 desc { |tcx| "checking loops in {}", describe_as_module(key, tcx) }
867 query check_mod_naked_functions(key: LocalDefId) -> () {
868 desc { |tcx| "checking naked functions in {}", describe_as_module(key, tcx) }
871 query check_mod_item_types(key: LocalDefId) -> () {
872 desc { |tcx| "checking item types in {}", describe_as_module(key, tcx) }
875 query check_mod_privacy(key: LocalDefId) -> () {
876 desc { |tcx| "checking privacy in {}", describe_as_module(key, tcx) }
879 query check_liveness(key: DefId) {
880 desc { |tcx| "checking liveness of variables in `{}`", tcx.def_path_str(key) }
883 /// Return the live symbols in the crate for dead code check.
885 /// The second return value maps from ADTs to ignored derived traits (e.g. Debug and Clone) and
886 /// their respective impl (i.e., part of the derive macro)
887 query live_symbols_and_ignored_derived_traits(_: ()) -> (
888 FxHashSet<LocalDefId>,
889 FxHashMap<LocalDefId, Vec<(DefId, DefId)>>
892 desc { "finding live symbols in crate" }
895 query check_mod_deathness(key: LocalDefId) -> () {
896 desc { |tcx| "checking deathness of variables in {}", describe_as_module(key, tcx) }
899 query check_mod_impl_wf(key: LocalDefId) -> () {
900 desc { |tcx| "checking that impls are well-formed in {}", describe_as_module(key, tcx) }
903 query check_mod_type_wf(key: LocalDefId) -> () {
904 desc { |tcx| "checking that types are well-formed in {}", describe_as_module(key, tcx) }
907 query collect_mod_item_types(key: LocalDefId) -> () {
908 desc { |tcx| "collecting item types in {}", describe_as_module(key, tcx) }
911 /// Caches `CoerceUnsized` kinds for impls on custom types.
912 query coerce_unsized_info(key: DefId) -> ty::adjustment::CoerceUnsizedInfo {
913 desc { |tcx| "computing CoerceUnsized info for `{}`", tcx.def_path_str(key) }
914 cache_on_disk_if { key.is_local() }
915 separate_provide_extern
918 query typeck_item_bodies(_: ()) -> () {
919 desc { "type-checking all item bodies" }
922 query typeck(key: LocalDefId) -> &'tcx ty::TypeckResults<'tcx> {
923 desc { |tcx| "type-checking `{}`", tcx.def_path_str(key.to_def_id()) }
924 cache_on_disk_if { true }
926 query typeck_const_arg(
927 key: (LocalDefId, DefId)
928 ) -> &'tcx ty::TypeckResults<'tcx> {
930 |tcx| "type-checking the const argument `{}`",
931 tcx.def_path_str(key.0.to_def_id()),
934 query diagnostic_only_typeck(key: LocalDefId) -> &'tcx ty::TypeckResults<'tcx> {
935 desc { |tcx| "type-checking `{}`", tcx.def_path_str(key.to_def_id()) }
936 cache_on_disk_if { true }
939 query used_trait_imports(key: LocalDefId) -> &'tcx UnordSet<LocalDefId> {
940 desc { |tcx| "finding used_trait_imports `{}`", tcx.def_path_str(key.to_def_id()) }
941 cache_on_disk_if { true }
944 query has_typeck_results(def_id: DefId) -> bool {
945 desc { |tcx| "checking whether `{}` has a body", tcx.def_path_str(def_id) }
948 query coherent_trait(def_id: DefId) -> () {
949 desc { |tcx| "coherence checking all impls of trait `{}`", tcx.def_path_str(def_id) }
952 /// Borrow-checks the function body. If this is a closure, returns
953 /// additional requirements that the closure's creator must verify.
954 query mir_borrowck(key: LocalDefId) -> &'tcx mir::BorrowCheckResult<'tcx> {
955 desc { |tcx| "borrow-checking `{}`", tcx.def_path_str(key.to_def_id()) }
956 cache_on_disk_if(tcx) { tcx.is_typeck_child(key.to_def_id()) }
958 query mir_borrowck_const_arg(key: (LocalDefId, DefId)) -> &'tcx mir::BorrowCheckResult<'tcx> {
960 |tcx| "borrow-checking the const argument`{}`",
961 tcx.def_path_str(key.0.to_def_id())
965 /// Gets a complete map from all types to their inherent impls.
966 /// Not meant to be used directly outside of coherence.
967 query crate_inherent_impls(k: ()) -> CrateInherentImpls {
969 desc { "finding all inherent impls defined in crate" }
972 /// Checks all types in the crate for overlap in their inherent impls. Reports errors.
973 /// Not meant to be used directly outside of coherence.
974 query crate_inherent_impls_overlap_check(_: ()) -> () {
975 desc { "check for overlap between inherent impls defined in this crate" }
978 /// Checks whether all impls in the crate pass the overlap check, returning
979 /// which impls fail it. If all impls are correct, the returned slice is empty.
980 query orphan_check_impl(key: LocalDefId) -> Result<(), ErrorGuaranteed> {
982 "checking whether impl `{}` follows the orphan rules",
983 tcx.def_path_str(key.to_def_id()),
987 /// Check whether the function has any recursion that could cause the inliner to trigger
988 /// a cycle. Returns the call stack causing the cycle. The call stack does not contain the
989 /// current function, just all intermediate functions.
990 query mir_callgraph_reachable(key: (ty::Instance<'tcx>, LocalDefId)) -> bool {
993 "computing if `{}` (transitively) calls `{}`",
995 tcx.def_path_str(key.1.to_def_id()),
999 /// Obtain all the calls into other local functions
1000 query mir_inliner_callees(key: ty::InstanceDef<'tcx>) -> &'tcx [(DefId, SubstsRef<'tcx>)] {
1003 "computing all local function calls in `{}`",
1004 tcx.def_path_str(key.def_id()),
1008 /// Evaluates a constant and returns the computed allocation.
1010 /// **Do not use this** directly, use the `tcx.eval_static_initializer` wrapper.
1011 query eval_to_allocation_raw(key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>)
1012 -> EvalToAllocationRawResult<'tcx> {
1014 "const-evaluating + checking `{}`",
1015 key.value.display(tcx)
1017 cache_on_disk_if { true }
1020 /// Evaluates const items or anonymous constants
1021 /// (such as enum variant explicit discriminants or array lengths)
1022 /// into a representation suitable for the type system and const generics.
1024 /// **Do not use this** directly, use one of the following wrappers: `tcx.const_eval_poly`,
1025 /// `tcx.const_eval_resolve`, `tcx.const_eval_instance`, or `tcx.const_eval_global_id`.
1026 query eval_to_const_value_raw(key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>)
1027 -> EvalToConstValueResult<'tcx> {
1029 "simplifying constant for the type system `{}`",
1030 key.value.display(tcx)
1032 cache_on_disk_if { true }
1035 /// Evaluate a constant and convert it to a type level constant or
1036 /// return `None` if that is not possible.
1037 query eval_to_valtree(
1038 key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>
1039 ) -> EvalToValTreeResult<'tcx> {
1040 desc { "evaluating type-level constant" }
1043 /// Converts a type level constant value into `ConstValue`
1044 query valtree_to_const_val(key: (Ty<'tcx>, ty::ValTree<'tcx>)) -> ConstValue<'tcx> {
1045 desc { "converting type-level constant value to mir constant value"}
1048 /// Destructures array, ADT or tuple constants into the constants
1049 /// of their fields.
1050 query destructure_const(key: ty::Const<'tcx>) -> ty::DestructuredConst<'tcx> {
1051 desc { "destructuring type level constant"}
1054 /// Tries to destructure an `mir::ConstantKind` ADT or array into its variant index
1055 /// and its field values.
1056 query try_destructure_mir_constant(
1057 key: ty::ParamEnvAnd<'tcx, mir::ConstantKind<'tcx>>
1058 ) -> Option<mir::DestructuredConstant<'tcx>> {
1059 desc { "destructuring MIR constant"}
1063 /// Dereference a constant reference or raw pointer and turn the result into a constant
1065 query deref_mir_constant(
1066 key: ty::ParamEnvAnd<'tcx, mir::ConstantKind<'tcx>>
1067 ) -> mir::ConstantKind<'tcx> {
1068 desc { "dereferencing MIR constant" }
1072 query const_caller_location(key: (rustc_span::Symbol, u32, u32)) -> ConstValue<'tcx> {
1073 desc { "getting a &core::panic::Location referring to a span" }
1076 // FIXME get rid of this with valtrees
1078 key: LitToConstInput<'tcx>
1079 ) -> Result<ty::Const<'tcx>, LitToConstError> {
1080 desc { "converting literal to const" }
1083 query lit_to_mir_constant(key: LitToConstInput<'tcx>) -> Result<mir::ConstantKind<'tcx>, LitToConstError> {
1084 desc { "converting literal to mir constant" }
1087 query check_match(key: DefId) {
1088 desc { |tcx| "match-checking `{}`", tcx.def_path_str(key) }
1089 cache_on_disk_if { key.is_local() }
1092 /// Performs part of the privacy check and computes effective visibilities.
1093 query effective_visibilities(_: ()) -> &'tcx EffectiveVisibilities {
1095 desc { "checking effective visibilities" }
1097 query check_private_in_public(_: ()) -> () {
1099 desc { "checking for private elements in public interfaces" }
1102 query reachable_set(_: ()) -> FxHashSet<LocalDefId> {
1104 desc { "reachability" }
1107 /// Per-body `region::ScopeTree`. The `DefId` should be the owner `DefId` for the body;
1108 /// in the case of closures, this will be redirected to the enclosing function.
1109 query region_scope_tree(def_id: DefId) -> &'tcx crate::middle::region::ScopeTree {
1110 desc { |tcx| "computing drop scopes for `{}`", tcx.def_path_str(def_id) }
1113 /// Generates a MIR body for the shim.
1114 query mir_shims(key: ty::InstanceDef<'tcx>) -> mir::Body<'tcx> {
1116 desc { |tcx| "generating MIR shim for `{}`", tcx.def_path_str(key.def_id()) }
1119 /// The `symbol_name` query provides the symbol name for calling a
1120 /// given instance from the local crate. In particular, it will also
1121 /// look up the correct symbol name of instances from upstream crates.
1122 query symbol_name(key: ty::Instance<'tcx>) -> ty::SymbolName<'tcx> {
1123 desc { "computing the symbol for `{}`", key }
1124 cache_on_disk_if { true }
1127 query opt_def_kind(def_id: DefId) -> Option<DefKind> {
1128 desc { |tcx| "looking up definition kind of `{}`", tcx.def_path_str(def_id) }
1129 cache_on_disk_if { def_id.is_local() }
1130 separate_provide_extern
1133 /// Gets the span for the definition.
1134 query def_span(def_id: DefId) -> Span {
1135 desc { |tcx| "looking up span for `{}`", tcx.def_path_str(def_id) }
1136 cache_on_disk_if { def_id.is_local() }
1137 separate_provide_extern
1141 /// Gets the span for the identifier of the definition.
1142 query def_ident_span(def_id: DefId) -> Option<Span> {
1143 desc { |tcx| "looking up span for `{}`'s identifier", tcx.def_path_str(def_id) }
1144 cache_on_disk_if { def_id.is_local() }
1145 separate_provide_extern
1148 query lookup_stability(def_id: DefId) -> Option<attr::Stability> {
1149 desc { |tcx| "looking up stability of `{}`", tcx.def_path_str(def_id) }
1150 cache_on_disk_if { def_id.is_local() }
1151 separate_provide_extern
1154 query lookup_const_stability(def_id: DefId) -> Option<attr::ConstStability> {
1155 desc { |tcx| "looking up const stability of `{}`", tcx.def_path_str(def_id) }
1156 cache_on_disk_if { def_id.is_local() }
1157 separate_provide_extern
1160 query lookup_default_body_stability(def_id: DefId) -> Option<attr::DefaultBodyStability> {
1161 desc { |tcx| "looking up default body stability of `{}`", tcx.def_path_str(def_id) }
1162 separate_provide_extern
1165 query should_inherit_track_caller(def_id: DefId) -> bool {
1166 desc { |tcx| "computing should_inherit_track_caller of `{}`", tcx.def_path_str(def_id) }
1169 query lookup_deprecation_entry(def_id: DefId) -> Option<DeprecationEntry> {
1170 desc { |tcx| "checking whether `{}` is deprecated", tcx.def_path_str(def_id) }
1171 cache_on_disk_if { def_id.is_local() }
1172 separate_provide_extern
1175 /// Determines whether an item is annotated with `doc(hidden)`.
1176 query is_doc_hidden(def_id: DefId) -> bool {
1177 desc { |tcx| "checking whether `{}` is `doc(hidden)`", tcx.def_path_str(def_id) }
1178 separate_provide_extern
1181 /// Determines whether an item is annotated with `doc(notable_trait)`.
1182 query is_doc_notable_trait(def_id: DefId) -> bool {
1183 desc { |tcx| "checking whether `{}` is `doc(notable_trait)`", tcx.def_path_str(def_id) }
1186 /// Returns the attributes on the item at `def_id`.
1188 /// Do not use this directly, use `tcx.get_attrs` instead.
1189 query item_attrs(def_id: DefId) -> &'tcx [ast::Attribute] {
1190 desc { |tcx| "collecting attributes of `{}`", tcx.def_path_str(def_id) }
1191 separate_provide_extern
1194 query codegen_fn_attrs(def_id: DefId) -> CodegenFnAttrs {
1195 desc { |tcx| "computing codegen attributes of `{}`", tcx.def_path_str(def_id) }
1197 cache_on_disk_if { def_id.is_local() }
1198 separate_provide_extern
1201 query asm_target_features(def_id: DefId) -> &'tcx FxHashSet<Symbol> {
1202 desc { |tcx| "computing target features for inline asm of `{}`", tcx.def_path_str(def_id) }
1205 query fn_arg_names(def_id: DefId) -> &'tcx [rustc_span::symbol::Ident] {
1206 desc { |tcx| "looking up function parameter names for `{}`", tcx.def_path_str(def_id) }
1207 cache_on_disk_if { def_id.is_local() }
1208 separate_provide_extern
1210 /// Gets the rendered value of the specified constant or associated constant.
1211 /// Used by rustdoc.
1212 query rendered_const(def_id: DefId) -> String {
1214 desc { |tcx| "rendering constant initializer of `{}`", tcx.def_path_str(def_id) }
1215 cache_on_disk_if { def_id.is_local() }
1216 separate_provide_extern
1218 query impl_parent(def_id: DefId) -> Option<DefId> {
1219 desc { |tcx| "computing specialization parent impl of `{}`", tcx.def_path_str(def_id) }
1220 cache_on_disk_if { def_id.is_local() }
1221 separate_provide_extern
1224 query is_ctfe_mir_available(key: DefId) -> bool {
1225 desc { |tcx| "checking if item has CTFE MIR available: `{}`", tcx.def_path_str(key) }
1226 cache_on_disk_if { key.is_local() }
1227 separate_provide_extern
1229 query is_mir_available(key: DefId) -> bool {
1230 desc { |tcx| "checking if item has MIR available: `{}`", tcx.def_path_str(key) }
1231 cache_on_disk_if { key.is_local() }
1232 separate_provide_extern
1235 query own_existential_vtable_entries(
1237 ) -> &'tcx [DefId] {
1238 desc { |tcx| "finding all existential vtable entries for trait `{}`", tcx.def_path_str(key) }
1241 query vtable_entries(key: ty::PolyTraitRef<'tcx>)
1242 -> &'tcx [ty::VtblEntry<'tcx>] {
1243 desc { |tcx| "finding all vtable entries for trait `{}`", tcx.def_path_str(key.def_id()) }
1246 query vtable_trait_upcasting_coercion_new_vptr_slot(key: (Ty<'tcx>, Ty<'tcx>)) -> Option<usize> {
1247 desc { |tcx| "finding the slot within vtable for trait object `{}` vtable ptr during trait upcasting coercion from `{}` vtable",
1251 query vtable_allocation(key: (Ty<'tcx>, Option<ty::PolyExistentialTraitRef<'tcx>>)) -> mir::interpret::AllocId {
1252 desc { |tcx| "vtable const allocation for <{} as {}>",
1254 key.1.map(|trait_ref| format!("{}", trait_ref)).unwrap_or("_".to_owned())
1258 query codegen_select_candidate(
1259 key: (ty::ParamEnv<'tcx>, ty::PolyTraitRef<'tcx>)
1260 ) -> Result<&'tcx ImplSource<'tcx, ()>, traits::CodegenObligationError> {
1261 cache_on_disk_if { true }
1262 desc { |tcx| "computing candidate for `{}`", key.1 }
1265 /// Return all `impl` blocks in the current crate.
1266 query all_local_trait_impls(_: ()) -> &'tcx rustc_data_structures::fx::FxIndexMap<DefId, Vec<LocalDefId>> {
1267 desc { "finding local trait impls" }
1270 /// Given a trait `trait_id`, return all known `impl` blocks.
1271 query trait_impls_of(trait_id: DefId) -> ty::trait_def::TraitImpls {
1273 desc { |tcx| "finding trait impls of `{}`", tcx.def_path_str(trait_id) }
1276 query specialization_graph_of(trait_id: DefId) -> specialization_graph::Graph {
1278 desc { |tcx| "building specialization graph of trait `{}`", tcx.def_path_str(trait_id) }
1279 cache_on_disk_if { true }
1281 query object_safety_violations(trait_id: DefId) -> &'tcx [traits::ObjectSafetyViolation] {
1282 desc { |tcx| "determining object safety of trait `{}`", tcx.def_path_str(trait_id) }
1284 query check_is_object_safe(trait_id: DefId) -> bool {
1285 desc { |tcx| "checking if trait `{}` is object safe", tcx.def_path_str(trait_id) }
1288 /// Gets the ParameterEnvironment for a given item; this environment
1289 /// will be in "user-facing" mode, meaning that it is suitable for
1290 /// type-checking etc, and it does not normalize specializable
1291 /// associated types. This is almost always what you want,
1292 /// unless you are doing MIR optimizations, in which case you
1293 /// might want to use `reveal_all()` method to change modes.
1294 query param_env(def_id: DefId) -> ty::ParamEnv<'tcx> {
1295 desc { |tcx| "computing normalized predicates of `{}`", tcx.def_path_str(def_id) }
1298 /// Like `param_env`, but returns the `ParamEnv` in `Reveal::All` mode.
1299 /// Prefer this over `tcx.param_env(def_id).with_reveal_all_normalized(tcx)`,
1300 /// as this method is more efficient.
1301 query param_env_reveal_all_normalized(def_id: DefId) -> ty::ParamEnv<'tcx> {
1302 desc { |tcx| "computing revealed normalized predicates of `{}`", tcx.def_path_str(def_id) }
1305 /// Trait selection queries. These are best used by invoking `ty.is_copy_modulo_regions()`,
1306 /// `ty.is_copy()`, etc, since that will prune the environment where possible.
1307 query is_copy_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1308 desc { "computing whether `{}` is `Copy`", env.value }
1311 /// Query backing `Ty::is_sized`.
1312 query is_sized_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1313 desc { "computing whether `{}` is `Sized`", env.value }
1316 /// Query backing `Ty::is_freeze`.
1317 query is_freeze_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1318 desc { "computing whether `{}` is freeze", env.value }
1321 /// Query backing `Ty::is_unpin`.
1322 query is_unpin_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1323 desc { "computing whether `{}` is `Unpin`", env.value }
1326 /// Query backing `Ty::needs_drop`.
1327 query needs_drop_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1328 desc { "computing whether `{}` needs drop", env.value }
1331 /// Query backing `Ty::has_significant_drop_raw`.
1332 query has_significant_drop_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1333 desc { "computing whether `{}` has a significant drop", env.value }
1337 /// Query backing `Ty::is_structural_eq_shallow`.
1339 /// This is only correct for ADTs. Call `is_structural_eq_shallow` to handle all types
1341 query has_structural_eq_impls(ty: Ty<'tcx>) -> bool {
1343 "computing whether `{}` implements `PartialStructuralEq` and `StructuralEq`",
1348 /// A list of types where the ADT requires drop if and only if any of
1349 /// those types require drop. If the ADT is known to always need drop
1350 /// then `Err(AlwaysRequiresDrop)` is returned.
1351 query adt_drop_tys(def_id: DefId) -> Result<&'tcx ty::List<Ty<'tcx>>, AlwaysRequiresDrop> {
1352 desc { |tcx| "computing when `{}` needs drop", tcx.def_path_str(def_id) }
1353 cache_on_disk_if { true }
1356 /// A list of types where the ADT requires drop if and only if any of those types
1357 /// has significant drop. A type marked with the attribute `rustc_insignificant_dtor`
1358 /// is considered to not be significant. A drop is significant if it is implemented
1359 /// by the user or does anything that will have any observable behavior (other than
1360 /// freeing up memory). If the ADT is known to have a significant destructor then
1361 /// `Err(AlwaysRequiresDrop)` is returned.
1362 query adt_significant_drop_tys(def_id: DefId) -> Result<&'tcx ty::List<Ty<'tcx>>, AlwaysRequiresDrop> {
1363 desc { |tcx| "computing when `{}` has a significant destructor", tcx.def_path_str(def_id) }
1364 cache_on_disk_if { false }
1367 /// Computes the layout of a type. Note that this implicitly
1368 /// executes in "reveal all" mode, and will normalize the input type.
1370 key: ty::ParamEnvAnd<'tcx, Ty<'tcx>>
1371 ) -> Result<ty::layout::TyAndLayout<'tcx>, ty::layout::LayoutError<'tcx>> {
1373 desc { "computing layout of `{}`", key.value }
1377 /// Compute a `FnAbi` suitable for indirect calls, i.e. to `fn` pointers.
1379 /// NB: this doesn't handle virtual calls - those should use `fn_abi_of_instance`
1380 /// instead, where the instance is an `InstanceDef::Virtual`.
1381 query fn_abi_of_fn_ptr(
1382 key: ty::ParamEnvAnd<'tcx, (ty::PolyFnSig<'tcx>, &'tcx ty::List<Ty<'tcx>>)>
1383 ) -> Result<&'tcx abi::call::FnAbi<'tcx, Ty<'tcx>>, ty::layout::FnAbiError<'tcx>> {
1384 desc { "computing call ABI of `{}` function pointers", key.value.0 }
1388 /// Compute a `FnAbi` suitable for declaring/defining an `fn` instance, and for
1389 /// direct calls to an `fn`.
1391 /// NB: that includes virtual calls, which are represented by "direct calls"
1392 /// to an `InstanceDef::Virtual` instance (of `<dyn Trait as Trait>::fn`).
1393 query fn_abi_of_instance(
1394 key: ty::ParamEnvAnd<'tcx, (ty::Instance<'tcx>, &'tcx ty::List<Ty<'tcx>>)>
1395 ) -> Result<&'tcx abi::call::FnAbi<'tcx, Ty<'tcx>>, ty::layout::FnAbiError<'tcx>> {
1396 desc { "computing call ABI of `{}`", key.value.0 }
1400 query dylib_dependency_formats(_: CrateNum)
1401 -> &'tcx [(CrateNum, LinkagePreference)] {
1402 desc { "getting dylib dependency formats of crate" }
1403 separate_provide_extern
1406 query dependency_formats(_: ()) -> Lrc<crate::middle::dependency_format::Dependencies> {
1408 desc { "getting the linkage format of all dependencies" }
1411 query is_compiler_builtins(_: CrateNum) -> bool {
1413 desc { "checking if the crate is_compiler_builtins" }
1414 separate_provide_extern
1416 query has_global_allocator(_: CrateNum) -> bool {
1417 // This query depends on untracked global state in CStore
1420 desc { "checking if the crate has_global_allocator" }
1421 separate_provide_extern
1423 query has_alloc_error_handler(_: CrateNum) -> bool {
1424 // This query depends on untracked global state in CStore
1427 desc { "checking if the crate has_alloc_error_handler" }
1428 separate_provide_extern
1430 query has_panic_handler(_: CrateNum) -> bool {
1432 desc { "checking if the crate has_panic_handler" }
1433 separate_provide_extern
1435 query is_profiler_runtime(_: CrateNum) -> bool {
1437 desc { "checking if a crate is `#![profiler_runtime]`" }
1438 separate_provide_extern
1440 query has_ffi_unwind_calls(key: LocalDefId) -> bool {
1441 desc { |tcx| "checking if `{}` contains FFI-unwind calls", tcx.def_path_str(key.to_def_id()) }
1442 cache_on_disk_if { true }
1444 query required_panic_strategy(_: CrateNum) -> Option<PanicStrategy> {
1446 desc { "getting a crate's required panic strategy" }
1447 separate_provide_extern
1449 query panic_in_drop_strategy(_: CrateNum) -> PanicStrategy {
1451 desc { "getting a crate's configured panic-in-drop strategy" }
1452 separate_provide_extern
1454 query is_no_builtins(_: CrateNum) -> bool {
1456 desc { "getting whether a crate has `#![no_builtins]`" }
1457 separate_provide_extern
1459 query symbol_mangling_version(_: CrateNum) -> SymbolManglingVersion {
1461 desc { "getting a crate's symbol mangling version" }
1462 separate_provide_extern
1465 query extern_crate(def_id: DefId) -> Option<&'tcx ExternCrate> {
1467 desc { "getting crate's ExternCrateData" }
1468 separate_provide_extern
1471 query specializes(_: (DefId, DefId)) -> bool {
1472 desc { "computing whether impls specialize one another" }
1474 query in_scope_traits_map(_: hir::OwnerId)
1475 -> Option<&'tcx FxHashMap<ItemLocalId, Box<[TraitCandidate]>>> {
1476 desc { "getting traits in scope at a block" }
1479 query module_reexports(def_id: LocalDefId) -> Option<&'tcx [ModChild]> {
1480 desc { |tcx| "looking up reexports of module `{}`", tcx.def_path_str(def_id.to_def_id()) }
1483 query impl_defaultness(def_id: DefId) -> hir::Defaultness {
1484 desc { |tcx| "looking up whether `{}` is a default impl", tcx.def_path_str(def_id) }
1485 cache_on_disk_if { def_id.is_local() }
1486 separate_provide_extern
1489 query check_well_formed(key: hir::OwnerId) -> () {
1490 desc { |tcx| "checking that `{}` is well-formed", tcx.def_path_str(key.to_def_id()) }
1493 // The `DefId`s of all non-generic functions and statics in the given crate
1494 // that can be reached from outside the crate.
1496 // We expect this items to be available for being linked to.
1498 // This query can also be called for `LOCAL_CRATE`. In this case it will
1499 // compute which items will be reachable to other crates, taking into account
1500 // the kind of crate that is currently compiled. Crates with only a
1501 // C interface have fewer reachable things.
1503 // Does not include external symbols that don't have a corresponding DefId,
1504 // like the compiler-generated `main` function and so on.
1505 query reachable_non_generics(_: CrateNum)
1506 -> DefIdMap<SymbolExportInfo> {
1508 desc { "looking up the exported symbols of a crate" }
1509 separate_provide_extern
1511 query is_reachable_non_generic(def_id: DefId) -> bool {
1512 desc { |tcx| "checking whether `{}` is an exported symbol", tcx.def_path_str(def_id) }
1513 cache_on_disk_if { def_id.is_local() }
1514 separate_provide_extern
1516 query is_unreachable_local_definition(def_id: LocalDefId) -> bool {
1518 "checking whether `{}` is reachable from outside the crate",
1519 tcx.def_path_str(def_id.to_def_id()),
1523 /// The entire set of monomorphizations the local crate can safely link
1524 /// to because they are exported from upstream crates. Do not depend on
1525 /// this directly, as its value changes anytime a monomorphization gets
1526 /// added or removed in any upstream crate. Instead use the narrower
1527 /// `upstream_monomorphizations_for`, `upstream_drop_glue_for`, or, even
1528 /// better, `Instance::upstream_monomorphization()`.
1529 query upstream_monomorphizations(_: ()) -> DefIdMap<FxHashMap<SubstsRef<'tcx>, CrateNum>> {
1531 desc { "collecting available upstream monomorphizations" }
1534 /// Returns the set of upstream monomorphizations available for the
1535 /// generic function identified by the given `def_id`. The query makes
1536 /// sure to make a stable selection if the same monomorphization is
1537 /// available in multiple upstream crates.
1539 /// You likely want to call `Instance::upstream_monomorphization()`
1540 /// instead of invoking this query directly.
1541 query upstream_monomorphizations_for(def_id: DefId)
1542 -> Option<&'tcx FxHashMap<SubstsRef<'tcx>, CrateNum>>
1545 "collecting available upstream monomorphizations for `{}`",
1546 tcx.def_path_str(def_id),
1548 separate_provide_extern
1551 /// Returns the upstream crate that exports drop-glue for the given
1552 /// type (`substs` is expected to be a single-item list containing the
1553 /// type one wants drop-glue for).
1555 /// This is a subset of `upstream_monomorphizations_for` in order to
1556 /// increase dep-tracking granularity. Otherwise adding or removing any
1557 /// type with drop-glue in any upstream crate would invalidate all
1558 /// functions calling drop-glue of an upstream type.
1560 /// You likely want to call `Instance::upstream_monomorphization()`
1561 /// instead of invoking this query directly.
1563 /// NOTE: This query could easily be extended to also support other
1564 /// common functions that have are large set of monomorphizations
1565 /// (like `Clone::clone` for example).
1566 query upstream_drop_glue_for(substs: SubstsRef<'tcx>) -> Option<CrateNum> {
1567 desc { "available upstream drop-glue for `{:?}`", substs }
1570 /// Returns a list of all `extern` blocks of a crate.
1571 query foreign_modules(_: CrateNum) -> FxHashMap<DefId, ForeignModule> {
1573 desc { "looking up the foreign modules of a linked crate" }
1574 separate_provide_extern
1577 /// Identifies the entry-point (e.g., the `main` function) for a given
1578 /// crate, returning `None` if there is no entry point (such as for library crates).
1579 query entry_fn(_: ()) -> Option<(DefId, EntryFnType)> {
1580 desc { "looking up the entry function of a crate" }
1583 /// Finds the `rustc_proc_macro_decls` item of a crate.
1584 query proc_macro_decls_static(_: ()) -> Option<LocalDefId> {
1585 desc { "looking up the proc macro declarations for a crate" }
1588 // The macro which defines `rustc_metadata::provide_extern` depends on this query's name.
1589 // Changing the name should cause a compiler error, but in case that changes, be aware.
1590 query crate_hash(_: CrateNum) -> Svh {
1592 desc { "looking up the hash a crate" }
1593 separate_provide_extern
1596 /// Gets the hash for the host proc macro. Used to support -Z dual-proc-macro.
1597 query crate_host_hash(_: CrateNum) -> Option<Svh> {
1599 desc { "looking up the hash of a host version of a crate" }
1600 separate_provide_extern
1603 /// Gets the extra data to put in each output filename for a crate.
1604 /// For example, compiling the `foo` crate with `extra-filename=-a` creates a `libfoo-b.rlib` file.
1605 query extra_filename(_: CrateNum) -> String {
1608 desc { "looking up the extra filename for a crate" }
1609 separate_provide_extern
1612 /// Gets the paths where the crate came from in the file system.
1613 query crate_extern_paths(_: CrateNum) -> Vec<PathBuf> {
1616 desc { "looking up the paths for extern crates" }
1617 separate_provide_extern
1620 /// Given a crate and a trait, look up all impls of that trait in the crate.
1621 /// Return `(impl_id, self_ty)`.
1622 query implementations_of_trait(_: (CrateNum, DefId)) -> &'tcx [(DefId, Option<SimplifiedType>)] {
1623 desc { "looking up implementations of a trait in a crate" }
1624 separate_provide_extern
1627 /// Collects all incoherent impls for the given crate and type.
1629 /// Do not call this directly, but instead use the `incoherent_impls` query.
1630 /// This query is only used to get the data necessary for that query.
1631 query crate_incoherent_impls(key: (CrateNum, SimplifiedType)) -> &'tcx [DefId] {
1632 desc { |tcx| "collecting all impls for a type in a crate" }
1633 separate_provide_extern
1636 /// Get the corresponding native library from the `native_libraries` query
1637 query native_library(def_id: DefId) -> Option<&'tcx NativeLib> {
1638 desc { |tcx| "getting the native library for `{}`", tcx.def_path_str(def_id) }
1641 /// Does lifetime resolution on items. Importantly, we can't resolve
1642 /// lifetimes directly on things like trait methods, because of trait params.
1643 /// See `rustc_resolve::late::lifetimes for details.
1644 query resolve_lifetimes(_: hir::OwnerId) -> ResolveLifetimes {
1646 desc { "resolving lifetimes" }
1648 query named_region_map(_: hir::OwnerId) ->
1649 Option<&'tcx FxHashMap<ItemLocalId, Region>> {
1650 desc { "looking up a named region" }
1652 query is_late_bound_map(_: hir::OwnerId) -> Option<&'tcx FxIndexSet<ItemLocalId>> {
1653 desc { "testing if a region is late bound" }
1655 /// For a given item's generic parameter, gets the default lifetimes to be used
1656 /// for each parameter if a trait object were to be passed for that parameter.
1657 /// For example, for `T` in `struct Foo<'a, T>`, this would be `'static`.
1658 /// For `T` in `struct Foo<'a, T: 'a>`, this would instead be `'a`.
1659 /// This query will panic if passed something that is not a type parameter.
1660 query object_lifetime_default(key: DefId) -> ObjectLifetimeDefault {
1661 desc { "looking up lifetime defaults for generic parameter `{}`", tcx.def_path_str(key) }
1662 separate_provide_extern
1664 query late_bound_vars_map(_: hir::OwnerId)
1665 -> Option<&'tcx FxHashMap<ItemLocalId, Vec<ty::BoundVariableKind>>> {
1666 desc { "looking up late bound vars" }
1669 /// Computes the visibility of the provided `def_id`.
1671 /// If the item from the `def_id` doesn't have a visibility, it will panic. For example
1672 /// a generic type parameter will panic if you call this method on it:
1675 /// use std::fmt::Debug;
1677 /// pub trait Foo<T: Debug> {}
1680 /// In here, if you call `visibility` on `T`, it'll panic.
1681 query visibility(def_id: DefId) -> ty::Visibility<DefId> {
1682 desc { |tcx| "computing visibility of `{}`", tcx.def_path_str(def_id) }
1683 separate_provide_extern
1686 query inhabited_predicate_adt(key: DefId) -> ty::inhabitedness::InhabitedPredicate<'tcx> {
1687 desc { "computing the uninhabited predicate of `{:?}`", key }
1690 /// Do not call this query directly: invoke `Ty::inhabited_predicate` instead.
1691 query inhabited_predicate_type(key: Ty<'tcx>) -> ty::inhabitedness::InhabitedPredicate<'tcx> {
1692 desc { "computing the uninhabited predicate of `{}`", key }
1695 query dep_kind(_: CrateNum) -> CrateDepKind {
1697 desc { "fetching what a dependency looks like" }
1698 separate_provide_extern
1701 /// Gets the name of the crate.
1702 query crate_name(_: CrateNum) -> Symbol {
1704 desc { "fetching what a crate is named" }
1705 separate_provide_extern
1707 query module_children(def_id: DefId) -> &'tcx [ModChild] {
1708 desc { |tcx| "collecting child items of module `{}`", tcx.def_path_str(def_id) }
1709 separate_provide_extern
1711 query extern_mod_stmt_cnum(def_id: LocalDefId) -> Option<CrateNum> {
1712 desc { |tcx| "computing crate imported by `{}`", tcx.def_path_str(def_id.to_def_id()) }
1715 query lib_features(_: ()) -> LibFeatures {
1717 desc { "calculating the lib features map" }
1719 query defined_lib_features(_: CrateNum) -> &'tcx [(Symbol, Option<Symbol>)] {
1720 desc { "calculating the lib features defined in a crate" }
1721 separate_provide_extern
1723 query stability_implications(_: CrateNum) -> FxHashMap<Symbol, Symbol> {
1725 desc { "calculating the implications between `#[unstable]` features defined in a crate" }
1726 separate_provide_extern
1728 /// Whether the function is an intrinsic
1729 query is_intrinsic(def_id: DefId) -> bool {
1730 desc { |tcx| "checking whether `{}` is an intrinsic", tcx.def_path_str(def_id) }
1731 separate_provide_extern
1733 /// Returns the lang items defined in another crate by loading it from metadata.
1734 query get_lang_items(_: ()) -> LanguageItems {
1737 desc { "calculating the lang items map" }
1740 /// Returns all diagnostic items defined in all crates.
1741 query all_diagnostic_items(_: ()) -> rustc_hir::diagnostic_items::DiagnosticItems {
1744 desc { "calculating the diagnostic items map" }
1747 /// Returns the lang items defined in another crate by loading it from metadata.
1748 query defined_lang_items(_: CrateNum) -> &'tcx [(DefId, LangItem)] {
1749 desc { "calculating the lang items defined in a crate" }
1750 separate_provide_extern
1753 /// Returns the diagnostic items defined in a crate.
1754 query diagnostic_items(_: CrateNum) -> rustc_hir::diagnostic_items::DiagnosticItems {
1756 desc { "calculating the diagnostic items map in a crate" }
1757 separate_provide_extern
1760 query missing_lang_items(_: CrateNum) -> &'tcx [LangItem] {
1761 desc { "calculating the missing lang items in a crate" }
1762 separate_provide_extern
1764 query visible_parent_map(_: ()) -> DefIdMap<DefId> {
1766 desc { "calculating the visible parent map" }
1768 query trimmed_def_paths(_: ()) -> FxHashMap<DefId, Symbol> {
1770 desc { "calculating trimmed def paths" }
1772 query missing_extern_crate_item(_: CrateNum) -> bool {
1774 desc { "seeing if we're missing an `extern crate` item for this crate" }
1775 separate_provide_extern
1777 query used_crate_source(_: CrateNum) -> Lrc<CrateSource> {
1780 desc { "looking at the source for a crate" }
1781 separate_provide_extern
1783 /// Returns the debugger visualizers defined for this crate.
1784 query debugger_visualizers(_: CrateNum) -> Vec<rustc_span::DebuggerVisualizerFile> {
1786 desc { "looking up the debugger visualizers for this crate" }
1787 separate_provide_extern
1789 query postorder_cnums(_: ()) -> &'tcx [CrateNum] {
1791 desc { "generating a postorder list of CrateNums" }
1793 /// Returns whether or not the crate with CrateNum 'cnum'
1794 /// is marked as a private dependency
1795 query is_private_dep(c: CrateNum) -> bool {
1797 desc { "checking whether crate `{}` is a private dependency", c }
1798 separate_provide_extern
1800 query allocator_kind(_: ()) -> Option<AllocatorKind> {
1802 desc { "getting the allocator kind for the current crate" }
1804 query alloc_error_handler_kind(_: ()) -> Option<AllocatorKind> {
1806 desc { "alloc error handler kind for the current crate" }
1809 query upvars_mentioned(def_id: DefId) -> Option<&'tcx FxIndexMap<hir::HirId, hir::Upvar>> {
1810 desc { |tcx| "collecting upvars mentioned in `{}`", tcx.def_path_str(def_id) }
1812 query maybe_unused_trait_imports(_: ()) -> &'tcx FxIndexSet<LocalDefId> {
1813 desc { "fetching potentially unused trait imports" }
1815 query maybe_unused_extern_crates(_: ()) -> &'tcx [(LocalDefId, Span)] {
1816 desc { "looking up all possibly unused extern crates" }
1818 query names_imported_by_glob_use(def_id: LocalDefId) -> &'tcx FxHashSet<Symbol> {
1819 desc { |tcx| "finding names imported by glob use for `{}`", tcx.def_path_str(def_id.to_def_id()) }
1822 query stability_index(_: ()) -> stability::Index {
1825 desc { "calculating the stability index for the local crate" }
1827 query crates(_: ()) -> &'tcx [CrateNum] {
1829 desc { "fetching all foreign CrateNum instances" }
1832 /// A list of all traits in a crate, used by rustdoc and error reporting.
1833 /// NOTE: Not named just `traits` due to a naming conflict.
1834 query traits_in_crate(_: CrateNum) -> &'tcx [DefId] {
1835 desc { "fetching all traits in a crate" }
1836 separate_provide_extern
1839 /// The list of symbols exported from the given crate.
1841 /// - All names contained in `exported_symbols(cnum)` are guaranteed to
1842 /// correspond to a publicly visible symbol in `cnum` machine code.
1843 /// - The `exported_symbols` sets of different crates do not intersect.
1844 query exported_symbols(cnum: CrateNum) -> &'tcx [(ExportedSymbol<'tcx>, SymbolExportInfo)] {
1845 desc { "collecting exported symbols for crate `{}`", cnum}
1846 cache_on_disk_if { *cnum == LOCAL_CRATE }
1847 separate_provide_extern
1850 query collect_and_partition_mono_items(_: ()) -> (&'tcx DefIdSet, &'tcx [CodegenUnit<'tcx>]) {
1852 desc { "collect_and_partition_mono_items" }
1855 query is_codegened_item(def_id: DefId) -> bool {
1856 desc { |tcx| "determining whether `{}` needs codegen", tcx.def_path_str(def_id) }
1859 /// All items participating in code generation together with items inlined into them.
1860 query codegened_and_inlined_items(_: ()) -> &'tcx DefIdSet {
1862 desc { "collecting codegened and inlined items" }
1865 query codegen_unit(sym: Symbol) -> &'tcx CodegenUnit<'tcx> {
1866 desc { "getting codegen unit `{sym}`" }
1869 query unused_generic_params(key: ty::InstanceDef<'tcx>) -> UnusedGenericParams {
1870 cache_on_disk_if { key.def_id().is_local() }
1872 |tcx| "determining which generic parameters are unused by `{}`",
1873 tcx.def_path_str(key.def_id())
1875 separate_provide_extern
1878 query backend_optimization_level(_: ()) -> OptLevel {
1879 desc { "optimization level used by backend" }
1882 /// Return the filenames where output artefacts shall be stored.
1884 /// This query returns an `&Arc` because codegen backends need the value even after the `TyCtxt`
1885 /// has been destroyed.
1886 query output_filenames(_: ()) -> Arc<OutputFilenames> {
1888 desc { "getting output filenames" }
1892 /// Do not call this query directly: invoke `normalize` instead.
1893 query normalize_projection_ty(
1894 goal: CanonicalProjectionGoal<'tcx>
1896 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, NormalizationResult<'tcx>>>,
1899 desc { "normalizing `{}`", goal.value.value }
1903 /// Do not call this query directly: invoke `try_normalize_erasing_regions` instead.
1904 query try_normalize_generic_arg_after_erasing_regions(
1905 goal: ParamEnvAnd<'tcx, GenericArg<'tcx>>
1906 ) -> Result<GenericArg<'tcx>, NoSolution> {
1907 desc { "normalizing `{}`", goal.value }
1911 query implied_outlives_bounds(
1912 goal: CanonicalTyGoal<'tcx>
1914 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, Vec<OutlivesBound<'tcx>>>>,
1917 desc { "computing implied outlives bounds for `{}`", goal.value.value }
1921 /// Do not call this query directly:
1922 /// invoke `DropckOutlives::new(dropped_ty)).fully_perform(typeck.infcx)` instead.
1923 query dropck_outlives(
1924 goal: CanonicalTyGoal<'tcx>
1926 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, DropckOutlivesResult<'tcx>>>,
1929 desc { "computing dropck types for `{}`", goal.value.value }
1933 /// Do not call this query directly: invoke `infcx.predicate_may_hold()` or
1934 /// `infcx.predicate_must_hold()` instead.
1935 query evaluate_obligation(
1936 goal: CanonicalPredicateGoal<'tcx>
1937 ) -> Result<traits::EvaluationResult, traits::OverflowError> {
1938 desc { "evaluating trait selection obligation `{}`", goal.value.value }
1941 query evaluate_goal(
1942 goal: traits::CanonicalChalkEnvironmentAndGoal<'tcx>
1944 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1947 desc { "evaluating trait selection obligation `{}`", goal.value }
1950 /// Do not call this query directly: part of the `Eq` type-op
1951 query type_op_ascribe_user_type(
1952 goal: CanonicalTypeOpAscribeUserTypeGoal<'tcx>
1954 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1957 desc { "evaluating `type_op_ascribe_user_type` `{:?}`", goal.value.value }
1961 /// Do not call this query directly: part of the `Eq` type-op
1963 goal: CanonicalTypeOpEqGoal<'tcx>
1965 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1968 desc { "evaluating `type_op_eq` `{:?}`", goal.value.value }
1972 /// Do not call this query directly: part of the `Subtype` type-op
1973 query type_op_subtype(
1974 goal: CanonicalTypeOpSubtypeGoal<'tcx>
1976 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1979 desc { "evaluating `type_op_subtype` `{:?}`", goal.value.value }
1983 /// Do not call this query directly: part of the `ProvePredicate` type-op
1984 query type_op_prove_predicate(
1985 goal: CanonicalTypeOpProvePredicateGoal<'tcx>
1987 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1990 desc { "evaluating `type_op_prove_predicate` `{:?}`", goal.value.value }
1993 /// Do not call this query directly: part of the `Normalize` type-op
1994 query type_op_normalize_ty(
1995 goal: CanonicalTypeOpNormalizeGoal<'tcx, Ty<'tcx>>
1997 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, Ty<'tcx>>>,
2000 desc { "normalizing `{}`", goal.value.value.value }
2004 /// Do not call this query directly: part of the `Normalize` type-op
2005 query type_op_normalize_predicate(
2006 goal: CanonicalTypeOpNormalizeGoal<'tcx, ty::Predicate<'tcx>>
2008 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ty::Predicate<'tcx>>>,
2011 desc { "normalizing `{:?}`", goal.value.value.value }
2015 /// Do not call this query directly: part of the `Normalize` type-op
2016 query type_op_normalize_poly_fn_sig(
2017 goal: CanonicalTypeOpNormalizeGoal<'tcx, ty::PolyFnSig<'tcx>>
2019 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ty::PolyFnSig<'tcx>>>,
2022 desc { "normalizing `{:?}`", goal.value.value.value }
2026 /// Do not call this query directly: part of the `Normalize` type-op
2027 query type_op_normalize_fn_sig(
2028 goal: CanonicalTypeOpNormalizeGoal<'tcx, ty::FnSig<'tcx>>
2030 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ty::FnSig<'tcx>>>,
2033 desc { "normalizing `{:?}`", goal.value.value.value }
2037 query subst_and_check_impossible_predicates(key: (DefId, SubstsRef<'tcx>)) -> bool {
2039 "checking impossible substituted predicates: `{}`",
2040 tcx.def_path_str(key.0)
2044 query is_impossible_method(key: (DefId, DefId)) -> bool {
2046 "checking if `{}` is impossible to call within `{}`",
2047 tcx.def_path_str(key.1),
2048 tcx.def_path_str(key.0),
2052 query method_autoderef_steps(
2053 goal: CanonicalTyGoal<'tcx>
2054 ) -> MethodAutoderefStepsResult<'tcx> {
2055 desc { "computing autoderef types for `{}`", goal.value.value }
2059 query supported_target_features(_: CrateNum) -> FxHashMap<String, Option<Symbol>> {
2062 desc { "looking up supported target features" }
2065 /// Get an estimate of the size of an InstanceDef based on its MIR for CGU partitioning.
2066 query instance_def_size_estimate(def: ty::InstanceDef<'tcx>)
2068 desc { |tcx| "estimating size for `{}`", tcx.def_path_str(def.def_id()) }
2071 query features_query(_: ()) -> &'tcx rustc_feature::Features {
2073 desc { "looking up enabled feature gates" }
2076 /// Attempt to resolve the given `DefId` to an `Instance`, for the
2077 /// given generics args (`SubstsRef`), returning one of:
2078 /// * `Ok(Some(instance))` on success
2079 /// * `Ok(None)` when the `SubstsRef` are still too generic,
2080 /// and therefore don't allow finding the final `Instance`
2081 /// * `Err(ErrorGuaranteed)` when the `Instance` resolution process
2082 /// couldn't complete due to errors elsewhere - this is distinct
2083 /// from `Ok(None)` to avoid misleading diagnostics when an error
2084 /// has already been/will be emitted, for the original cause
2085 query resolve_instance(
2086 key: ty::ParamEnvAnd<'tcx, (DefId, SubstsRef<'tcx>)>
2087 ) -> Result<Option<ty::Instance<'tcx>>, ErrorGuaranteed> {
2088 desc { "resolving instance `{}`", ty::Instance::new(key.value.0, key.value.1) }
2092 query resolve_instance_of_const_arg(
2093 key: ty::ParamEnvAnd<'tcx, (LocalDefId, DefId, SubstsRef<'tcx>)>
2094 ) -> Result<Option<ty::Instance<'tcx>>, ErrorGuaranteed> {
2096 "resolving instance of the const argument `{}`",
2097 ty::Instance::new(key.value.0.to_def_id(), key.value.2),
2102 query reveal_opaque_types_in_bounds(key: &'tcx ty::List<ty::Predicate<'tcx>>) -> &'tcx ty::List<ty::Predicate<'tcx>> {
2103 desc { "revealing opaque types in `{:?}`", key }
2106 query limits(key: ()) -> Limits {
2107 desc { "looking up limits" }
2110 /// Performs an HIR-based well-formed check on the item with the given `HirId`. If
2111 /// we get an `Unimplemented` error that matches the provided `Predicate`, return
2112 /// the cause of the newly created obligation.
2114 /// This is only used by error-reporting code to get a better cause (in particular, a better
2115 /// span) for an *existing* error. Therefore, it is best-effort, and may never handle
2116 /// all of the cases that the normal `ty::Ty`-based wfcheck does. This is fine,
2117 /// because the `ty::Ty`-based wfcheck is always run.
2118 query diagnostic_hir_wf_check(key: (ty::Predicate<'tcx>, traits::WellFormedLoc)) -> Option<traits::ObligationCause<'tcx>> {
2122 desc { "performing HIR wf-checking for predicate `{:?}` at item `{:?}`", key.0, key.1 }
2126 /// The list of backend features computed from CLI flags (`-Ctarget-cpu`, `-Ctarget-feature`,
2127 /// `--target` and similar).
2128 query global_backend_features(_: ()) -> Vec<String> {
2131 desc { "computing the backend features for CLI flags" }
2134 query generator_diagnostic_data(key: DefId) -> Option<GeneratorDiagnosticData<'tcx>> {
2136 desc { |tcx| "looking up generator diagnostic data of `{}`", tcx.def_path_str(key) }
2137 separate_provide_extern
2140 query permits_uninit_init(key: ty::ParamEnvAnd<'tcx, TyAndLayout<'tcx>>) -> bool {
2141 desc { "checking to see if `{}` permits being left uninit", key.value.ty }
2144 query permits_zero_init(key: ty::ParamEnvAnd<'tcx, TyAndLayout<'tcx>>) -> bool {
2145 desc { "checking to see if `{}` permits being left zeroed", key.value.ty }
2148 query compare_impl_const(
2149 key: (LocalDefId, DefId)
2150 ) -> Result<(), ErrorGuaranteed> {
2151 desc { |tcx| "checking assoc const `{}` has the same type as trait item", tcx.def_path_str(key.0.to_def_id()) }
2154 query deduced_param_attrs(def_id: DefId) -> &'tcx [ty::DeducedParamAttrs] {
2155 desc { |tcx| "deducing parameter attributes for {}", tcx.def_path_str(def_id) }
2156 separate_provide_extern