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 // Each of these queries corresponds to a function pointer field in the
8 // `Providers` struct for requesting a value of that type, and a method
9 // on `tcx: TyCtxt` (and `tcx.at(span)`) for doing that request in a way
10 // which memoizes and does dep-graph tracking, wrapping around the actual
11 // `Providers` that the driver creates (using several `rustc_*` crates).
13 // The result type of each query must implement `Clone`, and additionally
14 // `ty::query::values::Value`, which produces an appropriate placeholder
15 // (error) value if the query resulted in a query cycle.
16 // Queries marked with `fatal_cycle` do not need the latter implementation,
17 // as they will raise an fatal error on query cycles instead.
19 query trigger_delay_span_bug(key: DefId) -> () {
20 desc { "trigger a delay span bug" }
23 query resolutions(_: ()) -> &'tcx ty::ResolverOutputs {
26 desc { "get the resolver outputs" }
29 query resolver_for_lowering(_: ()) -> &'tcx Steal<ty::ResolverAstLowering> {
32 desc { "get the resolver for lowering" }
35 /// Return the span for a definition.
36 /// Contrary to `def_span` below, this query returns the full absolute span of the definition.
37 /// This span is meant for dep-tracking rather than diagnostics. It should not be used outside
38 /// of rustc_middle::hir::source_map.
39 query source_span(key: LocalDefId) -> Span {
40 desc { "get the source span" }
43 /// Represents crate as a whole (as distinct from the top-level crate module).
44 /// If you call `hir_crate` (e.g., indirectly by calling `tcx.hir().krate()`),
45 /// we will have to assume that any change means that you need to be recompiled.
46 /// This is because the `hir_crate` query gives you access to all other items.
47 /// To avoid this fate, do not call `tcx.hir().krate()`; instead,
48 /// prefer wrappers like `tcx.visit_all_items_in_krate()`.
49 query hir_crate(key: ()) -> Crate<'tcx> {
50 storage(ArenaCacheSelector<'tcx>)
52 desc { "get the crate HIR" }
55 /// All items in the crate.
56 query hir_crate_items(_: ()) -> rustc_middle::hir::ModuleItems {
57 storage(ArenaCacheSelector<'tcx>)
59 desc { "get HIR crate items" }
62 /// The items in a module.
64 /// This can be conveniently accessed by `tcx.hir().visit_item_likes_in_module`.
65 /// Avoid calling this query directly.
66 query hir_module_items(key: LocalDefId) -> rustc_middle::hir::ModuleItems {
67 storage(ArenaCacheSelector<'tcx>)
68 desc { |tcx| "HIR module items in `{}`", tcx.def_path_str(key.to_def_id()) }
69 cache_on_disk_if { true }
72 /// Gives access to the HIR node for the HIR owner `key`.
74 /// This can be conveniently accessed by methods on `tcx.hir()`.
75 /// Avoid calling this query directly.
76 query hir_owner(key: LocalDefId) -> Option<crate::hir::Owner<'tcx>> {
77 desc { |tcx| "HIR owner of `{}`", tcx.def_path_str(key.to_def_id()) }
80 /// Gives access to the HIR ID for the given `LocalDefId` owner `key`.
82 /// This can be conveniently accessed by methods on `tcx.hir()`.
83 /// Avoid calling this query directly.
84 query local_def_id_to_hir_id(key: LocalDefId) -> hir::HirId {
85 desc { |tcx| "HIR ID of `{}`", tcx.def_path_str(key.to_def_id()) }
88 /// Gives access to the HIR node's parent for the HIR owner `key`.
90 /// This can be conveniently accessed by methods on `tcx.hir()`.
91 /// Avoid calling this query directly.
92 query hir_owner_parent(key: LocalDefId) -> hir::HirId {
93 desc { |tcx| "HIR parent of `{}`", tcx.def_path_str(key.to_def_id()) }
96 /// Gives access to the HIR nodes and bodies inside 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_nodes(key: LocalDefId) -> hir::MaybeOwner<&'tcx hir::OwnerNodes<'tcx>> {
101 desc { |tcx| "HIR owner items in `{}`", tcx.def_path_str(key.to_def_id()) }
104 /// Gives access to the HIR attributes 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_attrs(key: LocalDefId) -> &'tcx hir::AttributeMap<'tcx> {
109 desc { |tcx| "HIR owner attributes in `{}`", tcx.def_path_str(key.to_def_id()) }
112 /// Computes the `DefId` of the corresponding const parameter in case the `key` is a
113 /// const argument and returns `None` otherwise.
115 /// ```ignore (incomplete)
116 /// let a = foo::<7>();
117 /// // ^ Calling `opt_const_param_of` for this argument,
119 /// fn foo<const N: usize>()
120 /// // ^ returns this `DefId`.
123 /// // ^ While calling `opt_const_param_of` for other bodies returns `None`.
126 // It looks like caching this query on disk actually slightly
127 // worsened performance in #74376.
129 // Once const generics are more prevalently used, we might want to
130 // consider only caching calls returning `Some`.
131 query opt_const_param_of(key: LocalDefId) -> Option<DefId> {
132 desc { |tcx| "computing the optional const parameter of `{}`", tcx.def_path_str(key.to_def_id()) }
135 /// Given the def_id of a const-generic parameter, computes the associated default const
136 /// parameter. e.g. `fn example<const N: usize=3>` called on `N` would return `3`.
137 query const_param_default(param: DefId) -> ty::Const<'tcx> {
138 desc { |tcx| "compute const default for a given parameter `{}`", tcx.def_path_str(param) }
139 cache_on_disk_if { param.is_local() }
140 separate_provide_extern
143 /// Returns the [`Ty`][rustc_middle::ty::Ty] of the given [`DefId`]. If the [`DefId`] points
144 /// to an alias, it will "skip" this alias to return the aliased type.
146 /// [`DefId`]: rustc_hir::def_id::DefId
147 query type_of(key: DefId) -> Ty<'tcx> {
151 use rustc_hir::def::DefKind;
152 match tcx.def_kind(key) {
153 DefKind::TyAlias => "expanding type alias",
154 DefKind::TraitAlias => "expanding trait alias",
155 _ => "computing type of",
158 path = tcx.def_path_str(key),
160 cache_on_disk_if { key.is_local() }
161 separate_provide_extern
164 query compare_predicates_and_trait_impl_trait_tys(key: DefId)
165 -> Result<&'tcx FxHashMap<DefId, Ty<'tcx>>, ErrorGuaranteed>
167 desc { "better description please" }
168 separate_provide_extern
171 query analysis(key: ()) -> Result<(), ErrorGuaranteed> {
173 desc { "running analysis passes on this crate" }
176 /// This query checks the fulfillment of collected lint expectations.
177 /// All lint emitting queries have to be done before this is executed
178 /// to ensure that all expectations can be fulfilled.
180 /// This is an extra query to enable other drivers (like rustdoc) to
181 /// only execute a small subset of the `analysis` query, while allowing
182 /// lints to be expected. In rustc, this query will be executed as part of
183 /// the `analysis` query and doesn't have to be called a second time.
185 /// Tools can additionally pass in a tool filter. That will restrict the
186 /// expectations to only trigger for lints starting with the listed tool
187 /// name. This is useful for cases were not all linting code from rustc
188 /// was called. With the default `None` all registered lints will also
189 /// be checked for expectation fulfillment.
190 query check_expectations(key: Option<Symbol>) -> () {
192 desc { "checking lint expectations (RFC 2383)" }
195 /// Maps from the `DefId` of an item (trait/struct/enum/fn) to its
196 /// associated generics.
197 query generics_of(key: DefId) -> ty::Generics {
198 desc { |tcx| "computing generics of `{}`", tcx.def_path_str(key) }
199 storage(ArenaCacheSelector<'tcx>)
200 cache_on_disk_if { key.is_local() }
201 separate_provide_extern
204 /// Maps from the `DefId` of an item (trait/struct/enum/fn) to the
205 /// predicates (where-clauses) that must be proven true in order
206 /// to reference it. This is almost always the "predicates query"
209 /// `predicates_of` builds on `predicates_defined_on` -- in fact,
210 /// it is almost always the same as that query, except for the
211 /// case of traits. For traits, `predicates_of` contains
212 /// an additional `Self: Trait<...>` predicate that users don't
213 /// actually write. This reflects the fact that to invoke the
214 /// trait (e.g., via `Default::default`) you must supply types
215 /// that actually implement the trait. (However, this extra
216 /// predicate gets in the way of some checks, which are intended
217 /// to operate over only the actual where-clauses written by the
219 query predicates_of(key: DefId) -> ty::GenericPredicates<'tcx> {
220 desc { |tcx| "computing predicates of `{}`", tcx.def_path_str(key) }
221 cache_on_disk_if { key.is_local() }
224 /// Returns the list of bounds that can be used for
225 /// `SelectionCandidate::ProjectionCandidate(_)` and
226 /// `ProjectionTyCandidate::TraitDef`.
227 /// Specifically this is the bounds written on the trait's type
228 /// definition, or those after the `impl` keyword
230 /// ```ignore (incomplete)
231 /// type X: Bound + 'lt
233 /// impl Debug + Display
234 /// // ^^^^^^^^^^^^^^^
237 /// `key` is the `DefId` of the associated type or opaque type.
239 /// Bounds from the parent (e.g. with nested impl trait) are not included.
240 query explicit_item_bounds(key: DefId) -> &'tcx [(ty::Predicate<'tcx>, Span)] {
241 desc { |tcx| "finding item bounds for `{}`", tcx.def_path_str(key) }
242 cache_on_disk_if { key.is_local() }
243 separate_provide_extern
246 /// Elaborated version of the predicates from `explicit_item_bounds`.
252 /// type MyAType: Eq + ?Sized;
256 /// `explicit_item_bounds` returns `[<Self as MyTrait>::MyAType: Eq]`,
257 /// and `item_bounds` returns
260 /// <Self as Trait>::MyAType: Eq,
261 /// <Self as Trait>::MyAType: PartialEq<<Self as Trait>::MyAType>
265 /// Bounds from the parent (e.g. with nested impl trait) are not included.
266 query item_bounds(key: DefId) -> &'tcx ty::List<ty::Predicate<'tcx>> {
267 desc { |tcx| "elaborating item bounds for `{}`", tcx.def_path_str(key) }
270 query native_libraries(_: CrateNum) -> Vec<NativeLib> {
271 storage(ArenaCacheSelector<'tcx>)
272 desc { "looking up the native libraries of a linked crate" }
273 separate_provide_extern
276 query lint_levels(_: ()) -> LintLevelMap {
277 storage(ArenaCacheSelector<'tcx>)
279 desc { "computing the lint levels for items in this crate" }
282 query parent_module_from_def_id(key: LocalDefId) -> LocalDefId {
284 desc { |tcx| "parent module of `{}`", tcx.def_path_str(key.to_def_id()) }
287 query expn_that_defined(key: DefId) -> rustc_span::ExpnId {
288 desc { |tcx| "expansion that defined `{}`", tcx.def_path_str(key) }
289 separate_provide_extern
292 query is_panic_runtime(_: CrateNum) -> bool {
294 desc { "checking if the crate is_panic_runtime" }
295 separate_provide_extern
298 /// Fetch the THIR for a given body. If typeck for that body failed, returns an empty `Thir`.
299 query thir_body(key: ty::WithOptConstParam<LocalDefId>)
300 -> Result<(&'tcx Steal<thir::Thir<'tcx>>, thir::ExprId), ErrorGuaranteed>
302 // Perf tests revealed that hashing THIR is inefficient (see #85729).
304 desc { |tcx| "building THIR for `{}`", tcx.def_path_str(key.did.to_def_id()) }
307 /// Create a THIR tree for debugging.
308 query thir_tree(key: ty::WithOptConstParam<LocalDefId>) -> String {
310 storage(ArenaCacheSelector<'tcx>)
311 desc { |tcx| "constructing THIR tree for `{}`", tcx.def_path_str(key.did.to_def_id()) }
314 /// Set of all the `DefId`s in this crate that have MIR associated with
315 /// them. This includes all the body owners, but also things like struct
317 query mir_keys(_: ()) -> rustc_data_structures::fx::FxIndexSet<LocalDefId> {
318 storage(ArenaCacheSelector<'tcx>)
319 desc { "getting a list of all mir_keys" }
322 /// Maps DefId's that have an associated `mir::Body` to the result
323 /// of the MIR const-checking pass. This is the set of qualifs in
324 /// the final value of a `const`.
325 query mir_const_qualif(key: DefId) -> mir::ConstQualifs {
326 desc { |tcx| "const checking `{}`", tcx.def_path_str(key) }
327 cache_on_disk_if { key.is_local() }
328 separate_provide_extern
330 query mir_const_qualif_const_arg(
331 key: (LocalDefId, DefId)
332 ) -> mir::ConstQualifs {
334 |tcx| "const checking the const argument `{}`",
335 tcx.def_path_str(key.0.to_def_id())
339 /// Fetch the MIR for a given `DefId` right after it's built - this includes
340 /// unreachable code.
341 query mir_built(key: ty::WithOptConstParam<LocalDefId>) -> &'tcx Steal<mir::Body<'tcx>> {
342 desc { |tcx| "building MIR for `{}`", tcx.def_path_str(key.did.to_def_id()) }
345 /// Fetch the MIR for a given `DefId` up till the point where it is
346 /// ready for const qualification.
348 /// See the README for the `mir` module for details.
349 query mir_const(key: ty::WithOptConstParam<LocalDefId>) -> &'tcx Steal<mir::Body<'tcx>> {
351 |tcx| "processing MIR for {}`{}`",
352 if key.const_param_did.is_some() { "the const argument " } else { "" },
353 tcx.def_path_str(key.did.to_def_id()),
358 /// Try to build an abstract representation of the given constant.
359 query thir_abstract_const(
361 ) -> Result<Option<&'tcx [ty::abstract_const::Node<'tcx>]>, ErrorGuaranteed> {
363 |tcx| "building an abstract representation for {}", tcx.def_path_str(key),
365 separate_provide_extern
367 /// Try to build an abstract representation of the given constant.
368 query thir_abstract_const_of_const_arg(
369 key: (LocalDefId, DefId)
370 ) -> Result<Option<&'tcx [ty::abstract_const::Node<'tcx>]>, ErrorGuaranteed> {
373 "building an abstract representation for the const argument {}",
374 tcx.def_path_str(key.0.to_def_id()),
378 query try_unify_abstract_consts(key:
379 ty::ParamEnvAnd<'tcx, (ty::Unevaluated<'tcx, ()>, ty::Unevaluated<'tcx, ()>
382 |tcx| "trying to unify the generic constants {} and {}",
383 tcx.def_path_str(key.value.0.def.did), tcx.def_path_str(key.value.1.def.did)
387 query mir_drops_elaborated_and_const_checked(
388 key: ty::WithOptConstParam<LocalDefId>
389 ) -> &'tcx Steal<mir::Body<'tcx>> {
391 desc { |tcx| "elaborating drops for `{}`", tcx.def_path_str(key.did.to_def_id()) }
396 ) -> &'tcx mir::Body<'tcx> {
397 desc { |tcx| "caching mir of `{}` for CTFE", tcx.def_path_str(key) }
398 cache_on_disk_if { key.is_local() }
399 separate_provide_extern
402 query mir_for_ctfe_of_const_arg(key: (LocalDefId, DefId)) -> &'tcx mir::Body<'tcx> {
404 |tcx| "MIR for CTFE of the const argument `{}`",
405 tcx.def_path_str(key.0.to_def_id())
409 query mir_promoted(key: ty::WithOptConstParam<LocalDefId>) ->
411 &'tcx Steal<mir::Body<'tcx>>,
412 &'tcx Steal<IndexVec<mir::Promoted, mir::Body<'tcx>>>
416 |tcx| "processing {}`{}`",
417 if key.const_param_did.is_some() { "the const argument " } else { "" },
418 tcx.def_path_str(key.did.to_def_id()),
422 query symbols_for_closure_captures(
423 key: (LocalDefId, LocalDefId)
424 ) -> Vec<rustc_span::Symbol> {
425 storage(ArenaCacheSelector<'tcx>)
427 |tcx| "symbols for captures of closure `{}` in `{}`",
428 tcx.def_path_str(key.1.to_def_id()),
429 tcx.def_path_str(key.0.to_def_id())
433 /// MIR after our optimization passes have run. This is MIR that is ready
434 /// for codegen. This is also the only query that can fetch non-local MIR, at present.
435 query optimized_mir(key: DefId) -> &'tcx mir::Body<'tcx> {
436 desc { |tcx| "optimizing MIR for `{}`", tcx.def_path_str(key) }
437 cache_on_disk_if { key.is_local() }
438 separate_provide_extern
441 /// Returns coverage summary info for a function, after executing the `InstrumentCoverage`
442 /// MIR pass (assuming the -Cinstrument-coverage option is enabled).
443 query coverageinfo(key: ty::InstanceDef<'tcx>) -> mir::CoverageInfo {
444 desc { |tcx| "retrieving coverage info from MIR for `{}`", tcx.def_path_str(key.def_id()) }
445 storage(ArenaCacheSelector<'tcx>)
448 /// Returns the `CodeRegions` for a function that has instrumented coverage, in case the
449 /// function was optimized out before codegen, and before being added to the Coverage Map.
450 query covered_code_regions(key: DefId) -> Vec<&'tcx mir::coverage::CodeRegion> {
452 |tcx| "retrieving the covered `CodeRegion`s, if instrumented, for `{}`",
453 tcx.def_path_str(key)
455 storage(ArenaCacheSelector<'tcx>)
456 cache_on_disk_if { key.is_local() }
459 /// The `DefId` is the `DefId` of the containing MIR body. Promoteds do not have their own
460 /// `DefId`. This function returns all promoteds in the specified body. The body references
461 /// promoteds by the `DefId` and the `mir::Promoted` index. This is necessary, because
462 /// after inlining a body may refer to promoteds from other bodies. In that case you still
463 /// need to use the `DefId` of the original body.
464 query promoted_mir(key: DefId) -> &'tcx IndexVec<mir::Promoted, mir::Body<'tcx>> {
465 desc { |tcx| "optimizing promoted MIR for `{}`", tcx.def_path_str(key) }
466 cache_on_disk_if { key.is_local() }
467 separate_provide_extern
469 query promoted_mir_of_const_arg(
470 key: (LocalDefId, DefId)
471 ) -> &'tcx IndexVec<mir::Promoted, mir::Body<'tcx>> {
473 |tcx| "optimizing promoted MIR for the const argument `{}`",
474 tcx.def_path_str(key.0.to_def_id()),
478 /// Erases regions from `ty` to yield a new type.
479 /// Normally you would just use `tcx.erase_regions(value)`,
480 /// however, which uses this query as a kind of cache.
481 query erase_regions_ty(ty: Ty<'tcx>) -> Ty<'tcx> {
482 // This query is not expected to have input -- as a result, it
483 // is not a good candidates for "replay" because it is essentially a
484 // pure function of its input (and hence the expectation is that
485 // no caller would be green **apart** from just these
486 // queries). Making it anonymous avoids hashing the result, which
487 // may save a bit of time.
489 desc { "erasing regions from `{:?}`", ty }
492 query wasm_import_module_map(_: CrateNum) -> FxHashMap<DefId, String> {
493 storage(ArenaCacheSelector<'tcx>)
494 desc { "wasm import module map" }
497 /// Maps from the `DefId` of an item (trait/struct/enum/fn) to the
498 /// predicates (where-clauses) directly defined on it. This is
499 /// equal to the `explicit_predicates_of` predicates plus the
500 /// `inferred_outlives_of` predicates.
501 query predicates_defined_on(key: DefId) -> ty::GenericPredicates<'tcx> {
502 desc { |tcx| "computing predicates of `{}`", tcx.def_path_str(key) }
505 /// Returns everything that looks like a predicate written explicitly
506 /// by the user on a trait item.
508 /// Traits are unusual, because predicates on associated types are
509 /// converted into bounds on that type for backwards compatibility:
511 /// trait X where Self::U: Copy { type U; }
515 /// trait X { type U: Copy; }
517 /// `explicit_predicates_of` and `explicit_item_bounds` will then take
518 /// the appropriate subsets of the predicates here.
519 query trait_explicit_predicates_and_bounds(key: LocalDefId) -> ty::GenericPredicates<'tcx> {
520 desc { |tcx| "computing explicit predicates of trait `{}`", tcx.def_path_str(key.to_def_id()) }
523 /// Returns the predicates written explicitly by the user.
524 query explicit_predicates_of(key: DefId) -> ty::GenericPredicates<'tcx> {
525 desc { |tcx| "computing explicit predicates of `{}`", tcx.def_path_str(key) }
526 cache_on_disk_if { key.is_local() }
527 separate_provide_extern
530 /// Returns the inferred outlives predicates (e.g., for `struct
531 /// Foo<'a, T> { x: &'a T }`, this would return `T: 'a`).
532 query inferred_outlives_of(key: DefId) -> &'tcx [(ty::Predicate<'tcx>, Span)] {
533 desc { |tcx| "computing inferred outlives predicates of `{}`", tcx.def_path_str(key) }
534 cache_on_disk_if { key.is_local() }
535 separate_provide_extern
538 /// Maps from the `DefId` of a trait to the list of
539 /// super-predicates. This is a subset of the full list of
540 /// predicates. We store these in a separate map because we must
541 /// evaluate them even during type conversion, often before the
542 /// full predicates are available (note that supertraits have
543 /// additional acyclicity requirements).
544 query super_predicates_of(key: DefId) -> ty::GenericPredicates<'tcx> {
545 desc { |tcx| "computing the super predicates of `{}`", tcx.def_path_str(key) }
546 cache_on_disk_if { key.is_local() }
547 separate_provide_extern
550 /// The `Option<Ident>` is the name of an associated type. If it is `None`, then this query
551 /// returns the full set of predicates. If `Some<Ident>`, then the query returns only the
552 /// subset of super-predicates that reference traits that define the given associated type.
553 /// This is used to avoid cycles in resolving types like `T::Item`.
554 query super_predicates_that_define_assoc_type(key: (DefId, Option<rustc_span::symbol::Ident>)) -> ty::GenericPredicates<'tcx> {
555 desc { |tcx| "computing the super traits of `{}`{}",
556 tcx.def_path_str(key.0),
557 if let Some(assoc_name) = key.1 { format!(" with associated type name `{}`", assoc_name) } else { "".to_string() },
561 /// To avoid cycles within the predicates of a single item we compute
562 /// per-type-parameter predicates for resolving `T::AssocTy`.
563 query type_param_predicates(key: (DefId, LocalDefId, rustc_span::symbol::Ident)) -> ty::GenericPredicates<'tcx> {
564 desc { |tcx| "computing the bounds for type parameter `{}`", tcx.hir().ty_param_name(key.1) }
567 query trait_def(key: DefId) -> ty::TraitDef {
568 desc { |tcx| "computing trait definition for `{}`", tcx.def_path_str(key) }
569 storage(ArenaCacheSelector<'tcx>)
570 cache_on_disk_if { key.is_local() }
571 separate_provide_extern
573 query adt_def(key: DefId) -> ty::AdtDef<'tcx> {
574 desc { |tcx| "computing ADT definition for `{}`", tcx.def_path_str(key) }
575 cache_on_disk_if { key.is_local() }
576 separate_provide_extern
578 query adt_destructor(key: DefId) -> Option<ty::Destructor> {
579 desc { |tcx| "computing `Drop` impl for `{}`", tcx.def_path_str(key) }
580 cache_on_disk_if { key.is_local() }
581 separate_provide_extern
584 // The cycle error here should be reported as an error by `check_representable`.
585 // We consider the type as Sized in the meanwhile to avoid
586 // further errors (done in impl Value for AdtSizedConstraint).
587 // Use `cycle_delay_bug` to delay the cycle error here to be emitted later
588 // in case we accidentally otherwise don't emit an error.
589 query adt_sized_constraint(
591 ) -> AdtSizedConstraint<'tcx> {
592 desc { |tcx| "computing `Sized` constraints for `{}`", tcx.def_path_str(key) }
596 query adt_dtorck_constraint(
598 ) -> Result<&'tcx DropckConstraint<'tcx>, NoSolution> {
599 desc { |tcx| "computing drop-check constraints for `{}`", tcx.def_path_str(key) }
602 /// Returns `true` if this is a const fn, use the `is_const_fn` to know whether your crate
603 /// actually sees it as const fn (e.g., the const-fn-ness might be unstable and you might
604 /// not have the feature gate active).
606 /// **Do not call this function manually.** It is only meant to cache the base data for the
607 /// `is_const_fn` function. Consider using `is_const_fn` or `is_const_fn_raw` instead.
608 query constness(key: DefId) -> hir::Constness {
609 desc { |tcx| "checking if item is const: `{}`", tcx.def_path_str(key) }
610 cache_on_disk_if { key.is_local() }
611 separate_provide_extern
614 query asyncness(key: DefId) -> hir::IsAsync {
615 desc { |tcx| "checking if the function is async: `{}`", tcx.def_path_str(key) }
616 cache_on_disk_if { key.is_local() }
617 separate_provide_extern
620 /// Returns `true` if calls to the function may be promoted.
622 /// This is either because the function is e.g., a tuple-struct or tuple-variant
623 /// constructor, or because it has the `#[rustc_promotable]` attribute. The attribute should
624 /// be removed in the future in favour of some form of check which figures out whether the
625 /// function does not inspect the bits of any of its arguments (so is essentially just a
626 /// constructor function).
627 query is_promotable_const_fn(key: DefId) -> bool {
628 desc { |tcx| "checking if item is promotable: `{}`", tcx.def_path_str(key) }
631 /// Returns `true` if this is a foreign item (i.e., linked via `extern { ... }`).
632 query is_foreign_item(key: DefId) -> bool {
633 desc { |tcx| "checking if `{}` is a foreign item", tcx.def_path_str(key) }
634 cache_on_disk_if { key.is_local() }
635 separate_provide_extern
638 /// Returns `Some(generator_kind)` if the node pointed to by `def_id` is a generator.
639 query generator_kind(def_id: DefId) -> Option<hir::GeneratorKind> {
640 desc { |tcx| "looking up generator kind of `{}`", tcx.def_path_str(def_id) }
641 cache_on_disk_if { def_id.is_local() }
642 separate_provide_extern
645 /// Gets a map with the variance of every item; use `item_variance` instead.
646 query crate_variances(_: ()) -> ty::CrateVariancesMap<'tcx> {
647 storage(ArenaCacheSelector<'tcx>)
648 desc { "computing the variances for items in this crate" }
651 /// Maps from the `DefId` of a type or region parameter to its (inferred) variance.
652 query variances_of(def_id: DefId) -> &'tcx [ty::Variance] {
653 desc { |tcx| "computing the variances of `{}`", tcx.def_path_str(def_id) }
654 cache_on_disk_if { def_id.is_local() }
655 separate_provide_extern
658 /// Maps from thee `DefId` of a type to its (inferred) outlives.
659 query inferred_outlives_crate(_: ()) -> ty::CratePredicatesMap<'tcx> {
660 storage(ArenaCacheSelector<'tcx>)
661 desc { "computing the inferred outlives predicates for items in this crate" }
664 /// Maps from an impl/trait `DefId` to a list of the `DefId`s of its items.
665 query associated_item_def_ids(key: DefId) -> &'tcx [DefId] {
666 desc { |tcx| "collecting associated items of `{}`", tcx.def_path_str(key) }
667 cache_on_disk_if { key.is_local() }
668 separate_provide_extern
671 /// Maps from a trait item to the trait item "descriptor".
672 query associated_item(key: DefId) -> ty::AssocItem {
673 desc { |tcx| "computing associated item data for `{}`", tcx.def_path_str(key) }
674 storage(ArenaCacheSelector<'tcx>)
675 cache_on_disk_if { key.is_local() }
676 separate_provide_extern
679 /// Collects the associated items defined on a trait or impl.
680 query associated_items(key: DefId) -> ty::AssocItems<'tcx> {
681 storage(ArenaCacheSelector<'tcx>)
682 desc { |tcx| "collecting associated items of {}", tcx.def_path_str(key) }
685 /// Maps from associated items on a trait to the corresponding associated
686 /// item on the impl specified by `impl_id`.
688 /// For example, with the following code
693 /// trait Trait { // trait_id
694 /// fn f(); // trait_f
695 /// fn g() {} // trait_g
698 /// impl Trait for Type { // impl_id
699 /// fn f() {} // impl_f
700 /// fn g() {} // impl_g
704 /// The map returned for `tcx.impl_item_implementor_ids(impl_id)` would be
705 ///`{ trait_f: impl_f, trait_g: impl_g }`
706 query impl_item_implementor_ids(impl_id: DefId) -> FxHashMap<DefId, DefId> {
707 storage(ArenaCacheSelector<'tcx>)
708 desc { |tcx| "comparing impl items against trait for {}", tcx.def_path_str(impl_id) }
711 /// Given an `impl_id`, return the trait it implements.
712 /// Return `None` if this is an inherent impl.
713 query impl_trait_ref(impl_id: DefId) -> Option<ty::TraitRef<'tcx>> {
714 desc { |tcx| "computing trait implemented by `{}`", tcx.def_path_str(impl_id) }
715 cache_on_disk_if { impl_id.is_local() }
716 separate_provide_extern
718 query impl_polarity(impl_id: DefId) -> ty::ImplPolarity {
719 desc { |tcx| "computing implementation polarity of `{}`", tcx.def_path_str(impl_id) }
720 cache_on_disk_if { impl_id.is_local() }
721 separate_provide_extern
724 query issue33140_self_ty(key: DefId) -> Option<ty::Ty<'tcx>> {
725 desc { |tcx| "computing Self type wrt issue #33140 `{}`", tcx.def_path_str(key) }
728 /// Maps a `DefId` of a type to a list of its inherent impls.
729 /// Contains implementations of methods that are inherent to a type.
730 /// Methods in these implementations don't need to be exported.
731 query inherent_impls(key: DefId) -> &'tcx [DefId] {
732 desc { |tcx| "collecting inherent impls for `{}`", tcx.def_path_str(key) }
733 cache_on_disk_if { key.is_local() }
734 separate_provide_extern
737 query incoherent_impls(key: SimplifiedType) -> &'tcx [DefId] {
738 desc { |tcx| "collecting all inherent impls for `{:?}`", key }
741 /// The result of unsafety-checking this `LocalDefId`.
742 query unsafety_check_result(key: LocalDefId) -> &'tcx mir::UnsafetyCheckResult {
743 desc { |tcx| "unsafety-checking `{}`", tcx.def_path_str(key.to_def_id()) }
744 cache_on_disk_if { true }
746 query unsafety_check_result_for_const_arg(key: (LocalDefId, DefId)) -> &'tcx mir::UnsafetyCheckResult {
748 |tcx| "unsafety-checking the const argument `{}`",
749 tcx.def_path_str(key.0.to_def_id())
753 /// Unsafety-check this `LocalDefId` with THIR unsafeck. This should be
754 /// used with `-Zthir-unsafeck`.
755 query thir_check_unsafety(key: LocalDefId) {
756 desc { |tcx| "unsafety-checking `{}`", tcx.def_path_str(key.to_def_id()) }
757 cache_on_disk_if { true }
759 query thir_check_unsafety_for_const_arg(key: (LocalDefId, DefId)) {
761 |tcx| "unsafety-checking the const argument `{}`",
762 tcx.def_path_str(key.0.to_def_id())
766 /// HACK: when evaluated, this reports an "unsafe derive on repr(packed)" error.
768 /// Unsafety checking is executed for each method separately, but we only want
769 /// to emit this error once per derive. As there are some impls with multiple
770 /// methods, we use a query for deduplication.
771 query unsafe_derive_on_repr_packed(key: LocalDefId) -> () {
772 desc { |tcx| "processing `{}`", tcx.def_path_str(key.to_def_id()) }
775 /// Returns the types assumed to be well formed while "inside" of the given item.
777 /// Note that we've liberated the late bound regions of function signatures, so
778 /// this can not be used to check whether these types are well formed.
779 query assumed_wf_types(key: DefId) -> &'tcx ty::List<Ty<'tcx>> {
780 desc { |tcx| "computing the implied bounds of {}", tcx.def_path_str(key) }
783 /// Computes the signature of the function.
784 query fn_sig(key: DefId) -> ty::PolyFnSig<'tcx> {
785 desc { |tcx| "computing function signature of `{}`", tcx.def_path_str(key) }
786 cache_on_disk_if { key.is_local() }
787 separate_provide_extern
791 /// Performs lint checking for the module.
792 query lint_mod(key: LocalDefId) -> () {
793 desc { |tcx| "linting {}", describe_as_module(key, tcx) }
796 /// Checks the attributes in the module.
797 query check_mod_attrs(key: LocalDefId) -> () {
798 desc { |tcx| "checking attributes in {}", describe_as_module(key, tcx) }
801 /// Checks for uses of unstable APIs in the module.
802 query check_mod_unstable_api_usage(key: LocalDefId) -> () {
803 desc { |tcx| "checking for unstable API usage in {}", describe_as_module(key, tcx) }
806 /// Checks the const bodies in the module for illegal operations (e.g. `if` or `loop`).
807 query check_mod_const_bodies(key: LocalDefId) -> () {
808 desc { |tcx| "checking consts in {}", describe_as_module(key, tcx) }
811 /// Checks the loops in the module.
812 query check_mod_loops(key: LocalDefId) -> () {
813 desc { |tcx| "checking loops in {}", describe_as_module(key, tcx) }
816 query check_mod_naked_functions(key: LocalDefId) -> () {
817 desc { |tcx| "checking naked functions in {}", describe_as_module(key, tcx) }
820 query check_mod_item_types(key: LocalDefId) -> () {
821 desc { |tcx| "checking item types in {}", describe_as_module(key, tcx) }
824 query check_mod_privacy(key: LocalDefId) -> () {
825 desc { |tcx| "checking privacy in {}", describe_as_module(key, tcx) }
828 query check_liveness(key: DefId) {
829 desc { |tcx| "checking liveness of variables in {}", tcx.def_path_str(key) }
832 /// Return the live symbols in the crate for dead code check.
834 /// The second return value maps from ADTs to ignored derived traits (e.g. Debug and Clone) and
835 /// their respective impl (i.e., part of the derive macro)
836 query live_symbols_and_ignored_derived_traits(_: ()) -> (
837 FxHashSet<LocalDefId>,
838 FxHashMap<LocalDefId, Vec<(DefId, DefId)>>
840 storage(ArenaCacheSelector<'tcx>)
841 desc { "find live symbols in crate" }
844 query check_mod_deathness(key: LocalDefId) -> () {
845 desc { |tcx| "checking deathness of variables in {}", describe_as_module(key, tcx) }
848 query check_mod_impl_wf(key: LocalDefId) -> () {
849 desc { |tcx| "checking that impls are well-formed in {}", describe_as_module(key, tcx) }
852 query check_mod_type_wf(key: LocalDefId) -> () {
853 desc { |tcx| "checking that types are well-formed in {}", describe_as_module(key, tcx) }
856 query collect_mod_item_types(key: LocalDefId) -> () {
857 desc { |tcx| "collecting item types in {}", describe_as_module(key, tcx) }
860 /// Caches `CoerceUnsized` kinds for impls on custom types.
861 query coerce_unsized_info(key: DefId) -> ty::adjustment::CoerceUnsizedInfo {
862 desc { |tcx| "computing CoerceUnsized info for `{}`", tcx.def_path_str(key) }
863 cache_on_disk_if { key.is_local() }
864 separate_provide_extern
867 query typeck_item_bodies(_: ()) -> () {
868 desc { "type-checking all item bodies" }
871 query typeck(key: LocalDefId) -> &'tcx ty::TypeckResults<'tcx> {
872 desc { |tcx| "type-checking `{}`", tcx.def_path_str(key.to_def_id()) }
873 cache_on_disk_if { true }
875 query typeck_const_arg(
876 key: (LocalDefId, DefId)
877 ) -> &'tcx ty::TypeckResults<'tcx> {
879 |tcx| "type-checking the const argument `{}`",
880 tcx.def_path_str(key.0.to_def_id()),
883 query diagnostic_only_typeck(key: LocalDefId) -> &'tcx ty::TypeckResults<'tcx> {
884 desc { |tcx| "type-checking `{}`", tcx.def_path_str(key.to_def_id()) }
885 cache_on_disk_if { true }
886 load_cached(tcx, id) {
887 let typeck_results: Option<ty::TypeckResults<'tcx>> = tcx
888 .on_disk_cache().as_ref()
889 .and_then(|c| c.try_load_query_result(*tcx, id));
891 typeck_results.map(|x| &*tcx.arena.alloc(x))
895 query used_trait_imports(key: LocalDefId) -> &'tcx FxHashSet<LocalDefId> {
896 desc { |tcx| "used_trait_imports `{}`", tcx.def_path_str(key.to_def_id()) }
897 cache_on_disk_if { true }
900 query has_typeck_results(def_id: DefId) -> bool {
901 desc { |tcx| "checking whether `{}` has a body", tcx.def_path_str(def_id) }
904 query coherent_trait(def_id: DefId) -> () {
905 desc { |tcx| "coherence checking all impls of trait `{}`", tcx.def_path_str(def_id) }
908 /// Borrow-checks the function body. If this is a closure, returns
909 /// additional requirements that the closure's creator must verify.
910 query mir_borrowck(key: LocalDefId) -> &'tcx mir::BorrowCheckResult<'tcx> {
911 desc { |tcx| "borrow-checking `{}`", tcx.def_path_str(key.to_def_id()) }
912 cache_on_disk_if(tcx) { tcx.is_typeck_child(key.to_def_id()) }
914 query mir_borrowck_const_arg(key: (LocalDefId, DefId)) -> &'tcx mir::BorrowCheckResult<'tcx> {
916 |tcx| "borrow-checking the const argument`{}`",
917 tcx.def_path_str(key.0.to_def_id())
921 /// Gets a complete map from all types to their inherent impls.
922 /// Not meant to be used directly outside of coherence.
923 query crate_inherent_impls(k: ()) -> CrateInherentImpls {
924 storage(ArenaCacheSelector<'tcx>)
925 desc { "all inherent impls defined in crate" }
928 /// Checks all types in the crate for overlap in their inherent impls. Reports errors.
929 /// Not meant to be used directly outside of coherence.
930 query crate_inherent_impls_overlap_check(_: ()) -> () {
931 desc { "check for overlap between inherent impls defined in this crate" }
934 /// Checks whether all impls in the crate pass the overlap check, returning
935 /// which impls fail it. If all impls are correct, the returned slice is empty.
936 query orphan_check_impl(key: LocalDefId) -> Result<(), ErrorGuaranteed> {
938 "checking whether impl `{}` follows the orphan rules",
939 tcx.def_path_str(key.to_def_id()),
943 /// Check whether the function has any recursion that could cause the inliner to trigger
944 /// a cycle. Returns the call stack causing the cycle. The call stack does not contain the
945 /// current function, just all intermediate functions.
946 query mir_callgraph_reachable(key: (ty::Instance<'tcx>, LocalDefId)) -> bool {
949 "computing if `{}` (transitively) calls `{}`",
951 tcx.def_path_str(key.1.to_def_id()),
955 /// Obtain all the calls into other local functions
956 query mir_inliner_callees(key: ty::InstanceDef<'tcx>) -> &'tcx [(DefId, SubstsRef<'tcx>)] {
959 "computing all local function calls in `{}`",
960 tcx.def_path_str(key.def_id()),
964 /// Evaluates a constant and returns the computed allocation.
966 /// **Do not use this** directly, use the `tcx.eval_static_initializer` wrapper.
967 query eval_to_allocation_raw(key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>)
968 -> EvalToAllocationRawResult<'tcx> {
970 "const-evaluating + checking `{}`",
971 key.value.display(tcx)
973 cache_on_disk_if { true }
976 /// Evaluates const items or anonymous constants
977 /// (such as enum variant explicit discriminants or array lengths)
978 /// into a representation suitable for the type system and const generics.
980 /// **Do not use this** directly, use one of the following wrappers: `tcx.const_eval_poly`,
981 /// `tcx.const_eval_resolve`, `tcx.const_eval_instance`, or `tcx.const_eval_global_id`.
982 query eval_to_const_value_raw(key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>)
983 -> EvalToConstValueResult<'tcx> {
985 "simplifying constant for the type system `{}`",
986 key.value.display(tcx)
988 cache_on_disk_if { true }
991 /// Evaluate a constant and convert it to a type level constant or
992 /// return `None` if that is not possible.
993 query eval_to_valtree(
994 key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>
995 ) -> EvalToValTreeResult<'tcx> {
996 desc { "evaluating type-level constant" }
999 /// Converts a type level constant value into `ConstValue`
1000 query valtree_to_const_val(key: (Ty<'tcx>, ty::ValTree<'tcx>)) -> ConstValue<'tcx> {
1001 desc { "converting type-level constant value to mir constant value"}
1004 /// Destructures array, ADT or tuple constants into the constants
1005 /// of their fields.
1006 query destructure_const(key: ty::Const<'tcx>) -> ty::DestructuredConst<'tcx> {
1007 desc { "destructuring type level constant"}
1010 /// Tries to destructure an `mir::ConstantKind` ADT or array into its variant index
1011 /// and its field values.
1012 query try_destructure_mir_constant(key: ty::ParamEnvAnd<'tcx, mir::ConstantKind<'tcx>>) -> Option<mir::DestructuredMirConstant<'tcx>> {
1013 desc { "destructuring mir constant"}
1017 /// Dereference a constant reference or raw pointer and turn the result into a constant
1019 query deref_mir_constant(
1020 key: ty::ParamEnvAnd<'tcx, mir::ConstantKind<'tcx>>
1021 ) -> mir::ConstantKind<'tcx> {
1022 desc { "dereferencing mir constant" }
1026 query const_caller_location(key: (rustc_span::Symbol, u32, u32)) -> ConstValue<'tcx> {
1027 desc { "get a &core::panic::Location referring to a span" }
1030 // FIXME get rid of this with valtrees
1032 key: LitToConstInput<'tcx>
1033 ) -> Result<ty::Const<'tcx>, LitToConstError> {
1034 desc { "converting literal to const" }
1037 query lit_to_mir_constant(key: LitToConstInput<'tcx>) -> Result<mir::ConstantKind<'tcx>, LitToConstError> {
1038 desc { "converting literal to mir constant" }
1041 query check_match(key: DefId) {
1042 desc { |tcx| "match-checking `{}`", tcx.def_path_str(key) }
1043 cache_on_disk_if { key.is_local() }
1046 /// Performs part of the privacy check and computes "access levels".
1047 query privacy_access_levels(_: ()) -> &'tcx AccessLevels {
1049 desc { "privacy access levels" }
1051 query check_private_in_public(_: ()) -> () {
1053 desc { "checking for private elements in public interfaces" }
1056 query reachable_set(_: ()) -> FxHashSet<LocalDefId> {
1057 storage(ArenaCacheSelector<'tcx>)
1058 desc { "reachability" }
1061 /// Per-body `region::ScopeTree`. The `DefId` should be the owner `DefId` for the body;
1062 /// in the case of closures, this will be redirected to the enclosing function.
1063 query region_scope_tree(def_id: DefId) -> &'tcx crate::middle::region::ScopeTree {
1064 desc { |tcx| "computing drop scopes for `{}`", tcx.def_path_str(def_id) }
1067 /// Generates a MIR body for the shim.
1068 query mir_shims(key: ty::InstanceDef<'tcx>) -> mir::Body<'tcx> {
1069 storage(ArenaCacheSelector<'tcx>)
1070 desc { |tcx| "generating MIR shim for `{}`", tcx.def_path_str(key.def_id()) }
1073 /// The `symbol_name` query provides the symbol name for calling a
1074 /// given instance from the local crate. In particular, it will also
1075 /// look up the correct symbol name of instances from upstream crates.
1076 query symbol_name(key: ty::Instance<'tcx>) -> ty::SymbolName<'tcx> {
1077 desc { "computing the symbol for `{}`", key }
1078 cache_on_disk_if { true }
1081 query opt_def_kind(def_id: DefId) -> Option<DefKind> {
1082 desc { |tcx| "looking up definition kind of `{}`", tcx.def_path_str(def_id) }
1083 cache_on_disk_if { def_id.is_local() }
1084 separate_provide_extern
1087 /// Gets the span for the definition.
1088 query def_span(def_id: DefId) -> Span {
1089 desc { |tcx| "looking up span for `{}`", tcx.def_path_str(def_id) }
1090 cache_on_disk_if { def_id.is_local() }
1091 separate_provide_extern
1094 /// Gets the span for the identifier of the definition.
1095 query def_ident_span(def_id: DefId) -> Option<Span> {
1096 desc { |tcx| "looking up span for `{}`'s identifier", tcx.def_path_str(def_id) }
1097 cache_on_disk_if { def_id.is_local() }
1098 separate_provide_extern
1101 query lookup_stability(def_id: DefId) -> Option<attr::Stability> {
1102 desc { |tcx| "looking up stability of `{}`", tcx.def_path_str(def_id) }
1103 cache_on_disk_if { def_id.is_local() }
1104 separate_provide_extern
1107 query lookup_const_stability(def_id: DefId) -> Option<attr::ConstStability> {
1108 desc { |tcx| "looking up const stability of `{}`", tcx.def_path_str(def_id) }
1109 cache_on_disk_if { def_id.is_local() }
1110 separate_provide_extern
1113 query lookup_default_body_stability(def_id: DefId) -> Option<attr::DefaultBodyStability> {
1114 desc { |tcx| "looking up default body stability of `{}`", tcx.def_path_str(def_id) }
1115 separate_provide_extern
1118 query should_inherit_track_caller(def_id: DefId) -> bool {
1119 desc { |tcx| "computing should_inherit_track_caller of `{}`", tcx.def_path_str(def_id) }
1122 query lookup_deprecation_entry(def_id: DefId) -> Option<DeprecationEntry> {
1123 desc { |tcx| "checking whether `{}` is deprecated", tcx.def_path_str(def_id) }
1124 cache_on_disk_if { def_id.is_local() }
1125 separate_provide_extern
1128 /// Determines whether an item is annotated with `doc(hidden)`.
1129 query is_doc_hidden(def_id: DefId) -> bool {
1130 desc { |tcx| "checking whether `{}` is `doc(hidden)`", tcx.def_path_str(def_id) }
1133 /// Returns the attributes on the item at `def_id`.
1135 /// Do not use this directly, use `tcx.get_attrs` instead.
1136 query item_attrs(def_id: DefId) -> &'tcx [ast::Attribute] {
1137 desc { |tcx| "collecting attributes of `{}`", tcx.def_path_str(def_id) }
1138 separate_provide_extern
1141 query codegen_fn_attrs(def_id: DefId) -> CodegenFnAttrs {
1142 desc { |tcx| "computing codegen attributes of `{}`", tcx.def_path_str(def_id) }
1143 storage(ArenaCacheSelector<'tcx>)
1144 cache_on_disk_if { def_id.is_local() }
1145 separate_provide_extern
1148 query asm_target_features(def_id: DefId) -> &'tcx FxHashSet<Symbol> {
1149 desc { |tcx| "computing target features for inline asm of `{}`", tcx.def_path_str(def_id) }
1152 query fn_arg_names(def_id: DefId) -> &'tcx [rustc_span::symbol::Ident] {
1153 desc { |tcx| "looking up function parameter names for `{}`", tcx.def_path_str(def_id) }
1154 cache_on_disk_if { def_id.is_local() }
1155 separate_provide_extern
1157 /// Gets the rendered value of the specified constant or associated constant.
1158 /// Used by rustdoc.
1159 query rendered_const(def_id: DefId) -> String {
1160 storage(ArenaCacheSelector<'tcx>)
1161 desc { |tcx| "rendering constant initializer of `{}`", tcx.def_path_str(def_id) }
1162 cache_on_disk_if { def_id.is_local() }
1163 separate_provide_extern
1165 query impl_parent(def_id: DefId) -> Option<DefId> {
1166 desc { |tcx| "computing specialization parent impl of `{}`", tcx.def_path_str(def_id) }
1167 cache_on_disk_if { def_id.is_local() }
1168 separate_provide_extern
1171 query is_ctfe_mir_available(key: DefId) -> bool {
1172 desc { |tcx| "checking if item has ctfe mir available: `{}`", tcx.def_path_str(key) }
1173 cache_on_disk_if { key.is_local() }
1174 separate_provide_extern
1176 query is_mir_available(key: DefId) -> bool {
1177 desc { |tcx| "checking if item has mir available: `{}`", tcx.def_path_str(key) }
1178 cache_on_disk_if { key.is_local() }
1179 separate_provide_extern
1182 query own_existential_vtable_entries(
1183 key: ty::PolyExistentialTraitRef<'tcx>
1184 ) -> &'tcx [DefId] {
1185 desc { |tcx| "finding all existential vtable entries for trait {}", tcx.def_path_str(key.def_id()) }
1188 query vtable_entries(key: ty::PolyTraitRef<'tcx>)
1189 -> &'tcx [ty::VtblEntry<'tcx>] {
1190 desc { |tcx| "finding all vtable entries for trait {}", tcx.def_path_str(key.def_id()) }
1193 query vtable_trait_upcasting_coercion_new_vptr_slot(key: (ty::Ty<'tcx>, ty::Ty<'tcx>)) -> Option<usize> {
1194 desc { |tcx| "finding the slot within vtable for trait object {} vtable ptr during trait upcasting coercion from {} vtable",
1198 query vtable_allocation(key: (Ty<'tcx>, Option<ty::PolyExistentialTraitRef<'tcx>>)) -> mir::interpret::AllocId {
1199 desc { |tcx| "vtable const allocation for <{} as {}>",
1201 key.1.map(|trait_ref| format!("{}", trait_ref)).unwrap_or("_".to_owned())
1205 query codegen_select_candidate(
1206 key: (ty::ParamEnv<'tcx>, ty::PolyTraitRef<'tcx>)
1207 ) -> Result<&'tcx ImplSource<'tcx, ()>, traits::CodegenObligationError> {
1208 cache_on_disk_if { true }
1209 desc { |tcx| "computing candidate for `{}`", key.1 }
1212 /// Return all `impl` blocks in the current crate.
1213 query all_local_trait_impls(_: ()) -> &'tcx rustc_data_structures::fx::FxIndexMap<DefId, Vec<LocalDefId>> {
1214 desc { "local trait impls" }
1217 /// Given a trait `trait_id`, return all known `impl` blocks.
1218 query trait_impls_of(trait_id: DefId) -> ty::trait_def::TraitImpls {
1219 storage(ArenaCacheSelector<'tcx>)
1220 desc { |tcx| "trait impls of `{}`", tcx.def_path_str(trait_id) }
1223 query specialization_graph_of(trait_id: DefId) -> specialization_graph::Graph {
1224 storage(ArenaCacheSelector<'tcx>)
1225 desc { |tcx| "building specialization graph of trait `{}`", tcx.def_path_str(trait_id) }
1226 cache_on_disk_if { true }
1228 query object_safety_violations(trait_id: DefId) -> &'tcx [traits::ObjectSafetyViolation] {
1229 desc { |tcx| "determine object safety of trait `{}`", tcx.def_path_str(trait_id) }
1232 /// Gets the ParameterEnvironment for a given item; this environment
1233 /// will be in "user-facing" mode, meaning that it is suitable for
1234 /// type-checking etc, and it does not normalize specializable
1235 /// associated types. This is almost always what you want,
1236 /// unless you are doing MIR optimizations, in which case you
1237 /// might want to use `reveal_all()` method to change modes.
1238 query param_env(def_id: DefId) -> ty::ParamEnv<'tcx> {
1239 desc { |tcx| "computing normalized predicates of `{}`", tcx.def_path_str(def_id) }
1242 /// Like `param_env`, but returns the `ParamEnv` in `Reveal::All` mode.
1243 /// Prefer this over `tcx.param_env(def_id).with_reveal_all_normalized(tcx)`,
1244 /// as this method is more efficient.
1245 query param_env_reveal_all_normalized(def_id: DefId) -> ty::ParamEnv<'tcx> {
1246 desc { |tcx| "computing revealed normalized predicates of `{}`", tcx.def_path_str(def_id) }
1249 /// Trait selection queries. These are best used by invoking `ty.is_copy_modulo_regions()`,
1250 /// `ty.is_copy()`, etc, since that will prune the environment where possible.
1251 query is_copy_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1252 desc { "computing whether `{}` is `Copy`", env.value }
1255 /// Query backing `Ty::is_sized`.
1256 query is_sized_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1257 desc { "computing whether `{}` is `Sized`", env.value }
1260 /// Query backing `Ty::is_freeze`.
1261 query is_freeze_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1262 desc { "computing whether `{}` is freeze", env.value }
1265 /// Query backing `Ty::is_unpin`.
1266 query is_unpin_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1267 desc { "computing whether `{}` is `Unpin`", env.value }
1270 /// Query backing `Ty::needs_drop`.
1271 query needs_drop_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1272 desc { "computing whether `{}` needs drop", env.value }
1275 /// Query backing `Ty::has_significant_drop_raw`.
1276 query has_significant_drop_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1277 desc { "computing whether `{}` has a significant drop", env.value }
1281 /// Query backing `Ty::is_structural_eq_shallow`.
1283 /// This is only correct for ADTs. Call `is_structural_eq_shallow` to handle all types
1285 query has_structural_eq_impls(ty: Ty<'tcx>) -> bool {
1287 "computing whether `{:?}` implements `PartialStructuralEq` and `StructuralEq`",
1292 /// A list of types where the ADT requires drop if and only if any of
1293 /// those types require drop. If the ADT is known to always need drop
1294 /// then `Err(AlwaysRequiresDrop)` is returned.
1295 query adt_drop_tys(def_id: DefId) -> Result<&'tcx ty::List<Ty<'tcx>>, AlwaysRequiresDrop> {
1296 desc { |tcx| "computing when `{}` needs drop", tcx.def_path_str(def_id) }
1297 cache_on_disk_if { true }
1300 /// A list of types where the ADT requires drop if and only if any of those types
1301 /// has significant drop. A type marked with the attribute `rustc_insignificant_dtor`
1302 /// is considered to not be significant. A drop is significant if it is implemented
1303 /// by the user or does anything that will have any observable behavior (other than
1304 /// freeing up memory). If the ADT is known to have a significant destructor then
1305 /// `Err(AlwaysRequiresDrop)` is returned.
1306 query adt_significant_drop_tys(def_id: DefId) -> Result<&'tcx ty::List<Ty<'tcx>>, AlwaysRequiresDrop> {
1307 desc { |tcx| "computing when `{}` has a significant destructor", tcx.def_path_str(def_id) }
1308 cache_on_disk_if { false }
1311 /// Computes the layout of a type. Note that this implicitly
1312 /// executes in "reveal all" mode, and will normalize the input type.
1314 key: ty::ParamEnvAnd<'tcx, Ty<'tcx>>
1315 ) -> Result<ty::layout::TyAndLayout<'tcx>, ty::layout::LayoutError<'tcx>> {
1317 desc { "computing layout of `{}`", key.value }
1321 /// Compute a `FnAbi` suitable for indirect calls, i.e. to `fn` pointers.
1323 /// NB: this doesn't handle virtual calls - those should use `fn_abi_of_instance`
1324 /// instead, where the instance is an `InstanceDef::Virtual`.
1325 query fn_abi_of_fn_ptr(
1326 key: ty::ParamEnvAnd<'tcx, (ty::PolyFnSig<'tcx>, &'tcx ty::List<Ty<'tcx>>)>
1327 ) -> Result<&'tcx abi::call::FnAbi<'tcx, Ty<'tcx>>, ty::layout::FnAbiError<'tcx>> {
1328 desc { "computing call ABI of `{}` function pointers", key.value.0 }
1332 /// Compute a `FnAbi` suitable for declaring/defining an `fn` instance, and for
1333 /// direct calls to an `fn`.
1335 /// NB: that includes virtual calls, which are represented by "direct calls"
1336 /// to an `InstanceDef::Virtual` instance (of `<dyn Trait as Trait>::fn`).
1337 query fn_abi_of_instance(
1338 key: ty::ParamEnvAnd<'tcx, (ty::Instance<'tcx>, &'tcx ty::List<Ty<'tcx>>)>
1339 ) -> Result<&'tcx abi::call::FnAbi<'tcx, Ty<'tcx>>, ty::layout::FnAbiError<'tcx>> {
1340 desc { "computing call ABI of `{}`", key.value.0 }
1344 query dylib_dependency_formats(_: CrateNum)
1345 -> &'tcx [(CrateNum, LinkagePreference)] {
1346 desc { "dylib dependency formats of crate" }
1347 separate_provide_extern
1350 query dependency_formats(_: ()) -> Lrc<crate::middle::dependency_format::Dependencies> {
1351 storage(ArenaCacheSelector<'tcx>)
1352 desc { "get the linkage format of all dependencies" }
1355 query is_compiler_builtins(_: CrateNum) -> bool {
1357 desc { "checking if the crate is_compiler_builtins" }
1358 separate_provide_extern
1360 query has_global_allocator(_: CrateNum) -> bool {
1361 // This query depends on untracked global state in CStore
1364 desc { "checking if the crate has_global_allocator" }
1365 separate_provide_extern
1367 query has_panic_handler(_: CrateNum) -> bool {
1369 desc { "checking if the crate has_panic_handler" }
1370 separate_provide_extern
1372 query is_profiler_runtime(_: CrateNum) -> bool {
1374 desc { "query a crate is `#![profiler_runtime]`" }
1375 separate_provide_extern
1377 query has_ffi_unwind_calls(key: LocalDefId) -> bool {
1378 desc { |tcx| "check if `{}` contains FFI-unwind calls", tcx.def_path_str(key.to_def_id()) }
1379 cache_on_disk_if { true }
1381 query required_panic_strategy(_: CrateNum) -> Option<PanicStrategy> {
1383 desc { "query a crate's required panic strategy" }
1384 separate_provide_extern
1386 query panic_in_drop_strategy(_: CrateNum) -> PanicStrategy {
1388 desc { "query a crate's configured panic-in-drop strategy" }
1389 separate_provide_extern
1391 query is_no_builtins(_: CrateNum) -> bool {
1393 desc { "test whether a crate has `#![no_builtins]`" }
1394 separate_provide_extern
1396 query symbol_mangling_version(_: CrateNum) -> SymbolManglingVersion {
1398 desc { "query a crate's symbol mangling version" }
1399 separate_provide_extern
1402 query extern_crate(def_id: DefId) -> Option<&'tcx ExternCrate> {
1404 desc { "getting crate's ExternCrateData" }
1405 separate_provide_extern
1408 query specializes(_: (DefId, DefId)) -> bool {
1409 desc { "computing whether impls specialize one another" }
1411 query in_scope_traits_map(_: LocalDefId)
1412 -> Option<&'tcx FxHashMap<ItemLocalId, Box<[TraitCandidate]>>> {
1413 desc { "traits in scope at a block" }
1416 query module_reexports(def_id: LocalDefId) -> Option<&'tcx [ModChild]> {
1417 desc { |tcx| "looking up reexports of module `{}`", tcx.def_path_str(def_id.to_def_id()) }
1420 query impl_defaultness(def_id: DefId) -> hir::Defaultness {
1421 desc { |tcx| "looking up whether `{}` is a default impl", tcx.def_path_str(def_id) }
1422 cache_on_disk_if { def_id.is_local() }
1423 separate_provide_extern
1426 query check_well_formed(key: LocalDefId) -> () {
1427 desc { |tcx| "checking that `{}` is well-formed", tcx.def_path_str(key.to_def_id()) }
1430 // The `DefId`s of all non-generic functions and statics in the given crate
1431 // that can be reached from outside the crate.
1433 // We expect this items to be available for being linked to.
1435 // This query can also be called for `LOCAL_CRATE`. In this case it will
1436 // compute which items will be reachable to other crates, taking into account
1437 // the kind of crate that is currently compiled. Crates with only a
1438 // C interface have fewer reachable things.
1440 // Does not include external symbols that don't have a corresponding DefId,
1441 // like the compiler-generated `main` function and so on.
1442 query reachable_non_generics(_: CrateNum)
1443 -> DefIdMap<SymbolExportInfo> {
1444 storage(ArenaCacheSelector<'tcx>)
1445 desc { "looking up the exported symbols of a crate" }
1446 separate_provide_extern
1448 query is_reachable_non_generic(def_id: DefId) -> bool {
1449 desc { |tcx| "checking whether `{}` is an exported symbol", tcx.def_path_str(def_id) }
1450 cache_on_disk_if { def_id.is_local() }
1451 separate_provide_extern
1453 query is_unreachable_local_definition(def_id: LocalDefId) -> bool {
1455 "checking whether `{}` is reachable from outside the crate",
1456 tcx.def_path_str(def_id.to_def_id()),
1460 /// The entire set of monomorphizations the local crate can safely link
1461 /// to because they are exported from upstream crates. Do not depend on
1462 /// this directly, as its value changes anytime a monomorphization gets
1463 /// added or removed in any upstream crate. Instead use the narrower
1464 /// `upstream_monomorphizations_for`, `upstream_drop_glue_for`, or, even
1465 /// better, `Instance::upstream_monomorphization()`.
1466 query upstream_monomorphizations(_: ()) -> DefIdMap<FxHashMap<SubstsRef<'tcx>, CrateNum>> {
1467 storage(ArenaCacheSelector<'tcx>)
1468 desc { "collecting available upstream monomorphizations" }
1471 /// Returns the set of upstream monomorphizations available for the
1472 /// generic function identified by the given `def_id`. The query makes
1473 /// sure to make a stable selection if the same monomorphization is
1474 /// available in multiple upstream crates.
1476 /// You likely want to call `Instance::upstream_monomorphization()`
1477 /// instead of invoking this query directly.
1478 query upstream_monomorphizations_for(def_id: DefId)
1479 -> Option<&'tcx FxHashMap<SubstsRef<'tcx>, CrateNum>>
1481 storage(ArenaCacheSelector<'tcx>)
1483 "collecting available upstream monomorphizations for `{}`",
1484 tcx.def_path_str(def_id),
1486 separate_provide_extern
1489 /// Returns the upstream crate that exports drop-glue for the given
1490 /// type (`substs` is expected to be a single-item list containing the
1491 /// type one wants drop-glue for).
1493 /// This is a subset of `upstream_monomorphizations_for` in order to
1494 /// increase dep-tracking granularity. Otherwise adding or removing any
1495 /// type with drop-glue in any upstream crate would invalidate all
1496 /// functions calling drop-glue of an upstream type.
1498 /// You likely want to call `Instance::upstream_monomorphization()`
1499 /// instead of invoking this query directly.
1501 /// NOTE: This query could easily be extended to also support other
1502 /// common functions that have are large set of monomorphizations
1503 /// (like `Clone::clone` for example).
1504 query upstream_drop_glue_for(substs: SubstsRef<'tcx>) -> Option<CrateNum> {
1505 desc { "available upstream drop-glue for `{:?}`", substs }
1508 query foreign_modules(_: CrateNum) -> FxHashMap<DefId, ForeignModule> {
1509 storage(ArenaCacheSelector<'tcx>)
1510 desc { "looking up the foreign modules of a linked crate" }
1511 separate_provide_extern
1514 /// Identifies the entry-point (e.g., the `main` function) for a given
1515 /// crate, returning `None` if there is no entry point (such as for library crates).
1516 query entry_fn(_: ()) -> Option<(DefId, EntryFnType)> {
1517 desc { "looking up the entry function of a crate" }
1519 query proc_macro_decls_static(_: ()) -> Option<LocalDefId> {
1520 desc { "looking up the derive registrar for a crate" }
1522 // The macro which defines `rustc_metadata::provide_extern` depends on this query's name.
1523 // Changing the name should cause a compiler error, but in case that changes, be aware.
1524 query crate_hash(_: CrateNum) -> Svh {
1526 desc { "looking up the hash a crate" }
1527 separate_provide_extern
1529 query crate_host_hash(_: CrateNum) -> Option<Svh> {
1531 desc { "looking up the hash of a host version of a crate" }
1532 separate_provide_extern
1534 query extra_filename(_: CrateNum) -> String {
1535 storage(ArenaCacheSelector<'tcx>)
1537 desc { "looking up the extra filename for a crate" }
1538 separate_provide_extern
1540 query crate_extern_paths(_: CrateNum) -> Vec<PathBuf> {
1541 storage(ArenaCacheSelector<'tcx>)
1543 desc { "looking up the paths for extern crates" }
1544 separate_provide_extern
1547 /// Given a crate and a trait, look up all impls of that trait in the crate.
1548 /// Return `(impl_id, self_ty)`.
1549 query implementations_of_trait(_: (CrateNum, DefId)) -> &'tcx [(DefId, Option<SimplifiedType>)] {
1550 desc { "looking up implementations of a trait in a crate" }
1551 separate_provide_extern
1554 /// Collects all incoherent impls for the given crate and type.
1556 /// Do not call this directly, but instead use the `incoherent_impls` query.
1557 /// This query is only used to get the data necessary for that query.
1558 query crate_incoherent_impls(key: (CrateNum, SimplifiedType)) -> &'tcx [DefId] {
1559 desc { |tcx| "collecting all impls for a type in a crate" }
1560 separate_provide_extern
1563 query is_dllimport_foreign_item(def_id: DefId) -> bool {
1564 desc { |tcx| "is_dllimport_foreign_item({})", tcx.def_path_str(def_id) }
1566 query is_statically_included_foreign_item(def_id: DefId) -> bool {
1567 desc { |tcx| "is_statically_included_foreign_item({})", tcx.def_path_str(def_id) }
1569 query native_library_kind(def_id: DefId)
1570 -> Option<NativeLibKind> {
1571 desc { |tcx| "native_library_kind({})", tcx.def_path_str(def_id) }
1573 query native_library(def_id: DefId) -> Option<&'tcx NativeLib> {
1574 desc { |tcx| "native_library({})", tcx.def_path_str(def_id) }
1577 /// Does lifetime resolution, but does not descend into trait items. This
1578 /// should only be used for resolving lifetimes of on trait definitions,
1579 /// and is used to avoid cycles. Importantly, `resolve_lifetimes` still visits
1580 /// the same lifetimes and is responsible for diagnostics.
1581 /// See `rustc_resolve::late::lifetimes for details.
1582 query resolve_lifetimes_trait_definition(_: LocalDefId) -> ResolveLifetimes {
1583 storage(ArenaCacheSelector<'tcx>)
1584 desc { "resolving lifetimes for a trait definition" }
1586 /// Does lifetime resolution on items. Importantly, we can't resolve
1587 /// lifetimes directly on things like trait methods, because of trait params.
1588 /// See `rustc_resolve::late::lifetimes for details.
1589 query resolve_lifetimes(_: LocalDefId) -> ResolveLifetimes {
1590 storage(ArenaCacheSelector<'tcx>)
1591 desc { "resolving lifetimes" }
1593 query named_region_map(_: LocalDefId) ->
1594 Option<&'tcx FxHashMap<ItemLocalId, Region>> {
1595 desc { "looking up a named region" }
1597 query is_late_bound_map(_: LocalDefId) -> Option<&'tcx FxIndexSet<LocalDefId>> {
1598 desc { "testing if a region is late bound" }
1600 /// For a given item's generic parameter, gets the default lifetimes to be used
1601 /// for each parameter if a trait object were to be passed for that parameter.
1602 /// For example, for `T` in `struct Foo<'a, T>`, this would be `'static`.
1603 /// For `T` in `struct Foo<'a, T: 'a>`, this would instead be `'a`.
1604 /// This query will panic if passed something that is not a type parameter.
1605 query object_lifetime_default(key: DefId) -> ObjectLifetimeDefault {
1606 desc { "looking up lifetime defaults for generic parameter `{}`", tcx.def_path_str(key) }
1607 separate_provide_extern
1609 query late_bound_vars_map(_: LocalDefId)
1610 -> Option<&'tcx FxHashMap<ItemLocalId, Vec<ty::BoundVariableKind>>> {
1611 desc { "looking up late bound vars" }
1614 query visibility(def_id: DefId) -> ty::Visibility<DefId> {
1615 desc { |tcx| "computing visibility of `{}`", tcx.def_path_str(def_id) }
1616 separate_provide_extern
1619 /// Computes the set of modules from which this type is visibly uninhabited.
1620 /// To check whether a type is uninhabited at all (not just from a given module), you could
1621 /// check whether the forest is empty.
1622 query type_uninhabited_from(
1623 key: ty::ParamEnvAnd<'tcx, Ty<'tcx>>
1624 ) -> ty::inhabitedness::DefIdForest<'tcx> {
1625 desc { "computing the inhabitedness of `{:?}`", key }
1629 query dep_kind(_: CrateNum) -> CrateDepKind {
1631 desc { "fetching what a dependency looks like" }
1632 separate_provide_extern
1635 /// Gets the name of the crate.
1636 query crate_name(_: CrateNum) -> Symbol {
1638 desc { "fetching what a crate is named" }
1639 separate_provide_extern
1641 query module_children(def_id: DefId) -> &'tcx [ModChild] {
1642 desc { |tcx| "collecting child items of module `{}`", tcx.def_path_str(def_id) }
1643 separate_provide_extern
1645 query extern_mod_stmt_cnum(def_id: LocalDefId) -> Option<CrateNum> {
1646 desc { |tcx| "computing crate imported by `{}`", tcx.def_path_str(def_id.to_def_id()) }
1649 query lib_features(_: ()) -> LibFeatures {
1650 storage(ArenaCacheSelector<'tcx>)
1651 desc { "calculating the lib features map" }
1653 query defined_lib_features(_: CrateNum) -> &'tcx [(Symbol, Option<Symbol>)] {
1654 desc { "calculating the lib features defined in a crate" }
1655 separate_provide_extern
1657 query stability_implications(_: CrateNum) -> FxHashMap<Symbol, Symbol> {
1658 storage(ArenaCacheSelector<'tcx>)
1659 desc { "calculating the implications between `#[unstable]` features defined in a crate" }
1660 separate_provide_extern
1662 /// Whether the function is an intrinsic
1663 query is_intrinsic(def_id: DefId) -> bool {
1664 desc { |tcx| "is_intrinsic({})", tcx.def_path_str(def_id) }
1665 separate_provide_extern
1667 /// Returns the lang items defined in another crate by loading it from metadata.
1668 query get_lang_items(_: ()) -> LanguageItems {
1669 storage(ArenaCacheSelector<'tcx>)
1671 desc { "calculating the lang items map" }
1674 /// Returns all diagnostic items defined in all crates.
1675 query all_diagnostic_items(_: ()) -> rustc_hir::diagnostic_items::DiagnosticItems {
1676 storage(ArenaCacheSelector<'tcx>)
1678 desc { "calculating the diagnostic items map" }
1681 /// Returns the lang items defined in another crate by loading it from metadata.
1682 query defined_lang_items(_: CrateNum) -> &'tcx [(DefId, usize)] {
1683 desc { "calculating the lang items defined in a crate" }
1684 separate_provide_extern
1687 /// Returns the diagnostic items defined in a crate.
1688 query diagnostic_items(_: CrateNum) -> rustc_hir::diagnostic_items::DiagnosticItems {
1689 storage(ArenaCacheSelector<'tcx>)
1690 desc { "calculating the diagnostic items map in a crate" }
1691 separate_provide_extern
1694 query missing_lang_items(_: CrateNum) -> &'tcx [LangItem] {
1695 desc { "calculating the missing lang items in a crate" }
1696 separate_provide_extern
1698 query visible_parent_map(_: ()) -> DefIdMap<DefId> {
1699 storage(ArenaCacheSelector<'tcx>)
1700 desc { "calculating the visible parent map" }
1702 query trimmed_def_paths(_: ()) -> FxHashMap<DefId, Symbol> {
1703 storage(ArenaCacheSelector<'tcx>)
1704 desc { "calculating trimmed def paths" }
1706 query missing_extern_crate_item(_: CrateNum) -> bool {
1708 desc { "seeing if we're missing an `extern crate` item for this crate" }
1709 separate_provide_extern
1711 query used_crate_source(_: CrateNum) -> Lrc<CrateSource> {
1712 storage(ArenaCacheSelector<'tcx>)
1714 desc { "looking at the source for a crate" }
1715 separate_provide_extern
1717 /// Returns the debugger visualizers defined for this crate.
1718 query debugger_visualizers(_: CrateNum) -> Vec<rustc_span::DebuggerVisualizerFile> {
1719 storage(ArenaCacheSelector<'tcx>)
1720 desc { "looking up the debugger visualizers for this crate" }
1721 separate_provide_extern
1723 query postorder_cnums(_: ()) -> &'tcx [CrateNum] {
1725 desc { "generating a postorder list of CrateNums" }
1727 /// Returns whether or not the crate with CrateNum 'cnum'
1728 /// is marked as a private dependency
1729 query is_private_dep(c: CrateNum) -> bool {
1731 desc { "check whether crate {} is a private dependency", c }
1732 separate_provide_extern
1734 query allocator_kind(_: ()) -> Option<AllocatorKind> {
1736 desc { "allocator kind for the current crate" }
1739 query upvars_mentioned(def_id: DefId) -> Option<&'tcx FxIndexMap<hir::HirId, hir::Upvar>> {
1740 desc { |tcx| "collecting upvars mentioned in `{}`", tcx.def_path_str(def_id) }
1742 query maybe_unused_trait_imports(_: ()) -> &'tcx FxIndexSet<LocalDefId> {
1743 desc { "fetching potentially unused trait imports" }
1745 query maybe_unused_extern_crates(_: ()) -> &'tcx [(LocalDefId, Span)] {
1746 desc { "looking up all possibly unused extern crates" }
1748 query names_imported_by_glob_use(def_id: LocalDefId) -> &'tcx FxHashSet<Symbol> {
1749 desc { |tcx| "names_imported_by_glob_use for `{}`", tcx.def_path_str(def_id.to_def_id()) }
1752 query stability_index(_: ()) -> stability::Index {
1753 storage(ArenaCacheSelector<'tcx>)
1755 desc { "calculating the stability index for the local crate" }
1757 query crates(_: ()) -> &'tcx [CrateNum] {
1759 desc { "fetching all foreign CrateNum instances" }
1762 /// A list of all traits in a crate, used by rustdoc and error reporting.
1763 /// NOTE: Not named just `traits` due to a naming conflict.
1764 query traits_in_crate(_: CrateNum) -> &'tcx [DefId] {
1765 desc { "fetching all traits in a crate" }
1766 separate_provide_extern
1769 /// The list of symbols exported from the given crate.
1771 /// - All names contained in `exported_symbols(cnum)` are guaranteed to
1772 /// correspond to a publicly visible symbol in `cnum` machine code.
1773 /// - The `exported_symbols` sets of different crates do not intersect.
1774 query exported_symbols(cnum: CrateNum) -> &'tcx [(ExportedSymbol<'tcx>, SymbolExportInfo)] {
1775 desc { "exported_symbols" }
1776 cache_on_disk_if { *cnum == LOCAL_CRATE }
1777 separate_provide_extern
1780 query collect_and_partition_mono_items(_: ()) -> (&'tcx DefIdSet, &'tcx [CodegenUnit<'tcx>]) {
1782 desc { "collect_and_partition_mono_items" }
1784 query is_codegened_item(def_id: DefId) -> bool {
1785 desc { |tcx| "determining whether `{}` needs codegen", tcx.def_path_str(def_id) }
1788 /// All items participating in code generation together with items inlined into them.
1789 query codegened_and_inlined_items(_: ()) -> &'tcx DefIdSet {
1791 desc { "codegened_and_inlined_items" }
1794 query codegen_unit(_: Symbol) -> &'tcx CodegenUnit<'tcx> {
1795 desc { "codegen_unit" }
1797 query unused_generic_params(key: ty::InstanceDef<'tcx>) -> FiniteBitSet<u32> {
1798 cache_on_disk_if { key.def_id().is_local() }
1800 |tcx| "determining which generic parameters are unused by `{}`",
1801 tcx.def_path_str(key.def_id())
1803 separate_provide_extern
1805 query backend_optimization_level(_: ()) -> OptLevel {
1806 desc { "optimization level used by backend" }
1809 /// Return the filenames where output artefacts shall be stored.
1811 /// This query returns an `&Arc` because codegen backends need the value even after the `TyCtxt`
1812 /// has been destroyed.
1813 query output_filenames(_: ()) -> &'tcx Arc<OutputFilenames> {
1815 desc { "output_filenames" }
1818 /// Do not call this query directly: invoke `normalize` instead.
1819 query normalize_projection_ty(
1820 goal: CanonicalProjectionGoal<'tcx>
1822 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, NormalizationResult<'tcx>>>,
1825 desc { "normalizing `{:?}`", goal }
1829 /// Do not call this query directly: invoke `try_normalize_erasing_regions` instead.
1830 query try_normalize_generic_arg_after_erasing_regions(
1831 goal: ParamEnvAnd<'tcx, GenericArg<'tcx>>
1832 ) -> Result<GenericArg<'tcx>, NoSolution> {
1833 desc { "normalizing `{}`", goal.value }
1837 /// Do not call this query directly: invoke `try_normalize_erasing_regions` instead.
1838 query try_normalize_mir_const_after_erasing_regions(
1839 goal: ParamEnvAnd<'tcx, mir::ConstantKind<'tcx>>
1840 ) -> Result<mir::ConstantKind<'tcx>, NoSolution> {
1841 desc { "normalizing `{}`", goal.value }
1845 query implied_outlives_bounds(
1846 goal: CanonicalTyGoal<'tcx>
1848 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, Vec<OutlivesBound<'tcx>>>>,
1851 desc { "computing implied outlives bounds for `{:?}`", goal }
1855 /// Do not call this query directly:
1856 /// invoke `DropckOutlives::new(dropped_ty)).fully_perform(typeck.infcx)` instead.
1857 query dropck_outlives(
1858 goal: CanonicalTyGoal<'tcx>
1860 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, DropckOutlivesResult<'tcx>>>,
1863 desc { "computing dropck types for `{:?}`", goal }
1867 /// Do not call this query directly: invoke `infcx.predicate_may_hold()` or
1868 /// `infcx.predicate_must_hold()` instead.
1869 query evaluate_obligation(
1870 goal: CanonicalPredicateGoal<'tcx>
1871 ) -> Result<traits::EvaluationResult, traits::OverflowError> {
1872 desc { "evaluating trait selection obligation `{}`", goal.value.value }
1875 query evaluate_goal(
1876 goal: traits::CanonicalChalkEnvironmentAndGoal<'tcx>
1878 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1881 desc { "evaluating trait selection obligation `{}`", goal.value }
1884 /// Do not call this query directly: part of the `Eq` type-op
1885 query type_op_ascribe_user_type(
1886 goal: CanonicalTypeOpAscribeUserTypeGoal<'tcx>
1888 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1891 desc { "evaluating `type_op_ascribe_user_type` `{:?}`", goal }
1895 /// Do not call this query directly: part of the `Eq` type-op
1897 goal: CanonicalTypeOpEqGoal<'tcx>
1899 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1902 desc { "evaluating `type_op_eq` `{:?}`", goal }
1906 /// Do not call this query directly: part of the `Subtype` type-op
1907 query type_op_subtype(
1908 goal: CanonicalTypeOpSubtypeGoal<'tcx>
1910 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1913 desc { "evaluating `type_op_subtype` `{:?}`", goal }
1917 /// Do not call this query directly: part of the `ProvePredicate` type-op
1918 query type_op_prove_predicate(
1919 goal: CanonicalTypeOpProvePredicateGoal<'tcx>
1921 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1924 desc { "evaluating `type_op_prove_predicate` `{:?}`", goal }
1927 /// Do not call this query directly: part of the `Normalize` type-op
1928 query type_op_normalize_ty(
1929 goal: CanonicalTypeOpNormalizeGoal<'tcx, Ty<'tcx>>
1931 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, Ty<'tcx>>>,
1934 desc { "normalizing `{:?}`", goal }
1938 /// Do not call this query directly: part of the `Normalize` type-op
1939 query type_op_normalize_predicate(
1940 goal: CanonicalTypeOpNormalizeGoal<'tcx, ty::Predicate<'tcx>>
1942 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ty::Predicate<'tcx>>>,
1945 desc { "normalizing `{:?}`", goal }
1949 /// Do not call this query directly: part of the `Normalize` type-op
1950 query type_op_normalize_poly_fn_sig(
1951 goal: CanonicalTypeOpNormalizeGoal<'tcx, ty::PolyFnSig<'tcx>>
1953 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ty::PolyFnSig<'tcx>>>,
1956 desc { "normalizing `{:?}`", goal }
1960 /// Do not call this query directly: part of the `Normalize` type-op
1961 query type_op_normalize_fn_sig(
1962 goal: CanonicalTypeOpNormalizeGoal<'tcx, ty::FnSig<'tcx>>
1964 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ty::FnSig<'tcx>>>,
1967 desc { "normalizing `{:?}`", goal }
1971 query subst_and_check_impossible_predicates(key: (DefId, SubstsRef<'tcx>)) -> bool {
1973 "impossible substituted predicates:`{}`",
1974 tcx.def_path_str(key.0)
1978 query is_impossible_method(key: (DefId, DefId)) -> bool {
1980 "checking if {} is impossible to call within {}",
1981 tcx.def_path_str(key.1),
1982 tcx.def_path_str(key.0),
1986 query method_autoderef_steps(
1987 goal: CanonicalTyGoal<'tcx>
1988 ) -> MethodAutoderefStepsResult<'tcx> {
1989 desc { "computing autoderef types for `{:?}`", goal }
1993 query supported_target_features(_: CrateNum) -> FxHashMap<String, Option<Symbol>> {
1994 storage(ArenaCacheSelector<'tcx>)
1996 desc { "looking up supported target features" }
1999 /// Get an estimate of the size of an InstanceDef based on its MIR for CGU partitioning.
2000 query instance_def_size_estimate(def: ty::InstanceDef<'tcx>)
2002 desc { |tcx| "estimating size for `{}`", tcx.def_path_str(def.def_id()) }
2005 query features_query(_: ()) -> &'tcx rustc_feature::Features {
2007 desc { "looking up enabled feature gates" }
2010 /// Attempt to resolve the given `DefId` to an `Instance`, for the
2011 /// given generics args (`SubstsRef`), returning one of:
2012 /// * `Ok(Some(instance))` on success
2013 /// * `Ok(None)` when the `SubstsRef` are still too generic,
2014 /// and therefore don't allow finding the final `Instance`
2015 /// * `Err(ErrorGuaranteed)` when the `Instance` resolution process
2016 /// couldn't complete due to errors elsewhere - this is distinct
2017 /// from `Ok(None)` to avoid misleading diagnostics when an error
2018 /// has already been/will be emitted, for the original cause
2019 query resolve_instance(
2020 key: ty::ParamEnvAnd<'tcx, (DefId, SubstsRef<'tcx>)>
2021 ) -> Result<Option<ty::Instance<'tcx>>, ErrorGuaranteed> {
2022 desc { "resolving instance `{}`", ty::Instance::new(key.value.0, key.value.1) }
2026 query resolve_instance_of_const_arg(
2027 key: ty::ParamEnvAnd<'tcx, (LocalDefId, DefId, SubstsRef<'tcx>)>
2028 ) -> Result<Option<ty::Instance<'tcx>>, ErrorGuaranteed> {
2030 "resolving instance of the const argument `{}`",
2031 ty::Instance::new(key.value.0.to_def_id(), key.value.2),
2036 query normalize_opaque_types(key: &'tcx ty::List<ty::Predicate<'tcx>>) -> &'tcx ty::List<ty::Predicate<'tcx>> {
2037 desc { "normalizing opaque types in {:?}", key }
2040 /// Checks whether a type is definitely uninhabited. This is
2041 /// conservative: for some types that are uninhabited we return `false`,
2042 /// but we only return `true` for types that are definitely uninhabited.
2043 /// `ty.conservative_is_privately_uninhabited` implies that any value of type `ty`
2044 /// will be `Abi::Uninhabited`. (Note that uninhabited types may have nonzero
2045 /// size, to account for partial initialisation. See #49298 for details.)
2046 query conservative_is_privately_uninhabited(key: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
2047 desc { "conservatively checking if {:?} is privately uninhabited", key }
2051 query limits(key: ()) -> Limits {
2052 desc { "looking up limits" }
2055 /// Performs an HIR-based well-formed check on the item with the given `HirId`. If
2056 /// we get an `Unimplemented` error that matches the provided `Predicate`, return
2057 /// the cause of the newly created obligation.
2059 /// This is only used by error-reporting code to get a better cause (in particular, a better
2060 /// span) for an *existing* error. Therefore, it is best-effort, and may never handle
2061 /// all of the cases that the normal `ty::Ty`-based wfcheck does. This is fine,
2062 /// because the `ty::Ty`-based wfcheck is always run.
2063 query diagnostic_hir_wf_check(key: (ty::Predicate<'tcx>, traits::WellFormedLoc)) -> Option<traits::ObligationCause<'tcx>> {
2064 storage(ArenaCacheSelector<'tcx>)
2067 desc { "performing HIR wf-checking for predicate {:?} at item {:?}", key.0, key.1 }
2071 /// The list of backend features computed from CLI flags (`-Ctarget-cpu`, `-Ctarget-feature`,
2072 /// `--target` and similar).
2073 query global_backend_features(_: ()) -> Vec<String> {
2074 storage(ArenaCacheSelector<'tcx>)
2076 desc { "computing the backend features for CLI flags" }
2079 query generator_diagnostic_data(key: DefId) -> Option<GeneratorDiagnosticData<'tcx>> {
2080 storage(ArenaCacheSelector<'tcx>)
2081 desc { |tcx| "looking up generator diagnostic data of `{}`", tcx.def_path_str(key) }
2082 separate_provide_extern
2085 query permits_uninit_init(key: TyAndLayout<'tcx>) -> bool {
2086 desc { "checking to see if {:?} permits being left uninit", key.ty }
2089 query permits_zero_init(key: TyAndLayout<'tcx>) -> bool {
2090 desc { "checking to see if {:?} permits being left zeroed", key.ty }