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: ()) -> &'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(_: ()) -> &'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<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: ()) -> 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 native_libraries(_: CrateNum) -> Lrc<Vec<NativeLib>> {
195 desc { "looking up the native libraries of a linked crate" }
198 query lint_levels(_: ()) -> LintLevelMap {
199 storage(ArenaCacheSelector<'tcx>)
201 desc { "computing the lint levels for items in this crate" }
204 query parent_module_from_def_id(key: LocalDefId) -> LocalDefId {
206 desc { |tcx| "parent module of `{}`", tcx.def_path_str(key.to_def_id()) }
209 query expn_that_defined(key: DefId) -> rustc_span::ExpnId {
211 desc { |tcx| "expansion that defined `{}`", tcx.def_path_str(key) }
214 query is_panic_runtime(_: CrateNum) -> bool {
216 desc { "checking if the crate is_panic_runtime" }
219 /// Fetch the THIR for a given body. If typeck for that body failed, returns an empty `Thir`.
220 query thir_body(key: ty::WithOptConstParam<LocalDefId>) -> (&'tcx Steal<thir::Thir<'tcx>>, thir::ExprId) {
221 // Perf tests revealed that hashing THIR is inefficient (see #85729).
223 desc { |tcx| "building THIR for `{}`", tcx.def_path_str(key.did.to_def_id()) }
226 /// Set of all the `DefId`s in this crate that have MIR associated with
227 /// them. This includes all the body owners, but also things like struct
229 query mir_keys(_: ()) -> FxHashSet<LocalDefId> {
230 storage(ArenaCacheSelector<'tcx>)
231 desc { "getting a list of all mir_keys" }
234 /// Maps DefId's that have an associated `mir::Body` to the result
235 /// of the MIR const-checking pass. This is the set of qualifs in
236 /// the final value of a `const`.
237 query mir_const_qualif(key: DefId) -> mir::ConstQualifs {
238 desc { |tcx| "const checking `{}`", tcx.def_path_str(key) }
239 cache_on_disk_if { key.is_local() }
241 query mir_const_qualif_const_arg(
242 key: (LocalDefId, DefId)
243 ) -> mir::ConstQualifs {
245 |tcx| "const checking the const argument `{}`",
246 tcx.def_path_str(key.0.to_def_id())
250 /// Fetch the MIR for a given `DefId` right after it's built - this includes
251 /// unreachable code.
252 query mir_built(key: ty::WithOptConstParam<LocalDefId>) -> &'tcx Steal<mir::Body<'tcx>> {
253 desc { |tcx| "building MIR for `{}`", tcx.def_path_str(key.did.to_def_id()) }
256 /// Fetch the MIR for a given `DefId` up till the point where it is
257 /// ready for const qualification.
259 /// See the README for the `mir` module for details.
260 query mir_const(key: ty::WithOptConstParam<LocalDefId>) -> &'tcx Steal<mir::Body<'tcx>> {
262 |tcx| "processing MIR for {}`{}`",
263 if key.const_param_did.is_some() { "the const argument " } else { "" },
264 tcx.def_path_str(key.did.to_def_id()),
269 /// Try to build an abstract representation of the given constant.
270 query mir_abstract_const(
272 ) -> Result<Option<&'tcx [mir::abstract_const::Node<'tcx>]>, ErrorReported> {
274 |tcx| "building an abstract representation for {}", tcx.def_path_str(key),
277 /// Try to build an abstract representation of the given constant.
278 query mir_abstract_const_of_const_arg(
279 key: (LocalDefId, DefId)
280 ) -> Result<Option<&'tcx [mir::abstract_const::Node<'tcx>]>, ErrorReported> {
283 "building an abstract representation for the const argument {}",
284 tcx.def_path_str(key.0.to_def_id()),
288 query try_unify_abstract_consts(key: (
289 (ty::WithOptConstParam<DefId>, SubstsRef<'tcx>),
290 (ty::WithOptConstParam<DefId>, SubstsRef<'tcx>)
293 |tcx| "trying to unify the generic constants {} and {}",
294 tcx.def_path_str(key.0.0.did), tcx.def_path_str(key.1.0.did)
298 query mir_drops_elaborated_and_const_checked(
299 key: ty::WithOptConstParam<LocalDefId>
300 ) -> &'tcx Steal<mir::Body<'tcx>> {
302 desc { |tcx| "elaborating drops for `{}`", tcx.def_path_str(key.did.to_def_id()) }
307 ) -> &'tcx mir::Body<'tcx> {
308 desc { |tcx| "caching mir of `{}` for CTFE", tcx.def_path_str(key) }
309 cache_on_disk_if { key.is_local() }
312 query mir_for_ctfe_of_const_arg(key: (LocalDefId, DefId)) -> &'tcx mir::Body<'tcx> {
314 |tcx| "MIR for CTFE of the const argument `{}`",
315 tcx.def_path_str(key.0.to_def_id())
319 query mir_promoted(key: ty::WithOptConstParam<LocalDefId>) ->
321 &'tcx Steal<mir::Body<'tcx>>,
322 &'tcx Steal<IndexVec<mir::Promoted, mir::Body<'tcx>>>
326 |tcx| "processing {}`{}`",
327 if key.const_param_did.is_some() { "the const argument " } else { "" },
328 tcx.def_path_str(key.did.to_def_id()),
332 /// MIR after our optimization passes have run. This is MIR that is ready
333 /// for codegen. This is also the only query that can fetch non-local MIR, at present.
334 query optimized_mir(key: DefId) -> &'tcx mir::Body<'tcx> {
335 desc { |tcx| "optimizing MIR for `{}`", tcx.def_path_str(key) }
336 cache_on_disk_if { key.is_local() }
339 /// Returns coverage summary info for a function, after executing the `InstrumentCoverage`
340 /// MIR pass (assuming the -Zinstrument-coverage option is enabled).
341 query coverageinfo(key: ty::InstanceDef<'tcx>) -> mir::CoverageInfo {
342 desc { |tcx| "retrieving coverage info from MIR for `{}`", tcx.def_path_str(key.def_id()) }
343 storage(ArenaCacheSelector<'tcx>)
346 /// Returns the name of the file that contains the function body, if instrumented for coverage.
347 query covered_file_name(key: DefId) -> Option<Symbol> {
349 |tcx| "retrieving the covered file name, if instrumented, for `{}`",
350 tcx.def_path_str(key)
352 storage(ArenaCacheSelector<'tcx>)
353 cache_on_disk_if { key.is_local() }
356 /// Returns the `CodeRegions` for a function that has instrumented coverage, in case the
357 /// function was optimized out before codegen, and before being added to the Coverage Map.
358 query covered_code_regions(key: DefId) -> Vec<&'tcx mir::coverage::CodeRegion> {
360 |tcx| "retrieving the covered `CodeRegion`s, if instrumented, for `{}`",
361 tcx.def_path_str(key)
363 storage(ArenaCacheSelector<'tcx>)
364 cache_on_disk_if { key.is_local() }
367 /// The `DefId` is the `DefId` of the containing MIR body. Promoteds do not have their own
368 /// `DefId`. This function returns all promoteds in the specified body. The body references
369 /// promoteds by the `DefId` and the `mir::Promoted` index. This is necessary, because
370 /// after inlining a body may refer to promoteds from other bodies. In that case you still
371 /// need to use the `DefId` of the original body.
372 query promoted_mir(key: DefId) -> &'tcx IndexVec<mir::Promoted, mir::Body<'tcx>> {
373 desc { |tcx| "optimizing promoted MIR for `{}`", tcx.def_path_str(key) }
374 cache_on_disk_if { key.is_local() }
376 query promoted_mir_of_const_arg(
377 key: (LocalDefId, DefId)
378 ) -> &'tcx IndexVec<mir::Promoted, mir::Body<'tcx>> {
380 |tcx| "optimizing promoted MIR for the const argument `{}`",
381 tcx.def_path_str(key.0.to_def_id()),
385 /// Erases regions from `ty` to yield a new type.
386 /// Normally you would just use `tcx.erase_regions(value)`,
387 /// however, which uses this query as a kind of cache.
388 query erase_regions_ty(ty: Ty<'tcx>) -> Ty<'tcx> {
389 // This query is not expected to have input -- as a result, it
390 // is not a good candidates for "replay" because it is essentially a
391 // pure function of its input (and hence the expectation is that
392 // no caller would be green **apart** from just these
393 // queries). Making it anonymous avoids hashing the result, which
394 // may save a bit of time.
396 desc { "erasing regions from `{:?}`", ty }
399 query wasm_import_module_map(_: CrateNum) -> FxHashMap<DefId, String> {
400 storage(ArenaCacheSelector<'tcx>)
401 desc { "wasm import module map" }
404 /// Maps from the `DefId` of an item (trait/struct/enum/fn) to the
405 /// predicates (where-clauses) directly defined on it. This is
406 /// equal to the `explicit_predicates_of` predicates plus the
407 /// `inferred_outlives_of` predicates.
408 query predicates_defined_on(key: DefId) -> ty::GenericPredicates<'tcx> {
409 desc { |tcx| "computing predicates of `{}`", tcx.def_path_str(key) }
412 /// Returns everything that looks like a predicate written explicitly
413 /// by the user on a trait item.
415 /// Traits are unusual, because predicates on associated types are
416 /// converted into bounds on that type for backwards compatibility:
418 /// trait X where Self::U: Copy { type U; }
422 /// trait X { type U: Copy; }
424 /// `explicit_predicates_of` and `explicit_item_bounds` will then take
425 /// the appropriate subsets of the predicates here.
426 query trait_explicit_predicates_and_bounds(key: LocalDefId) -> ty::GenericPredicates<'tcx> {
427 desc { |tcx| "computing explicit predicates of trait `{}`", tcx.def_path_str(key.to_def_id()) }
430 /// Returns the predicates written explicitly by the user.
431 query explicit_predicates_of(key: DefId) -> ty::GenericPredicates<'tcx> {
432 desc { |tcx| "computing explicit predicates of `{}`", tcx.def_path_str(key) }
435 /// Returns the inferred outlives predicates (e.g., for `struct
436 /// Foo<'a, T> { x: &'a T }`, this would return `T: 'a`).
437 query inferred_outlives_of(key: DefId) -> &'tcx [(ty::Predicate<'tcx>, Span)] {
438 desc { |tcx| "computing inferred outlives predicates of `{}`", tcx.def_path_str(key) }
441 /// Maps from the `DefId` of a trait to the list of
442 /// super-predicates. This is a subset of the full list of
443 /// predicates. We store these in a separate map because we must
444 /// evaluate them even during type conversion, often before the
445 /// full predicates are available (note that supertraits have
446 /// additional acyclicity requirements).
447 query super_predicates_of(key: DefId) -> ty::GenericPredicates<'tcx> {
448 desc { |tcx| "computing the super predicates of `{}`", tcx.def_path_str(key) }
451 /// The `Option<Ident>` is the name of an associated type. If it is `None`, then this query
452 /// returns the full set of predicates. If `Some<Ident>`, then the query returns only the
453 /// subset of super-predicates that reference traits that define the given associated type.
454 /// This is used to avoid cycles in resolving types like `T::Item`.
455 query super_predicates_that_define_assoc_type(key: (DefId, Option<rustc_span::symbol::Ident>)) -> ty::GenericPredicates<'tcx> {
456 desc { |tcx| "computing the super traits of `{}`{}",
457 tcx.def_path_str(key.0),
458 if let Some(assoc_name) = key.1 { format!(" with associated type name `{}`", assoc_name) } else { "".to_string() },
462 /// To avoid cycles within the predicates of a single item we compute
463 /// per-type-parameter predicates for resolving `T::AssocTy`.
464 query type_param_predicates(key: (DefId, LocalDefId, rustc_span::symbol::Ident)) -> ty::GenericPredicates<'tcx> {
465 desc { |tcx| "computing the bounds for type parameter `{}`", {
466 let id = tcx.hir().local_def_id_to_hir_id(key.1);
467 tcx.hir().ty_param_name(id)
471 query trait_def(key: DefId) -> ty::TraitDef {
472 desc { |tcx| "computing trait definition for `{}`", tcx.def_path_str(key) }
473 storage(ArenaCacheSelector<'tcx>)
475 query adt_def(key: DefId) -> &'tcx ty::AdtDef {
476 desc { |tcx| "computing ADT definition for `{}`", tcx.def_path_str(key) }
478 query adt_destructor(key: DefId) -> Option<ty::Destructor> {
479 desc { |tcx| "computing `Drop` impl for `{}`", tcx.def_path_str(key) }
482 // The cycle error here should be reported as an error by `check_representable`.
483 // We consider the type as Sized in the meanwhile to avoid
484 // further errors (done in impl Value for AdtSizedConstraint).
485 // Use `cycle_delay_bug` to delay the cycle error here to be emitted later
486 // in case we accidentally otherwise don't emit an error.
487 query adt_sized_constraint(
489 ) -> AdtSizedConstraint<'tcx> {
490 desc { |tcx| "computing `Sized` constraints for `{}`", tcx.def_path_str(key) }
494 query adt_dtorck_constraint(
496 ) -> Result<DtorckConstraint<'tcx>, NoSolution> {
497 desc { |tcx| "computing drop-check constraints for `{}`", tcx.def_path_str(key) }
500 /// Returns `true` if this is a const fn, use the `is_const_fn` to know whether your crate
501 /// actually sees it as const fn (e.g., the const-fn-ness might be unstable and you might
502 /// not have the feature gate active).
504 /// **Do not call this function manually.** It is only meant to cache the base data for the
505 /// `is_const_fn` function.
506 query is_const_fn_raw(key: DefId) -> bool {
507 desc { |tcx| "checking if item is const fn: `{}`", tcx.def_path_str(key) }
510 /// Returns `true` if this is a const `impl`. **Do not call this function manually.**
512 /// This query caches the base data for the `is_const_impl` helper function, which also
513 /// takes into account stability attributes (e.g., `#[rustc_const_unstable]`).
514 query is_const_impl_raw(key: DefId) -> bool {
515 desc { |tcx| "checking if item is const impl: `{}`", tcx.def_path_str(key) }
518 query asyncness(key: DefId) -> hir::IsAsync {
519 desc { |tcx| "checking if the function is async: `{}`", tcx.def_path_str(key) }
522 /// Returns `true` if calls to the function may be promoted.
524 /// This is either because the function is e.g., a tuple-struct or tuple-variant
525 /// constructor, or because it has the `#[rustc_promotable]` attribute. The attribute should
526 /// be removed in the future in favour of some form of check which figures out whether the
527 /// function does not inspect the bits of any of its arguments (so is essentially just a
528 /// constructor function).
529 query is_promotable_const_fn(key: DefId) -> bool {
530 desc { |tcx| "checking if item is promotable: `{}`", tcx.def_path_str(key) }
533 /// Returns `true` if this is a foreign item (i.e., linked via `extern { ... }`).
534 query is_foreign_item(key: DefId) -> bool {
535 desc { |tcx| "checking if `{}` is a foreign item", tcx.def_path_str(key) }
538 /// Returns `Some(mutability)` if the node pointed to by `def_id` is a static item.
539 query static_mutability(def_id: DefId) -> Option<hir::Mutability> {
540 desc { |tcx| "looking up static mutability of `{}`", tcx.def_path_str(def_id) }
543 /// Returns `Some(generator_kind)` if the node pointed to by `def_id` is a generator.
544 query generator_kind(def_id: DefId) -> Option<hir::GeneratorKind> {
545 desc { |tcx| "looking up generator kind of `{}`", tcx.def_path_str(def_id) }
548 /// Gets a map with the variance of every item; use `item_variance` instead.
549 query crate_variances(_: ()) -> ty::CrateVariancesMap<'tcx> {
550 storage(ArenaCacheSelector<'tcx>)
551 desc { "computing the variances for items in this crate" }
554 /// Maps from the `DefId` of a type or region parameter to its (inferred) variance.
555 query variances_of(def_id: DefId) -> &'tcx [ty::Variance] {
556 desc { |tcx| "computing the variances of `{}`", tcx.def_path_str(def_id) }
559 /// Maps from thee `DefId` of a type to its (inferred) outlives.
560 query inferred_outlives_crate(_: ()) -> ty::CratePredicatesMap<'tcx> {
561 storage(ArenaCacheSelector<'tcx>)
562 desc { "computing the inferred outlives predicates for items in this crate" }
565 /// Maps from an impl/trait `DefId to a list of the `DefId`s of its items.
566 query associated_item_def_ids(key: DefId) -> &'tcx [DefId] {
567 desc { |tcx| "collecting associated items of `{}`", tcx.def_path_str(key) }
570 /// Maps from a trait item to the trait item "descriptor".
571 query associated_item(key: DefId) -> ty::AssocItem {
572 desc { |tcx| "computing associated item data for `{}`", tcx.def_path_str(key) }
573 storage(ArenaCacheSelector<'tcx>)
576 /// Collects the associated items defined on a trait or impl.
577 query associated_items(key: DefId) -> ty::AssocItems<'tcx> {
578 storage(ArenaCacheSelector<'tcx>)
579 desc { |tcx| "collecting associated items of {}", tcx.def_path_str(key) }
582 /// Given an `impl_id`, return the trait it implements.
583 /// Return `None` if this is an inherent impl.
584 query impl_trait_ref(impl_id: DefId) -> Option<ty::TraitRef<'tcx>> {
585 desc { |tcx| "computing trait implemented by `{}`", tcx.def_path_str(impl_id) }
587 query impl_polarity(impl_id: DefId) -> ty::ImplPolarity {
588 desc { |tcx| "computing implementation polarity of `{}`", tcx.def_path_str(impl_id) }
591 query issue33140_self_ty(key: DefId) -> Option<ty::Ty<'tcx>> {
592 desc { |tcx| "computing Self type wrt issue #33140 `{}`", tcx.def_path_str(key) }
595 /// Maps a `DefId` of a type to a list of its inherent impls.
596 /// Contains implementations of methods that are inherent to a type.
597 /// Methods in these implementations don't need to be exported.
598 query inherent_impls(key: DefId) -> &'tcx [DefId] {
599 desc { |tcx| "collecting inherent impls for `{}`", tcx.def_path_str(key) }
603 /// The result of unsafety-checking this `LocalDefId`.
604 query unsafety_check_result(key: LocalDefId) -> &'tcx mir::UnsafetyCheckResult {
605 desc { |tcx| "unsafety-checking `{}`", tcx.def_path_str(key.to_def_id()) }
606 cache_on_disk_if { true }
608 query unsafety_check_result_for_const_arg(key: (LocalDefId, DefId)) -> &'tcx mir::UnsafetyCheckResult {
610 |tcx| "unsafety-checking the const argument `{}`",
611 tcx.def_path_str(key.0.to_def_id())
615 /// Unsafety-check this `LocalDefId` with THIR unsafeck. This should be
616 /// used with `-Zthir-unsafeck`.
617 query thir_check_unsafety(key: LocalDefId) {
618 desc { |tcx| "unsafety-checking `{}`", tcx.def_path_str(key.to_def_id()) }
619 cache_on_disk_if { true }
621 query thir_check_unsafety_for_const_arg(key: (LocalDefId, DefId)) {
623 |tcx| "unsafety-checking the const argument `{}`",
624 tcx.def_path_str(key.0.to_def_id())
628 /// HACK: when evaluated, this reports a "unsafe derive on repr(packed)" error.
630 /// Unsafety checking is executed for each method separately, but we only want
631 /// to emit this error once per derive. As there are some impls with multiple
632 /// methods, we use a query for deduplication.
633 query unsafe_derive_on_repr_packed(key: LocalDefId) -> () {
634 desc { |tcx| "processing `{}`", tcx.def_path_str(key.to_def_id()) }
637 /// The signature of functions.
638 query fn_sig(key: DefId) -> ty::PolyFnSig<'tcx> {
639 desc { |tcx| "computing function signature of `{}`", tcx.def_path_str(key) }
642 query lint_mod(key: LocalDefId) -> () {
643 desc { |tcx| "linting {}", describe_as_module(key, tcx) }
646 /// Checks the attributes in the module.
647 query check_mod_attrs(key: LocalDefId) -> () {
648 desc { |tcx| "checking attributes in {}", describe_as_module(key, tcx) }
651 query check_mod_unstable_api_usage(key: LocalDefId) -> () {
652 desc { |tcx| "checking for unstable API usage in {}", describe_as_module(key, tcx) }
655 /// Checks the const bodies in the module for illegal operations (e.g. `if` or `loop`).
656 query check_mod_const_bodies(key: LocalDefId) -> () {
657 desc { |tcx| "checking consts in {}", describe_as_module(key, tcx) }
660 /// Checks the loops in the module.
661 query check_mod_loops(key: LocalDefId) -> () {
662 desc { |tcx| "checking loops in {}", describe_as_module(key, tcx) }
665 query check_mod_naked_functions(key: LocalDefId) -> () {
666 desc { |tcx| "checking naked functions in {}", describe_as_module(key, tcx) }
669 query check_mod_item_types(key: LocalDefId) -> () {
670 desc { |tcx| "checking item types in {}", describe_as_module(key, tcx) }
673 query check_mod_privacy(key: LocalDefId) -> () {
674 desc { |tcx| "checking privacy in {}", describe_as_module(key, tcx) }
677 query check_mod_intrinsics(key: LocalDefId) -> () {
678 desc { |tcx| "checking intrinsics in {}", describe_as_module(key, tcx) }
681 query check_mod_liveness(key: LocalDefId) -> () {
682 desc { |tcx| "checking liveness of variables in {}", describe_as_module(key, tcx) }
685 query check_mod_impl_wf(key: LocalDefId) -> () {
686 desc { |tcx| "checking that impls are well-formed in {}", describe_as_module(key, tcx) }
689 query collect_mod_item_types(key: LocalDefId) -> () {
690 desc { |tcx| "collecting item types in {}", describe_as_module(key, tcx) }
693 /// Caches `CoerceUnsized` kinds for impls on custom types.
694 query coerce_unsized_info(key: DefId)
695 -> ty::adjustment::CoerceUnsizedInfo {
696 desc { |tcx| "computing CoerceUnsized info for `{}`", tcx.def_path_str(key) }
699 query typeck_item_bodies(_: ()) -> () {
700 desc { "type-checking all item bodies" }
703 query typeck(key: LocalDefId) -> &'tcx ty::TypeckResults<'tcx> {
704 desc { |tcx| "type-checking `{}`", tcx.def_path_str(key.to_def_id()) }
705 cache_on_disk_if { true }
707 query typeck_const_arg(
708 key: (LocalDefId, DefId)
709 ) -> &'tcx ty::TypeckResults<'tcx> {
711 |tcx| "type-checking the const argument `{}`",
712 tcx.def_path_str(key.0.to_def_id()),
715 query diagnostic_only_typeck(key: LocalDefId) -> &'tcx ty::TypeckResults<'tcx> {
716 desc { |tcx| "type-checking `{}`", tcx.def_path_str(key.to_def_id()) }
717 cache_on_disk_if { true }
718 load_cached(tcx, id) {
719 let typeck_results: Option<ty::TypeckResults<'tcx>> = tcx
720 .on_disk_cache.as_ref()
721 .and_then(|c| c.try_load_query_result(*tcx, id));
723 typeck_results.map(|x| &*tcx.arena.alloc(x))
727 query used_trait_imports(key: LocalDefId) -> &'tcx FxHashSet<LocalDefId> {
728 desc { |tcx| "used_trait_imports `{}`", tcx.def_path_str(key.to_def_id()) }
729 cache_on_disk_if { true }
732 query has_typeck_results(def_id: DefId) -> bool {
733 desc { |tcx| "checking whether `{}` has a body", tcx.def_path_str(def_id) }
736 query coherent_trait(def_id: DefId) -> () {
737 desc { |tcx| "coherence checking all impls of trait `{}`", tcx.def_path_str(def_id) }
740 /// Borrow-checks the function body. If this is a closure, returns
741 /// additional requirements that the closure's creator must verify.
742 query mir_borrowck(key: LocalDefId) -> &'tcx mir::BorrowCheckResult<'tcx> {
743 desc { |tcx| "borrow-checking `{}`", tcx.def_path_str(key.to_def_id()) }
744 cache_on_disk_if(tcx, opt_result) {
745 tcx.is_closure(key.to_def_id())
746 || opt_result.map_or(false, |r| !r.concrete_opaque_types.is_empty())
749 query mir_borrowck_const_arg(key: (LocalDefId, DefId)) -> &'tcx mir::BorrowCheckResult<'tcx> {
751 |tcx| "borrow-checking the const argument`{}`",
752 tcx.def_path_str(key.0.to_def_id())
756 /// Gets a complete map from all types to their inherent impls.
757 /// Not meant to be used directly outside of coherence.
758 query crate_inherent_impls(k: ()) -> CrateInherentImpls {
759 storage(ArenaCacheSelector<'tcx>)
761 desc { "all inherent impls defined in crate" }
764 /// Checks all types in the crate for overlap in their inherent impls. Reports errors.
765 /// Not meant to be used directly outside of coherence.
766 query crate_inherent_impls_overlap_check(_: ())
769 desc { "check for overlap between inherent impls defined in this crate" }
772 /// Check whether the function has any recursion that could cause the inliner to trigger
773 /// a cycle. Returns the call stack causing the cycle. The call stack does not contain the
774 /// current function, just all intermediate functions.
775 query mir_callgraph_reachable(key: (ty::Instance<'tcx>, LocalDefId)) -> bool {
778 "computing if `{}` (transitively) calls `{}`",
780 tcx.def_path_str(key.1.to_def_id()),
784 /// Obtain all the calls into other local functions
785 query mir_inliner_callees(key: ty::InstanceDef<'tcx>) -> &'tcx [(DefId, SubstsRef<'tcx>)] {
788 "computing all local function calls in `{}`",
789 tcx.def_path_str(key.def_id()),
793 /// Evaluates a constant and returns the computed allocation.
795 /// **Do not use this** directly, use the `tcx.eval_static_initializer` wrapper.
796 query eval_to_allocation_raw(key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>)
797 -> EvalToAllocationRawResult<'tcx> {
799 "const-evaluating + checking `{}`",
800 key.value.display(tcx)
802 cache_on_disk_if { true }
805 /// Evaluates const items or anonymous constants
806 /// (such as enum variant explicit discriminants or array lengths)
807 /// into a representation suitable for the type system and const generics.
809 /// **Do not use this** directly, use one of the following wrappers: `tcx.const_eval_poly`,
810 /// `tcx.const_eval_resolve`, `tcx.const_eval_instance`, or `tcx.const_eval_global_id`.
811 query eval_to_const_value_raw(key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>)
812 -> EvalToConstValueResult<'tcx> {
814 "simplifying constant for the type system `{}`",
815 key.value.display(tcx)
817 cache_on_disk_if { true }
820 /// Convert an evaluated constant to a type level constant or
821 /// return `None` if that is not possible.
822 query const_to_valtree(
823 key: ty::ParamEnvAnd<'tcx, ConstAlloc<'tcx>>
824 ) -> Option<ty::ValTree<'tcx>> {
825 desc { "destructure constant" }
828 /// Destructure a constant ADT or array into its variant index and its
830 query destructure_const(
831 key: ty::ParamEnvAnd<'tcx, &'tcx ty::Const<'tcx>>
832 ) -> mir::DestructuredConst<'tcx> {
833 desc { "destructure constant" }
836 /// Dereference a constant reference or raw pointer and turn the result into a constant
839 key: ty::ParamEnvAnd<'tcx, &'tcx ty::Const<'tcx>>
840 ) -> &'tcx ty::Const<'tcx> {
841 desc { "deref constant" }
844 query const_caller_location(key: (rustc_span::Symbol, u32, u32)) -> ConstValue<'tcx> {
845 desc { "get a &core::panic::Location referring to a span" }
849 key: LitToConstInput<'tcx>
850 ) -> Result<&'tcx ty::Const<'tcx>, LitToConstError> {
851 desc { "converting literal to const" }
854 query check_match(key: DefId) {
855 desc { |tcx| "match-checking `{}`", tcx.def_path_str(key) }
856 cache_on_disk_if { key.is_local() }
859 /// Performs part of the privacy check and computes "access levels".
860 query privacy_access_levels(_: ()) -> &'tcx AccessLevels {
862 desc { "privacy access levels" }
864 query check_private_in_public(_: ()) -> () {
866 desc { "checking for private elements in public interfaces" }
869 query reachable_set(_: ()) -> FxHashSet<LocalDefId> {
870 storage(ArenaCacheSelector<'tcx>)
871 desc { "reachability" }
874 /// Per-body `region::ScopeTree`. The `DefId` should be the owner `DefId` for the body;
875 /// in the case of closures, this will be redirected to the enclosing function.
876 query region_scope_tree(def_id: DefId) -> &'tcx region::ScopeTree {
877 desc { |tcx| "computing drop scopes for `{}`", tcx.def_path_str(def_id) }
880 query mir_shims(key: ty::InstanceDef<'tcx>) -> mir::Body<'tcx> {
881 storage(ArenaCacheSelector<'tcx>)
882 desc { |tcx| "generating MIR shim for `{}`", tcx.def_path_str(key.def_id()) }
885 /// The `symbol_name` query provides the symbol name for calling a
886 /// given instance from the local crate. In particular, it will also
887 /// look up the correct symbol name of instances from upstream crates.
888 query symbol_name(key: ty::Instance<'tcx>) -> ty::SymbolName<'tcx> {
889 desc { "computing the symbol for `{}`", key }
890 cache_on_disk_if { true }
893 query opt_def_kind(def_id: DefId) -> Option<DefKind> {
894 desc { |tcx| "looking up definition kind of `{}`", tcx.def_path_str(def_id) }
897 query def_span(def_id: DefId) -> Span {
898 desc { |tcx| "looking up span for `{}`", tcx.def_path_str(def_id) }
899 // FIXME(mw): DefSpans are not really inputs since they are derived from
900 // HIR. But at the moment HIR hashing still contains some hacks that allow
901 // to make type debuginfo to be source location independent. Declaring
902 // DefSpan an input makes sure that changes to these are always detected
903 // regardless of HIR hashing.
907 query def_ident_span(def_id: DefId) -> Option<Span> {
908 desc { |tcx| "looking up span for `{}`'s identifier", tcx.def_path_str(def_id) }
911 query lookup_stability(def_id: DefId) -> Option<&'tcx attr::Stability> {
912 desc { |tcx| "looking up stability of `{}`", tcx.def_path_str(def_id) }
915 query lookup_const_stability(def_id: DefId) -> Option<&'tcx attr::ConstStability> {
916 desc { |tcx| "looking up const stability of `{}`", tcx.def_path_str(def_id) }
919 query lookup_deprecation_entry(def_id: DefId) -> Option<DeprecationEntry> {
920 desc { |tcx| "checking whether `{}` is deprecated", tcx.def_path_str(def_id) }
923 query item_attrs(def_id: DefId) -> &'tcx [ast::Attribute] {
924 desc { |tcx| "collecting attributes of `{}`", tcx.def_path_str(def_id) }
927 query codegen_fn_attrs(def_id: DefId) -> CodegenFnAttrs {
928 desc { |tcx| "computing codegen attributes of `{}`", tcx.def_path_str(def_id) }
929 storage(ArenaCacheSelector<'tcx>)
930 cache_on_disk_if { true }
933 query fn_arg_names(def_id: DefId) -> &'tcx [rustc_span::symbol::Ident] {
934 desc { |tcx| "looking up function parameter names for `{}`", tcx.def_path_str(def_id) }
936 /// Gets the rendered value of the specified constant or associated constant.
938 query rendered_const(def_id: DefId) -> String {
939 desc { |tcx| "rendering constant intializer of `{}`", tcx.def_path_str(def_id) }
941 query impl_parent(def_id: DefId) -> Option<DefId> {
942 desc { |tcx| "computing specialization parent impl of `{}`", tcx.def_path_str(def_id) }
945 /// Given an `associated_item`, find the trait it belongs to.
946 /// Return `None` if the `DefId` is not an associated item.
947 query trait_of_item(associated_item: DefId) -> Option<DefId> {
948 desc { |tcx| "finding trait defining `{}`", tcx.def_path_str(associated_item) }
951 query is_ctfe_mir_available(key: DefId) -> bool {
952 desc { |tcx| "checking if item has ctfe mir available: `{}`", tcx.def_path_str(key) }
954 query is_mir_available(key: DefId) -> bool {
955 desc { |tcx| "checking if item has mir available: `{}`", tcx.def_path_str(key) }
958 query vtable_entries(key: ty::PolyTraitRef<'tcx>)
959 -> &'tcx [ty::VtblEntry<'tcx>] {
960 desc { |tcx| "finding all vtable entries for trait {}", tcx.def_path_str(key.def_id()) }
963 query codegen_fulfill_obligation(
964 key: (ty::ParamEnv<'tcx>, ty::PolyTraitRef<'tcx>)
965 ) -> Result<ImplSource<'tcx, ()>, ErrorReported> {
966 cache_on_disk_if { true }
968 "checking if `{}` fulfills its obligations",
969 tcx.def_path_str(key.1.def_id())
973 /// Return all `impl` blocks in the current crate.
975 /// To allow caching this between crates, you must pass in [`LOCAL_CRATE`] as the crate number.
976 /// Passing in any other crate will cause an ICE.
978 /// [`LOCAL_CRATE`]: rustc_hir::def_id::LOCAL_CRATE
979 query all_local_trait_impls(_: ()) -> &'tcx BTreeMap<DefId, Vec<LocalDefId>> {
980 desc { "local trait impls" }
983 /// Given a trait `trait_id`, return all known `impl` blocks.
984 query trait_impls_of(trait_id: DefId) -> ty::trait_def::TraitImpls {
985 storage(ArenaCacheSelector<'tcx>)
986 desc { |tcx| "trait impls of `{}`", tcx.def_path_str(trait_id) }
989 query specialization_graph_of(trait_id: DefId) -> specialization_graph::Graph {
990 storage(ArenaCacheSelector<'tcx>)
991 desc { |tcx| "building specialization graph of trait `{}`", tcx.def_path_str(trait_id) }
992 cache_on_disk_if { true }
994 query object_safety_violations(trait_id: DefId) -> &'tcx [traits::ObjectSafetyViolation] {
995 desc { |tcx| "determine object safety of trait `{}`", tcx.def_path_str(trait_id) }
998 /// Gets the ParameterEnvironment for a given item; this environment
999 /// will be in "user-facing" mode, meaning that it is suitable for
1000 /// type-checking etc, and it does not normalize specializable
1001 /// associated types. This is almost always what you want,
1002 /// unless you are doing MIR optimizations, in which case you
1003 /// might want to use `reveal_all()` method to change modes.
1004 query param_env(def_id: DefId) -> ty::ParamEnv<'tcx> {
1005 desc { |tcx| "computing normalized predicates of `{}`", tcx.def_path_str(def_id) }
1008 /// Like `param_env`, but returns the `ParamEnv` in `Reveal::All` mode.
1009 /// Prefer this over `tcx.param_env(def_id).with_reveal_all_normalized(tcx)`,
1010 /// as this method is more efficient.
1011 query param_env_reveal_all_normalized(def_id: DefId) -> ty::ParamEnv<'tcx> {
1012 desc { |tcx| "computing revealed normalized predicates of `{}`", tcx.def_path_str(def_id) }
1015 /// Trait selection queries. These are best used by invoking `ty.is_copy_modulo_regions()`,
1016 /// `ty.is_copy()`, etc, since that will prune the environment where possible.
1017 query is_copy_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1018 desc { "computing whether `{}` is `Copy`", env.value }
1020 /// Query backing `TyS::is_sized`.
1021 query is_sized_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1022 desc { "computing whether `{}` is `Sized`", env.value }
1024 /// Query backing `TyS::is_freeze`.
1025 query is_freeze_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1026 desc { "computing whether `{}` is freeze", env.value }
1028 /// Query backing `TyS::is_unpin`.
1029 query is_unpin_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1030 desc { "computing whether `{}` is `Unpin`", env.value }
1032 /// Query backing `TyS::needs_drop`.
1033 query needs_drop_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1034 desc { "computing whether `{}` needs drop", env.value }
1036 /// Query backing `TyS::has_significant_drop_raw`.
1037 query has_significant_drop_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1038 desc { "computing whether `{}` has a significant drop", env.value }
1041 /// Query backing `TyS::is_structural_eq_shallow`.
1043 /// This is only correct for ADTs. Call `is_structural_eq_shallow` to handle all types
1045 query has_structural_eq_impls(ty: Ty<'tcx>) -> bool {
1047 "computing whether `{:?}` implements `PartialStructuralEq` and `StructuralEq`",
1052 /// A list of types where the ADT requires drop if and only if any of
1053 /// those types require drop. If the ADT is known to always need drop
1054 /// then `Err(AlwaysRequiresDrop)` is returned.
1055 query adt_drop_tys(def_id: DefId) -> Result<&'tcx ty::List<Ty<'tcx>>, AlwaysRequiresDrop> {
1056 desc { |tcx| "computing when `{}` needs drop", tcx.def_path_str(def_id) }
1057 cache_on_disk_if { true }
1060 /// A list of types where the ADT requires drop if and only if any of those types
1061 /// has significant drop. A type marked with the attribute `rustc_insignificant_dtor`
1062 /// is considered to not be significant. A drop is significant if it is implemented
1063 /// by the user or does anything that will have any observable behavior (other than
1064 /// freeing up memory). If the ADT is known to have a significant destructor then
1065 /// `Err(AlwaysRequiresDrop)` is returned.
1066 query adt_significant_drop_tys(def_id: DefId) -> Result<&'tcx ty::List<Ty<'tcx>>, AlwaysRequiresDrop> {
1067 desc { |tcx| "computing when `{}` has a significant destructor", tcx.def_path_str(def_id) }
1068 cache_on_disk_if { false }
1072 env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>
1073 ) -> Result<&'tcx rustc_target::abi::Layout, ty::layout::LayoutError<'tcx>> {
1074 desc { "computing layout of `{}`", env.value }
1077 query dylib_dependency_formats(_: CrateNum)
1078 -> &'tcx [(CrateNum, LinkagePreference)] {
1079 desc { "dylib dependency formats of crate" }
1082 query dependency_formats(_: ()) -> Lrc<crate::middle::dependency_format::Dependencies> {
1083 desc { "get the linkage format of all dependencies" }
1086 query is_compiler_builtins(_: CrateNum) -> bool {
1088 desc { "checking if the crate is_compiler_builtins" }
1090 query has_global_allocator(_: CrateNum) -> bool {
1091 // This query depends on untracked global state in CStore
1094 desc { "checking if the crate has_global_allocator" }
1096 query has_panic_handler(_: CrateNum) -> bool {
1098 desc { "checking if the crate has_panic_handler" }
1100 query is_profiler_runtime(_: CrateNum) -> bool {
1102 desc { "query a crate is `#![profiler_runtime]`" }
1104 query panic_strategy(_: CrateNum) -> PanicStrategy {
1106 desc { "query a crate's configured panic strategy" }
1108 query is_no_builtins(_: CrateNum) -> bool {
1110 desc { "test whether a crate has `#![no_builtins]`" }
1112 query symbol_mangling_version(_: CrateNum) -> SymbolManglingVersion {
1114 desc { "query a crate's symbol mangling version" }
1117 query extern_crate(def_id: DefId) -> Option<&'tcx ExternCrate> {
1119 desc { "getting crate's ExternCrateData" }
1122 query specializes(_: (DefId, DefId)) -> bool {
1123 desc { "computing whether impls specialize one another" }
1125 query in_scope_traits_map(_: LocalDefId)
1126 -> Option<&'tcx FxHashMap<ItemLocalId, Box<[TraitCandidate]>>> {
1127 desc { "traits in scope at a block" }
1130 query module_exports(def_id: LocalDefId) -> Option<&'tcx [Export<LocalDefId>]> {
1131 desc { |tcx| "looking up items exported by `{}`", tcx.def_path_str(def_id.to_def_id()) }
1135 query impl_defaultness(def_id: DefId) -> hir::Defaultness {
1136 desc { |tcx| "looking up whether `{}` is a default impl", tcx.def_path_str(def_id) }
1139 query check_item_well_formed(key: LocalDefId) -> () {
1140 desc { |tcx| "checking that `{}` is well-formed", tcx.def_path_str(key.to_def_id()) }
1142 query check_trait_item_well_formed(key: LocalDefId) -> () {
1143 desc { |tcx| "checking that `{}` is well-formed", tcx.def_path_str(key.to_def_id()) }
1145 query check_impl_item_well_formed(key: LocalDefId) -> () {
1146 desc { |tcx| "checking that `{}` is well-formed", tcx.def_path_str(key.to_def_id()) }
1149 // The `DefId`s of all non-generic functions and statics in the given crate
1150 // that can be reached from outside the crate.
1152 // We expect this items to be available for being linked to.
1154 // This query can also be called for `LOCAL_CRATE`. In this case it will
1155 // compute which items will be reachable to other crates, taking into account
1156 // the kind of crate that is currently compiled. Crates with only a
1157 // C interface have fewer reachable things.
1159 // Does not include external symbols that don't have a corresponding DefId,
1160 // like the compiler-generated `main` function and so on.
1161 query reachable_non_generics(_: CrateNum)
1162 -> DefIdMap<SymbolExportLevel> {
1163 storage(ArenaCacheSelector<'tcx>)
1164 desc { "looking up the exported symbols of a crate" }
1166 query is_reachable_non_generic(def_id: DefId) -> bool {
1167 desc { |tcx| "checking whether `{}` is an exported symbol", tcx.def_path_str(def_id) }
1169 query is_unreachable_local_definition(def_id: LocalDefId) -> bool {
1171 "checking whether `{}` is reachable from outside the crate",
1172 tcx.def_path_str(def_id.to_def_id()),
1176 /// The entire set of monomorphizations the local crate can safely link
1177 /// to because they are exported from upstream crates. Do not depend on
1178 /// this directly, as its value changes anytime a monomorphization gets
1179 /// added or removed in any upstream crate. Instead use the narrower
1180 /// `upstream_monomorphizations_for`, `upstream_drop_glue_for`, or, even
1181 /// better, `Instance::upstream_monomorphization()`.
1182 query upstream_monomorphizations(_: ()) -> DefIdMap<FxHashMap<SubstsRef<'tcx>, CrateNum>> {
1183 storage(ArenaCacheSelector<'tcx>)
1184 desc { "collecting available upstream monomorphizations" }
1187 /// Returns the set of upstream monomorphizations available for the
1188 /// generic function identified by the given `def_id`. The query makes
1189 /// sure to make a stable selection if the same monomorphization is
1190 /// available in multiple upstream crates.
1192 /// You likely want to call `Instance::upstream_monomorphization()`
1193 /// instead of invoking this query directly.
1194 query upstream_monomorphizations_for(def_id: DefId)
1195 -> Option<&'tcx FxHashMap<SubstsRef<'tcx>, CrateNum>> {
1197 "collecting available upstream monomorphizations for `{}`",
1198 tcx.def_path_str(def_id),
1202 /// Returns the upstream crate that exports drop-glue for the given
1203 /// type (`substs` is expected to be a single-item list containing the
1204 /// type one wants drop-glue for).
1206 /// This is a subset of `upstream_monomorphizations_for` in order to
1207 /// increase dep-tracking granularity. Otherwise adding or removing any
1208 /// type with drop-glue in any upstream crate would invalidate all
1209 /// functions calling drop-glue of an upstream type.
1211 /// You likely want to call `Instance::upstream_monomorphization()`
1212 /// instead of invoking this query directly.
1214 /// NOTE: This query could easily be extended to also support other
1215 /// common functions that have are large set of monomorphizations
1216 /// (like `Clone::clone` for example).
1217 query upstream_drop_glue_for(substs: SubstsRef<'tcx>) -> Option<CrateNum> {
1218 desc { "available upstream drop-glue for `{:?}`", substs }
1221 query foreign_modules(_: CrateNum) -> Lrc<FxHashMap<DefId, ForeignModule>> {
1222 desc { "looking up the foreign modules of a linked crate" }
1225 /// Identifies the entry-point (e.g., the `main` function) for a given
1226 /// crate, returning `None` if there is no entry point (such as for library crates).
1227 query entry_fn(_: ()) -> Option<(DefId, EntryFnType)> {
1228 desc { "looking up the entry function of a crate" }
1230 query plugin_registrar_fn(_: ()) -> Option<LocalDefId> {
1231 desc { "looking up the plugin registrar for a crate" }
1233 query proc_macro_decls_static(_: ()) -> Option<LocalDefId> {
1234 desc { "looking up the derive registrar for a crate" }
1236 query crate_disambiguator(_: CrateNum) -> CrateDisambiguator {
1238 desc { "looking up the disambiguator a crate" }
1240 // The macro which defines `rustc_metadata::provide_extern` depends on this query's name.
1241 // Changing the name should cause a compiler error, but in case that changes, be aware.
1242 query crate_hash(_: CrateNum) -> Svh {
1244 desc { "looking up the hash a crate" }
1246 query crate_host_hash(_: CrateNum) -> Option<Svh> {
1248 desc { "looking up the hash of a host version of a crate" }
1250 query extra_filename(_: CrateNum) -> String {
1252 desc { "looking up the extra filename for a crate" }
1254 query crate_extern_paths(_: CrateNum) -> Vec<PathBuf> {
1256 desc { "looking up the paths for extern crates" }
1259 /// Given a crate and a trait, look up all impls of that trait in the crate.
1260 /// Return `(impl_id, self_ty)`.
1261 query implementations_of_trait(_: (CrateNum, DefId))
1262 -> &'tcx [(DefId, Option<ty::fast_reject::SimplifiedType>)] {
1263 desc { "looking up implementations of a trait in a crate" }
1266 /// Given a crate, look up all trait impls in that crate.
1267 /// Return `(impl_id, self_ty)`.
1268 query all_trait_implementations(_: CrateNum)
1269 -> &'tcx [(DefId, Option<ty::fast_reject::SimplifiedType>)] {
1270 desc { "looking up all (?) trait implementations" }
1273 query is_dllimport_foreign_item(def_id: DefId) -> bool {
1274 desc { |tcx| "is_dllimport_foreign_item({})", tcx.def_path_str(def_id) }
1276 query is_statically_included_foreign_item(def_id: DefId) -> bool {
1277 desc { |tcx| "is_statically_included_foreign_item({})", tcx.def_path_str(def_id) }
1279 query native_library_kind(def_id: DefId)
1280 -> Option<NativeLibKind> {
1281 desc { |tcx| "native_library_kind({})", tcx.def_path_str(def_id) }
1284 /// Does lifetime resolution, but does not descend into trait items. This
1285 /// should only be used for resolving lifetimes of on trait definitions,
1286 /// and is used to avoid cycles. Importantly, `resolve_lifetimes` still visits
1287 /// the same lifetimes and is responsible for diagnostics.
1288 /// See `rustc_resolve::late::lifetimes for details.
1289 query resolve_lifetimes_trait_definition(_: LocalDefId) -> ResolveLifetimes {
1290 storage(ArenaCacheSelector<'tcx>)
1291 desc { "resolving lifetimes for a trait definition" }
1293 /// Does lifetime resolution on items. Importantly, we can't resolve
1294 /// lifetimes directly on things like trait methods, because of trait params.
1295 /// See `rustc_resolve::late::lifetimes for details.
1296 query resolve_lifetimes(_: LocalDefId) -> ResolveLifetimes {
1297 storage(ArenaCacheSelector<'tcx>)
1298 desc { "resolving lifetimes" }
1300 query named_region_map(_: LocalDefId) ->
1301 Option<&'tcx FxHashMap<ItemLocalId, Region>> {
1302 desc { "looking up a named region" }
1304 query is_late_bound_map(_: LocalDefId) ->
1305 Option<(LocalDefId, &'tcx FxHashSet<ItemLocalId>)> {
1306 desc { "testing if a region is late bound" }
1308 /// For a given item (like a struct), gets the default lifetimes to be used
1309 /// for each parameter if a trait object were to be passed for that parameter.
1310 /// For example, for `struct Foo<'a, T, U>`, this would be `['static, 'static]`.
1311 /// For `struct Foo<'a, T: 'a, U>`, this would instead be `['a, 'static]`.
1312 query object_lifetime_defaults_map(_: LocalDefId)
1313 -> Option<Vec<ObjectLifetimeDefault>> {
1314 desc { "looking up lifetime defaults for a region on an item" }
1316 query late_bound_vars_map(_: LocalDefId)
1317 -> Option<&'tcx FxHashMap<ItemLocalId, Vec<ty::BoundVariableKind>>> {
1318 desc { "looking up late bound vars" }
1321 query lifetime_scope_map(_: LocalDefId) -> Option<FxHashMap<ItemLocalId, LifetimeScopeForPath>> {
1322 desc { "finds the lifetime scope for an HirId of a PathSegment" }
1325 query visibility(def_id: DefId) -> ty::Visibility {
1327 desc { |tcx| "computing visibility of `{}`", tcx.def_path_str(def_id) }
1330 /// Computes the set of modules from which this type is visibly uninhabited.
1331 /// To check whether a type is uninhabited at all (not just from a given module), you could
1332 /// check whether the forest is empty.
1333 query type_uninhabited_from(
1334 key: ty::ParamEnvAnd<'tcx, Ty<'tcx>>
1335 ) -> ty::inhabitedness::DefIdForest {
1336 desc { "computing the inhabitedness of `{:?}`", key }
1339 query dep_kind(_: CrateNum) -> CrateDepKind {
1341 desc { "fetching what a dependency looks like" }
1343 query crate_name(_: CrateNum) -> Symbol {
1345 desc { "fetching what a crate is named" }
1347 query item_children(def_id: DefId) -> &'tcx [Export<hir::HirId>] {
1348 desc { |tcx| "collecting child items of `{}`", tcx.def_path_str(def_id) }
1350 query extern_mod_stmt_cnum(def_id: LocalDefId) -> Option<CrateNum> {
1351 // This depends on untracked global state (`tcx.extern_crate_map`)
1353 desc { |tcx| "computing crate imported by `{}`", tcx.def_path_str(def_id.to_def_id()) }
1356 query get_lib_features(_: ()) -> LibFeatures {
1357 storage(ArenaCacheSelector<'tcx>)
1359 desc { "calculating the lib features map" }
1361 query defined_lib_features(_: CrateNum)
1362 -> &'tcx [(Symbol, Option<Symbol>)] {
1363 desc { "calculating the lib features defined in a crate" }
1365 /// Returns the lang items defined in another crate by loading it from metadata.
1366 query get_lang_items(_: ()) -> LanguageItems {
1367 storage(ArenaCacheSelector<'tcx>)
1369 desc { "calculating the lang items map" }
1372 /// Returns all diagnostic items defined in all crates.
1373 query all_diagnostic_items(_: ()) -> FxHashMap<Symbol, DefId> {
1374 storage(ArenaCacheSelector<'tcx>)
1376 desc { "calculating the diagnostic items map" }
1379 /// Returns the lang items defined in another crate by loading it from metadata.
1380 query defined_lang_items(_: CrateNum) -> &'tcx [(DefId, usize)] {
1381 desc { "calculating the lang items defined in a crate" }
1384 /// Returns the diagnostic items defined in a crate.
1385 query diagnostic_items(_: CrateNum) -> FxHashMap<Symbol, DefId> {
1386 storage(ArenaCacheSelector<'tcx>)
1387 desc { "calculating the diagnostic items map in a crate" }
1390 query missing_lang_items(_: CrateNum) -> &'tcx [LangItem] {
1391 desc { "calculating the missing lang items in a crate" }
1393 query visible_parent_map(_: ()) -> DefIdMap<DefId> {
1394 storage(ArenaCacheSelector<'tcx>)
1395 desc { "calculating the visible parent map" }
1397 query trimmed_def_paths(_: ()) -> FxHashMap<DefId, Symbol> {
1398 storage(ArenaCacheSelector<'tcx>)
1399 desc { "calculating trimmed def paths" }
1401 query missing_extern_crate_item(_: CrateNum) -> bool {
1403 desc { "seeing if we're missing an `extern crate` item for this crate" }
1405 query used_crate_source(_: CrateNum) -> Lrc<CrateSource> {
1407 desc { "looking at the source for a crate" }
1409 query postorder_cnums(_: ()) -> &'tcx [CrateNum] {
1411 desc { "generating a postorder list of CrateNums" }
1413 /// Returns whether or not the crate with CrateNum 'cnum'
1414 /// is marked as a private dependency
1415 query is_private_dep(c: CrateNum) -> bool {
1417 desc { "check whether crate {} is a private dependency", c }
1420 query upvars_mentioned(def_id: DefId) -> Option<&'tcx FxIndexMap<hir::HirId, hir::Upvar>> {
1421 desc { |tcx| "collecting upvars mentioned in `{}`", tcx.def_path_str(def_id) }
1424 query maybe_unused_trait_import(def_id: LocalDefId) -> bool {
1426 desc { |tcx| "maybe_unused_trait_import for `{}`", tcx.def_path_str(def_id.to_def_id()) }
1428 query maybe_unused_extern_crates(_: ()) -> &'tcx [(LocalDefId, Span)] {
1430 desc { "looking up all possibly unused extern crates" }
1432 query names_imported_by_glob_use(def_id: LocalDefId)
1433 -> &'tcx FxHashSet<Symbol> {
1435 desc { |tcx| "names_imported_by_glob_use for `{}`", tcx.def_path_str(def_id.to_def_id()) }
1438 query stability_index(_: ()) -> stability::Index<'tcx> {
1439 storage(ArenaCacheSelector<'tcx>)
1441 desc { "calculating the stability index for the local crate" }
1443 query all_crate_nums(_: ()) -> &'tcx [CrateNum] {
1445 desc { "fetching all foreign CrateNum instances" }
1448 /// A vector of every trait accessible in the whole crate
1449 /// (i.e., including those from subcrates). This is used only for
1450 /// error reporting.
1451 query all_traits(_: ()) -> &'tcx [DefId] {
1452 desc { "fetching all foreign and local traits" }
1455 /// The list of symbols exported from the given crate.
1457 /// - All names contained in `exported_symbols(cnum)` are guaranteed to
1458 /// correspond to a publicly visible symbol in `cnum` machine code.
1459 /// - The `exported_symbols` sets of different crates do not intersect.
1460 query exported_symbols(_: CrateNum)
1461 -> &'tcx [(ExportedSymbol<'tcx>, SymbolExportLevel)] {
1462 desc { "exported_symbols" }
1465 query collect_and_partition_mono_items(_: ()) -> (&'tcx DefIdSet, &'tcx [CodegenUnit<'tcx>]) {
1467 desc { "collect_and_partition_mono_items" }
1469 query is_codegened_item(def_id: DefId) -> bool {
1470 desc { |tcx| "determining whether `{}` needs codegen", tcx.def_path_str(def_id) }
1473 /// All items participating in code generation together with items inlined into them.
1474 query codegened_and_inlined_items(_: ()) -> &'tcx DefIdSet {
1476 desc { "codegened_and_inlined_items" }
1479 query codegen_unit(_: Symbol) -> &'tcx CodegenUnit<'tcx> {
1480 desc { "codegen_unit" }
1482 query unused_generic_params(key: DefId) -> FiniteBitSet<u32> {
1483 cache_on_disk_if { key.is_local() }
1485 |tcx| "determining which generic parameters are unused by `{}`",
1486 tcx.def_path_str(key)
1489 query backend_optimization_level(_: ()) -> OptLevel {
1490 desc { "optimization level used by backend" }
1493 query output_filenames(_: ()) -> Arc<OutputFilenames> {
1495 desc { "output_filenames" }
1498 /// Do not call this query directly: invoke `normalize` instead.
1499 query normalize_projection_ty(
1500 goal: CanonicalProjectionGoal<'tcx>
1502 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, NormalizationResult<'tcx>>>,
1505 desc { "normalizing `{:?}`", goal }
1508 /// Do not call this query directly: invoke `normalize_erasing_regions` instead.
1509 query normalize_generic_arg_after_erasing_regions(
1510 goal: ParamEnvAnd<'tcx, GenericArg<'tcx>>
1511 ) -> GenericArg<'tcx> {
1512 desc { "normalizing `{}`", goal.value }
1515 /// Do not call this query directly: invoke `normalize_erasing_regions` instead.
1516 query normalize_mir_const_after_erasing_regions(
1517 goal: ParamEnvAnd<'tcx, mir::ConstantKind<'tcx>>
1518 ) -> mir::ConstantKind<'tcx> {
1519 desc { "normalizing `{}`", goal.value }
1522 query implied_outlives_bounds(
1523 goal: CanonicalTyGoal<'tcx>
1525 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, Vec<OutlivesBound<'tcx>>>>,
1528 desc { "computing implied outlives bounds for `{:?}`", goal }
1531 /// Do not call this query directly: invoke `infcx.at().dropck_outlives()` instead.
1532 query dropck_outlives(
1533 goal: CanonicalTyGoal<'tcx>
1535 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, DropckOutlivesResult<'tcx>>>,
1538 desc { "computing dropck types for `{:?}`", goal }
1541 /// Do not call this query directly: invoke `infcx.predicate_may_hold()` or
1542 /// `infcx.predicate_must_hold()` instead.
1543 query evaluate_obligation(
1544 goal: CanonicalPredicateGoal<'tcx>
1545 ) -> Result<traits::EvaluationResult, traits::OverflowError> {
1546 desc { "evaluating trait selection obligation `{}`", goal.value.value }
1549 query evaluate_goal(
1550 goal: traits::CanonicalChalkEnvironmentAndGoal<'tcx>
1552 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1555 desc { "evaluating trait selection obligation `{}`", goal.value }
1558 query type_implements_trait(
1559 key: (DefId, Ty<'tcx>, SubstsRef<'tcx>, ty::ParamEnv<'tcx>, )
1561 desc { "evaluating `type_implements_trait` `{:?}`", key }
1564 /// Do not call this query directly: part of the `Eq` type-op
1565 query type_op_ascribe_user_type(
1566 goal: CanonicalTypeOpAscribeUserTypeGoal<'tcx>
1568 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1571 desc { "evaluating `type_op_ascribe_user_type` `{:?}`", goal }
1574 /// Do not call this query directly: part of the `Eq` type-op
1576 goal: CanonicalTypeOpEqGoal<'tcx>
1578 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1581 desc { "evaluating `type_op_eq` `{:?}`", goal }
1584 /// Do not call this query directly: part of the `Subtype` type-op
1585 query type_op_subtype(
1586 goal: CanonicalTypeOpSubtypeGoal<'tcx>
1588 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1591 desc { "evaluating `type_op_subtype` `{:?}`", goal }
1594 /// Do not call this query directly: part of the `ProvePredicate` type-op
1595 query type_op_prove_predicate(
1596 goal: CanonicalTypeOpProvePredicateGoal<'tcx>
1598 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1601 desc { "evaluating `type_op_prove_predicate` `{:?}`", goal }
1604 /// Do not call this query directly: part of the `Normalize` type-op
1605 query type_op_normalize_ty(
1606 goal: CanonicalTypeOpNormalizeGoal<'tcx, Ty<'tcx>>
1608 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, Ty<'tcx>>>,
1611 desc { "normalizing `{:?}`", goal }
1614 /// Do not call this query directly: part of the `Normalize` type-op
1615 query type_op_normalize_predicate(
1616 goal: CanonicalTypeOpNormalizeGoal<'tcx, ty::Predicate<'tcx>>
1618 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ty::Predicate<'tcx>>>,
1621 desc { "normalizing `{:?}`", goal }
1624 /// Do not call this query directly: part of the `Normalize` type-op
1625 query type_op_normalize_poly_fn_sig(
1626 goal: CanonicalTypeOpNormalizeGoal<'tcx, ty::PolyFnSig<'tcx>>
1628 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ty::PolyFnSig<'tcx>>>,
1631 desc { "normalizing `{:?}`", goal }
1634 /// Do not call this query directly: part of the `Normalize` type-op
1635 query type_op_normalize_fn_sig(
1636 goal: CanonicalTypeOpNormalizeGoal<'tcx, ty::FnSig<'tcx>>
1638 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ty::FnSig<'tcx>>>,
1641 desc { "normalizing `{:?}`", goal }
1644 query subst_and_check_impossible_predicates(key: (DefId, SubstsRef<'tcx>)) -> bool {
1646 "impossible substituted predicates:`{}`",
1647 tcx.def_path_str(key.0)
1651 query method_autoderef_steps(
1652 goal: CanonicalTyGoal<'tcx>
1653 ) -> MethodAutoderefStepsResult<'tcx> {
1654 desc { "computing autoderef types for `{:?}`", goal }
1657 query supported_target_features(_: CrateNum) -> FxHashMap<String, Option<Symbol>> {
1658 storage(ArenaCacheSelector<'tcx>)
1660 desc { "looking up supported target features" }
1663 /// Get an estimate of the size of an InstanceDef based on its MIR for CGU partitioning.
1664 query instance_def_size_estimate(def: ty::InstanceDef<'tcx>)
1666 desc { |tcx| "estimating size for `{}`", tcx.def_path_str(def.def_id()) }
1669 query features_query(_: ()) -> &'tcx rustc_feature::Features {
1671 desc { "looking up enabled feature gates" }
1674 /// Attempt to resolve the given `DefId` to an `Instance`, for the
1675 /// given generics args (`SubstsRef`), returning one of:
1676 /// * `Ok(Some(instance))` on success
1677 /// * `Ok(None)` when the `SubstsRef` are still too generic,
1678 /// and therefore don't allow finding the final `Instance`
1679 /// * `Err(ErrorReported)` when the `Instance` resolution process
1680 /// couldn't complete due to errors elsewhere - this is distinct
1681 /// from `Ok(None)` to avoid misleading diagnostics when an error
1682 /// has already been/will be emitted, for the original cause
1683 query resolve_instance(
1684 key: ty::ParamEnvAnd<'tcx, (DefId, SubstsRef<'tcx>)>
1685 ) -> Result<Option<ty::Instance<'tcx>>, ErrorReported> {
1686 desc { "resolving instance `{}`", ty::Instance::new(key.value.0, key.value.1) }
1689 query resolve_instance_of_const_arg(
1690 key: ty::ParamEnvAnd<'tcx, (LocalDefId, DefId, SubstsRef<'tcx>)>
1691 ) -> Result<Option<ty::Instance<'tcx>>, ErrorReported> {
1693 "resolving instance of the const argument `{}`",
1694 ty::Instance::new(key.value.0.to_def_id(), key.value.2),
1698 query normalize_opaque_types(key: &'tcx ty::List<ty::Predicate<'tcx>>) -> &'tcx ty::List<ty::Predicate<'tcx>> {
1699 desc { "normalizing opaque types in {:?}", key }
1702 /// Checks whether a type is definitely uninhabited. This is
1703 /// conservative: for some types that are uninhabited we return `false`,
1704 /// but we only return `true` for types that are definitely uninhabited.
1705 /// `ty.conservative_is_privately_uninhabited` implies that any value of type `ty`
1706 /// will be `Abi::Uninhabited`. (Note that uninhabited types may have nonzero
1707 /// size, to account for partial initialisation. See #49298 for details.)
1708 query conservative_is_privately_uninhabited(key: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1709 desc { "conservatively checking if {:?} is privately uninhabited", key }