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> {
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 desc { "getting the source span" }
49 /// Represents crate as a whole (as distinct from the top-level crate module).
50 /// If you call `hir_crate` (e.g., indirectly by calling `tcx.hir().krate()`),
51 /// we will have to assume that any change means that you need to be recompiled.
52 /// This is because the `hir_crate` query gives you access to all other items.
53 /// To avoid this fate, do not call `tcx.hir().krate()`; instead,
54 /// prefer wrappers like `tcx.visit_all_items_in_krate()`.
55 query hir_crate(key: ()) -> Crate<'tcx> {
58 desc { "getting the crate HIR" }
61 /// All items in the crate.
62 query hir_crate_items(_: ()) -> rustc_middle::hir::ModuleItems {
65 desc { "getting HIR crate items" }
68 /// The items in a module.
70 /// This can be conveniently accessed by `tcx.hir().visit_item_likes_in_module`.
71 /// Avoid calling this query directly.
72 query hir_module_items(key: LocalDefId) -> rustc_middle::hir::ModuleItems {
74 desc { |tcx| "getting HIR module items in `{}`", tcx.def_path_str(key.to_def_id()) }
75 cache_on_disk_if { true }
78 /// Gives access to the HIR node for the HIR owner `key`.
80 /// This can be conveniently accessed by methods on `tcx.hir()`.
81 /// Avoid calling this query directly.
82 query hir_owner(key: hir::OwnerId) -> Option<crate::hir::Owner<'tcx>> {
83 desc { |tcx| "getting HIR owner of `{}`", tcx.def_path_str(key.to_def_id()) }
86 /// Gives access to the HIR ID for the given `LocalDefId` owner `key`.
88 /// This can be conveniently accessed by methods on `tcx.hir()`.
89 /// Avoid calling this query directly.
90 query local_def_id_to_hir_id(key: LocalDefId) -> hir::HirId {
91 desc { |tcx| "getting HIR ID of `{}`", tcx.def_path_str(key.to_def_id()) }
94 /// Gives access to the HIR node's parent for the HIR owner `key`.
96 /// This can be conveniently accessed by methods on `tcx.hir()`.
97 /// Avoid calling this query directly.
98 query hir_owner_parent(key: hir::OwnerId) -> hir::HirId {
99 desc { |tcx| "getting HIR parent of `{}`", tcx.def_path_str(key.to_def_id()) }
102 /// Gives access to the HIR nodes and bodies inside the HIR owner `key`.
104 /// This can be conveniently accessed by methods on `tcx.hir()`.
105 /// Avoid calling this query directly.
106 query hir_owner_nodes(key: hir::OwnerId) -> hir::MaybeOwner<&'tcx hir::OwnerNodes<'tcx>> {
107 desc { |tcx| "getting HIR owner items in `{}`", tcx.def_path_str(key.to_def_id()) }
110 /// Gives access to the HIR attributes inside the HIR owner `key`.
112 /// This can be conveniently accessed by methods on `tcx.hir()`.
113 /// Avoid calling this query directly.
114 query hir_attrs(key: hir::OwnerId) -> &'tcx hir::AttributeMap<'tcx> {
115 desc { |tcx| "getting HIR owner attributes in `{}`", tcx.def_path_str(key.to_def_id()) }
118 /// Computes the `DefId` of the corresponding const parameter in case the `key` is a
119 /// const argument and returns `None` otherwise.
121 /// ```ignore (incomplete)
122 /// let a = foo::<7>();
123 /// // ^ Calling `opt_const_param_of` for this argument,
125 /// fn foo<const N: usize>()
126 /// // ^ returns this `DefId`.
129 /// // ^ While calling `opt_const_param_of` for other bodies returns `None`.
132 // It looks like caching this query on disk actually slightly
133 // worsened performance in #74376.
135 // Once const generics are more prevalently used, we might want to
136 // consider only caching calls returning `Some`.
137 query opt_const_param_of(key: LocalDefId) -> Option<DefId> {
138 desc { |tcx| "computing the optional const parameter of `{}`", tcx.def_path_str(key.to_def_id()) }
141 /// Given the def_id of a const-generic parameter, computes the associated default const
142 /// parameter. e.g. `fn example<const N: usize=3>` called on `N` would return `3`.
143 query const_param_default(param: DefId) -> ty::Const<'tcx> {
144 desc { |tcx| "computing const default for a given parameter `{}`", tcx.def_path_str(param) }
145 cache_on_disk_if { param.is_local() }
146 separate_provide_extern
149 /// Returns the [`Ty`][rustc_middle::ty::Ty] of the given [`DefId`]. If the [`DefId`] points
150 /// to an alias, it will "skip" this alias to return the aliased type.
152 /// [`DefId`]: rustc_hir::def_id::DefId
153 query type_of(key: DefId) -> Ty<'tcx> {
157 use rustc_hir::def::DefKind;
158 match tcx.def_kind(key) {
159 DefKind::TyAlias => "expanding type alias",
160 DefKind::TraitAlias => "expanding trait alias",
161 _ => "computing type of",
164 path = tcx.def_path_str(key),
166 cache_on_disk_if { key.is_local() }
167 separate_provide_extern
170 query collect_trait_impl_trait_tys(key: DefId)
171 -> Result<&'tcx FxHashMap<DefId, Ty<'tcx>>, ErrorGuaranteed>
173 desc { "comparing an impl and trait method signature, inferring any hidden `impl Trait` types in the process" }
174 cache_on_disk_if { key.is_local() }
175 separate_provide_extern
178 query analysis(key: ()) -> Result<(), ErrorGuaranteed> {
180 desc { "running analysis passes on this crate" }
183 /// This query checks the fulfillment of collected lint expectations.
184 /// All lint emitting queries have to be done before this is executed
185 /// to ensure that all expectations can be fulfilled.
187 /// This is an extra query to enable other drivers (like rustdoc) to
188 /// only execute a small subset of the `analysis` query, while allowing
189 /// lints to be expected. In rustc, this query will be executed as part of
190 /// the `analysis` query and doesn't have to be called a second time.
192 /// Tools can additionally pass in a tool filter. That will restrict the
193 /// expectations to only trigger for lints starting with the listed tool
194 /// name. This is useful for cases were not all linting code from rustc
195 /// was called. With the default `None` all registered lints will also
196 /// be checked for expectation fulfillment.
197 query check_expectations(key: Option<Symbol>) -> () {
199 desc { "checking lint expectations (RFC 2383)" }
202 /// Maps from the `DefId` of an item (trait/struct/enum/fn) to its
203 /// associated generics.
204 query generics_of(key: DefId) -> ty::Generics {
205 desc { |tcx| "computing generics of `{}`", tcx.def_path_str(key) }
207 cache_on_disk_if { key.is_local() }
208 separate_provide_extern
211 /// Maps from the `DefId` of an item (trait/struct/enum/fn) to the
212 /// predicates (where-clauses) that must be proven true in order
213 /// to reference it. This is almost always the "predicates query"
216 /// `predicates_of` builds on `predicates_defined_on` -- in fact,
217 /// it is almost always the same as that query, except for the
218 /// case of traits. For traits, `predicates_of` contains
219 /// an additional `Self: Trait<...>` predicate that users don't
220 /// actually write. This reflects the fact that to invoke the
221 /// trait (e.g., via `Default::default`) you must supply types
222 /// that actually implement the trait. (However, this extra
223 /// predicate gets in the way of some checks, which are intended
224 /// to operate over only the actual where-clauses written by the
226 query predicates_of(key: DefId) -> ty::GenericPredicates<'tcx> {
227 desc { |tcx| "computing predicates of `{}`", tcx.def_path_str(key) }
228 cache_on_disk_if { key.is_local() }
231 /// Returns the list of bounds that can be used for
232 /// `SelectionCandidate::ProjectionCandidate(_)` and
233 /// `ProjectionTyCandidate::TraitDef`.
234 /// Specifically this is the bounds written on the trait's type
235 /// definition, or those after the `impl` keyword
237 /// ```ignore (incomplete)
238 /// type X: Bound + 'lt
240 /// impl Debug + Display
241 /// // ^^^^^^^^^^^^^^^
244 /// `key` is the `DefId` of the associated type or opaque type.
246 /// Bounds from the parent (e.g. with nested impl trait) are not included.
247 query explicit_item_bounds(key: DefId) -> &'tcx [(ty::Predicate<'tcx>, Span)] {
248 desc { |tcx| "finding item bounds for `{}`", tcx.def_path_str(key) }
249 cache_on_disk_if { key.is_local() }
250 separate_provide_extern
253 /// Elaborated version of the predicates from `explicit_item_bounds`.
259 /// type MyAType: Eq + ?Sized;
263 /// `explicit_item_bounds` returns `[<Self as MyTrait>::MyAType: Eq]`,
264 /// and `item_bounds` returns
267 /// <Self as Trait>::MyAType: Eq,
268 /// <Self as Trait>::MyAType: PartialEq<<Self as Trait>::MyAType>
272 /// Bounds from the parent (e.g. with nested impl trait) are not included.
273 query item_bounds(key: DefId) -> &'tcx ty::List<ty::Predicate<'tcx>> {
274 desc { |tcx| "elaborating item bounds for `{}`", tcx.def_path_str(key) }
277 query native_libraries(_: CrateNum) -> Vec<NativeLib> {
279 desc { "looking up the native libraries of a linked crate" }
280 separate_provide_extern
283 query shallow_lint_levels_on(key: hir::OwnerId) -> rustc_middle::lint::ShallowLintLevelMap {
284 eval_always // fetches `resolutions`
286 desc { |tcx| "looking up lint levels for `{}`", tcx.def_path_str(key.to_def_id()) }
289 query lint_expectations(_: ()) -> Vec<(LintExpectationId, LintExpectation)> {
291 desc { "computing `#[expect]`ed lints in this crate" }
294 query parent_module_from_def_id(key: LocalDefId) -> LocalDefId {
296 desc { |tcx| "getting the parent module of `{}`", tcx.def_path_str(key.to_def_id()) }
299 query expn_that_defined(key: DefId) -> rustc_span::ExpnId {
300 desc { |tcx| "getting the expansion that defined `{}`", tcx.def_path_str(key) }
301 separate_provide_extern
304 query is_panic_runtime(_: CrateNum) -> bool {
306 desc { "checking if the crate is_panic_runtime" }
307 separate_provide_extern
310 /// Checks whether a type is representable or infinitely sized
311 query representability(_: LocalDefId) -> rustc_middle::ty::Representability {
312 desc { "checking if `{}` is representable", tcx.def_path_str(key.to_def_id()) }
313 // infinitely sized types will cause a cycle
315 // we don't want recursive representability calls to be forced with
316 // incremental compilation because, if a cycle occurs, we need the
317 // entire cycle to be in memory for diagnostics
321 /// An implementation detail for the `representability` query
322 query representability_adt_ty(_: Ty<'tcx>) -> rustc_middle::ty::Representability {
323 desc { "checking if `{}` is representable", key }
328 /// Set of param indexes for type params that are in the type's representation
329 query params_in_repr(key: DefId) -> rustc_index::bit_set::BitSet<u32> {
330 desc { "finding type parameters in the representation" }
333 separate_provide_extern
336 /// Fetch the THIR for a given body. If typeck for that body failed, returns an empty `Thir`.
337 query thir_body(key: ty::WithOptConstParam<LocalDefId>)
338 -> Result<(&'tcx Steal<thir::Thir<'tcx>>, thir::ExprId), ErrorGuaranteed>
340 // Perf tests revealed that hashing THIR is inefficient (see #85729).
342 desc { |tcx| "building THIR for `{}`", tcx.def_path_str(key.did.to_def_id()) }
345 /// Create a THIR tree for debugging.
346 query thir_tree(key: ty::WithOptConstParam<LocalDefId>) -> String {
349 desc { |tcx| "constructing THIR tree for `{}`", tcx.def_path_str(key.did.to_def_id()) }
352 /// Set of all the `DefId`s in this crate that have MIR associated with
353 /// them. This includes all the body owners, but also things like struct
355 query mir_keys(_: ()) -> rustc_data_structures::fx::FxIndexSet<LocalDefId> {
357 desc { "getting a list of all mir_keys" }
360 /// Maps DefId's that have an associated `mir::Body` to the result
361 /// of the MIR const-checking pass. This is the set of qualifs in
362 /// the final value of a `const`.
363 query mir_const_qualif(key: DefId) -> mir::ConstQualifs {
364 desc { |tcx| "const checking `{}`", tcx.def_path_str(key) }
365 cache_on_disk_if { key.is_local() }
366 separate_provide_extern
368 query mir_const_qualif_const_arg(
369 key: (LocalDefId, DefId)
370 ) -> mir::ConstQualifs {
372 |tcx| "const checking the const argument `{}`",
373 tcx.def_path_str(key.0.to_def_id())
377 /// Fetch the MIR for a given `DefId` right after it's built - this includes
378 /// unreachable code.
379 query mir_built(key: ty::WithOptConstParam<LocalDefId>) -> &'tcx Steal<mir::Body<'tcx>> {
380 desc { |tcx| "building MIR for `{}`", tcx.def_path_str(key.did.to_def_id()) }
383 /// Fetch the MIR for a given `DefId` up till the point where it is
384 /// ready for const qualification.
386 /// See the README for the `mir` module for details.
387 query mir_const(key: ty::WithOptConstParam<LocalDefId>) -> &'tcx Steal<mir::Body<'tcx>> {
389 |tcx| "preparing {}`{}` for borrow checking",
390 if key.const_param_did.is_some() { "the const argument " } else { "" },
391 tcx.def_path_str(key.did.to_def_id()),
396 /// Try to build an abstract representation of the given constant.
397 query thir_abstract_const(
399 ) -> Result<Option<&'tcx [ty::abstract_const::Node<'tcx>]>, ErrorGuaranteed> {
401 |tcx| "building an abstract representation for `{}`", tcx.def_path_str(key),
403 separate_provide_extern
405 /// Try to build an abstract representation of the given constant.
406 query thir_abstract_const_of_const_arg(
407 key: (LocalDefId, DefId)
408 ) -> Result<Option<&'tcx [ty::abstract_const::Node<'tcx>]>, ErrorGuaranteed> {
411 "building an abstract representation for the const argument `{}`",
412 tcx.def_path_str(key.0.to_def_id()),
416 query try_unify_abstract_consts(key:
417 ty::ParamEnvAnd<'tcx, (ty::UnevaluatedConst<'tcx>, ty::UnevaluatedConst<'tcx>
420 |tcx| "trying to unify the generic constants `{}` and `{}`",
421 tcx.def_path_str(key.value.0.def.did), tcx.def_path_str(key.value.1.def.did)
425 query mir_drops_elaborated_and_const_checked(
426 key: ty::WithOptConstParam<LocalDefId>
427 ) -> &'tcx Steal<mir::Body<'tcx>> {
429 desc { |tcx| "elaborating drops for `{}`", tcx.def_path_str(key.did.to_def_id()) }
434 ) -> &'tcx mir::Body<'tcx> {
435 desc { |tcx| "caching mir of `{}` for CTFE", tcx.def_path_str(key) }
436 cache_on_disk_if { key.is_local() }
437 separate_provide_extern
440 query mir_for_ctfe_of_const_arg(key: (LocalDefId, DefId)) -> &'tcx mir::Body<'tcx> {
442 |tcx| "caching MIR for CTFE of the const argument `{}`",
443 tcx.def_path_str(key.0.to_def_id())
447 query mir_promoted(key: ty::WithOptConstParam<LocalDefId>) ->
449 &'tcx Steal<mir::Body<'tcx>>,
450 &'tcx Steal<IndexVec<mir::Promoted, mir::Body<'tcx>>>
454 |tcx| "processing MIR for {}`{}`",
455 if key.const_param_did.is_some() { "the const argument " } else { "" },
456 tcx.def_path_str(key.did.to_def_id()),
460 query symbols_for_closure_captures(
461 key: (LocalDefId, LocalDefId)
462 ) -> Vec<rustc_span::Symbol> {
465 |tcx| "finding symbols for captures of closure `{}` in `{}`",
466 tcx.def_path_str(key.1.to_def_id()),
467 tcx.def_path_str(key.0.to_def_id())
471 /// MIR after our optimization passes have run. This is MIR that is ready
472 /// for codegen. This is also the only query that can fetch non-local MIR, at present.
473 query optimized_mir(key: DefId) -> &'tcx mir::Body<'tcx> {
474 desc { |tcx| "optimizing MIR for `{}`", tcx.def_path_str(key) }
475 cache_on_disk_if { key.is_local() }
476 separate_provide_extern
479 /// Returns coverage summary info for a function, after executing the `InstrumentCoverage`
480 /// MIR pass (assuming the -Cinstrument-coverage option is enabled).
481 query coverageinfo(key: ty::InstanceDef<'tcx>) -> mir::CoverageInfo {
482 desc { |tcx| "retrieving coverage info from MIR for `{}`", tcx.def_path_str(key.def_id()) }
486 /// Returns the `CodeRegions` for a function that has instrumented coverage, in case the
487 /// function was optimized out before codegen, and before being added to the Coverage Map.
488 query covered_code_regions(key: DefId) -> Vec<&'tcx mir::coverage::CodeRegion> {
490 |tcx| "retrieving the covered `CodeRegion`s, if instrumented, for `{}`",
491 tcx.def_path_str(key)
494 cache_on_disk_if { key.is_local() }
497 /// The `DefId` is the `DefId` of the containing MIR body. Promoteds do not have their own
498 /// `DefId`. This function returns all promoteds in the specified body. The body references
499 /// promoteds by the `DefId` and the `mir::Promoted` index. This is necessary, because
500 /// after inlining a body may refer to promoteds from other bodies. In that case you still
501 /// need to use the `DefId` of the original body.
502 query promoted_mir(key: DefId) -> &'tcx IndexVec<mir::Promoted, mir::Body<'tcx>> {
503 desc { |tcx| "optimizing promoted MIR for `{}`", tcx.def_path_str(key) }
504 cache_on_disk_if { key.is_local() }
505 separate_provide_extern
507 query promoted_mir_of_const_arg(
508 key: (LocalDefId, DefId)
509 ) -> &'tcx IndexVec<mir::Promoted, mir::Body<'tcx>> {
511 |tcx| "optimizing promoted MIR for the const argument `{}`",
512 tcx.def_path_str(key.0.to_def_id()),
516 /// Erases regions from `ty` to yield a new type.
517 /// Normally you would just use `tcx.erase_regions(value)`,
518 /// however, which uses this query as a kind of cache.
519 query erase_regions_ty(ty: Ty<'tcx>) -> Ty<'tcx> {
520 // This query is not expected to have input -- as a result, it
521 // is not a good candidates for "replay" because it is essentially a
522 // pure function of its input (and hence the expectation is that
523 // no caller would be green **apart** from just these
524 // queries). Making it anonymous avoids hashing the result, which
525 // may save a bit of time.
527 desc { "erasing regions from `{}`", ty }
530 query wasm_import_module_map(_: CrateNum) -> FxHashMap<DefId, String> {
532 desc { "getting wasm import module map" }
535 /// Maps from the `DefId` of an item (trait/struct/enum/fn) to the
536 /// predicates (where-clauses) directly defined on it. This is
537 /// equal to the `explicit_predicates_of` predicates plus the
538 /// `inferred_outlives_of` predicates.
539 query predicates_defined_on(key: DefId) -> ty::GenericPredicates<'tcx> {
540 desc { |tcx| "computing predicates of `{}`", tcx.def_path_str(key) }
543 /// Returns everything that looks like a predicate written explicitly
544 /// by the user on a trait item.
546 /// Traits are unusual, because predicates on associated types are
547 /// converted into bounds on that type for backwards compatibility:
549 /// trait X where Self::U: Copy { type U; }
553 /// trait X { type U: Copy; }
555 /// `explicit_predicates_of` and `explicit_item_bounds` will then take
556 /// the appropriate subsets of the predicates here.
557 query trait_explicit_predicates_and_bounds(key: LocalDefId) -> ty::GenericPredicates<'tcx> {
558 desc { |tcx| "computing explicit predicates of trait `{}`", tcx.def_path_str(key.to_def_id()) }
561 /// Returns the predicates written explicitly by the user.
562 query explicit_predicates_of(key: DefId) -> ty::GenericPredicates<'tcx> {
563 desc { |tcx| "computing explicit predicates of `{}`", tcx.def_path_str(key) }
564 cache_on_disk_if { key.is_local() }
565 separate_provide_extern
568 /// Returns the inferred outlives predicates (e.g., for `struct
569 /// Foo<'a, T> { x: &'a T }`, this would return `T: 'a`).
570 query inferred_outlives_of(key: DefId) -> &'tcx [(ty::Predicate<'tcx>, Span)] {
571 desc { |tcx| "computing inferred outlives predicates of `{}`", tcx.def_path_str(key) }
572 cache_on_disk_if { key.is_local() }
573 separate_provide_extern
576 /// Maps from the `DefId` of a trait to the list of
577 /// super-predicates. This is a subset of the full list of
578 /// predicates. We store these in a separate map because we must
579 /// evaluate them even during type conversion, often before the
580 /// full predicates are available (note that supertraits have
581 /// additional acyclicity requirements).
582 query super_predicates_of(key: DefId) -> ty::GenericPredicates<'tcx> {
583 desc { |tcx| "computing the super predicates of `{}`", tcx.def_path_str(key) }
584 cache_on_disk_if { key.is_local() }
585 separate_provide_extern
588 /// The `Option<Ident>` is the name of an associated type. If it is `None`, then this query
589 /// returns the full set of predicates. If `Some<Ident>`, then the query returns only the
590 /// subset of super-predicates that reference traits that define the given associated type.
591 /// This is used to avoid cycles in resolving types like `T::Item`.
592 query super_predicates_that_define_assoc_type(key: (DefId, Option<rustc_span::symbol::Ident>)) -> ty::GenericPredicates<'tcx> {
593 desc { |tcx| "computing the super traits of `{}`{}",
594 tcx.def_path_str(key.0),
595 if let Some(assoc_name) = key.1 { format!(" with associated type name `{}`", assoc_name) } else { "".to_string() },
599 /// To avoid cycles within the predicates of a single item we compute
600 /// per-type-parameter predicates for resolving `T::AssocTy`.
601 query type_param_predicates(key: (DefId, LocalDefId, rustc_span::symbol::Ident)) -> ty::GenericPredicates<'tcx> {
602 desc { |tcx| "computing the bounds for type parameter `{}`", tcx.hir().ty_param_name(key.1) }
605 query trait_def(key: DefId) -> ty::TraitDef {
606 desc { |tcx| "computing trait definition for `{}`", tcx.def_path_str(key) }
608 cache_on_disk_if { key.is_local() }
609 separate_provide_extern
611 query adt_def(key: DefId) -> ty::AdtDef<'tcx> {
612 desc { |tcx| "computing ADT definition for `{}`", tcx.def_path_str(key) }
613 cache_on_disk_if { key.is_local() }
614 separate_provide_extern
616 query adt_destructor(key: DefId) -> Option<ty::Destructor> {
617 desc { |tcx| "computing `Drop` impl for `{}`", tcx.def_path_str(key) }
618 cache_on_disk_if { key.is_local() }
619 separate_provide_extern
622 query adt_sized_constraint(key: DefId) -> &'tcx [Ty<'tcx>] {
623 desc { |tcx| "computing `Sized` constraints for `{}`", tcx.def_path_str(key) }
626 query adt_dtorck_constraint(
628 ) -> Result<&'tcx DropckConstraint<'tcx>, NoSolution> {
629 desc { |tcx| "computing drop-check constraints for `{}`", tcx.def_path_str(key) }
632 /// Returns `true` if this is a const fn, use the `is_const_fn` to know whether your crate
633 /// actually sees it as const fn (e.g., the const-fn-ness might be unstable and you might
634 /// not have the feature gate active).
636 /// **Do not call this function manually.** It is only meant to cache the base data for the
637 /// `is_const_fn` function. Consider using `is_const_fn` or `is_const_fn_raw` instead.
638 query constness(key: DefId) -> hir::Constness {
639 desc { |tcx| "checking if item is const: `{}`", tcx.def_path_str(key) }
640 cache_on_disk_if { key.is_local() }
641 separate_provide_extern
644 query asyncness(key: DefId) -> hir::IsAsync {
645 desc { |tcx| "checking if the function is async: `{}`", tcx.def_path_str(key) }
646 cache_on_disk_if { key.is_local() }
647 separate_provide_extern
650 /// Returns `true` if calls to the function may be promoted.
652 /// This is either because the function is e.g., a tuple-struct or tuple-variant
653 /// constructor, or because it has the `#[rustc_promotable]` attribute. The attribute should
654 /// be removed in the future in favour of some form of check which figures out whether the
655 /// function does not inspect the bits of any of its arguments (so is essentially just a
656 /// constructor function).
657 query is_promotable_const_fn(key: DefId) -> bool {
658 desc { |tcx| "checking if item is promotable: `{}`", tcx.def_path_str(key) }
661 /// Returns `true` if this is a foreign item (i.e., linked via `extern { ... }`).
662 query is_foreign_item(key: DefId) -> bool {
663 desc { |tcx| "checking if `{}` is a foreign item", tcx.def_path_str(key) }
664 cache_on_disk_if { key.is_local() }
665 separate_provide_extern
668 /// Returns `Some(generator_kind)` if the node pointed to by `def_id` is a generator.
669 query generator_kind(def_id: DefId) -> Option<hir::GeneratorKind> {
670 desc { |tcx| "looking up generator kind of `{}`", tcx.def_path_str(def_id) }
671 cache_on_disk_if { def_id.is_local() }
672 separate_provide_extern
675 /// Gets a map with the variance of every item; use `item_variance` instead.
676 query crate_variances(_: ()) -> ty::CrateVariancesMap<'tcx> {
678 desc { "computing the variances for items in this crate" }
681 /// Maps from the `DefId` of a type or region parameter to its (inferred) variance.
682 query variances_of(def_id: DefId) -> &'tcx [ty::Variance] {
683 desc { |tcx| "computing the variances of `{}`", tcx.def_path_str(def_id) }
684 cache_on_disk_if { def_id.is_local() }
685 separate_provide_extern
688 /// Maps from thee `DefId` of a type to its (inferred) outlives.
689 query inferred_outlives_crate(_: ()) -> ty::CratePredicatesMap<'tcx> {
691 desc { "computing the inferred outlives predicates for items in this crate" }
694 /// Maps from an impl/trait `DefId` to a list of the `DefId`s of its items.
695 query associated_item_def_ids(key: DefId) -> &'tcx [DefId] {
696 desc { |tcx| "collecting associated items of `{}`", tcx.def_path_str(key) }
697 cache_on_disk_if { key.is_local() }
698 separate_provide_extern
701 /// Maps from a trait item to the trait item "descriptor".
702 query associated_item(key: DefId) -> ty::AssocItem {
703 desc { |tcx| "computing associated item data for `{}`", tcx.def_path_str(key) }
705 cache_on_disk_if { key.is_local() }
706 separate_provide_extern
709 /// Collects the associated items defined on a trait or impl.
710 query associated_items(key: DefId) -> ty::AssocItems<'tcx> {
712 desc { |tcx| "collecting associated items of `{}`", tcx.def_path_str(key) }
715 /// Maps from associated items on a trait to the corresponding associated
716 /// item on the impl specified by `impl_id`.
718 /// For example, with the following code
723 /// trait Trait { // trait_id
724 /// fn f(); // trait_f
725 /// fn g() {} // trait_g
728 /// impl Trait for Type { // impl_id
729 /// fn f() {} // impl_f
730 /// fn g() {} // impl_g
734 /// The map returned for `tcx.impl_item_implementor_ids(impl_id)` would be
735 ///`{ trait_f: impl_f, trait_g: impl_g }`
736 query impl_item_implementor_ids(impl_id: DefId) -> FxHashMap<DefId, DefId> {
738 desc { |tcx| "comparing impl items against trait for `{}`", tcx.def_path_str(impl_id) }
741 /// Given an `impl_id`, return the trait it implements.
742 /// Return `None` if this is an inherent impl.
743 query impl_trait_ref(impl_id: DefId) -> Option<ty::TraitRef<'tcx>> {
744 desc { |tcx| "computing trait implemented by `{}`", tcx.def_path_str(impl_id) }
745 cache_on_disk_if { impl_id.is_local() }
746 separate_provide_extern
748 query impl_polarity(impl_id: DefId) -> ty::ImplPolarity {
749 desc { |tcx| "computing implementation polarity of `{}`", tcx.def_path_str(impl_id) }
750 cache_on_disk_if { impl_id.is_local() }
751 separate_provide_extern
754 query issue33140_self_ty(key: DefId) -> Option<ty::Ty<'tcx>> {
755 desc { |tcx| "computing Self type wrt issue #33140 `{}`", tcx.def_path_str(key) }
758 /// Maps a `DefId` of a type to a list of its inherent impls.
759 /// Contains implementations of methods that are inherent to a type.
760 /// Methods in these implementations don't need to be exported.
761 query inherent_impls(key: DefId) -> &'tcx [DefId] {
762 desc { |tcx| "collecting inherent impls for `{}`", tcx.def_path_str(key) }
763 cache_on_disk_if { key.is_local() }
764 separate_provide_extern
767 query incoherent_impls(key: SimplifiedType) -> &'tcx [DefId] {
768 desc { |tcx| "collecting all inherent impls for `{:?}`", key }
771 /// The result of unsafety-checking this `LocalDefId`.
772 query unsafety_check_result(key: LocalDefId) -> &'tcx mir::UnsafetyCheckResult {
773 desc { |tcx| "unsafety-checking `{}`", tcx.def_path_str(key.to_def_id()) }
774 cache_on_disk_if { true }
776 query unsafety_check_result_for_const_arg(key: (LocalDefId, DefId)) -> &'tcx mir::UnsafetyCheckResult {
778 |tcx| "unsafety-checking the const argument `{}`",
779 tcx.def_path_str(key.0.to_def_id())
783 /// Unsafety-check this `LocalDefId` with THIR unsafeck. This should be
784 /// used with `-Zthir-unsafeck`.
785 query thir_check_unsafety(key: LocalDefId) {
786 desc { |tcx| "unsafety-checking `{}`", tcx.def_path_str(key.to_def_id()) }
787 cache_on_disk_if { true }
789 query thir_check_unsafety_for_const_arg(key: (LocalDefId, DefId)) {
791 |tcx| "unsafety-checking the const argument `{}`",
792 tcx.def_path_str(key.0.to_def_id())
796 /// HACK: when evaluated, this reports an "unsafe derive on repr(packed)" error.
798 /// Unsafety checking is executed for each method separately, but we only want
799 /// to emit this error once per derive. As there are some impls with multiple
800 /// methods, we use a query for deduplication.
801 query unsafe_derive_on_repr_packed(key: LocalDefId) -> () {
802 desc { |tcx| "processing `{}`", tcx.def_path_str(key.to_def_id()) }
805 /// Returns the types assumed to be well formed while "inside" of the given item.
807 /// Note that we've liberated the late bound regions of function signatures, so
808 /// this can not be used to check whether these types are well formed.
809 query assumed_wf_types(key: DefId) -> &'tcx ty::List<Ty<'tcx>> {
810 desc { |tcx| "computing the implied bounds of `{}`", tcx.def_path_str(key) }
813 /// Computes the signature of the function.
814 query fn_sig(key: DefId) -> ty::PolyFnSig<'tcx> {
815 desc { |tcx| "computing function signature of `{}`", tcx.def_path_str(key) }
816 cache_on_disk_if { key.is_local() }
817 separate_provide_extern
821 /// Performs lint checking for the module.
822 query lint_mod(key: LocalDefId) -> () {
823 desc { |tcx| "linting {}", describe_as_module(key, tcx) }
826 /// Checks the attributes in the module.
827 query check_mod_attrs(key: LocalDefId) -> () {
828 desc { |tcx| "checking attributes in {}", describe_as_module(key, tcx) }
831 /// Checks for uses of unstable APIs in the module.
832 query check_mod_unstable_api_usage(key: LocalDefId) -> () {
833 desc { |tcx| "checking for unstable API usage in {}", describe_as_module(key, tcx) }
836 /// Checks the const bodies in the module for illegal operations (e.g. `if` or `loop`).
837 query check_mod_const_bodies(key: LocalDefId) -> () {
838 desc { |tcx| "checking consts in {}", describe_as_module(key, tcx) }
841 /// Checks the loops in the module.
842 query check_mod_loops(key: LocalDefId) -> () {
843 desc { |tcx| "checking loops in {}", describe_as_module(key, tcx) }
846 query check_mod_naked_functions(key: LocalDefId) -> () {
847 desc { |tcx| "checking naked functions in {}", describe_as_module(key, tcx) }
850 query check_mod_item_types(key: LocalDefId) -> () {
851 desc { |tcx| "checking item types in {}", describe_as_module(key, tcx) }
854 query check_mod_privacy(key: LocalDefId) -> () {
855 desc { |tcx| "checking privacy in {}", describe_as_module(key, tcx) }
858 query check_liveness(key: DefId) {
859 desc { |tcx| "checking liveness of variables in `{}`", tcx.def_path_str(key) }
862 /// Return the live symbols in the crate for dead code check.
864 /// The second return value maps from ADTs to ignored derived traits (e.g. Debug and Clone) and
865 /// their respective impl (i.e., part of the derive macro)
866 query live_symbols_and_ignored_derived_traits(_: ()) -> (
867 FxHashSet<LocalDefId>,
868 FxHashMap<LocalDefId, Vec<(DefId, DefId)>>
871 desc { "finding live symbols in crate" }
874 query check_mod_deathness(key: LocalDefId) -> () {
875 desc { |tcx| "checking deathness of variables in {}", describe_as_module(key, tcx) }
878 query check_mod_impl_wf(key: LocalDefId) -> () {
879 desc { |tcx| "checking that impls are well-formed in {}", describe_as_module(key, tcx) }
882 query check_mod_type_wf(key: LocalDefId) -> () {
883 desc { |tcx| "checking that types are well-formed in {}", describe_as_module(key, tcx) }
886 query collect_mod_item_types(key: LocalDefId) -> () {
887 desc { |tcx| "collecting item types in {}", describe_as_module(key, tcx) }
890 /// Caches `CoerceUnsized` kinds for impls on custom types.
891 query coerce_unsized_info(key: DefId) -> ty::adjustment::CoerceUnsizedInfo {
892 desc { |tcx| "computing CoerceUnsized info for `{}`", tcx.def_path_str(key) }
893 cache_on_disk_if { key.is_local() }
894 separate_provide_extern
897 query typeck_item_bodies(_: ()) -> () {
898 desc { "type-checking all item bodies" }
901 query typeck(key: LocalDefId) -> &'tcx ty::TypeckResults<'tcx> {
902 desc { |tcx| "type-checking `{}`", tcx.def_path_str(key.to_def_id()) }
903 cache_on_disk_if { true }
905 query typeck_const_arg(
906 key: (LocalDefId, DefId)
907 ) -> &'tcx ty::TypeckResults<'tcx> {
909 |tcx| "type-checking the const argument `{}`",
910 tcx.def_path_str(key.0.to_def_id()),
913 query diagnostic_only_typeck(key: LocalDefId) -> &'tcx ty::TypeckResults<'tcx> {
914 desc { |tcx| "type-checking `{}`", tcx.def_path_str(key.to_def_id()) }
915 cache_on_disk_if { true }
918 query used_trait_imports(key: LocalDefId) -> &'tcx UnordSet<LocalDefId> {
919 desc { |tcx| "finding used_trait_imports `{}`", tcx.def_path_str(key.to_def_id()) }
920 cache_on_disk_if { true }
923 query has_typeck_results(def_id: DefId) -> bool {
924 desc { |tcx| "checking whether `{}` has a body", tcx.def_path_str(def_id) }
927 query coherent_trait(def_id: DefId) -> () {
928 desc { |tcx| "coherence checking all impls of trait `{}`", tcx.def_path_str(def_id) }
931 /// Borrow-checks the function body. If this is a closure, returns
932 /// additional requirements that the closure's creator must verify.
933 query mir_borrowck(key: LocalDefId) -> &'tcx mir::BorrowCheckResult<'tcx> {
934 desc { |tcx| "borrow-checking `{}`", tcx.def_path_str(key.to_def_id()) }
935 cache_on_disk_if(tcx) { tcx.is_typeck_child(key.to_def_id()) }
937 query mir_borrowck_const_arg(key: (LocalDefId, DefId)) -> &'tcx mir::BorrowCheckResult<'tcx> {
939 |tcx| "borrow-checking the const argument`{}`",
940 tcx.def_path_str(key.0.to_def_id())
944 /// Gets a complete map from all types to their inherent impls.
945 /// Not meant to be used directly outside of coherence.
946 query crate_inherent_impls(k: ()) -> CrateInherentImpls {
948 desc { "finding all inherent impls defined in crate" }
951 /// Checks all types in the crate for overlap in their inherent impls. Reports errors.
952 /// Not meant to be used directly outside of coherence.
953 query crate_inherent_impls_overlap_check(_: ()) -> () {
954 desc { "check for overlap between inherent impls defined in this crate" }
957 /// Checks whether all impls in the crate pass the overlap check, returning
958 /// which impls fail it. If all impls are correct, the returned slice is empty.
959 query orphan_check_impl(key: LocalDefId) -> Result<(), ErrorGuaranteed> {
961 "checking whether impl `{}` follows the orphan rules",
962 tcx.def_path_str(key.to_def_id()),
966 /// Check whether the function has any recursion that could cause the inliner to trigger
967 /// a cycle. Returns the call stack causing the cycle. The call stack does not contain the
968 /// current function, just all intermediate functions.
969 query mir_callgraph_reachable(key: (ty::Instance<'tcx>, LocalDefId)) -> bool {
972 "computing if `{}` (transitively) calls `{}`",
974 tcx.def_path_str(key.1.to_def_id()),
978 /// Obtain all the calls into other local functions
979 query mir_inliner_callees(key: ty::InstanceDef<'tcx>) -> &'tcx [(DefId, SubstsRef<'tcx>)] {
982 "computing all local function calls in `{}`",
983 tcx.def_path_str(key.def_id()),
987 /// Evaluates a constant and returns the computed allocation.
989 /// **Do not use this** directly, use the `tcx.eval_static_initializer` wrapper.
990 query eval_to_allocation_raw(key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>)
991 -> EvalToAllocationRawResult<'tcx> {
993 "const-evaluating + checking `{}`",
994 key.value.display(tcx)
996 cache_on_disk_if { true }
999 /// Evaluates const items or anonymous constants
1000 /// (such as enum variant explicit discriminants or array lengths)
1001 /// into a representation suitable for the type system and const generics.
1003 /// **Do not use this** directly, use one of the following wrappers: `tcx.const_eval_poly`,
1004 /// `tcx.const_eval_resolve`, `tcx.const_eval_instance`, or `tcx.const_eval_global_id`.
1005 query eval_to_const_value_raw(key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>)
1006 -> EvalToConstValueResult<'tcx> {
1008 "simplifying constant for the type system `{}`",
1009 key.value.display(tcx)
1011 cache_on_disk_if { true }
1014 /// Evaluate a constant and convert it to a type level constant or
1015 /// return `None` if that is not possible.
1016 query eval_to_valtree(
1017 key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>
1018 ) -> EvalToValTreeResult<'tcx> {
1019 desc { "evaluating type-level constant" }
1022 /// Converts a type level constant value into `ConstValue`
1023 query valtree_to_const_val(key: (Ty<'tcx>, ty::ValTree<'tcx>)) -> ConstValue<'tcx> {
1024 desc { "converting type-level constant value to mir constant value"}
1027 /// Destructures array, ADT or tuple constants into the constants
1028 /// of their fields.
1029 query destructure_const(key: ty::Const<'tcx>) -> ty::DestructuredConst<'tcx> {
1030 desc { "destructuring type level constant"}
1033 /// Tries to destructure an `mir::ConstantKind` ADT or array into its variant index
1034 /// and its field values.
1035 query try_destructure_mir_constant(
1036 key: ty::ParamEnvAnd<'tcx, mir::ConstantKind<'tcx>>
1037 ) -> Option<mir::DestructuredConstant<'tcx>> {
1038 desc { "destructuring MIR constant"}
1042 /// Dereference a constant reference or raw pointer and turn the result into a constant
1044 query deref_mir_constant(
1045 key: ty::ParamEnvAnd<'tcx, mir::ConstantKind<'tcx>>
1046 ) -> mir::ConstantKind<'tcx> {
1047 desc { "dereferencing MIR constant" }
1051 query const_caller_location(key: (rustc_span::Symbol, u32, u32)) -> ConstValue<'tcx> {
1052 desc { "getting a &core::panic::Location referring to a span" }
1055 // FIXME get rid of this with valtrees
1057 key: LitToConstInput<'tcx>
1058 ) -> Result<ty::Const<'tcx>, LitToConstError> {
1059 desc { "converting literal to const" }
1062 query lit_to_mir_constant(key: LitToConstInput<'tcx>) -> Result<mir::ConstantKind<'tcx>, LitToConstError> {
1063 desc { "converting literal to mir constant" }
1066 query check_match(key: DefId) {
1067 desc { |tcx| "match-checking `{}`", tcx.def_path_str(key) }
1068 cache_on_disk_if { key.is_local() }
1071 /// Performs part of the privacy check and computes effective visibilities.
1072 query effective_visibilities(_: ()) -> &'tcx EffectiveVisibilities {
1074 desc { "checking effective visibilities" }
1076 query check_private_in_public(_: ()) -> () {
1078 desc { "checking for private elements in public interfaces" }
1081 query reachable_set(_: ()) -> FxHashSet<LocalDefId> {
1083 desc { "reachability" }
1086 /// Per-body `region::ScopeTree`. The `DefId` should be the owner `DefId` for the body;
1087 /// in the case of closures, this will be redirected to the enclosing function.
1088 query region_scope_tree(def_id: DefId) -> &'tcx crate::middle::region::ScopeTree {
1089 desc { |tcx| "computing drop scopes for `{}`", tcx.def_path_str(def_id) }
1092 /// Generates a MIR body for the shim.
1093 query mir_shims(key: ty::InstanceDef<'tcx>) -> mir::Body<'tcx> {
1095 desc { |tcx| "generating MIR shim for `{}`", tcx.def_path_str(key.def_id()) }
1098 /// The `symbol_name` query provides the symbol name for calling a
1099 /// given instance from the local crate. In particular, it will also
1100 /// look up the correct symbol name of instances from upstream crates.
1101 query symbol_name(key: ty::Instance<'tcx>) -> ty::SymbolName<'tcx> {
1102 desc { "computing the symbol for `{}`", key }
1103 cache_on_disk_if { true }
1106 query opt_def_kind(def_id: DefId) -> Option<DefKind> {
1107 desc { |tcx| "looking up definition kind of `{}`", tcx.def_path_str(def_id) }
1108 cache_on_disk_if { def_id.is_local() }
1109 separate_provide_extern
1112 /// Gets the span for the definition.
1113 query def_span(def_id: DefId) -> Span {
1114 desc { |tcx| "looking up span for `{}`", tcx.def_path_str(def_id) }
1115 cache_on_disk_if { def_id.is_local() }
1116 separate_provide_extern
1119 /// Gets the span for the identifier of the definition.
1120 query def_ident_span(def_id: DefId) -> Option<Span> {
1121 desc { |tcx| "looking up span for `{}`'s identifier", tcx.def_path_str(def_id) }
1122 cache_on_disk_if { def_id.is_local() }
1123 separate_provide_extern
1126 query lookup_stability(def_id: DefId) -> Option<attr::Stability> {
1127 desc { |tcx| "looking up stability of `{}`", tcx.def_path_str(def_id) }
1128 cache_on_disk_if { def_id.is_local() }
1129 separate_provide_extern
1132 query lookup_const_stability(def_id: DefId) -> Option<attr::ConstStability> {
1133 desc { |tcx| "looking up const stability of `{}`", tcx.def_path_str(def_id) }
1134 cache_on_disk_if { def_id.is_local() }
1135 separate_provide_extern
1138 query lookup_default_body_stability(def_id: DefId) -> Option<attr::DefaultBodyStability> {
1139 desc { |tcx| "looking up default body stability of `{}`", tcx.def_path_str(def_id) }
1140 separate_provide_extern
1143 query should_inherit_track_caller(def_id: DefId) -> bool {
1144 desc { |tcx| "computing should_inherit_track_caller of `{}`", tcx.def_path_str(def_id) }
1147 query lookup_deprecation_entry(def_id: DefId) -> Option<DeprecationEntry> {
1148 desc { |tcx| "checking whether `{}` is deprecated", tcx.def_path_str(def_id) }
1149 cache_on_disk_if { def_id.is_local() }
1150 separate_provide_extern
1153 /// Determines whether an item is annotated with `doc(hidden)`.
1154 query is_doc_hidden(def_id: DefId) -> bool {
1155 desc { |tcx| "checking whether `{}` is `doc(hidden)`", tcx.def_path_str(def_id) }
1158 /// Determines whether an item is annotated with `doc(notable_trait)`.
1159 query is_doc_notable_trait(def_id: DefId) -> bool {
1160 desc { |tcx| "checking whether `{}` is `doc(notable_trait)`", tcx.def_path_str(def_id) }
1163 /// Returns the attributes on the item at `def_id`.
1165 /// Do not use this directly, use `tcx.get_attrs` instead.
1166 query item_attrs(def_id: DefId) -> &'tcx [ast::Attribute] {
1167 desc { |tcx| "collecting attributes of `{}`", tcx.def_path_str(def_id) }
1168 separate_provide_extern
1171 query codegen_fn_attrs(def_id: DefId) -> CodegenFnAttrs {
1172 desc { |tcx| "computing codegen attributes of `{}`", tcx.def_path_str(def_id) }
1174 cache_on_disk_if { def_id.is_local() }
1175 separate_provide_extern
1178 query asm_target_features(def_id: DefId) -> &'tcx FxHashSet<Symbol> {
1179 desc { |tcx| "computing target features for inline asm of `{}`", tcx.def_path_str(def_id) }
1182 query fn_arg_names(def_id: DefId) -> &'tcx [rustc_span::symbol::Ident] {
1183 desc { |tcx| "looking up function parameter names for `{}`", tcx.def_path_str(def_id) }
1184 cache_on_disk_if { def_id.is_local() }
1185 separate_provide_extern
1187 /// Gets the rendered value of the specified constant or associated constant.
1188 /// Used by rustdoc.
1189 query rendered_const(def_id: DefId) -> String {
1191 desc { |tcx| "rendering constant initializer of `{}`", tcx.def_path_str(def_id) }
1192 cache_on_disk_if { def_id.is_local() }
1193 separate_provide_extern
1195 query impl_parent(def_id: DefId) -> Option<DefId> {
1196 desc { |tcx| "computing specialization parent impl of `{}`", tcx.def_path_str(def_id) }
1197 cache_on_disk_if { def_id.is_local() }
1198 separate_provide_extern
1201 query is_ctfe_mir_available(key: DefId) -> bool {
1202 desc { |tcx| "checking if item has CTFE MIR available: `{}`", tcx.def_path_str(key) }
1203 cache_on_disk_if { key.is_local() }
1204 separate_provide_extern
1206 query is_mir_available(key: DefId) -> bool {
1207 desc { |tcx| "checking if item has MIR available: `{}`", tcx.def_path_str(key) }
1208 cache_on_disk_if { key.is_local() }
1209 separate_provide_extern
1212 query own_existential_vtable_entries(
1214 ) -> &'tcx [DefId] {
1215 desc { |tcx| "finding all existential vtable entries for trait `{}`", tcx.def_path_str(key) }
1218 query vtable_entries(key: ty::PolyTraitRef<'tcx>)
1219 -> &'tcx [ty::VtblEntry<'tcx>] {
1220 desc { |tcx| "finding all vtable entries for trait `{}`", tcx.def_path_str(key.def_id()) }
1223 query vtable_trait_upcasting_coercion_new_vptr_slot(key: (Ty<'tcx>, Ty<'tcx>)) -> Option<usize> {
1224 desc { |tcx| "finding the slot within vtable for trait object `{}` vtable ptr during trait upcasting coercion from `{}` vtable",
1228 query vtable_allocation(key: (Ty<'tcx>, Option<ty::PolyExistentialTraitRef<'tcx>>)) -> mir::interpret::AllocId {
1229 desc { |tcx| "vtable const allocation for <{} as {}>",
1231 key.1.map(|trait_ref| format!("{}", trait_ref)).unwrap_or("_".to_owned())
1235 query codegen_select_candidate(
1236 key: (ty::ParamEnv<'tcx>, ty::PolyTraitRef<'tcx>)
1237 ) -> Result<&'tcx ImplSource<'tcx, ()>, traits::CodegenObligationError> {
1238 cache_on_disk_if { true }
1239 desc { |tcx| "computing candidate for `{}`", key.1 }
1242 /// Return all `impl` blocks in the current crate.
1243 query all_local_trait_impls(_: ()) -> &'tcx rustc_data_structures::fx::FxIndexMap<DefId, Vec<LocalDefId>> {
1244 desc { "finding local trait impls" }
1247 /// Given a trait `trait_id`, return all known `impl` blocks.
1248 query trait_impls_of(trait_id: DefId) -> ty::trait_def::TraitImpls {
1250 desc { |tcx| "finding trait impls of `{}`", tcx.def_path_str(trait_id) }
1253 query specialization_graph_of(trait_id: DefId) -> specialization_graph::Graph {
1255 desc { |tcx| "building specialization graph of trait `{}`", tcx.def_path_str(trait_id) }
1256 cache_on_disk_if { true }
1258 query object_safety_violations(trait_id: DefId) -> &'tcx [traits::ObjectSafetyViolation] {
1259 desc { |tcx| "determining object safety of trait `{}`", tcx.def_path_str(trait_id) }
1262 /// Gets the ParameterEnvironment for a given item; this environment
1263 /// will be in "user-facing" mode, meaning that it is suitable for
1264 /// type-checking etc, and it does not normalize specializable
1265 /// associated types. This is almost always what you want,
1266 /// unless you are doing MIR optimizations, in which case you
1267 /// might want to use `reveal_all()` method to change modes.
1268 query param_env(def_id: DefId) -> ty::ParamEnv<'tcx> {
1269 desc { |tcx| "computing normalized predicates of `{}`", tcx.def_path_str(def_id) }
1272 /// Like `param_env`, but returns the `ParamEnv` in `Reveal::All` mode.
1273 /// Prefer this over `tcx.param_env(def_id).with_reveal_all_normalized(tcx)`,
1274 /// as this method is more efficient.
1275 query param_env_reveal_all_normalized(def_id: DefId) -> ty::ParamEnv<'tcx> {
1276 desc { |tcx| "computing revealed normalized predicates of `{}`", tcx.def_path_str(def_id) }
1279 /// Trait selection queries. These are best used by invoking `ty.is_copy_modulo_regions()`,
1280 /// `ty.is_copy()`, etc, since that will prune the environment where possible.
1281 query is_copy_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1282 desc { "computing whether `{}` is `Copy`", env.value }
1285 /// Query backing `Ty::is_sized`.
1286 query is_sized_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1287 desc { "computing whether `{}` is `Sized`", env.value }
1290 /// Query backing `Ty::is_freeze`.
1291 query is_freeze_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1292 desc { "computing whether `{}` is freeze", env.value }
1295 /// Query backing `Ty::is_unpin`.
1296 query is_unpin_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1297 desc { "computing whether `{}` is `Unpin`", env.value }
1300 /// Query backing `Ty::needs_drop`.
1301 query needs_drop_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1302 desc { "computing whether `{}` needs drop", env.value }
1305 /// Query backing `Ty::has_significant_drop_raw`.
1306 query has_significant_drop_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1307 desc { "computing whether `{}` has a significant drop", env.value }
1311 /// Query backing `Ty::is_structural_eq_shallow`.
1313 /// This is only correct for ADTs. Call `is_structural_eq_shallow` to handle all types
1315 query has_structural_eq_impls(ty: Ty<'tcx>) -> bool {
1317 "computing whether `{}` implements `PartialStructuralEq` and `StructuralEq`",
1322 /// A list of types where the ADT requires drop if and only if any of
1323 /// those types require drop. If the ADT is known to always need drop
1324 /// then `Err(AlwaysRequiresDrop)` is returned.
1325 query adt_drop_tys(def_id: DefId) -> Result<&'tcx ty::List<Ty<'tcx>>, AlwaysRequiresDrop> {
1326 desc { |tcx| "computing when `{}` needs drop", tcx.def_path_str(def_id) }
1327 cache_on_disk_if { true }
1330 /// A list of types where the ADT requires drop if and only if any of those types
1331 /// has significant drop. A type marked with the attribute `rustc_insignificant_dtor`
1332 /// is considered to not be significant. A drop is significant if it is implemented
1333 /// by the user or does anything that will have any observable behavior (other than
1334 /// freeing up memory). If the ADT is known to have a significant destructor then
1335 /// `Err(AlwaysRequiresDrop)` is returned.
1336 query adt_significant_drop_tys(def_id: DefId) -> Result<&'tcx ty::List<Ty<'tcx>>, AlwaysRequiresDrop> {
1337 desc { |tcx| "computing when `{}` has a significant destructor", tcx.def_path_str(def_id) }
1338 cache_on_disk_if { false }
1341 /// Computes the layout of a type. Note that this implicitly
1342 /// executes in "reveal all" mode, and will normalize the input type.
1344 key: ty::ParamEnvAnd<'tcx, Ty<'tcx>>
1345 ) -> Result<ty::layout::TyAndLayout<'tcx>, ty::layout::LayoutError<'tcx>> {
1347 desc { "computing layout of `{}`", key.value }
1351 /// Compute a `FnAbi` suitable for indirect calls, i.e. to `fn` pointers.
1353 /// NB: this doesn't handle virtual calls - those should use `fn_abi_of_instance`
1354 /// instead, where the instance is an `InstanceDef::Virtual`.
1355 query fn_abi_of_fn_ptr(
1356 key: ty::ParamEnvAnd<'tcx, (ty::PolyFnSig<'tcx>, &'tcx ty::List<Ty<'tcx>>)>
1357 ) -> Result<&'tcx abi::call::FnAbi<'tcx, Ty<'tcx>>, ty::layout::FnAbiError<'tcx>> {
1358 desc { "computing call ABI of `{}` function pointers", key.value.0 }
1362 /// Compute a `FnAbi` suitable for declaring/defining an `fn` instance, and for
1363 /// direct calls to an `fn`.
1365 /// NB: that includes virtual calls, which are represented by "direct calls"
1366 /// to an `InstanceDef::Virtual` instance (of `<dyn Trait as Trait>::fn`).
1367 query fn_abi_of_instance(
1368 key: ty::ParamEnvAnd<'tcx, (ty::Instance<'tcx>, &'tcx ty::List<Ty<'tcx>>)>
1369 ) -> Result<&'tcx abi::call::FnAbi<'tcx, Ty<'tcx>>, ty::layout::FnAbiError<'tcx>> {
1370 desc { "computing call ABI of `{}`", key.value.0 }
1374 query dylib_dependency_formats(_: CrateNum)
1375 -> &'tcx [(CrateNum, LinkagePreference)] {
1376 desc { "getting dylib dependency formats of crate" }
1377 separate_provide_extern
1380 query dependency_formats(_: ()) -> Lrc<crate::middle::dependency_format::Dependencies> {
1382 desc { "getting the linkage format of all dependencies" }
1385 query is_compiler_builtins(_: CrateNum) -> bool {
1387 desc { "checking if the crate is_compiler_builtins" }
1388 separate_provide_extern
1390 query has_global_allocator(_: CrateNum) -> bool {
1391 // This query depends on untracked global state in CStore
1394 desc { "checking if the crate has_global_allocator" }
1395 separate_provide_extern
1397 query has_panic_handler(_: CrateNum) -> bool {
1399 desc { "checking if the crate has_panic_handler" }
1400 separate_provide_extern
1402 query is_profiler_runtime(_: CrateNum) -> bool {
1404 desc { "checking if a crate is `#![profiler_runtime]`" }
1405 separate_provide_extern
1407 query has_ffi_unwind_calls(key: LocalDefId) -> bool {
1408 desc { |tcx| "checking if `{}` contains FFI-unwind calls", tcx.def_path_str(key.to_def_id()) }
1409 cache_on_disk_if { true }
1411 query required_panic_strategy(_: CrateNum) -> Option<PanicStrategy> {
1413 desc { "getting a crate's required panic strategy" }
1414 separate_provide_extern
1416 query panic_in_drop_strategy(_: CrateNum) -> PanicStrategy {
1418 desc { "getting a crate's configured panic-in-drop strategy" }
1419 separate_provide_extern
1421 query is_no_builtins(_: CrateNum) -> bool {
1423 desc { "getting whether a crate has `#![no_builtins]`" }
1424 separate_provide_extern
1426 query symbol_mangling_version(_: CrateNum) -> SymbolManglingVersion {
1428 desc { "getting a crate's symbol mangling version" }
1429 separate_provide_extern
1432 query extern_crate(def_id: DefId) -> Option<&'tcx ExternCrate> {
1434 desc { "getting crate's ExternCrateData" }
1435 separate_provide_extern
1438 query specializes(_: (DefId, DefId)) -> bool {
1439 desc { "computing whether impls specialize one another" }
1441 query in_scope_traits_map(_: hir::OwnerId)
1442 -> Option<&'tcx FxHashMap<ItemLocalId, Box<[TraitCandidate]>>> {
1443 desc { "getting traits in scope at a block" }
1446 query module_reexports(def_id: LocalDefId) -> Option<&'tcx [ModChild]> {
1447 desc { |tcx| "looking up reexports of module `{}`", tcx.def_path_str(def_id.to_def_id()) }
1450 query impl_defaultness(def_id: DefId) -> hir::Defaultness {
1451 desc { |tcx| "looking up whether `{}` is a default impl", tcx.def_path_str(def_id) }
1452 cache_on_disk_if { def_id.is_local() }
1453 separate_provide_extern
1456 query check_well_formed(key: hir::OwnerId) -> () {
1457 desc { |tcx| "checking that `{}` is well-formed", tcx.def_path_str(key.to_def_id()) }
1460 // The `DefId`s of all non-generic functions and statics in the given crate
1461 // that can be reached from outside the crate.
1463 // We expect this items to be available for being linked to.
1465 // This query can also be called for `LOCAL_CRATE`. In this case it will
1466 // compute which items will be reachable to other crates, taking into account
1467 // the kind of crate that is currently compiled. Crates with only a
1468 // C interface have fewer reachable things.
1470 // Does not include external symbols that don't have a corresponding DefId,
1471 // like the compiler-generated `main` function and so on.
1472 query reachable_non_generics(_: CrateNum)
1473 -> DefIdMap<SymbolExportInfo> {
1475 desc { "looking up the exported symbols of a crate" }
1476 separate_provide_extern
1478 query is_reachable_non_generic(def_id: DefId) -> bool {
1479 desc { |tcx| "checking whether `{}` is an exported symbol", tcx.def_path_str(def_id) }
1480 cache_on_disk_if { def_id.is_local() }
1481 separate_provide_extern
1483 query is_unreachable_local_definition(def_id: LocalDefId) -> bool {
1485 "checking whether `{}` is reachable from outside the crate",
1486 tcx.def_path_str(def_id.to_def_id()),
1490 /// The entire set of monomorphizations the local crate can safely link
1491 /// to because they are exported from upstream crates. Do not depend on
1492 /// this directly, as its value changes anytime a monomorphization gets
1493 /// added or removed in any upstream crate. Instead use the narrower
1494 /// `upstream_monomorphizations_for`, `upstream_drop_glue_for`, or, even
1495 /// better, `Instance::upstream_monomorphization()`.
1496 query upstream_monomorphizations(_: ()) -> DefIdMap<FxHashMap<SubstsRef<'tcx>, CrateNum>> {
1498 desc { "collecting available upstream monomorphizations" }
1501 /// Returns the set of upstream monomorphizations available for the
1502 /// generic function identified by the given `def_id`. The query makes
1503 /// sure to make a stable selection if the same monomorphization is
1504 /// available in multiple upstream crates.
1506 /// You likely want to call `Instance::upstream_monomorphization()`
1507 /// instead of invoking this query directly.
1508 query upstream_monomorphizations_for(def_id: DefId)
1509 -> Option<&'tcx FxHashMap<SubstsRef<'tcx>, CrateNum>>
1513 "collecting available upstream monomorphizations for `{}`",
1514 tcx.def_path_str(def_id),
1516 separate_provide_extern
1519 /// Returns the upstream crate that exports drop-glue for the given
1520 /// type (`substs` is expected to be a single-item list containing the
1521 /// type one wants drop-glue for).
1523 /// This is a subset of `upstream_monomorphizations_for` in order to
1524 /// increase dep-tracking granularity. Otherwise adding or removing any
1525 /// type with drop-glue in any upstream crate would invalidate all
1526 /// functions calling drop-glue of an upstream type.
1528 /// You likely want to call `Instance::upstream_monomorphization()`
1529 /// instead of invoking this query directly.
1531 /// NOTE: This query could easily be extended to also support other
1532 /// common functions that have are large set of monomorphizations
1533 /// (like `Clone::clone` for example).
1534 query upstream_drop_glue_for(substs: SubstsRef<'tcx>) -> Option<CrateNum> {
1535 desc { "available upstream drop-glue for `{:?}`", substs }
1538 query foreign_modules(_: CrateNum) -> FxHashMap<DefId, ForeignModule> {
1540 desc { "looking up the foreign modules of a linked crate" }
1541 separate_provide_extern
1544 /// Identifies the entry-point (e.g., the `main` function) for a given
1545 /// crate, returning `None` if there is no entry point (such as for library crates).
1546 query entry_fn(_: ()) -> Option<(DefId, EntryFnType)> {
1547 desc { "looking up the entry function of a crate" }
1549 query proc_macro_decls_static(_: ()) -> Option<LocalDefId> {
1550 desc { "looking up the derive registrar for a crate" }
1552 // The macro which defines `rustc_metadata::provide_extern` depends on this query's name.
1553 // Changing the name should cause a compiler error, but in case that changes, be aware.
1554 query crate_hash(_: CrateNum) -> Svh {
1556 desc { "looking up the hash a crate" }
1557 separate_provide_extern
1559 query crate_host_hash(_: CrateNum) -> Option<Svh> {
1561 desc { "looking up the hash of a host version of a crate" }
1562 separate_provide_extern
1564 query extra_filename(_: CrateNum) -> String {
1567 desc { "looking up the extra filename for a crate" }
1568 separate_provide_extern
1570 query crate_extern_paths(_: CrateNum) -> Vec<PathBuf> {
1573 desc { "looking up the paths for extern crates" }
1574 separate_provide_extern
1577 /// Given a crate and a trait, look up all impls of that trait in the crate.
1578 /// Return `(impl_id, self_ty)`.
1579 query implementations_of_trait(_: (CrateNum, DefId)) -> &'tcx [(DefId, Option<SimplifiedType>)] {
1580 desc { "looking up implementations of a trait in a crate" }
1581 separate_provide_extern
1584 /// Collects all incoherent impls for the given crate and type.
1586 /// Do not call this directly, but instead use the `incoherent_impls` query.
1587 /// This query is only used to get the data necessary for that query.
1588 query crate_incoherent_impls(key: (CrateNum, SimplifiedType)) -> &'tcx [DefId] {
1589 desc { |tcx| "collecting all impls for a type in a crate" }
1590 separate_provide_extern
1593 query native_library(def_id: DefId) -> Option<&'tcx NativeLib> {
1594 desc { |tcx| "getting the native library for `{}`", tcx.def_path_str(def_id) }
1597 /// Does lifetime resolution, but does not descend into trait items. This
1598 /// should only be used for resolving lifetimes of on trait definitions,
1599 /// and is used to avoid cycles. Importantly, `resolve_lifetimes` still visits
1600 /// the same lifetimes and is responsible for diagnostics.
1601 /// See `rustc_resolve::late::lifetimes for details.
1602 query resolve_lifetimes_trait_definition(_: LocalDefId) -> ResolveLifetimes {
1604 desc { "resolving lifetimes for a trait definition" }
1606 /// Does lifetime resolution on items. Importantly, we can't resolve
1607 /// lifetimes directly on things like trait methods, because of trait params.
1608 /// See `rustc_resolve::late::lifetimes for details.
1609 query resolve_lifetimes(_: LocalDefId) -> ResolveLifetimes {
1611 desc { "resolving lifetimes" }
1613 query named_region_map(_: hir::OwnerId) ->
1614 Option<&'tcx FxHashMap<ItemLocalId, Region>> {
1615 desc { "looking up a named region" }
1617 query is_late_bound_map(_: LocalDefId) -> Option<&'tcx FxIndexSet<LocalDefId>> {
1618 desc { "testing if a region is late bound" }
1620 /// For a given item's generic parameter, gets the default lifetimes to be used
1621 /// for each parameter if a trait object were to be passed for that parameter.
1622 /// For example, for `T` in `struct Foo<'a, T>`, this would be `'static`.
1623 /// For `T` in `struct Foo<'a, T: 'a>`, this would instead be `'a`.
1624 /// This query will panic if passed something that is not a type parameter.
1625 query object_lifetime_default(key: DefId) -> ObjectLifetimeDefault {
1626 desc { "looking up lifetime defaults for generic parameter `{}`", tcx.def_path_str(key) }
1627 separate_provide_extern
1629 query late_bound_vars_map(_: hir::OwnerId)
1630 -> Option<&'tcx FxHashMap<ItemLocalId, Vec<ty::BoundVariableKind>>> {
1631 desc { "looking up late bound vars" }
1634 /// Computes the visibility of the provided `def_id`.
1636 /// If the item from the `def_id` doesn't have a visibility, it will panic. For example
1637 /// a generic type parameter will panic if you call this method on it:
1640 /// pub trait Foo<T: Debug> {}
1643 /// In here, if you call `visibility` on `T`, it'll panic.
1644 query visibility(def_id: DefId) -> ty::Visibility<DefId> {
1645 desc { |tcx| "computing visibility of `{}`", tcx.def_path_str(def_id) }
1646 separate_provide_extern
1649 query inhabited_predicate_adt(key: DefId) -> ty::inhabitedness::InhabitedPredicate<'tcx> {
1650 desc { "computing the uninhabited predicate of `{:?}`", key }
1653 /// Do not call this query directly: invoke `Ty::inhabited_predicate` instead.
1654 query inhabited_predicate_type(key: Ty<'tcx>) -> ty::inhabitedness::InhabitedPredicate<'tcx> {
1655 desc { "computing the uninhabited predicate of `{}`", key }
1658 query dep_kind(_: CrateNum) -> CrateDepKind {
1660 desc { "fetching what a dependency looks like" }
1661 separate_provide_extern
1664 /// Gets the name of the crate.
1665 query crate_name(_: CrateNum) -> Symbol {
1667 desc { "fetching what a crate is named" }
1668 separate_provide_extern
1670 query module_children(def_id: DefId) -> &'tcx [ModChild] {
1671 desc { |tcx| "collecting child items of module `{}`", tcx.def_path_str(def_id) }
1672 separate_provide_extern
1674 query extern_mod_stmt_cnum(def_id: LocalDefId) -> Option<CrateNum> {
1675 desc { |tcx| "computing crate imported by `{}`", tcx.def_path_str(def_id.to_def_id()) }
1678 query lib_features(_: ()) -> LibFeatures {
1680 desc { "calculating the lib features map" }
1682 query defined_lib_features(_: CrateNum) -> &'tcx [(Symbol, Option<Symbol>)] {
1683 desc { "calculating the lib features defined in a crate" }
1684 separate_provide_extern
1686 query stability_implications(_: CrateNum) -> FxHashMap<Symbol, Symbol> {
1688 desc { "calculating the implications between `#[unstable]` features defined in a crate" }
1689 separate_provide_extern
1691 /// Whether the function is an intrinsic
1692 query is_intrinsic(def_id: DefId) -> bool {
1693 desc { |tcx| "checking whether `{}` is an intrinsic", tcx.def_path_str(def_id) }
1694 separate_provide_extern
1696 /// Returns the lang items defined in another crate by loading it from metadata.
1697 query get_lang_items(_: ()) -> LanguageItems {
1700 desc { "calculating the lang items map" }
1703 /// Returns all diagnostic items defined in all crates.
1704 query all_diagnostic_items(_: ()) -> rustc_hir::diagnostic_items::DiagnosticItems {
1707 desc { "calculating the diagnostic items map" }
1710 /// Returns the lang items defined in another crate by loading it from metadata.
1711 query defined_lang_items(_: CrateNum) -> &'tcx [(DefId, LangItem)] {
1712 desc { "calculating the lang items defined in a crate" }
1713 separate_provide_extern
1716 /// Returns the diagnostic items defined in a crate.
1717 query diagnostic_items(_: CrateNum) -> rustc_hir::diagnostic_items::DiagnosticItems {
1719 desc { "calculating the diagnostic items map in a crate" }
1720 separate_provide_extern
1723 query missing_lang_items(_: CrateNum) -> &'tcx [LangItem] {
1724 desc { "calculating the missing lang items in a crate" }
1725 separate_provide_extern
1727 query visible_parent_map(_: ()) -> DefIdMap<DefId> {
1729 desc { "calculating the visible parent map" }
1731 query trimmed_def_paths(_: ()) -> FxHashMap<DefId, Symbol> {
1733 desc { "calculating trimmed def paths" }
1735 query missing_extern_crate_item(_: CrateNum) -> bool {
1737 desc { "seeing if we're missing an `extern crate` item for this crate" }
1738 separate_provide_extern
1740 query used_crate_source(_: CrateNum) -> Lrc<CrateSource> {
1743 desc { "looking at the source for a crate" }
1744 separate_provide_extern
1746 /// Returns the debugger visualizers defined for this crate.
1747 query debugger_visualizers(_: CrateNum) -> Vec<rustc_span::DebuggerVisualizerFile> {
1749 desc { "looking up the debugger visualizers for this crate" }
1750 separate_provide_extern
1752 query postorder_cnums(_: ()) -> &'tcx [CrateNum] {
1754 desc { "generating a postorder list of CrateNums" }
1756 /// Returns whether or not the crate with CrateNum 'cnum'
1757 /// is marked as a private dependency
1758 query is_private_dep(c: CrateNum) -> bool {
1760 desc { "checking whether crate `{}` is a private dependency", c }
1761 separate_provide_extern
1763 query allocator_kind(_: ()) -> Option<AllocatorKind> {
1765 desc { "getting the allocator kind for the current crate" }
1768 query upvars_mentioned(def_id: DefId) -> Option<&'tcx FxIndexMap<hir::HirId, hir::Upvar>> {
1769 desc { |tcx| "collecting upvars mentioned in `{}`", tcx.def_path_str(def_id) }
1771 query maybe_unused_trait_imports(_: ()) -> &'tcx FxIndexSet<LocalDefId> {
1772 desc { "fetching potentially unused trait imports" }
1774 query maybe_unused_extern_crates(_: ()) -> &'tcx [(LocalDefId, Span)] {
1775 desc { "looking up all possibly unused extern crates" }
1777 query names_imported_by_glob_use(def_id: LocalDefId) -> &'tcx FxHashSet<Symbol> {
1778 desc { |tcx| "finding names imported by glob use for `{}`", tcx.def_path_str(def_id.to_def_id()) }
1781 query stability_index(_: ()) -> stability::Index {
1784 desc { "calculating the stability index for the local crate" }
1786 query crates(_: ()) -> &'tcx [CrateNum] {
1788 desc { "fetching all foreign CrateNum instances" }
1791 /// A list of all traits in a crate, used by rustdoc and error reporting.
1792 /// NOTE: Not named just `traits` due to a naming conflict.
1793 query traits_in_crate(_: CrateNum) -> &'tcx [DefId] {
1794 desc { "fetching all traits in a crate" }
1795 separate_provide_extern
1798 /// The list of symbols exported from the given crate.
1800 /// - All names contained in `exported_symbols(cnum)` are guaranteed to
1801 /// correspond to a publicly visible symbol in `cnum` machine code.
1802 /// - The `exported_symbols` sets of different crates do not intersect.
1803 query exported_symbols(cnum: CrateNum) -> &'tcx [(ExportedSymbol<'tcx>, SymbolExportInfo)] {
1804 desc { "collecting exported symbols for crate `{}`", cnum}
1805 cache_on_disk_if { *cnum == LOCAL_CRATE }
1806 separate_provide_extern
1809 query collect_and_partition_mono_items(_: ()) -> (&'tcx DefIdSet, &'tcx [CodegenUnit<'tcx>]) {
1811 desc { "collect_and_partition_mono_items" }
1814 query is_codegened_item(def_id: DefId) -> bool {
1815 desc { |tcx| "determining whether `{}` needs codegen", tcx.def_path_str(def_id) }
1818 /// All items participating in code generation together with items inlined into them.
1819 query codegened_and_inlined_items(_: ()) -> &'tcx DefIdSet {
1821 desc { "collecting codegened and inlined items" }
1824 query codegen_unit(sym: Symbol) -> &'tcx CodegenUnit<'tcx> {
1825 desc { "getting codegen unit `{sym}`" }
1828 query unused_generic_params(key: ty::InstanceDef<'tcx>) -> FiniteBitSet<u32> {
1829 cache_on_disk_if { key.def_id().is_local() }
1831 |tcx| "determining which generic parameters are unused by `{}`",
1832 tcx.def_path_str(key.def_id())
1834 separate_provide_extern
1837 query backend_optimization_level(_: ()) -> OptLevel {
1838 desc { "optimization level used by backend" }
1841 /// Return the filenames where output artefacts shall be stored.
1843 /// This query returns an `&Arc` because codegen backends need the value even after the `TyCtxt`
1844 /// has been destroyed.
1845 query output_filenames(_: ()) -> &'tcx Arc<OutputFilenames> {
1847 desc { "getting output filenames" }
1850 /// Do not call this query directly: invoke `normalize` instead.
1851 query normalize_projection_ty(
1852 goal: CanonicalProjectionGoal<'tcx>
1854 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, NormalizationResult<'tcx>>>,
1857 desc { "normalizing `{}`", goal.value.value }
1861 /// Do not call this query directly: invoke `try_normalize_erasing_regions` instead.
1862 query try_normalize_generic_arg_after_erasing_regions(
1863 goal: ParamEnvAnd<'tcx, GenericArg<'tcx>>
1864 ) -> Result<GenericArg<'tcx>, NoSolution> {
1865 desc { "normalizing `{}`", goal.value }
1869 query implied_outlives_bounds(
1870 goal: CanonicalTyGoal<'tcx>
1872 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, Vec<OutlivesBound<'tcx>>>>,
1875 desc { "computing implied outlives bounds for `{}`", goal.value.value }
1879 /// Do not call this query directly:
1880 /// invoke `DropckOutlives::new(dropped_ty)).fully_perform(typeck.infcx)` instead.
1881 query dropck_outlives(
1882 goal: CanonicalTyGoal<'tcx>
1884 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, DropckOutlivesResult<'tcx>>>,
1887 desc { "computing dropck types for `{}`", goal.value.value }
1891 /// Do not call this query directly: invoke `infcx.predicate_may_hold()` or
1892 /// `infcx.predicate_must_hold()` instead.
1893 query evaluate_obligation(
1894 goal: CanonicalPredicateGoal<'tcx>
1895 ) -> Result<traits::EvaluationResult, traits::OverflowError> {
1896 desc { "evaluating trait selection obligation `{}`", goal.value.value }
1899 query evaluate_goal(
1900 goal: traits::CanonicalChalkEnvironmentAndGoal<'tcx>
1902 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1905 desc { "evaluating trait selection obligation `{}`", goal.value }
1908 /// Do not call this query directly: part of the `Eq` type-op
1909 query type_op_ascribe_user_type(
1910 goal: CanonicalTypeOpAscribeUserTypeGoal<'tcx>
1912 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1915 desc { "evaluating `type_op_ascribe_user_type` `{:?}`", goal.value.value }
1919 /// Do not call this query directly: part of the `Eq` type-op
1921 goal: CanonicalTypeOpEqGoal<'tcx>
1923 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1926 desc { "evaluating `type_op_eq` `{:?}`", goal.value.value }
1930 /// Do not call this query directly: part of the `Subtype` type-op
1931 query type_op_subtype(
1932 goal: CanonicalTypeOpSubtypeGoal<'tcx>
1934 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1937 desc { "evaluating `type_op_subtype` `{:?}`", goal.value.value }
1941 /// Do not call this query directly: part of the `ProvePredicate` type-op
1942 query type_op_prove_predicate(
1943 goal: CanonicalTypeOpProvePredicateGoal<'tcx>
1945 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1948 desc { "evaluating `type_op_prove_predicate` `{:?}`", goal.value.value }
1951 /// Do not call this query directly: part of the `Normalize` type-op
1952 query type_op_normalize_ty(
1953 goal: CanonicalTypeOpNormalizeGoal<'tcx, Ty<'tcx>>
1955 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, Ty<'tcx>>>,
1958 desc { "normalizing `{}`", goal.value.value.value }
1962 /// Do not call this query directly: part of the `Normalize` type-op
1963 query type_op_normalize_predicate(
1964 goal: CanonicalTypeOpNormalizeGoal<'tcx, ty::Predicate<'tcx>>
1966 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ty::Predicate<'tcx>>>,
1969 desc { "normalizing `{:?}`", goal.value.value.value }
1973 /// Do not call this query directly: part of the `Normalize` type-op
1974 query type_op_normalize_poly_fn_sig(
1975 goal: CanonicalTypeOpNormalizeGoal<'tcx, ty::PolyFnSig<'tcx>>
1977 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ty::PolyFnSig<'tcx>>>,
1980 desc { "normalizing `{:?}`", goal.value.value.value }
1984 /// Do not call this query directly: part of the `Normalize` type-op
1985 query type_op_normalize_fn_sig(
1986 goal: CanonicalTypeOpNormalizeGoal<'tcx, ty::FnSig<'tcx>>
1988 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ty::FnSig<'tcx>>>,
1991 desc { "normalizing `{:?}`", goal.value.value.value }
1995 query subst_and_check_impossible_predicates(key: (DefId, SubstsRef<'tcx>)) -> bool {
1997 "checking impossible substituted predicates: `{}`",
1998 tcx.def_path_str(key.0)
2002 query is_impossible_method(key: (DefId, DefId)) -> bool {
2004 "checking if `{}` is impossible to call within `{}`",
2005 tcx.def_path_str(key.1),
2006 tcx.def_path_str(key.0),
2010 query method_autoderef_steps(
2011 goal: CanonicalTyGoal<'tcx>
2012 ) -> MethodAutoderefStepsResult<'tcx> {
2013 desc { "computing autoderef types for `{}`", goal.value.value }
2017 query supported_target_features(_: CrateNum) -> FxHashMap<String, Option<Symbol>> {
2020 desc { "looking up supported target features" }
2023 /// Get an estimate of the size of an InstanceDef based on its MIR for CGU partitioning.
2024 query instance_def_size_estimate(def: ty::InstanceDef<'tcx>)
2026 desc { |tcx| "estimating size for `{}`", tcx.def_path_str(def.def_id()) }
2029 query features_query(_: ()) -> &'tcx rustc_feature::Features {
2031 desc { "looking up enabled feature gates" }
2034 /// Attempt to resolve the given `DefId` to an `Instance`, for the
2035 /// given generics args (`SubstsRef`), returning one of:
2036 /// * `Ok(Some(instance))` on success
2037 /// * `Ok(None)` when the `SubstsRef` are still too generic,
2038 /// and therefore don't allow finding the final `Instance`
2039 /// * `Err(ErrorGuaranteed)` when the `Instance` resolution process
2040 /// couldn't complete due to errors elsewhere - this is distinct
2041 /// from `Ok(None)` to avoid misleading diagnostics when an error
2042 /// has already been/will be emitted, for the original cause
2043 query resolve_instance(
2044 key: ty::ParamEnvAnd<'tcx, (DefId, SubstsRef<'tcx>)>
2045 ) -> Result<Option<ty::Instance<'tcx>>, ErrorGuaranteed> {
2046 desc { "resolving instance `{}`", ty::Instance::new(key.value.0, key.value.1) }
2050 query resolve_instance_of_const_arg(
2051 key: ty::ParamEnvAnd<'tcx, (LocalDefId, DefId, SubstsRef<'tcx>)>
2052 ) -> Result<Option<ty::Instance<'tcx>>, ErrorGuaranteed> {
2054 "resolving instance of the const argument `{}`",
2055 ty::Instance::new(key.value.0.to_def_id(), key.value.2),
2060 query normalize_opaque_types(key: &'tcx ty::List<ty::Predicate<'tcx>>) -> &'tcx ty::List<ty::Predicate<'tcx>> {
2061 desc { "normalizing opaque types in `{:?}`", key }
2064 /// Checks whether a type is definitely uninhabited. This is
2065 /// conservative: for some types that are uninhabited we return `false`,
2066 /// but we only return `true` for types that are definitely uninhabited.
2067 /// `ty.conservative_is_privately_uninhabited` implies that any value of type `ty`
2068 /// will be `Abi::Uninhabited`. (Note that uninhabited types may have nonzero
2069 /// size, to account for partial initialisation. See #49298 for details.)
2070 query conservative_is_privately_uninhabited(key: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
2071 desc { "conservatively checking if `{}` is privately uninhabited", key.value }
2075 query limits(key: ()) -> Limits {
2076 desc { "looking up limits" }
2079 /// Performs an HIR-based well-formed check on the item with the given `HirId`. If
2080 /// we get an `Unimplemented` error that matches the provided `Predicate`, return
2081 /// the cause of the newly created obligation.
2083 /// This is only used by error-reporting code to get a better cause (in particular, a better
2084 /// span) for an *existing* error. Therefore, it is best-effort, and may never handle
2085 /// all of the cases that the normal `ty::Ty`-based wfcheck does. This is fine,
2086 /// because the `ty::Ty`-based wfcheck is always run.
2087 query diagnostic_hir_wf_check(key: (ty::Predicate<'tcx>, traits::WellFormedLoc)) -> Option<traits::ObligationCause<'tcx>> {
2091 desc { "performing HIR wf-checking for predicate `{:?}` at item `{:?}`", key.0, key.1 }
2095 /// The list of backend features computed from CLI flags (`-Ctarget-cpu`, `-Ctarget-feature`,
2096 /// `--target` and similar).
2097 query global_backend_features(_: ()) -> Vec<String> {
2100 desc { "computing the backend features for CLI flags" }
2103 query generator_diagnostic_data(key: DefId) -> Option<GeneratorDiagnosticData<'tcx>> {
2105 desc { |tcx| "looking up generator diagnostic data of `{}`", tcx.def_path_str(key) }
2106 separate_provide_extern
2109 query permits_uninit_init(key: TyAndLayout<'tcx>) -> bool {
2110 desc { "checking to see if `{}` permits being left uninit", key.ty }
2113 query permits_zero_init(key: TyAndLayout<'tcx>) -> bool {
2114 desc { "checking to see if `{}` permits being left zeroed", key.ty }
2117 query compare_assoc_const_impl_item_with_trait_item(
2118 key: (LocalDefId, DefId)
2119 ) -> Result<(), ErrorGuaranteed> {
2120 desc { |tcx| "checking assoc const `{}` has the same type as trait item", tcx.def_path_str(key.0.to_def_id()) }
2123 query deduced_param_attrs(def_id: DefId) -> &'tcx [ty::DeducedParamAttrs] {
2124 desc { |tcx| "deducing parameter attributes for {}", tcx.def_path_str(def_id) }
2125 separate_provide_extern