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 analysis(key: ()) -> Result<(), ErrorGuaranteed> {
188 desc { "running analysis passes on this crate" }
191 /// This query checks the fulfillment of collected lint expectations.
192 /// All lint emitting queries have to be done before this is executed
193 /// to ensure that all expectations can be fulfilled.
195 /// This is an extra query to enable other drivers (like rustdoc) to
196 /// only execute a small subset of the `analysis` query, while allowing
197 /// lints to be expected. In rustc, this query will be executed as part of
198 /// the `analysis` query and doesn't have to be called a second time.
200 /// Tools can additionally pass in a tool filter. That will restrict the
201 /// expectations to only trigger for lints starting with the listed tool
202 /// name. This is useful for cases were not all linting code from rustc
203 /// was called. With the default `None` all registered lints will also
204 /// be checked for expectation fulfillment.
205 query check_expectations(key: Option<Symbol>) -> () {
207 desc { "checking lint expectations (RFC 2383)" }
210 /// Maps from the `DefId` of an item (trait/struct/enum/fn) to its
211 /// associated generics.
212 query generics_of(key: DefId) -> ty::Generics {
213 desc { |tcx| "computing generics of `{}`", tcx.def_path_str(key) }
215 cache_on_disk_if { key.is_local() }
216 separate_provide_extern
219 /// Maps from the `DefId` of an item (trait/struct/enum/fn) to the
220 /// predicates (where-clauses) that must be proven true in order
221 /// to reference it. This is almost always the "predicates query"
224 /// `predicates_of` builds on `predicates_defined_on` -- in fact,
225 /// it is almost always the same as that query, except for the
226 /// case of traits. For traits, `predicates_of` contains
227 /// an additional `Self: Trait<...>` predicate that users don't
228 /// actually write. This reflects the fact that to invoke the
229 /// trait (e.g., via `Default::default`) you must supply types
230 /// that actually implement the trait. (However, this extra
231 /// predicate gets in the way of some checks, which are intended
232 /// to operate over only the actual where-clauses written by the
234 query predicates_of(key: DefId) -> ty::GenericPredicates<'tcx> {
235 desc { |tcx| "computing predicates of `{}`", tcx.def_path_str(key) }
236 cache_on_disk_if { key.is_local() }
239 /// Returns the list of bounds that can be used for
240 /// `SelectionCandidate::ProjectionCandidate(_)` and
241 /// `ProjectionTyCandidate::TraitDef`.
242 /// Specifically this is the bounds written on the trait's type
243 /// definition, or those after the `impl` keyword
245 /// ```ignore (incomplete)
246 /// type X: Bound + 'lt
248 /// impl Debug + Display
249 /// // ^^^^^^^^^^^^^^^
252 /// `key` is the `DefId` of the associated type or opaque type.
254 /// Bounds from the parent (e.g. with nested impl trait) are not included.
255 query explicit_item_bounds(key: DefId) -> &'tcx [(ty::Predicate<'tcx>, Span)] {
256 desc { |tcx| "finding item bounds for `{}`", tcx.def_path_str(key) }
257 cache_on_disk_if { key.is_local() }
258 separate_provide_extern
261 /// Elaborated version of the predicates from `explicit_item_bounds`.
267 /// type MyAType: Eq + ?Sized;
271 /// `explicit_item_bounds` returns `[<Self as MyTrait>::MyAType: Eq]`,
272 /// and `item_bounds` returns
275 /// <Self as Trait>::MyAType: Eq,
276 /// <Self as Trait>::MyAType: PartialEq<<Self as Trait>::MyAType>
280 /// Bounds from the parent (e.g. with nested impl trait) are not included.
281 query item_bounds(key: DefId) -> ty::EarlyBinder<&'tcx ty::List<ty::Predicate<'tcx>>> {
282 desc { |tcx| "elaborating item bounds for `{}`", tcx.def_path_str(key) }
285 /// Look up all native libraries this crate depends on.
286 /// These are assembled from the following places:
287 /// - `extern` blocks (depending on their `link` attributes)
288 /// - the `libs` (`-l`) option
289 query native_libraries(_: CrateNum) -> Vec<NativeLib> {
291 desc { "looking up the native libraries of a linked crate" }
292 separate_provide_extern
295 query shallow_lint_levels_on(key: hir::OwnerId) -> rustc_middle::lint::ShallowLintLevelMap {
296 eval_always // fetches `resolutions`
298 desc { |tcx| "looking up lint levels for `{}`", tcx.def_path_str(key.to_def_id()) }
301 query lint_expectations(_: ()) -> Vec<(LintExpectationId, LintExpectation)> {
303 desc { "computing `#[expect]`ed lints in this crate" }
306 query parent_module_from_def_id(key: LocalDefId) -> LocalDefId {
308 desc { |tcx| "getting the parent module of `{}`", tcx.def_path_str(key.to_def_id()) }
311 query expn_that_defined(key: DefId) -> rustc_span::ExpnId {
312 desc { |tcx| "getting the expansion that defined `{}`", tcx.def_path_str(key) }
313 separate_provide_extern
316 query is_panic_runtime(_: CrateNum) -> bool {
318 desc { "checking if the crate is_panic_runtime" }
319 separate_provide_extern
322 /// Checks whether a type is representable or infinitely sized
323 query representability(_: LocalDefId) -> rustc_middle::ty::Representability {
324 desc { "checking if `{}` is representable", tcx.def_path_str(key.to_def_id()) }
325 // infinitely sized types will cause a cycle
327 // we don't want recursive representability calls to be forced with
328 // incremental compilation because, if a cycle occurs, we need the
329 // entire cycle to be in memory for diagnostics
333 /// An implementation detail for the `representability` query
334 query representability_adt_ty(_: Ty<'tcx>) -> rustc_middle::ty::Representability {
335 desc { "checking if `{}` is representable", key }
340 /// Set of param indexes for type params that are in the type's representation
341 query params_in_repr(key: DefId) -> rustc_index::bit_set::BitSet<u32> {
342 desc { "finding type parameters in the representation" }
345 separate_provide_extern
348 /// Fetch the THIR for a given body. If typeck for that body failed, returns an empty `Thir`.
349 query thir_body(key: ty::WithOptConstParam<LocalDefId>)
350 -> Result<(&'tcx Steal<thir::Thir<'tcx>>, thir::ExprId), ErrorGuaranteed>
352 // Perf tests revealed that hashing THIR is inefficient (see #85729).
354 desc { |tcx| "building THIR for `{}`", tcx.def_path_str(key.did.to_def_id()) }
357 /// Create a THIR tree for debugging.
358 query thir_tree(key: ty::WithOptConstParam<LocalDefId>) -> String {
361 desc { |tcx| "constructing THIR tree for `{}`", tcx.def_path_str(key.did.to_def_id()) }
364 /// Set of all the `DefId`s in this crate that have MIR associated with
365 /// them. This includes all the body owners, but also things like struct
367 query mir_keys(_: ()) -> rustc_data_structures::fx::FxIndexSet<LocalDefId> {
369 desc { "getting a list of all mir_keys" }
372 /// Maps DefId's that have an associated `mir::Body` to the result
373 /// of the MIR const-checking pass. This is the set of qualifs in
374 /// the final value of a `const`.
375 query mir_const_qualif(key: DefId) -> mir::ConstQualifs {
376 desc { |tcx| "const checking `{}`", tcx.def_path_str(key) }
377 cache_on_disk_if { key.is_local() }
378 separate_provide_extern
380 query mir_const_qualif_const_arg(
381 key: (LocalDefId, DefId)
382 ) -> mir::ConstQualifs {
384 |tcx| "const checking the const argument `{}`",
385 tcx.def_path_str(key.0.to_def_id())
389 /// Fetch the MIR for a given `DefId` right after it's built - this includes
390 /// unreachable code.
391 query mir_built(key: ty::WithOptConstParam<LocalDefId>) -> &'tcx Steal<mir::Body<'tcx>> {
392 desc { |tcx| "building MIR for `{}`", tcx.def_path_str(key.did.to_def_id()) }
395 /// Fetch the MIR for a given `DefId` up till the point where it is
396 /// ready for const qualification.
398 /// See the README for the `mir` module for details.
399 query mir_const(key: ty::WithOptConstParam<LocalDefId>) -> &'tcx Steal<mir::Body<'tcx>> {
401 |tcx| "preparing {}`{}` for borrow checking",
402 if key.const_param_did.is_some() { "the const argument " } else { "" },
403 tcx.def_path_str(key.did.to_def_id()),
408 /// Try to build an abstract representation of the given constant.
409 query thir_abstract_const(
411 ) -> Result<Option<ty::Const<'tcx>>, ErrorGuaranteed> {
413 |tcx| "building an abstract representation for `{}`", tcx.def_path_str(key),
415 separate_provide_extern
417 /// Try to build an abstract representation of the given constant.
418 query thir_abstract_const_of_const_arg(
419 key: (LocalDefId, DefId)
420 ) -> Result<Option<ty::Const<'tcx>>, ErrorGuaranteed> {
423 "building an abstract representation for the const argument `{}`",
424 tcx.def_path_str(key.0.to_def_id()),
428 query mir_drops_elaborated_and_const_checked(
429 key: ty::WithOptConstParam<LocalDefId>
430 ) -> &'tcx Steal<mir::Body<'tcx>> {
432 desc { |tcx| "elaborating drops for `{}`", tcx.def_path_str(key.did.to_def_id()) }
437 ) -> &'tcx mir::Body<'tcx> {
438 desc { |tcx| "caching mir of `{}` for CTFE", tcx.def_path_str(key) }
439 cache_on_disk_if { key.is_local() }
440 separate_provide_extern
443 query mir_for_ctfe_of_const_arg(key: (LocalDefId, DefId)) -> &'tcx mir::Body<'tcx> {
445 |tcx| "caching MIR for CTFE of the const argument `{}`",
446 tcx.def_path_str(key.0.to_def_id())
450 query mir_promoted(key: ty::WithOptConstParam<LocalDefId>) ->
452 &'tcx Steal<mir::Body<'tcx>>,
453 &'tcx Steal<IndexVec<mir::Promoted, mir::Body<'tcx>>>
457 |tcx| "processing MIR for {}`{}`",
458 if key.const_param_did.is_some() { "the const argument " } else { "" },
459 tcx.def_path_str(key.did.to_def_id()),
463 query symbols_for_closure_captures(
464 key: (LocalDefId, LocalDefId)
465 ) -> Vec<rustc_span::Symbol> {
468 |tcx| "finding symbols for captures of closure `{}` in `{}`",
469 tcx.def_path_str(key.1.to_def_id()),
470 tcx.def_path_str(key.0.to_def_id())
474 /// MIR after our optimization passes have run. This is MIR that is ready
475 /// for codegen. This is also the only query that can fetch non-local MIR, at present.
476 query optimized_mir(key: DefId) -> &'tcx mir::Body<'tcx> {
477 desc { |tcx| "optimizing MIR for `{}`", tcx.def_path_str(key) }
478 cache_on_disk_if { key.is_local() }
479 separate_provide_extern
482 /// Returns coverage summary info for a function, after executing the `InstrumentCoverage`
483 /// MIR pass (assuming the -Cinstrument-coverage option is enabled).
484 query coverageinfo(key: ty::InstanceDef<'tcx>) -> mir::CoverageInfo {
485 desc { |tcx| "retrieving coverage info from MIR for `{}`", tcx.def_path_str(key.def_id()) }
489 /// Returns the `CodeRegions` for a function that has instrumented coverage, in case the
490 /// function was optimized out before codegen, and before being added to the Coverage Map.
491 query covered_code_regions(key: DefId) -> Vec<&'tcx mir::coverage::CodeRegion> {
493 |tcx| "retrieving the covered `CodeRegion`s, if instrumented, for `{}`",
494 tcx.def_path_str(key)
497 cache_on_disk_if { key.is_local() }
500 /// The `DefId` is the `DefId` of the containing MIR body. Promoteds do not have their own
501 /// `DefId`. This function returns all promoteds in the specified body. The body references
502 /// promoteds by the `DefId` and the `mir::Promoted` index. This is necessary, because
503 /// after inlining a body may refer to promoteds from other bodies. In that case you still
504 /// need to use the `DefId` of the original body.
505 query promoted_mir(key: DefId) -> &'tcx IndexVec<mir::Promoted, mir::Body<'tcx>> {
506 desc { |tcx| "optimizing promoted MIR for `{}`", tcx.def_path_str(key) }
507 cache_on_disk_if { key.is_local() }
508 separate_provide_extern
510 query promoted_mir_of_const_arg(
511 key: (LocalDefId, DefId)
512 ) -> &'tcx IndexVec<mir::Promoted, mir::Body<'tcx>> {
514 |tcx| "optimizing promoted MIR for the const argument `{}`",
515 tcx.def_path_str(key.0.to_def_id()),
519 /// Erases regions from `ty` to yield a new type.
520 /// Normally you would just use `tcx.erase_regions(value)`,
521 /// however, which uses this query as a kind of cache.
522 query erase_regions_ty(ty: Ty<'tcx>) -> Ty<'tcx> {
523 // This query is not expected to have input -- as a result, it
524 // is not a good candidates for "replay" because it is essentially a
525 // pure function of its input (and hence the expectation is that
526 // no caller would be green **apart** from just these
527 // queries). Making it anonymous avoids hashing the result, which
528 // may save a bit of time.
530 desc { "erasing regions from `{}`", ty }
533 query wasm_import_module_map(_: CrateNum) -> FxHashMap<DefId, String> {
535 desc { "getting wasm import module map" }
538 /// Maps from the `DefId` of an item (trait/struct/enum/fn) to the
539 /// predicates (where-clauses) directly defined on it. This is
540 /// equal to the `explicit_predicates_of` predicates plus the
541 /// `inferred_outlives_of` predicates.
542 query predicates_defined_on(key: DefId) -> ty::GenericPredicates<'tcx> {
543 desc { |tcx| "computing predicates of `{}`", tcx.def_path_str(key) }
546 /// Returns everything that looks like a predicate written explicitly
547 /// by the user on a trait item.
549 /// Traits are unusual, because predicates on associated types are
550 /// converted into bounds on that type for backwards compatibility:
552 /// trait X where Self::U: Copy { type U; }
556 /// trait X { type U: Copy; }
558 /// `explicit_predicates_of` and `explicit_item_bounds` will then take
559 /// the appropriate subsets of the predicates here.
560 query trait_explicit_predicates_and_bounds(key: LocalDefId) -> ty::GenericPredicates<'tcx> {
561 desc { |tcx| "computing explicit predicates of trait `{}`", tcx.def_path_str(key.to_def_id()) }
564 /// Returns the predicates written explicitly by the user.
565 query explicit_predicates_of(key: DefId) -> ty::GenericPredicates<'tcx> {
566 desc { |tcx| "computing explicit predicates of `{}`", tcx.def_path_str(key) }
567 cache_on_disk_if { key.is_local() }
568 separate_provide_extern
571 /// Returns the inferred outlives predicates (e.g., for `struct
572 /// Foo<'a, T> { x: &'a T }`, this would return `T: 'a`).
573 query inferred_outlives_of(key: DefId) -> &'tcx [(ty::Clause<'tcx>, Span)] {
574 desc { |tcx| "computing inferred outlives predicates of `{}`", tcx.def_path_str(key) }
575 cache_on_disk_if { key.is_local() }
576 separate_provide_extern
579 /// Maps from the `DefId` of a trait to the list of
580 /// super-predicates. This is a subset of the full list of
581 /// predicates. We store these in a separate map because we must
582 /// evaluate them even during type conversion, often before the
583 /// full predicates are available (note that supertraits have
584 /// additional acyclicity requirements).
585 query super_predicates_of(key: DefId) -> ty::GenericPredicates<'tcx> {
586 desc { |tcx| "computing the super predicates of `{}`", tcx.def_path_str(key) }
587 cache_on_disk_if { key.is_local() }
588 separate_provide_extern
591 /// The `Option<Ident>` is the name of an associated type. If it is `None`, then this query
592 /// returns the full set of predicates. If `Some<Ident>`, then the query returns only the
593 /// subset of super-predicates that reference traits that define the given associated type.
594 /// This is used to avoid cycles in resolving types like `T::Item`.
595 query super_predicates_that_define_assoc_type(key: (DefId, Option<rustc_span::symbol::Ident>)) -> ty::GenericPredicates<'tcx> {
596 desc { |tcx| "computing the super traits of `{}`{}",
597 tcx.def_path_str(key.0),
598 if let Some(assoc_name) = key.1 { format!(" with associated type name `{}`", assoc_name) } else { "".to_string() },
602 /// To avoid cycles within the predicates of a single item we compute
603 /// per-type-parameter predicates for resolving `T::AssocTy`.
604 query type_param_predicates(key: (DefId, LocalDefId, rustc_span::symbol::Ident)) -> ty::GenericPredicates<'tcx> {
605 desc { |tcx| "computing the bounds for type parameter `{}`", tcx.hir().ty_param_name(key.1) }
608 query trait_def(key: DefId) -> ty::TraitDef {
609 desc { |tcx| "computing trait definition for `{}`", tcx.def_path_str(key) }
611 cache_on_disk_if { key.is_local() }
612 separate_provide_extern
614 query adt_def(key: DefId) -> ty::AdtDef<'tcx> {
615 desc { |tcx| "computing ADT definition for `{}`", tcx.def_path_str(key) }
616 cache_on_disk_if { key.is_local() }
617 separate_provide_extern
619 query adt_destructor(key: DefId) -> Option<ty::Destructor> {
620 desc { |tcx| "computing `Drop` impl for `{}`", tcx.def_path_str(key) }
621 cache_on_disk_if { key.is_local() }
622 separate_provide_extern
625 query adt_sized_constraint(key: DefId) -> &'tcx [Ty<'tcx>] {
626 desc { |tcx| "computing `Sized` constraints for `{}`", tcx.def_path_str(key) }
629 query adt_dtorck_constraint(
631 ) -> Result<&'tcx DropckConstraint<'tcx>, NoSolution> {
632 desc { |tcx| "computing drop-check constraints for `{}`", tcx.def_path_str(key) }
635 /// Returns `true` if this is a const fn, use the `is_const_fn` to know whether your crate
636 /// actually sees it as const fn (e.g., the const-fn-ness might be unstable and you might
637 /// not have the feature gate active).
639 /// **Do not call this function manually.** It is only meant to cache the base data for the
640 /// `is_const_fn` function. Consider using `is_const_fn` or `is_const_fn_raw` instead.
641 query constness(key: DefId) -> hir::Constness {
642 desc { |tcx| "checking if item is const: `{}`", tcx.def_path_str(key) }
643 cache_on_disk_if { key.is_local() }
644 separate_provide_extern
647 query asyncness(key: DefId) -> hir::IsAsync {
648 desc { |tcx| "checking if the function is async: `{}`", tcx.def_path_str(key) }
649 cache_on_disk_if { key.is_local() }
650 separate_provide_extern
653 /// Returns `true` if calls to the function may be promoted.
655 /// This is either because the function is e.g., a tuple-struct or tuple-variant
656 /// constructor, or because it has the `#[rustc_promotable]` attribute. The attribute should
657 /// be removed in the future in favour of some form of check which figures out whether the
658 /// function does not inspect the bits of any of its arguments (so is essentially just a
659 /// constructor function).
660 query is_promotable_const_fn(key: DefId) -> bool {
661 desc { |tcx| "checking if item is promotable: `{}`", tcx.def_path_str(key) }
664 /// Returns `true` if this is a foreign item (i.e., linked via `extern { ... }`).
665 query is_foreign_item(key: DefId) -> bool {
666 desc { |tcx| "checking if `{}` is a foreign item", tcx.def_path_str(key) }
667 cache_on_disk_if { key.is_local() }
668 separate_provide_extern
671 /// Returns `Some(generator_kind)` if the node pointed to by `def_id` is a generator.
672 query generator_kind(def_id: DefId) -> Option<hir::GeneratorKind> {
673 desc { |tcx| "looking up generator kind of `{}`", tcx.def_path_str(def_id) }
674 cache_on_disk_if { def_id.is_local() }
675 separate_provide_extern
678 /// Gets a map with the variance of every item; use `item_variance` instead.
679 query crate_variances(_: ()) -> ty::CrateVariancesMap<'tcx> {
681 desc { "computing the variances for items in this crate" }
684 /// Maps from the `DefId` of a type or region parameter to its (inferred) variance.
685 query variances_of(def_id: DefId) -> &'tcx [ty::Variance] {
686 desc { |tcx| "computing the variances of `{}`", tcx.def_path_str(def_id) }
687 cache_on_disk_if { def_id.is_local() }
688 separate_provide_extern
691 /// Maps from thee `DefId` of a type to its (inferred) outlives.
692 query inferred_outlives_crate(_: ()) -> ty::CratePredicatesMap<'tcx> {
694 desc { "computing the inferred outlives predicates for items in this crate" }
697 /// Maps from an impl/trait `DefId` to a list of the `DefId`s of its items.
698 query associated_item_def_ids(key: DefId) -> &'tcx [DefId] {
699 desc { |tcx| "collecting associated items of `{}`", tcx.def_path_str(key) }
700 cache_on_disk_if { key.is_local() }
701 separate_provide_extern
704 /// Maps from a trait item to the trait item "descriptor".
705 query associated_item(key: DefId) -> ty::AssocItem {
706 desc { |tcx| "computing associated item data for `{}`", tcx.def_path_str(key) }
708 cache_on_disk_if { key.is_local() }
709 separate_provide_extern
712 /// Collects the associated items defined on a trait or impl.
713 query associated_items(key: DefId) -> ty::AssocItems<'tcx> {
715 desc { |tcx| "collecting associated items of `{}`", tcx.def_path_str(key) }
718 /// Maps from associated items on a trait to the corresponding associated
719 /// item on the impl specified by `impl_id`.
721 /// For example, with the following code
726 /// trait Trait { // trait_id
727 /// fn f(); // trait_f
728 /// fn g() {} // trait_g
731 /// impl Trait for Type { // impl_id
732 /// fn f() {} // impl_f
733 /// fn g() {} // impl_g
737 /// The map returned for `tcx.impl_item_implementor_ids(impl_id)` would be
738 ///`{ trait_f: impl_f, trait_g: impl_g }`
739 query impl_item_implementor_ids(impl_id: DefId) -> FxHashMap<DefId, DefId> {
741 desc { |tcx| "comparing impl items against trait for `{}`", tcx.def_path_str(impl_id) }
744 /// Given an `impl_id`, return the trait it implements.
745 /// Return `None` if this is an inherent impl.
746 query impl_trait_ref(impl_id: DefId) -> Option<ty::EarlyBinder<ty::TraitRef<'tcx>>> {
747 desc { |tcx| "computing trait implemented by `{}`", tcx.def_path_str(impl_id) }
748 cache_on_disk_if { impl_id.is_local() }
749 separate_provide_extern
751 query impl_polarity(impl_id: DefId) -> ty::ImplPolarity {
752 desc { |tcx| "computing implementation polarity of `{}`", tcx.def_path_str(impl_id) }
753 cache_on_disk_if { impl_id.is_local() }
754 separate_provide_extern
757 query issue33140_self_ty(key: DefId) -> Option<ty::Ty<'tcx>> {
758 desc { |tcx| "computing Self type wrt issue #33140 `{}`", tcx.def_path_str(key) }
761 /// Maps a `DefId` of a type to a list of its inherent impls.
762 /// Contains implementations of methods that are inherent to a type.
763 /// Methods in these implementations don't need to be exported.
764 query inherent_impls(key: DefId) -> &'tcx [DefId] {
765 desc { |tcx| "collecting inherent impls for `{}`", tcx.def_path_str(key) }
766 cache_on_disk_if { key.is_local() }
767 separate_provide_extern
770 query incoherent_impls(key: SimplifiedType) -> &'tcx [DefId] {
771 desc { |tcx| "collecting all inherent impls for `{:?}`", key }
774 /// The result of unsafety-checking this `LocalDefId`.
775 query unsafety_check_result(key: LocalDefId) -> &'tcx mir::UnsafetyCheckResult {
776 desc { |tcx| "unsafety-checking `{}`", tcx.def_path_str(key.to_def_id()) }
777 cache_on_disk_if { true }
779 query unsafety_check_result_for_const_arg(key: (LocalDefId, DefId)) -> &'tcx mir::UnsafetyCheckResult {
781 |tcx| "unsafety-checking the const argument `{}`",
782 tcx.def_path_str(key.0.to_def_id())
786 /// Unsafety-check this `LocalDefId` with THIR unsafeck. This should be
787 /// used with `-Zthir-unsafeck`.
788 query thir_check_unsafety(key: LocalDefId) {
789 desc { |tcx| "unsafety-checking `{}`", tcx.def_path_str(key.to_def_id()) }
790 cache_on_disk_if { true }
792 query thir_check_unsafety_for_const_arg(key: (LocalDefId, DefId)) {
794 |tcx| "unsafety-checking the const argument `{}`",
795 tcx.def_path_str(key.0.to_def_id())
799 /// HACK: when evaluated, this reports an "unsafe derive on repr(packed)" error.
801 /// Unsafety checking is executed for each method separately, but we only want
802 /// to emit this error once per derive. As there are some impls with multiple
803 /// methods, we use a query for deduplication.
804 query unsafe_derive_on_repr_packed(key: LocalDefId) -> () {
805 desc { |tcx| "processing `{}`", tcx.def_path_str(key.to_def_id()) }
808 /// Returns the types assumed to be well formed while "inside" of the given item.
810 /// Note that we've liberated the late bound regions of function signatures, so
811 /// this can not be used to check whether these types are well formed.
812 query assumed_wf_types(key: DefId) -> &'tcx ty::List<Ty<'tcx>> {
813 desc { |tcx| "computing the implied bounds of `{}`", tcx.def_path_str(key) }
816 /// Computes the signature of the function.
817 query fn_sig(key: DefId) -> ty::PolyFnSig<'tcx> {
818 desc { |tcx| "computing function signature of `{}`", tcx.def_path_str(key) }
819 cache_on_disk_if { key.is_local() }
820 separate_provide_extern
824 /// Performs lint checking for the module.
825 query lint_mod(key: LocalDefId) -> () {
826 desc { |tcx| "linting {}", describe_as_module(key, tcx) }
829 /// Checks the attributes in the module.
830 query check_mod_attrs(key: LocalDefId) -> () {
831 desc { |tcx| "checking attributes in {}", describe_as_module(key, tcx) }
834 /// Checks for uses of unstable APIs in the module.
835 query check_mod_unstable_api_usage(key: LocalDefId) -> () {
836 desc { |tcx| "checking for unstable API usage in {}", describe_as_module(key, tcx) }
839 /// Checks the const bodies in the module for illegal operations (e.g. `if` or `loop`).
840 query check_mod_const_bodies(key: LocalDefId) -> () {
841 desc { |tcx| "checking consts in {}", describe_as_module(key, tcx) }
844 /// Checks the loops in the module.
845 query check_mod_loops(key: LocalDefId) -> () {
846 desc { |tcx| "checking loops in {}", describe_as_module(key, tcx) }
849 query check_mod_naked_functions(key: LocalDefId) -> () {
850 desc { |tcx| "checking naked functions in {}", describe_as_module(key, tcx) }
853 query check_mod_item_types(key: LocalDefId) -> () {
854 desc { |tcx| "checking item types in {}", describe_as_module(key, tcx) }
857 query check_mod_privacy(key: LocalDefId) -> () {
858 desc { |tcx| "checking privacy in {}", describe_as_module(key, tcx) }
861 query check_liveness(key: DefId) {
862 desc { |tcx| "checking liveness of variables in `{}`", tcx.def_path_str(key) }
865 /// Return the live symbols in the crate for dead code check.
867 /// The second return value maps from ADTs to ignored derived traits (e.g. Debug and Clone) and
868 /// their respective impl (i.e., part of the derive macro)
869 query live_symbols_and_ignored_derived_traits(_: ()) -> (
870 FxHashSet<LocalDefId>,
871 FxHashMap<LocalDefId, Vec<(DefId, DefId)>>
874 desc { "finding live symbols in crate" }
877 query check_mod_deathness(key: LocalDefId) -> () {
878 desc { |tcx| "checking deathness of variables in {}", describe_as_module(key, tcx) }
881 query check_mod_impl_wf(key: LocalDefId) -> () {
882 desc { |tcx| "checking that impls are well-formed in {}", describe_as_module(key, tcx) }
885 query check_mod_type_wf(key: LocalDefId) -> () {
886 desc { |tcx| "checking that types are well-formed in {}", describe_as_module(key, tcx) }
889 query collect_mod_item_types(key: LocalDefId) -> () {
890 desc { |tcx| "collecting item types in {}", describe_as_module(key, tcx) }
893 /// Caches `CoerceUnsized` kinds for impls on custom types.
894 query coerce_unsized_info(key: DefId) -> ty::adjustment::CoerceUnsizedInfo {
895 desc { |tcx| "computing CoerceUnsized info for `{}`", tcx.def_path_str(key) }
896 cache_on_disk_if { key.is_local() }
897 separate_provide_extern
900 query typeck_item_bodies(_: ()) -> () {
901 desc { "type-checking all item bodies" }
904 query typeck(key: LocalDefId) -> &'tcx ty::TypeckResults<'tcx> {
905 desc { |tcx| "type-checking `{}`", tcx.def_path_str(key.to_def_id()) }
906 cache_on_disk_if { true }
908 query typeck_const_arg(
909 key: (LocalDefId, DefId)
910 ) -> &'tcx ty::TypeckResults<'tcx> {
912 |tcx| "type-checking the const argument `{}`",
913 tcx.def_path_str(key.0.to_def_id()),
916 query diagnostic_only_typeck(key: LocalDefId) -> &'tcx ty::TypeckResults<'tcx> {
917 desc { |tcx| "type-checking `{}`", tcx.def_path_str(key.to_def_id()) }
918 cache_on_disk_if { true }
921 query used_trait_imports(key: LocalDefId) -> &'tcx UnordSet<LocalDefId> {
922 desc { |tcx| "finding used_trait_imports `{}`", tcx.def_path_str(key.to_def_id()) }
923 cache_on_disk_if { true }
926 query has_typeck_results(def_id: DefId) -> bool {
927 desc { |tcx| "checking whether `{}` has a body", tcx.def_path_str(def_id) }
930 query coherent_trait(def_id: DefId) -> () {
931 desc { |tcx| "coherence checking all impls of trait `{}`", tcx.def_path_str(def_id) }
934 /// Borrow-checks the function body. If this is a closure, returns
935 /// additional requirements that the closure's creator must verify.
936 query mir_borrowck(key: LocalDefId) -> &'tcx mir::BorrowCheckResult<'tcx> {
937 desc { |tcx| "borrow-checking `{}`", tcx.def_path_str(key.to_def_id()) }
938 cache_on_disk_if(tcx) { tcx.is_typeck_child(key.to_def_id()) }
940 query mir_borrowck_const_arg(key: (LocalDefId, DefId)) -> &'tcx mir::BorrowCheckResult<'tcx> {
942 |tcx| "borrow-checking the const argument`{}`",
943 tcx.def_path_str(key.0.to_def_id())
947 /// Gets a complete map from all types to their inherent impls.
948 /// Not meant to be used directly outside of coherence.
949 query crate_inherent_impls(k: ()) -> CrateInherentImpls {
951 desc { "finding all inherent impls defined in crate" }
954 /// Checks all types in the crate for overlap in their inherent impls. Reports errors.
955 /// Not meant to be used directly outside of coherence.
956 query crate_inherent_impls_overlap_check(_: ()) -> () {
957 desc { "check for overlap between inherent impls defined in this crate" }
960 /// Checks whether all impls in the crate pass the overlap check, returning
961 /// which impls fail it. If all impls are correct, the returned slice is empty.
962 query orphan_check_impl(key: LocalDefId) -> Result<(), ErrorGuaranteed> {
964 "checking whether impl `{}` follows the orphan rules",
965 tcx.def_path_str(key.to_def_id()),
969 /// Check whether the function has any recursion that could cause the inliner to trigger
970 /// a cycle. Returns the call stack causing the cycle. The call stack does not contain the
971 /// current function, just all intermediate functions.
972 query mir_callgraph_reachable(key: (ty::Instance<'tcx>, LocalDefId)) -> bool {
975 "computing if `{}` (transitively) calls `{}`",
977 tcx.def_path_str(key.1.to_def_id()),
981 /// Obtain all the calls into other local functions
982 query mir_inliner_callees(key: ty::InstanceDef<'tcx>) -> &'tcx [(DefId, SubstsRef<'tcx>)] {
985 "computing all local function calls in `{}`",
986 tcx.def_path_str(key.def_id()),
990 /// Evaluates a constant and returns the computed allocation.
992 /// **Do not use this** directly, use the `tcx.eval_static_initializer` wrapper.
993 query eval_to_allocation_raw(key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>)
994 -> EvalToAllocationRawResult<'tcx> {
996 "const-evaluating + checking `{}`",
997 key.value.display(tcx)
999 cache_on_disk_if { true }
1002 /// Evaluates const items or anonymous constants
1003 /// (such as enum variant explicit discriminants or array lengths)
1004 /// into a representation suitable for the type system and const generics.
1006 /// **Do not use this** directly, use one of the following wrappers: `tcx.const_eval_poly`,
1007 /// `tcx.const_eval_resolve`, `tcx.const_eval_instance`, or `tcx.const_eval_global_id`.
1008 query eval_to_const_value_raw(key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>)
1009 -> EvalToConstValueResult<'tcx> {
1011 "simplifying constant for the type system `{}`",
1012 key.value.display(tcx)
1014 cache_on_disk_if { true }
1017 /// Evaluate a constant and convert it to a type level constant or
1018 /// return `None` if that is not possible.
1019 query eval_to_valtree(
1020 key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>
1021 ) -> EvalToValTreeResult<'tcx> {
1022 desc { "evaluating type-level constant" }
1025 /// Converts a type level constant value into `ConstValue`
1026 query valtree_to_const_val(key: (Ty<'tcx>, ty::ValTree<'tcx>)) -> ConstValue<'tcx> {
1027 desc { "converting type-level constant value to mir constant value"}
1030 /// Destructures array, ADT or tuple constants into the constants
1031 /// of their fields.
1032 query destructure_const(key: ty::Const<'tcx>) -> ty::DestructuredConst<'tcx> {
1033 desc { "destructuring type level constant"}
1036 /// Tries to destructure an `mir::ConstantKind` ADT or array into its variant index
1037 /// and its field values.
1038 query try_destructure_mir_constant(
1039 key: ty::ParamEnvAnd<'tcx, mir::ConstantKind<'tcx>>
1040 ) -> Option<mir::DestructuredConstant<'tcx>> {
1041 desc { "destructuring MIR constant"}
1045 /// Dereference a constant reference or raw pointer and turn the result into a constant
1047 query deref_mir_constant(
1048 key: ty::ParamEnvAnd<'tcx, mir::ConstantKind<'tcx>>
1049 ) -> mir::ConstantKind<'tcx> {
1050 desc { "dereferencing MIR constant" }
1054 query const_caller_location(key: (rustc_span::Symbol, u32, u32)) -> ConstValue<'tcx> {
1055 desc { "getting a &core::panic::Location referring to a span" }
1058 // FIXME get rid of this with valtrees
1060 key: LitToConstInput<'tcx>
1061 ) -> Result<ty::Const<'tcx>, LitToConstError> {
1062 desc { "converting literal to const" }
1065 query lit_to_mir_constant(key: LitToConstInput<'tcx>) -> Result<mir::ConstantKind<'tcx>, LitToConstError> {
1066 desc { "converting literal to mir constant" }
1069 query check_match(key: DefId) {
1070 desc { |tcx| "match-checking `{}`", tcx.def_path_str(key) }
1071 cache_on_disk_if { key.is_local() }
1074 /// Performs part of the privacy check and computes effective visibilities.
1075 query effective_visibilities(_: ()) -> &'tcx EffectiveVisibilities {
1077 desc { "checking effective visibilities" }
1079 query check_private_in_public(_: ()) -> () {
1081 desc { "checking for private elements in public interfaces" }
1084 query reachable_set(_: ()) -> FxHashSet<LocalDefId> {
1086 desc { "reachability" }
1089 /// Per-body `region::ScopeTree`. The `DefId` should be the owner `DefId` for the body;
1090 /// in the case of closures, this will be redirected to the enclosing function.
1091 query region_scope_tree(def_id: DefId) -> &'tcx crate::middle::region::ScopeTree {
1092 desc { |tcx| "computing drop scopes for `{}`", tcx.def_path_str(def_id) }
1095 /// Generates a MIR body for the shim.
1096 query mir_shims(key: ty::InstanceDef<'tcx>) -> mir::Body<'tcx> {
1098 desc { |tcx| "generating MIR shim for `{}`", tcx.def_path_str(key.def_id()) }
1101 /// The `symbol_name` query provides the symbol name for calling a
1102 /// given instance from the local crate. In particular, it will also
1103 /// look up the correct symbol name of instances from upstream crates.
1104 query symbol_name(key: ty::Instance<'tcx>) -> ty::SymbolName<'tcx> {
1105 desc { "computing the symbol for `{}`", key }
1106 cache_on_disk_if { true }
1109 query opt_def_kind(def_id: DefId) -> Option<DefKind> {
1110 desc { |tcx| "looking up definition kind of `{}`", tcx.def_path_str(def_id) }
1111 cache_on_disk_if { def_id.is_local() }
1112 separate_provide_extern
1115 /// Gets the span for the definition.
1116 query def_span(def_id: DefId) -> Span {
1117 desc { |tcx| "looking up span for `{}`", tcx.def_path_str(def_id) }
1118 cache_on_disk_if { def_id.is_local() }
1119 separate_provide_extern
1123 /// Gets the span for the identifier of the definition.
1124 query def_ident_span(def_id: DefId) -> Option<Span> {
1125 desc { |tcx| "looking up span for `{}`'s identifier", tcx.def_path_str(def_id) }
1126 cache_on_disk_if { def_id.is_local() }
1127 separate_provide_extern
1130 query lookup_stability(def_id: DefId) -> Option<attr::Stability> {
1131 desc { |tcx| "looking up stability of `{}`", tcx.def_path_str(def_id) }
1132 cache_on_disk_if { def_id.is_local() }
1133 separate_provide_extern
1136 query lookup_const_stability(def_id: DefId) -> Option<attr::ConstStability> {
1137 desc { |tcx| "looking up const stability of `{}`", tcx.def_path_str(def_id) }
1138 cache_on_disk_if { def_id.is_local() }
1139 separate_provide_extern
1142 query lookup_default_body_stability(def_id: DefId) -> Option<attr::DefaultBodyStability> {
1143 desc { |tcx| "looking up default body stability of `{}`", tcx.def_path_str(def_id) }
1144 separate_provide_extern
1147 query should_inherit_track_caller(def_id: DefId) -> bool {
1148 desc { |tcx| "computing should_inherit_track_caller of `{}`", tcx.def_path_str(def_id) }
1151 query lookup_deprecation_entry(def_id: DefId) -> Option<DeprecationEntry> {
1152 desc { |tcx| "checking whether `{}` is deprecated", tcx.def_path_str(def_id) }
1153 cache_on_disk_if { def_id.is_local() }
1154 separate_provide_extern
1157 /// Determines whether an item is annotated with `doc(hidden)`.
1158 query is_doc_hidden(def_id: DefId) -> bool {
1159 desc { |tcx| "checking whether `{}` is `doc(hidden)`", tcx.def_path_str(def_id) }
1160 separate_provide_extern
1163 /// Determines whether an item is annotated with `doc(notable_trait)`.
1164 query is_doc_notable_trait(def_id: DefId) -> bool {
1165 desc { |tcx| "checking whether `{}` is `doc(notable_trait)`", tcx.def_path_str(def_id) }
1168 /// Returns the attributes on the item at `def_id`.
1170 /// Do not use this directly, use `tcx.get_attrs` instead.
1171 query item_attrs(def_id: DefId) -> &'tcx [ast::Attribute] {
1172 desc { |tcx| "collecting attributes of `{}`", tcx.def_path_str(def_id) }
1173 separate_provide_extern
1176 query codegen_fn_attrs(def_id: DefId) -> CodegenFnAttrs {
1177 desc { |tcx| "computing codegen attributes of `{}`", tcx.def_path_str(def_id) }
1179 cache_on_disk_if { def_id.is_local() }
1180 separate_provide_extern
1183 query asm_target_features(def_id: DefId) -> &'tcx FxHashSet<Symbol> {
1184 desc { |tcx| "computing target features for inline asm of `{}`", tcx.def_path_str(def_id) }
1187 query fn_arg_names(def_id: DefId) -> &'tcx [rustc_span::symbol::Ident] {
1188 desc { |tcx| "looking up function parameter names for `{}`", tcx.def_path_str(def_id) }
1189 cache_on_disk_if { def_id.is_local() }
1190 separate_provide_extern
1192 /// Gets the rendered value of the specified constant or associated constant.
1193 /// Used by rustdoc.
1194 query rendered_const(def_id: DefId) -> String {
1196 desc { |tcx| "rendering constant initializer of `{}`", tcx.def_path_str(def_id) }
1197 cache_on_disk_if { def_id.is_local() }
1198 separate_provide_extern
1200 query impl_parent(def_id: DefId) -> Option<DefId> {
1201 desc { |tcx| "computing specialization parent impl of `{}`", tcx.def_path_str(def_id) }
1202 cache_on_disk_if { def_id.is_local() }
1203 separate_provide_extern
1206 query is_ctfe_mir_available(key: DefId) -> bool {
1207 desc { |tcx| "checking if item has CTFE MIR available: `{}`", tcx.def_path_str(key) }
1208 cache_on_disk_if { key.is_local() }
1209 separate_provide_extern
1211 query is_mir_available(key: DefId) -> bool {
1212 desc { |tcx| "checking if item has MIR available: `{}`", tcx.def_path_str(key) }
1213 cache_on_disk_if { key.is_local() }
1214 separate_provide_extern
1217 query own_existential_vtable_entries(
1219 ) -> &'tcx [DefId] {
1220 desc { |tcx| "finding all existential vtable entries for trait `{}`", tcx.def_path_str(key) }
1223 query vtable_entries(key: ty::PolyTraitRef<'tcx>)
1224 -> &'tcx [ty::VtblEntry<'tcx>] {
1225 desc { |tcx| "finding all vtable entries for trait `{}`", tcx.def_path_str(key.def_id()) }
1228 query vtable_trait_upcasting_coercion_new_vptr_slot(key: (Ty<'tcx>, Ty<'tcx>)) -> Option<usize> {
1229 desc { |tcx| "finding the slot within vtable for trait object `{}` vtable ptr during trait upcasting coercion from `{}` vtable",
1233 query vtable_allocation(key: (Ty<'tcx>, Option<ty::PolyExistentialTraitRef<'tcx>>)) -> mir::interpret::AllocId {
1234 desc { |tcx| "vtable const allocation for <{} as {}>",
1236 key.1.map(|trait_ref| format!("{}", trait_ref)).unwrap_or("_".to_owned())
1240 query codegen_select_candidate(
1241 key: (ty::ParamEnv<'tcx>, ty::PolyTraitRef<'tcx>)
1242 ) -> Result<&'tcx ImplSource<'tcx, ()>, traits::CodegenObligationError> {
1243 cache_on_disk_if { true }
1244 desc { |tcx| "computing candidate for `{}`", key.1 }
1247 /// Return all `impl` blocks in the current crate.
1248 query all_local_trait_impls(_: ()) -> &'tcx rustc_data_structures::fx::FxIndexMap<DefId, Vec<LocalDefId>> {
1249 desc { "finding local trait impls" }
1252 /// Given a trait `trait_id`, return all known `impl` blocks.
1253 query trait_impls_of(trait_id: DefId) -> ty::trait_def::TraitImpls {
1255 desc { |tcx| "finding trait impls of `{}`", tcx.def_path_str(trait_id) }
1258 query specialization_graph_of(trait_id: DefId) -> specialization_graph::Graph {
1260 desc { |tcx| "building specialization graph of trait `{}`", tcx.def_path_str(trait_id) }
1261 cache_on_disk_if { true }
1263 query object_safety_violations(trait_id: DefId) -> &'tcx [traits::ObjectSafetyViolation] {
1264 desc { |tcx| "determining object safety of trait `{}`", tcx.def_path_str(trait_id) }
1267 /// Gets the ParameterEnvironment for a given item; this environment
1268 /// will be in "user-facing" mode, meaning that it is suitable for
1269 /// type-checking etc, and it does not normalize specializable
1270 /// associated types. This is almost always what you want,
1271 /// unless you are doing MIR optimizations, in which case you
1272 /// might want to use `reveal_all()` method to change modes.
1273 query param_env(def_id: DefId) -> ty::ParamEnv<'tcx> {
1274 desc { |tcx| "computing normalized predicates of `{}`", tcx.def_path_str(def_id) }
1277 /// Like `param_env`, but returns the `ParamEnv` in `Reveal::All` mode.
1278 /// Prefer this over `tcx.param_env(def_id).with_reveal_all_normalized(tcx)`,
1279 /// as this method is more efficient.
1280 query param_env_reveal_all_normalized(def_id: DefId) -> ty::ParamEnv<'tcx> {
1281 desc { |tcx| "computing revealed normalized predicates of `{}`", tcx.def_path_str(def_id) }
1284 /// Trait selection queries. These are best used by invoking `ty.is_copy_modulo_regions()`,
1285 /// `ty.is_copy()`, etc, since that will prune the environment where possible.
1286 query is_copy_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1287 desc { "computing whether `{}` is `Copy`", env.value }
1290 /// Query backing `Ty::is_sized`.
1291 query is_sized_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1292 desc { "computing whether `{}` is `Sized`", env.value }
1295 /// Query backing `Ty::is_freeze`.
1296 query is_freeze_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1297 desc { "computing whether `{}` is freeze", env.value }
1300 /// Query backing `Ty::is_unpin`.
1301 query is_unpin_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1302 desc { "computing whether `{}` is `Unpin`", env.value }
1305 /// Query backing `Ty::needs_drop`.
1306 query needs_drop_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1307 desc { "computing whether `{}` needs drop", env.value }
1310 /// Query backing `Ty::has_significant_drop_raw`.
1311 query has_significant_drop_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1312 desc { "computing whether `{}` has a significant drop", env.value }
1316 /// Query backing `Ty::is_structural_eq_shallow`.
1318 /// This is only correct for ADTs. Call `is_structural_eq_shallow` to handle all types
1320 query has_structural_eq_impls(ty: Ty<'tcx>) -> bool {
1322 "computing whether `{}` implements `PartialStructuralEq` and `StructuralEq`",
1327 /// A list of types where the ADT requires drop if and only if any of
1328 /// those types require drop. If the ADT is known to always need drop
1329 /// then `Err(AlwaysRequiresDrop)` is returned.
1330 query adt_drop_tys(def_id: DefId) -> Result<&'tcx ty::List<Ty<'tcx>>, AlwaysRequiresDrop> {
1331 desc { |tcx| "computing when `{}` needs drop", tcx.def_path_str(def_id) }
1332 cache_on_disk_if { true }
1335 /// A list of types where the ADT requires drop if and only if any of those types
1336 /// has significant drop. A type marked with the attribute `rustc_insignificant_dtor`
1337 /// is considered to not be significant. A drop is significant if it is implemented
1338 /// by the user or does anything that will have any observable behavior (other than
1339 /// freeing up memory). If the ADT is known to have a significant destructor then
1340 /// `Err(AlwaysRequiresDrop)` is returned.
1341 query adt_significant_drop_tys(def_id: DefId) -> Result<&'tcx ty::List<Ty<'tcx>>, AlwaysRequiresDrop> {
1342 desc { |tcx| "computing when `{}` has a significant destructor", tcx.def_path_str(def_id) }
1343 cache_on_disk_if { false }
1346 /// Computes the layout of a type. Note that this implicitly
1347 /// executes in "reveal all" mode, and will normalize the input type.
1349 key: ty::ParamEnvAnd<'tcx, Ty<'tcx>>
1350 ) -> Result<ty::layout::TyAndLayout<'tcx>, ty::layout::LayoutError<'tcx>> {
1352 desc { "computing layout of `{}`", key.value }
1356 /// Compute a `FnAbi` suitable for indirect calls, i.e. to `fn` pointers.
1358 /// NB: this doesn't handle virtual calls - those should use `fn_abi_of_instance`
1359 /// instead, where the instance is an `InstanceDef::Virtual`.
1360 query fn_abi_of_fn_ptr(
1361 key: ty::ParamEnvAnd<'tcx, (ty::PolyFnSig<'tcx>, &'tcx ty::List<Ty<'tcx>>)>
1362 ) -> Result<&'tcx abi::call::FnAbi<'tcx, Ty<'tcx>>, ty::layout::FnAbiError<'tcx>> {
1363 desc { "computing call ABI of `{}` function pointers", key.value.0 }
1367 /// Compute a `FnAbi` suitable for declaring/defining an `fn` instance, and for
1368 /// direct calls to an `fn`.
1370 /// NB: that includes virtual calls, which are represented by "direct calls"
1371 /// to an `InstanceDef::Virtual` instance (of `<dyn Trait as Trait>::fn`).
1372 query fn_abi_of_instance(
1373 key: ty::ParamEnvAnd<'tcx, (ty::Instance<'tcx>, &'tcx ty::List<Ty<'tcx>>)>
1374 ) -> Result<&'tcx abi::call::FnAbi<'tcx, Ty<'tcx>>, ty::layout::FnAbiError<'tcx>> {
1375 desc { "computing call ABI of `{}`", key.value.0 }
1379 query dylib_dependency_formats(_: CrateNum)
1380 -> &'tcx [(CrateNum, LinkagePreference)] {
1381 desc { "getting dylib dependency formats of crate" }
1382 separate_provide_extern
1385 query dependency_formats(_: ()) -> Lrc<crate::middle::dependency_format::Dependencies> {
1387 desc { "getting the linkage format of all dependencies" }
1390 query is_compiler_builtins(_: CrateNum) -> bool {
1392 desc { "checking if the crate is_compiler_builtins" }
1393 separate_provide_extern
1395 query has_global_allocator(_: CrateNum) -> bool {
1396 // This query depends on untracked global state in CStore
1399 desc { "checking if the crate has_global_allocator" }
1400 separate_provide_extern
1402 query has_alloc_error_handler(_: CrateNum) -> bool {
1403 // This query depends on untracked global state in CStore
1406 desc { "checking if the crate has_alloc_error_handler" }
1407 separate_provide_extern
1409 query has_panic_handler(_: CrateNum) -> bool {
1411 desc { "checking if the crate has_panic_handler" }
1412 separate_provide_extern
1414 query is_profiler_runtime(_: CrateNum) -> bool {
1416 desc { "checking if a crate is `#![profiler_runtime]`" }
1417 separate_provide_extern
1419 query has_ffi_unwind_calls(key: LocalDefId) -> bool {
1420 desc { |tcx| "checking if `{}` contains FFI-unwind calls", tcx.def_path_str(key.to_def_id()) }
1421 cache_on_disk_if { true }
1423 query required_panic_strategy(_: CrateNum) -> Option<PanicStrategy> {
1425 desc { "getting a crate's required panic strategy" }
1426 separate_provide_extern
1428 query panic_in_drop_strategy(_: CrateNum) -> PanicStrategy {
1430 desc { "getting a crate's configured panic-in-drop strategy" }
1431 separate_provide_extern
1433 query is_no_builtins(_: CrateNum) -> bool {
1435 desc { "getting whether a crate has `#![no_builtins]`" }
1436 separate_provide_extern
1438 query symbol_mangling_version(_: CrateNum) -> SymbolManglingVersion {
1440 desc { "getting a crate's symbol mangling version" }
1441 separate_provide_extern
1444 query extern_crate(def_id: DefId) -> Option<&'tcx ExternCrate> {
1446 desc { "getting crate's ExternCrateData" }
1447 separate_provide_extern
1450 query specializes(_: (DefId, DefId)) -> bool {
1451 desc { "computing whether impls specialize one another" }
1453 query in_scope_traits_map(_: hir::OwnerId)
1454 -> Option<&'tcx FxHashMap<ItemLocalId, Box<[TraitCandidate]>>> {
1455 desc { "getting traits in scope at a block" }
1458 query module_reexports(def_id: LocalDefId) -> Option<&'tcx [ModChild]> {
1459 desc { |tcx| "looking up reexports of module `{}`", tcx.def_path_str(def_id.to_def_id()) }
1462 query impl_defaultness(def_id: DefId) -> hir::Defaultness {
1463 desc { |tcx| "looking up whether `{}` is a default impl", tcx.def_path_str(def_id) }
1464 cache_on_disk_if { def_id.is_local() }
1465 separate_provide_extern
1468 query check_well_formed(key: hir::OwnerId) -> () {
1469 desc { |tcx| "checking that `{}` is well-formed", tcx.def_path_str(key.to_def_id()) }
1472 // The `DefId`s of all non-generic functions and statics in the given crate
1473 // that can be reached from outside the crate.
1475 // We expect this items to be available for being linked to.
1477 // This query can also be called for `LOCAL_CRATE`. In this case it will
1478 // compute which items will be reachable to other crates, taking into account
1479 // the kind of crate that is currently compiled. Crates with only a
1480 // C interface have fewer reachable things.
1482 // Does not include external symbols that don't have a corresponding DefId,
1483 // like the compiler-generated `main` function and so on.
1484 query reachable_non_generics(_: CrateNum)
1485 -> DefIdMap<SymbolExportInfo> {
1487 desc { "looking up the exported symbols of a crate" }
1488 separate_provide_extern
1490 query is_reachable_non_generic(def_id: DefId) -> bool {
1491 desc { |tcx| "checking whether `{}` is an exported symbol", tcx.def_path_str(def_id) }
1492 cache_on_disk_if { def_id.is_local() }
1493 separate_provide_extern
1495 query is_unreachable_local_definition(def_id: LocalDefId) -> bool {
1497 "checking whether `{}` is reachable from outside the crate",
1498 tcx.def_path_str(def_id.to_def_id()),
1502 /// The entire set of monomorphizations the local crate can safely link
1503 /// to because they are exported from upstream crates. Do not depend on
1504 /// this directly, as its value changes anytime a monomorphization gets
1505 /// added or removed in any upstream crate. Instead use the narrower
1506 /// `upstream_monomorphizations_for`, `upstream_drop_glue_for`, or, even
1507 /// better, `Instance::upstream_monomorphization()`.
1508 query upstream_monomorphizations(_: ()) -> DefIdMap<FxHashMap<SubstsRef<'tcx>, CrateNum>> {
1510 desc { "collecting available upstream monomorphizations" }
1513 /// Returns the set of upstream monomorphizations available for the
1514 /// generic function identified by the given `def_id`. The query makes
1515 /// sure to make a stable selection if the same monomorphization is
1516 /// available in multiple upstream crates.
1518 /// You likely want to call `Instance::upstream_monomorphization()`
1519 /// instead of invoking this query directly.
1520 query upstream_monomorphizations_for(def_id: DefId)
1521 -> Option<&'tcx FxHashMap<SubstsRef<'tcx>, CrateNum>>
1525 "collecting available upstream monomorphizations for `{}`",
1526 tcx.def_path_str(def_id),
1528 separate_provide_extern
1531 /// Returns the upstream crate that exports drop-glue for the given
1532 /// type (`substs` is expected to be a single-item list containing the
1533 /// type one wants drop-glue for).
1535 /// This is a subset of `upstream_monomorphizations_for` in order to
1536 /// increase dep-tracking granularity. Otherwise adding or removing any
1537 /// type with drop-glue in any upstream crate would invalidate all
1538 /// functions calling drop-glue of an upstream type.
1540 /// You likely want to call `Instance::upstream_monomorphization()`
1541 /// instead of invoking this query directly.
1543 /// NOTE: This query could easily be extended to also support other
1544 /// common functions that have are large set of monomorphizations
1545 /// (like `Clone::clone` for example).
1546 query upstream_drop_glue_for(substs: SubstsRef<'tcx>) -> Option<CrateNum> {
1547 desc { "available upstream drop-glue for `{:?}`", substs }
1550 /// Returns a list of all `extern` blocks of a crate.
1551 query foreign_modules(_: CrateNum) -> FxHashMap<DefId, ForeignModule> {
1553 desc { "looking up the foreign modules of a linked crate" }
1554 separate_provide_extern
1557 /// Identifies the entry-point (e.g., the `main` function) for a given
1558 /// crate, returning `None` if there is no entry point (such as for library crates).
1559 query entry_fn(_: ()) -> Option<(DefId, EntryFnType)> {
1560 desc { "looking up the entry function of a crate" }
1563 /// Finds the `rustc_proc_macro_decls` item of a crate.
1564 query proc_macro_decls_static(_: ()) -> Option<LocalDefId> {
1565 desc { "looking up the proc macro declarations for a crate" }
1568 // The macro which defines `rustc_metadata::provide_extern` depends on this query's name.
1569 // Changing the name should cause a compiler error, but in case that changes, be aware.
1570 query crate_hash(_: CrateNum) -> Svh {
1572 desc { "looking up the hash a crate" }
1573 separate_provide_extern
1576 /// Gets the hash for the host proc macro. Used to support -Z dual-proc-macro.
1577 query crate_host_hash(_: CrateNum) -> Option<Svh> {
1579 desc { "looking up the hash of a host version of a crate" }
1580 separate_provide_extern
1583 /// Gets the extra data to put in each output filename for a crate.
1584 /// For example, compiling the `foo` crate with `extra-filename=-a` creates a `libfoo-b.rlib` file.
1585 query extra_filename(_: CrateNum) -> String {
1588 desc { "looking up the extra filename for a crate" }
1589 separate_provide_extern
1592 /// Gets the paths where the crate came from in the file system.
1593 query crate_extern_paths(_: CrateNum) -> Vec<PathBuf> {
1596 desc { "looking up the paths for extern crates" }
1597 separate_provide_extern
1600 /// Given a crate and a trait, look up all impls of that trait in the crate.
1601 /// Return `(impl_id, self_ty)`.
1602 query implementations_of_trait(_: (CrateNum, DefId)) -> &'tcx [(DefId, Option<SimplifiedType>)] {
1603 desc { "looking up implementations of a trait in a crate" }
1604 separate_provide_extern
1607 /// Collects all incoherent impls for the given crate and type.
1609 /// Do not call this directly, but instead use the `incoherent_impls` query.
1610 /// This query is only used to get the data necessary for that query.
1611 query crate_incoherent_impls(key: (CrateNum, SimplifiedType)) -> &'tcx [DefId] {
1612 desc { |tcx| "collecting all impls for a type in a crate" }
1613 separate_provide_extern
1616 /// Get the corresponding native library from the `native_libraries` query
1617 query native_library(def_id: DefId) -> Option<&'tcx NativeLib> {
1618 desc { |tcx| "getting the native library for `{}`", tcx.def_path_str(def_id) }
1621 /// Does lifetime resolution on items. Importantly, we can't resolve
1622 /// lifetimes directly on things like trait methods, because of trait params.
1623 /// See `rustc_resolve::late::lifetimes for details.
1624 query resolve_lifetimes(_: hir::OwnerId) -> ResolveLifetimes {
1626 desc { "resolving lifetimes" }
1628 query named_region_map(_: hir::OwnerId) ->
1629 Option<&'tcx FxHashMap<ItemLocalId, Region>> {
1630 desc { "looking up a named region" }
1632 query is_late_bound_map(_: LocalDefId) -> Option<&'tcx FxIndexSet<LocalDefId>> {
1633 desc { "testing if a region is late bound" }
1635 /// For a given item's generic parameter, gets the default lifetimes to be used
1636 /// for each parameter if a trait object were to be passed for that parameter.
1637 /// For example, for `T` in `struct Foo<'a, T>`, this would be `'static`.
1638 /// For `T` in `struct Foo<'a, T: 'a>`, this would instead be `'a`.
1639 /// This query will panic if passed something that is not a type parameter.
1640 query object_lifetime_default(key: DefId) -> ObjectLifetimeDefault {
1641 desc { "looking up lifetime defaults for generic parameter `{}`", tcx.def_path_str(key) }
1642 separate_provide_extern
1644 query late_bound_vars_map(_: hir::OwnerId)
1645 -> Option<&'tcx FxHashMap<ItemLocalId, Vec<ty::BoundVariableKind>>> {
1646 desc { "looking up late bound vars" }
1649 /// Computes the visibility of the provided `def_id`.
1651 /// If the item from the `def_id` doesn't have a visibility, it will panic. For example
1652 /// a generic type parameter will panic if you call this method on it:
1655 /// use std::fmt::Debug;
1657 /// pub trait Foo<T: Debug> {}
1660 /// In here, if you call `visibility` on `T`, it'll panic.
1661 query visibility(def_id: DefId) -> ty::Visibility<DefId> {
1662 desc { |tcx| "computing visibility of `{}`", tcx.def_path_str(def_id) }
1663 separate_provide_extern
1666 query inhabited_predicate_adt(key: DefId) -> ty::inhabitedness::InhabitedPredicate<'tcx> {
1667 desc { "computing the uninhabited predicate of `{:?}`", key }
1670 /// Do not call this query directly: invoke `Ty::inhabited_predicate` instead.
1671 query inhabited_predicate_type(key: Ty<'tcx>) -> ty::inhabitedness::InhabitedPredicate<'tcx> {
1672 desc { "computing the uninhabited predicate of `{}`", key }
1675 query dep_kind(_: CrateNum) -> CrateDepKind {
1677 desc { "fetching what a dependency looks like" }
1678 separate_provide_extern
1681 /// Gets the name of the crate.
1682 query crate_name(_: CrateNum) -> Symbol {
1684 desc { "fetching what a crate is named" }
1685 separate_provide_extern
1687 query module_children(def_id: DefId) -> &'tcx [ModChild] {
1688 desc { |tcx| "collecting child items of module `{}`", tcx.def_path_str(def_id) }
1689 separate_provide_extern
1691 query extern_mod_stmt_cnum(def_id: LocalDefId) -> Option<CrateNum> {
1692 desc { |tcx| "computing crate imported by `{}`", tcx.def_path_str(def_id.to_def_id()) }
1695 query lib_features(_: ()) -> LibFeatures {
1697 desc { "calculating the lib features map" }
1699 query defined_lib_features(_: CrateNum) -> &'tcx [(Symbol, Option<Symbol>)] {
1700 desc { "calculating the lib features defined in a crate" }
1701 separate_provide_extern
1703 query stability_implications(_: CrateNum) -> FxHashMap<Symbol, Symbol> {
1705 desc { "calculating the implications between `#[unstable]` features defined in a crate" }
1706 separate_provide_extern
1708 /// Whether the function is an intrinsic
1709 query is_intrinsic(def_id: DefId) -> bool {
1710 desc { |tcx| "checking whether `{}` is an intrinsic", tcx.def_path_str(def_id) }
1711 separate_provide_extern
1713 /// Returns the lang items defined in another crate by loading it from metadata.
1714 query get_lang_items(_: ()) -> LanguageItems {
1717 desc { "calculating the lang items map" }
1720 /// Returns all diagnostic items defined in all crates.
1721 query all_diagnostic_items(_: ()) -> rustc_hir::diagnostic_items::DiagnosticItems {
1724 desc { "calculating the diagnostic items map" }
1727 /// Returns the lang items defined in another crate by loading it from metadata.
1728 query defined_lang_items(_: CrateNum) -> &'tcx [(DefId, LangItem)] {
1729 desc { "calculating the lang items defined in a crate" }
1730 separate_provide_extern
1733 /// Returns the diagnostic items defined in a crate.
1734 query diagnostic_items(_: CrateNum) -> rustc_hir::diagnostic_items::DiagnosticItems {
1736 desc { "calculating the diagnostic items map in a crate" }
1737 separate_provide_extern
1740 query missing_lang_items(_: CrateNum) -> &'tcx [LangItem] {
1741 desc { "calculating the missing lang items in a crate" }
1742 separate_provide_extern
1744 query visible_parent_map(_: ()) -> DefIdMap<DefId> {
1746 desc { "calculating the visible parent map" }
1748 query trimmed_def_paths(_: ()) -> FxHashMap<DefId, Symbol> {
1750 desc { "calculating trimmed def paths" }
1752 query missing_extern_crate_item(_: CrateNum) -> bool {
1754 desc { "seeing if we're missing an `extern crate` item for this crate" }
1755 separate_provide_extern
1757 query used_crate_source(_: CrateNum) -> Lrc<CrateSource> {
1760 desc { "looking at the source for a crate" }
1761 separate_provide_extern
1763 /// Returns the debugger visualizers defined for this crate.
1764 query debugger_visualizers(_: CrateNum) -> Vec<rustc_span::DebuggerVisualizerFile> {
1766 desc { "looking up the debugger visualizers for this crate" }
1767 separate_provide_extern
1769 query postorder_cnums(_: ()) -> &'tcx [CrateNum] {
1771 desc { "generating a postorder list of CrateNums" }
1773 /// Returns whether or not the crate with CrateNum 'cnum'
1774 /// is marked as a private dependency
1775 query is_private_dep(c: CrateNum) -> bool {
1777 desc { "checking whether crate `{}` is a private dependency", c }
1778 separate_provide_extern
1780 query allocator_kind(_: ()) -> Option<AllocatorKind> {
1782 desc { "getting the allocator kind for the current crate" }
1784 query alloc_error_handler_kind(_: ()) -> Option<AllocatorKind> {
1786 desc { "alloc error handler kind for the current crate" }
1789 query upvars_mentioned(def_id: DefId) -> Option<&'tcx FxIndexMap<hir::HirId, hir::Upvar>> {
1790 desc { |tcx| "collecting upvars mentioned in `{}`", tcx.def_path_str(def_id) }
1792 query maybe_unused_trait_imports(_: ()) -> &'tcx FxIndexSet<LocalDefId> {
1793 desc { "fetching potentially unused trait imports" }
1795 query maybe_unused_extern_crates(_: ()) -> &'tcx [(LocalDefId, Span)] {
1796 desc { "looking up all possibly unused extern crates" }
1798 query names_imported_by_glob_use(def_id: LocalDefId) -> &'tcx FxHashSet<Symbol> {
1799 desc { |tcx| "finding names imported by glob use for `{}`", tcx.def_path_str(def_id.to_def_id()) }
1802 query stability_index(_: ()) -> stability::Index {
1805 desc { "calculating the stability index for the local crate" }
1807 query crates(_: ()) -> &'tcx [CrateNum] {
1809 desc { "fetching all foreign CrateNum instances" }
1812 /// A list of all traits in a crate, used by rustdoc and error reporting.
1813 /// NOTE: Not named just `traits` due to a naming conflict.
1814 query traits_in_crate(_: CrateNum) -> &'tcx [DefId] {
1815 desc { "fetching all traits in a crate" }
1816 separate_provide_extern
1819 /// The list of symbols exported from the given crate.
1821 /// - All names contained in `exported_symbols(cnum)` are guaranteed to
1822 /// correspond to a publicly visible symbol in `cnum` machine code.
1823 /// - The `exported_symbols` sets of different crates do not intersect.
1824 query exported_symbols(cnum: CrateNum) -> &'tcx [(ExportedSymbol<'tcx>, SymbolExportInfo)] {
1825 desc { "collecting exported symbols for crate `{}`", cnum}
1826 cache_on_disk_if { *cnum == LOCAL_CRATE }
1827 separate_provide_extern
1830 query collect_and_partition_mono_items(_: ()) -> (&'tcx DefIdSet, &'tcx [CodegenUnit<'tcx>]) {
1832 desc { "collect_and_partition_mono_items" }
1835 query is_codegened_item(def_id: DefId) -> bool {
1836 desc { |tcx| "determining whether `{}` needs codegen", tcx.def_path_str(def_id) }
1839 /// All items participating in code generation together with items inlined into them.
1840 query codegened_and_inlined_items(_: ()) -> &'tcx DefIdSet {
1842 desc { "collecting codegened and inlined items" }
1845 query codegen_unit(sym: Symbol) -> &'tcx CodegenUnit<'tcx> {
1846 desc { "getting codegen unit `{sym}`" }
1849 query unused_generic_params(key: ty::InstanceDef<'tcx>) -> UnusedGenericParams {
1850 cache_on_disk_if { key.def_id().is_local() }
1852 |tcx| "determining which generic parameters are unused by `{}`",
1853 tcx.def_path_str(key.def_id())
1855 separate_provide_extern
1858 query backend_optimization_level(_: ()) -> OptLevel {
1859 desc { "optimization level used by backend" }
1862 /// Return the filenames where output artefacts shall be stored.
1864 /// This query returns an `&Arc` because codegen backends need the value even after the `TyCtxt`
1865 /// has been destroyed.
1866 query output_filenames(_: ()) -> &'tcx Arc<OutputFilenames> {
1868 desc { "getting output filenames" }
1871 /// Do not call this query directly: invoke `normalize` instead.
1872 query normalize_projection_ty(
1873 goal: CanonicalProjectionGoal<'tcx>
1875 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, NormalizationResult<'tcx>>>,
1878 desc { "normalizing `{}`", goal.value.value }
1882 /// Do not call this query directly: invoke `try_normalize_erasing_regions` instead.
1883 query try_normalize_generic_arg_after_erasing_regions(
1884 goal: ParamEnvAnd<'tcx, GenericArg<'tcx>>
1885 ) -> Result<GenericArg<'tcx>, NoSolution> {
1886 desc { "normalizing `{}`", goal.value }
1890 query implied_outlives_bounds(
1891 goal: CanonicalTyGoal<'tcx>
1893 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, Vec<OutlivesBound<'tcx>>>>,
1896 desc { "computing implied outlives bounds for `{}`", goal.value.value }
1900 /// Do not call this query directly:
1901 /// invoke `DropckOutlives::new(dropped_ty)).fully_perform(typeck.infcx)` instead.
1902 query dropck_outlives(
1903 goal: CanonicalTyGoal<'tcx>
1905 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, DropckOutlivesResult<'tcx>>>,
1908 desc { "computing dropck types for `{}`", goal.value.value }
1912 /// Do not call this query directly: invoke `infcx.predicate_may_hold()` or
1913 /// `infcx.predicate_must_hold()` instead.
1914 query evaluate_obligation(
1915 goal: CanonicalPredicateGoal<'tcx>
1916 ) -> Result<traits::EvaluationResult, traits::OverflowError> {
1917 desc { "evaluating trait selection obligation `{}`", goal.value.value }
1920 query evaluate_goal(
1921 goal: traits::CanonicalChalkEnvironmentAndGoal<'tcx>
1923 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1926 desc { "evaluating trait selection obligation `{}`", goal.value }
1929 /// Do not call this query directly: part of the `Eq` type-op
1930 query type_op_ascribe_user_type(
1931 goal: CanonicalTypeOpAscribeUserTypeGoal<'tcx>
1933 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1936 desc { "evaluating `type_op_ascribe_user_type` `{:?}`", goal.value.value }
1940 /// Do not call this query directly: part of the `Eq` type-op
1942 goal: CanonicalTypeOpEqGoal<'tcx>
1944 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1947 desc { "evaluating `type_op_eq` `{:?}`", goal.value.value }
1951 /// Do not call this query directly: part of the `Subtype` type-op
1952 query type_op_subtype(
1953 goal: CanonicalTypeOpSubtypeGoal<'tcx>
1955 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1958 desc { "evaluating `type_op_subtype` `{:?}`", goal.value.value }
1962 /// Do not call this query directly: part of the `ProvePredicate` type-op
1963 query type_op_prove_predicate(
1964 goal: CanonicalTypeOpProvePredicateGoal<'tcx>
1966 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1969 desc { "evaluating `type_op_prove_predicate` `{:?}`", goal.value.value }
1972 /// Do not call this query directly: part of the `Normalize` type-op
1973 query type_op_normalize_ty(
1974 goal: CanonicalTypeOpNormalizeGoal<'tcx, Ty<'tcx>>
1976 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, Ty<'tcx>>>,
1979 desc { "normalizing `{}`", goal.value.value.value }
1983 /// Do not call this query directly: part of the `Normalize` type-op
1984 query type_op_normalize_predicate(
1985 goal: CanonicalTypeOpNormalizeGoal<'tcx, ty::Predicate<'tcx>>
1987 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ty::Predicate<'tcx>>>,
1990 desc { "normalizing `{:?}`", goal.value.value.value }
1994 /// Do not call this query directly: part of the `Normalize` type-op
1995 query type_op_normalize_poly_fn_sig(
1996 goal: CanonicalTypeOpNormalizeGoal<'tcx, ty::PolyFnSig<'tcx>>
1998 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ty::PolyFnSig<'tcx>>>,
2001 desc { "normalizing `{:?}`", goal.value.value.value }
2005 /// Do not call this query directly: part of the `Normalize` type-op
2006 query type_op_normalize_fn_sig(
2007 goal: CanonicalTypeOpNormalizeGoal<'tcx, ty::FnSig<'tcx>>
2009 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ty::FnSig<'tcx>>>,
2012 desc { "normalizing `{:?}`", goal.value.value.value }
2016 query subst_and_check_impossible_predicates(key: (DefId, SubstsRef<'tcx>)) -> bool {
2018 "checking impossible substituted predicates: `{}`",
2019 tcx.def_path_str(key.0)
2023 query is_impossible_method(key: (DefId, DefId)) -> bool {
2025 "checking if `{}` is impossible to call within `{}`",
2026 tcx.def_path_str(key.1),
2027 tcx.def_path_str(key.0),
2031 query method_autoderef_steps(
2032 goal: CanonicalTyGoal<'tcx>
2033 ) -> MethodAutoderefStepsResult<'tcx> {
2034 desc { "computing autoderef types for `{}`", goal.value.value }
2038 query supported_target_features(_: CrateNum) -> FxHashMap<String, Option<Symbol>> {
2041 desc { "looking up supported target features" }
2044 /// Get an estimate of the size of an InstanceDef based on its MIR for CGU partitioning.
2045 query instance_def_size_estimate(def: ty::InstanceDef<'tcx>)
2047 desc { |tcx| "estimating size for `{}`", tcx.def_path_str(def.def_id()) }
2050 query features_query(_: ()) -> &'tcx rustc_feature::Features {
2052 desc { "looking up enabled feature gates" }
2055 /// Attempt to resolve the given `DefId` to an `Instance`, for the
2056 /// given generics args (`SubstsRef`), returning one of:
2057 /// * `Ok(Some(instance))` on success
2058 /// * `Ok(None)` when the `SubstsRef` are still too generic,
2059 /// and therefore don't allow finding the final `Instance`
2060 /// * `Err(ErrorGuaranteed)` when the `Instance` resolution process
2061 /// couldn't complete due to errors elsewhere - this is distinct
2062 /// from `Ok(None)` to avoid misleading diagnostics when an error
2063 /// has already been/will be emitted, for the original cause
2064 query resolve_instance(
2065 key: ty::ParamEnvAnd<'tcx, (DefId, SubstsRef<'tcx>)>
2066 ) -> Result<Option<ty::Instance<'tcx>>, ErrorGuaranteed> {
2067 desc { "resolving instance `{}`", ty::Instance::new(key.value.0, key.value.1) }
2071 query resolve_instance_of_const_arg(
2072 key: ty::ParamEnvAnd<'tcx, (LocalDefId, DefId, SubstsRef<'tcx>)>
2073 ) -> Result<Option<ty::Instance<'tcx>>, ErrorGuaranteed> {
2075 "resolving instance of the const argument `{}`",
2076 ty::Instance::new(key.value.0.to_def_id(), key.value.2),
2081 query reveal_opaque_types_in_bounds(key: &'tcx ty::List<ty::Predicate<'tcx>>) -> &'tcx ty::List<ty::Predicate<'tcx>> {
2082 desc { "revealing opaque types in `{:?}`", key }
2085 query limits(key: ()) -> Limits {
2086 desc { "looking up limits" }
2089 /// Performs an HIR-based well-formed check on the item with the given `HirId`. If
2090 /// we get an `Unimplemented` error that matches the provided `Predicate`, return
2091 /// the cause of the newly created obligation.
2093 /// This is only used by error-reporting code to get a better cause (in particular, a better
2094 /// span) for an *existing* error. Therefore, it is best-effort, and may never handle
2095 /// all of the cases that the normal `ty::Ty`-based wfcheck does. This is fine,
2096 /// because the `ty::Ty`-based wfcheck is always run.
2097 query diagnostic_hir_wf_check(key: (ty::Predicate<'tcx>, traits::WellFormedLoc)) -> Option<traits::ObligationCause<'tcx>> {
2101 desc { "performing HIR wf-checking for predicate `{:?}` at item `{:?}`", key.0, key.1 }
2105 /// The list of backend features computed from CLI flags (`-Ctarget-cpu`, `-Ctarget-feature`,
2106 /// `--target` and similar).
2107 query global_backend_features(_: ()) -> Vec<String> {
2110 desc { "computing the backend features for CLI flags" }
2113 query generator_diagnostic_data(key: DefId) -> Option<GeneratorDiagnosticData<'tcx>> {
2115 desc { |tcx| "looking up generator diagnostic data of `{}`", tcx.def_path_str(key) }
2116 separate_provide_extern
2119 query permits_uninit_init(key: TyAndLayout<'tcx>) -> bool {
2120 desc { "checking to see if `{}` permits being left uninit", key.ty }
2123 query permits_zero_init(key: TyAndLayout<'tcx>) -> bool {
2124 desc { "checking to see if `{}` permits being left zeroed", key.ty }
2127 query compare_impl_const(
2128 key: (LocalDefId, DefId)
2129 ) -> Result<(), ErrorGuaranteed> {
2130 desc { |tcx| "checking assoc const `{}` has the same type as trait item", tcx.def_path_str(key.0.to_def_id()) }
2133 query deduced_param_attrs(def_id: DefId) -> &'tcx [ty::DeducedParamAttrs] {
2134 desc { |tcx| "deducing parameter attributes for {}", tcx.def_path_str(def_id) }
2135 separate_provide_extern