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 /// Return the span for a definition.
30 /// Contrary to `def_span` below, this query returns the full absolute span of the definition.
31 /// This span is meant for dep-tracking rather than diagnostics. It should not be used outside
32 /// of rustc_middle::hir::source_map.
33 query source_span(key: LocalDefId) -> Span {
34 desc { "get the source span" }
37 /// Represents crate as a whole (as distinct from the top-level crate module).
38 /// If you call `hir_crate` (e.g., indirectly by calling `tcx.hir().krate()`),
39 /// we will have to assume that any change means that you need to be recompiled.
40 /// This is because the `hir_crate` query gives you access to all other items.
41 /// To avoid this fate, do not call `tcx.hir().krate()`; instead,
42 /// prefer wrappers like `tcx.visit_all_items_in_krate()`.
43 query hir_crate(key: ()) -> &'tcx Crate<'tcx> {
45 desc { "get the crate HIR" }
48 /// All items in the crate.
49 query hir_crate_items(_: ()) -> rustc_middle::hir::ModuleItems {
50 storage(ArenaCacheSelector<'tcx>)
52 desc { "get HIR crate items" }
55 /// The items in a module.
57 /// This can be conveniently accessed by `tcx.hir().visit_item_likes_in_module`.
58 /// Avoid calling this query directly.
59 query hir_module_items(key: LocalDefId) -> rustc_middle::hir::ModuleItems {
60 storage(ArenaCacheSelector<'tcx>)
61 desc { |tcx| "HIR module items in `{}`", tcx.def_path_str(key.to_def_id()) }
62 cache_on_disk_if { true }
65 /// Gives access to the HIR node for the HIR owner `key`.
67 /// This can be conveniently accessed by methods on `tcx.hir()`.
68 /// Avoid calling this query directly.
69 query hir_owner(key: LocalDefId) -> Option<crate::hir::Owner<'tcx>> {
70 desc { |tcx| "HIR owner of `{}`", tcx.def_path_str(key.to_def_id()) }
73 /// Gives access to the HIR ID for the given `LocalDefId` owner `key`.
75 /// This can be conveniently accessed by methods on `tcx.hir()`.
76 /// Avoid calling this query directly.
77 query local_def_id_to_hir_id(key: LocalDefId) -> hir::HirId {
78 desc { |tcx| "HIR ID of `{}`", tcx.def_path_str(key.to_def_id()) }
81 /// Gives access to the HIR node's parent for the HIR owner `key`.
83 /// This can be conveniently accessed by methods on `tcx.hir()`.
84 /// Avoid calling this query directly.
85 query hir_owner_parent(key: LocalDefId) -> hir::HirId {
86 desc { |tcx| "HIR parent of `{}`", tcx.def_path_str(key.to_def_id()) }
89 /// Gives access to the HIR nodes and bodies inside the HIR owner `key`.
91 /// This can be conveniently accessed by methods on `tcx.hir()`.
92 /// Avoid calling this query directly.
93 query hir_owner_nodes(key: LocalDefId) -> hir::MaybeOwner<&'tcx hir::OwnerNodes<'tcx>> {
94 desc { |tcx| "HIR owner items in `{}`", tcx.def_path_str(key.to_def_id()) }
97 /// Gives access to the HIR attributes inside the HIR owner `key`.
99 /// This can be conveniently accessed by methods on `tcx.hir()`.
100 /// Avoid calling this query directly.
101 query hir_attrs(key: LocalDefId) -> &'tcx hir::AttributeMap<'tcx> {
102 desc { |tcx| "HIR owner attributes in `{}`", tcx.def_path_str(key.to_def_id()) }
105 /// Computes the `DefId` of the corresponding const parameter in case the `key` is a
106 /// const argument and returns `None` otherwise.
108 /// ```ignore (incomplete)
109 /// let a = foo::<7>();
110 /// // ^ Calling `opt_const_param_of` for this argument,
112 /// fn foo<const N: usize>()
113 /// // ^ returns this `DefId`.
116 /// // ^ While calling `opt_const_param_of` for other bodies returns `None`.
119 // It looks like caching this query on disk actually slightly
120 // worsened performance in #74376.
122 // Once const generics are more prevalently used, we might want to
123 // consider only caching calls returning `Some`.
124 query opt_const_param_of(key: LocalDefId) -> Option<DefId> {
125 desc { |tcx| "computing the optional const parameter of `{}`", tcx.def_path_str(key.to_def_id()) }
128 /// Given the def_id of a const-generic parameter, computes the associated default const
129 /// parameter. e.g. `fn example<const N: usize=3>` called on `N` would return `3`.
130 query const_param_default(param: DefId) -> ty::Const<'tcx> {
131 desc { |tcx| "compute const default for a given parameter `{}`", tcx.def_path_str(param) }
132 cache_on_disk_if { param.is_local() }
133 separate_provide_extern
136 /// Returns the [`Ty`][rustc_middle::ty::Ty] of the given [`DefId`]. If the [`DefId`] points
137 /// to an alias, it will "skip" this alias to return the aliased type.
139 /// [`DefId`]: rustc_hir::def_id::DefId
140 query type_of(key: DefId) -> Ty<'tcx> {
144 use rustc_hir::def::DefKind;
145 match tcx.def_kind(key) {
146 DefKind::TyAlias => "expanding type alias",
147 DefKind::TraitAlias => "expanding trait alias",
148 _ => "computing type of",
151 path = tcx.def_path_str(key),
153 cache_on_disk_if { key.is_local() }
154 separate_provide_extern
157 query analysis(key: ()) -> Result<(), ErrorGuaranteed> {
159 desc { "running analysis passes on this crate" }
162 /// This query checks the fulfillment of collected lint expectations.
163 /// All lint emitting queries have to be done before this is executed
164 /// to ensure that all expectations can be fulfilled.
166 /// This is an extra query to enable other drivers (like rustdoc) to
167 /// only execute a small subset of the `analysis` query, while allowing
168 /// lints to be expected. In rustc, this query will be executed as part of
169 /// the `analysis` query and doesn't have to be called a second time.
171 /// Tools can additionally pass in a tool filter. That will restrict the
172 /// expectations to only trigger for lints starting with the listed tool
173 /// name. This is useful for cases were not all linting code from rustc
174 /// was called. With the default `None` all registered lints will also
175 /// be checked for expectation fulfillment.
176 query check_expectations(key: Option<Symbol>) -> () {
178 desc { "checking lint expectations (RFC 2383)" }
181 /// Maps from the `DefId` of an item (trait/struct/enum/fn) to its
182 /// associated generics.
183 query generics_of(key: DefId) -> ty::Generics {
184 desc { |tcx| "computing generics of `{}`", tcx.def_path_str(key) }
185 storage(ArenaCacheSelector<'tcx>)
186 cache_on_disk_if { key.is_local() }
187 separate_provide_extern
190 /// Maps from the `DefId` of an item (trait/struct/enum/fn) to the
191 /// predicates (where-clauses) that must be proven true in order
192 /// to reference it. This is almost always the "predicates query"
195 /// `predicates_of` builds on `predicates_defined_on` -- in fact,
196 /// it is almost always the same as that query, except for the
197 /// case of traits. For traits, `predicates_of` contains
198 /// an additional `Self: Trait<...>` predicate that users don't
199 /// actually write. This reflects the fact that to invoke the
200 /// trait (e.g., via `Default::default`) you must supply types
201 /// that actually implement the trait. (However, this extra
202 /// predicate gets in the way of some checks, which are intended
203 /// to operate over only the actual where-clauses written by the
205 query predicates_of(key: DefId) -> ty::GenericPredicates<'tcx> {
206 desc { |tcx| "computing predicates of `{}`", tcx.def_path_str(key) }
207 cache_on_disk_if { key.is_local() }
210 /// Returns the list of bounds that can be used for
211 /// `SelectionCandidate::ProjectionCandidate(_)` and
212 /// `ProjectionTyCandidate::TraitDef`.
213 /// Specifically this is the bounds written on the trait's type
214 /// definition, or those after the `impl` keyword
216 /// ```ignore (incomplete)
217 /// type X: Bound + 'lt
219 /// impl Debug + Display
220 /// // ^^^^^^^^^^^^^^^
223 /// `key` is the `DefId` of the associated type or opaque type.
225 /// Bounds from the parent (e.g. with nested impl trait) are not included.
226 query explicit_item_bounds(key: DefId) -> &'tcx [(ty::Predicate<'tcx>, Span)] {
227 desc { |tcx| "finding item bounds for `{}`", tcx.def_path_str(key) }
228 cache_on_disk_if { key.is_local() }
229 separate_provide_extern
232 /// Elaborated version of the predicates from `explicit_item_bounds`.
238 /// type MyAType: Eq + ?Sized;
242 /// `explicit_item_bounds` returns `[<Self as MyTrait>::MyAType: Eq]`,
243 /// and `item_bounds` returns
246 /// <Self as Trait>::MyAType: Eq,
247 /// <Self as Trait>::MyAType: PartialEq<<Self as Trait>::MyAType>
251 /// Bounds from the parent (e.g. with nested impl trait) are not included.
252 query item_bounds(key: DefId) -> &'tcx ty::List<ty::Predicate<'tcx>> {
253 desc { |tcx| "elaborating item bounds for `{}`", tcx.def_path_str(key) }
256 query native_libraries(_: CrateNum) -> Vec<NativeLib> {
257 storage(ArenaCacheSelector<'tcx>)
258 desc { "looking up the native libraries of a linked crate" }
259 separate_provide_extern
262 query lint_levels(_: ()) -> LintLevelMap {
263 storage(ArenaCacheSelector<'tcx>)
265 desc { "computing the lint levels for items in this crate" }
268 query parent_module_from_def_id(key: LocalDefId) -> LocalDefId {
270 desc { |tcx| "parent module of `{}`", tcx.def_path_str(key.to_def_id()) }
273 query expn_that_defined(key: DefId) -> rustc_span::ExpnId {
274 desc { |tcx| "expansion that defined `{}`", tcx.def_path_str(key) }
275 separate_provide_extern
278 query is_panic_runtime(_: CrateNum) -> bool {
280 desc { "checking if the crate is_panic_runtime" }
281 separate_provide_extern
284 /// Fetch the THIR for a given body. If typeck for that body failed, returns an empty `Thir`.
285 query thir_body(key: ty::WithOptConstParam<LocalDefId>)
286 -> Result<(&'tcx Steal<thir::Thir<'tcx>>, thir::ExprId), ErrorGuaranteed>
288 // Perf tests revealed that hashing THIR is inefficient (see #85729).
290 desc { |tcx| "building THIR for `{}`", tcx.def_path_str(key.did.to_def_id()) }
293 /// Create a THIR tree for debugging.
294 query thir_tree(key: ty::WithOptConstParam<LocalDefId>) -> String {
296 storage(ArenaCacheSelector<'tcx>)
297 desc { |tcx| "constructing THIR tree for `{}`", tcx.def_path_str(key.did.to_def_id()) }
300 /// Set of all the `DefId`s in this crate that have MIR associated with
301 /// them. This includes all the body owners, but also things like struct
303 query mir_keys(_: ()) -> rustc_data_structures::fx::FxIndexSet<LocalDefId> {
304 storage(ArenaCacheSelector<'tcx>)
305 desc { "getting a list of all mir_keys" }
308 /// Maps DefId's that have an associated `mir::Body` to the result
309 /// of the MIR const-checking pass. This is the set of qualifs in
310 /// the final value of a `const`.
311 query mir_const_qualif(key: DefId) -> mir::ConstQualifs {
312 desc { |tcx| "const checking `{}`", tcx.def_path_str(key) }
313 cache_on_disk_if { key.is_local() }
314 separate_provide_extern
316 query mir_const_qualif_const_arg(
317 key: (LocalDefId, DefId)
318 ) -> mir::ConstQualifs {
320 |tcx| "const checking the const argument `{}`",
321 tcx.def_path_str(key.0.to_def_id())
325 /// Fetch the MIR for a given `DefId` right after it's built - this includes
326 /// unreachable code.
327 query mir_built(key: ty::WithOptConstParam<LocalDefId>) -> &'tcx Steal<mir::Body<'tcx>> {
328 desc { |tcx| "building MIR for `{}`", tcx.def_path_str(key.did.to_def_id()) }
331 /// Fetch the MIR for a given `DefId` up till the point where it is
332 /// ready for const qualification.
334 /// See the README for the `mir` module for details.
335 query mir_const(key: ty::WithOptConstParam<LocalDefId>) -> &'tcx Steal<mir::Body<'tcx>> {
337 |tcx| "processing MIR for {}`{}`",
338 if key.const_param_did.is_some() { "the const argument " } else { "" },
339 tcx.def_path_str(key.did.to_def_id()),
344 /// Try to build an abstract representation of the given constant.
345 query thir_abstract_const(
347 ) -> Result<Option<&'tcx [thir::abstract_const::Node<'tcx>]>, ErrorGuaranteed> {
349 |tcx| "building an abstract representation for {}", tcx.def_path_str(key),
351 separate_provide_extern
353 /// Try to build an abstract representation of the given constant.
354 query thir_abstract_const_of_const_arg(
355 key: (LocalDefId, DefId)
356 ) -> Result<Option<&'tcx [thir::abstract_const::Node<'tcx>]>, ErrorGuaranteed> {
359 "building an abstract representation for the const argument {}",
360 tcx.def_path_str(key.0.to_def_id()),
364 query try_unify_abstract_consts(key:
365 ty::ParamEnvAnd<'tcx, (ty::Unevaluated<'tcx, ()>, ty::Unevaluated<'tcx, ()>
368 |tcx| "trying to unify the generic constants {} and {}",
369 tcx.def_path_str(key.value.0.def.did), tcx.def_path_str(key.value.1.def.did)
373 query mir_drops_elaborated_and_const_checked(
374 key: ty::WithOptConstParam<LocalDefId>
375 ) -> &'tcx Steal<mir::Body<'tcx>> {
377 desc { |tcx| "elaborating drops for `{}`", tcx.def_path_str(key.did.to_def_id()) }
382 ) -> &'tcx mir::Body<'tcx> {
383 desc { |tcx| "caching mir of `{}` for CTFE", tcx.def_path_str(key) }
384 cache_on_disk_if { key.is_local() }
385 separate_provide_extern
388 query mir_for_ctfe_of_const_arg(key: (LocalDefId, DefId)) -> &'tcx mir::Body<'tcx> {
390 |tcx| "MIR for CTFE of the const argument `{}`",
391 tcx.def_path_str(key.0.to_def_id())
395 query mir_promoted(key: ty::WithOptConstParam<LocalDefId>) ->
397 &'tcx Steal<mir::Body<'tcx>>,
398 &'tcx Steal<IndexVec<mir::Promoted, mir::Body<'tcx>>>
402 |tcx| "processing {}`{}`",
403 if key.const_param_did.is_some() { "the const argument " } else { "" },
404 tcx.def_path_str(key.did.to_def_id()),
408 query symbols_for_closure_captures(
409 key: (LocalDefId, DefId)
410 ) -> Vec<rustc_span::Symbol> {
411 storage(ArenaCacheSelector<'tcx>)
413 |tcx| "symbols for captures of closure `{}` in `{}`",
414 tcx.def_path_str(key.1),
415 tcx.def_path_str(key.0.to_def_id())
419 /// MIR after our optimization passes have run. This is MIR that is ready
420 /// for codegen. This is also the only query that can fetch non-local MIR, at present.
421 query optimized_mir(key: DefId) -> &'tcx mir::Body<'tcx> {
422 desc { |tcx| "optimizing MIR for `{}`", tcx.def_path_str(key) }
423 cache_on_disk_if { key.is_local() }
424 separate_provide_extern
427 /// Returns coverage summary info for a function, after executing the `InstrumentCoverage`
428 /// MIR pass (assuming the -Cinstrument-coverage option is enabled).
429 query coverageinfo(key: ty::InstanceDef<'tcx>) -> mir::CoverageInfo {
430 desc { |tcx| "retrieving coverage info from MIR for `{}`", tcx.def_path_str(key.def_id()) }
431 storage(ArenaCacheSelector<'tcx>)
434 /// Returns the `CodeRegions` for a function that has instrumented coverage, in case the
435 /// function was optimized out before codegen, and before being added to the Coverage Map.
436 query covered_code_regions(key: DefId) -> Vec<&'tcx mir::coverage::CodeRegion> {
438 |tcx| "retrieving the covered `CodeRegion`s, if instrumented, for `{}`",
439 tcx.def_path_str(key)
441 storage(ArenaCacheSelector<'tcx>)
442 cache_on_disk_if { key.is_local() }
445 /// The `DefId` is the `DefId` of the containing MIR body. Promoteds do not have their own
446 /// `DefId`. This function returns all promoteds in the specified body. The body references
447 /// promoteds by the `DefId` and the `mir::Promoted` index. This is necessary, because
448 /// after inlining a body may refer to promoteds from other bodies. In that case you still
449 /// need to use the `DefId` of the original body.
450 query promoted_mir(key: DefId) -> &'tcx IndexVec<mir::Promoted, mir::Body<'tcx>> {
451 desc { |tcx| "optimizing promoted MIR for `{}`", tcx.def_path_str(key) }
452 cache_on_disk_if { key.is_local() }
453 separate_provide_extern
455 query promoted_mir_of_const_arg(
456 key: (LocalDefId, DefId)
457 ) -> &'tcx IndexVec<mir::Promoted, mir::Body<'tcx>> {
459 |tcx| "optimizing promoted MIR for the const argument `{}`",
460 tcx.def_path_str(key.0.to_def_id()),
464 /// Erases regions from `ty` to yield a new type.
465 /// Normally you would just use `tcx.erase_regions(value)`,
466 /// however, which uses this query as a kind of cache.
467 query erase_regions_ty(ty: Ty<'tcx>) -> Ty<'tcx> {
468 // This query is not expected to have input -- as a result, it
469 // is not a good candidates for "replay" because it is essentially a
470 // pure function of its input (and hence the expectation is that
471 // no caller would be green **apart** from just these
472 // queries). Making it anonymous avoids hashing the result, which
473 // may save a bit of time.
475 desc { "erasing regions from `{:?}`", ty }
478 query wasm_import_module_map(_: CrateNum) -> FxHashMap<DefId, String> {
479 storage(ArenaCacheSelector<'tcx>)
480 desc { "wasm import module map" }
483 /// Maps from the `DefId` of an item (trait/struct/enum/fn) to the
484 /// predicates (where-clauses) directly defined on it. This is
485 /// equal to the `explicit_predicates_of` predicates plus the
486 /// `inferred_outlives_of` predicates.
487 query predicates_defined_on(key: DefId) -> ty::GenericPredicates<'tcx> {
488 desc { |tcx| "computing predicates of `{}`", tcx.def_path_str(key) }
491 /// Returns everything that looks like a predicate written explicitly
492 /// by the user on a trait item.
494 /// Traits are unusual, because predicates on associated types are
495 /// converted into bounds on that type for backwards compatibility:
497 /// trait X where Self::U: Copy { type U; }
501 /// trait X { type U: Copy; }
503 /// `explicit_predicates_of` and `explicit_item_bounds` will then take
504 /// the appropriate subsets of the predicates here.
505 query trait_explicit_predicates_and_bounds(key: LocalDefId) -> ty::GenericPredicates<'tcx> {
506 desc { |tcx| "computing explicit predicates of trait `{}`", tcx.def_path_str(key.to_def_id()) }
509 /// Returns the predicates written explicitly by the user.
510 query explicit_predicates_of(key: DefId) -> ty::GenericPredicates<'tcx> {
511 desc { |tcx| "computing explicit predicates of `{}`", tcx.def_path_str(key) }
512 cache_on_disk_if { key.is_local() }
513 separate_provide_extern
516 /// Returns the inferred outlives predicates (e.g., for `struct
517 /// Foo<'a, T> { x: &'a T }`, this would return `T: 'a`).
518 query inferred_outlives_of(key: DefId) -> &'tcx [(ty::Predicate<'tcx>, Span)] {
519 desc { |tcx| "computing inferred outlives predicates of `{}`", tcx.def_path_str(key) }
520 cache_on_disk_if { key.is_local() }
521 separate_provide_extern
524 /// Maps from the `DefId` of a trait to the list of
525 /// super-predicates. This is a subset of the full list of
526 /// predicates. We store these in a separate map because we must
527 /// evaluate them even during type conversion, often before the
528 /// full predicates are available (note that supertraits have
529 /// additional acyclicity requirements).
530 query super_predicates_of(key: DefId) -> ty::GenericPredicates<'tcx> {
531 desc { |tcx| "computing the super predicates of `{}`", tcx.def_path_str(key) }
532 cache_on_disk_if { key.is_local() }
533 separate_provide_extern
536 /// The `Option<Ident>` is the name of an associated type. If it is `None`, then this query
537 /// returns the full set of predicates. If `Some<Ident>`, then the query returns only the
538 /// subset of super-predicates that reference traits that define the given associated type.
539 /// This is used to avoid cycles in resolving types like `T::Item`.
540 query super_predicates_that_define_assoc_type(key: (DefId, Option<rustc_span::symbol::Ident>)) -> ty::GenericPredicates<'tcx> {
541 desc { |tcx| "computing the super traits of `{}`{}",
542 tcx.def_path_str(key.0),
543 if let Some(assoc_name) = key.1 { format!(" with associated type name `{}`", assoc_name) } else { "".to_string() },
547 /// To avoid cycles within the predicates of a single item we compute
548 /// per-type-parameter predicates for resolving `T::AssocTy`.
549 query type_param_predicates(key: (DefId, LocalDefId, rustc_span::symbol::Ident)) -> ty::GenericPredicates<'tcx> {
550 desc { |tcx| "computing the bounds for type parameter `{}`", tcx.hir().ty_param_name(key.1) }
553 query trait_def(key: DefId) -> ty::TraitDef {
554 desc { |tcx| "computing trait definition for `{}`", tcx.def_path_str(key) }
555 storage(ArenaCacheSelector<'tcx>)
556 cache_on_disk_if { key.is_local() }
557 separate_provide_extern
559 query adt_def(key: DefId) -> ty::AdtDef<'tcx> {
560 desc { |tcx| "computing ADT definition for `{}`", tcx.def_path_str(key) }
561 cache_on_disk_if { key.is_local() }
562 separate_provide_extern
564 query adt_destructor(key: DefId) -> Option<ty::Destructor> {
565 desc { |tcx| "computing `Drop` impl for `{}`", tcx.def_path_str(key) }
566 cache_on_disk_if { key.is_local() }
567 separate_provide_extern
570 // The cycle error here should be reported as an error by `check_representable`.
571 // We consider the type as Sized in the meanwhile to avoid
572 // further errors (done in impl Value for AdtSizedConstraint).
573 // Use `cycle_delay_bug` to delay the cycle error here to be emitted later
574 // in case we accidentally otherwise don't emit an error.
575 query adt_sized_constraint(
577 ) -> AdtSizedConstraint<'tcx> {
578 desc { |tcx| "computing `Sized` constraints for `{}`", tcx.def_path_str(key) }
582 query adt_dtorck_constraint(
584 ) -> Result<&'tcx DropckConstraint<'tcx>, NoSolution> {
585 desc { |tcx| "computing drop-check constraints for `{}`", tcx.def_path_str(key) }
588 /// Returns `true` if this is a const fn, use the `is_const_fn` to know whether your crate
589 /// actually sees it as const fn (e.g., the const-fn-ness might be unstable and you might
590 /// not have the feature gate active).
592 /// **Do not call this function manually.** It is only meant to cache the base data for the
593 /// `is_const_fn` function. Consider using `is_const_fn` or `is_const_fn_raw` instead.
594 query constness(key: DefId) -> hir::Constness {
595 desc { |tcx| "checking if item is const: `{}`", tcx.def_path_str(key) }
596 cache_on_disk_if { key.is_local() }
597 separate_provide_extern
600 query asyncness(key: DefId) -> hir::IsAsync {
601 desc { |tcx| "checking if the function is async: `{}`", tcx.def_path_str(key) }
602 cache_on_disk_if { key.is_local() }
603 separate_provide_extern
606 /// Returns `true` if calls to the function may be promoted.
608 /// This is either because the function is e.g., a tuple-struct or tuple-variant
609 /// constructor, or because it has the `#[rustc_promotable]` attribute. The attribute should
610 /// be removed in the future in favour of some form of check which figures out whether the
611 /// function does not inspect the bits of any of its arguments (so is essentially just a
612 /// constructor function).
613 query is_promotable_const_fn(key: DefId) -> bool {
614 desc { |tcx| "checking if item is promotable: `{}`", tcx.def_path_str(key) }
617 /// Returns `true` if this is a foreign item (i.e., linked via `extern { ... }`).
618 query is_foreign_item(key: DefId) -> bool {
619 desc { |tcx| "checking if `{}` is a foreign item", tcx.def_path_str(key) }
620 cache_on_disk_if { key.is_local() }
621 separate_provide_extern
624 /// Returns `Some(generator_kind)` if the node pointed to by `def_id` is a generator.
625 query generator_kind(def_id: DefId) -> Option<hir::GeneratorKind> {
626 desc { |tcx| "looking up generator kind of `{}`", tcx.def_path_str(def_id) }
627 cache_on_disk_if { def_id.is_local() }
628 separate_provide_extern
631 /// Gets a map with the variance of every item; use `item_variance` instead.
632 query crate_variances(_: ()) -> ty::CrateVariancesMap<'tcx> {
633 storage(ArenaCacheSelector<'tcx>)
634 desc { "computing the variances for items in this crate" }
637 /// Maps from the `DefId` of a type or region parameter to its (inferred) variance.
638 query variances_of(def_id: DefId) -> &'tcx [ty::Variance] {
639 desc { |tcx| "computing the variances of `{}`", tcx.def_path_str(def_id) }
640 cache_on_disk_if { def_id.is_local() }
641 separate_provide_extern
644 /// Maps from thee `DefId` of a type to its (inferred) outlives.
645 query inferred_outlives_crate(_: ()) -> ty::CratePredicatesMap<'tcx> {
646 storage(ArenaCacheSelector<'tcx>)
647 desc { "computing the inferred outlives predicates for items in this crate" }
650 /// Maps from an impl/trait `DefId` to a list of the `DefId`s of its items.
651 query associated_item_def_ids(key: DefId) -> &'tcx [DefId] {
652 desc { |tcx| "collecting associated items of `{}`", tcx.def_path_str(key) }
653 cache_on_disk_if { key.is_local() }
654 separate_provide_extern
657 /// Maps from a trait item to the trait item "descriptor".
658 query associated_item(key: DefId) -> ty::AssocItem {
659 desc { |tcx| "computing associated item data for `{}`", tcx.def_path_str(key) }
660 storage(ArenaCacheSelector<'tcx>)
661 cache_on_disk_if { key.is_local() }
662 separate_provide_extern
665 /// Collects the associated items defined on a trait or impl.
666 query associated_items(key: DefId) -> ty::AssocItems<'tcx> {
667 storage(ArenaCacheSelector<'tcx>)
668 desc { |tcx| "collecting associated items of {}", tcx.def_path_str(key) }
671 /// Maps from associated items on a trait to the corresponding associated
672 /// item on the impl specified by `impl_id`.
674 /// For example, with the following code
679 /// trait Trait { // trait_id
680 /// fn f(); // trait_f
681 /// fn g() {} // trait_g
684 /// impl Trait for Type { // impl_id
685 /// fn f() {} // impl_f
686 /// fn g() {} // impl_g
690 /// The map returned for `tcx.impl_item_implementor_ids(impl_id)` would be
691 ///`{ trait_f: impl_f, trait_g: impl_g }`
692 query impl_item_implementor_ids(impl_id: DefId) -> FxHashMap<DefId, DefId> {
693 storage(ArenaCacheSelector<'tcx>)
694 desc { |tcx| "comparing impl items against trait for {}", tcx.def_path_str(impl_id) }
697 /// Given an `impl_id`, return the trait it implements.
698 /// Return `None` if this is an inherent impl.
699 query impl_trait_ref(impl_id: DefId) -> Option<ty::TraitRef<'tcx>> {
700 desc { |tcx| "computing trait implemented by `{}`", tcx.def_path_str(impl_id) }
701 cache_on_disk_if { impl_id.is_local() }
702 separate_provide_extern
704 query impl_polarity(impl_id: DefId) -> ty::ImplPolarity {
705 desc { |tcx| "computing implementation polarity of `{}`", tcx.def_path_str(impl_id) }
706 cache_on_disk_if { impl_id.is_local() }
707 separate_provide_extern
710 query issue33140_self_ty(key: DefId) -> Option<ty::Ty<'tcx>> {
711 desc { |tcx| "computing Self type wrt issue #33140 `{}`", tcx.def_path_str(key) }
714 /// Maps a `DefId` of a type to a list of its inherent impls.
715 /// Contains implementations of methods that are inherent to a type.
716 /// Methods in these implementations don't need to be exported.
717 query inherent_impls(key: DefId) -> &'tcx [DefId] {
718 desc { |tcx| "collecting inherent impls for `{}`", tcx.def_path_str(key) }
719 cache_on_disk_if { key.is_local() }
720 separate_provide_extern
723 query incoherent_impls(key: SimplifiedType) -> &'tcx [DefId] {
724 desc { |tcx| "collecting all inherent impls for `{:?}`", key }
727 /// The result of unsafety-checking this `LocalDefId`.
728 query unsafety_check_result(key: LocalDefId) -> &'tcx mir::UnsafetyCheckResult {
729 desc { |tcx| "unsafety-checking `{}`", tcx.def_path_str(key.to_def_id()) }
730 cache_on_disk_if { true }
732 query unsafety_check_result_for_const_arg(key: (LocalDefId, DefId)) -> &'tcx mir::UnsafetyCheckResult {
734 |tcx| "unsafety-checking the const argument `{}`",
735 tcx.def_path_str(key.0.to_def_id())
739 /// Unsafety-check this `LocalDefId` with THIR unsafeck. This should be
740 /// used with `-Zthir-unsafeck`.
741 query thir_check_unsafety(key: LocalDefId) {
742 desc { |tcx| "unsafety-checking `{}`", tcx.def_path_str(key.to_def_id()) }
743 cache_on_disk_if { true }
745 query thir_check_unsafety_for_const_arg(key: (LocalDefId, DefId)) {
747 |tcx| "unsafety-checking the const argument `{}`",
748 tcx.def_path_str(key.0.to_def_id())
752 /// HACK: when evaluated, this reports an "unsafe derive on repr(packed)" error.
754 /// Unsafety checking is executed for each method separately, but we only want
755 /// to emit this error once per derive. As there are some impls with multiple
756 /// methods, we use a query for deduplication.
757 query unsafe_derive_on_repr_packed(key: LocalDefId) -> () {
758 desc { |tcx| "processing `{}`", tcx.def_path_str(key.to_def_id()) }
761 /// Computes the signature of the function.
762 query fn_sig(key: DefId) -> ty::PolyFnSig<'tcx> {
763 desc { |tcx| "computing function signature of `{}`", tcx.def_path_str(key) }
764 cache_on_disk_if { key.is_local() }
765 separate_provide_extern
768 /// Performs lint checking for the module.
769 query lint_mod(key: LocalDefId) -> () {
770 desc { |tcx| "linting {}", describe_as_module(key, tcx) }
773 /// Checks the attributes in the module.
774 query check_mod_attrs(key: LocalDefId) -> () {
775 desc { |tcx| "checking attributes in {}", describe_as_module(key, tcx) }
778 /// Checks for uses of unstable APIs in the module.
779 query check_mod_unstable_api_usage(key: LocalDefId) -> () {
780 desc { |tcx| "checking for unstable API usage in {}", describe_as_module(key, tcx) }
783 /// Checks the const bodies in the module for illegal operations (e.g. `if` or `loop`).
784 query check_mod_const_bodies(key: LocalDefId) -> () {
785 desc { |tcx| "checking consts in {}", describe_as_module(key, tcx) }
788 /// Checks the loops in the module.
789 query check_mod_loops(key: LocalDefId) -> () {
790 desc { |tcx| "checking loops in {}", describe_as_module(key, tcx) }
793 query check_mod_naked_functions(key: LocalDefId) -> () {
794 desc { |tcx| "checking naked functions in {}", describe_as_module(key, tcx) }
797 query check_mod_item_types(key: LocalDefId) -> () {
798 desc { |tcx| "checking item types in {}", describe_as_module(key, tcx) }
801 query check_mod_privacy(key: LocalDefId) -> () {
802 desc { |tcx| "checking privacy in {}", describe_as_module(key, tcx) }
805 query check_mod_liveness(key: LocalDefId) -> () {
806 desc { |tcx| "checking liveness of variables in {}", describe_as_module(key, tcx) }
809 /// Return the live symbols in the crate for dead code check.
811 /// The second return value maps from ADTs to ignored derived traits (e.g. Debug and Clone) and
812 /// their respective impl (i.e., part of the derive macro)
813 query live_symbols_and_ignored_derived_traits(_: ()) -> (
814 FxHashSet<LocalDefId>,
815 FxHashMap<LocalDefId, Vec<(DefId, DefId)>>
817 storage(ArenaCacheSelector<'tcx>)
818 desc { "find live symbols in crate" }
821 query check_mod_deathness(key: LocalDefId) -> () {
822 desc { |tcx| "checking deathness of variables in {}", describe_as_module(key, tcx) }
825 query check_mod_impl_wf(key: LocalDefId) -> () {
826 desc { |tcx| "checking that impls are well-formed in {}", describe_as_module(key, tcx) }
829 query check_mod_type_wf(key: LocalDefId) -> () {
830 desc { |tcx| "checking that types are well-formed in {}", describe_as_module(key, tcx) }
833 query collect_mod_item_types(key: LocalDefId) -> () {
834 desc { |tcx| "collecting item types in {}", describe_as_module(key, tcx) }
837 /// Caches `CoerceUnsized` kinds for impls on custom types.
838 query coerce_unsized_info(key: DefId) -> ty::adjustment::CoerceUnsizedInfo {
839 desc { |tcx| "computing CoerceUnsized info for `{}`", tcx.def_path_str(key) }
840 cache_on_disk_if { key.is_local() }
841 separate_provide_extern
844 query typeck_item_bodies(_: ()) -> () {
845 desc { "type-checking all item bodies" }
848 query typeck(key: LocalDefId) -> &'tcx ty::TypeckResults<'tcx> {
849 desc { |tcx| "type-checking `{}`", tcx.def_path_str(key.to_def_id()) }
850 cache_on_disk_if { true }
852 query typeck_const_arg(
853 key: (LocalDefId, DefId)
854 ) -> &'tcx ty::TypeckResults<'tcx> {
856 |tcx| "type-checking the const argument `{}`",
857 tcx.def_path_str(key.0.to_def_id()),
860 query diagnostic_only_typeck(key: LocalDefId) -> &'tcx ty::TypeckResults<'tcx> {
861 desc { |tcx| "type-checking `{}`", tcx.def_path_str(key.to_def_id()) }
862 cache_on_disk_if { true }
863 load_cached(tcx, id) {
864 let typeck_results: Option<ty::TypeckResults<'tcx>> = tcx
865 .on_disk_cache().as_ref()
866 .and_then(|c| c.try_load_query_result(*tcx, id));
868 typeck_results.map(|x| &*tcx.arena.alloc(x))
872 query used_trait_imports(key: LocalDefId) -> &'tcx FxHashSet<LocalDefId> {
873 desc { |tcx| "used_trait_imports `{}`", tcx.def_path_str(key.to_def_id()) }
874 cache_on_disk_if { true }
877 query has_typeck_results(def_id: DefId) -> bool {
878 desc { |tcx| "checking whether `{}` has a body", tcx.def_path_str(def_id) }
881 query coherent_trait(def_id: DefId) -> () {
882 desc { |tcx| "coherence checking all impls of trait `{}`", tcx.def_path_str(def_id) }
885 /// Borrow-checks the function body. If this is a closure, returns
886 /// additional requirements that the closure's creator must verify.
887 query mir_borrowck(key: LocalDefId) -> &'tcx mir::BorrowCheckResult<'tcx> {
888 desc { |tcx| "borrow-checking `{}`", tcx.def_path_str(key.to_def_id()) }
889 cache_on_disk_if(tcx) { tcx.is_typeck_child(key.to_def_id()) }
891 query mir_borrowck_const_arg(key: (LocalDefId, DefId)) -> &'tcx mir::BorrowCheckResult<'tcx> {
893 |tcx| "borrow-checking the const argument`{}`",
894 tcx.def_path_str(key.0.to_def_id())
898 /// Gets a complete map from all types to their inherent impls.
899 /// Not meant to be used directly outside of coherence.
900 query crate_inherent_impls(k: ()) -> CrateInherentImpls {
901 storage(ArenaCacheSelector<'tcx>)
902 desc { "all inherent impls defined in crate" }
905 /// Checks all types in the crate for overlap in their inherent impls. Reports errors.
906 /// Not meant to be used directly outside of coherence.
907 query crate_inherent_impls_overlap_check(_: ()) -> () {
908 desc { "check for overlap between inherent impls defined in this crate" }
911 /// Checks whether all impls in the crate pass the overlap check, returning
912 /// which impls fail it. If all impls are correct, the returned slice is empty.
913 query orphan_check_impl(key: LocalDefId) -> Result<(), ErrorGuaranteed> {
915 "checking whether impl `{}` follows the orphan rules",
916 tcx.def_path_str(key.to_def_id()),
920 /// Check whether the function has any recursion that could cause the inliner to trigger
921 /// a cycle. Returns the call stack causing the cycle. The call stack does not contain the
922 /// current function, just all intermediate functions.
923 query mir_callgraph_reachable(key: (ty::Instance<'tcx>, LocalDefId)) -> bool {
926 "computing if `{}` (transitively) calls `{}`",
928 tcx.def_path_str(key.1.to_def_id()),
932 /// Obtain all the calls into other local functions
933 query mir_inliner_callees(key: ty::InstanceDef<'tcx>) -> &'tcx [(DefId, SubstsRef<'tcx>)] {
936 "computing all local function calls in `{}`",
937 tcx.def_path_str(key.def_id()),
941 /// Evaluates a constant and returns the computed allocation.
943 /// **Do not use this** directly, use the `tcx.eval_static_initializer` wrapper.
944 query eval_to_allocation_raw(key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>)
945 -> EvalToAllocationRawResult<'tcx> {
947 "const-evaluating + checking `{}`",
948 key.value.display(tcx)
950 cache_on_disk_if { true }
953 /// Evaluates const items or anonymous constants
954 /// (such as enum variant explicit discriminants or array lengths)
955 /// into a representation suitable for the type system and const generics.
957 /// **Do not use this** directly, use one of the following wrappers: `tcx.const_eval_poly`,
958 /// `tcx.const_eval_resolve`, `tcx.const_eval_instance`, or `tcx.const_eval_global_id`.
959 query eval_to_const_value_raw(key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>)
960 -> EvalToConstValueResult<'tcx> {
962 "simplifying constant for the type system `{}`",
963 key.value.display(tcx)
965 cache_on_disk_if { true }
968 /// Evaluate a constant and convert it to a type level constant or
969 /// return `None` if that is not possible.
970 query eval_to_valtree(
971 key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>
972 ) -> EvalToValTreeResult<'tcx> {
973 desc { "evaluating type-level constant" }
976 /// Converts a type level constant value into `ConstValue`
977 query valtree_to_const_val(key: (Ty<'tcx>, ty::ValTree<'tcx>)) -> ConstValue<'tcx> {
978 desc { "converting type-level constant value to mir constant value"}
981 /// Destructure a constant ADT or array into its variant index and its
982 /// field values or return `None` if constant is invalid.
984 /// Use infallible `TyCtxt::destructure_const` when you know that constant is valid.
985 query try_destructure_const(key: ty::Const<'tcx>) -> Option<ty::DestructuredConst<'tcx>> {
986 desc { "destructuring type level constant"}
989 /// Tries to destructure an `mir::ConstantKind` ADT or array into its variant index
990 /// and its field values.
991 query try_destructure_mir_constant(key: ty::ParamEnvAnd<'tcx, mir::ConstantKind<'tcx>>) -> Option<mir::DestructuredMirConstant<'tcx>> {
992 desc { "destructuring mir constant"}
996 /// Dereference a constant reference or raw pointer and turn the result into a constant
998 query deref_mir_constant(
999 key: ty::ParamEnvAnd<'tcx, mir::ConstantKind<'tcx>>
1000 ) -> mir::ConstantKind<'tcx> {
1001 desc { "dereferencing mir constant" }
1005 query const_caller_location(key: (rustc_span::Symbol, u32, u32)) -> ConstValue<'tcx> {
1006 desc { "get a &core::panic::Location referring to a span" }
1009 // FIXME get rid of this with valtrees
1011 key: LitToConstInput<'tcx>
1012 ) -> Result<ty::Const<'tcx>, LitToConstError> {
1013 desc { "converting literal to const" }
1016 query lit_to_mir_constant(key: LitToConstInput<'tcx>) -> Result<mir::ConstantKind<'tcx>, LitToConstError> {
1017 desc { "converting literal to mir constant" }
1020 query check_match(key: DefId) {
1021 desc { |tcx| "match-checking `{}`", tcx.def_path_str(key) }
1022 cache_on_disk_if { key.is_local() }
1025 /// Performs part of the privacy check and computes "access levels".
1026 query privacy_access_levels(_: ()) -> &'tcx AccessLevels {
1028 desc { "privacy access levels" }
1030 query check_private_in_public(_: ()) -> () {
1032 desc { "checking for private elements in public interfaces" }
1035 query reachable_set(_: ()) -> FxHashSet<LocalDefId> {
1036 storage(ArenaCacheSelector<'tcx>)
1037 desc { "reachability" }
1040 /// Per-body `region::ScopeTree`. The `DefId` should be the owner `DefId` for the body;
1041 /// in the case of closures, this will be redirected to the enclosing function.
1042 query region_scope_tree(def_id: DefId) -> &'tcx crate::middle::region::ScopeTree {
1043 desc { |tcx| "computing drop scopes for `{}`", tcx.def_path_str(def_id) }
1046 /// Generates a MIR body for the shim.
1047 query mir_shims(key: ty::InstanceDef<'tcx>) -> mir::Body<'tcx> {
1048 storage(ArenaCacheSelector<'tcx>)
1049 desc { |tcx| "generating MIR shim for `{}`", tcx.def_path_str(key.def_id()) }
1052 /// The `symbol_name` query provides the symbol name for calling a
1053 /// given instance from the local crate. In particular, it will also
1054 /// look up the correct symbol name of instances from upstream crates.
1055 query symbol_name(key: ty::Instance<'tcx>) -> ty::SymbolName<'tcx> {
1056 desc { "computing the symbol for `{}`", key }
1057 cache_on_disk_if { true }
1060 query opt_def_kind(def_id: DefId) -> Option<DefKind> {
1061 desc { |tcx| "looking up definition kind of `{}`", tcx.def_path_str(def_id) }
1062 cache_on_disk_if { def_id.is_local() }
1063 separate_provide_extern
1066 /// Gets the span for the definition.
1067 query def_span(def_id: DefId) -> Span {
1068 desc { |tcx| "looking up span for `{}`", tcx.def_path_str(def_id) }
1069 cache_on_disk_if { def_id.is_local() }
1070 separate_provide_extern
1073 /// Gets the span for the identifier of the definition.
1074 query def_ident_span(def_id: DefId) -> Option<Span> {
1075 desc { |tcx| "looking up span for `{}`'s identifier", tcx.def_path_str(def_id) }
1076 cache_on_disk_if { def_id.is_local() }
1077 separate_provide_extern
1080 query lookup_stability(def_id: DefId) -> Option<attr::Stability> {
1081 desc { |tcx| "looking up stability of `{}`", tcx.def_path_str(def_id) }
1082 cache_on_disk_if { def_id.is_local() }
1083 separate_provide_extern
1086 query lookup_const_stability(def_id: DefId) -> Option<attr::ConstStability> {
1087 desc { |tcx| "looking up const stability of `{}`", tcx.def_path_str(def_id) }
1088 cache_on_disk_if { def_id.is_local() }
1089 separate_provide_extern
1092 query should_inherit_track_caller(def_id: DefId) -> bool {
1093 desc { |tcx| "computing should_inherit_track_caller of `{}`", tcx.def_path_str(def_id) }
1096 query lookup_deprecation_entry(def_id: DefId) -> Option<DeprecationEntry> {
1097 desc { |tcx| "checking whether `{}` is deprecated", tcx.def_path_str(def_id) }
1098 cache_on_disk_if { def_id.is_local() }
1099 separate_provide_extern
1102 /// Determines whether an item is annotated with `doc(hidden)`.
1103 query is_doc_hidden(def_id: DefId) -> bool {
1104 desc { |tcx| "checking whether `{}` is `doc(hidden)`", tcx.def_path_str(def_id) }
1107 /// Returns the attributes on the item at `def_id`.
1109 /// Do not use this directly, use `tcx.get_attrs` instead.
1110 query item_attrs(def_id: DefId) -> &'tcx [ast::Attribute] {
1111 desc { |tcx| "collecting attributes of `{}`", tcx.def_path_str(def_id) }
1112 separate_provide_extern
1115 query codegen_fn_attrs(def_id: DefId) -> CodegenFnAttrs {
1116 desc { |tcx| "computing codegen attributes of `{}`", tcx.def_path_str(def_id) }
1117 storage(ArenaCacheSelector<'tcx>)
1118 cache_on_disk_if { def_id.is_local() }
1119 separate_provide_extern
1122 query asm_target_features(def_id: DefId) -> &'tcx FxHashSet<Symbol> {
1123 desc { |tcx| "computing target features for inline asm of `{}`", tcx.def_path_str(def_id) }
1126 query fn_arg_names(def_id: DefId) -> &'tcx [rustc_span::symbol::Ident] {
1127 desc { |tcx| "looking up function parameter names for `{}`", tcx.def_path_str(def_id) }
1128 cache_on_disk_if { def_id.is_local() }
1129 separate_provide_extern
1131 /// Gets the rendered value of the specified constant or associated constant.
1132 /// Used by rustdoc.
1133 query rendered_const(def_id: DefId) -> String {
1134 storage(ArenaCacheSelector<'tcx>)
1135 desc { |tcx| "rendering constant intializer of `{}`", tcx.def_path_str(def_id) }
1136 cache_on_disk_if { def_id.is_local() }
1137 separate_provide_extern
1139 query impl_parent(def_id: DefId) -> Option<DefId> {
1140 desc { |tcx| "computing specialization parent impl of `{}`", tcx.def_path_str(def_id) }
1141 cache_on_disk_if { def_id.is_local() }
1142 separate_provide_extern
1145 /// Given an `associated_item`, find the trait it belongs to.
1146 /// Return `None` if the `DefId` is not an associated item.
1147 query trait_of_item(associated_item: DefId) -> Option<DefId> {
1148 desc { |tcx| "finding trait defining `{}`", tcx.def_path_str(associated_item) }
1149 cache_on_disk_if { associated_item.is_local() }
1150 separate_provide_extern
1153 query is_ctfe_mir_available(key: DefId) -> bool {
1154 desc { |tcx| "checking if item has ctfe mir available: `{}`", tcx.def_path_str(key) }
1155 cache_on_disk_if { key.is_local() }
1156 separate_provide_extern
1158 query is_mir_available(key: DefId) -> bool {
1159 desc { |tcx| "checking if item has mir available: `{}`", tcx.def_path_str(key) }
1160 cache_on_disk_if { key.is_local() }
1161 separate_provide_extern
1164 query own_existential_vtable_entries(
1165 key: ty::PolyExistentialTraitRef<'tcx>
1166 ) -> &'tcx [DefId] {
1167 desc { |tcx| "finding all existential vtable entries for trait {}", tcx.def_path_str(key.def_id()) }
1170 query vtable_entries(key: ty::PolyTraitRef<'tcx>)
1171 -> &'tcx [ty::VtblEntry<'tcx>] {
1172 desc { |tcx| "finding all vtable entries for trait {}", tcx.def_path_str(key.def_id()) }
1175 query vtable_trait_upcasting_coercion_new_vptr_slot(key: (ty::Ty<'tcx>, ty::Ty<'tcx>)) -> Option<usize> {
1176 desc { |tcx| "finding the slot within vtable for trait object {} vtable ptr during trait upcasting coercion from {} vtable",
1180 query vtable_allocation(key: (Ty<'tcx>, Option<ty::PolyExistentialTraitRef<'tcx>>)) -> mir::interpret::AllocId {
1181 desc { |tcx| "vtable const allocation for <{} as {}>",
1183 key.1.map(|trait_ref| format!("{}", trait_ref)).unwrap_or("_".to_owned())
1187 query codegen_fulfill_obligation(
1188 key: (ty::ParamEnv<'tcx>, ty::PolyTraitRef<'tcx>)
1189 ) -> Result<&'tcx ImplSource<'tcx, ()>, traits::CodegenObligationError> {
1190 cache_on_disk_if { true }
1192 "checking if `{}` fulfills its obligations",
1193 tcx.def_path_str(key.1.def_id())
1197 /// Return all `impl` blocks in the current crate.
1198 query all_local_trait_impls(_: ()) -> &'tcx rustc_data_structures::fx::FxIndexMap<DefId, Vec<LocalDefId>> {
1199 desc { "local trait impls" }
1202 /// Given a trait `trait_id`, return all known `impl` blocks.
1203 query trait_impls_of(trait_id: DefId) -> ty::trait_def::TraitImpls {
1204 storage(ArenaCacheSelector<'tcx>)
1205 desc { |tcx| "trait impls of `{}`", tcx.def_path_str(trait_id) }
1208 query specialization_graph_of(trait_id: DefId) -> specialization_graph::Graph {
1209 storage(ArenaCacheSelector<'tcx>)
1210 desc { |tcx| "building specialization graph of trait `{}`", tcx.def_path_str(trait_id) }
1211 cache_on_disk_if { true }
1213 query object_safety_violations(trait_id: DefId) -> &'tcx [traits::ObjectSafetyViolation] {
1214 desc { |tcx| "determine object safety of trait `{}`", tcx.def_path_str(trait_id) }
1217 /// Gets the ParameterEnvironment for a given item; this environment
1218 /// will be in "user-facing" mode, meaning that it is suitable for
1219 /// type-checking etc, and it does not normalize specializable
1220 /// associated types. This is almost always what you want,
1221 /// unless you are doing MIR optimizations, in which case you
1222 /// might want to use `reveal_all()` method to change modes.
1223 query param_env(def_id: DefId) -> ty::ParamEnv<'tcx> {
1224 desc { |tcx| "computing normalized predicates of `{}`", tcx.def_path_str(def_id) }
1227 /// Like `param_env`, but returns the `ParamEnv` in `Reveal::All` mode.
1228 /// Prefer this over `tcx.param_env(def_id).with_reveal_all_normalized(tcx)`,
1229 /// as this method is more efficient.
1230 query param_env_reveal_all_normalized(def_id: DefId) -> ty::ParamEnv<'tcx> {
1231 desc { |tcx| "computing revealed normalized predicates of `{}`", tcx.def_path_str(def_id) }
1234 /// Trait selection queries. These are best used by invoking `ty.is_copy_modulo_regions()`,
1235 /// `ty.is_copy()`, etc, since that will prune the environment where possible.
1236 query is_copy_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1237 desc { "computing whether `{}` is `Copy`", env.value }
1240 /// Query backing `Ty::is_sized`.
1241 query is_sized_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1242 desc { "computing whether `{}` is `Sized`", env.value }
1245 /// Query backing `Ty::is_freeze`.
1246 query is_freeze_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1247 desc { "computing whether `{}` is freeze", env.value }
1250 /// Query backing `Ty::is_unpin`.
1251 query is_unpin_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1252 desc { "computing whether `{}` is `Unpin`", env.value }
1255 /// Query backing `Ty::needs_drop`.
1256 query needs_drop_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1257 desc { "computing whether `{}` needs drop", env.value }
1260 /// Query backing `Ty::has_significant_drop_raw`.
1261 query has_significant_drop_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1262 desc { "computing whether `{}` has a significant drop", env.value }
1266 /// Query backing `Ty::is_structural_eq_shallow`.
1268 /// This is only correct for ADTs. Call `is_structural_eq_shallow` to handle all types
1270 query has_structural_eq_impls(ty: Ty<'tcx>) -> bool {
1272 "computing whether `{:?}` implements `PartialStructuralEq` and `StructuralEq`",
1277 /// A list of types where the ADT requires drop if and only if any of
1278 /// those types require drop. If the ADT is known to always need drop
1279 /// then `Err(AlwaysRequiresDrop)` is returned.
1280 query adt_drop_tys(def_id: DefId) -> Result<&'tcx ty::List<Ty<'tcx>>, AlwaysRequiresDrop> {
1281 desc { |tcx| "computing when `{}` needs drop", tcx.def_path_str(def_id) }
1282 cache_on_disk_if { true }
1285 /// A list of types where the ADT requires drop if and only if any of those types
1286 /// has significant drop. A type marked with the attribute `rustc_insignificant_dtor`
1287 /// is considered to not be significant. A drop is significant if it is implemented
1288 /// by the user or does anything that will have any observable behavior (other than
1289 /// freeing up memory). If the ADT is known to have a significant destructor then
1290 /// `Err(AlwaysRequiresDrop)` is returned.
1291 query adt_significant_drop_tys(def_id: DefId) -> Result<&'tcx ty::List<Ty<'tcx>>, AlwaysRequiresDrop> {
1292 desc { |tcx| "computing when `{}` has a significant destructor", tcx.def_path_str(def_id) }
1293 cache_on_disk_if { false }
1296 /// Computes the layout of a type. Note that this implicitly
1297 /// executes in "reveal all" mode, and will normalize the input type.
1299 key: ty::ParamEnvAnd<'tcx, Ty<'tcx>>
1300 ) -> Result<ty::layout::TyAndLayout<'tcx>, ty::layout::LayoutError<'tcx>> {
1301 desc { "computing layout of `{}`", key.value }
1305 /// Compute a `FnAbi` suitable for indirect calls, i.e. to `fn` pointers.
1307 /// NB: this doesn't handle virtual calls - those should use `fn_abi_of_instance`
1308 /// instead, where the instance is an `InstanceDef::Virtual`.
1309 query fn_abi_of_fn_ptr(
1310 key: ty::ParamEnvAnd<'tcx, (ty::PolyFnSig<'tcx>, &'tcx ty::List<Ty<'tcx>>)>
1311 ) -> Result<&'tcx abi::call::FnAbi<'tcx, Ty<'tcx>>, ty::layout::FnAbiError<'tcx>> {
1312 desc { "computing call ABI of `{}` function pointers", key.value.0 }
1316 /// Compute a `FnAbi` suitable for declaring/defining an `fn` instance, and for
1317 /// direct calls to an `fn`.
1319 /// NB: that includes virtual calls, which are represented by "direct calls"
1320 /// to an `InstanceDef::Virtual` instance (of `<dyn Trait as Trait>::fn`).
1321 query fn_abi_of_instance(
1322 key: ty::ParamEnvAnd<'tcx, (ty::Instance<'tcx>, &'tcx ty::List<Ty<'tcx>>)>
1323 ) -> Result<&'tcx abi::call::FnAbi<'tcx, Ty<'tcx>>, ty::layout::FnAbiError<'tcx>> {
1324 desc { "computing call ABI of `{}`", key.value.0 }
1328 query dylib_dependency_formats(_: CrateNum)
1329 -> &'tcx [(CrateNum, LinkagePreference)] {
1330 desc { "dylib dependency formats of crate" }
1331 separate_provide_extern
1334 query dependency_formats(_: ()) -> Lrc<crate::middle::dependency_format::Dependencies> {
1335 storage(ArenaCacheSelector<'tcx>)
1336 desc { "get the linkage format of all dependencies" }
1339 query is_compiler_builtins(_: CrateNum) -> bool {
1341 desc { "checking if the crate is_compiler_builtins" }
1342 separate_provide_extern
1344 query has_global_allocator(_: CrateNum) -> bool {
1345 // This query depends on untracked global state in CStore
1348 desc { "checking if the crate has_global_allocator" }
1349 separate_provide_extern
1351 query has_panic_handler(_: CrateNum) -> bool {
1353 desc { "checking if the crate has_panic_handler" }
1354 separate_provide_extern
1356 query is_profiler_runtime(_: CrateNum) -> bool {
1358 desc { "query a crate is `#![profiler_runtime]`" }
1359 separate_provide_extern
1361 query panic_strategy(_: CrateNum) -> PanicStrategy {
1363 desc { "query a crate's configured panic strategy" }
1364 separate_provide_extern
1366 query panic_in_drop_strategy(_: CrateNum) -> PanicStrategy {
1368 desc { "query a crate's configured panic-in-drop strategy" }
1369 separate_provide_extern
1371 query is_no_builtins(_: CrateNum) -> bool {
1373 desc { "test whether a crate has `#![no_builtins]`" }
1374 separate_provide_extern
1376 query symbol_mangling_version(_: CrateNum) -> SymbolManglingVersion {
1378 desc { "query a crate's symbol mangling version" }
1379 separate_provide_extern
1382 query extern_crate(def_id: DefId) -> Option<&'tcx ExternCrate> {
1384 desc { "getting crate's ExternCrateData" }
1385 separate_provide_extern
1388 query specializes(_: (DefId, DefId)) -> bool {
1389 desc { "computing whether impls specialize one another" }
1391 query in_scope_traits_map(_: LocalDefId)
1392 -> Option<&'tcx FxHashMap<ItemLocalId, Box<[TraitCandidate]>>> {
1393 desc { "traits in scope at a block" }
1396 query module_reexports(def_id: LocalDefId) -> Option<&'tcx [ModChild]> {
1397 desc { |tcx| "looking up reexports of module `{}`", tcx.def_path_str(def_id.to_def_id()) }
1400 query impl_defaultness(def_id: DefId) -> hir::Defaultness {
1401 desc { |tcx| "looking up whether `{}` is a default impl", tcx.def_path_str(def_id) }
1402 cache_on_disk_if { def_id.is_local() }
1403 separate_provide_extern
1406 query check_well_formed(key: LocalDefId) -> () {
1407 desc { |tcx| "checking that `{}` is well-formed", tcx.def_path_str(key.to_def_id()) }
1410 // The `DefId`s of all non-generic functions and statics in the given crate
1411 // that can be reached from outside the crate.
1413 // We expect this items to be available for being linked to.
1415 // This query can also be called for `LOCAL_CRATE`. In this case it will
1416 // compute which items will be reachable to other crates, taking into account
1417 // the kind of crate that is currently compiled. Crates with only a
1418 // C interface have fewer reachable things.
1420 // Does not include external symbols that don't have a corresponding DefId,
1421 // like the compiler-generated `main` function and so on.
1422 query reachable_non_generics(_: CrateNum)
1423 -> DefIdMap<SymbolExportInfo> {
1424 storage(ArenaCacheSelector<'tcx>)
1425 desc { "looking up the exported symbols of a crate" }
1426 separate_provide_extern
1428 query is_reachable_non_generic(def_id: DefId) -> bool {
1429 desc { |tcx| "checking whether `{}` is an exported symbol", tcx.def_path_str(def_id) }
1430 cache_on_disk_if { def_id.is_local() }
1431 separate_provide_extern
1433 query is_unreachable_local_definition(def_id: LocalDefId) -> bool {
1435 "checking whether `{}` is reachable from outside the crate",
1436 tcx.def_path_str(def_id.to_def_id()),
1440 /// The entire set of monomorphizations the local crate can safely link
1441 /// to because they are exported from upstream crates. Do not depend on
1442 /// this directly, as its value changes anytime a monomorphization gets
1443 /// added or removed in any upstream crate. Instead use the narrower
1444 /// `upstream_monomorphizations_for`, `upstream_drop_glue_for`, or, even
1445 /// better, `Instance::upstream_monomorphization()`.
1446 query upstream_monomorphizations(_: ()) -> DefIdMap<FxHashMap<SubstsRef<'tcx>, CrateNum>> {
1447 storage(ArenaCacheSelector<'tcx>)
1448 desc { "collecting available upstream monomorphizations" }
1451 /// Returns the set of upstream monomorphizations available for the
1452 /// generic function identified by the given `def_id`. The query makes
1453 /// sure to make a stable selection if the same monomorphization is
1454 /// available in multiple upstream crates.
1456 /// You likely want to call `Instance::upstream_monomorphization()`
1457 /// instead of invoking this query directly.
1458 query upstream_monomorphizations_for(def_id: DefId)
1459 -> Option<&'tcx FxHashMap<SubstsRef<'tcx>, CrateNum>>
1461 storage(ArenaCacheSelector<'tcx>)
1463 "collecting available upstream monomorphizations for `{}`",
1464 tcx.def_path_str(def_id),
1466 separate_provide_extern
1469 /// Returns the upstream crate that exports drop-glue for the given
1470 /// type (`substs` is expected to be a single-item list containing the
1471 /// type one wants drop-glue for).
1473 /// This is a subset of `upstream_monomorphizations_for` in order to
1474 /// increase dep-tracking granularity. Otherwise adding or removing any
1475 /// type with drop-glue in any upstream crate would invalidate all
1476 /// functions calling drop-glue of an upstream type.
1478 /// You likely want to call `Instance::upstream_monomorphization()`
1479 /// instead of invoking this query directly.
1481 /// NOTE: This query could easily be extended to also support other
1482 /// common functions that have are large set of monomorphizations
1483 /// (like `Clone::clone` for example).
1484 query upstream_drop_glue_for(substs: SubstsRef<'tcx>) -> Option<CrateNum> {
1485 desc { "available upstream drop-glue for `{:?}`", substs }
1488 query foreign_modules(_: CrateNum) -> FxHashMap<DefId, ForeignModule> {
1489 storage(ArenaCacheSelector<'tcx>)
1490 desc { "looking up the foreign modules of a linked crate" }
1491 separate_provide_extern
1494 /// Identifies the entry-point (e.g., the `main` function) for a given
1495 /// crate, returning `None` if there is no entry point (such as for library crates).
1496 query entry_fn(_: ()) -> Option<(DefId, EntryFnType)> {
1497 desc { "looking up the entry function of a crate" }
1499 query proc_macro_decls_static(_: ()) -> Option<LocalDefId> {
1500 desc { "looking up the derive registrar for a crate" }
1502 // The macro which defines `rustc_metadata::provide_extern` depends on this query's name.
1503 // Changing the name should cause a compiler error, but in case that changes, be aware.
1504 query crate_hash(_: CrateNum) -> Svh {
1506 desc { "looking up the hash a crate" }
1507 separate_provide_extern
1509 query crate_host_hash(_: CrateNum) -> Option<Svh> {
1511 desc { "looking up the hash of a host version of a crate" }
1512 separate_provide_extern
1514 query extra_filename(_: CrateNum) -> String {
1515 storage(ArenaCacheSelector<'tcx>)
1517 desc { "looking up the extra filename for a crate" }
1518 separate_provide_extern
1520 query crate_extern_paths(_: CrateNum) -> Vec<PathBuf> {
1521 storage(ArenaCacheSelector<'tcx>)
1523 desc { "looking up the paths for extern crates" }
1524 separate_provide_extern
1527 /// Given a crate and a trait, look up all impls of that trait in the crate.
1528 /// Return `(impl_id, self_ty)`.
1529 query implementations_of_trait(_: (CrateNum, DefId)) -> &'tcx [(DefId, Option<SimplifiedType>)] {
1530 desc { "looking up implementations of a trait in a crate" }
1531 separate_provide_extern
1534 /// Collects all incoherent impls for the given crate and type.
1536 /// Do not call this directly, but instead use the `incoherent_impls` query.
1537 /// This query is only used to get the data necessary for that query.
1538 query crate_incoherent_impls(key: (CrateNum, SimplifiedType)) -> &'tcx [DefId] {
1539 desc { |tcx| "collecting all impls for a type in a crate" }
1540 separate_provide_extern
1543 query is_dllimport_foreign_item(def_id: DefId) -> bool {
1544 desc { |tcx| "is_dllimport_foreign_item({})", tcx.def_path_str(def_id) }
1546 query is_statically_included_foreign_item(def_id: DefId) -> bool {
1547 desc { |tcx| "is_statically_included_foreign_item({})", tcx.def_path_str(def_id) }
1549 query native_library_kind(def_id: DefId)
1550 -> Option<NativeLibKind> {
1551 desc { |tcx| "native_library_kind({})", tcx.def_path_str(def_id) }
1554 /// Does lifetime resolution, but does not descend into trait items. This
1555 /// should only be used for resolving lifetimes of on trait definitions,
1556 /// and is used to avoid cycles. Importantly, `resolve_lifetimes` still visits
1557 /// the same lifetimes and is responsible for diagnostics.
1558 /// See `rustc_resolve::late::lifetimes for details.
1559 query resolve_lifetimes_trait_definition(_: LocalDefId) -> ResolveLifetimes {
1560 storage(ArenaCacheSelector<'tcx>)
1561 desc { "resolving lifetimes for a trait definition" }
1563 /// Does lifetime resolution on items. Importantly, we can't resolve
1564 /// lifetimes directly on things like trait methods, because of trait params.
1565 /// See `rustc_resolve::late::lifetimes for details.
1566 query resolve_lifetimes(_: LocalDefId) -> ResolveLifetimes {
1567 storage(ArenaCacheSelector<'tcx>)
1568 desc { "resolving lifetimes" }
1570 query named_region_map(_: LocalDefId) ->
1571 Option<&'tcx FxHashMap<ItemLocalId, Region>> {
1572 desc { "looking up a named region" }
1574 query is_late_bound_map(_: LocalDefId) -> Option<&'tcx FxHashSet<LocalDefId>> {
1575 desc { "testing if a region is late bound" }
1577 /// For a given item (like a struct), gets the default lifetimes to be used
1578 /// for each parameter if a trait object were to be passed for that parameter.
1579 /// For example, for `struct Foo<'a, T, U>`, this would be `['static, 'static]`.
1580 /// For `struct Foo<'a, T: 'a, U>`, this would instead be `['a, 'static]`.
1581 query object_lifetime_defaults(_: LocalDefId) -> Option<&'tcx [ObjectLifetimeDefault]> {
1582 desc { "looking up lifetime defaults for a region on an item" }
1584 query late_bound_vars_map(_: LocalDefId)
1585 -> Option<&'tcx FxHashMap<ItemLocalId, Vec<ty::BoundVariableKind>>> {
1586 desc { "looking up late bound vars" }
1589 query visibility(def_id: DefId) -> ty::Visibility {
1590 desc { |tcx| "computing visibility of `{}`", tcx.def_path_str(def_id) }
1591 separate_provide_extern
1594 /// Computes the set of modules from which this type is visibly uninhabited.
1595 /// To check whether a type is uninhabited at all (not just from a given module), you could
1596 /// check whether the forest is empty.
1597 query type_uninhabited_from(
1598 key: ty::ParamEnvAnd<'tcx, Ty<'tcx>>
1599 ) -> ty::inhabitedness::DefIdForest<'tcx> {
1600 desc { "computing the inhabitedness of `{:?}`", key }
1604 query dep_kind(_: CrateNum) -> CrateDepKind {
1606 desc { "fetching what a dependency looks like" }
1607 separate_provide_extern
1610 /// Gets the name of the crate.
1611 query crate_name(_: CrateNum) -> Symbol {
1613 desc { "fetching what a crate is named" }
1614 separate_provide_extern
1616 query module_children(def_id: DefId) -> &'tcx [ModChild] {
1617 desc { |tcx| "collecting child items of module `{}`", tcx.def_path_str(def_id) }
1618 separate_provide_extern
1620 query extern_mod_stmt_cnum(def_id: LocalDefId) -> Option<CrateNum> {
1621 desc { |tcx| "computing crate imported by `{}`", tcx.def_path_str(def_id.to_def_id()) }
1624 query lib_features(_: ()) -> LibFeatures {
1625 storage(ArenaCacheSelector<'tcx>)
1626 desc { "calculating the lib features map" }
1628 query defined_lib_features(_: CrateNum)
1629 -> &'tcx [(Symbol, Option<Symbol>)] {
1630 desc { "calculating the lib features defined in a crate" }
1631 separate_provide_extern
1633 /// Whether the function is an intrinsic
1634 query is_intrinsic(def_id: DefId) -> bool {
1635 desc { |tcx| "is_intrinsic({})", tcx.def_path_str(def_id) }
1636 separate_provide_extern
1638 /// Returns the lang items defined in another crate by loading it from metadata.
1639 query get_lang_items(_: ()) -> LanguageItems {
1640 storage(ArenaCacheSelector<'tcx>)
1642 desc { "calculating the lang items map" }
1645 /// Returns all diagnostic items defined in all crates.
1646 query all_diagnostic_items(_: ()) -> rustc_hir::diagnostic_items::DiagnosticItems {
1647 storage(ArenaCacheSelector<'tcx>)
1649 desc { "calculating the diagnostic items map" }
1652 /// Returns the lang items defined in another crate by loading it from metadata.
1653 query defined_lang_items(_: CrateNum) -> &'tcx [(DefId, usize)] {
1654 desc { "calculating the lang items defined in a crate" }
1655 separate_provide_extern
1658 /// Returns the diagnostic items defined in a crate.
1659 query diagnostic_items(_: CrateNum) -> rustc_hir::diagnostic_items::DiagnosticItems {
1660 storage(ArenaCacheSelector<'tcx>)
1661 desc { "calculating the diagnostic items map in a crate" }
1662 separate_provide_extern
1665 query missing_lang_items(_: CrateNum) -> &'tcx [LangItem] {
1666 desc { "calculating the missing lang items in a crate" }
1667 separate_provide_extern
1669 query visible_parent_map(_: ()) -> DefIdMap<DefId> {
1670 storage(ArenaCacheSelector<'tcx>)
1671 desc { "calculating the visible parent map" }
1673 query trimmed_def_paths(_: ()) -> FxHashMap<DefId, Symbol> {
1674 storage(ArenaCacheSelector<'tcx>)
1675 desc { "calculating trimmed def paths" }
1677 query missing_extern_crate_item(_: CrateNum) -> bool {
1679 desc { "seeing if we're missing an `extern crate` item for this crate" }
1680 separate_provide_extern
1682 query used_crate_source(_: CrateNum) -> Lrc<CrateSource> {
1683 storage(ArenaCacheSelector<'tcx>)
1685 desc { "looking at the source for a crate" }
1686 separate_provide_extern
1688 /// Returns the debugger visualizers defined for this crate.
1689 query debugger_visualizers(_: CrateNum) -> Vec<rustc_span::DebuggerVisualizerFile> {
1690 storage(ArenaCacheSelector<'tcx>)
1691 desc { "looking up the debugger visualizers for this crate" }
1692 separate_provide_extern
1694 query postorder_cnums(_: ()) -> &'tcx [CrateNum] {
1696 desc { "generating a postorder list of CrateNums" }
1698 /// Returns whether or not the crate with CrateNum 'cnum'
1699 /// is marked as a private dependency
1700 query is_private_dep(c: CrateNum) -> bool {
1702 desc { "check whether crate {} is a private dependency", c }
1703 separate_provide_extern
1705 query allocator_kind(_: ()) -> Option<AllocatorKind> {
1707 desc { "allocator kind for the current crate" }
1710 query upvars_mentioned(def_id: DefId) -> Option<&'tcx FxIndexMap<hir::HirId, hir::Upvar>> {
1711 desc { |tcx| "collecting upvars mentioned in `{}`", tcx.def_path_str(def_id) }
1713 query maybe_unused_trait_imports(_: ()) -> &'tcx FxIndexSet<LocalDefId> {
1714 desc { "fetching potentially unused trait imports" }
1716 query maybe_unused_extern_crates(_: ()) -> &'tcx [(LocalDefId, Span)] {
1717 desc { "looking up all possibly unused extern crates" }
1719 query names_imported_by_glob_use(def_id: LocalDefId) -> &'tcx FxHashSet<Symbol> {
1720 desc { |tcx| "names_imported_by_glob_use for `{}`", tcx.def_path_str(def_id.to_def_id()) }
1723 query stability_index(_: ()) -> stability::Index {
1724 storage(ArenaCacheSelector<'tcx>)
1726 desc { "calculating the stability index for the local crate" }
1728 query crates(_: ()) -> &'tcx [CrateNum] {
1730 desc { "fetching all foreign CrateNum instances" }
1733 /// A list of all traits in a crate, used by rustdoc and error reporting.
1734 /// NOTE: Not named just `traits` due to a naming conflict.
1735 query traits_in_crate(_: CrateNum) -> &'tcx [DefId] {
1736 desc { "fetching all traits in a crate" }
1737 separate_provide_extern
1740 /// The list of symbols exported from the given crate.
1742 /// - All names contained in `exported_symbols(cnum)` are guaranteed to
1743 /// correspond to a publicly visible symbol in `cnum` machine code.
1744 /// - The `exported_symbols` sets of different crates do not intersect.
1745 query exported_symbols(cnum: CrateNum) -> &'tcx [(ExportedSymbol<'tcx>, SymbolExportInfo)] {
1746 desc { "exported_symbols" }
1747 cache_on_disk_if { *cnum == LOCAL_CRATE }
1748 separate_provide_extern
1751 query collect_and_partition_mono_items(_: ()) -> (&'tcx DefIdSet, &'tcx [CodegenUnit<'tcx>]) {
1753 desc { "collect_and_partition_mono_items" }
1755 query is_codegened_item(def_id: DefId) -> bool {
1756 desc { |tcx| "determining whether `{}` needs codegen", tcx.def_path_str(def_id) }
1759 /// All items participating in code generation together with items inlined into them.
1760 query codegened_and_inlined_items(_: ()) -> &'tcx DefIdSet {
1762 desc { "codegened_and_inlined_items" }
1765 query codegen_unit(_: Symbol) -> &'tcx CodegenUnit<'tcx> {
1766 desc { "codegen_unit" }
1768 query unused_generic_params(key: ty::InstanceDef<'tcx>) -> FiniteBitSet<u32> {
1769 cache_on_disk_if { key.def_id().is_local() }
1771 |tcx| "determining which generic parameters are unused by `{}`",
1772 tcx.def_path_str(key.def_id())
1774 separate_provide_extern
1776 query backend_optimization_level(_: ()) -> OptLevel {
1777 desc { "optimization level used by backend" }
1780 /// Return the filenames where output artefacts shall be stored.
1782 /// This query returns an `&Arc` because codegen backends need the value even after the `TyCtxt`
1783 /// has been destroyed.
1784 query output_filenames(_: ()) -> &'tcx Arc<OutputFilenames> {
1786 desc { "output_filenames" }
1789 /// Do not call this query directly: invoke `normalize` instead.
1790 query normalize_projection_ty(
1791 goal: CanonicalProjectionGoal<'tcx>
1793 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, NormalizationResult<'tcx>>>,
1796 desc { "normalizing `{:?}`", goal }
1800 /// Do not call this query directly: invoke `try_normalize_erasing_regions` instead.
1801 query try_normalize_generic_arg_after_erasing_regions(
1802 goal: ParamEnvAnd<'tcx, GenericArg<'tcx>>
1803 ) -> Result<GenericArg<'tcx>, NoSolution> {
1804 desc { "normalizing `{}`", goal.value }
1808 /// Do not call this query directly: invoke `try_normalize_erasing_regions` instead.
1809 query try_normalize_mir_const_after_erasing_regions(
1810 goal: ParamEnvAnd<'tcx, mir::ConstantKind<'tcx>>
1811 ) -> Result<mir::ConstantKind<'tcx>, NoSolution> {
1812 desc { "normalizing `{}`", goal.value }
1816 query implied_outlives_bounds(
1817 goal: CanonicalTyGoal<'tcx>
1819 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, Vec<OutlivesBound<'tcx>>>>,
1822 desc { "computing implied outlives bounds for `{:?}`", goal }
1826 /// Do not call this query directly: invoke `infcx.at().dropck_outlives()` instead.
1827 query dropck_outlives(
1828 goal: CanonicalTyGoal<'tcx>
1830 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, DropckOutlivesResult<'tcx>>>,
1833 desc { "computing dropck types for `{:?}`", goal }
1837 /// Do not call this query directly: invoke `infcx.predicate_may_hold()` or
1838 /// `infcx.predicate_must_hold()` instead.
1839 query evaluate_obligation(
1840 goal: CanonicalPredicateGoal<'tcx>
1841 ) -> Result<traits::EvaluationResult, traits::OverflowError> {
1842 desc { "evaluating trait selection obligation `{}`", goal.value.value }
1845 query evaluate_goal(
1846 goal: traits::CanonicalChalkEnvironmentAndGoal<'tcx>
1848 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1851 desc { "evaluating trait selection obligation `{}`", goal.value }
1854 /// Do not call this query directly: part of the `Eq` type-op
1855 query type_op_ascribe_user_type(
1856 goal: CanonicalTypeOpAscribeUserTypeGoal<'tcx>
1858 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1861 desc { "evaluating `type_op_ascribe_user_type` `{:?}`", goal }
1865 /// Do not call this query directly: part of the `Eq` type-op
1867 goal: CanonicalTypeOpEqGoal<'tcx>
1869 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1872 desc { "evaluating `type_op_eq` `{:?}`", goal }
1876 /// Do not call this query directly: part of the `Subtype` type-op
1877 query type_op_subtype(
1878 goal: CanonicalTypeOpSubtypeGoal<'tcx>
1880 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1883 desc { "evaluating `type_op_subtype` `{:?}`", goal }
1887 /// Do not call this query directly: part of the `ProvePredicate` type-op
1888 query type_op_prove_predicate(
1889 goal: CanonicalTypeOpProvePredicateGoal<'tcx>
1891 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1894 desc { "evaluating `type_op_prove_predicate` `{:?}`", goal }
1897 /// Do not call this query directly: part of the `Normalize` type-op
1898 query type_op_normalize_ty(
1899 goal: CanonicalTypeOpNormalizeGoal<'tcx, Ty<'tcx>>
1901 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, Ty<'tcx>>>,
1904 desc { "normalizing `{:?}`", goal }
1908 /// Do not call this query directly: part of the `Normalize` type-op
1909 query type_op_normalize_predicate(
1910 goal: CanonicalTypeOpNormalizeGoal<'tcx, ty::Predicate<'tcx>>
1912 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ty::Predicate<'tcx>>>,
1915 desc { "normalizing `{:?}`", goal }
1919 /// Do not call this query directly: part of the `Normalize` type-op
1920 query type_op_normalize_poly_fn_sig(
1921 goal: CanonicalTypeOpNormalizeGoal<'tcx, ty::PolyFnSig<'tcx>>
1923 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ty::PolyFnSig<'tcx>>>,
1926 desc { "normalizing `{:?}`", goal }
1930 /// Do not call this query directly: part of the `Normalize` type-op
1931 query type_op_normalize_fn_sig(
1932 goal: CanonicalTypeOpNormalizeGoal<'tcx, ty::FnSig<'tcx>>
1934 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ty::FnSig<'tcx>>>,
1937 desc { "normalizing `{:?}`", goal }
1941 query subst_and_check_impossible_predicates(key: (DefId, SubstsRef<'tcx>)) -> bool {
1943 "impossible substituted predicates:`{}`",
1944 tcx.def_path_str(key.0)
1948 query method_autoderef_steps(
1949 goal: CanonicalTyGoal<'tcx>
1950 ) -> MethodAutoderefStepsResult<'tcx> {
1951 desc { "computing autoderef types for `{:?}`", goal }
1955 query supported_target_features(_: CrateNum) -> FxHashMap<String, Option<Symbol>> {
1956 storage(ArenaCacheSelector<'tcx>)
1958 desc { "looking up supported target features" }
1961 /// Get an estimate of the size of an InstanceDef based on its MIR for CGU partitioning.
1962 query instance_def_size_estimate(def: ty::InstanceDef<'tcx>)
1964 desc { |tcx| "estimating size for `{}`", tcx.def_path_str(def.def_id()) }
1967 query features_query(_: ()) -> &'tcx rustc_feature::Features {
1969 desc { "looking up enabled feature gates" }
1972 /// Attempt to resolve the given `DefId` to an `Instance`, for the
1973 /// given generics args (`SubstsRef`), returning one of:
1974 /// * `Ok(Some(instance))` on success
1975 /// * `Ok(None)` when the `SubstsRef` are still too generic,
1976 /// and therefore don't allow finding the final `Instance`
1977 /// * `Err(ErrorGuaranteed)` when the `Instance` resolution process
1978 /// couldn't complete due to errors elsewhere - this is distinct
1979 /// from `Ok(None)` to avoid misleading diagnostics when an error
1980 /// has already been/will be emitted, for the original cause
1981 query resolve_instance(
1982 key: ty::ParamEnvAnd<'tcx, (DefId, SubstsRef<'tcx>)>
1983 ) -> Result<Option<ty::Instance<'tcx>>, ErrorGuaranteed> {
1984 desc { "resolving instance `{}`", ty::Instance::new(key.value.0, key.value.1) }
1988 query resolve_instance_of_const_arg(
1989 key: ty::ParamEnvAnd<'tcx, (LocalDefId, DefId, SubstsRef<'tcx>)>
1990 ) -> Result<Option<ty::Instance<'tcx>>, ErrorGuaranteed> {
1992 "resolving instance of the const argument `{}`",
1993 ty::Instance::new(key.value.0.to_def_id(), key.value.2),
1998 query normalize_opaque_types(key: &'tcx ty::List<ty::Predicate<'tcx>>) -> &'tcx ty::List<ty::Predicate<'tcx>> {
1999 desc { "normalizing opaque types in {:?}", key }
2002 /// Checks whether a type is definitely uninhabited. This is
2003 /// conservative: for some types that are uninhabited we return `false`,
2004 /// but we only return `true` for types that are definitely uninhabited.
2005 /// `ty.conservative_is_privately_uninhabited` implies that any value of type `ty`
2006 /// will be `Abi::Uninhabited`. (Note that uninhabited types may have nonzero
2007 /// size, to account for partial initialisation. See #49298 for details.)
2008 query conservative_is_privately_uninhabited(key: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
2009 desc { "conservatively checking if {:?} is privately uninhabited", key }
2013 query limits(key: ()) -> Limits {
2014 desc { "looking up limits" }
2017 /// Performs an HIR-based well-formed check on the item with the given `HirId`. If
2018 /// we get an `Unimplemented` error that matches the provided `Predicate`, return
2019 /// the cause of the newly created obligation.
2021 /// This is only used by error-reporting code to get a better cause (in particular, a better
2022 /// span) for an *existing* error. Therefore, it is best-effort, and may never handle
2023 /// all of the cases that the normal `ty::Ty`-based wfcheck does. This is fine,
2024 /// because the `ty::Ty`-based wfcheck is always run.
2025 query diagnostic_hir_wf_check(key: (ty::Predicate<'tcx>, traits::WellFormedLoc)) -> Option<traits::ObligationCause<'tcx>> {
2026 storage(ArenaCacheSelector<'tcx>)
2029 desc { "performing HIR wf-checking for predicate {:?} at item {:?}", key.0, key.1 }
2033 /// The list of backend features computed from CLI flags (`-Ctarget-cpu`, `-Ctarget-feature`,
2034 /// `--target` and similar).
2035 query global_backend_features(_: ()) -> Vec<String> {
2036 storage(ArenaCacheSelector<'tcx>)
2038 desc { "computing the backend features for CLI flags" }
2041 query generator_diagnostic_data(key: DefId) -> Option<GeneratorDiagnosticData<'tcx>> {
2042 storage(ArenaCacheSelector<'tcx>)
2043 desc { |tcx| "looking up generator diagnostic data of `{}`", tcx.def_path_str(key) }
2044 separate_provide_extern