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 map::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 nodes and bodies inside 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_nodes(key: LocalDefId) -> Option<&'tcx crate::hir::OwnerNodes<'tcx>> {
61 desc { |tcx| "HIR owner items in `{}`", tcx.def_path_str(key.to_def_id()) }
64 /// Gives access to the HIR attributes 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_attrs(key: LocalDefId) -> rustc_middle::hir::AttributeMap<'tcx> {
70 desc { |tcx| "HIR owner attributes in `{}`", tcx.def_path_str(key.to_def_id()) }
73 /// Computes the `DefId` of the corresponding const parameter in case the `key` is a
74 /// const argument and returns `None` otherwise.
76 /// ```ignore (incomplete)
77 /// let a = foo::<7>();
78 /// // ^ Calling `opt_const_param_of` for this argument,
80 /// fn foo<const N: usize>()
81 /// // ^ returns this `DefId`.
84 /// // ^ While calling `opt_const_param_of` for other bodies returns `None`.
87 // It looks like caching this query on disk actually slightly
88 // worsened performance in #74376.
90 // Once const generics are more prevalently used, we might want to
91 // consider only caching calls returning `Some`.
92 query opt_const_param_of(key: LocalDefId) -> Option<DefId> {
93 desc { |tcx| "computing the optional const parameter of `{}`", tcx.def_path_str(key.to_def_id()) }
96 /// Given the def_id of a const-generic parameter, computes the associated default const
97 /// parameter. e.g. `fn example<const N: usize=3>` called on `N` would return `3`.
98 query const_param_default(param: DefId) -> &'tcx ty::Const<'tcx> {
99 desc { |tcx| "compute const default for a given parameter `{}`", tcx.def_path_str(param) }
102 /// Records the type of every item.
103 query type_of(key: DefId) -> Ty<'tcx> {
104 desc { |tcx| "computing type of `{}`", tcx.def_path_str(key) }
105 cache_on_disk_if { key.is_local() }
108 query analysis(key: CrateNum) -> Result<(), ErrorReported> {
110 desc { "running analysis passes on this crate" }
113 /// Maps from the `DefId` of an item (trait/struct/enum/fn) to its
114 /// associated generics.
115 query generics_of(key: DefId) -> ty::Generics {
116 desc { |tcx| "computing generics of `{}`", tcx.def_path_str(key) }
117 storage(ArenaCacheSelector<'tcx>)
118 cache_on_disk_if { key.is_local() }
121 /// Maps from the `DefId` of an item (trait/struct/enum/fn) to the
122 /// predicates (where-clauses) that must be proven true in order
123 /// to reference it. This is almost always the "predicates query"
126 /// `predicates_of` builds on `predicates_defined_on` -- in fact,
127 /// it is almost always the same as that query, except for the
128 /// case of traits. For traits, `predicates_of` contains
129 /// an additional `Self: Trait<...>` predicate that users don't
130 /// actually write. This reflects the fact that to invoke the
131 /// trait (e.g., via `Default::default`) you must supply types
132 /// that actually implement the trait. (However, this extra
133 /// predicate gets in the way of some checks, which are intended
134 /// to operate over only the actual where-clauses written by the
136 query predicates_of(key: DefId) -> ty::GenericPredicates<'tcx> {
137 desc { |tcx| "computing predicates of `{}`", tcx.def_path_str(key) }
138 cache_on_disk_if { key.is_local() }
141 /// Returns the list of bounds that can be used for
142 /// `SelectionCandidate::ProjectionCandidate(_)` and
143 /// `ProjectionTyCandidate::TraitDef`.
144 /// Specifically this is the bounds written on the trait's type
145 /// definition, or those after the `impl` keyword
147 /// ```ignore (incomplete)
148 /// type X: Bound + 'lt
150 /// impl Debug + Display
151 /// // ^^^^^^^^^^^^^^^
154 /// `key` is the `DefId` of the associated type or opaque type.
156 /// Bounds from the parent (e.g. with nested impl trait) are not included.
157 query explicit_item_bounds(key: DefId) -> &'tcx [(ty::Predicate<'tcx>, Span)] {
158 desc { |tcx| "finding item bounds for `{}`", tcx.def_path_str(key) }
161 /// Elaborated version of the predicates from `explicit_item_bounds`.
167 /// type MyAType: Eq + ?Sized;
171 /// `explicit_item_bounds` returns `[<Self as MyTrait>::MyAType: Eq]`,
172 /// and `item_bounds` returns
175 /// <Self as Trait>::MyAType: Eq,
176 /// <Self as Trait>::MyAType: PartialEq<<Self as Trait>::MyAType>
180 /// Bounds from the parent (e.g. with nested impl trait) are not included.
181 query item_bounds(key: DefId) -> &'tcx ty::List<ty::Predicate<'tcx>> {
182 desc { |tcx| "elaborating item bounds for `{}`", tcx.def_path_str(key) }
185 query projection_ty_from_predicates(key: (DefId, DefId)) -> Option<ty::ProjectionTy<'tcx>> {
186 desc { |tcx| "finding projection type inside predicates of `{}`", tcx.def_path_str(key.0) }
189 query native_libraries(_: CrateNum) -> Lrc<Vec<NativeLib>> {
190 desc { "looking up the native libraries of a linked crate" }
193 query lint_levels(_: CrateNum) -> LintLevelMap {
194 storage(ArenaCacheSelector<'tcx>)
196 desc { "computing the lint levels for items in this crate" }
199 query parent_module_from_def_id(key: LocalDefId) -> LocalDefId {
201 desc { |tcx| "parent module of `{}`", tcx.def_path_str(key.to_def_id()) }
204 /// Internal helper query. Use `tcx.expansion_that_defined` instead
205 query expn_that_defined(key: DefId) -> rustc_span::ExpnId {
206 desc { |tcx| "expansion that defined `{}`", tcx.def_path_str(key) }
209 query is_panic_runtime(_: CrateNum) -> bool {
211 desc { "checking if the crate is_panic_runtime" }
214 /// Set of all the `DefId`s in this crate that have MIR associated with
215 /// them. This includes all the body owners, but also things like struct
217 query mir_keys(_: CrateNum) -> FxHashSet<LocalDefId> {
218 storage(ArenaCacheSelector<'tcx>)
219 desc { "getting a list of all mir_keys" }
222 /// Maps DefId's that have an associated `mir::Body` to the result
223 /// of the MIR const-checking pass. This is the set of qualifs in
224 /// the final value of a `const`.
225 query mir_const_qualif(key: DefId) -> mir::ConstQualifs {
226 desc { |tcx| "const checking `{}`", tcx.def_path_str(key) }
227 cache_on_disk_if { key.is_local() }
229 query mir_const_qualif_const_arg(
230 key: (LocalDefId, DefId)
231 ) -> mir::ConstQualifs {
233 |tcx| "const checking the const argument `{}`",
234 tcx.def_path_str(key.0.to_def_id())
238 /// Fetch the MIR for a given `DefId` right after it's built - this includes
239 /// unreachable code.
240 query mir_built(key: ty::WithOptConstParam<LocalDefId>) -> &'tcx Steal<mir::Body<'tcx>> {
241 desc { |tcx| "building MIR for `{}`", tcx.def_path_str(key.did.to_def_id()) }
244 /// Fetch the MIR for a given `DefId` up till the point where it is
245 /// ready for const qualification.
247 /// See the README for the `mir` module for details.
248 query mir_const(key: ty::WithOptConstParam<LocalDefId>) -> &'tcx Steal<mir::Body<'tcx>> {
250 |tcx| "processing MIR for {}`{}`",
251 if key.const_param_did.is_some() { "the const argument " } else { "" },
252 tcx.def_path_str(key.did.to_def_id()),
257 /// Try to build an abstract representation of the given constant.
258 query mir_abstract_const(
260 ) -> Result<Option<&'tcx [mir::abstract_const::Node<'tcx>]>, ErrorReported> {
262 |tcx| "building an abstract representation for {}", tcx.def_path_str(key),
265 /// Try to build an abstract representation of the given constant.
266 query mir_abstract_const_of_const_arg(
267 key: (LocalDefId, DefId)
268 ) -> Result<Option<&'tcx [mir::abstract_const::Node<'tcx>]>, ErrorReported> {
271 "building an abstract representation for the const argument {}",
272 tcx.def_path_str(key.0.to_def_id()),
276 query try_unify_abstract_consts(key: (
277 (ty::WithOptConstParam<DefId>, SubstsRef<'tcx>),
278 (ty::WithOptConstParam<DefId>, SubstsRef<'tcx>)
281 |tcx| "trying to unify the generic constants {} and {}",
282 tcx.def_path_str(key.0.0.did), tcx.def_path_str(key.1.0.did)
286 query mir_drops_elaborated_and_const_checked(
287 key: ty::WithOptConstParam<LocalDefId>
288 ) -> &'tcx Steal<mir::Body<'tcx>> {
290 desc { |tcx| "elaborating drops for `{}`", tcx.def_path_str(key.did.to_def_id()) }
295 ) -> &'tcx mir::Body<'tcx> {
296 desc { |tcx| "caching mir of `{}` for CTFE", tcx.def_path_str(key) }
297 cache_on_disk_if { key.is_local() }
300 query mir_for_ctfe_of_const_arg(key: (LocalDefId, DefId)) -> &'tcx mir::Body<'tcx> {
302 |tcx| "MIR for CTFE of the const argument `{}`",
303 tcx.def_path_str(key.0.to_def_id())
307 query mir_promoted(key: ty::WithOptConstParam<LocalDefId>) ->
309 &'tcx Steal<mir::Body<'tcx>>,
310 &'tcx Steal<IndexVec<mir::Promoted, mir::Body<'tcx>>>
314 |tcx| "processing {}`{}`",
315 if key.const_param_did.is_some() { "the const argument " } else { "" },
316 tcx.def_path_str(key.did.to_def_id()),
320 /// MIR after our optimization passes have run. This is MIR that is ready
321 /// for codegen. This is also the only query that can fetch non-local MIR, at present.
322 query optimized_mir(key: DefId) -> &'tcx mir::Body<'tcx> {
323 desc { |tcx| "optimizing MIR for `{}`", tcx.def_path_str(key) }
324 cache_on_disk_if { key.is_local() }
327 /// Returns coverage summary info for a function, after executing the `InstrumentCoverage`
328 /// MIR pass (assuming the -Zinstrument-coverage option is enabled).
329 query coverageinfo(key: DefId) -> mir::CoverageInfo {
330 desc { |tcx| "retrieving coverage info from MIR for `{}`", tcx.def_path_str(key) }
331 storage(ArenaCacheSelector<'tcx>)
332 cache_on_disk_if { key.is_local() }
335 /// Returns the name of the file that contains the function body, if instrumented for coverage.
336 query covered_file_name(key: DefId) -> Option<Symbol> {
338 |tcx| "retrieving the covered file name, if instrumented, for `{}`",
339 tcx.def_path_str(key)
341 storage(ArenaCacheSelector<'tcx>)
342 cache_on_disk_if { key.is_local() }
345 /// Returns the `CodeRegions` for a function that has instrumented coverage, in case the
346 /// function was optimized out before codegen, and before being added to the Coverage Map.
347 query covered_code_regions(key: DefId) -> Vec<&'tcx mir::coverage::CodeRegion> {
349 |tcx| "retrieving the covered `CodeRegion`s, if instrumented, for `{}`",
350 tcx.def_path_str(key)
352 storage(ArenaCacheSelector<'tcx>)
353 cache_on_disk_if { key.is_local() }
356 /// The `DefId` is the `DefId` of the containing MIR body. Promoteds do not have their own
357 /// `DefId`. This function returns all promoteds in the specified body. The body references
358 /// promoteds by the `DefId` and the `mir::Promoted` index. This is necessary, because
359 /// after inlining a body may refer to promoteds from other bodies. In that case you still
360 /// need to use the `DefId` of the original body.
361 query promoted_mir(key: DefId) -> &'tcx IndexVec<mir::Promoted, mir::Body<'tcx>> {
362 desc { |tcx| "optimizing promoted MIR for `{}`", tcx.def_path_str(key) }
363 cache_on_disk_if { key.is_local() }
365 query promoted_mir_of_const_arg(
366 key: (LocalDefId, DefId)
367 ) -> &'tcx IndexVec<mir::Promoted, mir::Body<'tcx>> {
369 |tcx| "optimizing promoted MIR for the const argument `{}`",
370 tcx.def_path_str(key.0.to_def_id()),
374 /// Erases regions from `ty` to yield a new type.
375 /// Normally you would just use `tcx.erase_regions(value)`,
376 /// however, which uses this query as a kind of cache.
377 query erase_regions_ty(ty: Ty<'tcx>) -> Ty<'tcx> {
378 // This query is not expected to have input -- as a result, it
379 // is not a good candidates for "replay" because it is essentially a
380 // pure function of its input (and hence the expectation is that
381 // no caller would be green **apart** from just these
382 // queries). Making it anonymous avoids hashing the result, which
383 // may save a bit of time.
385 desc { "erasing regions from `{:?}`", ty }
388 query wasm_import_module_map(_: CrateNum) -> FxHashMap<DefId, String> {
389 storage(ArenaCacheSelector<'tcx>)
390 desc { "wasm import module map" }
393 /// Maps from the `DefId` of an item (trait/struct/enum/fn) to the
394 /// predicates (where-clauses) directly defined on it. This is
395 /// equal to the `explicit_predicates_of` predicates plus the
396 /// `inferred_outlives_of` predicates.
397 query predicates_defined_on(key: DefId) -> ty::GenericPredicates<'tcx> {
398 desc { |tcx| "computing predicates of `{}`", tcx.def_path_str(key) }
401 /// Returns everything that looks like a predicate written explicitly
402 /// by the user on a trait item.
404 /// Traits are unusual, because predicates on associated types are
405 /// converted into bounds on that type for backwards compatibility:
407 /// trait X where Self::U: Copy { type U; }
411 /// trait X { type U: Copy; }
413 /// `explicit_predicates_of` and `explicit_item_bounds` will then take
414 /// the appropriate subsets of the predicates here.
415 query trait_explicit_predicates_and_bounds(key: LocalDefId) -> ty::GenericPredicates<'tcx> {
416 desc { |tcx| "computing explicit predicates of trait `{}`", tcx.def_path_str(key.to_def_id()) }
419 /// Returns the predicates written explicitly by the user.
420 query explicit_predicates_of(key: DefId) -> ty::GenericPredicates<'tcx> {
421 desc { |tcx| "computing explicit predicates of `{}`", tcx.def_path_str(key) }
424 /// Returns the inferred outlives predicates (e.g., for `struct
425 /// Foo<'a, T> { x: &'a T }`, this would return `T: 'a`).
426 query inferred_outlives_of(key: DefId) -> &'tcx [(ty::Predicate<'tcx>, Span)] {
427 desc { |tcx| "computing inferred outlives predicates of `{}`", tcx.def_path_str(key) }
430 /// Maps from the `DefId` of a trait to the list of
431 /// super-predicates. This is a subset of the full list of
432 /// predicates. We store these in a separate map because we must
433 /// evaluate them even during type conversion, often before the
434 /// full predicates are available (note that supertraits have
435 /// additional acyclicity requirements).
436 query super_predicates_of(key: DefId) -> ty::GenericPredicates<'tcx> {
437 desc { |tcx| "computing the super predicates of `{}`", tcx.def_path_str(key) }
440 /// The `Option<Ident>` is the name of an associated type. If it is `None`, then this query
441 /// returns the full set of predicates. If `Some<Ident>`, then the query returns only the
442 /// subset of super-predicates that reference traits that define the given associated type.
443 /// This is used to avoid cycles in resolving types like `T::Item`.
444 query super_predicates_that_define_assoc_type(key: (DefId, Option<rustc_span::symbol::Ident>)) -> ty::GenericPredicates<'tcx> {
445 desc { |tcx| "computing the super traits of `{}`{}",
446 tcx.def_path_str(key.0),
447 if let Some(assoc_name) = key.1 { format!(" with associated type name `{}`", assoc_name) } else { "".to_string() },
451 /// To avoid cycles within the predicates of a single item we compute
452 /// per-type-parameter predicates for resolving `T::AssocTy`.
453 query type_param_predicates(key: (DefId, LocalDefId, rustc_span::symbol::Ident)) -> ty::GenericPredicates<'tcx> {
454 desc { |tcx| "computing the bounds for type parameter `{}`", {
455 let id = tcx.hir().local_def_id_to_hir_id(key.1);
456 tcx.hir().ty_param_name(id)
460 query trait_def(key: DefId) -> ty::TraitDef {
461 desc { |tcx| "computing trait definition for `{}`", tcx.def_path_str(key) }
462 storage(ArenaCacheSelector<'tcx>)
464 query adt_def(key: DefId) -> &'tcx ty::AdtDef {
465 desc { |tcx| "computing ADT definition for `{}`", tcx.def_path_str(key) }
467 query adt_destructor(key: DefId) -> Option<ty::Destructor> {
468 desc { |tcx| "computing `Drop` impl for `{}`", tcx.def_path_str(key) }
471 // The cycle error here should be reported as an error by `check_representable`.
472 // We consider the type as Sized in the meanwhile to avoid
473 // further errors (done in impl Value for AdtSizedConstraint).
474 // Use `cycle_delay_bug` to delay the cycle error here to be emitted later
475 // in case we accidentally otherwise don't emit an error.
476 query adt_sized_constraint(
478 ) -> AdtSizedConstraint<'tcx> {
479 desc { |tcx| "computing `Sized` constraints for `{}`", tcx.def_path_str(key) }
483 query adt_dtorck_constraint(
485 ) -> Result<DtorckConstraint<'tcx>, NoSolution> {
486 desc { |tcx| "computing drop-check constraints for `{}`", tcx.def_path_str(key) }
489 /// Returns `true` if this is a const fn, use the `is_const_fn` to know whether your crate
490 /// actually sees it as const fn (e.g., the const-fn-ness might be unstable and you might
491 /// not have the feature gate active).
493 /// **Do not call this function manually.** It is only meant to cache the base data for the
494 /// `is_const_fn` function.
495 query is_const_fn_raw(key: DefId) -> bool {
496 desc { |tcx| "checking if item is const fn: `{}`", tcx.def_path_str(key) }
499 /// Returns `true` if this is a const `impl`. **Do not call this function manually.**
501 /// This query caches the base data for the `is_const_impl` helper function, which also
502 /// takes into account stability attributes (e.g., `#[rustc_const_unstable]`).
503 query is_const_impl_raw(key: DefId) -> bool {
504 desc { |tcx| "checking if item is const impl: `{}`", tcx.def_path_str(key) }
507 query asyncness(key: DefId) -> hir::IsAsync {
508 desc { |tcx| "checking if the function is async: `{}`", tcx.def_path_str(key) }
511 /// Returns `true` if calls to the function may be promoted.
513 /// This is either because the function is e.g., a tuple-struct or tuple-variant
514 /// constructor, or because it has the `#[rustc_promotable]` attribute. The attribute should
515 /// be removed in the future in favour of some form of check which figures out whether the
516 /// function does not inspect the bits of any of its arguments (so is essentially just a
517 /// constructor function).
518 query is_promotable_const_fn(key: DefId) -> bool {
519 desc { |tcx| "checking if item is promotable: `{}`", tcx.def_path_str(key) }
522 /// Returns `true` if this is a foreign item (i.e., linked via `extern { ... }`).
523 query is_foreign_item(key: DefId) -> bool {
524 desc { |tcx| "checking if `{}` is a foreign item", tcx.def_path_str(key) }
527 /// Returns `Some(mutability)` if the node pointed to by `def_id` is a static item.
528 query static_mutability(def_id: DefId) -> Option<hir::Mutability> {
529 desc { |tcx| "looking up static mutability of `{}`", tcx.def_path_str(def_id) }
532 /// Returns `Some(generator_kind)` if the node pointed to by `def_id` is a generator.
533 query generator_kind(def_id: DefId) -> Option<hir::GeneratorKind> {
534 desc { |tcx| "looking up generator kind of `{}`", tcx.def_path_str(def_id) }
537 /// Gets a map with the variance of every item; use `item_variance` instead.
538 query crate_variances(_: CrateNum) -> ty::CrateVariancesMap<'tcx> {
539 storage(ArenaCacheSelector<'tcx>)
540 desc { "computing the variances for items in this crate" }
543 /// Maps from the `DefId` of a type or region parameter to its (inferred) variance.
544 query variances_of(def_id: DefId) -> &'tcx [ty::Variance] {
545 desc { |tcx| "computing the variances of `{}`", tcx.def_path_str(def_id) }
548 /// Maps from thee `DefId` of a type to its (inferred) outlives.
549 query inferred_outlives_crate(_: CrateNum)
550 -> ty::CratePredicatesMap<'tcx> {
551 storage(ArenaCacheSelector<'tcx>)
552 desc { "computing the inferred outlives predicates for items in this crate" }
555 /// Maps from an impl/trait `DefId to a list of the `DefId`s of its items.
556 query associated_item_def_ids(key: DefId) -> &'tcx [DefId] {
557 desc { |tcx| "collecting associated items of `{}`", tcx.def_path_str(key) }
560 /// Maps from a trait item to the trait item "descriptor".
561 query associated_item(key: DefId) -> ty::AssocItem {
562 desc { |tcx| "computing associated item data for `{}`", tcx.def_path_str(key) }
563 storage(ArenaCacheSelector<'tcx>)
566 /// Collects the associated items defined on a trait or impl.
567 query associated_items(key: DefId) -> ty::AssociatedItems<'tcx> {
568 storage(ArenaCacheSelector<'tcx>)
569 desc { |tcx| "collecting associated items of {}", tcx.def_path_str(key) }
572 /// Given an `impl_id`, return the trait it implements.
573 /// Return `None` if this is an inherent impl.
574 query impl_trait_ref(impl_id: DefId) -> Option<ty::TraitRef<'tcx>> {
575 desc { |tcx| "computing trait implemented by `{}`", tcx.def_path_str(impl_id) }
577 query impl_polarity(impl_id: DefId) -> ty::ImplPolarity {
578 desc { |tcx| "computing implementation polarity of `{}`", tcx.def_path_str(impl_id) }
581 query issue33140_self_ty(key: DefId) -> Option<ty::Ty<'tcx>> {
582 desc { |tcx| "computing Self type wrt issue #33140 `{}`", tcx.def_path_str(key) }
585 /// Maps a `DefId` of a type to a list of its inherent impls.
586 /// Contains implementations of methods that are inherent to a type.
587 /// Methods in these implementations don't need to be exported.
588 query inherent_impls(key: DefId) -> &'tcx [DefId] {
589 desc { |tcx| "collecting inherent impls for `{}`", tcx.def_path_str(key) }
593 /// The result of unsafety-checking this `LocalDefId`.
594 query unsafety_check_result(key: LocalDefId) -> &'tcx mir::UnsafetyCheckResult {
595 desc { |tcx| "unsafety-checking `{}`", tcx.def_path_str(key.to_def_id()) }
596 cache_on_disk_if { true }
598 query unsafety_check_result_for_const_arg(key: (LocalDefId, DefId)) -> &'tcx mir::UnsafetyCheckResult {
600 |tcx| "unsafety-checking the const argument `{}`",
601 tcx.def_path_str(key.0.to_def_id())
605 /// HACK: when evaluated, this reports a "unsafe derive on repr(packed)" error.
607 /// Unsafety checking is executed for each method separately, but we only want
608 /// to emit this error once per derive. As there are some impls with multiple
609 /// methods, we use a query for deduplication.
610 query unsafe_derive_on_repr_packed(key: LocalDefId) -> () {
611 desc { |tcx| "processing `{}`", tcx.def_path_str(key.to_def_id()) }
614 /// The signature of functions.
615 query fn_sig(key: DefId) -> ty::PolyFnSig<'tcx> {
616 desc { |tcx| "computing function signature of `{}`", tcx.def_path_str(key) }
619 query lint_mod(key: LocalDefId) -> () {
620 desc { |tcx| "linting {}", describe_as_module(key, tcx) }
623 /// Checks the attributes in the module.
624 query check_mod_attrs(key: LocalDefId) -> () {
625 desc { |tcx| "checking attributes in {}", describe_as_module(key, tcx) }
628 query check_mod_unstable_api_usage(key: LocalDefId) -> () {
629 desc { |tcx| "checking for unstable API usage in {}", describe_as_module(key, tcx) }
632 /// Checks the const bodies in the module for illegal operations (e.g. `if` or `loop`).
633 query check_mod_const_bodies(key: LocalDefId) -> () {
634 desc { |tcx| "checking consts in {}", describe_as_module(key, tcx) }
637 /// Checks the loops in the module.
638 query check_mod_loops(key: LocalDefId) -> () {
639 desc { |tcx| "checking loops in {}", describe_as_module(key, tcx) }
642 query check_mod_naked_functions(key: LocalDefId) -> () {
643 desc { |tcx| "checking naked functions in {}", describe_as_module(key, tcx) }
646 query check_mod_item_types(key: LocalDefId) -> () {
647 desc { |tcx| "checking item types in {}", describe_as_module(key, tcx) }
650 query check_mod_privacy(key: LocalDefId) -> () {
651 desc { |tcx| "checking privacy in {}", describe_as_module(key, tcx) }
654 query check_mod_intrinsics(key: LocalDefId) -> () {
655 desc { |tcx| "checking intrinsics in {}", describe_as_module(key, tcx) }
658 query check_mod_liveness(key: LocalDefId) -> () {
659 desc { |tcx| "checking liveness of variables in {}", describe_as_module(key, tcx) }
662 query check_mod_impl_wf(key: LocalDefId) -> () {
663 desc { |tcx| "checking that impls are well-formed in {}", describe_as_module(key, tcx) }
666 query collect_mod_item_types(key: LocalDefId) -> () {
667 desc { |tcx| "collecting item types in {}", describe_as_module(key, tcx) }
670 /// Caches `CoerceUnsized` kinds for impls on custom types.
671 query coerce_unsized_info(key: DefId)
672 -> ty::adjustment::CoerceUnsizedInfo {
673 desc { |tcx| "computing CoerceUnsized info for `{}`", tcx.def_path_str(key) }
676 query typeck_item_bodies(_: CrateNum) -> () {
677 desc { "type-checking all item bodies" }
680 query typeck(key: LocalDefId) -> &'tcx ty::TypeckResults<'tcx> {
681 desc { |tcx| "type-checking `{}`", tcx.def_path_str(key.to_def_id()) }
682 cache_on_disk_if { true }
684 query typeck_const_arg(
685 key: (LocalDefId, DefId)
686 ) -> &'tcx ty::TypeckResults<'tcx> {
688 |tcx| "type-checking the const argument `{}`",
689 tcx.def_path_str(key.0.to_def_id()),
692 query diagnostic_only_typeck(key: LocalDefId) -> &'tcx ty::TypeckResults<'tcx> {
693 desc { |tcx| "type-checking `{}`", tcx.def_path_str(key.to_def_id()) }
694 cache_on_disk_if { true }
695 load_cached(tcx, id) {
696 let typeck_results: Option<ty::TypeckResults<'tcx>> = tcx
697 .on_disk_cache.as_ref()
698 .and_then(|c| c.try_load_query_result(*tcx, id));
700 typeck_results.map(|x| &*tcx.arena.alloc(x))
704 query used_trait_imports(key: LocalDefId) -> &'tcx FxHashSet<LocalDefId> {
705 desc { |tcx| "used_trait_imports `{}`", tcx.def_path_str(key.to_def_id()) }
706 cache_on_disk_if { true }
709 query has_typeck_results(def_id: DefId) -> bool {
710 desc { |tcx| "checking whether `{}` has a body", tcx.def_path_str(def_id) }
713 query coherent_trait(def_id: DefId) -> () {
714 desc { |tcx| "coherence checking all impls of trait `{}`", tcx.def_path_str(def_id) }
717 /// Borrow-checks the function body. If this is a closure, returns
718 /// additional requirements that the closure's creator must verify.
719 query mir_borrowck(key: LocalDefId) -> &'tcx mir::BorrowCheckResult<'tcx> {
720 desc { |tcx| "borrow-checking `{}`", tcx.def_path_str(key.to_def_id()) }
721 cache_on_disk_if(tcx, opt_result) {
722 tcx.is_closure(key.to_def_id())
723 || opt_result.map_or(false, |r| !r.concrete_opaque_types.is_empty())
726 query mir_borrowck_const_arg(key: (LocalDefId, DefId)) -> &'tcx mir::BorrowCheckResult<'tcx> {
728 |tcx| "borrow-checking the const argument`{}`",
729 tcx.def_path_str(key.0.to_def_id())
733 /// Gets a complete map from all types to their inherent impls.
734 /// Not meant to be used directly outside of coherence.
735 /// (Defined only for `LOCAL_CRATE`.)
736 query crate_inherent_impls(k: CrateNum)
737 -> CrateInherentImpls {
738 storage(ArenaCacheSelector<'tcx>)
740 desc { "all inherent impls defined in crate `{:?}`", k }
743 /// Checks all types in the crate for overlap in their inherent impls. Reports errors.
744 /// Not meant to be used directly outside of coherence.
745 /// (Defined only for `LOCAL_CRATE`.)
746 query crate_inherent_impls_overlap_check(_: CrateNum)
749 desc { "check for overlap between inherent impls defined in this crate" }
752 /// Check whether the function has any recursion that could cause the inliner to trigger
753 /// a cycle. Returns the call stack causing the cycle. The call stack does not contain the
754 /// current function, just all intermediate functions.
755 query mir_callgraph_reachable(key: (ty::Instance<'tcx>, LocalDefId)) -> bool {
758 "computing if `{}` (transitively) calls `{}`",
760 tcx.def_path_str(key.1.to_def_id()),
764 /// Obtain all the calls into other local functions
765 query mir_inliner_callees(key: ty::InstanceDef<'tcx>) -> &'tcx [(DefId, SubstsRef<'tcx>)] {
768 "computing all local function calls in `{}`",
769 tcx.def_path_str(key.def_id()),
773 /// Evaluates a constant and returns the computed allocation.
775 /// **Do not use this** directly, use the `tcx.eval_static_initializer` wrapper.
776 query eval_to_allocation_raw(key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>)
777 -> EvalToAllocationRawResult<'tcx> {
779 "const-evaluating + checking `{}`",
780 key.value.display(tcx)
782 cache_on_disk_if { true }
785 /// Evaluates const items or anonymous constants
786 /// (such as enum variant explicit discriminants or array lengths)
787 /// into a representation suitable for the type system and const generics.
789 /// **Do not use this** directly, use one of the following wrappers: `tcx.const_eval_poly`,
790 /// `tcx.const_eval_resolve`, `tcx.const_eval_instance`, or `tcx.const_eval_global_id`.
791 query eval_to_const_value_raw(key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>)
792 -> EvalToConstValueResult<'tcx> {
794 "simplifying constant for the type system `{}`",
795 key.value.display(tcx)
797 cache_on_disk_if { true }
800 /// Convert an evaluated constant to a type level constant or
801 /// return `None` if that is not possible.
802 query const_to_valtree(
803 key: ty::ParamEnvAnd<'tcx, ConstAlloc<'tcx>>
804 ) -> Option<ty::ValTree<'tcx>> {
805 desc { "destructure constant" }
808 /// Destructure a constant ADT or array into its variant index and its
810 query destructure_const(
811 key: ty::ParamEnvAnd<'tcx, &'tcx ty::Const<'tcx>>
812 ) -> mir::DestructuredConst<'tcx> {
813 desc { "destructure constant" }
816 /// Dereference a constant reference or raw pointer and turn the result into a constant
819 key: ty::ParamEnvAnd<'tcx, &'tcx ty::Const<'tcx>>
820 ) -> &'tcx ty::Const<'tcx> {
821 desc { "deref constant" }
824 query const_caller_location(key: (rustc_span::Symbol, u32, u32)) -> ConstValue<'tcx> {
825 desc { "get a &core::panic::Location referring to a span" }
829 key: LitToConstInput<'tcx>
830 ) -> Result<&'tcx ty::Const<'tcx>, LitToConstError> {
831 desc { "converting literal to const" }
834 query check_match(key: DefId) {
835 desc { |tcx| "match-checking `{}`", tcx.def_path_str(key) }
836 cache_on_disk_if { key.is_local() }
839 /// Performs part of the privacy check and computes "access levels".
840 query privacy_access_levels(_: CrateNum) -> &'tcx AccessLevels {
842 desc { "privacy access levels" }
844 query check_private_in_public(_: CrateNum) -> () {
846 desc { "checking for private elements in public interfaces" }
849 query reachable_set(_: CrateNum) -> FxHashSet<LocalDefId> {
850 storage(ArenaCacheSelector<'tcx>)
851 desc { "reachability" }
854 /// Per-body `region::ScopeTree`. The `DefId` should be the owner `DefId` for the body;
855 /// in the case of closures, this will be redirected to the enclosing function.
856 query region_scope_tree(def_id: DefId) -> &'tcx region::ScopeTree {
857 desc { |tcx| "computing drop scopes for `{}`", tcx.def_path_str(def_id) }
860 query mir_shims(key: ty::InstanceDef<'tcx>) -> mir::Body<'tcx> {
861 storage(ArenaCacheSelector<'tcx>)
862 desc { |tcx| "generating MIR shim for `{}`", tcx.def_path_str(key.def_id()) }
865 /// The `symbol_name` query provides the symbol name for calling a
866 /// given instance from the local crate. In particular, it will also
867 /// look up the correct symbol name of instances from upstream crates.
868 query symbol_name(key: ty::Instance<'tcx>) -> ty::SymbolName<'tcx> {
869 desc { "computing the symbol for `{}`", key }
870 cache_on_disk_if { true }
873 query opt_def_kind(def_id: DefId) -> Option<DefKind> {
874 desc { |tcx| "looking up definition kind of `{}`", tcx.def_path_str(def_id) }
877 query def_span(def_id: DefId) -> Span {
878 desc { |tcx| "looking up span for `{}`", tcx.def_path_str(def_id) }
879 // FIXME(mw): DefSpans are not really inputs since they are derived from
880 // HIR. But at the moment HIR hashing still contains some hacks that allow
881 // to make type debuginfo to be source location independent. Declaring
882 // DefSpan an input makes sure that changes to these are always detected
883 // regardless of HIR hashing.
887 query def_ident_span(def_id: DefId) -> Option<Span> {
888 desc { |tcx| "looking up span for `{}`'s identifier", tcx.def_path_str(def_id) }
891 query lookup_stability(def_id: DefId) -> Option<&'tcx attr::Stability> {
892 desc { |tcx| "looking up stability of `{}`", tcx.def_path_str(def_id) }
895 query lookup_const_stability(def_id: DefId) -> Option<&'tcx attr::ConstStability> {
896 desc { |tcx| "looking up const stability of `{}`", tcx.def_path_str(def_id) }
899 query lookup_deprecation_entry(def_id: DefId) -> Option<DeprecationEntry> {
900 desc { |tcx| "checking whether `{}` is deprecated", tcx.def_path_str(def_id) }
903 query item_attrs(def_id: DefId) -> &'tcx [ast::Attribute] {
904 desc { |tcx| "collecting attributes of `{}`", tcx.def_path_str(def_id) }
907 query codegen_fn_attrs(def_id: DefId) -> CodegenFnAttrs {
908 desc { |tcx| "computing codegen attributes of `{}`", tcx.def_path_str(def_id) }
909 storage(ArenaCacheSelector<'tcx>)
910 cache_on_disk_if { true }
913 query fn_arg_names(def_id: DefId) -> &'tcx [rustc_span::symbol::Ident] {
914 desc { |tcx| "looking up function parameter names for `{}`", tcx.def_path_str(def_id) }
916 /// Gets the rendered value of the specified constant or associated constant.
918 query rendered_const(def_id: DefId) -> String {
919 desc { |tcx| "rendering constant intializer of `{}`", tcx.def_path_str(def_id) }
921 query impl_parent(def_id: DefId) -> Option<DefId> {
922 desc { |tcx| "computing specialization parent impl of `{}`", tcx.def_path_str(def_id) }
925 /// Given an `associated_item`, find the trait it belongs to.
926 /// Return `None` if the `DefId` is not an associated item.
927 query trait_of_item(associated_item: DefId) -> Option<DefId> {
928 desc { |tcx| "finding trait defining `{}`", tcx.def_path_str(associated_item) }
931 query is_ctfe_mir_available(key: DefId) -> bool {
932 desc { |tcx| "checking if item has ctfe mir available: `{}`", tcx.def_path_str(key) }
934 query is_mir_available(key: DefId) -> bool {
935 desc { |tcx| "checking if item has mir available: `{}`", tcx.def_path_str(key) }
938 query vtable_methods(key: ty::PolyTraitRef<'tcx>)
939 -> &'tcx [Option<(DefId, SubstsRef<'tcx>)>] {
940 desc { |tcx| "finding all methods for trait {}", tcx.def_path_str(key.def_id()) }
943 query codegen_fulfill_obligation(
944 key: (ty::ParamEnv<'tcx>, ty::PolyTraitRef<'tcx>)
945 ) -> Result<ImplSource<'tcx, ()>, ErrorReported> {
946 cache_on_disk_if { true }
948 "checking if `{}` fulfills its obligations",
949 tcx.def_path_str(key.1.def_id())
953 /// Return all `impl` blocks in the current crate.
955 /// To allow caching this between crates, you must pass in [`LOCAL_CRATE`] as the crate number.
956 /// Passing in any other crate will cause an ICE.
958 /// [`LOCAL_CRATE`]: rustc_hir::def_id::LOCAL_CRATE
959 query all_local_trait_impls(local_crate: CrateNum) -> &'tcx BTreeMap<DefId, Vec<LocalDefId>> {
960 desc { "local trait impls" }
963 /// Given a trait `trait_id`, return all known `impl` blocks.
964 query trait_impls_of(trait_id: DefId) -> ty::trait_def::TraitImpls {
965 storage(ArenaCacheSelector<'tcx>)
966 desc { |tcx| "trait impls of `{}`", tcx.def_path_str(trait_id) }
969 query specialization_graph_of(trait_id: DefId) -> specialization_graph::Graph {
970 storage(ArenaCacheSelector<'tcx>)
971 desc { |tcx| "building specialization graph of trait `{}`", tcx.def_path_str(trait_id) }
972 cache_on_disk_if { true }
974 query object_safety_violations(trait_id: DefId) -> &'tcx [traits::ObjectSafetyViolation] {
975 desc { |tcx| "determine object safety of trait `{}`", tcx.def_path_str(trait_id) }
978 /// Gets the ParameterEnvironment for a given item; this environment
979 /// will be in "user-facing" mode, meaning that it is suitable for
980 /// type-checking etc, and it does not normalize specializable
981 /// associated types. This is almost always what you want,
982 /// unless you are doing MIR optimizations, in which case you
983 /// might want to use `reveal_all()` method to change modes.
984 query param_env(def_id: DefId) -> ty::ParamEnv<'tcx> {
985 desc { |tcx| "computing normalized predicates of `{}`", tcx.def_path_str(def_id) }
988 /// Like `param_env`, but returns the `ParamEnv` in `Reveal::All` mode.
989 /// Prefer this over `tcx.param_env(def_id).with_reveal_all_normalized(tcx)`,
990 /// as this method is more efficient.
991 query param_env_reveal_all_normalized(def_id: DefId) -> ty::ParamEnv<'tcx> {
992 desc { |tcx| "computing revealed normalized predicates of `{}`", tcx.def_path_str(def_id) }
995 /// Trait selection queries. These are best used by invoking `ty.is_copy_modulo_regions()`,
996 /// `ty.is_copy()`, etc, since that will prune the environment where possible.
997 query is_copy_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
998 desc { "computing whether `{}` is `Copy`", env.value }
1000 /// Query backing `TyS::is_sized`.
1001 query is_sized_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1002 desc { "computing whether `{}` is `Sized`", env.value }
1004 /// Query backing `TyS::is_freeze`.
1005 query is_freeze_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1006 desc { "computing whether `{}` is freeze", env.value }
1008 /// Query backing `TyS::is_unpin`.
1009 query is_unpin_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1010 desc { "computing whether `{}` is `Unpin`", env.value }
1012 /// Query backing `TyS::needs_drop`.
1013 query needs_drop_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1014 desc { "computing whether `{}` needs drop", env.value }
1017 /// Query backing `TyS::is_structural_eq_shallow`.
1019 /// This is only correct for ADTs. Call `is_structural_eq_shallow` to handle all types
1021 query has_structural_eq_impls(ty: Ty<'tcx>) -> bool {
1023 "computing whether `{:?}` implements `PartialStructuralEq` and `StructuralEq`",
1028 /// A list of types where the ADT requires drop if and only if any of
1029 /// those types require drop. If the ADT is known to always need drop
1030 /// then `Err(AlwaysRequiresDrop)` is returned.
1031 query adt_drop_tys(def_id: DefId) -> Result<&'tcx ty::List<Ty<'tcx>>, AlwaysRequiresDrop> {
1032 desc { |tcx| "computing when `{}` needs drop", tcx.def_path_str(def_id) }
1033 cache_on_disk_if { true }
1037 env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>
1038 ) -> Result<&'tcx rustc_target::abi::Layout, ty::layout::LayoutError<'tcx>> {
1039 desc { "computing layout of `{}`", env.value }
1042 query dylib_dependency_formats(_: CrateNum)
1043 -> &'tcx [(CrateNum, LinkagePreference)] {
1044 desc { "dylib dependency formats of crate" }
1047 query dependency_formats(_: CrateNum)
1048 -> Lrc<crate::middle::dependency_format::Dependencies>
1050 desc { "get the linkage format of all dependencies" }
1053 query is_compiler_builtins(_: CrateNum) -> bool {
1055 desc { "checking if the crate is_compiler_builtins" }
1057 query has_global_allocator(_: CrateNum) -> bool {
1059 desc { "checking if the crate has_global_allocator" }
1061 query has_panic_handler(_: CrateNum) -> bool {
1063 desc { "checking if the crate has_panic_handler" }
1065 query is_profiler_runtime(_: CrateNum) -> bool {
1067 desc { "query a crate is `#![profiler_runtime]`" }
1069 query panic_strategy(_: CrateNum) -> PanicStrategy {
1071 desc { "query a crate's configured panic strategy" }
1073 query is_no_builtins(_: CrateNum) -> bool {
1075 desc { "test whether a crate has `#![no_builtins]`" }
1077 query symbol_mangling_version(_: CrateNum) -> SymbolManglingVersion {
1079 desc { "query a crate's symbol mangling version" }
1082 query extern_crate(def_id: DefId) -> Option<&'tcx ExternCrate> {
1084 desc { "getting crate's ExternCrateData" }
1087 query specializes(_: (DefId, DefId)) -> bool {
1088 desc { "computing whether impls specialize one another" }
1090 query in_scope_traits_map(_: LocalDefId)
1091 -> Option<&'tcx FxHashMap<ItemLocalId, StableVec<TraitCandidate>>> {
1093 desc { "traits in scope at a block" }
1096 query module_exports(def_id: LocalDefId) -> Option<&'tcx [Export<LocalDefId>]> {
1097 desc { |tcx| "looking up items exported by `{}`", tcx.def_path_str(def_id.to_def_id()) }
1101 query impl_defaultness(def_id: DefId) -> hir::Defaultness {
1102 desc { |tcx| "looking up whether `{}` is a default impl", tcx.def_path_str(def_id) }
1105 query check_item_well_formed(key: LocalDefId) -> () {
1106 desc { |tcx| "checking that `{}` is well-formed", tcx.def_path_str(key.to_def_id()) }
1108 query check_trait_item_well_formed(key: LocalDefId) -> () {
1109 desc { |tcx| "checking that `{}` is well-formed", tcx.def_path_str(key.to_def_id()) }
1111 query check_impl_item_well_formed(key: LocalDefId) -> () {
1112 desc { |tcx| "checking that `{}` is well-formed", tcx.def_path_str(key.to_def_id()) }
1115 // The `DefId`s of all non-generic functions and statics in the given crate
1116 // that can be reached from outside the crate.
1118 // We expect this items to be available for being linked to.
1120 // This query can also be called for `LOCAL_CRATE`. In this case it will
1121 // compute which items will be reachable to other crates, taking into account
1122 // the kind of crate that is currently compiled. Crates with only a
1123 // C interface have fewer reachable things.
1125 // Does not include external symbols that don't have a corresponding DefId,
1126 // like the compiler-generated `main` function and so on.
1127 query reachable_non_generics(_: CrateNum)
1128 -> DefIdMap<SymbolExportLevel> {
1129 storage(ArenaCacheSelector<'tcx>)
1130 desc { "looking up the exported symbols of a crate" }
1132 query is_reachable_non_generic(def_id: DefId) -> bool {
1133 desc { |tcx| "checking whether `{}` is an exported symbol", tcx.def_path_str(def_id) }
1135 query is_unreachable_local_definition(def_id: DefId) -> bool {
1137 "checking whether `{}` is reachable from outside the crate",
1138 tcx.def_path_str(def_id),
1142 /// The entire set of monomorphizations the local crate can safely link
1143 /// to because they are exported from upstream crates. Do not depend on
1144 /// this directly, as its value changes anytime a monomorphization gets
1145 /// added or removed in any upstream crate. Instead use the narrower
1146 /// `upstream_monomorphizations_for`, `upstream_drop_glue_for`, or, even
1147 /// better, `Instance::upstream_monomorphization()`.
1148 query upstream_monomorphizations(
1150 ) -> DefIdMap<FxHashMap<SubstsRef<'tcx>, CrateNum>> {
1151 storage(ArenaCacheSelector<'tcx>)
1152 desc { "collecting available upstream monomorphizations `{:?}`", k }
1155 /// Returns the set of upstream monomorphizations available for the
1156 /// generic function identified by the given `def_id`. The query makes
1157 /// sure to make a stable selection if the same monomorphization is
1158 /// available in multiple upstream crates.
1160 /// You likely want to call `Instance::upstream_monomorphization()`
1161 /// instead of invoking this query directly.
1162 query upstream_monomorphizations_for(def_id: DefId)
1163 -> Option<&'tcx FxHashMap<SubstsRef<'tcx>, CrateNum>> {
1165 "collecting available upstream monomorphizations for `{}`",
1166 tcx.def_path_str(def_id),
1170 /// Returns the upstream crate that exports drop-glue for the given
1171 /// type (`substs` is expected to be a single-item list containing the
1172 /// type one wants drop-glue for).
1174 /// This is a subset of `upstream_monomorphizations_for` in order to
1175 /// increase dep-tracking granularity. Otherwise adding or removing any
1176 /// type with drop-glue in any upstream crate would invalidate all
1177 /// functions calling drop-glue of an upstream type.
1179 /// You likely want to call `Instance::upstream_monomorphization()`
1180 /// instead of invoking this query directly.
1182 /// NOTE: This query could easily be extended to also support other
1183 /// common functions that have are large set of monomorphizations
1184 /// (like `Clone::clone` for example).
1185 query upstream_drop_glue_for(substs: SubstsRef<'tcx>) -> Option<CrateNum> {
1186 desc { "available upstream drop-glue for `{:?}`", substs }
1189 query foreign_modules(_: CrateNum) -> Lrc<FxHashMap<DefId, ForeignModule>> {
1190 desc { "looking up the foreign modules of a linked crate" }
1193 /// Identifies the entry-point (e.g., the `main` function) for a given
1194 /// crate, returning `None` if there is no entry point (such as for library crates).
1195 query entry_fn(_: CrateNum) -> Option<(LocalDefId, EntryFnType)> {
1196 desc { "looking up the entry function of a crate" }
1198 query plugin_registrar_fn(_: CrateNum) -> Option<DefId> {
1199 desc { "looking up the plugin registrar for a crate" }
1201 query proc_macro_decls_static(_: CrateNum) -> Option<DefId> {
1202 desc { "looking up the derive registrar for a crate" }
1204 query crate_disambiguator(_: CrateNum) -> CrateDisambiguator {
1206 desc { "looking up the disambiguator a crate" }
1208 // The macro which defines `rustc_metadata::provide_extern` depends on this query's name.
1209 // Changing the name should cause a compiler error, but in case that changes, be aware.
1210 query crate_hash(_: CrateNum) -> Svh {
1212 desc { "looking up the hash a crate" }
1214 query crate_host_hash(_: CrateNum) -> Option<Svh> {
1216 desc { "looking up the hash of a host version of a crate" }
1218 query original_crate_name(_: CrateNum) -> Symbol {
1220 desc { "looking up the original name a crate" }
1222 query extra_filename(_: CrateNum) -> String {
1224 desc { "looking up the extra filename for a crate" }
1226 query crate_extern_paths(_: CrateNum) -> Vec<PathBuf> {
1228 desc { "looking up the paths for extern crates" }
1231 /// Given a crate and a trait, look up all impls of that trait in the crate.
1232 /// Return `(impl_id, self_ty)`.
1233 query implementations_of_trait(_: (CrateNum, DefId))
1234 -> &'tcx [(DefId, Option<ty::fast_reject::SimplifiedType>)] {
1235 desc { "looking up implementations of a trait in a crate" }
1238 /// Given a crate, look up all trait impls in that crate.
1239 /// Return `(impl_id, self_ty)`.
1240 query all_trait_implementations(_: CrateNum)
1241 -> &'tcx [(DefId, Option<ty::fast_reject::SimplifiedType>)] {
1242 desc { "looking up all (?) trait implementations" }
1245 query is_dllimport_foreign_item(def_id: DefId) -> bool {
1246 desc { |tcx| "is_dllimport_foreign_item({})", tcx.def_path_str(def_id) }
1248 query is_statically_included_foreign_item(def_id: DefId) -> bool {
1249 desc { |tcx| "is_statically_included_foreign_item({})", tcx.def_path_str(def_id) }
1251 query native_library_kind(def_id: DefId)
1252 -> Option<NativeLibKind> {
1253 desc { |tcx| "native_library_kind({})", tcx.def_path_str(def_id) }
1256 /// Does lifetime resolution, but does not descend into trait items. This
1257 /// should only be used for resolving lifetimes of on trait definitions,
1258 /// and is used to avoid cycles. Importantly, `resolve_lifetimes` still visits
1259 /// the same lifetimes and is responsible for diagnostics.
1260 /// See `rustc_resolve::late::lifetimes for details.
1261 query resolve_lifetimes_trait_definition(_: LocalDefId) -> ResolveLifetimes {
1262 storage(ArenaCacheSelector<'tcx>)
1263 desc { "resolving lifetimes for a trait definition" }
1265 /// Does lifetime resolution on items. Importantly, we can't resolve
1266 /// lifetimes directly on things like trait methods, because of trait params.
1267 /// See `rustc_resolve::late::lifetimes for details.
1268 query resolve_lifetimes(_: LocalDefId) -> ResolveLifetimes {
1269 storage(ArenaCacheSelector<'tcx>)
1270 desc { "resolving lifetimes" }
1272 query named_region_map(_: LocalDefId) ->
1273 Option<&'tcx FxHashMap<ItemLocalId, Region>> {
1274 desc { "looking up a named region" }
1276 query is_late_bound_map(_: LocalDefId) ->
1277 Option<(LocalDefId, &'tcx FxHashSet<ItemLocalId>)> {
1278 desc { "testing if a region is late bound" }
1280 /// For a given item (like a struct), gets the default lifetimes to be used
1281 /// for each paramter if a trait object were to be passed for that parameter.
1282 /// For example, for `struct Foo<'a, T, U>`, this would be `['static, 'static]`.
1283 /// For `struct Foo<'a, T: 'a, U>`, this would instead be `['a, 'static]`.
1284 query object_lifetime_defaults_map(_: LocalDefId)
1285 -> Option<Vec<ObjectLifetimeDefault>> {
1286 desc { "looking up lifetime defaults for a region on an item" }
1288 query late_bound_vars_map(_: LocalDefId)
1289 -> Option<&'tcx FxHashMap<ItemLocalId, Vec<ty::BoundVariableKind>>> {
1290 desc { "looking up late bound vars" }
1293 query visibility(def_id: DefId) -> ty::Visibility {
1295 desc { |tcx| "computing visibility of `{}`", tcx.def_path_str(def_id) }
1298 /// Computes the set of modules from which this type is visibly uninhabited.
1299 /// To check whether a type is uninhabited at all (not just from a given module), you could
1300 /// check whether the forest is empty.
1301 query type_uninhabited_from(
1302 key: ty::ParamEnvAnd<'tcx, Ty<'tcx>>
1303 ) -> ty::inhabitedness::DefIdForest {
1304 desc { "computing the inhabitedness of `{:?}`", key }
1307 query dep_kind(_: CrateNum) -> CrateDepKind {
1309 desc { "fetching what a dependency looks like" }
1311 query crate_name(_: CrateNum) -> Symbol {
1313 desc { "fetching what a crate is named" }
1315 query item_children(def_id: DefId) -> &'tcx [Export<hir::HirId>] {
1316 desc { |tcx| "collecting child items of `{}`", tcx.def_path_str(def_id) }
1318 query extern_mod_stmt_cnum(def_id: LocalDefId) -> Option<CrateNum> {
1319 // This depends on untracked global state (`tcx.extern_crate_map`)
1321 desc { |tcx| "computing crate imported by `{}`", tcx.def_path_str(def_id.to_def_id()) }
1324 query get_lib_features(_: CrateNum) -> LibFeatures {
1325 storage(ArenaCacheSelector<'tcx>)
1327 desc { "calculating the lib features map" }
1329 query defined_lib_features(_: CrateNum)
1330 -> &'tcx [(Symbol, Option<Symbol>)] {
1331 desc { "calculating the lib features defined in a crate" }
1333 /// Returns the lang items defined in another crate by loading it from metadata.
1334 // FIXME: It is illegal to pass a `CrateNum` other than `LOCAL_CRATE` here, just get rid
1335 // of that argument?
1336 query get_lang_items(_: CrateNum) -> LanguageItems {
1337 storage(ArenaCacheSelector<'tcx>)
1339 desc { "calculating the lang items map" }
1342 /// Returns all diagnostic items defined in all crates.
1343 query all_diagnostic_items(_: CrateNum) -> FxHashMap<Symbol, DefId> {
1344 storage(ArenaCacheSelector<'tcx>)
1346 desc { "calculating the diagnostic items map" }
1349 /// Returns the lang items defined in another crate by loading it from metadata.
1350 query defined_lang_items(_: CrateNum) -> &'tcx [(DefId, usize)] {
1351 desc { "calculating the lang items defined in a crate" }
1354 /// Returns the diagnostic items defined in a crate.
1355 query diagnostic_items(_: CrateNum) -> FxHashMap<Symbol, DefId> {
1356 storage(ArenaCacheSelector<'tcx>)
1357 desc { "calculating the diagnostic items map in a crate" }
1360 query missing_lang_items(_: CrateNum) -> &'tcx [LangItem] {
1361 desc { "calculating the missing lang items in a crate" }
1363 query visible_parent_map(_: CrateNum)
1364 -> DefIdMap<DefId> {
1365 storage(ArenaCacheSelector<'tcx>)
1366 desc { "calculating the visible parent map" }
1368 query trimmed_def_paths(_: CrateNum)
1369 -> FxHashMap<DefId, Symbol> {
1370 storage(ArenaCacheSelector<'tcx>)
1371 desc { "calculating trimmed def paths" }
1373 query missing_extern_crate_item(_: CrateNum) -> bool {
1375 desc { "seeing if we're missing an `extern crate` item for this crate" }
1377 query used_crate_source(_: CrateNum) -> Lrc<CrateSource> {
1379 desc { "looking at the source for a crate" }
1381 query postorder_cnums(_: CrateNum) -> &'tcx [CrateNum] {
1383 desc { "generating a postorder list of CrateNums" }
1386 query upvars_mentioned(def_id: DefId) -> Option<&'tcx FxIndexMap<hir::HirId, hir::Upvar>> {
1387 desc { |tcx| "collecting upvars mentioned in `{}`", tcx.def_path_str(def_id) }
1390 query maybe_unused_trait_import(def_id: LocalDefId) -> bool {
1392 desc { |tcx| "maybe_unused_trait_import for `{}`", tcx.def_path_str(def_id.to_def_id()) }
1394 query maybe_unused_extern_crates(_: CrateNum)
1395 -> &'tcx [(LocalDefId, Span)] {
1397 desc { "looking up all possibly unused extern crates" }
1399 query names_imported_by_glob_use(def_id: LocalDefId)
1400 -> &'tcx FxHashSet<Symbol> {
1402 desc { |tcx| "names_imported_by_glob_use for `{}`", tcx.def_path_str(def_id.to_def_id()) }
1405 query stability_index(_: CrateNum) -> stability::Index<'tcx> {
1406 storage(ArenaCacheSelector<'tcx>)
1408 desc { "calculating the stability index for the local crate" }
1410 query all_crate_nums(_: CrateNum) -> &'tcx [CrateNum] {
1412 desc { "fetching all foreign CrateNum instances" }
1415 /// A vector of every trait accessible in the whole crate
1416 /// (i.e., including those from subcrates). This is used only for
1417 /// error reporting.
1418 query all_traits(_: CrateNum) -> &'tcx [DefId] {
1419 desc { "fetching all foreign and local traits" }
1422 /// The list of symbols exported from the given crate.
1424 /// - All names contained in `exported_symbols(cnum)` are guaranteed to
1425 /// correspond to a publicly visible symbol in `cnum` machine code.
1426 /// - The `exported_symbols` sets of different crates do not intersect.
1427 query exported_symbols(_: CrateNum)
1428 -> &'tcx [(ExportedSymbol<'tcx>, SymbolExportLevel)] {
1429 desc { "exported_symbols" }
1432 query collect_and_partition_mono_items(_: CrateNum)
1433 -> (&'tcx DefIdSet, &'tcx [CodegenUnit<'tcx>]) {
1435 desc { "collect_and_partition_mono_items" }
1437 query is_codegened_item(def_id: DefId) -> bool {
1438 desc { |tcx| "determining whether `{}` needs codegen", tcx.def_path_str(def_id) }
1441 /// All items participating in code generation together with items inlined into them.
1442 query codegened_and_inlined_items(_: CrateNum)
1445 desc { "codegened_and_inlined_items" }
1448 query codegen_unit(_: Symbol) -> &'tcx CodegenUnit<'tcx> {
1449 desc { "codegen_unit" }
1451 query unused_generic_params(key: DefId) -> FiniteBitSet<u32> {
1452 cache_on_disk_if { key.is_local() }
1454 |tcx| "determining which generic parameters are unused by `{}`",
1455 tcx.def_path_str(key)
1458 query backend_optimization_level(_: CrateNum) -> OptLevel {
1459 desc { "optimization level used by backend" }
1462 query output_filenames(_: CrateNum) -> Arc<OutputFilenames> {
1464 desc { "output_filenames" }
1467 /// Do not call this query directly: invoke `normalize` instead.
1468 query normalize_projection_ty(
1469 goal: CanonicalProjectionGoal<'tcx>
1471 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, NormalizationResult<'tcx>>>,
1474 desc { "normalizing `{:?}`", goal }
1477 /// Do not call this query directly: invoke `normalize_erasing_regions` instead.
1478 query normalize_generic_arg_after_erasing_regions(
1479 goal: ParamEnvAnd<'tcx, GenericArg<'tcx>>
1480 ) -> GenericArg<'tcx> {
1481 desc { "normalizing `{}`", goal.value }
1484 /// Do not call this query directly: invoke `normalize_erasing_regions` instead.
1485 query normalize_mir_const_after_erasing_regions(
1486 goal: ParamEnvAnd<'tcx, mir::ConstantKind<'tcx>>
1487 ) -> mir::ConstantKind<'tcx> {
1488 desc { "normalizing `{}`", goal.value }
1491 query implied_outlives_bounds(
1492 goal: CanonicalTyGoal<'tcx>
1494 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, Vec<OutlivesBound<'tcx>>>>,
1497 desc { "computing implied outlives bounds for `{:?}`", goal }
1500 /// Do not call this query directly: invoke `infcx.at().dropck_outlives()` instead.
1501 query dropck_outlives(
1502 goal: CanonicalTyGoal<'tcx>
1504 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, DropckOutlivesResult<'tcx>>>,
1507 desc { "computing dropck types for `{:?}`", goal }
1510 /// Do not call this query directly: invoke `infcx.predicate_may_hold()` or
1511 /// `infcx.predicate_must_hold()` instead.
1512 query evaluate_obligation(
1513 goal: CanonicalPredicateGoal<'tcx>
1514 ) -> Result<traits::EvaluationResult, traits::OverflowError> {
1515 desc { "evaluating trait selection obligation `{}`", goal.value.value }
1518 query evaluate_goal(
1519 goal: traits::CanonicalChalkEnvironmentAndGoal<'tcx>
1521 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1524 desc { "evaluating trait selection obligation `{}`", goal.value }
1527 query type_implements_trait(
1528 key: (DefId, Ty<'tcx>, SubstsRef<'tcx>, ty::ParamEnv<'tcx>, )
1530 desc { "evaluating `type_implements_trait` `{:?}`", key }
1533 /// Do not call this query directly: part of the `Eq` type-op
1534 query type_op_ascribe_user_type(
1535 goal: CanonicalTypeOpAscribeUserTypeGoal<'tcx>
1537 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1540 desc { "evaluating `type_op_ascribe_user_type` `{:?}`", goal }
1543 /// Do not call this query directly: part of the `Eq` type-op
1545 goal: CanonicalTypeOpEqGoal<'tcx>
1547 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1550 desc { "evaluating `type_op_eq` `{:?}`", goal }
1553 /// Do not call this query directly: part of the `Subtype` type-op
1554 query type_op_subtype(
1555 goal: CanonicalTypeOpSubtypeGoal<'tcx>
1557 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1560 desc { "evaluating `type_op_subtype` `{:?}`", goal }
1563 /// Do not call this query directly: part of the `ProvePredicate` type-op
1564 query type_op_prove_predicate(
1565 goal: CanonicalTypeOpProvePredicateGoal<'tcx>
1567 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1570 desc { "evaluating `type_op_prove_predicate` `{:?}`", goal }
1573 /// Do not call this query directly: part of the `Normalize` type-op
1574 query type_op_normalize_ty(
1575 goal: CanonicalTypeOpNormalizeGoal<'tcx, Ty<'tcx>>
1577 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, Ty<'tcx>>>,
1580 desc { "normalizing `{:?}`", goal }
1583 /// Do not call this query directly: part of the `Normalize` type-op
1584 query type_op_normalize_predicate(
1585 goal: CanonicalTypeOpNormalizeGoal<'tcx, ty::Predicate<'tcx>>
1587 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ty::Predicate<'tcx>>>,
1590 desc { "normalizing `{:?}`", goal }
1593 /// Do not call this query directly: part of the `Normalize` type-op
1594 query type_op_normalize_poly_fn_sig(
1595 goal: CanonicalTypeOpNormalizeGoal<'tcx, ty::PolyFnSig<'tcx>>
1597 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ty::PolyFnSig<'tcx>>>,
1600 desc { "normalizing `{:?}`", goal }
1603 /// Do not call this query directly: part of the `Normalize` type-op
1604 query type_op_normalize_fn_sig(
1605 goal: CanonicalTypeOpNormalizeGoal<'tcx, ty::FnSig<'tcx>>
1607 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ty::FnSig<'tcx>>>,
1610 desc { "normalizing `{:?}`", goal }
1613 query subst_and_check_impossible_predicates(key: (DefId, SubstsRef<'tcx>)) -> bool {
1615 "impossible substituted predicates:`{}`",
1616 tcx.def_path_str(key.0)
1620 query method_autoderef_steps(
1621 goal: CanonicalTyGoal<'tcx>
1622 ) -> MethodAutoderefStepsResult<'tcx> {
1623 desc { "computing autoderef types for `{:?}`", goal }
1626 query supported_target_features(_: CrateNum) -> FxHashMap<String, Option<Symbol>> {
1627 storage(ArenaCacheSelector<'tcx>)
1629 desc { "looking up supported target features" }
1632 /// Get an estimate of the size of an InstanceDef based on its MIR for CGU partitioning.
1633 query instance_def_size_estimate(def: ty::InstanceDef<'tcx>)
1635 desc { |tcx| "estimating size for `{}`", tcx.def_path_str(def.def_id()) }
1638 query features_query(_: CrateNum) -> &'tcx rustc_feature::Features {
1640 desc { "looking up enabled feature gates" }
1643 /// Attempt to resolve the given `DefId` to an `Instance`, for the
1644 /// given generics args (`SubstsRef`), returning one of:
1645 /// * `Ok(Some(instance))` on success
1646 /// * `Ok(None)` when the `SubstsRef` are still too generic,
1647 /// and therefore don't allow finding the final `Instance`
1648 /// * `Err(ErrorReported)` when the `Instance` resolution process
1649 /// couldn't complete due to errors elsewhere - this is distinct
1650 /// from `Ok(None)` to avoid misleading diagnostics when an error
1651 /// has already been/will be emitted, for the original cause
1652 query resolve_instance(
1653 key: ty::ParamEnvAnd<'tcx, (DefId, SubstsRef<'tcx>)>
1654 ) -> Result<Option<ty::Instance<'tcx>>, ErrorReported> {
1655 desc { "resolving instance `{}`", ty::Instance::new(key.value.0, key.value.1) }
1658 query resolve_instance_of_const_arg(
1659 key: ty::ParamEnvAnd<'tcx, (LocalDefId, DefId, SubstsRef<'tcx>)>
1660 ) -> Result<Option<ty::Instance<'tcx>>, ErrorReported> {
1662 "resolving instance of the const argument `{}`",
1663 ty::Instance::new(key.value.0.to_def_id(), key.value.2),
1667 query normalize_opaque_types(key: &'tcx ty::List<ty::Predicate<'tcx>>) -> &'tcx ty::List<ty::Predicate<'tcx>> {
1668 desc { "normalizing opaque types in {:?}", key }
1671 /// Checks whether a type is definitely uninhabited. This is
1672 /// conservative: for some types that are uninhabited we return `false`,
1673 /// but we only return `true` for types that are definitely uninhabited.
1674 /// `ty.conservative_is_privately_uninhabited` implies that any value of type `ty`
1675 /// will be `Abi::Uninhabited`. (Note that uninhabited types may have nonzero
1676 /// size, to account for partial initialisation. See #49298 for details.)
1677 query conservative_is_privately_uninhabited(key: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1678 desc { "conservatively checking if {:?} is privately uninhabited", key }