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 // This query reads from untracked data in definitions.
276 desc { |tcx| "expansion that defined `{}`", tcx.def_path_str(key) }
277 separate_provide_extern
280 query is_panic_runtime(_: CrateNum) -> bool {
282 desc { "checking if the crate is_panic_runtime" }
283 separate_provide_extern
286 /// Fetch the THIR for a given body. If typeck for that body failed, returns an empty `Thir`.
287 query thir_body(key: ty::WithOptConstParam<LocalDefId>)
288 -> Result<(&'tcx Steal<thir::Thir<'tcx>>, thir::ExprId), ErrorGuaranteed>
290 // Perf tests revealed that hashing THIR is inefficient (see #85729).
292 desc { |tcx| "building THIR for `{}`", tcx.def_path_str(key.did.to_def_id()) }
295 /// Create a THIR tree for debugging.
296 query thir_tree(key: ty::WithOptConstParam<LocalDefId>) -> String {
298 storage(ArenaCacheSelector<'tcx>)
299 desc { |tcx| "constructing THIR tree for `{}`", tcx.def_path_str(key.did.to_def_id()) }
302 /// Set of all the `DefId`s in this crate that have MIR associated with
303 /// them. This includes all the body owners, but also things like struct
305 query mir_keys(_: ()) -> rustc_data_structures::fx::FxIndexSet<LocalDefId> {
306 storage(ArenaCacheSelector<'tcx>)
307 desc { "getting a list of all mir_keys" }
310 /// Maps DefId's that have an associated `mir::Body` to the result
311 /// of the MIR const-checking pass. This is the set of qualifs in
312 /// the final value of a `const`.
313 query mir_const_qualif(key: DefId) -> mir::ConstQualifs {
314 desc { |tcx| "const checking `{}`", tcx.def_path_str(key) }
315 cache_on_disk_if { key.is_local() }
316 separate_provide_extern
318 query mir_const_qualif_const_arg(
319 key: (LocalDefId, DefId)
320 ) -> mir::ConstQualifs {
322 |tcx| "const checking the const argument `{}`",
323 tcx.def_path_str(key.0.to_def_id())
327 /// Fetch the MIR for a given `DefId` right after it's built - this includes
328 /// unreachable code.
329 query mir_built(key: ty::WithOptConstParam<LocalDefId>) -> &'tcx Steal<mir::Body<'tcx>> {
330 desc { |tcx| "building MIR for `{}`", tcx.def_path_str(key.did.to_def_id()) }
333 /// Fetch the MIR for a given `DefId` up till the point where it is
334 /// ready for const qualification.
336 /// See the README for the `mir` module for details.
337 query mir_const(key: ty::WithOptConstParam<LocalDefId>) -> &'tcx Steal<mir::Body<'tcx>> {
339 |tcx| "processing MIR for {}`{}`",
340 if key.const_param_did.is_some() { "the const argument " } else { "" },
341 tcx.def_path_str(key.did.to_def_id()),
346 /// Try to build an abstract representation of the given constant.
347 query thir_abstract_const(
349 ) -> Result<Option<&'tcx [thir::abstract_const::Node<'tcx>]>, ErrorGuaranteed> {
351 |tcx| "building an abstract representation for {}", tcx.def_path_str(key),
353 separate_provide_extern
355 /// Try to build an abstract representation of the given constant.
356 query thir_abstract_const_of_const_arg(
357 key: (LocalDefId, DefId)
358 ) -> Result<Option<&'tcx [thir::abstract_const::Node<'tcx>]>, ErrorGuaranteed> {
361 "building an abstract representation for the const argument {}",
362 tcx.def_path_str(key.0.to_def_id()),
366 query try_unify_abstract_consts(key:
367 ty::ParamEnvAnd<'tcx, (ty::Unevaluated<'tcx, ()>, ty::Unevaluated<'tcx, ()>
370 |tcx| "trying to unify the generic constants {} and {}",
371 tcx.def_path_str(key.value.0.def.did), tcx.def_path_str(key.value.1.def.did)
375 query mir_drops_elaborated_and_const_checked(
376 key: ty::WithOptConstParam<LocalDefId>
377 ) -> &'tcx Steal<mir::Body<'tcx>> {
379 desc { |tcx| "elaborating drops for `{}`", tcx.def_path_str(key.did.to_def_id()) }
384 ) -> &'tcx mir::Body<'tcx> {
385 desc { |tcx| "caching mir of `{}` for CTFE", tcx.def_path_str(key) }
386 cache_on_disk_if { key.is_local() }
387 separate_provide_extern
390 query mir_for_ctfe_of_const_arg(key: (LocalDefId, DefId)) -> &'tcx mir::Body<'tcx> {
392 |tcx| "MIR for CTFE of the const argument `{}`",
393 tcx.def_path_str(key.0.to_def_id())
397 query mir_promoted(key: ty::WithOptConstParam<LocalDefId>) ->
399 &'tcx Steal<mir::Body<'tcx>>,
400 &'tcx Steal<IndexVec<mir::Promoted, mir::Body<'tcx>>>
404 |tcx| "processing {}`{}`",
405 if key.const_param_did.is_some() { "the const argument " } else { "" },
406 tcx.def_path_str(key.did.to_def_id()),
410 query symbols_for_closure_captures(
411 key: (LocalDefId, DefId)
412 ) -> Vec<rustc_span::Symbol> {
413 storage(ArenaCacheSelector<'tcx>)
415 |tcx| "symbols for captures of closure `{}` in `{}`",
416 tcx.def_path_str(key.1),
417 tcx.def_path_str(key.0.to_def_id())
421 /// MIR after our optimization passes have run. This is MIR that is ready
422 /// for codegen. This is also the only query that can fetch non-local MIR, at present.
423 query optimized_mir(key: DefId) -> &'tcx mir::Body<'tcx> {
424 desc { |tcx| "optimizing MIR for `{}`", tcx.def_path_str(key) }
425 cache_on_disk_if { key.is_local() }
426 separate_provide_extern
429 /// Returns coverage summary info for a function, after executing the `InstrumentCoverage`
430 /// MIR pass (assuming the -Cinstrument-coverage option is enabled).
431 query coverageinfo(key: ty::InstanceDef<'tcx>) -> mir::CoverageInfo {
432 desc { |tcx| "retrieving coverage info from MIR for `{}`", tcx.def_path_str(key.def_id()) }
433 storage(ArenaCacheSelector<'tcx>)
436 /// Returns the `CodeRegions` for a function that has instrumented coverage, in case the
437 /// function was optimized out before codegen, and before being added to the Coverage Map.
438 query covered_code_regions(key: DefId) -> Vec<&'tcx mir::coverage::CodeRegion> {
440 |tcx| "retrieving the covered `CodeRegion`s, if instrumented, for `{}`",
441 tcx.def_path_str(key)
443 storage(ArenaCacheSelector<'tcx>)
444 cache_on_disk_if { key.is_local() }
447 /// The `DefId` is the `DefId` of the containing MIR body. Promoteds do not have their own
448 /// `DefId`. This function returns all promoteds in the specified body. The body references
449 /// promoteds by the `DefId` and the `mir::Promoted` index. This is necessary, because
450 /// after inlining a body may refer to promoteds from other bodies. In that case you still
451 /// need to use the `DefId` of the original body.
452 query promoted_mir(key: DefId) -> &'tcx IndexVec<mir::Promoted, mir::Body<'tcx>> {
453 desc { |tcx| "optimizing promoted MIR for `{}`", tcx.def_path_str(key) }
454 cache_on_disk_if { key.is_local() }
455 separate_provide_extern
457 query promoted_mir_of_const_arg(
458 key: (LocalDefId, DefId)
459 ) -> &'tcx IndexVec<mir::Promoted, mir::Body<'tcx>> {
461 |tcx| "optimizing promoted MIR for the const argument `{}`",
462 tcx.def_path_str(key.0.to_def_id()),
466 /// Erases regions from `ty` to yield a new type.
467 /// Normally you would just use `tcx.erase_regions(value)`,
468 /// however, which uses this query as a kind of cache.
469 query erase_regions_ty(ty: Ty<'tcx>) -> Ty<'tcx> {
470 // This query is not expected to have input -- as a result, it
471 // is not a good candidates for "replay" because it is essentially a
472 // pure function of its input (and hence the expectation is that
473 // no caller would be green **apart** from just these
474 // queries). Making it anonymous avoids hashing the result, which
475 // may save a bit of time.
477 desc { "erasing regions from `{:?}`", ty }
480 query wasm_import_module_map(_: CrateNum) -> FxHashMap<DefId, String> {
481 storage(ArenaCacheSelector<'tcx>)
482 desc { "wasm import module map" }
485 /// Maps from the `DefId` of an item (trait/struct/enum/fn) to the
486 /// predicates (where-clauses) directly defined on it. This is
487 /// equal to the `explicit_predicates_of` predicates plus the
488 /// `inferred_outlives_of` predicates.
489 query predicates_defined_on(key: DefId) -> ty::GenericPredicates<'tcx> {
490 desc { |tcx| "computing predicates of `{}`", tcx.def_path_str(key) }
493 /// Returns everything that looks like a predicate written explicitly
494 /// by the user on a trait item.
496 /// Traits are unusual, because predicates on associated types are
497 /// converted into bounds on that type for backwards compatibility:
499 /// trait X where Self::U: Copy { type U; }
503 /// trait X { type U: Copy; }
505 /// `explicit_predicates_of` and `explicit_item_bounds` will then take
506 /// the appropriate subsets of the predicates here.
507 query trait_explicit_predicates_and_bounds(key: LocalDefId) -> ty::GenericPredicates<'tcx> {
508 desc { |tcx| "computing explicit predicates of trait `{}`", tcx.def_path_str(key.to_def_id()) }
511 /// Returns the predicates written explicitly by the user.
512 query explicit_predicates_of(key: DefId) -> ty::GenericPredicates<'tcx> {
513 desc { |tcx| "computing explicit predicates of `{}`", tcx.def_path_str(key) }
514 cache_on_disk_if { key.is_local() }
515 separate_provide_extern
518 /// Returns the inferred outlives predicates (e.g., for `struct
519 /// Foo<'a, T> { x: &'a T }`, this would return `T: 'a`).
520 query inferred_outlives_of(key: DefId) -> &'tcx [(ty::Predicate<'tcx>, Span)] {
521 desc { |tcx| "computing inferred outlives predicates of `{}`", tcx.def_path_str(key) }
522 cache_on_disk_if { key.is_local() }
523 separate_provide_extern
526 /// Maps from the `DefId` of a trait to the list of
527 /// super-predicates. This is a subset of the full list of
528 /// predicates. We store these in a separate map because we must
529 /// evaluate them even during type conversion, often before the
530 /// full predicates are available (note that supertraits have
531 /// additional acyclicity requirements).
532 query super_predicates_of(key: DefId) -> ty::GenericPredicates<'tcx> {
533 desc { |tcx| "computing the super predicates of `{}`", tcx.def_path_str(key) }
534 cache_on_disk_if { key.is_local() }
535 separate_provide_extern
538 /// The `Option<Ident>` is the name of an associated type. If it is `None`, then this query
539 /// returns the full set of predicates. If `Some<Ident>`, then the query returns only the
540 /// subset of super-predicates that reference traits that define the given associated type.
541 /// This is used to avoid cycles in resolving types like `T::Item`.
542 query super_predicates_that_define_assoc_type(key: (DefId, Option<rustc_span::symbol::Ident>)) -> ty::GenericPredicates<'tcx> {
543 desc { |tcx| "computing the super traits of `{}`{}",
544 tcx.def_path_str(key.0),
545 if let Some(assoc_name) = key.1 { format!(" with associated type name `{}`", assoc_name) } else { "".to_string() },
549 /// To avoid cycles within the predicates of a single item we compute
550 /// per-type-parameter predicates for resolving `T::AssocTy`.
551 query type_param_predicates(key: (DefId, LocalDefId, rustc_span::symbol::Ident)) -> ty::GenericPredicates<'tcx> {
552 desc { |tcx| "computing the bounds for type parameter `{}`", tcx.hir().ty_param_name(key.1) }
555 query trait_def(key: DefId) -> ty::TraitDef {
556 desc { |tcx| "computing trait definition for `{}`", tcx.def_path_str(key) }
557 storage(ArenaCacheSelector<'tcx>)
558 cache_on_disk_if { key.is_local() }
559 separate_provide_extern
561 query adt_def(key: DefId) -> ty::AdtDef<'tcx> {
562 desc { |tcx| "computing ADT definition for `{}`", tcx.def_path_str(key) }
563 cache_on_disk_if { key.is_local() }
564 separate_provide_extern
566 query adt_destructor(key: DefId) -> Option<ty::Destructor> {
567 desc { |tcx| "computing `Drop` impl for `{}`", tcx.def_path_str(key) }
568 cache_on_disk_if { key.is_local() }
569 separate_provide_extern
572 // The cycle error here should be reported as an error by `check_representable`.
573 // We consider the type as Sized in the meanwhile to avoid
574 // further errors (done in impl Value for AdtSizedConstraint).
575 // Use `cycle_delay_bug` to delay the cycle error here to be emitted later
576 // in case we accidentally otherwise don't emit an error.
577 query adt_sized_constraint(
579 ) -> AdtSizedConstraint<'tcx> {
580 desc { |tcx| "computing `Sized` constraints for `{}`", tcx.def_path_str(key) }
584 query adt_dtorck_constraint(
586 ) -> Result<&'tcx DropckConstraint<'tcx>, NoSolution> {
587 desc { |tcx| "computing drop-check constraints for `{}`", tcx.def_path_str(key) }
590 /// Returns `true` if this is a const fn, use the `is_const_fn` to know whether your crate
591 /// actually sees it as const fn (e.g., the const-fn-ness might be unstable and you might
592 /// not have the feature gate active).
594 /// **Do not call this function manually.** It is only meant to cache the base data for the
595 /// `is_const_fn` function.
596 query impl_constness(key: DefId) -> hir::Constness {
597 desc { |tcx| "checking if item is const fn: `{}`", tcx.def_path_str(key) }
598 cache_on_disk_if { key.is_local() }
599 separate_provide_extern
602 query asyncness(key: DefId) -> hir::IsAsync {
603 desc { |tcx| "checking if the function is async: `{}`", tcx.def_path_str(key) }
604 cache_on_disk_if { key.is_local() }
605 separate_provide_extern
608 /// Returns `true` if calls to the function may be promoted.
610 /// This is either because the function is e.g., a tuple-struct or tuple-variant
611 /// constructor, or because it has the `#[rustc_promotable]` attribute. The attribute should
612 /// be removed in the future in favour of some form of check which figures out whether the
613 /// function does not inspect the bits of any of its arguments (so is essentially just a
614 /// constructor function).
615 query is_promotable_const_fn(key: DefId) -> bool {
616 desc { |tcx| "checking if item is promotable: `{}`", tcx.def_path_str(key) }
619 /// Returns `true` if this is a foreign item (i.e., linked via `extern { ... }`).
620 query is_foreign_item(key: DefId) -> bool {
621 desc { |tcx| "checking if `{}` is a foreign item", tcx.def_path_str(key) }
622 cache_on_disk_if { key.is_local() }
623 separate_provide_extern
626 /// Returns `Some(generator_kind)` if the node pointed to by `def_id` is a generator.
627 query generator_kind(def_id: DefId) -> Option<hir::GeneratorKind> {
628 desc { |tcx| "looking up generator kind of `{}`", tcx.def_path_str(def_id) }
629 cache_on_disk_if { def_id.is_local() }
630 separate_provide_extern
633 /// Gets a map with the variance of every item; use `item_variance` instead.
634 query crate_variances(_: ()) -> ty::CrateVariancesMap<'tcx> {
635 storage(ArenaCacheSelector<'tcx>)
636 desc { "computing the variances for items in this crate" }
639 /// Maps from the `DefId` of a type or region parameter to its (inferred) variance.
640 query variances_of(def_id: DefId) -> &'tcx [ty::Variance] {
641 desc { |tcx| "computing the variances of `{}`", tcx.def_path_str(def_id) }
642 cache_on_disk_if { def_id.is_local() }
643 separate_provide_extern
646 /// Maps from thee `DefId` of a type to its (inferred) outlives.
647 query inferred_outlives_crate(_: ()) -> ty::CratePredicatesMap<'tcx> {
648 storage(ArenaCacheSelector<'tcx>)
649 desc { "computing the inferred outlives predicates for items in this crate" }
652 /// Maps from an impl/trait `DefId` to a list of the `DefId`s of its items.
653 query associated_item_def_ids(key: DefId) -> &'tcx [DefId] {
654 desc { |tcx| "collecting associated items of `{}`", tcx.def_path_str(key) }
655 cache_on_disk_if { key.is_local() }
656 separate_provide_extern
659 /// Maps from a trait item to the trait item "descriptor".
660 query associated_item(key: DefId) -> ty::AssocItem {
661 desc { |tcx| "computing associated item data for `{}`", tcx.def_path_str(key) }
662 storage(ArenaCacheSelector<'tcx>)
663 cache_on_disk_if { key.is_local() }
664 separate_provide_extern
667 /// Collects the associated items defined on a trait or impl.
668 query associated_items(key: DefId) -> ty::AssocItems<'tcx> {
669 storage(ArenaCacheSelector<'tcx>)
670 desc { |tcx| "collecting associated items of {}", tcx.def_path_str(key) }
673 /// Maps from associated items on a trait to the corresponding associated
674 /// item on the impl specified by `impl_id`.
676 /// For example, with the following code
681 /// trait Trait { // trait_id
682 /// fn f(); // trait_f
683 /// fn g() {} // trait_g
686 /// impl Trait for Type { // impl_id
687 /// fn f() {} // impl_f
688 /// fn g() {} // impl_g
692 /// The map returned for `tcx.impl_item_implementor_ids(impl_id)` would be
693 ///`{ trait_f: impl_f, trait_g: impl_g }`
694 query impl_item_implementor_ids(impl_id: DefId) -> FxHashMap<DefId, DefId> {
695 storage(ArenaCacheSelector<'tcx>)
696 desc { |tcx| "comparing impl items against trait for {}", tcx.def_path_str(impl_id) }
699 /// Given an `impl_id`, return the trait it implements.
700 /// Return `None` if this is an inherent impl.
701 query impl_trait_ref(impl_id: DefId) -> Option<ty::TraitRef<'tcx>> {
702 desc { |tcx| "computing trait implemented by `{}`", tcx.def_path_str(impl_id) }
703 cache_on_disk_if { impl_id.is_local() }
704 separate_provide_extern
706 query impl_polarity(impl_id: DefId) -> ty::ImplPolarity {
707 desc { |tcx| "computing implementation polarity of `{}`", tcx.def_path_str(impl_id) }
708 cache_on_disk_if { impl_id.is_local() }
709 separate_provide_extern
712 query issue33140_self_ty(key: DefId) -> Option<ty::Ty<'tcx>> {
713 desc { |tcx| "computing Self type wrt issue #33140 `{}`", tcx.def_path_str(key) }
716 /// Maps a `DefId` of a type to a list of its inherent impls.
717 /// Contains implementations of methods that are inherent to a type.
718 /// Methods in these implementations don't need to be exported.
719 query inherent_impls(key: DefId) -> &'tcx [DefId] {
720 desc { |tcx| "collecting inherent impls for `{}`", tcx.def_path_str(key) }
721 cache_on_disk_if { key.is_local() }
722 separate_provide_extern
725 query incoherent_impls(key: SimplifiedType) -> &'tcx [DefId] {
726 desc { |tcx| "collecting all inherent impls for `{:?}`", key }
729 /// The result of unsafety-checking this `LocalDefId`.
730 query unsafety_check_result(key: LocalDefId) -> &'tcx mir::UnsafetyCheckResult {
731 desc { |tcx| "unsafety-checking `{}`", tcx.def_path_str(key.to_def_id()) }
732 cache_on_disk_if { true }
734 query unsafety_check_result_for_const_arg(key: (LocalDefId, DefId)) -> &'tcx mir::UnsafetyCheckResult {
736 |tcx| "unsafety-checking the const argument `{}`",
737 tcx.def_path_str(key.0.to_def_id())
741 /// Unsafety-check this `LocalDefId` with THIR unsafeck. This should be
742 /// used with `-Zthir-unsafeck`.
743 query thir_check_unsafety(key: LocalDefId) {
744 desc { |tcx| "unsafety-checking `{}`", tcx.def_path_str(key.to_def_id()) }
745 cache_on_disk_if { true }
747 query thir_check_unsafety_for_const_arg(key: (LocalDefId, DefId)) {
749 |tcx| "unsafety-checking the const argument `{}`",
750 tcx.def_path_str(key.0.to_def_id())
754 /// HACK: when evaluated, this reports an "unsafe derive on repr(packed)" error.
756 /// Unsafety checking is executed for each method separately, but we only want
757 /// to emit this error once per derive. As there are some impls with multiple
758 /// methods, we use a query for deduplication.
759 query unsafe_derive_on_repr_packed(key: LocalDefId) -> () {
760 desc { |tcx| "processing `{}`", tcx.def_path_str(key.to_def_id()) }
763 /// Computes the signature of the function.
764 query fn_sig(key: DefId) -> ty::PolyFnSig<'tcx> {
765 desc { |tcx| "computing function signature of `{}`", tcx.def_path_str(key) }
766 cache_on_disk_if { key.is_local() }
767 separate_provide_extern
770 /// Performs lint checking for the module.
771 query lint_mod(key: LocalDefId) -> () {
772 desc { |tcx| "linting {}", describe_as_module(key, tcx) }
775 /// Checks the attributes in the module.
776 query check_mod_attrs(key: LocalDefId) -> () {
777 desc { |tcx| "checking attributes in {}", describe_as_module(key, tcx) }
780 /// Checks for uses of unstable APIs in the module.
781 query check_mod_unstable_api_usage(key: LocalDefId) -> () {
782 desc { |tcx| "checking for unstable API usage in {}", describe_as_module(key, tcx) }
785 /// Checks the const bodies in the module for illegal operations (e.g. `if` or `loop`).
786 query check_mod_const_bodies(key: LocalDefId) -> () {
787 desc { |tcx| "checking consts in {}", describe_as_module(key, tcx) }
790 /// Checks the loops in the module.
791 query check_mod_loops(key: LocalDefId) -> () {
792 desc { |tcx| "checking loops in {}", describe_as_module(key, tcx) }
795 query check_mod_naked_functions(key: LocalDefId) -> () {
796 desc { |tcx| "checking naked functions in {}", describe_as_module(key, tcx) }
799 query check_mod_item_types(key: LocalDefId) -> () {
800 desc { |tcx| "checking item types in {}", describe_as_module(key, tcx) }
803 query check_mod_privacy(key: LocalDefId) -> () {
804 desc { |tcx| "checking privacy in {}", describe_as_module(key, tcx) }
807 query check_mod_liveness(key: LocalDefId) -> () {
808 desc { |tcx| "checking liveness of variables in {}", describe_as_module(key, tcx) }
811 /// Return the live symbols in the crate for dead code check.
813 /// The second return value maps from ADTs to ignored derived traits (e.g. Debug and Clone) and
814 /// their respective impl (i.e., part of the derive macro)
815 query live_symbols_and_ignored_derived_traits(_: ()) -> (
816 FxHashSet<LocalDefId>,
817 FxHashMap<LocalDefId, Vec<(DefId, DefId)>>
819 storage(ArenaCacheSelector<'tcx>)
820 desc { "find live symbols in crate" }
823 query check_mod_deathness(key: LocalDefId) -> () {
824 desc { |tcx| "checking deathness of variables in {}", describe_as_module(key, tcx) }
827 query check_mod_impl_wf(key: LocalDefId) -> () {
828 desc { |tcx| "checking that impls are well-formed in {}", describe_as_module(key, tcx) }
831 query collect_mod_item_types(key: LocalDefId) -> () {
832 desc { |tcx| "collecting item types in {}", describe_as_module(key, tcx) }
835 /// Caches `CoerceUnsized` kinds for impls on custom types.
836 query coerce_unsized_info(key: DefId) -> ty::adjustment::CoerceUnsizedInfo {
837 desc { |tcx| "computing CoerceUnsized info for `{}`", tcx.def_path_str(key) }
838 cache_on_disk_if { key.is_local() }
839 separate_provide_extern
842 query typeck_item_bodies(_: ()) -> () {
843 desc { "type-checking all item bodies" }
846 query typeck(key: LocalDefId) -> &'tcx ty::TypeckResults<'tcx> {
847 desc { |tcx| "type-checking `{}`", tcx.def_path_str(key.to_def_id()) }
848 cache_on_disk_if { true }
850 query typeck_const_arg(
851 key: (LocalDefId, DefId)
852 ) -> &'tcx ty::TypeckResults<'tcx> {
854 |tcx| "type-checking the const argument `{}`",
855 tcx.def_path_str(key.0.to_def_id()),
858 query diagnostic_only_typeck(key: LocalDefId) -> &'tcx ty::TypeckResults<'tcx> {
859 desc { |tcx| "type-checking `{}`", tcx.def_path_str(key.to_def_id()) }
860 cache_on_disk_if { true }
861 load_cached(tcx, id) {
862 let typeck_results: Option<ty::TypeckResults<'tcx>> = tcx
863 .on_disk_cache().as_ref()
864 .and_then(|c| c.try_load_query_result(*tcx, id));
866 typeck_results.map(|x| &*tcx.arena.alloc(x))
870 query used_trait_imports(key: LocalDefId) -> &'tcx FxHashSet<LocalDefId> {
871 desc { |tcx| "used_trait_imports `{}`", tcx.def_path_str(key.to_def_id()) }
872 cache_on_disk_if { true }
875 query has_typeck_results(def_id: DefId) -> bool {
876 desc { |tcx| "checking whether `{}` has a body", tcx.def_path_str(def_id) }
879 query coherent_trait(def_id: DefId) -> () {
880 desc { |tcx| "coherence checking all impls of trait `{}`", tcx.def_path_str(def_id) }
883 /// Borrow-checks the function body. If this is a closure, returns
884 /// additional requirements that the closure's creator must verify.
885 query mir_borrowck(key: LocalDefId) -> &'tcx mir::BorrowCheckResult<'tcx> {
886 desc { |tcx| "borrow-checking `{}`", tcx.def_path_str(key.to_def_id()) }
887 cache_on_disk_if(tcx) { tcx.is_typeck_child(key.to_def_id()) }
889 query mir_borrowck_const_arg(key: (LocalDefId, DefId)) -> &'tcx mir::BorrowCheckResult<'tcx> {
891 |tcx| "borrow-checking the const argument`{}`",
892 tcx.def_path_str(key.0.to_def_id())
896 /// Gets a complete map from all types to their inherent impls.
897 /// Not meant to be used directly outside of coherence.
898 query crate_inherent_impls(k: ()) -> CrateInherentImpls {
899 storage(ArenaCacheSelector<'tcx>)
900 desc { "all inherent impls defined in crate" }
903 /// Checks all types in the crate for overlap in their inherent impls. Reports errors.
904 /// Not meant to be used directly outside of coherence.
905 query crate_inherent_impls_overlap_check(_: ()) -> () {
906 desc { "check for overlap between inherent impls defined in this crate" }
909 /// Checks whether all impls in the crate pass the overlap check, returning
910 /// which impls fail it. If all impls are correct, the returned slice is empty.
911 query orphan_check_crate(_: ()) -> &'tcx [LocalDefId] {
913 "checking whether the immpl in the this crate follow the orphan rules",
917 /// Check whether the function has any recursion that could cause the inliner to trigger
918 /// a cycle. Returns the call stack causing the cycle. The call stack does not contain the
919 /// current function, just all intermediate functions.
920 query mir_callgraph_reachable(key: (ty::Instance<'tcx>, LocalDefId)) -> bool {
923 "computing if `{}` (transitively) calls `{}`",
925 tcx.def_path_str(key.1.to_def_id()),
929 /// Obtain all the calls into other local functions
930 query mir_inliner_callees(key: ty::InstanceDef<'tcx>) -> &'tcx [(DefId, SubstsRef<'tcx>)] {
933 "computing all local function calls in `{}`",
934 tcx.def_path_str(key.def_id()),
938 /// Evaluates a constant and returns the computed allocation.
940 /// **Do not use this** directly, use the `tcx.eval_static_initializer` wrapper.
941 query eval_to_allocation_raw(key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>)
942 -> EvalToAllocationRawResult<'tcx> {
944 "const-evaluating + checking `{}`",
945 key.value.display(tcx)
947 cache_on_disk_if { true }
950 /// Evaluates const items or anonymous constants
951 /// (such as enum variant explicit discriminants or array lengths)
952 /// into a representation suitable for the type system and const generics.
954 /// **Do not use this** directly, use one of the following wrappers: `tcx.const_eval_poly`,
955 /// `tcx.const_eval_resolve`, `tcx.const_eval_instance`, or `tcx.const_eval_global_id`.
956 query eval_to_const_value_raw(key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>)
957 -> EvalToConstValueResult<'tcx> {
959 "simplifying constant for the type system `{}`",
960 key.value.display(tcx)
962 cache_on_disk_if { true }
965 /// Evaluate a constant and convert it to a type level constant or
966 /// return `None` if that is not possible.
967 query eval_to_valtree(
968 key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>
969 ) -> EvalToValTreeResult<'tcx> {
970 desc { "evaluate type-level constant" }
974 /// Converts a type level constant value into `ConstValue`
975 query valtree_to_const_val(key: (Ty<'tcx>, ty::ValTree<'tcx>)) -> ConstValue<'tcx> {
976 desc { "convert type-level constant value to mir constant value"}
979 /// Destructure a constant ADT or array into its variant index and its
980 /// field values or return `None` if constant is invalid.
982 /// Use infallible `TyCtxt::destructure_const` when you know that constant is valid.
983 query try_destructure_const(key: ty::ParamEnvAnd<'tcx, ty::Const<'tcx>>) -> Option<mir::DestructuredConst<'tcx>> {
984 desc { "destructure type level constant"}
987 /// Tries to destructure an `mir::ConstantKind` ADT or array into its variant index
988 /// and its field values.
989 query try_destructure_mir_constant(key: ty::ParamEnvAnd<'tcx, mir::ConstantKind<'tcx>>) -> Option<mir::DestructuredMirConstant<'tcx>> {
990 desc { "destructure mir constant"}
994 /// Dereference a constant reference or raw pointer and turn the result into a constant
997 key: ty::ParamEnvAnd<'tcx, ty::Const<'tcx>>
998 ) -> ty::Const<'tcx> {
999 desc { "deref constant" }
1003 /// Dereference a constant reference or raw pointer and turn the result into a constant
1005 query deref_mir_constant(
1006 key: ty::ParamEnvAnd<'tcx, mir::ConstantKind<'tcx>>
1007 ) -> mir::ConstantKind<'tcx> {
1008 desc { "deref constant" }
1012 query const_caller_location(key: (rustc_span::Symbol, u32, u32)) -> ConstValue<'tcx> {
1013 desc { "get a &core::panic::Location referring to a span" }
1016 // FIXME get rid of this with valtrees
1018 key: LitToConstInput<'tcx>
1019 ) -> Result<ty::Const<'tcx>, LitToConstError> {
1020 desc { "converting literal to const" }
1023 query lit_to_mir_constant(key: LitToConstInput<'tcx>) -> Result<mir::ConstantKind<'tcx>, LitToConstError> {
1024 desc { "converting literal to mir constant" }
1027 query check_match(key: DefId) {
1028 desc { |tcx| "match-checking `{}`", tcx.def_path_str(key) }
1029 cache_on_disk_if { key.is_local() }
1032 /// Performs part of the privacy check and computes "access levels".
1033 query privacy_access_levels(_: ()) -> &'tcx AccessLevels {
1035 desc { "privacy access levels" }
1037 query check_private_in_public(_: ()) -> () {
1039 desc { "checking for private elements in public interfaces" }
1042 query reachable_set(_: ()) -> FxHashSet<LocalDefId> {
1043 storage(ArenaCacheSelector<'tcx>)
1044 desc { "reachability" }
1047 /// Per-body `region::ScopeTree`. The `DefId` should be the owner `DefId` for the body;
1048 /// in the case of closures, this will be redirected to the enclosing function.
1049 query region_scope_tree(def_id: DefId) -> &'tcx crate::middle::region::ScopeTree {
1050 desc { |tcx| "computing drop scopes for `{}`", tcx.def_path_str(def_id) }
1053 /// Generates a MIR body for the shim.
1054 query mir_shims(key: ty::InstanceDef<'tcx>) -> mir::Body<'tcx> {
1055 storage(ArenaCacheSelector<'tcx>)
1056 desc { |tcx| "generating MIR shim for `{}`", tcx.def_path_str(key.def_id()) }
1059 /// The `symbol_name` query provides the symbol name for calling a
1060 /// given instance from the local crate. In particular, it will also
1061 /// look up the correct symbol name of instances from upstream crates.
1062 query symbol_name(key: ty::Instance<'tcx>) -> ty::SymbolName<'tcx> {
1063 desc { "computing the symbol for `{}`", key }
1064 cache_on_disk_if { true }
1067 query opt_def_kind(def_id: DefId) -> Option<DefKind> {
1068 desc { |tcx| "looking up definition kind of `{}`", 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 definition.
1074 query def_span(def_id: DefId) -> Span {
1075 desc { |tcx| "looking up span for `{}`", tcx.def_path_str(def_id) }
1076 cache_on_disk_if { def_id.is_local() }
1077 separate_provide_extern
1080 /// Gets the span for the identifier of the definition.
1081 query def_ident_span(def_id: DefId) -> Option<Span> {
1082 desc { |tcx| "looking up span for `{}`'s identifier", tcx.def_path_str(def_id) }
1083 cache_on_disk_if { def_id.is_local() }
1084 separate_provide_extern
1087 query lookup_stability(def_id: DefId) -> Option<attr::Stability> {
1088 desc { |tcx| "looking up stability of `{}`", tcx.def_path_str(def_id) }
1089 cache_on_disk_if { def_id.is_local() }
1090 separate_provide_extern
1093 query lookup_const_stability(def_id: DefId) -> Option<attr::ConstStability> {
1094 desc { |tcx| "looking up const stability of `{}`", tcx.def_path_str(def_id) }
1095 cache_on_disk_if { def_id.is_local() }
1096 separate_provide_extern
1099 query should_inherit_track_caller(def_id: DefId) -> bool {
1100 desc { |tcx| "computing should_inherit_track_caller of `{}`", tcx.def_path_str(def_id) }
1103 query lookup_deprecation_entry(def_id: DefId) -> Option<DeprecationEntry> {
1104 desc { |tcx| "checking whether `{}` is deprecated", tcx.def_path_str(def_id) }
1105 cache_on_disk_if { def_id.is_local() }
1106 separate_provide_extern
1109 /// Determines whether an item is annotated with `doc(hidden)`.
1110 query is_doc_hidden(def_id: DefId) -> bool {
1111 desc { |tcx| "checking whether `{}` is `doc(hidden)`", tcx.def_path_str(def_id) }
1114 /// Returns the attributes on the item at `def_id`.
1116 /// Do not use this directly, use `tcx.get_attrs` instead.
1117 query item_attrs(def_id: DefId) -> &'tcx [ast::Attribute] {
1118 desc { |tcx| "collecting attributes of `{}`", tcx.def_path_str(def_id) }
1119 separate_provide_extern
1122 query codegen_fn_attrs(def_id: DefId) -> CodegenFnAttrs {
1123 desc { |tcx| "computing codegen attributes of `{}`", tcx.def_path_str(def_id) }
1124 storage(ArenaCacheSelector<'tcx>)
1125 cache_on_disk_if { def_id.is_local() }
1126 separate_provide_extern
1129 query asm_target_features(def_id: DefId) -> &'tcx FxHashSet<Symbol> {
1130 desc { |tcx| "computing target features for inline asm of `{}`", tcx.def_path_str(def_id) }
1133 query fn_arg_names(def_id: DefId) -> &'tcx [rustc_span::symbol::Ident] {
1134 desc { |tcx| "looking up function parameter names for `{}`", tcx.def_path_str(def_id) }
1135 cache_on_disk_if { def_id.is_local() }
1136 separate_provide_extern
1138 /// Gets the rendered value of the specified constant or associated constant.
1139 /// Used by rustdoc.
1140 query rendered_const(def_id: DefId) -> String {
1141 storage(ArenaCacheSelector<'tcx>)
1142 desc { |tcx| "rendering constant intializer of `{}`", tcx.def_path_str(def_id) }
1143 cache_on_disk_if { def_id.is_local() }
1144 separate_provide_extern
1146 query impl_parent(def_id: DefId) -> Option<DefId> {
1147 desc { |tcx| "computing specialization parent impl of `{}`", tcx.def_path_str(def_id) }
1148 cache_on_disk_if { def_id.is_local() }
1149 separate_provide_extern
1152 /// Given an `associated_item`, find the trait it belongs to.
1153 /// Return `None` if the `DefId` is not an associated item.
1154 query trait_of_item(associated_item: DefId) -> Option<DefId> {
1155 desc { |tcx| "finding trait defining `{}`", tcx.def_path_str(associated_item) }
1156 cache_on_disk_if { associated_item.is_local() }
1157 separate_provide_extern
1160 query is_ctfe_mir_available(key: DefId) -> bool {
1161 desc { |tcx| "checking if item has ctfe mir available: `{}`", tcx.def_path_str(key) }
1162 cache_on_disk_if { key.is_local() }
1163 separate_provide_extern
1165 query is_mir_available(key: DefId) -> bool {
1166 desc { |tcx| "checking if item has mir available: `{}`", tcx.def_path_str(key) }
1167 cache_on_disk_if { key.is_local() }
1168 separate_provide_extern
1171 query own_existential_vtable_entries(
1172 key: ty::PolyExistentialTraitRef<'tcx>
1173 ) -> &'tcx [DefId] {
1174 desc { |tcx| "finding all existential vtable entries for trait {}", tcx.def_path_str(key.def_id()) }
1177 query vtable_entries(key: ty::PolyTraitRef<'tcx>)
1178 -> &'tcx [ty::VtblEntry<'tcx>] {
1179 desc { |tcx| "finding all vtable entries for trait {}", tcx.def_path_str(key.def_id()) }
1182 query vtable_trait_upcasting_coercion_new_vptr_slot(key: (ty::Ty<'tcx>, ty::Ty<'tcx>)) -> Option<usize> {
1183 desc { |tcx| "finding the slot within vtable for trait object {} vtable ptr during trait upcasting coercion from {} vtable",
1187 query vtable_allocation(key: (Ty<'tcx>, Option<ty::PolyExistentialTraitRef<'tcx>>)) -> mir::interpret::AllocId {
1188 desc { |tcx| "vtable const allocation for <{} as {}>",
1190 key.1.map(|trait_ref| format!("{}", trait_ref)).unwrap_or("_".to_owned())
1194 query codegen_fulfill_obligation(
1195 key: (ty::ParamEnv<'tcx>, ty::PolyTraitRef<'tcx>)
1196 ) -> Result<&'tcx ImplSource<'tcx, ()>, traits::CodegenObligationError> {
1197 cache_on_disk_if { true }
1199 "checking if `{}` fulfills its obligations",
1200 tcx.def_path_str(key.1.def_id())
1204 /// Return all `impl` blocks in the current crate.
1205 query all_local_trait_impls(_: ()) -> &'tcx rustc_data_structures::fx::FxIndexMap<DefId, Vec<LocalDefId>> {
1206 desc { "local trait impls" }
1209 /// Given a trait `trait_id`, return all known `impl` blocks.
1210 query trait_impls_of(trait_id: DefId) -> ty::trait_def::TraitImpls {
1211 storage(ArenaCacheSelector<'tcx>)
1212 desc { |tcx| "trait impls of `{}`", tcx.def_path_str(trait_id) }
1215 query specialization_graph_of(trait_id: DefId) -> specialization_graph::Graph {
1216 storage(ArenaCacheSelector<'tcx>)
1217 desc { |tcx| "building specialization graph of trait `{}`", tcx.def_path_str(trait_id) }
1218 cache_on_disk_if { true }
1220 query object_safety_violations(trait_id: DefId) -> &'tcx [traits::ObjectSafetyViolation] {
1221 desc { |tcx| "determine object safety of trait `{}`", tcx.def_path_str(trait_id) }
1224 /// Gets the ParameterEnvironment for a given item; this environment
1225 /// will be in "user-facing" mode, meaning that it is suitable for
1226 /// type-checking etc, and it does not normalize specializable
1227 /// associated types. This is almost always what you want,
1228 /// unless you are doing MIR optimizations, in which case you
1229 /// might want to use `reveal_all()` method to change modes.
1230 query param_env(def_id: DefId) -> ty::ParamEnv<'tcx> {
1231 desc { |tcx| "computing normalized predicates of `{}`", tcx.def_path_str(def_id) }
1234 /// Like `param_env`, but returns the `ParamEnv` in `Reveal::All` mode.
1235 /// Prefer this over `tcx.param_env(def_id).with_reveal_all_normalized(tcx)`,
1236 /// as this method is more efficient.
1237 query param_env_reveal_all_normalized(def_id: DefId) -> ty::ParamEnv<'tcx> {
1238 desc { |tcx| "computing revealed normalized predicates of `{}`", tcx.def_path_str(def_id) }
1241 /// Trait selection queries. These are best used by invoking `ty.is_copy_modulo_regions()`,
1242 /// `ty.is_copy()`, etc, since that will prune the environment where possible.
1243 query is_copy_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1244 desc { "computing whether `{}` is `Copy`", env.value }
1247 /// Query backing `Ty::is_sized`.
1248 query is_sized_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1249 desc { "computing whether `{}` is `Sized`", env.value }
1252 /// Query backing `Ty::is_freeze`.
1253 query is_freeze_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1254 desc { "computing whether `{}` is freeze", env.value }
1257 /// Query backing `Ty::is_unpin`.
1258 query is_unpin_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1259 desc { "computing whether `{}` is `Unpin`", env.value }
1262 /// Query backing `Ty::needs_drop`.
1263 query needs_drop_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1264 desc { "computing whether `{}` needs drop", env.value }
1267 /// Query backing `Ty::has_significant_drop_raw`.
1268 query has_significant_drop_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1269 desc { "computing whether `{}` has a significant drop", env.value }
1273 /// Query backing `Ty::is_structural_eq_shallow`.
1275 /// This is only correct for ADTs. Call `is_structural_eq_shallow` to handle all types
1277 query has_structural_eq_impls(ty: Ty<'tcx>) -> bool {
1279 "computing whether `{:?}` implements `PartialStructuralEq` and `StructuralEq`",
1284 /// A list of types where the ADT requires drop if and only if any of
1285 /// those types require drop. If the ADT is known to always need drop
1286 /// then `Err(AlwaysRequiresDrop)` is returned.
1287 query adt_drop_tys(def_id: DefId) -> Result<&'tcx ty::List<Ty<'tcx>>, AlwaysRequiresDrop> {
1288 desc { |tcx| "computing when `{}` needs drop", tcx.def_path_str(def_id) }
1289 cache_on_disk_if { true }
1292 /// A list of types where the ADT requires drop if and only if any of those types
1293 /// has significant drop. A type marked with the attribute `rustc_insignificant_dtor`
1294 /// is considered to not be significant. A drop is significant if it is implemented
1295 /// by the user or does anything that will have any observable behavior (other than
1296 /// freeing up memory). If the ADT is known to have a significant destructor then
1297 /// `Err(AlwaysRequiresDrop)` is returned.
1298 query adt_significant_drop_tys(def_id: DefId) -> Result<&'tcx ty::List<Ty<'tcx>>, AlwaysRequiresDrop> {
1299 desc { |tcx| "computing when `{}` has a significant destructor", tcx.def_path_str(def_id) }
1300 cache_on_disk_if { false }
1303 /// Computes the layout of a type. Note that this implicitly
1304 /// executes in "reveal all" mode, and will normalize the input type.
1306 key: ty::ParamEnvAnd<'tcx, Ty<'tcx>>
1307 ) -> Result<ty::layout::TyAndLayout<'tcx>, ty::layout::LayoutError<'tcx>> {
1308 desc { "computing layout of `{}`", key.value }
1312 /// Compute a `FnAbi` suitable for indirect calls, i.e. to `fn` pointers.
1314 /// NB: this doesn't handle virtual calls - those should use `fn_abi_of_instance`
1315 /// instead, where the instance is an `InstanceDef::Virtual`.
1316 query fn_abi_of_fn_ptr(
1317 key: ty::ParamEnvAnd<'tcx, (ty::PolyFnSig<'tcx>, &'tcx ty::List<Ty<'tcx>>)>
1318 ) -> Result<&'tcx abi::call::FnAbi<'tcx, Ty<'tcx>>, ty::layout::FnAbiError<'tcx>> {
1319 desc { "computing call ABI of `{}` function pointers", key.value.0 }
1323 /// Compute a `FnAbi` suitable for declaring/defining an `fn` instance, and for
1324 /// direct calls to an `fn`.
1326 /// NB: that includes virtual calls, which are represented by "direct calls"
1327 /// to an `InstanceDef::Virtual` instance (of `<dyn Trait as Trait>::fn`).
1328 query fn_abi_of_instance(
1329 key: ty::ParamEnvAnd<'tcx, (ty::Instance<'tcx>, &'tcx ty::List<Ty<'tcx>>)>
1330 ) -> Result<&'tcx abi::call::FnAbi<'tcx, Ty<'tcx>>, ty::layout::FnAbiError<'tcx>> {
1331 desc { "computing call ABI of `{}`", key.value.0 }
1335 query dylib_dependency_formats(_: CrateNum)
1336 -> &'tcx [(CrateNum, LinkagePreference)] {
1337 desc { "dylib dependency formats of crate" }
1338 separate_provide_extern
1341 query dependency_formats(_: ()) -> Lrc<crate::middle::dependency_format::Dependencies> {
1342 storage(ArenaCacheSelector<'tcx>)
1343 desc { "get the linkage format of all dependencies" }
1346 query is_compiler_builtins(_: CrateNum) -> bool {
1348 desc { "checking if the crate is_compiler_builtins" }
1349 separate_provide_extern
1351 query has_global_allocator(_: CrateNum) -> bool {
1352 // This query depends on untracked global state in CStore
1355 desc { "checking if the crate has_global_allocator" }
1356 separate_provide_extern
1358 query has_panic_handler(_: CrateNum) -> bool {
1360 desc { "checking if the crate has_panic_handler" }
1361 separate_provide_extern
1363 query is_profiler_runtime(_: CrateNum) -> bool {
1365 desc { "query a crate is `#![profiler_runtime]`" }
1366 separate_provide_extern
1368 query panic_strategy(_: CrateNum) -> PanicStrategy {
1370 desc { "query a crate's configured panic strategy" }
1371 separate_provide_extern
1373 query panic_in_drop_strategy(_: CrateNum) -> PanicStrategy {
1375 desc { "query a crate's configured panic-in-drop strategy" }
1376 separate_provide_extern
1378 query is_no_builtins(_: CrateNum) -> bool {
1380 desc { "test whether a crate has `#![no_builtins]`" }
1381 separate_provide_extern
1383 query symbol_mangling_version(_: CrateNum) -> SymbolManglingVersion {
1385 desc { "query a crate's symbol mangling version" }
1386 separate_provide_extern
1389 query extern_crate(def_id: DefId) -> Option<&'tcx ExternCrate> {
1391 desc { "getting crate's ExternCrateData" }
1392 separate_provide_extern
1395 query specializes(_: (DefId, DefId)) -> bool {
1396 desc { "computing whether impls specialize one another" }
1398 query in_scope_traits_map(_: LocalDefId)
1399 -> Option<&'tcx FxHashMap<ItemLocalId, Box<[TraitCandidate]>>> {
1400 desc { "traits in scope at a block" }
1403 query module_reexports(def_id: LocalDefId) -> Option<&'tcx [ModChild]> {
1404 desc { |tcx| "looking up reexports of module `{}`", tcx.def_path_str(def_id.to_def_id()) }
1407 query impl_defaultness(def_id: DefId) -> hir::Defaultness {
1408 desc { |tcx| "looking up whether `{}` is a default impl", tcx.def_path_str(def_id) }
1409 cache_on_disk_if { def_id.is_local() }
1410 separate_provide_extern
1413 query check_item_well_formed(key: LocalDefId) -> () {
1414 desc { |tcx| "checking that `{}` is well-formed", tcx.def_path_str(key.to_def_id()) }
1416 query check_trait_item_well_formed(key: LocalDefId) -> () {
1417 desc { |tcx| "checking that `{}` is well-formed", tcx.def_path_str(key.to_def_id()) }
1419 query check_impl_item_well_formed(key: LocalDefId) -> () {
1420 desc { |tcx| "checking that `{}` is well-formed", tcx.def_path_str(key.to_def_id()) }
1423 // The `DefId`s of all non-generic functions and statics in the given crate
1424 // that can be reached from outside the crate.
1426 // We expect this items to be available for being linked to.
1428 // This query can also be called for `LOCAL_CRATE`. In this case it will
1429 // compute which items will be reachable to other crates, taking into account
1430 // the kind of crate that is currently compiled. Crates with only a
1431 // C interface have fewer reachable things.
1433 // Does not include external symbols that don't have a corresponding DefId,
1434 // like the compiler-generated `main` function and so on.
1435 query reachable_non_generics(_: CrateNum)
1436 -> DefIdMap<SymbolExportInfo> {
1437 storage(ArenaCacheSelector<'tcx>)
1438 desc { "looking up the exported symbols of a crate" }
1439 separate_provide_extern
1441 query is_reachable_non_generic(def_id: DefId) -> bool {
1442 desc { |tcx| "checking whether `{}` is an exported symbol", tcx.def_path_str(def_id) }
1443 cache_on_disk_if { def_id.is_local() }
1444 separate_provide_extern
1446 query is_unreachable_local_definition(def_id: LocalDefId) -> bool {
1448 "checking whether `{}` is reachable from outside the crate",
1449 tcx.def_path_str(def_id.to_def_id()),
1453 /// The entire set of monomorphizations the local crate can safely link
1454 /// to because they are exported from upstream crates. Do not depend on
1455 /// this directly, as its value changes anytime a monomorphization gets
1456 /// added or removed in any upstream crate. Instead use the narrower
1457 /// `upstream_monomorphizations_for`, `upstream_drop_glue_for`, or, even
1458 /// better, `Instance::upstream_monomorphization()`.
1459 query upstream_monomorphizations(_: ()) -> DefIdMap<FxHashMap<SubstsRef<'tcx>, CrateNum>> {
1460 storage(ArenaCacheSelector<'tcx>)
1461 desc { "collecting available upstream monomorphizations" }
1464 /// Returns the set of upstream monomorphizations available for the
1465 /// generic function identified by the given `def_id`. The query makes
1466 /// sure to make a stable selection if the same monomorphization is
1467 /// available in multiple upstream crates.
1469 /// You likely want to call `Instance::upstream_monomorphization()`
1470 /// instead of invoking this query directly.
1471 query upstream_monomorphizations_for(def_id: DefId)
1472 -> Option<&'tcx FxHashMap<SubstsRef<'tcx>, CrateNum>>
1474 storage(ArenaCacheSelector<'tcx>)
1476 "collecting available upstream monomorphizations for `{}`",
1477 tcx.def_path_str(def_id),
1479 separate_provide_extern
1482 /// Returns the upstream crate that exports drop-glue for the given
1483 /// type (`substs` is expected to be a single-item list containing the
1484 /// type one wants drop-glue for).
1486 /// This is a subset of `upstream_monomorphizations_for` in order to
1487 /// increase dep-tracking granularity. Otherwise adding or removing any
1488 /// type with drop-glue in any upstream crate would invalidate all
1489 /// functions calling drop-glue of an upstream type.
1491 /// You likely want to call `Instance::upstream_monomorphization()`
1492 /// instead of invoking this query directly.
1494 /// NOTE: This query could easily be extended to also support other
1495 /// common functions that have are large set of monomorphizations
1496 /// (like `Clone::clone` for example).
1497 query upstream_drop_glue_for(substs: SubstsRef<'tcx>) -> Option<CrateNum> {
1498 desc { "available upstream drop-glue for `{:?}`", substs }
1501 query foreign_modules(_: CrateNum) -> FxHashMap<DefId, ForeignModule> {
1502 storage(ArenaCacheSelector<'tcx>)
1503 desc { "looking up the foreign modules of a linked crate" }
1504 separate_provide_extern
1507 /// Identifies the entry-point (e.g., the `main` function) for a given
1508 /// crate, returning `None` if there is no entry point (such as for library crates).
1509 query entry_fn(_: ()) -> Option<(DefId, EntryFnType)> {
1510 desc { "looking up the entry function of a crate" }
1512 query proc_macro_decls_static(_: ()) -> Option<LocalDefId> {
1513 desc { "looking up the derive registrar for a crate" }
1515 // The macro which defines `rustc_metadata::provide_extern` depends on this query's name.
1516 // Changing the name should cause a compiler error, but in case that changes, be aware.
1517 query crate_hash(_: CrateNum) -> Svh {
1519 desc { "looking up the hash a crate" }
1520 separate_provide_extern
1522 query crate_host_hash(_: CrateNum) -> Option<Svh> {
1524 desc { "looking up the hash of a host version of a crate" }
1525 separate_provide_extern
1527 query extra_filename(_: CrateNum) -> String {
1528 storage(ArenaCacheSelector<'tcx>)
1530 desc { "looking up the extra filename for a crate" }
1531 separate_provide_extern
1533 query crate_extern_paths(_: CrateNum) -> Vec<PathBuf> {
1534 storage(ArenaCacheSelector<'tcx>)
1536 desc { "looking up the paths for extern crates" }
1537 separate_provide_extern
1540 /// Given a crate and a trait, look up all impls of that trait in the crate.
1541 /// Return `(impl_id, self_ty)`.
1542 query implementations_of_trait(_: (CrateNum, DefId)) -> &'tcx [(DefId, Option<SimplifiedType>)] {
1543 desc { "looking up implementations of a trait in a crate" }
1544 separate_provide_extern
1547 /// Collects all incoherent impls for the given crate and type.
1549 /// Do not call this directly, but instead use the `incoherent_impls` query.
1550 /// This query is only used to get the data necessary for that query.
1551 query crate_incoherent_impls(key: (CrateNum, SimplifiedType)) -> &'tcx [DefId] {
1552 desc { |tcx| "collecting all impls for a type in a crate" }
1553 separate_provide_extern
1556 query is_dllimport_foreign_item(def_id: DefId) -> bool {
1557 desc { |tcx| "is_dllimport_foreign_item({})", tcx.def_path_str(def_id) }
1559 query is_statically_included_foreign_item(def_id: DefId) -> bool {
1560 desc { |tcx| "is_statically_included_foreign_item({})", tcx.def_path_str(def_id) }
1562 query native_library_kind(def_id: DefId)
1563 -> Option<NativeLibKind> {
1564 desc { |tcx| "native_library_kind({})", tcx.def_path_str(def_id) }
1567 /// Does lifetime resolution, but does not descend into trait items. This
1568 /// should only be used for resolving lifetimes of on trait definitions,
1569 /// and is used to avoid cycles. Importantly, `resolve_lifetimes` still visits
1570 /// the same lifetimes and is responsible for diagnostics.
1571 /// See `rustc_resolve::late::lifetimes for details.
1572 query resolve_lifetimes_trait_definition(_: LocalDefId) -> ResolveLifetimes {
1573 storage(ArenaCacheSelector<'tcx>)
1574 desc { "resolving lifetimes for a trait definition" }
1576 /// Does lifetime resolution on items. Importantly, we can't resolve
1577 /// lifetimes directly on things like trait methods, because of trait params.
1578 /// See `rustc_resolve::late::lifetimes for details.
1579 query resolve_lifetimes(_: LocalDefId) -> ResolveLifetimes {
1580 storage(ArenaCacheSelector<'tcx>)
1581 desc { "resolving lifetimes" }
1583 query named_region_map(_: LocalDefId) ->
1584 Option<&'tcx FxHashMap<ItemLocalId, Region>> {
1585 desc { "looking up a named region" }
1587 query is_late_bound_map(_: LocalDefId) -> Option<&'tcx FxHashSet<LocalDefId>> {
1588 desc { "testing if a region is late bound" }
1590 /// For a given item (like a struct), gets the default lifetimes to be used
1591 /// for each parameter if a trait object were to be passed for that parameter.
1592 /// For example, for `struct Foo<'a, T, U>`, this would be `['static, 'static]`.
1593 /// For `struct Foo<'a, T: 'a, U>`, this would instead be `['a, 'static]`.
1594 query object_lifetime_defaults(_: LocalDefId) -> Option<&'tcx [ObjectLifetimeDefault]> {
1595 desc { "looking up lifetime defaults for a region on an item" }
1597 query late_bound_vars_map(_: LocalDefId)
1598 -> Option<&'tcx FxHashMap<ItemLocalId, Vec<ty::BoundVariableKind>>> {
1599 desc { "looking up late bound vars" }
1602 query lifetime_scope_map(_: LocalDefId) -> Option<FxHashMap<ItemLocalId, LifetimeScopeForPath>> {
1603 storage(ArenaCacheSelector<'tcx>)
1604 desc { "finds the lifetime scope for an HirId of a PathSegment" }
1607 query visibility(def_id: DefId) -> ty::Visibility {
1608 desc { |tcx| "computing visibility of `{}`", tcx.def_path_str(def_id) }
1609 separate_provide_extern
1612 /// Computes the set of modules from which this type is visibly uninhabited.
1613 /// To check whether a type is uninhabited at all (not just from a given module), you could
1614 /// check whether the forest is empty.
1615 query type_uninhabited_from(
1616 key: ty::ParamEnvAnd<'tcx, Ty<'tcx>>
1617 ) -> ty::inhabitedness::DefIdForest<'tcx> {
1618 desc { "computing the inhabitedness of `{:?}`", key }
1622 query dep_kind(_: CrateNum) -> CrateDepKind {
1624 desc { "fetching what a dependency looks like" }
1625 separate_provide_extern
1628 /// Gets the name of the crate.
1629 query crate_name(_: CrateNum) -> Symbol {
1631 desc { "fetching what a crate is named" }
1632 separate_provide_extern
1634 query module_children(def_id: DefId) -> &'tcx [ModChild] {
1635 desc { |tcx| "collecting child items of module `{}`", tcx.def_path_str(def_id) }
1636 separate_provide_extern
1638 query extern_mod_stmt_cnum(def_id: LocalDefId) -> Option<CrateNum> {
1639 desc { |tcx| "computing crate imported by `{}`", tcx.def_path_str(def_id.to_def_id()) }
1642 query lib_features(_: ()) -> LibFeatures {
1643 storage(ArenaCacheSelector<'tcx>)
1644 desc { "calculating the lib features map" }
1646 query defined_lib_features(_: CrateNum)
1647 -> &'tcx [(Symbol, Option<Symbol>)] {
1648 desc { "calculating the lib features defined in a crate" }
1649 separate_provide_extern
1651 /// Whether the function is an intrinsic
1652 query is_intrinsic(def_id: DefId) -> bool {
1653 desc { |tcx| "is_intrinsic({})", tcx.def_path_str(def_id) }
1654 separate_provide_extern
1656 /// Returns the lang items defined in another crate by loading it from metadata.
1657 query get_lang_items(_: ()) -> LanguageItems {
1658 storage(ArenaCacheSelector<'tcx>)
1660 desc { "calculating the lang items map" }
1663 /// Returns all diagnostic items defined in all crates.
1664 query all_diagnostic_items(_: ()) -> rustc_hir::diagnostic_items::DiagnosticItems {
1665 storage(ArenaCacheSelector<'tcx>)
1667 desc { "calculating the diagnostic items map" }
1670 /// Returns the lang items defined in another crate by loading it from metadata.
1671 query defined_lang_items(_: CrateNum) -> &'tcx [(DefId, usize)] {
1672 desc { "calculating the lang items defined in a crate" }
1673 separate_provide_extern
1676 /// Returns the diagnostic items defined in a crate.
1677 query diagnostic_items(_: CrateNum) -> rustc_hir::diagnostic_items::DiagnosticItems {
1678 storage(ArenaCacheSelector<'tcx>)
1679 desc { "calculating the diagnostic items map in a crate" }
1680 separate_provide_extern
1683 query missing_lang_items(_: CrateNum) -> &'tcx [LangItem] {
1684 desc { "calculating the missing lang items in a crate" }
1685 separate_provide_extern
1687 query visible_parent_map(_: ()) -> DefIdMap<DefId> {
1688 storage(ArenaCacheSelector<'tcx>)
1689 desc { "calculating the visible parent map" }
1691 query trimmed_def_paths(_: ()) -> FxHashMap<DefId, Symbol> {
1692 storage(ArenaCacheSelector<'tcx>)
1693 desc { "calculating trimmed def paths" }
1695 query missing_extern_crate_item(_: CrateNum) -> bool {
1697 desc { "seeing if we're missing an `extern crate` item for this crate" }
1698 separate_provide_extern
1700 query used_crate_source(_: CrateNum) -> Lrc<CrateSource> {
1701 storage(ArenaCacheSelector<'tcx>)
1703 desc { "looking at the source for a crate" }
1704 separate_provide_extern
1706 /// Returns the debugger visualizers defined for this crate.
1707 query debugger_visualizers(_: CrateNum) -> Vec<rustc_span::DebuggerVisualizerFile> {
1708 storage(ArenaCacheSelector<'tcx>)
1709 desc { "looking up the debugger visualizers for this crate" }
1710 separate_provide_extern
1712 query postorder_cnums(_: ()) -> &'tcx [CrateNum] {
1714 desc { "generating a postorder list of CrateNums" }
1716 /// Returns whether or not the crate with CrateNum 'cnum'
1717 /// is marked as a private dependency
1718 query is_private_dep(c: CrateNum) -> bool {
1720 desc { "check whether crate {} is a private dependency", c }
1721 separate_provide_extern
1723 query allocator_kind(_: ()) -> Option<AllocatorKind> {
1725 desc { "allocator kind for the current crate" }
1728 query upvars_mentioned(def_id: DefId) -> Option<&'tcx FxIndexMap<hir::HirId, hir::Upvar>> {
1729 desc { |tcx| "collecting upvars mentioned in `{}`", tcx.def_path_str(def_id) }
1731 query maybe_unused_trait_imports(_: ()) -> &'tcx FxIndexSet<LocalDefId> {
1732 desc { "fetching potentially unused trait imports" }
1734 query maybe_unused_extern_crates(_: ()) -> &'tcx [(LocalDefId, Span)] {
1735 desc { "looking up all possibly unused extern crates" }
1737 query names_imported_by_glob_use(def_id: LocalDefId) -> &'tcx FxHashSet<Symbol> {
1738 desc { |tcx| "names_imported_by_glob_use for `{}`", tcx.def_path_str(def_id.to_def_id()) }
1741 query stability_index(_: ()) -> stability::Index {
1742 storage(ArenaCacheSelector<'tcx>)
1744 desc { "calculating the stability index for the local crate" }
1746 query crates(_: ()) -> &'tcx [CrateNum] {
1748 desc { "fetching all foreign CrateNum instances" }
1751 /// A list of all traits in a crate, used by rustdoc and error reporting.
1752 /// NOTE: Not named just `traits` due to a naming conflict.
1753 query traits_in_crate(_: CrateNum) -> &'tcx [DefId] {
1754 desc { "fetching all traits in a crate" }
1755 separate_provide_extern
1758 /// The list of symbols exported from the given crate.
1760 /// - All names contained in `exported_symbols(cnum)` are guaranteed to
1761 /// correspond to a publicly visible symbol in `cnum` machine code.
1762 /// - The `exported_symbols` sets of different crates do not intersect.
1763 query exported_symbols(cnum: CrateNum) -> &'tcx [(ExportedSymbol<'tcx>, SymbolExportInfo)] {
1764 desc { "exported_symbols" }
1765 cache_on_disk_if { *cnum == LOCAL_CRATE }
1766 separate_provide_extern
1769 query collect_and_partition_mono_items(_: ()) -> (&'tcx DefIdSet, &'tcx [CodegenUnit<'tcx>]) {
1771 desc { "collect_and_partition_mono_items" }
1773 query is_codegened_item(def_id: DefId) -> bool {
1774 desc { |tcx| "determining whether `{}` needs codegen", tcx.def_path_str(def_id) }
1777 /// All items participating in code generation together with items inlined into them.
1778 query codegened_and_inlined_items(_: ()) -> &'tcx DefIdSet {
1780 desc { "codegened_and_inlined_items" }
1783 query codegen_unit(_: Symbol) -> &'tcx CodegenUnit<'tcx> {
1784 desc { "codegen_unit" }
1786 query unused_generic_params(key: ty::InstanceDef<'tcx>) -> FiniteBitSet<u32> {
1787 cache_on_disk_if { key.def_id().is_local() }
1789 |tcx| "determining which generic parameters are unused by `{}`",
1790 tcx.def_path_str(key.def_id())
1792 separate_provide_extern
1794 query backend_optimization_level(_: ()) -> OptLevel {
1795 desc { "optimization level used by backend" }
1798 /// Return the filenames where output artefacts shall be stored.
1800 /// This query returns an `&Arc` because codegen backends need the value even after the `TyCtxt`
1801 /// has been destroyed.
1802 query output_filenames(_: ()) -> &'tcx Arc<OutputFilenames> {
1804 desc { "output_filenames" }
1807 /// Do not call this query directly: invoke `normalize` instead.
1808 query normalize_projection_ty(
1809 goal: CanonicalProjectionGoal<'tcx>
1811 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, NormalizationResult<'tcx>>>,
1814 desc { "normalizing `{:?}`", goal }
1818 /// Do not call this query directly: invoke `try_normalize_erasing_regions` instead.
1819 query try_normalize_generic_arg_after_erasing_regions(
1820 goal: ParamEnvAnd<'tcx, GenericArg<'tcx>>
1821 ) -> Result<GenericArg<'tcx>, NoSolution> {
1822 desc { "normalizing `{}`", goal.value }
1826 /// Do not call this query directly: invoke `try_normalize_erasing_regions` instead.
1827 query try_normalize_mir_const_after_erasing_regions(
1828 goal: ParamEnvAnd<'tcx, mir::ConstantKind<'tcx>>
1829 ) -> Result<mir::ConstantKind<'tcx>, NoSolution> {
1830 desc { "normalizing `{}`", goal.value }
1834 query implied_outlives_bounds(
1835 goal: CanonicalTyGoal<'tcx>
1837 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, Vec<OutlivesBound<'tcx>>>>,
1840 desc { "computing implied outlives bounds for `{:?}`", goal }
1844 /// Do not call this query directly: invoke `infcx.at().dropck_outlives()` instead.
1845 query dropck_outlives(
1846 goal: CanonicalTyGoal<'tcx>
1848 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, DropckOutlivesResult<'tcx>>>,
1851 desc { "computing dropck types for `{:?}`", goal }
1855 /// Do not call this query directly: invoke `infcx.predicate_may_hold()` or
1856 /// `infcx.predicate_must_hold()` instead.
1857 query evaluate_obligation(
1858 goal: CanonicalPredicateGoal<'tcx>
1859 ) -> Result<traits::EvaluationResult, traits::OverflowError> {
1860 desc { "evaluating trait selection obligation `{}`", goal.value.value }
1863 query evaluate_goal(
1864 goal: traits::CanonicalChalkEnvironmentAndGoal<'tcx>
1866 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1869 desc { "evaluating trait selection obligation `{}`", goal.value }
1872 /// Do not call this query directly: part of the `Eq` type-op
1873 query type_op_ascribe_user_type(
1874 goal: CanonicalTypeOpAscribeUserTypeGoal<'tcx>
1876 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1879 desc { "evaluating `type_op_ascribe_user_type` `{:?}`", goal }
1883 /// Do not call this query directly: part of the `Eq` type-op
1885 goal: CanonicalTypeOpEqGoal<'tcx>
1887 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1890 desc { "evaluating `type_op_eq` `{:?}`", goal }
1894 /// Do not call this query directly: part of the `Subtype` type-op
1895 query type_op_subtype(
1896 goal: CanonicalTypeOpSubtypeGoal<'tcx>
1898 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1901 desc { "evaluating `type_op_subtype` `{:?}`", goal }
1905 /// Do not call this query directly: part of the `ProvePredicate` type-op
1906 query type_op_prove_predicate(
1907 goal: CanonicalTypeOpProvePredicateGoal<'tcx>
1909 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1912 desc { "evaluating `type_op_prove_predicate` `{:?}`", goal }
1915 /// Do not call this query directly: part of the `Normalize` type-op
1916 query type_op_normalize_ty(
1917 goal: CanonicalTypeOpNormalizeGoal<'tcx, Ty<'tcx>>
1919 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, Ty<'tcx>>>,
1922 desc { "normalizing `{:?}`", goal }
1926 /// Do not call this query directly: part of the `Normalize` type-op
1927 query type_op_normalize_predicate(
1928 goal: CanonicalTypeOpNormalizeGoal<'tcx, ty::Predicate<'tcx>>
1930 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ty::Predicate<'tcx>>>,
1933 desc { "normalizing `{:?}`", goal }
1937 /// Do not call this query directly: part of the `Normalize` type-op
1938 query type_op_normalize_poly_fn_sig(
1939 goal: CanonicalTypeOpNormalizeGoal<'tcx, ty::PolyFnSig<'tcx>>
1941 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ty::PolyFnSig<'tcx>>>,
1944 desc { "normalizing `{:?}`", goal }
1948 /// Do not call this query directly: part of the `Normalize` type-op
1949 query type_op_normalize_fn_sig(
1950 goal: CanonicalTypeOpNormalizeGoal<'tcx, ty::FnSig<'tcx>>
1952 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ty::FnSig<'tcx>>>,
1955 desc { "normalizing `{:?}`", goal }
1959 query subst_and_check_impossible_predicates(key: (DefId, SubstsRef<'tcx>)) -> bool {
1961 "impossible substituted predicates:`{}`",
1962 tcx.def_path_str(key.0)
1966 query method_autoderef_steps(
1967 goal: CanonicalTyGoal<'tcx>
1968 ) -> MethodAutoderefStepsResult<'tcx> {
1969 desc { "computing autoderef types for `{:?}`", goal }
1973 query supported_target_features(_: CrateNum) -> FxHashMap<String, Option<Symbol>> {
1974 storage(ArenaCacheSelector<'tcx>)
1976 desc { "looking up supported target features" }
1979 /// Get an estimate of the size of an InstanceDef based on its MIR for CGU partitioning.
1980 query instance_def_size_estimate(def: ty::InstanceDef<'tcx>)
1982 desc { |tcx| "estimating size for `{}`", tcx.def_path_str(def.def_id()) }
1985 query features_query(_: ()) -> &'tcx rustc_feature::Features {
1987 desc { "looking up enabled feature gates" }
1990 /// Attempt to resolve the given `DefId` to an `Instance`, for the
1991 /// given generics args (`SubstsRef`), returning one of:
1992 /// * `Ok(Some(instance))` on success
1993 /// * `Ok(None)` when the `SubstsRef` are still too generic,
1994 /// and therefore don't allow finding the final `Instance`
1995 /// * `Err(ErrorGuaranteed)` when the `Instance` resolution process
1996 /// couldn't complete due to errors elsewhere - this is distinct
1997 /// from `Ok(None)` to avoid misleading diagnostics when an error
1998 /// has already been/will be emitted, for the original cause
1999 query resolve_instance(
2000 key: ty::ParamEnvAnd<'tcx, (DefId, SubstsRef<'tcx>)>
2001 ) -> Result<Option<ty::Instance<'tcx>>, ErrorGuaranteed> {
2002 desc { "resolving instance `{}`", ty::Instance::new(key.value.0, key.value.1) }
2006 query resolve_instance_of_const_arg(
2007 key: ty::ParamEnvAnd<'tcx, (LocalDefId, DefId, SubstsRef<'tcx>)>
2008 ) -> Result<Option<ty::Instance<'tcx>>, ErrorGuaranteed> {
2010 "resolving instance of the const argument `{}`",
2011 ty::Instance::new(key.value.0.to_def_id(), key.value.2),
2016 query normalize_opaque_types(key: &'tcx ty::List<ty::Predicate<'tcx>>) -> &'tcx ty::List<ty::Predicate<'tcx>> {
2017 desc { "normalizing opaque types in {:?}", key }
2020 /// Checks whether a type is definitely uninhabited. This is
2021 /// conservative: for some types that are uninhabited we return `false`,
2022 /// but we only return `true` for types that are definitely uninhabited.
2023 /// `ty.conservative_is_privately_uninhabited` implies that any value of type `ty`
2024 /// will be `Abi::Uninhabited`. (Note that uninhabited types may have nonzero
2025 /// size, to account for partial initialisation. See #49298 for details.)
2026 query conservative_is_privately_uninhabited(key: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
2027 desc { "conservatively checking if {:?} is privately uninhabited", key }
2031 query limits(key: ()) -> Limits {
2032 desc { "looking up limits" }
2035 /// Performs an HIR-based well-formed check on the item with the given `HirId`. If
2036 /// we get an `Unimplemented` error that matches the provided `Predicate`, return
2037 /// the cause of the newly created obligation.
2039 /// This is only used by error-reporting code to get a better cause (in particular, a better
2040 /// span) for an *existing* error. Therefore, it is best-effort, and may never handle
2041 /// all of the cases that the normal `ty::Ty`-based wfcheck does. This is fine,
2042 /// because the `ty::Ty`-based wfcheck is always run.
2043 query diagnostic_hir_wf_check(key: (ty::Predicate<'tcx>, traits::WellFormedLoc)) -> Option<traits::ObligationCause<'tcx>> {
2044 storage(ArenaCacheSelector<'tcx>)
2047 desc { "performing HIR wf-checking for predicate {:?} at item {:?}", key.0, key.1 }
2051 /// The list of backend features computed from CLI flags (`-Ctarget-cpu`, `-Ctarget-feature`,
2052 /// `--target` and similar).
2053 query global_backend_features(_: ()) -> Vec<String> {
2054 storage(ArenaCacheSelector<'tcx>)
2056 desc { "computing the backend features for CLI flags" }
2059 query generator_diagnostic_data(key: DefId) -> Option<GeneratorDiagnosticData<'tcx>> {
2060 storage(ArenaCacheSelector<'tcx>)
2061 desc { |tcx| "looking up generator diagnostic data of `{}`", tcx.def_path_str(key) }
2062 separate_provide_extern