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;
10 // Each of these queries corresponds to a function pointer field in the
11 // `Providers` struct for requesting a value of that type, and a method
12 // on `tcx: TyCtxt` (and `tcx.at(span)`) for doing that request in a way
13 // which memoizes and does dep-graph tracking, wrapping around the actual
14 // `Providers` that the driver creates (using several `rustc_*` crates).
16 // The result type of each query must implement `Clone`, and additionally
17 // `ty::query::values::Value`, which produces an appropriate placeholder
18 // (error) value if the query resulted in a query cycle.
19 // Queries marked with `fatal_cycle` do not need the latter implementation,
20 // as they will raise an fatal error on query cycles instead.
22 query trigger_delay_span_bug(key: DefId) -> () {
23 desc { "trigger a delay span bug" }
26 query resolutions(_: ()) -> &'tcx ty::ResolverOutputs {
29 desc { "get the resolver outputs" }
32 query resolver_for_lowering(_: ()) -> &'tcx Steal<ty::ResolverAstLowering> {
35 desc { "get the resolver for lowering" }
38 /// Return the span for a definition.
39 /// Contrary to `def_span` below, this query returns the full absolute span of the definition.
40 /// This span is meant for dep-tracking rather than diagnostics. It should not be used outside
41 /// of rustc_middle::hir::source_map.
42 query source_span(key: LocalDefId) -> Span {
43 desc { "get the source span" }
46 /// Represents crate as a whole (as distinct from the top-level crate module).
47 /// If you call `hir_crate` (e.g., indirectly by calling `tcx.hir().krate()`),
48 /// we will have to assume that any change means that you need to be recompiled.
49 /// This is because the `hir_crate` query gives you access to all other items.
50 /// To avoid this fate, do not call `tcx.hir().krate()`; instead,
51 /// prefer wrappers like `tcx.visit_all_items_in_krate()`.
52 query hir_crate(key: ()) -> Crate<'tcx> {
55 desc { "get the crate HIR" }
58 /// All items in the crate.
59 query hir_crate_items(_: ()) -> rustc_middle::hir::ModuleItems {
62 desc { "get HIR crate items" }
65 /// The items in a module.
67 /// This can be conveniently accessed by `tcx.hir().visit_item_likes_in_module`.
68 /// Avoid calling this query directly.
69 query hir_module_items(key: LocalDefId) -> rustc_middle::hir::ModuleItems {
71 desc { |tcx| "HIR module items in `{}`", tcx.def_path_str(key.to_def_id()) }
72 cache_on_disk_if { true }
75 /// Gives access to the HIR node for the HIR owner `key`.
77 /// This can be conveniently accessed by methods on `tcx.hir()`.
78 /// Avoid calling this query directly.
79 query hir_owner(key: hir::OwnerId) -> Option<crate::hir::Owner<'tcx>> {
80 desc { |tcx| "HIR owner of `{}`", tcx.def_path_str(key.to_def_id()) }
83 /// Gives access to the HIR ID for the given `LocalDefId` owner `key`.
85 /// This can be conveniently accessed by methods on `tcx.hir()`.
86 /// Avoid calling this query directly.
87 query local_def_id_to_hir_id(key: LocalDefId) -> hir::HirId {
88 desc { |tcx| "HIR ID of `{}`", tcx.def_path_str(key.to_def_id()) }
91 /// Gives access to the HIR node's parent for the HIR owner `key`.
93 /// This can be conveniently accessed by methods on `tcx.hir()`.
94 /// Avoid calling this query directly.
95 query hir_owner_parent(key: hir::OwnerId) -> hir::HirId {
96 desc { |tcx| "HIR parent of `{}`", tcx.def_path_str(key.to_def_id()) }
99 /// Gives access to the HIR nodes and bodies inside the HIR owner `key`.
101 /// This can be conveniently accessed by methods on `tcx.hir()`.
102 /// Avoid calling this query directly.
103 query hir_owner_nodes(key: hir::OwnerId) -> hir::MaybeOwner<&'tcx hir::OwnerNodes<'tcx>> {
104 desc { |tcx| "HIR owner items in `{}`", tcx.def_path_str(key.to_def_id()) }
107 /// Gives access to the HIR attributes inside the HIR owner `key`.
109 /// This can be conveniently accessed by methods on `tcx.hir()`.
110 /// Avoid calling this query directly.
111 query hir_attrs(key: hir::OwnerId) -> &'tcx hir::AttributeMap<'tcx> {
112 desc { |tcx| "HIR owner attributes in `{}`", tcx.def_path_str(key.to_def_id()) }
115 /// Computes the `DefId` of the corresponding const parameter in case the `key` is a
116 /// const argument and returns `None` otherwise.
118 /// ```ignore (incomplete)
119 /// let a = foo::<7>();
120 /// // ^ Calling `opt_const_param_of` for this argument,
122 /// fn foo<const N: usize>()
123 /// // ^ returns this `DefId`.
126 /// // ^ While calling `opt_const_param_of` for other bodies returns `None`.
129 // It looks like caching this query on disk actually slightly
130 // worsened performance in #74376.
132 // Once const generics are more prevalently used, we might want to
133 // consider only caching calls returning `Some`.
134 query opt_const_param_of(key: LocalDefId) -> Option<DefId> {
135 desc { |tcx| "computing the optional const parameter of `{}`", tcx.def_path_str(key.to_def_id()) }
138 /// Given the def_id of a const-generic parameter, computes the associated default const
139 /// parameter. e.g. `fn example<const N: usize=3>` called on `N` would return `3`.
140 query const_param_default(param: DefId) -> ty::Const<'tcx> {
141 desc { |tcx| "compute const default for a given parameter `{}`", tcx.def_path_str(param) }
142 cache_on_disk_if { param.is_local() }
143 separate_provide_extern
146 /// Returns the [`Ty`][rustc_middle::ty::Ty] of the given [`DefId`]. If the [`DefId`] points
147 /// to an alias, it will "skip" this alias to return the aliased type.
149 /// [`DefId`]: rustc_hir::def_id::DefId
150 query type_of(key: DefId) -> Ty<'tcx> {
154 use rustc_hir::def::DefKind;
155 match tcx.def_kind(key) {
156 DefKind::TyAlias => "expanding type alias",
157 DefKind::TraitAlias => "expanding trait alias",
158 _ => "computing type of",
161 path = tcx.def_path_str(key),
163 cache_on_disk_if { key.is_local() }
164 separate_provide_extern
167 query collect_trait_impl_trait_tys(key: DefId)
168 -> Result<&'tcx FxHashMap<DefId, Ty<'tcx>>, ErrorGuaranteed>
170 desc { "compare an impl and trait method signature, inferring any hidden `impl Trait` types in the process" }
171 cache_on_disk_if { key.is_local() }
172 separate_provide_extern
175 query analysis(key: ()) -> Result<(), ErrorGuaranteed> {
177 desc { "running analysis passes on this crate" }
180 /// This query checks the fulfillment of collected lint expectations.
181 /// All lint emitting queries have to be done before this is executed
182 /// to ensure that all expectations can be fulfilled.
184 /// This is an extra query to enable other drivers (like rustdoc) to
185 /// only execute a small subset of the `analysis` query, while allowing
186 /// lints to be expected. In rustc, this query will be executed as part of
187 /// the `analysis` query and doesn't have to be called a second time.
189 /// Tools can additionally pass in a tool filter. That will restrict the
190 /// expectations to only trigger for lints starting with the listed tool
191 /// name. This is useful for cases were not all linting code from rustc
192 /// was called. With the default `None` all registered lints will also
193 /// be checked for expectation fulfillment.
194 query check_expectations(key: Option<Symbol>) -> () {
196 desc { "checking lint expectations (RFC 2383)" }
199 /// Maps from the `DefId` of an item (trait/struct/enum/fn) to its
200 /// associated generics.
201 query generics_of(key: DefId) -> ty::Generics {
202 desc { |tcx| "computing generics of `{}`", tcx.def_path_str(key) }
204 cache_on_disk_if { key.is_local() }
205 separate_provide_extern
208 /// Maps from the `DefId` of an item (trait/struct/enum/fn) to the
209 /// predicates (where-clauses) that must be proven true in order
210 /// to reference it. This is almost always the "predicates query"
213 /// `predicates_of` builds on `predicates_defined_on` -- in fact,
214 /// it is almost always the same as that query, except for the
215 /// case of traits. For traits, `predicates_of` contains
216 /// an additional `Self: Trait<...>` predicate that users don't
217 /// actually write. This reflects the fact that to invoke the
218 /// trait (e.g., via `Default::default`) you must supply types
219 /// that actually implement the trait. (However, this extra
220 /// predicate gets in the way of some checks, which are intended
221 /// to operate over only the actual where-clauses written by the
223 query predicates_of(key: DefId) -> ty::GenericPredicates<'tcx> {
224 desc { |tcx| "computing predicates of `{}`", tcx.def_path_str(key) }
225 cache_on_disk_if { key.is_local() }
228 /// Returns the list of bounds that can be used for
229 /// `SelectionCandidate::ProjectionCandidate(_)` and
230 /// `ProjectionTyCandidate::TraitDef`.
231 /// Specifically this is the bounds written on the trait's type
232 /// definition, or those after the `impl` keyword
234 /// ```ignore (incomplete)
235 /// type X: Bound + 'lt
237 /// impl Debug + Display
238 /// // ^^^^^^^^^^^^^^^
241 /// `key` is the `DefId` of the associated type or opaque type.
243 /// Bounds from the parent (e.g. with nested impl trait) are not included.
244 query explicit_item_bounds(key: DefId) -> &'tcx [(ty::Predicate<'tcx>, Span)] {
245 desc { |tcx| "finding item bounds for `{}`", tcx.def_path_str(key) }
246 cache_on_disk_if { key.is_local() }
247 separate_provide_extern
250 /// Elaborated version of the predicates from `explicit_item_bounds`.
256 /// type MyAType: Eq + ?Sized;
260 /// `explicit_item_bounds` returns `[<Self as MyTrait>::MyAType: Eq]`,
261 /// and `item_bounds` returns
264 /// <Self as Trait>::MyAType: Eq,
265 /// <Self as Trait>::MyAType: PartialEq<<Self as Trait>::MyAType>
269 /// Bounds from the parent (e.g. with nested impl trait) are not included.
270 query item_bounds(key: DefId) -> &'tcx ty::List<ty::Predicate<'tcx>> {
271 desc { |tcx| "elaborating item bounds for `{}`", tcx.def_path_str(key) }
274 query native_libraries(_: CrateNum) -> Vec<NativeLib> {
276 desc { "looking up the native libraries of a linked crate" }
277 separate_provide_extern
280 query shallow_lint_levels_on(key: hir::OwnerId) -> rustc_middle::lint::ShallowLintLevelMap {
281 eval_always // fetches `resolutions`
283 desc { |tcx| "looking up lint levels for `{}`", tcx.def_path_str(key.to_def_id()) }
286 query lint_expectations(_: ()) -> Vec<(LintExpectationId, LintExpectation)> {
288 desc { "computing `#[expect]`ed lints in this crate" }
291 query parent_module_from_def_id(key: LocalDefId) -> LocalDefId {
293 desc { |tcx| "parent module of `{}`", tcx.def_path_str(key.to_def_id()) }
296 query expn_that_defined(key: DefId) -> rustc_span::ExpnId {
297 desc { |tcx| "expansion that defined `{}`", tcx.def_path_str(key) }
298 separate_provide_extern
301 query is_panic_runtime(_: CrateNum) -> bool {
303 desc { "checking if the crate is_panic_runtime" }
304 separate_provide_extern
307 /// Checks whether a type is representable or infinitely sized
308 query representability(_: LocalDefId) -> rustc_middle::ty::Representability {
309 desc { "checking if {:?} is representable", tcx.def_path_str(key.to_def_id()) }
310 // infinitely sized types will cause a cycle
312 // we don't want recursive representability calls to be forced with
313 // incremental compilation because, if a cycle occurs, we need the
314 // entire cycle to be in memory for diagnostics
318 /// An implementation detail for the `representability` query
319 query representability_adt_ty(_: Ty<'tcx>) -> rustc_middle::ty::Representability {
320 desc { "checking if {:?} is representable", key }
325 /// Set of param indexes for type params that are in the type's representation
326 query params_in_repr(key: DefId) -> rustc_index::bit_set::BitSet<u32> {
327 desc { "finding type parameters in the representation" }
330 separate_provide_extern
333 /// Fetch the THIR for a given body. If typeck for that body failed, returns an empty `Thir`.
334 query thir_body(key: ty::WithOptConstParam<LocalDefId>)
335 -> Result<(&'tcx Steal<thir::Thir<'tcx>>, thir::ExprId), ErrorGuaranteed>
337 // Perf tests revealed that hashing THIR is inefficient (see #85729).
339 desc { |tcx| "building THIR for `{}`", tcx.def_path_str(key.did.to_def_id()) }
342 /// Create a THIR tree for debugging.
343 query thir_tree(key: ty::WithOptConstParam<LocalDefId>) -> String {
346 desc { |tcx| "constructing THIR tree for `{}`", tcx.def_path_str(key.did.to_def_id()) }
349 /// Set of all the `DefId`s in this crate that have MIR associated with
350 /// them. This includes all the body owners, but also things like struct
352 query mir_keys(_: ()) -> rustc_data_structures::fx::FxIndexSet<LocalDefId> {
354 desc { "getting a list of all mir_keys" }
357 /// Maps DefId's that have an associated `mir::Body` to the result
358 /// of the MIR const-checking pass. This is the set of qualifs in
359 /// the final value of a `const`.
360 query mir_const_qualif(key: DefId) -> mir::ConstQualifs {
361 desc { |tcx| "const checking `{}`", tcx.def_path_str(key) }
362 cache_on_disk_if { key.is_local() }
363 separate_provide_extern
365 query mir_const_qualif_const_arg(
366 key: (LocalDefId, DefId)
367 ) -> mir::ConstQualifs {
369 |tcx| "const checking the const argument `{}`",
370 tcx.def_path_str(key.0.to_def_id())
374 /// Fetch the MIR for a given `DefId` right after it's built - this includes
375 /// unreachable code.
376 query mir_built(key: ty::WithOptConstParam<LocalDefId>) -> &'tcx Steal<mir::Body<'tcx>> {
377 desc { |tcx| "building MIR for `{}`", tcx.def_path_str(key.did.to_def_id()) }
380 /// Fetch the MIR for a given `DefId` up till the point where it is
381 /// ready for const qualification.
383 /// See the README for the `mir` module for details.
384 query mir_const(key: ty::WithOptConstParam<LocalDefId>) -> &'tcx Steal<mir::Body<'tcx>> {
386 |tcx| "processing MIR for {}`{}`",
387 if key.const_param_did.is_some() { "the const argument " } else { "" },
388 tcx.def_path_str(key.did.to_def_id()),
393 /// Try to build an abstract representation of the given constant.
394 query thir_abstract_const(
396 ) -> Result<Option<&'tcx [ty::abstract_const::Node<'tcx>]>, ErrorGuaranteed> {
398 |tcx| "building an abstract representation for {}", tcx.def_path_str(key),
400 separate_provide_extern
402 /// Try to build an abstract representation of the given constant.
403 query thir_abstract_const_of_const_arg(
404 key: (LocalDefId, DefId)
405 ) -> Result<Option<&'tcx [ty::abstract_const::Node<'tcx>]>, ErrorGuaranteed> {
408 "building an abstract representation for the const argument {}",
409 tcx.def_path_str(key.0.to_def_id()),
413 query try_unify_abstract_consts(key:
414 ty::ParamEnvAnd<'tcx, (ty::UnevaluatedConst<'tcx>, ty::UnevaluatedConst<'tcx>
417 |tcx| "trying to unify the generic constants {} and {}",
418 tcx.def_path_str(key.value.0.def.did), tcx.def_path_str(key.value.1.def.did)
422 query mir_drops_elaborated_and_const_checked(
423 key: ty::WithOptConstParam<LocalDefId>
424 ) -> &'tcx Steal<mir::Body<'tcx>> {
426 desc { |tcx| "elaborating drops for `{}`", tcx.def_path_str(key.did.to_def_id()) }
431 ) -> &'tcx mir::Body<'tcx> {
432 desc { |tcx| "caching mir of `{}` for CTFE", tcx.def_path_str(key) }
433 cache_on_disk_if { key.is_local() }
434 separate_provide_extern
437 query mir_for_ctfe_of_const_arg(key: (LocalDefId, DefId)) -> &'tcx mir::Body<'tcx> {
439 |tcx| "MIR for CTFE of the const argument `{}`",
440 tcx.def_path_str(key.0.to_def_id())
444 query mir_promoted(key: ty::WithOptConstParam<LocalDefId>) ->
446 &'tcx Steal<mir::Body<'tcx>>,
447 &'tcx Steal<IndexVec<mir::Promoted, mir::Body<'tcx>>>
451 |tcx| "processing {}`{}`",
452 if key.const_param_did.is_some() { "the const argument " } else { "" },
453 tcx.def_path_str(key.did.to_def_id()),
457 query symbols_for_closure_captures(
458 key: (LocalDefId, LocalDefId)
459 ) -> Vec<rustc_span::Symbol> {
462 |tcx| "symbols for captures of closure `{}` in `{}`",
463 tcx.def_path_str(key.1.to_def_id()),
464 tcx.def_path_str(key.0.to_def_id())
468 /// MIR after our optimization passes have run. This is MIR that is ready
469 /// for codegen. This is also the only query that can fetch non-local MIR, at present.
470 query optimized_mir(key: DefId) -> &'tcx mir::Body<'tcx> {
471 desc { |tcx| "optimizing MIR for `{}`", tcx.def_path_str(key) }
472 cache_on_disk_if { key.is_local() }
473 separate_provide_extern
476 /// Returns coverage summary info for a function, after executing the `InstrumentCoverage`
477 /// MIR pass (assuming the -Cinstrument-coverage option is enabled).
478 query coverageinfo(key: ty::InstanceDef<'tcx>) -> mir::CoverageInfo {
479 desc { |tcx| "retrieving coverage info from MIR for `{}`", tcx.def_path_str(key.def_id()) }
483 /// Returns the `CodeRegions` for a function that has instrumented coverage, in case the
484 /// function was optimized out before codegen, and before being added to the Coverage Map.
485 query covered_code_regions(key: DefId) -> Vec<&'tcx mir::coverage::CodeRegion> {
487 |tcx| "retrieving the covered `CodeRegion`s, if instrumented, for `{}`",
488 tcx.def_path_str(key)
491 cache_on_disk_if { key.is_local() }
494 /// The `DefId` is the `DefId` of the containing MIR body. Promoteds do not have their own
495 /// `DefId`. This function returns all promoteds in the specified body. The body references
496 /// promoteds by the `DefId` and the `mir::Promoted` index. This is necessary, because
497 /// after inlining a body may refer to promoteds from other bodies. In that case you still
498 /// need to use the `DefId` of the original body.
499 query promoted_mir(key: DefId) -> &'tcx IndexVec<mir::Promoted, mir::Body<'tcx>> {
500 desc { |tcx| "optimizing promoted MIR for `{}`", tcx.def_path_str(key) }
501 cache_on_disk_if { key.is_local() }
502 separate_provide_extern
504 query promoted_mir_of_const_arg(
505 key: (LocalDefId, DefId)
506 ) -> &'tcx IndexVec<mir::Promoted, mir::Body<'tcx>> {
508 |tcx| "optimizing promoted MIR for the const argument `{}`",
509 tcx.def_path_str(key.0.to_def_id()),
513 /// Erases regions from `ty` to yield a new type.
514 /// Normally you would just use `tcx.erase_regions(value)`,
515 /// however, which uses this query as a kind of cache.
516 query erase_regions_ty(ty: Ty<'tcx>) -> Ty<'tcx> {
517 // This query is not expected to have input -- as a result, it
518 // is not a good candidates for "replay" because it is essentially a
519 // pure function of its input (and hence the expectation is that
520 // no caller would be green **apart** from just these
521 // queries). Making it anonymous avoids hashing the result, which
522 // may save a bit of time.
524 desc { "erasing regions from `{:?}`", ty }
527 query wasm_import_module_map(_: CrateNum) -> FxHashMap<DefId, String> {
529 desc { "wasm import module map" }
532 /// Maps from the `DefId` of an item (trait/struct/enum/fn) to the
533 /// predicates (where-clauses) directly defined on it. This is
534 /// equal to the `explicit_predicates_of` predicates plus the
535 /// `inferred_outlives_of` predicates.
536 query predicates_defined_on(key: DefId) -> ty::GenericPredicates<'tcx> {
537 desc { |tcx| "computing predicates of `{}`", tcx.def_path_str(key) }
540 /// Returns everything that looks like a predicate written explicitly
541 /// by the user on a trait item.
543 /// Traits are unusual, because predicates on associated types are
544 /// converted into bounds on that type for backwards compatibility:
546 /// trait X where Self::U: Copy { type U; }
550 /// trait X { type U: Copy; }
552 /// `explicit_predicates_of` and `explicit_item_bounds` will then take
553 /// the appropriate subsets of the predicates here.
554 query trait_explicit_predicates_and_bounds(key: LocalDefId) -> ty::GenericPredicates<'tcx> {
555 desc { |tcx| "computing explicit predicates of trait `{}`", tcx.def_path_str(key.to_def_id()) }
558 /// Returns the predicates written explicitly by the user.
559 query explicit_predicates_of(key: DefId) -> ty::GenericPredicates<'tcx> {
560 desc { |tcx| "computing explicit predicates of `{}`", tcx.def_path_str(key) }
561 cache_on_disk_if { key.is_local() }
562 separate_provide_extern
565 /// Returns the inferred outlives predicates (e.g., for `struct
566 /// Foo<'a, T> { x: &'a T }`, this would return `T: 'a`).
567 query inferred_outlives_of(key: DefId) -> &'tcx [(ty::Predicate<'tcx>, Span)] {
568 desc { |tcx| "computing inferred outlives predicates of `{}`", tcx.def_path_str(key) }
569 cache_on_disk_if { key.is_local() }
570 separate_provide_extern
573 /// Maps from the `DefId` of a trait to the list of
574 /// super-predicates. This is a subset of the full list of
575 /// predicates. We store these in a separate map because we must
576 /// evaluate them even during type conversion, often before the
577 /// full predicates are available (note that supertraits have
578 /// additional acyclicity requirements).
579 query super_predicates_of(key: DefId) -> ty::GenericPredicates<'tcx> {
580 desc { |tcx| "computing the super predicates of `{}`", tcx.def_path_str(key) }
581 cache_on_disk_if { key.is_local() }
582 separate_provide_extern
585 /// The `Option<Ident>` is the name of an associated type. If it is `None`, then this query
586 /// returns the full set of predicates. If `Some<Ident>`, then the query returns only the
587 /// subset of super-predicates that reference traits that define the given associated type.
588 /// This is used to avoid cycles in resolving types like `T::Item`.
589 query super_predicates_that_define_assoc_type(key: (DefId, Option<rustc_span::symbol::Ident>)) -> ty::GenericPredicates<'tcx> {
590 desc { |tcx| "computing the super traits of `{}`{}",
591 tcx.def_path_str(key.0),
592 if let Some(assoc_name) = key.1 { format!(" with associated type name `{}`", assoc_name) } else { "".to_string() },
596 /// To avoid cycles within the predicates of a single item we compute
597 /// per-type-parameter predicates for resolving `T::AssocTy`.
598 query type_param_predicates(key: (DefId, LocalDefId, rustc_span::symbol::Ident)) -> ty::GenericPredicates<'tcx> {
599 desc { |tcx| "computing the bounds for type parameter `{}`", tcx.hir().ty_param_name(key.1) }
602 query trait_def(key: DefId) -> ty::TraitDef {
603 desc { |tcx| "computing trait definition for `{}`", tcx.def_path_str(key) }
605 cache_on_disk_if { key.is_local() }
606 separate_provide_extern
608 query adt_def(key: DefId) -> ty::AdtDef<'tcx> {
609 desc { |tcx| "computing ADT definition for `{}`", tcx.def_path_str(key) }
610 cache_on_disk_if { key.is_local() }
611 separate_provide_extern
613 query adt_destructor(key: DefId) -> Option<ty::Destructor> {
614 desc { |tcx| "computing `Drop` impl for `{}`", tcx.def_path_str(key) }
615 cache_on_disk_if { key.is_local() }
616 separate_provide_extern
619 query adt_sized_constraint(key: DefId) -> &'tcx [Ty<'tcx>] {
620 desc { |tcx| "computing `Sized` constraints for `{}`", tcx.def_path_str(key) }
623 query adt_dtorck_constraint(
625 ) -> Result<&'tcx DropckConstraint<'tcx>, NoSolution> {
626 desc { |tcx| "computing drop-check constraints for `{}`", tcx.def_path_str(key) }
629 /// Returns `true` if this is a const fn, use the `is_const_fn` to know whether your crate
630 /// actually sees it as const fn (e.g., the const-fn-ness might be unstable and you might
631 /// not have the feature gate active).
633 /// **Do not call this function manually.** It is only meant to cache the base data for the
634 /// `is_const_fn` function. Consider using `is_const_fn` or `is_const_fn_raw` instead.
635 query constness(key: DefId) -> hir::Constness {
636 desc { |tcx| "checking if item is const: `{}`", tcx.def_path_str(key) }
637 cache_on_disk_if { key.is_local() }
638 separate_provide_extern
641 query asyncness(key: DefId) -> hir::IsAsync {
642 desc { |tcx| "checking if the function is async: `{}`", tcx.def_path_str(key) }
643 cache_on_disk_if { key.is_local() }
644 separate_provide_extern
647 /// Returns `true` if calls to the function may be promoted.
649 /// This is either because the function is e.g., a tuple-struct or tuple-variant
650 /// constructor, or because it has the `#[rustc_promotable]` attribute. The attribute should
651 /// be removed in the future in favour of some form of check which figures out whether the
652 /// function does not inspect the bits of any of its arguments (so is essentially just a
653 /// constructor function).
654 query is_promotable_const_fn(key: DefId) -> bool {
655 desc { |tcx| "checking if item is promotable: `{}`", tcx.def_path_str(key) }
658 /// Returns `true` if this is a foreign item (i.e., linked via `extern { ... }`).
659 query is_foreign_item(key: DefId) -> bool {
660 desc { |tcx| "checking if `{}` is a foreign item", tcx.def_path_str(key) }
661 cache_on_disk_if { key.is_local() }
662 separate_provide_extern
665 /// Returns `Some(generator_kind)` if the node pointed to by `def_id` is a generator.
666 query generator_kind(def_id: DefId) -> Option<hir::GeneratorKind> {
667 desc { |tcx| "looking up generator kind of `{}`", tcx.def_path_str(def_id) }
668 cache_on_disk_if { def_id.is_local() }
669 separate_provide_extern
672 /// Gets a map with the variance of every item; use `item_variance` instead.
673 query crate_variances(_: ()) -> ty::CrateVariancesMap<'tcx> {
675 desc { "computing the variances for items in this crate" }
678 /// Maps from the `DefId` of a type or region parameter to its (inferred) variance.
679 query variances_of(def_id: DefId) -> &'tcx [ty::Variance] {
680 desc { |tcx| "computing the variances of `{}`", tcx.def_path_str(def_id) }
681 cache_on_disk_if { def_id.is_local() }
682 separate_provide_extern
685 /// Maps from thee `DefId` of a type to its (inferred) outlives.
686 query inferred_outlives_crate(_: ()) -> ty::CratePredicatesMap<'tcx> {
688 desc { "computing the inferred outlives predicates for items in this crate" }
691 /// Maps from an impl/trait `DefId` to a list of the `DefId`s of its items.
692 query associated_item_def_ids(key: DefId) -> &'tcx [DefId] {
693 desc { |tcx| "collecting associated items of `{}`", tcx.def_path_str(key) }
694 cache_on_disk_if { key.is_local() }
695 separate_provide_extern
698 /// Maps from a trait item to the trait item "descriptor".
699 query associated_item(key: DefId) -> ty::AssocItem {
700 desc { |tcx| "computing associated item data for `{}`", tcx.def_path_str(key) }
702 cache_on_disk_if { key.is_local() }
703 separate_provide_extern
706 /// Collects the associated items defined on a trait or impl.
707 query associated_items(key: DefId) -> ty::AssocItems<'tcx> {
709 desc { |tcx| "collecting associated items of {}", tcx.def_path_str(key) }
712 /// Maps from associated items on a trait to the corresponding associated
713 /// item on the impl specified by `impl_id`.
715 /// For example, with the following code
720 /// trait Trait { // trait_id
721 /// fn f(); // trait_f
722 /// fn g() {} // trait_g
725 /// impl Trait for Type { // impl_id
726 /// fn f() {} // impl_f
727 /// fn g() {} // impl_g
731 /// The map returned for `tcx.impl_item_implementor_ids(impl_id)` would be
732 ///`{ trait_f: impl_f, trait_g: impl_g }`
733 query impl_item_implementor_ids(impl_id: DefId) -> FxHashMap<DefId, DefId> {
735 desc { |tcx| "comparing impl items against trait for {}", tcx.def_path_str(impl_id) }
738 /// Given an `impl_id`, return the trait it implements.
739 /// Return `None` if this is an inherent impl.
740 query impl_trait_ref(impl_id: DefId) -> Option<ty::TraitRef<'tcx>> {
741 desc { |tcx| "computing trait implemented by `{}`", tcx.def_path_str(impl_id) }
742 cache_on_disk_if { impl_id.is_local() }
743 separate_provide_extern
745 query impl_polarity(impl_id: DefId) -> ty::ImplPolarity {
746 desc { |tcx| "computing implementation polarity of `{}`", tcx.def_path_str(impl_id) }
747 cache_on_disk_if { impl_id.is_local() }
748 separate_provide_extern
751 query issue33140_self_ty(key: DefId) -> Option<ty::Ty<'tcx>> {
752 desc { |tcx| "computing Self type wrt issue #33140 `{}`", tcx.def_path_str(key) }
755 /// Maps a `DefId` of a type to a list of its inherent impls.
756 /// Contains implementations of methods that are inherent to a type.
757 /// Methods in these implementations don't need to be exported.
758 query inherent_impls(key: DefId) -> &'tcx [DefId] {
759 desc { |tcx| "collecting inherent impls for `{}`", tcx.def_path_str(key) }
760 cache_on_disk_if { key.is_local() }
761 separate_provide_extern
764 query incoherent_impls(key: SimplifiedType) -> &'tcx [DefId] {
765 desc { |tcx| "collecting all inherent impls for `{:?}`", key }
768 /// The result of unsafety-checking this `LocalDefId`.
769 query unsafety_check_result(key: LocalDefId) -> &'tcx mir::UnsafetyCheckResult {
770 desc { |tcx| "unsafety-checking `{}`", tcx.def_path_str(key.to_def_id()) }
771 cache_on_disk_if { true }
773 query unsafety_check_result_for_const_arg(key: (LocalDefId, DefId)) -> &'tcx mir::UnsafetyCheckResult {
775 |tcx| "unsafety-checking the const argument `{}`",
776 tcx.def_path_str(key.0.to_def_id())
780 /// Unsafety-check this `LocalDefId` with THIR unsafeck. This should be
781 /// used with `-Zthir-unsafeck`.
782 query thir_check_unsafety(key: LocalDefId) {
783 desc { |tcx| "unsafety-checking `{}`", tcx.def_path_str(key.to_def_id()) }
784 cache_on_disk_if { true }
786 query thir_check_unsafety_for_const_arg(key: (LocalDefId, DefId)) {
788 |tcx| "unsafety-checking the const argument `{}`",
789 tcx.def_path_str(key.0.to_def_id())
793 /// HACK: when evaluated, this reports an "unsafe derive on repr(packed)" error.
795 /// Unsafety checking is executed for each method separately, but we only want
796 /// to emit this error once per derive. As there are some impls with multiple
797 /// methods, we use a query for deduplication.
798 query unsafe_derive_on_repr_packed(key: LocalDefId) -> () {
799 desc { |tcx| "processing `{}`", tcx.def_path_str(key.to_def_id()) }
802 /// Returns the types assumed to be well formed while "inside" of the given item.
804 /// Note that we've liberated the late bound regions of function signatures, so
805 /// this can not be used to check whether these types are well formed.
806 query assumed_wf_types(key: DefId) -> &'tcx ty::List<Ty<'tcx>> {
807 desc { |tcx| "computing the implied bounds of {}", tcx.def_path_str(key) }
810 /// Computes the signature of the function.
811 query fn_sig(key: DefId) -> ty::PolyFnSig<'tcx> {
812 desc { |tcx| "computing function signature of `{}`", tcx.def_path_str(key) }
813 cache_on_disk_if { key.is_local() }
814 separate_provide_extern
818 /// Performs lint checking for the module.
819 query lint_mod(key: LocalDefId) -> () {
820 desc { |tcx| "linting {}", describe_as_module(key, tcx) }
823 /// Checks the attributes in the module.
824 query check_mod_attrs(key: LocalDefId) -> () {
825 desc { |tcx| "checking attributes in {}", describe_as_module(key, tcx) }
828 /// Checks for uses of unstable APIs in the module.
829 query check_mod_unstable_api_usage(key: LocalDefId) -> () {
830 desc { |tcx| "checking for unstable API usage in {}", describe_as_module(key, tcx) }
833 /// Checks the const bodies in the module for illegal operations (e.g. `if` or `loop`).
834 query check_mod_const_bodies(key: LocalDefId) -> () {
835 desc { |tcx| "checking consts in {}", describe_as_module(key, tcx) }
838 /// Checks the loops in the module.
839 query check_mod_loops(key: LocalDefId) -> () {
840 desc { |tcx| "checking loops in {}", describe_as_module(key, tcx) }
843 query check_mod_naked_functions(key: LocalDefId) -> () {
844 desc { |tcx| "checking naked functions in {}", describe_as_module(key, tcx) }
847 query check_mod_item_types(key: LocalDefId) -> () {
848 desc { |tcx| "checking item types in {}", describe_as_module(key, tcx) }
851 query check_mod_privacy(key: LocalDefId) -> () {
852 desc { |tcx| "checking privacy in {}", describe_as_module(key, tcx) }
855 query check_liveness(key: DefId) {
856 desc { |tcx| "checking liveness of variables in {}", tcx.def_path_str(key) }
859 /// Return the live symbols in the crate for dead code check.
861 /// The second return value maps from ADTs to ignored derived traits (e.g. Debug and Clone) and
862 /// their respective impl (i.e., part of the derive macro)
863 query live_symbols_and_ignored_derived_traits(_: ()) -> (
864 FxHashSet<LocalDefId>,
865 FxHashMap<LocalDefId, Vec<(DefId, DefId)>>
868 desc { "find live symbols in crate" }
871 query check_mod_deathness(key: LocalDefId) -> () {
872 desc { |tcx| "checking deathness of variables in {}", describe_as_module(key, tcx) }
875 query check_mod_impl_wf(key: LocalDefId) -> () {
876 desc { |tcx| "checking that impls are well-formed in {}", describe_as_module(key, tcx) }
879 query check_mod_type_wf(key: LocalDefId) -> () {
880 desc { |tcx| "checking that types are well-formed in {}", describe_as_module(key, tcx) }
883 query collect_mod_item_types(key: LocalDefId) -> () {
884 desc { |tcx| "collecting item types in {}", describe_as_module(key, tcx) }
887 /// Caches `CoerceUnsized` kinds for impls on custom types.
888 query coerce_unsized_info(key: DefId) -> ty::adjustment::CoerceUnsizedInfo {
889 desc { |tcx| "computing CoerceUnsized info for `{}`", tcx.def_path_str(key) }
890 cache_on_disk_if { key.is_local() }
891 separate_provide_extern
894 query typeck_item_bodies(_: ()) -> () {
895 desc { "type-checking all item bodies" }
898 query typeck(key: LocalDefId) -> &'tcx ty::TypeckResults<'tcx> {
899 desc { |tcx| "type-checking `{}`", tcx.def_path_str(key.to_def_id()) }
900 cache_on_disk_if { true }
902 query typeck_const_arg(
903 key: (LocalDefId, DefId)
904 ) -> &'tcx ty::TypeckResults<'tcx> {
906 |tcx| "type-checking the const argument `{}`",
907 tcx.def_path_str(key.0.to_def_id()),
910 query diagnostic_only_typeck(key: LocalDefId) -> &'tcx ty::TypeckResults<'tcx> {
911 desc { |tcx| "type-checking `{}`", tcx.def_path_str(key.to_def_id()) }
912 cache_on_disk_if { true }
915 query used_trait_imports(key: LocalDefId) -> &'tcx FxHashSet<LocalDefId> {
916 desc { |tcx| "used_trait_imports `{}`", tcx.def_path_str(key.to_def_id()) }
917 cache_on_disk_if { true }
920 query has_typeck_results(def_id: DefId) -> bool {
921 desc { |tcx| "checking whether `{}` has a body", tcx.def_path_str(def_id) }
924 query coherent_trait(def_id: DefId) -> () {
925 desc { |tcx| "coherence checking all impls of trait `{}`", tcx.def_path_str(def_id) }
928 /// Borrow-checks the function body. If this is a closure, returns
929 /// additional requirements that the closure's creator must verify.
930 query mir_borrowck(key: LocalDefId) -> &'tcx mir::BorrowCheckResult<'tcx> {
931 desc { |tcx| "borrow-checking `{}`", tcx.def_path_str(key.to_def_id()) }
932 cache_on_disk_if(tcx) { tcx.is_typeck_child(key.to_def_id()) }
934 query mir_borrowck_const_arg(key: (LocalDefId, DefId)) -> &'tcx mir::BorrowCheckResult<'tcx> {
936 |tcx| "borrow-checking the const argument`{}`",
937 tcx.def_path_str(key.0.to_def_id())
941 /// Gets a complete map from all types to their inherent impls.
942 /// Not meant to be used directly outside of coherence.
943 query crate_inherent_impls(k: ()) -> CrateInherentImpls {
945 desc { "all inherent impls defined in crate" }
948 /// Checks all types in the crate for overlap in their inherent impls. Reports errors.
949 /// Not meant to be used directly outside of coherence.
950 query crate_inherent_impls_overlap_check(_: ()) -> () {
951 desc { "check for overlap between inherent impls defined in this crate" }
954 /// Checks whether all impls in the crate pass the overlap check, returning
955 /// which impls fail it. If all impls are correct, the returned slice is empty.
956 query orphan_check_impl(key: LocalDefId) -> Result<(), ErrorGuaranteed> {
958 "checking whether impl `{}` follows the orphan rules",
959 tcx.def_path_str(key.to_def_id()),
963 /// Check whether the function has any recursion that could cause the inliner to trigger
964 /// a cycle. Returns the call stack causing the cycle. The call stack does not contain the
965 /// current function, just all intermediate functions.
966 query mir_callgraph_reachable(key: (ty::Instance<'tcx>, LocalDefId)) -> bool {
969 "computing if `{}` (transitively) calls `{}`",
971 tcx.def_path_str(key.1.to_def_id()),
975 /// Obtain all the calls into other local functions
976 query mir_inliner_callees(key: ty::InstanceDef<'tcx>) -> &'tcx [(DefId, SubstsRef<'tcx>)] {
979 "computing all local function calls in `{}`",
980 tcx.def_path_str(key.def_id()),
984 /// Evaluates a constant and returns the computed allocation.
986 /// **Do not use this** directly, use the `tcx.eval_static_initializer` wrapper.
987 query eval_to_allocation_raw(key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>)
988 -> EvalToAllocationRawResult<'tcx> {
990 "const-evaluating + checking `{}`",
991 key.value.display(tcx)
993 cache_on_disk_if { true }
996 /// Evaluates const items or anonymous constants
997 /// (such as enum variant explicit discriminants or array lengths)
998 /// into a representation suitable for the type system and const generics.
1000 /// **Do not use this** directly, use one of the following wrappers: `tcx.const_eval_poly`,
1001 /// `tcx.const_eval_resolve`, `tcx.const_eval_instance`, or `tcx.const_eval_global_id`.
1002 query eval_to_const_value_raw(key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>)
1003 -> EvalToConstValueResult<'tcx> {
1005 "simplifying constant for the type system `{}`",
1006 key.value.display(tcx)
1008 cache_on_disk_if { true }
1011 /// Evaluate a constant and convert it to a type level constant or
1012 /// return `None` if that is not possible.
1013 query eval_to_valtree(
1014 key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>
1015 ) -> EvalToValTreeResult<'tcx> {
1016 desc { "evaluating type-level constant" }
1019 /// Converts a type level constant value into `ConstValue`
1020 query valtree_to_const_val(key: (Ty<'tcx>, ty::ValTree<'tcx>)) -> ConstValue<'tcx> {
1021 desc { "converting type-level constant value to mir constant value"}
1024 /// Destructures array, ADT or tuple constants into the constants
1025 /// of their fields.
1026 query destructure_const(key: ty::Const<'tcx>) -> ty::DestructuredConst<'tcx> {
1027 desc { "destructuring type level constant"}
1030 /// Tries to destructure an `mir::ConstantKind` ADT or array into its variant index
1031 /// and its field values.
1032 query try_destructure_mir_constant(
1033 key: ty::ParamEnvAnd<'tcx, mir::ConstantKind<'tcx>>
1034 ) -> Option<mir::DestructuredConstant<'tcx>> {
1035 desc { "destructuring mir constant"}
1039 /// Dereference a constant reference or raw pointer and turn the result into a constant
1041 query deref_mir_constant(
1042 key: ty::ParamEnvAnd<'tcx, mir::ConstantKind<'tcx>>
1043 ) -> mir::ConstantKind<'tcx> {
1044 desc { "dereferencing mir constant" }
1048 query const_caller_location(key: (rustc_span::Symbol, u32, u32)) -> ConstValue<'tcx> {
1049 desc { "get a &core::panic::Location referring to a span" }
1052 // FIXME get rid of this with valtrees
1054 key: LitToConstInput<'tcx>
1055 ) -> Result<ty::Const<'tcx>, LitToConstError> {
1056 desc { "converting literal to const" }
1059 query lit_to_mir_constant(key: LitToConstInput<'tcx>) -> Result<mir::ConstantKind<'tcx>, LitToConstError> {
1060 desc { "converting literal to mir constant" }
1063 query check_match(key: DefId) {
1064 desc { |tcx| "match-checking `{}`", tcx.def_path_str(key) }
1065 cache_on_disk_if { key.is_local() }
1068 /// Performs part of the privacy check and computes "access levels".
1069 query privacy_access_levels(_: ()) -> &'tcx AccessLevels {
1071 desc { "privacy access levels" }
1073 query check_private_in_public(_: ()) -> () {
1075 desc { "checking for private elements in public interfaces" }
1078 query reachable_set(_: ()) -> FxHashSet<LocalDefId> {
1080 desc { "reachability" }
1083 /// Per-body `region::ScopeTree`. The `DefId` should be the owner `DefId` for the body;
1084 /// in the case of closures, this will be redirected to the enclosing function.
1085 query region_scope_tree(def_id: DefId) -> &'tcx crate::middle::region::ScopeTree {
1086 desc { |tcx| "computing drop scopes for `{}`", tcx.def_path_str(def_id) }
1089 /// Generates a MIR body for the shim.
1090 query mir_shims(key: ty::InstanceDef<'tcx>) -> mir::Body<'tcx> {
1092 desc { |tcx| "generating MIR shim for `{}`", tcx.def_path_str(key.def_id()) }
1095 /// The `symbol_name` query provides the symbol name for calling a
1096 /// given instance from the local crate. In particular, it will also
1097 /// look up the correct symbol name of instances from upstream crates.
1098 query symbol_name(key: ty::Instance<'tcx>) -> ty::SymbolName<'tcx> {
1099 desc { "computing the symbol for `{}`", key }
1100 cache_on_disk_if { true }
1103 query opt_def_kind(def_id: DefId) -> Option<DefKind> {
1104 desc { |tcx| "looking up definition kind of `{}`", tcx.def_path_str(def_id) }
1105 cache_on_disk_if { def_id.is_local() }
1106 separate_provide_extern
1109 /// Gets the span for the definition.
1110 query def_span(def_id: DefId) -> Span {
1111 desc { |tcx| "looking up span for `{}`", tcx.def_path_str(def_id) }
1112 cache_on_disk_if { def_id.is_local() }
1113 separate_provide_extern
1116 /// Gets the span for the identifier of the definition.
1117 query def_ident_span(def_id: DefId) -> Option<Span> {
1118 desc { |tcx| "looking up span for `{}`'s identifier", tcx.def_path_str(def_id) }
1119 cache_on_disk_if { def_id.is_local() }
1120 separate_provide_extern
1123 query lookup_stability(def_id: DefId) -> Option<attr::Stability> {
1124 desc { |tcx| "looking up stability of `{}`", tcx.def_path_str(def_id) }
1125 cache_on_disk_if { def_id.is_local() }
1126 separate_provide_extern
1129 query lookup_const_stability(def_id: DefId) -> Option<attr::ConstStability> {
1130 desc { |tcx| "looking up const stability of `{}`", tcx.def_path_str(def_id) }
1131 cache_on_disk_if { def_id.is_local() }
1132 separate_provide_extern
1135 query lookup_default_body_stability(def_id: DefId) -> Option<attr::DefaultBodyStability> {
1136 desc { |tcx| "looking up default body stability of `{}`", tcx.def_path_str(def_id) }
1137 separate_provide_extern
1140 query should_inherit_track_caller(def_id: DefId) -> bool {
1141 desc { |tcx| "computing should_inherit_track_caller of `{}`", tcx.def_path_str(def_id) }
1144 query lookup_deprecation_entry(def_id: DefId) -> Option<DeprecationEntry> {
1145 desc { |tcx| "checking whether `{}` is deprecated", tcx.def_path_str(def_id) }
1146 cache_on_disk_if { def_id.is_local() }
1147 separate_provide_extern
1150 /// Determines whether an item is annotated with `doc(hidden)`.
1151 query is_doc_hidden(def_id: DefId) -> bool {
1152 desc { |tcx| "checking whether `{}` is `doc(hidden)`", tcx.def_path_str(def_id) }
1155 /// Determines whether an item is annotated with `doc(notable_trait)`.
1156 query is_doc_notable_trait(def_id: DefId) -> bool {
1157 desc { |tcx| "checking whether `{}` is `doc(notable_trait)`", tcx.def_path_str(def_id) }
1160 /// Returns the attributes on the item at `def_id`.
1162 /// Do not use this directly, use `tcx.get_attrs` instead.
1163 query item_attrs(def_id: DefId) -> &'tcx [ast::Attribute] {
1164 desc { |tcx| "collecting attributes of `{}`", tcx.def_path_str(def_id) }
1165 separate_provide_extern
1168 query codegen_fn_attrs(def_id: DefId) -> CodegenFnAttrs {
1169 desc { |tcx| "computing codegen attributes of `{}`", tcx.def_path_str(def_id) }
1171 cache_on_disk_if { def_id.is_local() }
1172 separate_provide_extern
1175 query asm_target_features(def_id: DefId) -> &'tcx FxHashSet<Symbol> {
1176 desc { |tcx| "computing target features for inline asm of `{}`", tcx.def_path_str(def_id) }
1179 query fn_arg_names(def_id: DefId) -> &'tcx [rustc_span::symbol::Ident] {
1180 desc { |tcx| "looking up function parameter names for `{}`", tcx.def_path_str(def_id) }
1181 cache_on_disk_if { def_id.is_local() }
1182 separate_provide_extern
1184 /// Gets the rendered value of the specified constant or associated constant.
1185 /// Used by rustdoc.
1186 query rendered_const(def_id: DefId) -> String {
1188 desc { |tcx| "rendering constant initializer of `{}`", tcx.def_path_str(def_id) }
1189 cache_on_disk_if { def_id.is_local() }
1190 separate_provide_extern
1192 query impl_parent(def_id: DefId) -> Option<DefId> {
1193 desc { |tcx| "computing specialization parent impl of `{}`", tcx.def_path_str(def_id) }
1194 cache_on_disk_if { def_id.is_local() }
1195 separate_provide_extern
1198 query is_ctfe_mir_available(key: DefId) -> bool {
1199 desc { |tcx| "checking if item has ctfe mir available: `{}`", tcx.def_path_str(key) }
1200 cache_on_disk_if { key.is_local() }
1201 separate_provide_extern
1203 query is_mir_available(key: DefId) -> bool {
1204 desc { |tcx| "checking if item has mir available: `{}`", tcx.def_path_str(key) }
1205 cache_on_disk_if { key.is_local() }
1206 separate_provide_extern
1209 query own_existential_vtable_entries(
1210 key: ty::PolyExistentialTraitRef<'tcx>
1211 ) -> &'tcx [DefId] {
1212 desc { |tcx| "finding all existential vtable entries for trait {}", tcx.def_path_str(key.def_id()) }
1215 query vtable_entries(key: ty::PolyTraitRef<'tcx>)
1216 -> &'tcx [ty::VtblEntry<'tcx>] {
1217 desc { |tcx| "finding all vtable entries for trait {}", tcx.def_path_str(key.def_id()) }
1220 query vtable_trait_upcasting_coercion_new_vptr_slot(key: (Ty<'tcx>, Ty<'tcx>)) -> Option<usize> {
1221 desc { |tcx| "finding the slot within vtable for trait object {} vtable ptr during trait upcasting coercion from {} vtable",
1225 query vtable_allocation(key: (Ty<'tcx>, Option<ty::PolyExistentialTraitRef<'tcx>>)) -> mir::interpret::AllocId {
1226 desc { |tcx| "vtable const allocation for <{} as {}>",
1228 key.1.map(|trait_ref| format!("{}", trait_ref)).unwrap_or("_".to_owned())
1232 query codegen_select_candidate(
1233 key: (ty::ParamEnv<'tcx>, ty::PolyTraitRef<'tcx>)
1234 ) -> Result<&'tcx ImplSource<'tcx, ()>, traits::CodegenObligationError> {
1235 cache_on_disk_if { true }
1236 desc { |tcx| "computing candidate for `{}`", key.1 }
1239 /// Return all `impl` blocks in the current crate.
1240 query all_local_trait_impls(_: ()) -> &'tcx rustc_data_structures::fx::FxIndexMap<DefId, Vec<LocalDefId>> {
1241 desc { "local trait impls" }
1244 /// Given a trait `trait_id`, return all known `impl` blocks.
1245 query trait_impls_of(trait_id: DefId) -> ty::trait_def::TraitImpls {
1247 desc { |tcx| "trait impls of `{}`", tcx.def_path_str(trait_id) }
1250 query specialization_graph_of(trait_id: DefId) -> specialization_graph::Graph {
1252 desc { |tcx| "building specialization graph of trait `{}`", tcx.def_path_str(trait_id) }
1253 cache_on_disk_if { true }
1255 query object_safety_violations(trait_id: DefId) -> &'tcx [traits::ObjectSafetyViolation] {
1256 desc { |tcx| "determine object safety of trait `{}`", tcx.def_path_str(trait_id) }
1259 /// Gets the ParameterEnvironment for a given item; this environment
1260 /// will be in "user-facing" mode, meaning that it is suitable for
1261 /// type-checking etc, and it does not normalize specializable
1262 /// associated types. This is almost always what you want,
1263 /// unless you are doing MIR optimizations, in which case you
1264 /// might want to use `reveal_all()` method to change modes.
1265 query param_env(def_id: DefId) -> ty::ParamEnv<'tcx> {
1266 desc { |tcx| "computing normalized predicates of `{}`", tcx.def_path_str(def_id) }
1269 /// Like `param_env`, but returns the `ParamEnv` in `Reveal::All` mode.
1270 /// Prefer this over `tcx.param_env(def_id).with_reveal_all_normalized(tcx)`,
1271 /// as this method is more efficient.
1272 query param_env_reveal_all_normalized(def_id: DefId) -> ty::ParamEnv<'tcx> {
1273 desc { |tcx| "computing revealed normalized predicates of `{}`", tcx.def_path_str(def_id) }
1276 /// Trait selection queries. These are best used by invoking `ty.is_copy_modulo_regions()`,
1277 /// `ty.is_copy()`, etc, since that will prune the environment where possible.
1278 query is_copy_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1279 desc { "computing whether `{}` is `Copy`", env.value }
1282 /// Query backing `Ty::is_sized`.
1283 query is_sized_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1284 desc { "computing whether `{}` is `Sized`", env.value }
1287 /// Query backing `Ty::is_freeze`.
1288 query is_freeze_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1289 desc { "computing whether `{}` is freeze", env.value }
1292 /// Query backing `Ty::is_unpin`.
1293 query is_unpin_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1294 desc { "computing whether `{}` is `Unpin`", env.value }
1297 /// Query backing `Ty::needs_drop`.
1298 query needs_drop_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1299 desc { "computing whether `{}` needs drop", env.value }
1302 /// Query backing `Ty::has_significant_drop_raw`.
1303 query has_significant_drop_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1304 desc { "computing whether `{}` has a significant drop", env.value }
1308 /// Query backing `Ty::is_structural_eq_shallow`.
1310 /// This is only correct for ADTs. Call `is_structural_eq_shallow` to handle all types
1312 query has_structural_eq_impls(ty: Ty<'tcx>) -> bool {
1314 "computing whether `{:?}` implements `PartialStructuralEq` and `StructuralEq`",
1319 /// A list of types where the ADT requires drop if and only if any of
1320 /// those types require drop. If the ADT is known to always need drop
1321 /// then `Err(AlwaysRequiresDrop)` is returned.
1322 query adt_drop_tys(def_id: DefId) -> Result<&'tcx ty::List<Ty<'tcx>>, AlwaysRequiresDrop> {
1323 desc { |tcx| "computing when `{}` needs drop", tcx.def_path_str(def_id) }
1324 cache_on_disk_if { true }
1327 /// A list of types where the ADT requires drop if and only if any of those types
1328 /// has significant drop. A type marked with the attribute `rustc_insignificant_dtor`
1329 /// is considered to not be significant. A drop is significant if it is implemented
1330 /// by the user or does anything that will have any observable behavior (other than
1331 /// freeing up memory). If the ADT is known to have a significant destructor then
1332 /// `Err(AlwaysRequiresDrop)` is returned.
1333 query adt_significant_drop_tys(def_id: DefId) -> Result<&'tcx ty::List<Ty<'tcx>>, AlwaysRequiresDrop> {
1334 desc { |tcx| "computing when `{}` has a significant destructor", tcx.def_path_str(def_id) }
1335 cache_on_disk_if { false }
1338 /// Computes the layout of a type. Note that this implicitly
1339 /// executes in "reveal all" mode, and will normalize the input type.
1341 key: ty::ParamEnvAnd<'tcx, Ty<'tcx>>
1342 ) -> Result<ty::layout::TyAndLayout<'tcx>, ty::layout::LayoutError<'tcx>> {
1344 desc { "computing layout of `{}`", key.value }
1348 /// Compute a `FnAbi` suitable for indirect calls, i.e. to `fn` pointers.
1350 /// NB: this doesn't handle virtual calls - those should use `fn_abi_of_instance`
1351 /// instead, where the instance is an `InstanceDef::Virtual`.
1352 query fn_abi_of_fn_ptr(
1353 key: ty::ParamEnvAnd<'tcx, (ty::PolyFnSig<'tcx>, &'tcx ty::List<Ty<'tcx>>)>
1354 ) -> Result<&'tcx abi::call::FnAbi<'tcx, Ty<'tcx>>, ty::layout::FnAbiError<'tcx>> {
1355 desc { "computing call ABI of `{}` function pointers", key.value.0 }
1359 /// Compute a `FnAbi` suitable for declaring/defining an `fn` instance, and for
1360 /// direct calls to an `fn`.
1362 /// NB: that includes virtual calls, which are represented by "direct calls"
1363 /// to an `InstanceDef::Virtual` instance (of `<dyn Trait as Trait>::fn`).
1364 query fn_abi_of_instance(
1365 key: ty::ParamEnvAnd<'tcx, (ty::Instance<'tcx>, &'tcx ty::List<Ty<'tcx>>)>
1366 ) -> Result<&'tcx abi::call::FnAbi<'tcx, Ty<'tcx>>, ty::layout::FnAbiError<'tcx>> {
1367 desc { "computing call ABI of `{}`", key.value.0 }
1371 query dylib_dependency_formats(_: CrateNum)
1372 -> &'tcx [(CrateNum, LinkagePreference)] {
1373 desc { "dylib dependency formats of crate" }
1374 separate_provide_extern
1377 query dependency_formats(_: ()) -> Lrc<crate::middle::dependency_format::Dependencies> {
1379 desc { "get the linkage format of all dependencies" }
1382 query is_compiler_builtins(_: CrateNum) -> bool {
1384 desc { "checking if the crate is_compiler_builtins" }
1385 separate_provide_extern
1387 query has_global_allocator(_: CrateNum) -> bool {
1388 // This query depends on untracked global state in CStore
1391 desc { "checking if the crate has_global_allocator" }
1392 separate_provide_extern
1394 query has_panic_handler(_: CrateNum) -> bool {
1396 desc { "checking if the crate has_panic_handler" }
1397 separate_provide_extern
1399 query is_profiler_runtime(_: CrateNum) -> bool {
1401 desc { "query a crate is `#![profiler_runtime]`" }
1402 separate_provide_extern
1404 query has_ffi_unwind_calls(key: LocalDefId) -> bool {
1405 desc { |tcx| "check if `{}` contains FFI-unwind calls", tcx.def_path_str(key.to_def_id()) }
1406 cache_on_disk_if { true }
1408 query required_panic_strategy(_: CrateNum) -> Option<PanicStrategy> {
1410 desc { "query a crate's required panic strategy" }
1411 separate_provide_extern
1413 query panic_in_drop_strategy(_: CrateNum) -> PanicStrategy {
1415 desc { "query a crate's configured panic-in-drop strategy" }
1416 separate_provide_extern
1418 query is_no_builtins(_: CrateNum) -> bool {
1420 desc { "test whether a crate has `#![no_builtins]`" }
1421 separate_provide_extern
1423 query symbol_mangling_version(_: CrateNum) -> SymbolManglingVersion {
1425 desc { "query a crate's symbol mangling version" }
1426 separate_provide_extern
1429 query extern_crate(def_id: DefId) -> Option<&'tcx ExternCrate> {
1431 desc { "getting crate's ExternCrateData" }
1432 separate_provide_extern
1435 query specializes(_: (DefId, DefId)) -> bool {
1436 desc { "computing whether impls specialize one another" }
1438 query in_scope_traits_map(_: hir::OwnerId)
1439 -> Option<&'tcx FxHashMap<ItemLocalId, Box<[TraitCandidate]>>> {
1440 desc { "traits in scope at a block" }
1443 query module_reexports(def_id: LocalDefId) -> Option<&'tcx [ModChild]> {
1444 desc { |tcx| "looking up reexports of module `{}`", tcx.def_path_str(def_id.to_def_id()) }
1447 query impl_defaultness(def_id: DefId) -> hir::Defaultness {
1448 desc { |tcx| "looking up whether `{}` is a default impl", tcx.def_path_str(def_id) }
1449 cache_on_disk_if { def_id.is_local() }
1450 separate_provide_extern
1453 query check_well_formed(key: hir::OwnerId) -> () {
1454 desc { |tcx| "checking that `{}` is well-formed", tcx.def_path_str(key.to_def_id()) }
1457 // The `DefId`s of all non-generic functions and statics in the given crate
1458 // that can be reached from outside the crate.
1460 // We expect this items to be available for being linked to.
1462 // This query can also be called for `LOCAL_CRATE`. In this case it will
1463 // compute which items will be reachable to other crates, taking into account
1464 // the kind of crate that is currently compiled. Crates with only a
1465 // C interface have fewer reachable things.
1467 // Does not include external symbols that don't have a corresponding DefId,
1468 // like the compiler-generated `main` function and so on.
1469 query reachable_non_generics(_: CrateNum)
1470 -> DefIdMap<SymbolExportInfo> {
1472 desc { "looking up the exported symbols of a crate" }
1473 separate_provide_extern
1475 query is_reachable_non_generic(def_id: DefId) -> bool {
1476 desc { |tcx| "checking whether `{}` is an exported symbol", tcx.def_path_str(def_id) }
1477 cache_on_disk_if { def_id.is_local() }
1478 separate_provide_extern
1480 query is_unreachable_local_definition(def_id: LocalDefId) -> bool {
1482 "checking whether `{}` is reachable from outside the crate",
1483 tcx.def_path_str(def_id.to_def_id()),
1487 /// The entire set of monomorphizations the local crate can safely link
1488 /// to because they are exported from upstream crates. Do not depend on
1489 /// this directly, as its value changes anytime a monomorphization gets
1490 /// added or removed in any upstream crate. Instead use the narrower
1491 /// `upstream_monomorphizations_for`, `upstream_drop_glue_for`, or, even
1492 /// better, `Instance::upstream_monomorphization()`.
1493 query upstream_monomorphizations(_: ()) -> DefIdMap<FxHashMap<SubstsRef<'tcx>, CrateNum>> {
1495 desc { "collecting available upstream monomorphizations" }
1498 /// Returns the set of upstream monomorphizations available for the
1499 /// generic function identified by the given `def_id`. The query makes
1500 /// sure to make a stable selection if the same monomorphization is
1501 /// available in multiple upstream crates.
1503 /// You likely want to call `Instance::upstream_monomorphization()`
1504 /// instead of invoking this query directly.
1505 query upstream_monomorphizations_for(def_id: DefId)
1506 -> Option<&'tcx FxHashMap<SubstsRef<'tcx>, CrateNum>>
1510 "collecting available upstream monomorphizations for `{}`",
1511 tcx.def_path_str(def_id),
1513 separate_provide_extern
1516 /// Returns the upstream crate that exports drop-glue for the given
1517 /// type (`substs` is expected to be a single-item list containing the
1518 /// type one wants drop-glue for).
1520 /// This is a subset of `upstream_monomorphizations_for` in order to
1521 /// increase dep-tracking granularity. Otherwise adding or removing any
1522 /// type with drop-glue in any upstream crate would invalidate all
1523 /// functions calling drop-glue of an upstream type.
1525 /// You likely want to call `Instance::upstream_monomorphization()`
1526 /// instead of invoking this query directly.
1528 /// NOTE: This query could easily be extended to also support other
1529 /// common functions that have are large set of monomorphizations
1530 /// (like `Clone::clone` for example).
1531 query upstream_drop_glue_for(substs: SubstsRef<'tcx>) -> Option<CrateNum> {
1532 desc { "available upstream drop-glue for `{:?}`", substs }
1535 query foreign_modules(_: CrateNum) -> FxHashMap<DefId, ForeignModule> {
1537 desc { "looking up the foreign modules of a linked crate" }
1538 separate_provide_extern
1541 /// Identifies the entry-point (e.g., the `main` function) for a given
1542 /// crate, returning `None` if there is no entry point (such as for library crates).
1543 query entry_fn(_: ()) -> Option<(DefId, EntryFnType)> {
1544 desc { "looking up the entry function of a crate" }
1546 query proc_macro_decls_static(_: ()) -> Option<LocalDefId> {
1547 desc { "looking up the derive registrar for a crate" }
1549 // The macro which defines `rustc_metadata::provide_extern` depends on this query's name.
1550 // Changing the name should cause a compiler error, but in case that changes, be aware.
1551 query crate_hash(_: CrateNum) -> Svh {
1553 desc { "looking up the hash a crate" }
1554 separate_provide_extern
1556 query crate_host_hash(_: CrateNum) -> Option<Svh> {
1558 desc { "looking up the hash of a host version of a crate" }
1559 separate_provide_extern
1561 query extra_filename(_: CrateNum) -> String {
1564 desc { "looking up the extra filename for a crate" }
1565 separate_provide_extern
1567 query crate_extern_paths(_: CrateNum) -> Vec<PathBuf> {
1570 desc { "looking up the paths for extern crates" }
1571 separate_provide_extern
1574 /// Given a crate and a trait, look up all impls of that trait in the crate.
1575 /// Return `(impl_id, self_ty)`.
1576 query implementations_of_trait(_: (CrateNum, DefId)) -> &'tcx [(DefId, Option<SimplifiedType>)] {
1577 desc { "looking up implementations of a trait in a crate" }
1578 separate_provide_extern
1581 /// Collects all incoherent impls for the given crate and type.
1583 /// Do not call this directly, but instead use the `incoherent_impls` query.
1584 /// This query is only used to get the data necessary for that query.
1585 query crate_incoherent_impls(key: (CrateNum, SimplifiedType)) -> &'tcx [DefId] {
1586 desc { |tcx| "collecting all impls for a type in a crate" }
1587 separate_provide_extern
1590 query is_dllimport_foreign_item(def_id: DefId) -> bool {
1591 desc { |tcx| "is_dllimport_foreign_item({})", tcx.def_path_str(def_id) }
1593 query is_statically_included_foreign_item(def_id: DefId) -> bool {
1594 desc { |tcx| "is_statically_included_foreign_item({})", tcx.def_path_str(def_id) }
1596 query native_library_kind(def_id: DefId)
1597 -> Option<NativeLibKind> {
1598 desc { |tcx| "native_library_kind({})", tcx.def_path_str(def_id) }
1600 query native_library(def_id: DefId) -> Option<&'tcx NativeLib> {
1601 desc { |tcx| "native_library({})", tcx.def_path_str(def_id) }
1604 /// Does lifetime resolution, but does not descend into trait items. This
1605 /// should only be used for resolving lifetimes of on trait definitions,
1606 /// and is used to avoid cycles. Importantly, `resolve_lifetimes` still visits
1607 /// the same lifetimes and is responsible for diagnostics.
1608 /// See `rustc_resolve::late::lifetimes for details.
1609 query resolve_lifetimes_trait_definition(_: LocalDefId) -> ResolveLifetimes {
1611 desc { "resolving lifetimes for a trait definition" }
1613 /// Does lifetime resolution on items. Importantly, we can't resolve
1614 /// lifetimes directly on things like trait methods, because of trait params.
1615 /// See `rustc_resolve::late::lifetimes for details.
1616 query resolve_lifetimes(_: LocalDefId) -> ResolveLifetimes {
1618 desc { "resolving lifetimes" }
1620 query named_region_map(_: hir::OwnerId) ->
1621 Option<&'tcx FxHashMap<ItemLocalId, Region>> {
1622 desc { "looking up a named region" }
1624 query is_late_bound_map(_: LocalDefId) -> Option<&'tcx FxIndexSet<LocalDefId>> {
1625 desc { "testing if a region is late bound" }
1627 /// For a given item's generic parameter, gets the default lifetimes to be used
1628 /// for each parameter if a trait object were to be passed for that parameter.
1629 /// For example, for `T` in `struct Foo<'a, T>`, this would be `'static`.
1630 /// For `T` in `struct Foo<'a, T: 'a>`, this would instead be `'a`.
1631 /// This query will panic if passed something that is not a type parameter.
1632 query object_lifetime_default(key: DefId) -> ObjectLifetimeDefault {
1633 desc { "looking up lifetime defaults for generic parameter `{}`", tcx.def_path_str(key) }
1634 separate_provide_extern
1636 query late_bound_vars_map(_: hir::OwnerId)
1637 -> Option<&'tcx FxHashMap<ItemLocalId, Vec<ty::BoundVariableKind>>> {
1638 desc { "looking up late bound vars" }
1641 /// Computes the visibility of the provided `def_id`.
1643 /// If the item from the `def_id` doesn't have a visibility, it will panic. For example
1644 /// a generic type parameter will panic if you call this method on it:
1647 /// pub trait Foo<T: Debug> {}
1650 /// In here, if you call `visibility` on `T`, it'll panic.
1651 query visibility(def_id: DefId) -> ty::Visibility<DefId> {
1652 desc { |tcx| "computing visibility of `{}`", tcx.def_path_str(def_id) }
1653 separate_provide_extern
1656 /// Computes the set of modules from which this type is visibly uninhabited.
1657 /// To check whether a type is uninhabited at all (not just from a given module), you could
1658 /// check whether the forest is empty.
1659 query type_uninhabited_from(
1660 key: ty::ParamEnvAnd<'tcx, Ty<'tcx>>
1661 ) -> ty::inhabitedness::DefIdForest<'tcx> {
1662 desc { "computing the inhabitedness of `{:?}`", key }
1666 query dep_kind(_: CrateNum) -> CrateDepKind {
1668 desc { "fetching what a dependency looks like" }
1669 separate_provide_extern
1672 /// Gets the name of the crate.
1673 query crate_name(_: CrateNum) -> Symbol {
1675 desc { "fetching what a crate is named" }
1676 separate_provide_extern
1678 query module_children(def_id: DefId) -> &'tcx [ModChild] {
1679 desc { |tcx| "collecting child items of module `{}`", tcx.def_path_str(def_id) }
1680 separate_provide_extern
1682 query extern_mod_stmt_cnum(def_id: LocalDefId) -> Option<CrateNum> {
1683 desc { |tcx| "computing crate imported by `{}`", tcx.def_path_str(def_id.to_def_id()) }
1686 query lib_features(_: ()) -> LibFeatures {
1688 desc { "calculating the lib features map" }
1690 query defined_lib_features(_: CrateNum) -> &'tcx [(Symbol, Option<Symbol>)] {
1691 desc { "calculating the lib features defined in a crate" }
1692 separate_provide_extern
1694 query stability_implications(_: CrateNum) -> FxHashMap<Symbol, Symbol> {
1696 desc { "calculating the implications between `#[unstable]` features defined in a crate" }
1697 separate_provide_extern
1699 /// Whether the function is an intrinsic
1700 query is_intrinsic(def_id: DefId) -> bool {
1701 desc { |tcx| "is_intrinsic({})", tcx.def_path_str(def_id) }
1702 separate_provide_extern
1704 /// Returns the lang items defined in another crate by loading it from metadata.
1705 query get_lang_items(_: ()) -> LanguageItems {
1708 desc { "calculating the lang items map" }
1711 /// Returns all diagnostic items defined in all crates.
1712 query all_diagnostic_items(_: ()) -> rustc_hir::diagnostic_items::DiagnosticItems {
1715 desc { "calculating the diagnostic items map" }
1718 /// Returns the lang items defined in another crate by loading it from metadata.
1719 query defined_lang_items(_: CrateNum) -> &'tcx [(DefId, usize)] {
1720 desc { "calculating the lang items defined in a crate" }
1721 separate_provide_extern
1724 /// Returns the diagnostic items defined in a crate.
1725 query diagnostic_items(_: CrateNum) -> rustc_hir::diagnostic_items::DiagnosticItems {
1727 desc { "calculating the diagnostic items map in a crate" }
1728 separate_provide_extern
1731 query missing_lang_items(_: CrateNum) -> &'tcx [LangItem] {
1732 desc { "calculating the missing lang items in a crate" }
1733 separate_provide_extern
1735 query visible_parent_map(_: ()) -> DefIdMap<DefId> {
1737 desc { "calculating the visible parent map" }
1739 query trimmed_def_paths(_: ()) -> FxHashMap<DefId, Symbol> {
1741 desc { "calculating trimmed def paths" }
1743 query missing_extern_crate_item(_: CrateNum) -> bool {
1745 desc { "seeing if we're missing an `extern crate` item for this crate" }
1746 separate_provide_extern
1748 query used_crate_source(_: CrateNum) -> Lrc<CrateSource> {
1751 desc { "looking at the source for a crate" }
1752 separate_provide_extern
1754 /// Returns the debugger visualizers defined for this crate.
1755 query debugger_visualizers(_: CrateNum) -> Vec<rustc_span::DebuggerVisualizerFile> {
1757 desc { "looking up the debugger visualizers for this crate" }
1758 separate_provide_extern
1760 query postorder_cnums(_: ()) -> &'tcx [CrateNum] {
1762 desc { "generating a postorder list of CrateNums" }
1764 /// Returns whether or not the crate with CrateNum 'cnum'
1765 /// is marked as a private dependency
1766 query is_private_dep(c: CrateNum) -> bool {
1768 desc { "check whether crate {} is a private dependency", c }
1769 separate_provide_extern
1771 query allocator_kind(_: ()) -> Option<AllocatorKind> {
1773 desc { "allocator kind for the current crate" }
1776 query upvars_mentioned(def_id: DefId) -> Option<&'tcx FxIndexMap<hir::HirId, hir::Upvar>> {
1777 desc { |tcx| "collecting upvars mentioned in `{}`", tcx.def_path_str(def_id) }
1779 query maybe_unused_trait_imports(_: ()) -> &'tcx FxIndexSet<LocalDefId> {
1780 desc { "fetching potentially unused trait imports" }
1782 query maybe_unused_extern_crates(_: ()) -> &'tcx [(LocalDefId, Span)] {
1783 desc { "looking up all possibly unused extern crates" }
1785 query names_imported_by_glob_use(def_id: LocalDefId) -> &'tcx FxHashSet<Symbol> {
1786 desc { |tcx| "names_imported_by_glob_use for `{}`", tcx.def_path_str(def_id.to_def_id()) }
1789 query stability_index(_: ()) -> stability::Index {
1792 desc { "calculating the stability index for the local crate" }
1794 query crates(_: ()) -> &'tcx [CrateNum] {
1796 desc { "fetching all foreign CrateNum instances" }
1799 /// A list of all traits in a crate, used by rustdoc and error reporting.
1800 /// NOTE: Not named just `traits` due to a naming conflict.
1801 query traits_in_crate(_: CrateNum) -> &'tcx [DefId] {
1802 desc { "fetching all traits in a crate" }
1803 separate_provide_extern
1806 /// The list of symbols exported from the given crate.
1808 /// - All names contained in `exported_symbols(cnum)` are guaranteed to
1809 /// correspond to a publicly visible symbol in `cnum` machine code.
1810 /// - The `exported_symbols` sets of different crates do not intersect.
1811 query exported_symbols(cnum: CrateNum) -> &'tcx [(ExportedSymbol<'tcx>, SymbolExportInfo)] {
1812 desc { "exported_symbols" }
1813 cache_on_disk_if { *cnum == LOCAL_CRATE }
1814 separate_provide_extern
1817 query collect_and_partition_mono_items(_: ()) -> (&'tcx DefIdSet, &'tcx [CodegenUnit<'tcx>]) {
1819 desc { "collect_and_partition_mono_items" }
1821 query is_codegened_item(def_id: DefId) -> bool {
1822 desc { |tcx| "determining whether `{}` needs codegen", tcx.def_path_str(def_id) }
1825 /// All items participating in code generation together with items inlined into them.
1826 query codegened_and_inlined_items(_: ()) -> &'tcx DefIdSet {
1828 desc { "codegened_and_inlined_items" }
1831 query codegen_unit(_: Symbol) -> &'tcx CodegenUnit<'tcx> {
1832 desc { "codegen_unit" }
1834 query unused_generic_params(key: ty::InstanceDef<'tcx>) -> FiniteBitSet<u32> {
1835 cache_on_disk_if { key.def_id().is_local() }
1837 |tcx| "determining which generic parameters are unused by `{}`",
1838 tcx.def_path_str(key.def_id())
1840 separate_provide_extern
1842 query backend_optimization_level(_: ()) -> OptLevel {
1843 desc { "optimization level used by backend" }
1846 /// Return the filenames where output artefacts shall be stored.
1848 /// This query returns an `&Arc` because codegen backends need the value even after the `TyCtxt`
1849 /// has been destroyed.
1850 query output_filenames(_: ()) -> &'tcx Arc<OutputFilenames> {
1852 desc { "output_filenames" }
1855 /// Do not call this query directly: invoke `normalize` instead.
1856 query normalize_projection_ty(
1857 goal: CanonicalProjectionGoal<'tcx>
1859 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, NormalizationResult<'tcx>>>,
1862 desc { "normalizing `{:?}`", goal }
1866 /// Do not call this query directly: invoke `try_normalize_erasing_regions` instead.
1867 query try_normalize_generic_arg_after_erasing_regions(
1868 goal: ParamEnvAnd<'tcx, GenericArg<'tcx>>
1869 ) -> Result<GenericArg<'tcx>, NoSolution> {
1870 desc { "normalizing `{}`", goal.value }
1874 /// Do not call this query directly: invoke `try_normalize_erasing_regions` instead.
1875 query try_normalize_mir_const_after_erasing_regions(
1876 goal: ParamEnvAnd<'tcx, mir::ConstantKind<'tcx>>
1877 ) -> Result<mir::ConstantKind<'tcx>, NoSolution> {
1878 desc { "normalizing `{}`", goal.value }
1882 query implied_outlives_bounds(
1883 goal: CanonicalTyGoal<'tcx>
1885 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, Vec<OutlivesBound<'tcx>>>>,
1888 desc { "computing implied outlives bounds for `{:?}`", goal }
1892 /// Do not call this query directly:
1893 /// invoke `DropckOutlives::new(dropped_ty)).fully_perform(typeck.infcx)` instead.
1894 query dropck_outlives(
1895 goal: CanonicalTyGoal<'tcx>
1897 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, DropckOutlivesResult<'tcx>>>,
1900 desc { "computing dropck types for `{:?}`", goal }
1904 /// Do not call this query directly: invoke `infcx.predicate_may_hold()` or
1905 /// `infcx.predicate_must_hold()` instead.
1906 query evaluate_obligation(
1907 goal: CanonicalPredicateGoal<'tcx>
1908 ) -> Result<traits::EvaluationResult, traits::OverflowError> {
1909 desc { "evaluating trait selection obligation `{}`", goal.value.value }
1912 query evaluate_goal(
1913 goal: traits::CanonicalChalkEnvironmentAndGoal<'tcx>
1915 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1918 desc { "evaluating trait selection obligation `{}`", goal.value }
1921 /// Do not call this query directly: part of the `Eq` type-op
1922 query type_op_ascribe_user_type(
1923 goal: CanonicalTypeOpAscribeUserTypeGoal<'tcx>
1925 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1928 desc { "evaluating `type_op_ascribe_user_type` `{:?}`", goal }
1932 /// Do not call this query directly: part of the `Eq` type-op
1934 goal: CanonicalTypeOpEqGoal<'tcx>
1936 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1939 desc { "evaluating `type_op_eq` `{:?}`", goal }
1943 /// Do not call this query directly: part of the `Subtype` type-op
1944 query type_op_subtype(
1945 goal: CanonicalTypeOpSubtypeGoal<'tcx>
1947 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1950 desc { "evaluating `type_op_subtype` `{:?}`", goal }
1954 /// Do not call this query directly: part of the `ProvePredicate` type-op
1955 query type_op_prove_predicate(
1956 goal: CanonicalTypeOpProvePredicateGoal<'tcx>
1958 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1961 desc { "evaluating `type_op_prove_predicate` `{:?}`", goal }
1964 /// Do not call this query directly: part of the `Normalize` type-op
1965 query type_op_normalize_ty(
1966 goal: CanonicalTypeOpNormalizeGoal<'tcx, Ty<'tcx>>
1968 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, Ty<'tcx>>>,
1971 desc { "normalizing `{:?}`", goal }
1975 /// Do not call this query directly: part of the `Normalize` type-op
1976 query type_op_normalize_predicate(
1977 goal: CanonicalTypeOpNormalizeGoal<'tcx, ty::Predicate<'tcx>>
1979 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ty::Predicate<'tcx>>>,
1982 desc { "normalizing `{:?}`", goal }
1986 /// Do not call this query directly: part of the `Normalize` type-op
1987 query type_op_normalize_poly_fn_sig(
1988 goal: CanonicalTypeOpNormalizeGoal<'tcx, ty::PolyFnSig<'tcx>>
1990 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ty::PolyFnSig<'tcx>>>,
1993 desc { "normalizing `{:?}`", goal }
1997 /// Do not call this query directly: part of the `Normalize` type-op
1998 query type_op_normalize_fn_sig(
1999 goal: CanonicalTypeOpNormalizeGoal<'tcx, ty::FnSig<'tcx>>
2001 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ty::FnSig<'tcx>>>,
2004 desc { "normalizing `{:?}`", goal }
2008 query subst_and_check_impossible_predicates(key: (DefId, SubstsRef<'tcx>)) -> bool {
2010 "impossible substituted predicates:`{}`",
2011 tcx.def_path_str(key.0)
2015 query is_impossible_method(key: (DefId, DefId)) -> bool {
2017 "checking if {} is impossible to call within {}",
2018 tcx.def_path_str(key.1),
2019 tcx.def_path_str(key.0),
2023 query method_autoderef_steps(
2024 goal: CanonicalTyGoal<'tcx>
2025 ) -> MethodAutoderefStepsResult<'tcx> {
2026 desc { "computing autoderef types for `{:?}`", goal }
2030 query supported_target_features(_: CrateNum) -> FxHashMap<String, Option<Symbol>> {
2033 desc { "looking up supported target features" }
2036 /// Get an estimate of the size of an InstanceDef based on its MIR for CGU partitioning.
2037 query instance_def_size_estimate(def: ty::InstanceDef<'tcx>)
2039 desc { |tcx| "estimating size for `{}`", tcx.def_path_str(def.def_id()) }
2042 query features_query(_: ()) -> &'tcx rustc_feature::Features {
2044 desc { "looking up enabled feature gates" }
2047 /// Attempt to resolve the given `DefId` to an `Instance`, for the
2048 /// given generics args (`SubstsRef`), returning one of:
2049 /// * `Ok(Some(instance))` on success
2050 /// * `Ok(None)` when the `SubstsRef` are still too generic,
2051 /// and therefore don't allow finding the final `Instance`
2052 /// * `Err(ErrorGuaranteed)` when the `Instance` resolution process
2053 /// couldn't complete due to errors elsewhere - this is distinct
2054 /// from `Ok(None)` to avoid misleading diagnostics when an error
2055 /// has already been/will be emitted, for the original cause
2056 query resolve_instance(
2057 key: ty::ParamEnvAnd<'tcx, (DefId, SubstsRef<'tcx>)>
2058 ) -> Result<Option<ty::Instance<'tcx>>, ErrorGuaranteed> {
2059 desc { "resolving instance `{}`", ty::Instance::new(key.value.0, key.value.1) }
2063 query resolve_instance_of_const_arg(
2064 key: ty::ParamEnvAnd<'tcx, (LocalDefId, DefId, SubstsRef<'tcx>)>
2065 ) -> Result<Option<ty::Instance<'tcx>>, ErrorGuaranteed> {
2067 "resolving instance of the const argument `{}`",
2068 ty::Instance::new(key.value.0.to_def_id(), key.value.2),
2073 query normalize_opaque_types(key: &'tcx ty::List<ty::Predicate<'tcx>>) -> &'tcx ty::List<ty::Predicate<'tcx>> {
2074 desc { "normalizing opaque types in {:?}", key }
2077 /// Checks whether a type is definitely uninhabited. This is
2078 /// conservative: for some types that are uninhabited we return `false`,
2079 /// but we only return `true` for types that are definitely uninhabited.
2080 /// `ty.conservative_is_privately_uninhabited` implies that any value of type `ty`
2081 /// will be `Abi::Uninhabited`. (Note that uninhabited types may have nonzero
2082 /// size, to account for partial initialisation. See #49298 for details.)
2083 query conservative_is_privately_uninhabited(key: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
2084 desc { "conservatively checking if {:?} is privately uninhabited", key }
2088 query limits(key: ()) -> Limits {
2089 desc { "looking up limits" }
2092 /// Performs an HIR-based well-formed check on the item with the given `HirId`. If
2093 /// we get an `Unimplemented` error that matches the provided `Predicate`, return
2094 /// the cause of the newly created obligation.
2096 /// This is only used by error-reporting code to get a better cause (in particular, a better
2097 /// span) for an *existing* error. Therefore, it is best-effort, and may never handle
2098 /// all of the cases that the normal `ty::Ty`-based wfcheck does. This is fine,
2099 /// because the `ty::Ty`-based wfcheck is always run.
2100 query diagnostic_hir_wf_check(key: (ty::Predicate<'tcx>, traits::WellFormedLoc)) -> Option<traits::ObligationCause<'tcx>> {
2104 desc { "performing HIR wf-checking for predicate {:?} at item {:?}", key.0, key.1 }
2108 /// The list of backend features computed from CLI flags (`-Ctarget-cpu`, `-Ctarget-feature`,
2109 /// `--target` and similar).
2110 query global_backend_features(_: ()) -> Vec<String> {
2113 desc { "computing the backend features for CLI flags" }
2116 query generator_diagnostic_data(key: DefId) -> Option<GeneratorDiagnosticData<'tcx>> {
2118 desc { |tcx| "looking up generator diagnostic data of `{}`", tcx.def_path_str(key) }
2119 separate_provide_extern
2122 query permits_uninit_init(key: TyAndLayout<'tcx>) -> bool {
2123 desc { "checking to see if {:?} permits being left uninit", key.ty }
2126 query permits_zero_init(key: TyAndLayout<'tcx>) -> bool {
2127 desc { "checking to see if {:?} permits being left zeroed", key.ty }
2130 query compare_assoc_const_impl_item_with_trait_item(
2131 key: (LocalDefId, DefId)
2132 ) -> Result<(), ErrorGuaranteed> {
2133 desc { |tcx| "checking assoc const `{}` has the same type as trait item", tcx.def_path_str(key.0.to_def_id()) }