1 // Each of these queries corresponds to a function pointer field in the
2 // `Providers` struct for requesting a value of that type, and a method
3 // on `tcx: TyCtxt` (and `tcx.at(span)`) for doing that request in a way
4 // which memoizes and does dep-graph tracking, wrapping around the actual
5 // `Providers` that the driver creates (using several `rustc_*` crates).
7 // The result type of each query must implement `Clone`, and additionally
8 // `ty::query::values::Value`, which produces an appropriate placeholder
9 // (error) value if the query resulted in a query cycle.
10 // Queries marked with `fatal_cycle` do not need the latter implementation,
11 // as they will raise an fatal error on query cycles instead.
13 query trigger_delay_span_bug(key: DefId) -> () {
14 desc { "trigger a delay span bug" }
17 /// Represents crate as a whole (as distinct from the top-level crate module).
18 /// If you call `hir_crate` (e.g., indirectly by calling `tcx.hir().krate()`),
19 /// we will have to assume that any change means that you need to be recompiled.
20 /// This is because the `hir_crate` query gives you access to all other items.
21 /// To avoid this fate, do not call `tcx.hir().krate()`; instead,
22 /// prefer wrappers like `tcx.visit_all_items_in_krate()`.
23 query hir_crate(key: CrateNum) -> &'tcx Crate<'tcx> {
26 desc { "get the crate HIR" }
29 /// The indexed HIR. This can be conveniently accessed by `tcx.hir()`.
30 /// Avoid calling this query directly.
31 query index_hir(_: CrateNum) -> &'tcx crate::hir::IndexedHir<'tcx> {
37 /// The items in a module.
39 /// This can be conveniently accessed by `tcx.hir().visit_item_likes_in_module`.
40 /// Avoid calling this query directly.
41 query hir_module_items(key: LocalDefId) -> &'tcx hir::ModuleItems {
43 desc { |tcx| "HIR module items in `{}`", tcx.def_path_str(key.to_def_id()) }
46 /// Gives access to the HIR node for the HIR owner `key`.
48 /// This can be conveniently accessed by methods on `tcx.hir()`.
49 /// Avoid calling this query directly.
50 query hir_owner(key: LocalDefId) -> Option<&'tcx crate::hir::Owner<'tcx>> {
52 desc { |tcx| "HIR owner of `{}`", tcx.def_path_str(key.to_def_id()) }
55 /// Gives access to the HIR node's parent for the HIR owner `key`.
57 /// This can be conveniently accessed by methods on `tcx.hir()`.
58 /// Avoid calling this query directly.
59 query hir_owner_parent(key: LocalDefId) -> hir::HirId {
61 desc { |tcx| "HIR parent of `{}`", tcx.def_path_str(key.to_def_id()) }
64 /// Gives access to the HIR nodes and bodies inside the HIR owner `key`.
66 /// This can be conveniently accessed by methods on `tcx.hir()`.
67 /// Avoid calling this query directly.
68 query hir_owner_nodes(key: LocalDefId) -> Option<&'tcx crate::hir::OwnerNodes<'tcx>> {
70 desc { |tcx| "HIR owner items in `{}`", tcx.def_path_str(key.to_def_id()) }
73 /// Gives access to the HIR attributes inside the HIR owner `key`.
75 /// This can be conveniently accessed by methods on `tcx.hir()`.
76 /// Avoid calling this query directly.
77 query hir_attrs(key: LocalDefId) -> rustc_middle::hir::AttributeMap<'tcx> {
79 desc { |tcx| "HIR owner attributes in `{}`", tcx.def_path_str(key.to_def_id()) }
82 /// Computes the `DefId` of the corresponding const parameter in case the `key` is a
83 /// const argument and returns `None` otherwise.
85 /// ```ignore (incomplete)
86 /// let a = foo::<7>();
87 /// // ^ Calling `opt_const_param_of` for this argument,
89 /// fn foo<const N: usize>()
90 /// // ^ returns this `DefId`.
93 /// // ^ While calling `opt_const_param_of` for other bodies returns `None`.
96 // It looks like caching this query on disk actually slightly
97 // worsened performance in #74376.
99 // Once const generics are more prevalently used, we might want to
100 // consider only caching calls returning `Some`.
101 query opt_const_param_of(key: LocalDefId) -> Option<DefId> {
102 desc { |tcx| "computing the optional const parameter of `{}`", tcx.def_path_str(key.to_def_id()) }
105 /// Given the def_id of a const-generic parameter, computes the associated default const
106 /// parameter. e.g. `fn example<const N: usize=3>` called on `N` would return `3`.
107 query const_param_default(param: DefId) -> &'tcx ty::Const<'tcx> {
108 desc { |tcx| "compute const default for a given parameter `{}`", tcx.def_path_str(param) }
111 /// Records the type of every item.
112 query type_of(key: DefId) -> Ty<'tcx> {
113 desc { |tcx| "computing type of `{}`", tcx.def_path_str(key) }
114 cache_on_disk_if { key.is_local() }
117 query analysis(key: CrateNum) -> Result<(), ErrorReported> {
119 desc { "running analysis passes on this crate" }
122 /// Maps from the `DefId` of an item (trait/struct/enum/fn) to its
123 /// associated generics.
124 query generics_of(key: DefId) -> ty::Generics {
125 desc { |tcx| "computing generics of `{}`", tcx.def_path_str(key) }
126 storage(ArenaCacheSelector<'tcx>)
127 cache_on_disk_if { key.is_local() }
130 /// Maps from the `DefId` of an item (trait/struct/enum/fn) to the
131 /// predicates (where-clauses) that must be proven true in order
132 /// to reference it. This is almost always the "predicates query"
135 /// `predicates_of` builds on `predicates_defined_on` -- in fact,
136 /// it is almost always the same as that query, except for the
137 /// case of traits. For traits, `predicates_of` contains
138 /// an additional `Self: Trait<...>` predicate that users don't
139 /// actually write. This reflects the fact that to invoke the
140 /// trait (e.g., via `Default::default`) you must supply types
141 /// that actually implement the trait. (However, this extra
142 /// predicate gets in the way of some checks, which are intended
143 /// to operate over only the actual where-clauses written by the
145 query predicates_of(key: DefId) -> ty::GenericPredicates<'tcx> {
146 desc { |tcx| "computing predicates of `{}`", tcx.def_path_str(key) }
147 cache_on_disk_if { key.is_local() }
150 /// Returns the list of bounds that can be used for
151 /// `SelectionCandidate::ProjectionCandidate(_)` and
152 /// `ProjectionTyCandidate::TraitDef`.
153 /// Specifically this is the bounds written on the trait's type
154 /// definition, or those after the `impl` keyword
156 /// ```ignore (incomplete)
157 /// type X: Bound + 'lt
159 /// impl Debug + Display
160 /// // ^^^^^^^^^^^^^^^
163 /// `key` is the `DefId` of the associated type or opaque type.
165 /// Bounds from the parent (e.g. with nested impl trait) are not included.
166 query explicit_item_bounds(key: DefId) -> &'tcx [(ty::Predicate<'tcx>, Span)] {
167 desc { |tcx| "finding item bounds for `{}`", tcx.def_path_str(key) }
170 /// Elaborated version of the predicates from `explicit_item_bounds`.
176 /// type MyAType: Eq + ?Sized;
180 /// `explicit_item_bounds` returns `[<Self as MyTrait>::MyAType: Eq]`,
181 /// and `item_bounds` returns
184 /// <Self as Trait>::MyAType: Eq,
185 /// <Self as Trait>::MyAType: PartialEq<<Self as Trait>::MyAType>
189 /// Bounds from the parent (e.g. with nested impl trait) are not included.
190 query item_bounds(key: DefId) -> &'tcx ty::List<ty::Predicate<'tcx>> {
191 desc { |tcx| "elaborating item bounds for `{}`", tcx.def_path_str(key) }
194 query projection_ty_from_predicates(key: (DefId, DefId)) -> Option<ty::ProjectionTy<'tcx>> {
195 desc { |tcx| "finding projection type inside predicates of `{}`", tcx.def_path_str(key.0) }
198 query native_libraries(_: CrateNum) -> Lrc<Vec<NativeLib>> {
199 desc { "looking up the native libraries of a linked crate" }
202 query lint_levels(_: CrateNum) -> LintLevelMap {
203 storage(ArenaCacheSelector<'tcx>)
205 desc { "computing the lint levels for items in this crate" }
208 query parent_module_from_def_id(key: LocalDefId) -> LocalDefId {
210 desc { |tcx| "parent module of `{}`", tcx.def_path_str(key.to_def_id()) }
213 /// Internal helper query. Use `tcx.expansion_that_defined` instead
214 query expn_that_defined(key: DefId) -> rustc_span::ExpnId {
215 desc { |tcx| "expansion that defined `{}`", tcx.def_path_str(key) }
218 query is_panic_runtime(_: CrateNum) -> bool {
220 desc { "checking if the crate is_panic_runtime" }
223 /// Set of all the `DefId`s in this crate that have MIR associated with
224 /// them. This includes all the body owners, but also things like struct
226 query mir_keys(_: CrateNum) -> FxHashSet<LocalDefId> {
227 storage(ArenaCacheSelector<'tcx>)
228 desc { "getting a list of all mir_keys" }
231 /// Maps DefId's that have an associated `mir::Body` to the result
232 /// of the MIR const-checking pass. This is the set of qualifs in
233 /// the final value of a `const`.
234 query mir_const_qualif(key: DefId) -> mir::ConstQualifs {
235 desc { |tcx| "const checking `{}`", tcx.def_path_str(key) }
236 cache_on_disk_if { key.is_local() }
238 query mir_const_qualif_const_arg(
239 key: (LocalDefId, DefId)
240 ) -> mir::ConstQualifs {
242 |tcx| "const checking the const argument `{}`",
243 tcx.def_path_str(key.0.to_def_id())
247 /// Fetch the MIR for a given `DefId` right after it's built - this includes
248 /// unreachable code.
249 query mir_built(key: ty::WithOptConstParam<LocalDefId>) -> &'tcx Steal<mir::Body<'tcx>> {
250 desc { |tcx| "building MIR for `{}`", tcx.def_path_str(key.did.to_def_id()) }
253 /// Fetch the MIR for a given `DefId` up till the point where it is
254 /// ready for const qualification.
256 /// See the README for the `mir` module for details.
257 query mir_const(key: ty::WithOptConstParam<LocalDefId>) -> &'tcx Steal<mir::Body<'tcx>> {
259 |tcx| "processing MIR for {}`{}`",
260 if key.const_param_did.is_some() { "the const argument " } else { "" },
261 tcx.def_path_str(key.did.to_def_id()),
266 /// Try to build an abstract representation of the given constant.
267 query mir_abstract_const(
269 ) -> Result<Option<&'tcx [mir::abstract_const::Node<'tcx>]>, ErrorReported> {
271 |tcx| "building an abstract representation for {}", tcx.def_path_str(key),
274 /// Try to build an abstract representation of the given constant.
275 query mir_abstract_const_of_const_arg(
276 key: (LocalDefId, DefId)
277 ) -> Result<Option<&'tcx [mir::abstract_const::Node<'tcx>]>, ErrorReported> {
280 "building an abstract representation for the const argument {}",
281 tcx.def_path_str(key.0.to_def_id()),
285 query try_unify_abstract_consts(key: (
286 (ty::WithOptConstParam<DefId>, SubstsRef<'tcx>),
287 (ty::WithOptConstParam<DefId>, SubstsRef<'tcx>)
290 |tcx| "trying to unify the generic constants {} and {}",
291 tcx.def_path_str(key.0.0.did), tcx.def_path_str(key.1.0.did)
295 query mir_drops_elaborated_and_const_checked(
296 key: ty::WithOptConstParam<LocalDefId>
297 ) -> &'tcx Steal<mir::Body<'tcx>> {
299 desc { |tcx| "elaborating drops for `{}`", tcx.def_path_str(key.did.to_def_id()) }
304 ) -> &'tcx mir::Body<'tcx> {
305 desc { |tcx| "caching mir of `{}` for CTFE", tcx.def_path_str(key) }
306 cache_on_disk_if { key.is_local() }
309 query mir_for_ctfe_of_const_arg(key: (LocalDefId, DefId)) -> &'tcx mir::Body<'tcx> {
311 |tcx| "MIR for CTFE of the const argument `{}`",
312 tcx.def_path_str(key.0.to_def_id())
316 query mir_promoted(key: ty::WithOptConstParam<LocalDefId>) ->
318 &'tcx Steal<mir::Body<'tcx>>,
319 &'tcx Steal<IndexVec<mir::Promoted, mir::Body<'tcx>>>
323 |tcx| "processing {}`{}`",
324 if key.const_param_did.is_some() { "the const argument " } else { "" },
325 tcx.def_path_str(key.did.to_def_id()),
329 /// MIR after our optimization passes have run. This is MIR that is ready
330 /// for codegen. This is also the only query that can fetch non-local MIR, at present.
331 query optimized_mir(key: DefId) -> &'tcx mir::Body<'tcx> {
332 desc { |tcx| "optimizing MIR for `{}`", tcx.def_path_str(key) }
333 cache_on_disk_if { key.is_local() }
336 /// Returns coverage summary info for a function, after executing the `InstrumentCoverage`
337 /// MIR pass (assuming the -Zinstrument-coverage option is enabled).
338 query coverageinfo(key: DefId) -> mir::CoverageInfo {
339 desc { |tcx| "retrieving coverage info from MIR for `{}`", tcx.def_path_str(key) }
340 storage(ArenaCacheSelector<'tcx>)
341 cache_on_disk_if { key.is_local() }
344 /// Returns the name of the file that contains the function body, if instrumented for coverage.
345 query covered_file_name(key: DefId) -> Option<Symbol> {
347 |tcx| "retrieving the covered file name, if instrumented, for `{}`",
348 tcx.def_path_str(key)
350 storage(ArenaCacheSelector<'tcx>)
351 cache_on_disk_if { key.is_local() }
354 /// Returns the `CodeRegions` for a function that has instrumented coverage, in case the
355 /// function was optimized out before codegen, and before being added to the Coverage Map.
356 query covered_code_regions(key: DefId) -> Vec<&'tcx mir::coverage::CodeRegion> {
358 |tcx| "retrieving the covered `CodeRegion`s, if instrumented, for `{}`",
359 tcx.def_path_str(key)
361 storage(ArenaCacheSelector<'tcx>)
362 cache_on_disk_if { key.is_local() }
365 /// The `DefId` is the `DefId` of the containing MIR body. Promoteds do not have their own
366 /// `DefId`. This function returns all promoteds in the specified body. The body references
367 /// promoteds by the `DefId` and the `mir::Promoted` index. This is necessary, because
368 /// after inlining a body may refer to promoteds from other bodies. In that case you still
369 /// need to use the `DefId` of the original body.
370 query promoted_mir(key: DefId) -> &'tcx IndexVec<mir::Promoted, mir::Body<'tcx>> {
371 desc { |tcx| "optimizing promoted MIR for `{}`", tcx.def_path_str(key) }
372 cache_on_disk_if { key.is_local() }
374 query promoted_mir_of_const_arg(
375 key: (LocalDefId, DefId)
376 ) -> &'tcx IndexVec<mir::Promoted, mir::Body<'tcx>> {
378 |tcx| "optimizing promoted MIR for the const argument `{}`",
379 tcx.def_path_str(key.0.to_def_id()),
383 /// Erases regions from `ty` to yield a new type.
384 /// Normally you would just use `tcx.erase_regions(value)`,
385 /// however, which uses this query as a kind of cache.
386 query erase_regions_ty(ty: Ty<'tcx>) -> Ty<'tcx> {
387 // This query is not expected to have input -- as a result, it
388 // is not a good candidates for "replay" because it is essentially a
389 // pure function of its input (and hence the expectation is that
390 // no caller would be green **apart** from just these
391 // queries). Making it anonymous avoids hashing the result, which
392 // may save a bit of time.
394 desc { "erasing regions from `{:?}`", ty }
397 query wasm_import_module_map(_: CrateNum) -> FxHashMap<DefId, String> {
398 storage(ArenaCacheSelector<'tcx>)
399 desc { "wasm import module map" }
402 /// Maps from the `DefId` of an item (trait/struct/enum/fn) to the
403 /// predicates (where-clauses) directly defined on it. This is
404 /// equal to the `explicit_predicates_of` predicates plus the
405 /// `inferred_outlives_of` predicates.
406 query predicates_defined_on(key: DefId) -> ty::GenericPredicates<'tcx> {
407 desc { |tcx| "computing predicates of `{}`", tcx.def_path_str(key) }
410 /// Returns everything that looks like a predicate written explicitly
411 /// by the user on a trait item.
413 /// Traits are unusual, because predicates on associated types are
414 /// converted into bounds on that type for backwards compatibility:
416 /// trait X where Self::U: Copy { type U; }
420 /// trait X { type U: Copy; }
422 /// `explicit_predicates_of` and `explicit_item_bounds` will then take
423 /// the appropriate subsets of the predicates here.
424 query trait_explicit_predicates_and_bounds(key: LocalDefId) -> ty::GenericPredicates<'tcx> {
425 desc { |tcx| "computing explicit predicates of trait `{}`", tcx.def_path_str(key.to_def_id()) }
428 /// Returns the predicates written explicitly by the user.
429 query explicit_predicates_of(key: DefId) -> ty::GenericPredicates<'tcx> {
430 desc { |tcx| "computing explicit predicates of `{}`", tcx.def_path_str(key) }
433 /// Returns the inferred outlives predicates (e.g., for `struct
434 /// Foo<'a, T> { x: &'a T }`, this would return `T: 'a`).
435 query inferred_outlives_of(key: DefId) -> &'tcx [(ty::Predicate<'tcx>, Span)] {
436 desc { |tcx| "computing inferred outlives predicates of `{}`", tcx.def_path_str(key) }
439 /// Maps from the `DefId` of a trait to the list of
440 /// super-predicates. This is a subset of the full list of
441 /// predicates. We store these in a separate map because we must
442 /// evaluate them even during type conversion, often before the
443 /// full predicates are available (note that supertraits have
444 /// additional acyclicity requirements).
445 query super_predicates_of(key: DefId) -> ty::GenericPredicates<'tcx> {
446 desc { |tcx| "computing the super predicates of `{}`", tcx.def_path_str(key) }
449 /// The `Option<Ident>` is the name of an associated type. If it is `None`, then this query
450 /// returns the full set of predicates. If `Some<Ident>`, then the query returns only the
451 /// subset of super-predicates that reference traits that define the given associated type.
452 /// This is used to avoid cycles in resolving types like `T::Item`.
453 query super_predicates_that_define_assoc_type(key: (DefId, Option<rustc_span::symbol::Ident>)) -> ty::GenericPredicates<'tcx> {
454 desc { |tcx| "computing the super traits of `{}`{}",
455 tcx.def_path_str(key.0),
456 if let Some(assoc_name) = key.1 { format!(" with associated type name `{}`", assoc_name) } else { "".to_string() },
460 /// To avoid cycles within the predicates of a single item we compute
461 /// per-type-parameter predicates for resolving `T::AssocTy`.
462 query type_param_predicates(key: (DefId, LocalDefId, rustc_span::symbol::Ident)) -> ty::GenericPredicates<'tcx> {
463 desc { |tcx| "computing the bounds for type parameter `{}`", {
464 let id = tcx.hir().local_def_id_to_hir_id(key.1);
465 tcx.hir().ty_param_name(id)
469 query trait_def(key: DefId) -> ty::TraitDef {
470 desc { |tcx| "computing trait definition for `{}`", tcx.def_path_str(key) }
471 storage(ArenaCacheSelector<'tcx>)
473 query adt_def(key: DefId) -> &'tcx ty::AdtDef {
474 desc { |tcx| "computing ADT definition for `{}`", tcx.def_path_str(key) }
476 query adt_destructor(key: DefId) -> Option<ty::Destructor> {
477 desc { |tcx| "computing `Drop` impl for `{}`", tcx.def_path_str(key) }
480 // The cycle error here should be reported as an error by `check_representable`.
481 // We consider the type as Sized in the meanwhile to avoid
482 // further errors (done in impl Value for AdtSizedConstraint).
483 // Use `cycle_delay_bug` to delay the cycle error here to be emitted later
484 // in case we accidentally otherwise don't emit an error.
485 query adt_sized_constraint(
487 ) -> AdtSizedConstraint<'tcx> {
488 desc { |tcx| "computing `Sized` constraints for `{}`", tcx.def_path_str(key) }
492 query adt_dtorck_constraint(
494 ) -> Result<DtorckConstraint<'tcx>, NoSolution> {
495 desc { |tcx| "computing drop-check constraints for `{}`", tcx.def_path_str(key) }
498 /// Returns `true` if this is a const fn, use the `is_const_fn` to know whether your crate
499 /// actually sees it as const fn (e.g., the const-fn-ness might be unstable and you might
500 /// not have the feature gate active).
502 /// **Do not call this function manually.** It is only meant to cache the base data for the
503 /// `is_const_fn` function.
504 query is_const_fn_raw(key: DefId) -> bool {
505 desc { |tcx| "checking if item is const fn: `{}`", tcx.def_path_str(key) }
508 /// Returns `true` if this is a const `impl`. **Do not call this function manually.**
510 /// This query caches the base data for the `is_const_impl` helper function, which also
511 /// takes into account stability attributes (e.g., `#[rustc_const_unstable]`).
512 query is_const_impl_raw(key: DefId) -> bool {
513 desc { |tcx| "checking if item is const impl: `{}`", tcx.def_path_str(key) }
516 query asyncness(key: DefId) -> hir::IsAsync {
517 desc { |tcx| "checking if the function is async: `{}`", tcx.def_path_str(key) }
520 /// Returns `true` if calls to the function may be promoted.
522 /// This is either because the function is e.g., a tuple-struct or tuple-variant
523 /// constructor, or because it has the `#[rustc_promotable]` attribute. The attribute should
524 /// be removed in the future in favour of some form of check which figures out whether the
525 /// function does not inspect the bits of any of its arguments (so is essentially just a
526 /// constructor function).
527 query is_promotable_const_fn(key: DefId) -> bool {
528 desc { |tcx| "checking if item is promotable: `{}`", tcx.def_path_str(key) }
531 /// Returns `true` if this is a foreign item (i.e., linked via `extern { ... }`).
532 query is_foreign_item(key: DefId) -> bool {
533 desc { |tcx| "checking if `{}` is a foreign item", tcx.def_path_str(key) }
536 /// Returns `Some(mutability)` if the node pointed to by `def_id` is a static item.
537 query static_mutability(def_id: DefId) -> Option<hir::Mutability> {
538 desc { |tcx| "looking up static mutability of `{}`", tcx.def_path_str(def_id) }
541 /// Returns `Some(generator_kind)` if the node pointed to by `def_id` is a generator.
542 query generator_kind(def_id: DefId) -> Option<hir::GeneratorKind> {
543 desc { |tcx| "looking up generator kind of `{}`", tcx.def_path_str(def_id) }
546 /// Gets a map with the variance of every item; use `item_variance` instead.
547 query crate_variances(_: CrateNum) -> ty::CrateVariancesMap<'tcx> {
548 storage(ArenaCacheSelector<'tcx>)
549 desc { "computing the variances for items in this crate" }
552 /// Maps from the `DefId` of a type or region parameter to its (inferred) variance.
553 query variances_of(def_id: DefId) -> &'tcx [ty::Variance] {
554 desc { |tcx| "computing the variances of `{}`", tcx.def_path_str(def_id) }
557 /// Maps from thee `DefId` of a type to its (inferred) outlives.
558 query inferred_outlives_crate(_: CrateNum)
559 -> ty::CratePredicatesMap<'tcx> {
560 storage(ArenaCacheSelector<'tcx>)
561 desc { "computing the inferred outlives predicates for items in this crate" }
564 /// Maps from an impl/trait `DefId to a list of the `DefId`s of its items.
565 query associated_item_def_ids(key: DefId) -> &'tcx [DefId] {
566 desc { |tcx| "collecting associated items of `{}`", tcx.def_path_str(key) }
569 /// Maps from a trait item to the trait item "descriptor".
570 query associated_item(key: DefId) -> ty::AssocItem {
571 desc { |tcx| "computing associated item data for `{}`", tcx.def_path_str(key) }
572 storage(ArenaCacheSelector<'tcx>)
575 /// Collects the associated items defined on a trait or impl.
576 query associated_items(key: DefId) -> ty::AssocItems<'tcx> {
577 storage(ArenaCacheSelector<'tcx>)
578 desc { |tcx| "collecting associated items of {}", tcx.def_path_str(key) }
581 /// Given an `impl_id`, return the trait it implements.
582 /// Return `None` if this is an inherent impl.
583 query impl_trait_ref(impl_id: DefId) -> Option<ty::TraitRef<'tcx>> {
584 desc { |tcx| "computing trait implemented by `{}`", tcx.def_path_str(impl_id) }
586 query impl_polarity(impl_id: DefId) -> ty::ImplPolarity {
587 desc { |tcx| "computing implementation polarity of `{}`", tcx.def_path_str(impl_id) }
590 query issue33140_self_ty(key: DefId) -> Option<ty::Ty<'tcx>> {
591 desc { |tcx| "computing Self type wrt issue #33140 `{}`", tcx.def_path_str(key) }
594 /// Maps a `DefId` of a type to a list of its inherent impls.
595 /// Contains implementations of methods that are inherent to a type.
596 /// Methods in these implementations don't need to be exported.
597 query inherent_impls(key: DefId) -> &'tcx [DefId] {
598 desc { |tcx| "collecting inherent impls for `{}`", tcx.def_path_str(key) }
602 /// The result of unsafety-checking this `LocalDefId`.
603 query unsafety_check_result(key: LocalDefId) -> &'tcx mir::UnsafetyCheckResult {
604 desc { |tcx| "unsafety-checking `{}`", tcx.def_path_str(key.to_def_id()) }
605 cache_on_disk_if { true }
607 query unsafety_check_result_for_const_arg(key: (LocalDefId, DefId)) -> &'tcx mir::UnsafetyCheckResult {
609 |tcx| "unsafety-checking the const argument `{}`",
610 tcx.def_path_str(key.0.to_def_id())
614 /// HACK: when evaluated, this reports a "unsafe derive on repr(packed)" error.
616 /// Unsafety checking is executed for each method separately, but we only want
617 /// to emit this error once per derive. As there are some impls with multiple
618 /// methods, we use a query for deduplication.
619 query unsafe_derive_on_repr_packed(key: LocalDefId) -> () {
620 desc { |tcx| "processing `{}`", tcx.def_path_str(key.to_def_id()) }
623 /// The signature of functions.
624 query fn_sig(key: DefId) -> ty::PolyFnSig<'tcx> {
625 desc { |tcx| "computing function signature of `{}`", tcx.def_path_str(key) }
628 query lint_mod(key: LocalDefId) -> () {
629 desc { |tcx| "linting {}", describe_as_module(key, tcx) }
632 /// Checks the attributes in the module.
633 query check_mod_attrs(key: LocalDefId) -> () {
634 desc { |tcx| "checking attributes in {}", describe_as_module(key, tcx) }
637 query check_mod_unstable_api_usage(key: LocalDefId) -> () {
638 desc { |tcx| "checking for unstable API usage in {}", describe_as_module(key, tcx) }
641 /// Checks the const bodies in the module for illegal operations (e.g. `if` or `loop`).
642 query check_mod_const_bodies(key: LocalDefId) -> () {
643 desc { |tcx| "checking consts in {}", describe_as_module(key, tcx) }
646 /// Checks the loops in the module.
647 query check_mod_loops(key: LocalDefId) -> () {
648 desc { |tcx| "checking loops in {}", describe_as_module(key, tcx) }
651 query check_mod_naked_functions(key: LocalDefId) -> () {
652 desc { |tcx| "checking naked functions in {}", describe_as_module(key, tcx) }
655 query check_mod_item_types(key: LocalDefId) -> () {
656 desc { |tcx| "checking item types in {}", describe_as_module(key, tcx) }
659 query check_mod_privacy(key: LocalDefId) -> () {
660 desc { |tcx| "checking privacy in {}", describe_as_module(key, tcx) }
663 query check_mod_intrinsics(key: LocalDefId) -> () {
664 desc { |tcx| "checking intrinsics in {}", describe_as_module(key, tcx) }
667 query check_mod_liveness(key: LocalDefId) -> () {
668 desc { |tcx| "checking liveness of variables in {}", describe_as_module(key, tcx) }
671 query check_mod_impl_wf(key: LocalDefId) -> () {
672 desc { |tcx| "checking that impls are well-formed in {}", describe_as_module(key, tcx) }
675 query collect_mod_item_types(key: LocalDefId) -> () {
676 desc { |tcx| "collecting item types in {}", describe_as_module(key, tcx) }
679 /// Caches `CoerceUnsized` kinds for impls on custom types.
680 query coerce_unsized_info(key: DefId)
681 -> ty::adjustment::CoerceUnsizedInfo {
682 desc { |tcx| "computing CoerceUnsized info for `{}`", tcx.def_path_str(key) }
685 query typeck_item_bodies(_: CrateNum) -> () {
686 desc { "type-checking all item bodies" }
689 query typeck(key: LocalDefId) -> &'tcx ty::TypeckResults<'tcx> {
690 desc { |tcx| "type-checking `{}`", tcx.def_path_str(key.to_def_id()) }
691 cache_on_disk_if { true }
693 query typeck_const_arg(
694 key: (LocalDefId, DefId)
695 ) -> &'tcx ty::TypeckResults<'tcx> {
697 |tcx| "type-checking the const argument `{}`",
698 tcx.def_path_str(key.0.to_def_id()),
701 query diagnostic_only_typeck(key: LocalDefId) -> &'tcx ty::TypeckResults<'tcx> {
702 desc { |tcx| "type-checking `{}`", tcx.def_path_str(key.to_def_id()) }
703 cache_on_disk_if { true }
704 load_cached(tcx, id) {
705 let typeck_results: Option<ty::TypeckResults<'tcx>> = tcx
706 .on_disk_cache.as_ref()
707 .and_then(|c| c.try_load_query_result(*tcx, id));
709 typeck_results.map(|x| &*tcx.arena.alloc(x))
713 query used_trait_imports(key: LocalDefId) -> &'tcx FxHashSet<LocalDefId> {
714 desc { |tcx| "used_trait_imports `{}`", tcx.def_path_str(key.to_def_id()) }
715 cache_on_disk_if { true }
718 query has_typeck_results(def_id: DefId) -> bool {
719 desc { |tcx| "checking whether `{}` has a body", tcx.def_path_str(def_id) }
722 query coherent_trait(def_id: DefId) -> () {
723 desc { |tcx| "coherence checking all impls of trait `{}`", tcx.def_path_str(def_id) }
726 /// Borrow-checks the function body. If this is a closure, returns
727 /// additional requirements that the closure's creator must verify.
728 query mir_borrowck(key: LocalDefId) -> &'tcx mir::BorrowCheckResult<'tcx> {
729 desc { |tcx| "borrow-checking `{}`", tcx.def_path_str(key.to_def_id()) }
730 cache_on_disk_if(tcx, opt_result) {
731 tcx.is_closure(key.to_def_id())
732 || opt_result.map_or(false, |r| !r.concrete_opaque_types.is_empty())
735 query mir_borrowck_const_arg(key: (LocalDefId, DefId)) -> &'tcx mir::BorrowCheckResult<'tcx> {
737 |tcx| "borrow-checking the const argument`{}`",
738 tcx.def_path_str(key.0.to_def_id())
742 /// Gets a complete map from all types to their inherent impls.
743 /// Not meant to be used directly outside of coherence.
744 /// (Defined only for `LOCAL_CRATE`.)
745 query crate_inherent_impls(k: CrateNum)
746 -> CrateInherentImpls {
747 storage(ArenaCacheSelector<'tcx>)
749 desc { "all inherent impls defined in crate `{:?}`", k }
752 /// Checks all types in the crate for overlap in their inherent impls. Reports errors.
753 /// Not meant to be used directly outside of coherence.
754 /// (Defined only for `LOCAL_CRATE`.)
755 query crate_inherent_impls_overlap_check(_: CrateNum)
758 desc { "check for overlap between inherent impls defined in this crate" }
761 /// Check whether the function has any recursion that could cause the inliner to trigger
762 /// a cycle. Returns the call stack causing the cycle. The call stack does not contain the
763 /// current function, just all intermediate functions.
764 query mir_callgraph_reachable(key: (ty::Instance<'tcx>, LocalDefId)) -> bool {
767 "computing if `{}` (transitively) calls `{}`",
769 tcx.def_path_str(key.1.to_def_id()),
773 /// Obtain all the calls into other local functions
774 query mir_inliner_callees(key: ty::InstanceDef<'tcx>) -> &'tcx [(DefId, SubstsRef<'tcx>)] {
777 "computing all local function calls in `{}`",
778 tcx.def_path_str(key.def_id()),
782 /// Evaluates a constant and returns the computed allocation.
784 /// **Do not use this** directly, use the `tcx.eval_static_initializer` wrapper.
785 query eval_to_allocation_raw(key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>)
786 -> EvalToAllocationRawResult<'tcx> {
788 "const-evaluating + checking `{}`",
789 key.value.display(tcx)
791 cache_on_disk_if { true }
794 /// Evaluates const items or anonymous constants
795 /// (such as enum variant explicit discriminants or array lengths)
796 /// into a representation suitable for the type system and const generics.
798 /// **Do not use this** directly, use one of the following wrappers: `tcx.const_eval_poly`,
799 /// `tcx.const_eval_resolve`, `tcx.const_eval_instance`, or `tcx.const_eval_global_id`.
800 query eval_to_const_value_raw(key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>)
801 -> EvalToConstValueResult<'tcx> {
803 "simplifying constant for the type system `{}`",
804 key.value.display(tcx)
806 cache_on_disk_if { true }
809 /// Convert an evaluated constant to a type level constant or
810 /// return `None` if that is not possible.
811 query const_to_valtree(
812 key: ty::ParamEnvAnd<'tcx, ConstAlloc<'tcx>>
813 ) -> Option<ty::ValTree<'tcx>> {
814 desc { "destructure constant" }
817 /// Destructure a constant ADT or array into its variant index and its
819 query destructure_const(
820 key: ty::ParamEnvAnd<'tcx, &'tcx ty::Const<'tcx>>
821 ) -> mir::DestructuredConst<'tcx> {
822 desc { "destructure constant" }
825 /// Dereference a constant reference or raw pointer and turn the result into a constant
828 key: ty::ParamEnvAnd<'tcx, &'tcx ty::Const<'tcx>>
829 ) -> &'tcx ty::Const<'tcx> {
830 desc { "deref constant" }
833 query const_caller_location(key: (rustc_span::Symbol, u32, u32)) -> ConstValue<'tcx> {
834 desc { "get a &core::panic::Location referring to a span" }
838 key: LitToConstInput<'tcx>
839 ) -> Result<&'tcx ty::Const<'tcx>, LitToConstError> {
840 desc { "converting literal to const" }
843 query check_match(key: DefId) {
844 desc { |tcx| "match-checking `{}`", tcx.def_path_str(key) }
845 cache_on_disk_if { key.is_local() }
848 /// Performs part of the privacy check and computes "access levels".
849 query privacy_access_levels(_: CrateNum) -> &'tcx AccessLevels {
851 desc { "privacy access levels" }
853 query check_private_in_public(_: CrateNum) -> () {
855 desc { "checking for private elements in public interfaces" }
858 query reachable_set(_: CrateNum) -> FxHashSet<LocalDefId> {
859 storage(ArenaCacheSelector<'tcx>)
860 desc { "reachability" }
863 /// Per-body `region::ScopeTree`. The `DefId` should be the owner `DefId` for the body;
864 /// in the case of closures, this will be redirected to the enclosing function.
865 query region_scope_tree(def_id: DefId) -> &'tcx region::ScopeTree {
866 desc { |tcx| "computing drop scopes for `{}`", tcx.def_path_str(def_id) }
869 query mir_shims(key: ty::InstanceDef<'tcx>) -> mir::Body<'tcx> {
870 storage(ArenaCacheSelector<'tcx>)
871 desc { |tcx| "generating MIR shim for `{}`", tcx.def_path_str(key.def_id()) }
874 /// The `symbol_name` query provides the symbol name for calling a
875 /// given instance from the local crate. In particular, it will also
876 /// look up the correct symbol name of instances from upstream crates.
877 query symbol_name(key: ty::Instance<'tcx>) -> ty::SymbolName<'tcx> {
878 desc { "computing the symbol for `{}`", key }
879 cache_on_disk_if { true }
882 query opt_def_kind(def_id: DefId) -> Option<DefKind> {
883 desc { |tcx| "looking up definition kind of `{}`", tcx.def_path_str(def_id) }
886 query def_span(def_id: DefId) -> Span {
887 desc { |tcx| "looking up span for `{}`", tcx.def_path_str(def_id) }
888 // FIXME(mw): DefSpans are not really inputs since they are derived from
889 // HIR. But at the moment HIR hashing still contains some hacks that allow
890 // to make type debuginfo to be source location independent. Declaring
891 // DefSpan an input makes sure that changes to these are always detected
892 // regardless of HIR hashing.
896 query def_ident_span(def_id: DefId) -> Option<Span> {
897 desc { |tcx| "looking up span for `{}`'s identifier", tcx.def_path_str(def_id) }
900 query lookup_stability(def_id: DefId) -> Option<&'tcx attr::Stability> {
901 desc { |tcx| "looking up stability of `{}`", tcx.def_path_str(def_id) }
904 query lookup_const_stability(def_id: DefId) -> Option<&'tcx attr::ConstStability> {
905 desc { |tcx| "looking up const stability of `{}`", tcx.def_path_str(def_id) }
908 query lookup_deprecation_entry(def_id: DefId) -> Option<DeprecationEntry> {
909 desc { |tcx| "checking whether `{}` is deprecated", tcx.def_path_str(def_id) }
912 query item_attrs(def_id: DefId) -> &'tcx [ast::Attribute] {
913 desc { |tcx| "collecting attributes of `{}`", tcx.def_path_str(def_id) }
916 query codegen_fn_attrs(def_id: DefId) -> CodegenFnAttrs {
917 desc { |tcx| "computing codegen attributes of `{}`", tcx.def_path_str(def_id) }
918 storage(ArenaCacheSelector<'tcx>)
919 cache_on_disk_if { true }
922 query fn_arg_names(def_id: DefId) -> &'tcx [rustc_span::symbol::Ident] {
923 desc { |tcx| "looking up function parameter names for `{}`", tcx.def_path_str(def_id) }
925 /// Gets the rendered value of the specified constant or associated constant.
927 query rendered_const(def_id: DefId) -> String {
928 desc { |tcx| "rendering constant intializer of `{}`", tcx.def_path_str(def_id) }
930 query impl_parent(def_id: DefId) -> Option<DefId> {
931 desc { |tcx| "computing specialization parent impl of `{}`", tcx.def_path_str(def_id) }
934 /// Given an `associated_item`, find the trait it belongs to.
935 /// Return `None` if the `DefId` is not an associated item.
936 query trait_of_item(associated_item: DefId) -> Option<DefId> {
937 desc { |tcx| "finding trait defining `{}`", tcx.def_path_str(associated_item) }
940 query is_ctfe_mir_available(key: DefId) -> bool {
941 desc { |tcx| "checking if item has ctfe mir available: `{}`", tcx.def_path_str(key) }
943 query is_mir_available(key: DefId) -> bool {
944 desc { |tcx| "checking if item has mir available: `{}`", tcx.def_path_str(key) }
947 query vtable_methods(key: ty::PolyTraitRef<'tcx>)
948 -> &'tcx [Option<(DefId, SubstsRef<'tcx>)>] {
949 desc { |tcx| "finding all methods for trait {}", tcx.def_path_str(key.def_id()) }
952 query codegen_fulfill_obligation(
953 key: (ty::ParamEnv<'tcx>, ty::PolyTraitRef<'tcx>)
954 ) -> Result<ImplSource<'tcx, ()>, ErrorReported> {
955 cache_on_disk_if { true }
957 "checking if `{}` fulfills its obligations",
958 tcx.def_path_str(key.1.def_id())
962 /// Return all `impl` blocks in the current crate.
964 /// To allow caching this between crates, you must pass in [`LOCAL_CRATE`] as the crate number.
965 /// Passing in any other crate will cause an ICE.
967 /// [`LOCAL_CRATE`]: rustc_hir::def_id::LOCAL_CRATE
968 query all_local_trait_impls(local_crate: CrateNum) -> &'tcx BTreeMap<DefId, Vec<LocalDefId>> {
969 desc { "local trait impls" }
972 /// Given a trait `trait_id`, return all known `impl` blocks.
973 query trait_impls_of(trait_id: DefId) -> ty::trait_def::TraitImpls {
974 storage(ArenaCacheSelector<'tcx>)
975 desc { |tcx| "trait impls of `{}`", tcx.def_path_str(trait_id) }
978 query specialization_graph_of(trait_id: DefId) -> specialization_graph::Graph {
979 storage(ArenaCacheSelector<'tcx>)
980 desc { |tcx| "building specialization graph of trait `{}`", tcx.def_path_str(trait_id) }
981 cache_on_disk_if { true }
983 query object_safety_violations(trait_id: DefId) -> &'tcx [traits::ObjectSafetyViolation] {
984 desc { |tcx| "determine object safety of trait `{}`", tcx.def_path_str(trait_id) }
987 /// Gets the ParameterEnvironment for a given item; this environment
988 /// will be in "user-facing" mode, meaning that it is suitable for
989 /// type-checking etc, and it does not normalize specializable
990 /// associated types. This is almost always what you want,
991 /// unless you are doing MIR optimizations, in which case you
992 /// might want to use `reveal_all()` method to change modes.
993 query param_env(def_id: DefId) -> ty::ParamEnv<'tcx> {
994 desc { |tcx| "computing normalized predicates of `{}`", tcx.def_path_str(def_id) }
997 /// Like `param_env`, but returns the `ParamEnv` in `Reveal::All` mode.
998 /// Prefer this over `tcx.param_env(def_id).with_reveal_all_normalized(tcx)`,
999 /// as this method is more efficient.
1000 query param_env_reveal_all_normalized(def_id: DefId) -> ty::ParamEnv<'tcx> {
1001 desc { |tcx| "computing revealed normalized predicates of `{}`", tcx.def_path_str(def_id) }
1004 /// Trait selection queries. These are best used by invoking `ty.is_copy_modulo_regions()`,
1005 /// `ty.is_copy()`, etc, since that will prune the environment where possible.
1006 query is_copy_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1007 desc { "computing whether `{}` is `Copy`", env.value }
1009 /// Query backing `TyS::is_sized`.
1010 query is_sized_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1011 desc { "computing whether `{}` is `Sized`", env.value }
1013 /// Query backing `TyS::is_freeze`.
1014 query is_freeze_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1015 desc { "computing whether `{}` is freeze", env.value }
1017 /// Query backing `TyS::is_unpin`.
1018 query is_unpin_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1019 desc { "computing whether `{}` is `Unpin`", env.value }
1021 /// Query backing `TyS::needs_drop`.
1022 query needs_drop_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1023 desc { "computing whether `{}` needs drop", env.value }
1026 /// Query backing `TyS::is_structural_eq_shallow`.
1028 /// This is only correct for ADTs. Call `is_structural_eq_shallow` to handle all types
1030 query has_structural_eq_impls(ty: Ty<'tcx>) -> bool {
1032 "computing whether `{:?}` implements `PartialStructuralEq` and `StructuralEq`",
1037 /// A list of types where the ADT requires drop if and only if any of
1038 /// those types require drop. If the ADT is known to always need drop
1039 /// then `Err(AlwaysRequiresDrop)` is returned.
1040 query adt_drop_tys(def_id: DefId) -> Result<&'tcx ty::List<Ty<'tcx>>, AlwaysRequiresDrop> {
1041 desc { |tcx| "computing when `{}` needs drop", tcx.def_path_str(def_id) }
1042 cache_on_disk_if { true }
1046 env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>
1047 ) -> Result<&'tcx rustc_target::abi::Layout, ty::layout::LayoutError<'tcx>> {
1048 desc { "computing layout of `{}`", env.value }
1051 query dylib_dependency_formats(_: CrateNum)
1052 -> &'tcx [(CrateNum, LinkagePreference)] {
1053 desc { "dylib dependency formats of crate" }
1056 query dependency_formats(_: ()) -> Lrc<crate::middle::dependency_format::Dependencies> {
1057 desc { "get the linkage format of all dependencies" }
1060 query is_compiler_builtins(_: CrateNum) -> bool {
1062 desc { "checking if the crate is_compiler_builtins" }
1064 query has_global_allocator(_: CrateNum) -> bool {
1065 // This query depends on untracked global state in CStore
1068 desc { "checking if the crate has_global_allocator" }
1070 query has_panic_handler(_: CrateNum) -> bool {
1072 desc { "checking if the crate has_panic_handler" }
1074 query is_profiler_runtime(_: CrateNum) -> bool {
1076 desc { "query a crate is `#![profiler_runtime]`" }
1078 query panic_strategy(_: CrateNum) -> PanicStrategy {
1080 desc { "query a crate's configured panic strategy" }
1082 query is_no_builtins(_: CrateNum) -> bool {
1084 desc { "test whether a crate has `#![no_builtins]`" }
1086 query symbol_mangling_version(_: CrateNum) -> SymbolManglingVersion {
1088 desc { "query a crate's symbol mangling version" }
1091 query extern_crate(def_id: DefId) -> Option<&'tcx ExternCrate> {
1093 desc { "getting crate's ExternCrateData" }
1096 query specializes(_: (DefId, DefId)) -> bool {
1097 desc { "computing whether impls specialize one another" }
1099 query in_scope_traits_map(_: LocalDefId)
1100 -> Option<&'tcx FxHashMap<ItemLocalId, StableVec<TraitCandidate>>> {
1102 desc { "traits in scope at a block" }
1105 query module_exports(def_id: LocalDefId) -> Option<&'tcx [Export<LocalDefId>]> {
1106 desc { |tcx| "looking up items exported by `{}`", tcx.def_path_str(def_id.to_def_id()) }
1110 query impl_defaultness(def_id: DefId) -> hir::Defaultness {
1111 desc { |tcx| "looking up whether `{}` is a default impl", tcx.def_path_str(def_id) }
1114 query check_item_well_formed(key: LocalDefId) -> () {
1115 desc { |tcx| "checking that `{}` is well-formed", tcx.def_path_str(key.to_def_id()) }
1117 query check_trait_item_well_formed(key: LocalDefId) -> () {
1118 desc { |tcx| "checking that `{}` is well-formed", tcx.def_path_str(key.to_def_id()) }
1120 query check_impl_item_well_formed(key: LocalDefId) -> () {
1121 desc { |tcx| "checking that `{}` is well-formed", tcx.def_path_str(key.to_def_id()) }
1124 // The `DefId`s of all non-generic functions and statics in the given crate
1125 // that can be reached from outside the crate.
1127 // We expect this items to be available for being linked to.
1129 // This query can also be called for `LOCAL_CRATE`. In this case it will
1130 // compute which items will be reachable to other crates, taking into account
1131 // the kind of crate that is currently compiled. Crates with only a
1132 // C interface have fewer reachable things.
1134 // Does not include external symbols that don't have a corresponding DefId,
1135 // like the compiler-generated `main` function and so on.
1136 query reachable_non_generics(_: CrateNum)
1137 -> DefIdMap<SymbolExportLevel> {
1138 storage(ArenaCacheSelector<'tcx>)
1139 desc { "looking up the exported symbols of a crate" }
1141 query is_reachable_non_generic(def_id: DefId) -> bool {
1142 desc { |tcx| "checking whether `{}` is an exported symbol", tcx.def_path_str(def_id) }
1144 query is_unreachable_local_definition(def_id: DefId) -> bool {
1146 "checking whether `{}` is reachable from outside the crate",
1147 tcx.def_path_str(def_id),
1151 /// The entire set of monomorphizations the local crate can safely link
1152 /// to because they are exported from upstream crates. Do not depend on
1153 /// this directly, as its value changes anytime a monomorphization gets
1154 /// added or removed in any upstream crate. Instead use the narrower
1155 /// `upstream_monomorphizations_for`, `upstream_drop_glue_for`, or, even
1156 /// better, `Instance::upstream_monomorphization()`.
1157 query upstream_monomorphizations(
1159 ) -> DefIdMap<FxHashMap<SubstsRef<'tcx>, CrateNum>> {
1160 storage(ArenaCacheSelector<'tcx>)
1161 desc { "collecting available upstream monomorphizations `{:?}`", k }
1164 /// Returns the set of upstream monomorphizations available for the
1165 /// generic function identified by the given `def_id`. The query makes
1166 /// sure to make a stable selection if the same monomorphization is
1167 /// available in multiple upstream crates.
1169 /// You likely want to call `Instance::upstream_monomorphization()`
1170 /// instead of invoking this query directly.
1171 query upstream_monomorphizations_for(def_id: DefId)
1172 -> Option<&'tcx FxHashMap<SubstsRef<'tcx>, CrateNum>> {
1174 "collecting available upstream monomorphizations for `{}`",
1175 tcx.def_path_str(def_id),
1179 /// Returns the upstream crate that exports drop-glue for the given
1180 /// type (`substs` is expected to be a single-item list containing the
1181 /// type one wants drop-glue for).
1183 /// This is a subset of `upstream_monomorphizations_for` in order to
1184 /// increase dep-tracking granularity. Otherwise adding or removing any
1185 /// type with drop-glue in any upstream crate would invalidate all
1186 /// functions calling drop-glue of an upstream type.
1188 /// You likely want to call `Instance::upstream_monomorphization()`
1189 /// instead of invoking this query directly.
1191 /// NOTE: This query could easily be extended to also support other
1192 /// common functions that have are large set of monomorphizations
1193 /// (like `Clone::clone` for example).
1194 query upstream_drop_glue_for(substs: SubstsRef<'tcx>) -> Option<CrateNum> {
1195 desc { "available upstream drop-glue for `{:?}`", substs }
1198 query foreign_modules(_: CrateNum) -> Lrc<FxHashMap<DefId, ForeignModule>> {
1199 desc { "looking up the foreign modules of a linked crate" }
1202 /// Identifies the entry-point (e.g., the `main` function) for a given
1203 /// crate, returning `None` if there is no entry point (such as for library crates).
1204 query entry_fn(_: CrateNum) -> Option<(DefId, EntryFnType)> {
1205 desc { "looking up the entry function of a crate" }
1207 query plugin_registrar_fn(_: CrateNum) -> Option<DefId> {
1208 desc { "looking up the plugin registrar for a crate" }
1210 query proc_macro_decls_static(_: CrateNum) -> Option<DefId> {
1211 desc { "looking up the derive registrar for a crate" }
1213 query crate_disambiguator(_: CrateNum) -> CrateDisambiguator {
1215 desc { "looking up the disambiguator a crate" }
1217 // The macro which defines `rustc_metadata::provide_extern` depends on this query's name.
1218 // Changing the name should cause a compiler error, but in case that changes, be aware.
1219 query crate_hash(_: CrateNum) -> Svh {
1221 desc { "looking up the hash a crate" }
1223 query crate_host_hash(_: CrateNum) -> Option<Svh> {
1225 desc { "looking up the hash of a host version of a crate" }
1227 query original_crate_name(_: CrateNum) -> Symbol {
1229 desc { "looking up the original name a crate" }
1231 query extra_filename(_: CrateNum) -> String {
1233 desc { "looking up the extra filename for a crate" }
1235 query crate_extern_paths(_: CrateNum) -> Vec<PathBuf> {
1237 desc { "looking up the paths for extern crates" }
1240 /// Given a crate and a trait, look up all impls of that trait in the crate.
1241 /// Return `(impl_id, self_ty)`.
1242 query implementations_of_trait(_: (CrateNum, DefId))
1243 -> &'tcx [(DefId, Option<ty::fast_reject::SimplifiedType>)] {
1244 desc { "looking up implementations of a trait in a crate" }
1247 /// Given a crate, look up all trait impls in that crate.
1248 /// Return `(impl_id, self_ty)`.
1249 query all_trait_implementations(_: CrateNum)
1250 -> &'tcx [(DefId, Option<ty::fast_reject::SimplifiedType>)] {
1251 desc { "looking up all (?) trait implementations" }
1254 query is_dllimport_foreign_item(def_id: DefId) -> bool {
1255 desc { |tcx| "is_dllimport_foreign_item({})", tcx.def_path_str(def_id) }
1257 query is_statically_included_foreign_item(def_id: DefId) -> bool {
1258 desc { |tcx| "is_statically_included_foreign_item({})", tcx.def_path_str(def_id) }
1260 query native_library_kind(def_id: DefId)
1261 -> Option<NativeLibKind> {
1262 desc { |tcx| "native_library_kind({})", tcx.def_path_str(def_id) }
1265 /// Does lifetime resolution, but does not descend into trait items. This
1266 /// should only be used for resolving lifetimes of on trait definitions,
1267 /// and is used to avoid cycles. Importantly, `resolve_lifetimes` still visits
1268 /// the same lifetimes and is responsible for diagnostics.
1269 /// See `rustc_resolve::late::lifetimes for details.
1270 query resolve_lifetimes_trait_definition(_: LocalDefId) -> ResolveLifetimes {
1271 storage(ArenaCacheSelector<'tcx>)
1272 desc { "resolving lifetimes for a trait definition" }
1274 /// Does lifetime resolution on items. Importantly, we can't resolve
1275 /// lifetimes directly on things like trait methods, because of trait params.
1276 /// See `rustc_resolve::late::lifetimes for details.
1277 query resolve_lifetimes(_: LocalDefId) -> ResolveLifetimes {
1278 storage(ArenaCacheSelector<'tcx>)
1279 desc { "resolving lifetimes" }
1281 query named_region_map(_: LocalDefId) ->
1282 Option<&'tcx FxHashMap<ItemLocalId, Region>> {
1283 desc { "looking up a named region" }
1285 query is_late_bound_map(_: LocalDefId) ->
1286 Option<(LocalDefId, &'tcx FxHashSet<ItemLocalId>)> {
1287 desc { "testing if a region is late bound" }
1289 /// For a given item (like a struct), gets the default lifetimes to be used
1290 /// for each parameter if a trait object were to be passed for that parameter.
1291 /// For example, for `struct Foo<'a, T, U>`, this would be `['static, 'static]`.
1292 /// For `struct Foo<'a, T: 'a, U>`, this would instead be `['a, 'static]`.
1293 query object_lifetime_defaults_map(_: LocalDefId)
1294 -> Option<Vec<ObjectLifetimeDefault>> {
1295 desc { "looking up lifetime defaults for a region on an item" }
1297 query late_bound_vars_map(_: LocalDefId)
1298 -> Option<&'tcx FxHashMap<ItemLocalId, Vec<ty::BoundVariableKind>>> {
1299 desc { "looking up late bound vars" }
1302 query lifetime_scope_map(_: LocalDefId) -> Option<FxHashMap<ItemLocalId, LifetimeScopeForPath>> {
1303 desc { "finds the lifetime scope for an HirId of a PathSegment" }
1306 query visibility(def_id: DefId) -> ty::Visibility {
1308 desc { |tcx| "computing visibility of `{}`", tcx.def_path_str(def_id) }
1311 /// Computes the set of modules from which this type is visibly uninhabited.
1312 /// To check whether a type is uninhabited at all (not just from a given module), you could
1313 /// check whether the forest is empty.
1314 query type_uninhabited_from(
1315 key: ty::ParamEnvAnd<'tcx, Ty<'tcx>>
1316 ) -> ty::inhabitedness::DefIdForest {
1317 desc { "computing the inhabitedness of `{:?}`", key }
1320 query dep_kind(_: CrateNum) -> CrateDepKind {
1322 desc { "fetching what a dependency looks like" }
1324 query crate_name(_: CrateNum) -> Symbol {
1326 desc { "fetching what a crate is named" }
1328 query item_children(def_id: DefId) -> &'tcx [Export<hir::HirId>] {
1329 desc { |tcx| "collecting child items of `{}`", tcx.def_path_str(def_id) }
1331 query extern_mod_stmt_cnum(def_id: LocalDefId) -> Option<CrateNum> {
1332 // This depends on untracked global state (`tcx.extern_crate_map`)
1334 desc { |tcx| "computing crate imported by `{}`", tcx.def_path_str(def_id.to_def_id()) }
1337 query get_lib_features(_: CrateNum) -> LibFeatures {
1338 storage(ArenaCacheSelector<'tcx>)
1340 desc { "calculating the lib features map" }
1342 query defined_lib_features(_: CrateNum)
1343 -> &'tcx [(Symbol, Option<Symbol>)] {
1344 desc { "calculating the lib features defined in a crate" }
1346 /// Returns the lang items defined in another crate by loading it from metadata.
1347 // FIXME: It is illegal to pass a `CrateNum` other than `LOCAL_CRATE` here, just get rid
1348 // of that argument?
1349 query get_lang_items(_: CrateNum) -> LanguageItems {
1350 storage(ArenaCacheSelector<'tcx>)
1352 desc { "calculating the lang items map" }
1355 /// Returns all diagnostic items defined in all crates.
1356 query all_diagnostic_items(_: CrateNum) -> FxHashMap<Symbol, DefId> {
1357 storage(ArenaCacheSelector<'tcx>)
1359 desc { "calculating the diagnostic items map" }
1362 /// Returns the lang items defined in another crate by loading it from metadata.
1363 query defined_lang_items(_: CrateNum) -> &'tcx [(DefId, usize)] {
1364 desc { "calculating the lang items defined in a crate" }
1367 /// Returns the diagnostic items defined in a crate.
1368 query diagnostic_items(_: CrateNum) -> FxHashMap<Symbol, DefId> {
1369 storage(ArenaCacheSelector<'tcx>)
1370 desc { "calculating the diagnostic items map in a crate" }
1373 query missing_lang_items(_: CrateNum) -> &'tcx [LangItem] {
1374 desc { "calculating the missing lang items in a crate" }
1376 query visible_parent_map(_: CrateNum)
1377 -> DefIdMap<DefId> {
1378 storage(ArenaCacheSelector<'tcx>)
1379 desc { "calculating the visible parent map" }
1381 query trimmed_def_paths(_: CrateNum)
1382 -> FxHashMap<DefId, Symbol> {
1383 storage(ArenaCacheSelector<'tcx>)
1384 desc { "calculating trimmed def paths" }
1386 query missing_extern_crate_item(_: CrateNum) -> bool {
1388 desc { "seeing if we're missing an `extern crate` item for this crate" }
1390 query used_crate_source(_: CrateNum) -> Lrc<CrateSource> {
1392 desc { "looking at the source for a crate" }
1394 query postorder_cnums(_: CrateNum) -> &'tcx [CrateNum] {
1396 desc { "generating a postorder list of CrateNums" }
1399 query upvars_mentioned(def_id: DefId) -> Option<&'tcx FxIndexMap<hir::HirId, hir::Upvar>> {
1400 desc { |tcx| "collecting upvars mentioned in `{}`", tcx.def_path_str(def_id) }
1403 query maybe_unused_trait_import(def_id: LocalDefId) -> bool {
1405 desc { |tcx| "maybe_unused_trait_import for `{}`", tcx.def_path_str(def_id.to_def_id()) }
1407 query maybe_unused_extern_crates(_: CrateNum)
1408 -> &'tcx [(LocalDefId, Span)] {
1410 desc { "looking up all possibly unused extern crates" }
1412 query names_imported_by_glob_use(def_id: LocalDefId)
1413 -> &'tcx FxHashSet<Symbol> {
1415 desc { |tcx| "names_imported_by_glob_use for `{}`", tcx.def_path_str(def_id.to_def_id()) }
1418 query stability_index(_: CrateNum) -> stability::Index<'tcx> {
1419 storage(ArenaCacheSelector<'tcx>)
1421 desc { "calculating the stability index for the local crate" }
1423 query all_crate_nums(_: CrateNum) -> &'tcx [CrateNum] {
1425 desc { "fetching all foreign CrateNum instances" }
1428 /// A vector of every trait accessible in the whole crate
1429 /// (i.e., including those from subcrates). This is used only for
1430 /// error reporting.
1431 query all_traits(_: CrateNum) -> &'tcx [DefId] {
1432 desc { "fetching all foreign and local traits" }
1435 /// The list of symbols exported from the given crate.
1437 /// - All names contained in `exported_symbols(cnum)` are guaranteed to
1438 /// correspond to a publicly visible symbol in `cnum` machine code.
1439 /// - The `exported_symbols` sets of different crates do not intersect.
1440 query exported_symbols(_: CrateNum)
1441 -> &'tcx [(ExportedSymbol<'tcx>, SymbolExportLevel)] {
1442 desc { "exported_symbols" }
1445 query collect_and_partition_mono_items(_: CrateNum)
1446 -> (&'tcx DefIdSet, &'tcx [CodegenUnit<'tcx>]) {
1448 desc { "collect_and_partition_mono_items" }
1450 query is_codegened_item(def_id: DefId) -> bool {
1451 desc { |tcx| "determining whether `{}` needs codegen", tcx.def_path_str(def_id) }
1454 /// All items participating in code generation together with items inlined into them.
1455 query codegened_and_inlined_items(_: CrateNum)
1458 desc { "codegened_and_inlined_items" }
1461 query codegen_unit(_: Symbol) -> &'tcx CodegenUnit<'tcx> {
1462 desc { "codegen_unit" }
1464 query unused_generic_params(key: DefId) -> FiniteBitSet<u32> {
1465 cache_on_disk_if { key.is_local() }
1467 |tcx| "determining which generic parameters are unused by `{}`",
1468 tcx.def_path_str(key)
1471 query backend_optimization_level(_: CrateNum) -> OptLevel {
1472 desc { "optimization level used by backend" }
1475 query output_filenames(_: CrateNum) -> Arc<OutputFilenames> {
1477 desc { "output_filenames" }
1480 /// Do not call this query directly: invoke `normalize` instead.
1481 query normalize_projection_ty(
1482 goal: CanonicalProjectionGoal<'tcx>
1484 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, NormalizationResult<'tcx>>>,
1487 desc { "normalizing `{:?}`", goal }
1490 /// Do not call this query directly: invoke `normalize_erasing_regions` instead.
1491 query normalize_generic_arg_after_erasing_regions(
1492 goal: ParamEnvAnd<'tcx, GenericArg<'tcx>>
1493 ) -> GenericArg<'tcx> {
1494 desc { "normalizing `{}`", goal.value }
1497 /// Do not call this query directly: invoke `normalize_erasing_regions` instead.
1498 query normalize_mir_const_after_erasing_regions(
1499 goal: ParamEnvAnd<'tcx, mir::ConstantKind<'tcx>>
1500 ) -> mir::ConstantKind<'tcx> {
1501 desc { "normalizing `{}`", goal.value }
1504 query implied_outlives_bounds(
1505 goal: CanonicalTyGoal<'tcx>
1507 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, Vec<OutlivesBound<'tcx>>>>,
1510 desc { "computing implied outlives bounds for `{:?}`", goal }
1513 /// Do not call this query directly: invoke `infcx.at().dropck_outlives()` instead.
1514 query dropck_outlives(
1515 goal: CanonicalTyGoal<'tcx>
1517 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, DropckOutlivesResult<'tcx>>>,
1520 desc { "computing dropck types for `{:?}`", goal }
1523 /// Do not call this query directly: invoke `infcx.predicate_may_hold()` or
1524 /// `infcx.predicate_must_hold()` instead.
1525 query evaluate_obligation(
1526 goal: CanonicalPredicateGoal<'tcx>
1527 ) -> Result<traits::EvaluationResult, traits::OverflowError> {
1528 desc { "evaluating trait selection obligation `{}`", goal.value.value }
1531 query evaluate_goal(
1532 goal: traits::CanonicalChalkEnvironmentAndGoal<'tcx>
1534 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1537 desc { "evaluating trait selection obligation `{}`", goal.value }
1540 query type_implements_trait(
1541 key: (DefId, Ty<'tcx>, SubstsRef<'tcx>, ty::ParamEnv<'tcx>, )
1543 desc { "evaluating `type_implements_trait` `{:?}`", key }
1546 /// Do not call this query directly: part of the `Eq` type-op
1547 query type_op_ascribe_user_type(
1548 goal: CanonicalTypeOpAscribeUserTypeGoal<'tcx>
1550 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1553 desc { "evaluating `type_op_ascribe_user_type` `{:?}`", goal }
1556 /// Do not call this query directly: part of the `Eq` type-op
1558 goal: CanonicalTypeOpEqGoal<'tcx>
1560 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1563 desc { "evaluating `type_op_eq` `{:?}`", goal }
1566 /// Do not call this query directly: part of the `Subtype` type-op
1567 query type_op_subtype(
1568 goal: CanonicalTypeOpSubtypeGoal<'tcx>
1570 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1573 desc { "evaluating `type_op_subtype` `{:?}`", goal }
1576 /// Do not call this query directly: part of the `ProvePredicate` type-op
1577 query type_op_prove_predicate(
1578 goal: CanonicalTypeOpProvePredicateGoal<'tcx>
1580 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1583 desc { "evaluating `type_op_prove_predicate` `{:?}`", goal }
1586 /// Do not call this query directly: part of the `Normalize` type-op
1587 query type_op_normalize_ty(
1588 goal: CanonicalTypeOpNormalizeGoal<'tcx, Ty<'tcx>>
1590 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, Ty<'tcx>>>,
1593 desc { "normalizing `{:?}`", goal }
1596 /// Do not call this query directly: part of the `Normalize` type-op
1597 query type_op_normalize_predicate(
1598 goal: CanonicalTypeOpNormalizeGoal<'tcx, ty::Predicate<'tcx>>
1600 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ty::Predicate<'tcx>>>,
1603 desc { "normalizing `{:?}`", goal }
1606 /// Do not call this query directly: part of the `Normalize` type-op
1607 query type_op_normalize_poly_fn_sig(
1608 goal: CanonicalTypeOpNormalizeGoal<'tcx, ty::PolyFnSig<'tcx>>
1610 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ty::PolyFnSig<'tcx>>>,
1613 desc { "normalizing `{:?}`", goal }
1616 /// Do not call this query directly: part of the `Normalize` type-op
1617 query type_op_normalize_fn_sig(
1618 goal: CanonicalTypeOpNormalizeGoal<'tcx, ty::FnSig<'tcx>>
1620 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ty::FnSig<'tcx>>>,
1623 desc { "normalizing `{:?}`", goal }
1626 query subst_and_check_impossible_predicates(key: (DefId, SubstsRef<'tcx>)) -> bool {
1628 "impossible substituted predicates:`{}`",
1629 tcx.def_path_str(key.0)
1633 query method_autoderef_steps(
1634 goal: CanonicalTyGoal<'tcx>
1635 ) -> MethodAutoderefStepsResult<'tcx> {
1636 desc { "computing autoderef types for `{:?}`", goal }
1639 query supported_target_features(_: CrateNum) -> FxHashMap<String, Option<Symbol>> {
1640 storage(ArenaCacheSelector<'tcx>)
1642 desc { "looking up supported target features" }
1645 /// Get an estimate of the size of an InstanceDef based on its MIR for CGU partitioning.
1646 query instance_def_size_estimate(def: ty::InstanceDef<'tcx>)
1648 desc { |tcx| "estimating size for `{}`", tcx.def_path_str(def.def_id()) }
1651 query features_query(_: CrateNum) -> &'tcx rustc_feature::Features {
1653 desc { "looking up enabled feature gates" }
1656 /// Attempt to resolve the given `DefId` to an `Instance`, for the
1657 /// given generics args (`SubstsRef`), returning one of:
1658 /// * `Ok(Some(instance))` on success
1659 /// * `Ok(None)` when the `SubstsRef` are still too generic,
1660 /// and therefore don't allow finding the final `Instance`
1661 /// * `Err(ErrorReported)` when the `Instance` resolution process
1662 /// couldn't complete due to errors elsewhere - this is distinct
1663 /// from `Ok(None)` to avoid misleading diagnostics when an error
1664 /// has already been/will be emitted, for the original cause
1665 query resolve_instance(
1666 key: ty::ParamEnvAnd<'tcx, (DefId, SubstsRef<'tcx>)>
1667 ) -> Result<Option<ty::Instance<'tcx>>, ErrorReported> {
1668 desc { "resolving instance `{}`", ty::Instance::new(key.value.0, key.value.1) }
1671 query resolve_instance_of_const_arg(
1672 key: ty::ParamEnvAnd<'tcx, (LocalDefId, DefId, SubstsRef<'tcx>)>
1673 ) -> Result<Option<ty::Instance<'tcx>>, ErrorReported> {
1675 "resolving instance of the const argument `{}`",
1676 ty::Instance::new(key.value.0.to_def_id(), key.value.2),
1680 query normalize_opaque_types(key: &'tcx ty::List<ty::Predicate<'tcx>>) -> &'tcx ty::List<ty::Predicate<'tcx>> {
1681 desc { "normalizing opaque types in {:?}", key }
1684 /// Checks whether a type is definitely uninhabited. This is
1685 /// conservative: for some types that are uninhabited we return `false`,
1686 /// but we only return `true` for types that are definitely uninhabited.
1687 /// `ty.conservative_is_privately_uninhabited` implies that any value of type `ty`
1688 /// will be `Abi::Uninhabited`. (Note that uninhabited types may have nonzero
1689 /// size, to account for partial initialisation. See #49298 for details.)
1690 query conservative_is_privately_uninhabited(key: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1691 desc { "conservatively checking if {:?} is privately uninhabited", key }