1 use crate::dep_graph::SerializedDepNodeIndex;
2 use crate::mir::interpret::{GlobalId, LitToConstInput};
4 use crate::traits::query::{
5 CanonicalPredicateGoal, CanonicalProjectionGoal, CanonicalTyGoal,
6 CanonicalTypeOpAscribeUserTypeGoal, CanonicalTypeOpEqGoal, CanonicalTypeOpNormalizeGoal,
7 CanonicalTypeOpProvePredicateGoal, CanonicalTypeOpSubtypeGoal,
9 use crate::ty::query::queries;
10 use crate::ty::subst::{GenericArg, SubstsRef};
11 use crate::ty::{self, ParamEnvAnd, Ty, TyCtxt};
12 use rustc_hir::def_id::{CrateNum, DefId, LocalDefId};
13 use rustc_query_system::query::QueryDescription;
15 use rustc_span::symbol::Symbol;
18 fn describe_as_module(def_id: LocalDefId, tcx: TyCtxt<'_>) -> String {
19 if def_id.is_top_level_module() {
20 "top-level module".to_string()
22 format!("module `{}`", tcx.def_path_str(def_id.to_def_id()))
26 // Each of these queries corresponds to a function pointer field in the
27 // `Providers` struct for requesting a value of that type, and a method
28 // on `tcx: TyCtxt` (and `tcx.at(span)`) for doing that request in a way
29 // which memoizes and does dep-graph tracking, wrapping around the actual
30 // `Providers` that the driver creates (using several `rustc_*` crates).
32 // The result type of each query must implement `Clone`, and additionally
33 // `ty::query::values::Value`, which produces an appropriate placeholder
34 // (error) value if the query resulted in a query cycle.
35 // Queries marked with `fatal_cycle` do not need the latter implementation,
36 // as they will raise an fatal error on query cycles instead.
38 query trigger_delay_span_bug(key: DefId) -> () {
39 desc { "trigger a delay span bug" }
42 /// Represents crate as a whole (as distinct from the top-level crate module).
43 /// If you call `hir_crate` (e.g., indirectly by calling `tcx.hir().krate()`),
44 /// we will have to assume that any change means that you need to be recompiled.
45 /// This is because the `hir_crate` query gives you access to all other items.
46 /// To avoid this fate, do not call `tcx.hir().krate()`; instead,
47 /// prefer wrappers like `tcx.visit_all_items_in_krate()`.
48 query hir_crate(key: CrateNum) -> &'tcx Crate<'tcx> {
51 desc { "get the crate HIR" }
54 /// The indexed HIR. This can be conveniently accessed by `tcx.hir()`.
55 /// Avoid calling this query directly.
56 query index_hir(_: CrateNum) -> &'tcx map::IndexedHir<'tcx> {
62 /// The items in a module.
64 /// This can be conveniently accessed by `tcx.hir().visit_item_likes_in_module`.
65 /// Avoid calling this query directly.
66 query hir_module_items(key: LocalDefId) -> &'tcx hir::ModuleItems {
68 desc { |tcx| "HIR module items in `{}`", tcx.def_path_str(key.to_def_id()) }
71 /// Gives access to the HIR node for the HIR owner `key`.
73 /// This can be conveniently accessed by methods on `tcx.hir()`.
74 /// Avoid calling this query directly.
75 query hir_owner(key: LocalDefId) -> Option<&'tcx crate::hir::Owner<'tcx>> {
77 desc { |tcx| "HIR owner of `{}`", tcx.def_path_str(key.to_def_id()) }
80 /// Gives access to the HIR nodes and bodies inside the HIR owner `key`.
82 /// This can be conveniently accessed by methods on `tcx.hir()`.
83 /// Avoid calling this query directly.
84 query hir_owner_nodes(key: LocalDefId) -> Option<&'tcx crate::hir::OwnerNodes<'tcx>> {
86 desc { |tcx| "HIR owner items in `{}`", tcx.def_path_str(key.to_def_id()) }
89 /// Computes the `DefId` of the corresponding const parameter in case the `key` is a
90 /// const argument and returns `None` otherwise.
92 /// ```ignore (incomplete)
93 /// let a = foo::<7>();
94 /// // ^ Calling `opt_const_param_of` for this argument,
96 /// fn foo<const N: usize>()
97 /// // ^ returns this `DefId`.
100 /// // ^ While calling `opt_const_param_of` for other bodies returns `None`.
103 // It looks like caching this query on disk actually slightly
104 // worsened performance in #74376.
106 // Once const generics are more prevalently used, we might want to
107 // consider only caching calls returning `Some`.
108 query opt_const_param_of(key: LocalDefId) -> Option<DefId> {
109 desc { |tcx| "computing the optional const parameter of `{}`", tcx.def_path_str(key.to_def_id()) }
112 /// Records the type of every item.
113 query type_of(key: DefId) -> Ty<'tcx> {
114 desc { |tcx| "computing type of `{}`", tcx.def_path_str(key) }
115 cache_on_disk_if { key.is_local() }
118 query analysis(key: CrateNum) -> Result<(), ErrorReported> {
120 desc { "running analysis passes on this crate" }
123 /// Maps from the `DefId` of an item (trait/struct/enum/fn) to its
124 /// associated generics.
125 query generics_of(key: DefId) -> ty::Generics {
126 desc { |tcx| "computing generics of `{}`", tcx.def_path_str(key) }
127 storage(ArenaCacheSelector<'tcx>)
128 cache_on_disk_if { key.is_local() }
129 load_cached(tcx, id) {
130 let generics: Option<ty::Generics> = tcx.queries.on_disk_cache.as_ref()
131 .and_then(|c| c.try_load_query_result(tcx, id));
136 /// Maps from the `DefId` of an item (trait/struct/enum/fn) to the
137 /// predicates (where-clauses) that must be proven true in order
138 /// to reference it. This is almost always the "predicates query"
141 /// `predicates_of` builds on `predicates_defined_on` -- in fact,
142 /// it is almost always the same as that query, except for the
143 /// case of traits. For traits, `predicates_of` contains
144 /// an additional `Self: Trait<...>` predicate that users don't
145 /// actually write. This reflects the fact that to invoke the
146 /// trait (e.g., via `Default::default`) you must supply types
147 /// that actually implement the trait. (However, this extra
148 /// predicate gets in the way of some checks, which are intended
149 /// to operate over only the actual where-clauses written by the
151 query predicates_of(key: DefId) -> ty::GenericPredicates<'tcx> {
152 desc { |tcx| "computing predicates of `{}`", tcx.def_path_str(key) }
153 cache_on_disk_if { key.is_local() }
156 /// Returns the list of bounds that can be used for
157 /// `SelectionCandidate::ProjectionCandidate(_)` and
158 /// `ProjectionTyCandidate::TraitDef`.
159 /// Specifically this is the bounds written on the trait's type
160 /// definition, or those after the `impl` keyword
162 /// ```ignore (incomplete)
163 /// type X: Bound + 'lt
165 /// impl Debug + Display
166 /// // ^^^^^^^^^^^^^^^
169 /// `key` is the `DefId` of the associated type or opaque type.
171 /// Bounds from the parent (e.g. with nested impl trait) are not included.
172 query explicit_item_bounds(key: DefId) -> &'tcx [(ty::Predicate<'tcx>, Span)] {
173 desc { |tcx| "finding item bounds for `{}`", tcx.def_path_str(key) }
176 /// Elaborated version of the predicates from `explicit_item_bounds`.
182 /// type MyAType: Eq + ?Sized;
186 /// `explicit_item_bounds` returns `[<Self as MyTrait>::MyAType: Eq]`,
187 /// and `item_bounds` returns
190 /// <Self as Trait>::MyAType: Eq,
191 /// <Self as Trait>::MyAType: PartialEq<<Self as Trait>::MyAType>
195 /// Bounds from the parent (e.g. with nested impl trait) are not included.
196 query item_bounds(key: DefId) -> &'tcx ty::List<ty::Predicate<'tcx>> {
197 desc { |tcx| "elaborating item bounds for `{}`", tcx.def_path_str(key) }
200 query projection_ty_from_predicates(key: (DefId, DefId)) -> Option<ty::ProjectionTy<'tcx>> {
201 desc { |tcx| "finding projection type inside predicates of `{}`", tcx.def_path_str(key.0) }
204 query native_libraries(_: CrateNum) -> Lrc<Vec<NativeLib>> {
205 desc { "looking up the native libraries of a linked crate" }
208 query lint_levels(_: CrateNum) -> LintLevelMap {
209 storage(ArenaCacheSelector<'tcx>)
211 desc { "computing the lint levels for items in this crate" }
214 query parent_module_from_def_id(key: LocalDefId) -> LocalDefId {
216 desc { |tcx| "parent module of `{}`", tcx.def_path_str(key.to_def_id()) }
219 /// Internal helper query. Use `tcx.expansion_that_defined` instead
220 query expn_that_defined(key: DefId) -> rustc_span::ExpnId {
221 desc { |tcx| "expansion that defined `{}`", tcx.def_path_str(key) }
224 query is_panic_runtime(_: CrateNum) -> bool {
226 desc { "checking if the crate is_panic_runtime" }
229 /// Set of all the `DefId`s in this crate that have MIR associated with
230 /// them. This includes all the body owners, but also things like struct
232 query mir_keys(_: CrateNum) -> FxHashSet<LocalDefId> {
233 storage(ArenaCacheSelector<'tcx>)
234 desc { "getting a list of all mir_keys" }
237 /// Maps DefId's that have an associated `mir::Body` to the result
238 /// of the MIR const-checking pass. This is the set of qualifs in
239 /// the final value of a `const`.
240 query mir_const_qualif(key: DefId) -> mir::ConstQualifs {
241 desc { |tcx| "const checking `{}`", tcx.def_path_str(key) }
242 cache_on_disk_if { key.is_local() }
244 query mir_const_qualif_const_arg(
245 key: (LocalDefId, DefId)
246 ) -> mir::ConstQualifs {
248 |tcx| "const checking the const argument `{}`",
249 tcx.def_path_str(key.0.to_def_id())
253 /// Fetch the MIR for a given `DefId` right after it's built - this includes
254 /// unreachable code.
255 query mir_built(key: ty::WithOptConstParam<LocalDefId>) -> &'tcx Steal<mir::Body<'tcx>> {
256 desc { |tcx| "building MIR for `{}`", tcx.def_path_str(key.did.to_def_id()) }
259 /// Fetch the MIR for a given `DefId` up till the point where it is
260 /// ready for const qualification.
262 /// See the README for the `mir` module for details.
263 query mir_const(key: ty::WithOptConstParam<LocalDefId>) -> &'tcx Steal<mir::Body<'tcx>> {
265 |tcx| "processing MIR for {}`{}`",
266 if key.const_param_did.is_some() { "the const argument " } else { "" },
267 tcx.def_path_str(key.did.to_def_id()),
272 /// Try to build an abstract representation of the given constant.
273 query mir_abstract_const(
275 ) -> Result<Option<&'tcx [mir::abstract_const::Node<'tcx>]>, ErrorReported> {
277 |tcx| "building an abstract representation for {}", tcx.def_path_str(key),
280 /// Try to build an abstract representation of the given constant.
281 query mir_abstract_const_of_const_arg(
282 key: (LocalDefId, DefId)
283 ) -> Result<Option<&'tcx [mir::abstract_const::Node<'tcx>]>, ErrorReported> {
286 "building an abstract representation for the const argument {}",
287 tcx.def_path_str(key.0.to_def_id()),
291 query try_unify_abstract_consts(key: (
292 (ty::WithOptConstParam<DefId>, SubstsRef<'tcx>),
293 (ty::WithOptConstParam<DefId>, SubstsRef<'tcx>)
296 |tcx| "trying to unify the generic constants {} and {}",
297 tcx.def_path_str(key.0.0.did), tcx.def_path_str(key.1.0.did)
301 query mir_drops_elaborated_and_const_checked(
302 key: ty::WithOptConstParam<LocalDefId>
303 ) -> &'tcx Steal<mir::Body<'tcx>> {
305 desc { |tcx| "elaborating drops for `{}`", tcx.def_path_str(key.did.to_def_id()) }
310 ) -> &'tcx mir::Body<'tcx> {
311 desc { |tcx| "caching mir of `{}` for CTFE", tcx.def_path_str(key) }
312 cache_on_disk_if { key.is_local() }
315 query mir_for_ctfe_of_const_arg(key: (LocalDefId, DefId)) -> &'tcx mir::Body<'tcx> {
317 |tcx| "MIR for CTFE of the const argument `{}`",
318 tcx.def_path_str(key.0.to_def_id())
322 query mir_promoted(key: ty::WithOptConstParam<LocalDefId>) ->
324 &'tcx Steal<mir::Body<'tcx>>,
325 &'tcx Steal<IndexVec<mir::Promoted, mir::Body<'tcx>>>
329 |tcx| "processing {}`{}`",
330 if key.const_param_did.is_some() { "the const argument " } else { "" },
331 tcx.def_path_str(key.did.to_def_id()),
335 /// MIR after our optimization passes have run. This is MIR that is ready
336 /// for codegen. This is also the only query that can fetch non-local MIR, at present.
337 query optimized_mir(key: DefId) -> &'tcx mir::Body<'tcx> {
338 desc { |tcx| "optimizing MIR for `{}`", tcx.def_path_str(key) }
339 cache_on_disk_if { key.is_local() }
342 /// Returns coverage summary info for a function, after executing the `InstrumentCoverage`
343 /// MIR pass (assuming the -Zinstrument-coverage option is enabled).
344 query coverageinfo(key: DefId) -> mir::CoverageInfo {
345 desc { |tcx| "retrieving coverage info from MIR for `{}`", tcx.def_path_str(key) }
346 storage(ArenaCacheSelector<'tcx>)
347 cache_on_disk_if { key.is_local() }
350 /// Returns the name of the file that contains the function body, if instrumented for coverage.
351 query covered_file_name(key: DefId) -> Option<Symbol> {
352 desc { |tcx| "retrieving the covered file name, if instrumented, for `{}`", tcx.def_path_str(key) }
353 storage(ArenaCacheSelector<'tcx>)
354 cache_on_disk_if { key.is_local() }
357 /// Returns the `CodeRegions` for a function that has instrumented coverage, in case the
358 /// function was optimized out before codegen, and before being added to the Coverage Map.
359 query covered_code_regions(key: DefId) -> Vec<&'tcx mir::coverage::CodeRegion> {
360 desc { |tcx| "retrieving the covered `CodeRegion`s, if instrumented, for `{}`", tcx.def_path_str(key) }
361 storage(ArenaCacheSelector<'tcx>)
362 cache_on_disk_if { key.is_local() }
365 /// The `DefId` is the `DefId` of the containing MIR body. Promoteds do not have their own
366 /// `DefId`. This function returns all promoteds in the specified body. The body references
367 /// promoteds by the `DefId` and the `mir::Promoted` index. This is necessary, because
368 /// after inlining a body may refer to promoteds from other bodies. In that case you still
369 /// need to use the `DefId` of the original body.
370 query promoted_mir(key: DefId) -> &'tcx IndexVec<mir::Promoted, mir::Body<'tcx>> {
371 desc { |tcx| "optimizing promoted MIR for `{}`", tcx.def_path_str(key) }
372 cache_on_disk_if { key.is_local() }
374 query promoted_mir_of_const_arg(
375 key: (LocalDefId, DefId)
376 ) -> &'tcx IndexVec<mir::Promoted, mir::Body<'tcx>> {
378 |tcx| "optimizing promoted MIR for the const argument `{}`",
379 tcx.def_path_str(key.0.to_def_id()),
383 /// Erases regions from `ty` to yield a new type.
384 /// Normally you would just use `tcx.erase_regions(value)`,
385 /// however, which uses this query as a kind of cache.
386 query erase_regions_ty(ty: Ty<'tcx>) -> Ty<'tcx> {
387 // This query is not expected to have input -- as a result, it
388 // is not a good candidates for "replay" because it is essentially a
389 // pure function of its input (and hence the expectation is that
390 // no caller would be green **apart** from just these
391 // queries). Making it anonymous avoids hashing the result, which
392 // may save a bit of time.
394 desc { "erasing regions from `{:?}`", ty }
397 query wasm_import_module_map(_: CrateNum) -> FxHashMap<DefId, String> {
398 storage(ArenaCacheSelector<'tcx>)
399 desc { "wasm import module map" }
402 /// Maps from the `DefId` of an item (trait/struct/enum/fn) to the
403 /// predicates (where-clauses) directly defined on it. This is
404 /// equal to the `explicit_predicates_of` predicates plus the
405 /// `inferred_outlives_of` predicates.
406 query predicates_defined_on(key: DefId) -> ty::GenericPredicates<'tcx> {
407 desc { |tcx| "computing predicates of `{}`", tcx.def_path_str(key) }
410 /// Returns everything that looks like a predicate written explicitly
411 /// by the user on a trait item.
413 /// Traits are unusual, because predicates on associated types are
414 /// converted into bounds on that type for backwards compatibility:
416 /// trait X where Self::U: Copy { type U; }
420 /// trait X { type U: Copy; }
422 /// `explicit_predicates_of` and `explicit_item_bounds` will then take
423 /// the appropriate subsets of the predicates here.
424 query trait_explicit_predicates_and_bounds(key: LocalDefId) -> ty::GenericPredicates<'tcx> {
425 desc { |tcx| "computing explicit predicates of trait `{}`", tcx.def_path_str(key.to_def_id()) }
428 /// Returns the predicates written explicitly by the user.
429 query explicit_predicates_of(key: DefId) -> ty::GenericPredicates<'tcx> {
430 desc { |tcx| "computing explicit predicates of `{}`", tcx.def_path_str(key) }
433 /// Returns the inferred outlives predicates (e.g., for `struct
434 /// Foo<'a, T> { x: &'a T }`, this would return `T: 'a`).
435 query inferred_outlives_of(key: DefId) -> &'tcx [(ty::Predicate<'tcx>, Span)] {
436 desc { |tcx| "computing inferred outlives predicates of `{}`", tcx.def_path_str(key) }
439 /// Maps from the `DefId` of a trait to the list of
440 /// super-predicates. This is a subset of the full list of
441 /// predicates. We store these in a separate map because we must
442 /// evaluate them even during type conversion, often before the
443 /// full predicates are available (note that supertraits have
444 /// additional acyclicity requirements).
445 query super_predicates_of(key: DefId) -> ty::GenericPredicates<'tcx> {
446 desc { |tcx| "computing the supertraits of `{}`", tcx.def_path_str(key) }
449 /// To avoid cycles within the predicates of a single item we compute
450 /// per-type-parameter predicates for resolving `T::AssocTy`.
451 query type_param_predicates(key: (DefId, LocalDefId)) -> ty::GenericPredicates<'tcx> {
452 desc { |tcx| "computing the bounds for type parameter `{}`", {
453 let id = tcx.hir().local_def_id_to_hir_id(key.1);
454 tcx.hir().ty_param_name(id)
458 query trait_def(key: DefId) -> ty::TraitDef {
459 desc { |tcx| "computing trait definition for `{}`", tcx.def_path_str(key) }
460 storage(ArenaCacheSelector<'tcx>)
462 query adt_def(key: DefId) -> &'tcx ty::AdtDef {
463 desc { |tcx| "computing ADT definition for `{}`", tcx.def_path_str(key) }
465 query adt_destructor(key: DefId) -> Option<ty::Destructor> {
466 desc { |tcx| "computing `Drop` impl for `{}`", tcx.def_path_str(key) }
469 // The cycle error here should be reported as an error by `check_representable`.
470 // We consider the type as Sized in the meanwhile to avoid
471 // further errors (done in impl Value for AdtSizedConstraint).
472 // Use `cycle_delay_bug` to delay the cycle error here to be emitted later
473 // in case we accidentally otherwise don't emit an error.
474 query adt_sized_constraint(
476 ) -> AdtSizedConstraint<'tcx> {
477 desc { |tcx| "computing `Sized` constraints for `{}`", tcx.def_path_str(key) }
481 query adt_dtorck_constraint(
483 ) -> Result<DtorckConstraint<'tcx>, NoSolution> {
484 desc { |tcx| "computing drop-check constraints for `{}`", tcx.def_path_str(key) }
487 /// Returns `true` if this is a const fn, use the `is_const_fn` to know whether your crate
488 /// actually sees it as const fn (e.g., the const-fn-ness might be unstable and you might
489 /// not have the feature gate active).
491 /// **Do not call this function manually.** It is only meant to cache the base data for the
492 /// `is_const_fn` function.
493 query is_const_fn_raw(key: DefId) -> bool {
494 desc { |tcx| "checking if item is const fn: `{}`", tcx.def_path_str(key) }
497 /// Returns `true` if this is a const `impl`. **Do not call this function manually.**
499 /// This query caches the base data for the `is_const_impl` helper function, which also
500 /// takes into account stability attributes (e.g., `#[rustc_const_unstable]`).
501 query is_const_impl_raw(key: DefId) -> bool {
502 desc { |tcx| "checking if item is const impl: `{}`", tcx.def_path_str(key) }
505 query asyncness(key: DefId) -> hir::IsAsync {
506 desc { |tcx| "checking if the function is async: `{}`", tcx.def_path_str(key) }
509 /// Returns `true` if calls to the function may be promoted.
511 /// This is either because the function is e.g., a tuple-struct or tuple-variant
512 /// constructor, or because it has the `#[rustc_promotable]` attribute. The attribute should
513 /// be removed in the future in favour of some form of check which figures out whether the
514 /// function does not inspect the bits of any of its arguments (so is essentially just a
515 /// constructor function).
516 query is_promotable_const_fn(key: DefId) -> bool {
517 desc { |tcx| "checking if item is promotable: `{}`", tcx.def_path_str(key) }
520 /// Returns `true` if this is a foreign item (i.e., linked via `extern { ... }`).
521 query is_foreign_item(key: DefId) -> bool {
522 desc { |tcx| "checking if `{}` is a foreign item", tcx.def_path_str(key) }
525 /// Returns `Some(mutability)` if the node pointed to by `def_id` is a static item.
526 query static_mutability(def_id: DefId) -> Option<hir::Mutability> {
527 desc { |tcx| "looking up static mutability of `{}`", tcx.def_path_str(def_id) }
530 /// Returns `Some(generator_kind)` if the node pointed to by `def_id` is a generator.
531 query generator_kind(def_id: DefId) -> Option<hir::GeneratorKind> {
532 desc { |tcx| "looking up generator kind of `{}`", tcx.def_path_str(def_id) }
535 /// Gets a map with the variance of every item; use `item_variance` instead.
536 query crate_variances(_: CrateNum) -> ty::CrateVariancesMap<'tcx> {
537 storage(ArenaCacheSelector<'tcx>)
538 desc { "computing the variances for items in this crate" }
541 /// Maps from the `DefId` of a type or region parameter to its (inferred) variance.
542 query variances_of(def_id: DefId) -> &'tcx [ty::Variance] {
543 desc { |tcx| "computing the variances of `{}`", tcx.def_path_str(def_id) }
546 /// Maps from thee `DefId` of a type to its (inferred) outlives.
547 query inferred_outlives_crate(_: CrateNum)
548 -> ty::CratePredicatesMap<'tcx> {
549 storage(ArenaCacheSelector<'tcx>)
550 desc { "computing the inferred outlives predicates for items in this crate" }
553 /// Maps from an impl/trait `DefId to a list of the `DefId`s of its items.
554 query associated_item_def_ids(key: DefId) -> &'tcx [DefId] {
555 desc { |tcx| "collecting associated items of `{}`", tcx.def_path_str(key) }
558 /// Maps from a trait item to the trait item "descriptor".
559 query associated_item(key: DefId) -> ty::AssocItem {
560 desc { |tcx| "computing associated item data for `{}`", tcx.def_path_str(key) }
561 storage(ArenaCacheSelector<'tcx>)
564 /// Collects the associated items defined on a trait or impl.
565 query associated_items(key: DefId) -> ty::AssociatedItems<'tcx> {
566 storage(ArenaCacheSelector<'tcx>)
567 desc { |tcx| "collecting associated items of {}", tcx.def_path_str(key) }
570 /// Given an `impl_id`, return the trait it implements.
571 /// Return `None` if this is an inherent impl.
572 query impl_trait_ref(impl_id: DefId) -> Option<ty::TraitRef<'tcx>> {
573 desc { |tcx| "computing trait implemented by `{}`", tcx.def_path_str(impl_id) }
575 query impl_polarity(impl_id: DefId) -> ty::ImplPolarity {
576 desc { |tcx| "computing implementation polarity of `{}`", tcx.def_path_str(impl_id) }
579 query issue33140_self_ty(key: DefId) -> Option<ty::Ty<'tcx>> {
580 desc { |tcx| "computing Self type wrt issue #33140 `{}`", tcx.def_path_str(key) }
583 /// Maps a `DefId` of a type to a list of its inherent impls.
584 /// Contains implementations of methods that are inherent to a type.
585 /// Methods in these implementations don't need to be exported.
586 query inherent_impls(key: DefId) -> &'tcx [DefId] {
587 desc { |tcx| "collecting inherent impls for `{}`", tcx.def_path_str(key) }
591 /// The result of unsafety-checking this `LocalDefId`.
592 query unsafety_check_result(key: LocalDefId) -> &'tcx mir::UnsafetyCheckResult {
593 desc { |tcx| "unsafety-checking `{}`", tcx.def_path_str(key.to_def_id()) }
594 cache_on_disk_if { true }
596 query unsafety_check_result_for_const_arg(key: (LocalDefId, DefId)) -> &'tcx mir::UnsafetyCheckResult {
598 |tcx| "unsafety-checking the const argument `{}`",
599 tcx.def_path_str(key.0.to_def_id())
603 /// HACK: when evaluated, this reports a "unsafe derive on repr(packed)" error.
605 /// Unsafety checking is executed for each method separately, but we only want
606 /// to emit this error once per derive. As there are some impls with multiple
607 /// methods, we use a query for deduplication.
608 query unsafe_derive_on_repr_packed(key: LocalDefId) -> () {
609 desc { |tcx| "processing `{}`", tcx.def_path_str(key.to_def_id()) }
612 /// The signature of functions.
613 query fn_sig(key: DefId) -> ty::PolyFnSig<'tcx> {
614 desc { |tcx| "computing function signature of `{}`", tcx.def_path_str(key) }
617 query lint_mod(key: LocalDefId) -> () {
618 desc { |tcx| "linting {}", describe_as_module(key, tcx) }
621 /// Checks the attributes in the module.
622 query check_mod_attrs(key: LocalDefId) -> () {
623 desc { |tcx| "checking attributes in {}", describe_as_module(key, tcx) }
626 query check_mod_unstable_api_usage(key: LocalDefId) -> () {
627 desc { |tcx| "checking for unstable API usage in {}", describe_as_module(key, tcx) }
630 /// Checks the const bodies in the module for illegal operations (e.g. `if` or `loop`).
631 query check_mod_const_bodies(key: LocalDefId) -> () {
632 desc { |tcx| "checking consts in {}", describe_as_module(key, tcx) }
635 /// Checks the loops in the module.
636 query check_mod_loops(key: LocalDefId) -> () {
637 desc { |tcx| "checking loops in {}", describe_as_module(key, tcx) }
640 query check_mod_naked_functions(key: LocalDefId) -> () {
641 desc { |tcx| "checking naked functions in {}", describe_as_module(key, tcx) }
644 query check_mod_item_types(key: LocalDefId) -> () {
645 desc { |tcx| "checking item types in {}", describe_as_module(key, tcx) }
648 query check_mod_privacy(key: LocalDefId) -> () {
649 desc { |tcx| "checking privacy in {}", describe_as_module(key, tcx) }
652 query check_mod_intrinsics(key: LocalDefId) -> () {
653 desc { |tcx| "checking intrinsics in {}", describe_as_module(key, tcx) }
656 query check_mod_liveness(key: LocalDefId) -> () {
657 desc { |tcx| "checking liveness of variables in {}", describe_as_module(key, tcx) }
660 query check_mod_impl_wf(key: LocalDefId) -> () {
661 desc { |tcx| "checking that impls are well-formed in {}", describe_as_module(key, tcx) }
664 query collect_mod_item_types(key: LocalDefId) -> () {
665 desc { |tcx| "collecting item types in {}", describe_as_module(key, tcx) }
668 /// Caches `CoerceUnsized` kinds for impls on custom types.
669 query coerce_unsized_info(key: DefId)
670 -> ty::adjustment::CoerceUnsizedInfo {
671 desc { |tcx| "computing CoerceUnsized info for `{}`", tcx.def_path_str(key) }
674 query typeck_item_bodies(_: CrateNum) -> () {
675 desc { "type-checking all item bodies" }
678 query typeck(key: LocalDefId) -> &'tcx ty::TypeckResults<'tcx> {
679 desc { |tcx| "type-checking `{}`", tcx.def_path_str(key.to_def_id()) }
680 cache_on_disk_if { true }
682 query typeck_const_arg(
683 key: (LocalDefId, DefId)
684 ) -> &'tcx ty::TypeckResults<'tcx> {
686 |tcx| "type-checking the const argument `{}`",
687 tcx.def_path_str(key.0.to_def_id()),
690 query diagnostic_only_typeck(key: LocalDefId) -> &'tcx ty::TypeckResults<'tcx> {
691 desc { |tcx| "type-checking `{}`", tcx.def_path_str(key.to_def_id()) }
692 cache_on_disk_if { true }
693 load_cached(tcx, id) {
694 let typeck_results: Option<ty::TypeckResults<'tcx>> = tcx
695 .queries.on_disk_cache.as_ref()
696 .and_then(|c| c.try_load_query_result(tcx, id));
698 typeck_results.map(|x| &*tcx.arena.alloc(x))
702 query used_trait_imports(key: LocalDefId) -> &'tcx FxHashSet<LocalDefId> {
703 desc { |tcx| "used_trait_imports `{}`", tcx.def_path_str(key.to_def_id()) }
704 cache_on_disk_if { true }
707 query has_typeck_results(def_id: DefId) -> bool {
708 desc { |tcx| "checking whether `{}` has a body", tcx.def_path_str(def_id) }
711 query coherent_trait(def_id: DefId) -> () {
712 desc { |tcx| "coherence checking all impls of trait `{}`", tcx.def_path_str(def_id) }
715 /// Borrow-checks the function body. If this is a closure, returns
716 /// additional requirements that the closure's creator must verify.
717 query mir_borrowck(key: LocalDefId) -> &'tcx mir::BorrowCheckResult<'tcx> {
718 desc { |tcx| "borrow-checking `{}`", tcx.def_path_str(key.to_def_id()) }
719 cache_on_disk_if(tcx, opt_result) {
720 tcx.is_closure(key.to_def_id())
721 || opt_result.map_or(false, |r| !r.concrete_opaque_types.is_empty())
724 query mir_borrowck_const_arg(key: (LocalDefId, DefId)) -> &'tcx mir::BorrowCheckResult<'tcx> {
726 |tcx| "borrow-checking the const argument`{}`",
727 tcx.def_path_str(key.0.to_def_id())
731 /// Gets a complete map from all types to their inherent impls.
732 /// Not meant to be used directly outside of coherence.
733 /// (Defined only for `LOCAL_CRATE`.)
734 query crate_inherent_impls(k: CrateNum)
735 -> CrateInherentImpls {
736 storage(ArenaCacheSelector<'tcx>)
738 desc { "all inherent impls defined in crate `{:?}`", k }
741 /// Checks all types in the crate for overlap in their inherent impls. Reports errors.
742 /// Not meant to be used directly outside of coherence.
743 /// (Defined only for `LOCAL_CRATE`.)
744 query crate_inherent_impls_overlap_check(_: CrateNum)
747 desc { "check for overlap between inherent impls defined in this crate" }
750 /// Check whether the function has any recursion that could cause the inliner to trigger
751 /// a cycle. Returns the call stack causing the cycle. The call stack does not contain the
752 /// current function, just all intermediate functions.
753 query mir_callgraph_reachable(key: (ty::Instance<'tcx>, LocalDefId)) -> bool {
756 "computing if `{}` (transitively) calls `{}`",
758 tcx.def_path_str(key.1.to_def_id()),
762 /// Obtain all the calls into other local functions
763 query mir_inliner_callees(key: ty::InstanceDef<'tcx>) -> &'tcx [(DefId, SubstsRef<'tcx>)] {
766 "computing all local function calls in `{}`",
767 tcx.def_path_str(key.def_id()),
771 /// Evaluates a constant and returns the computed allocation.
773 /// **Do not use this** directly, use the `tcx.eval_static_initializer` wrapper.
774 query eval_to_allocation_raw(key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>)
775 -> EvalToAllocationRawResult<'tcx> {
777 "const-evaluating + checking `{}`",
778 key.value.display(tcx)
780 cache_on_disk_if { true }
783 /// Evaluates const items or anonymous constants
784 /// (such as enum variant explicit discriminants or array lengths)
785 /// into a representation suitable for the type system and const generics.
787 /// **Do not use this** directly, use one of the following wrappers: `tcx.const_eval_poly`,
788 /// `tcx.const_eval_resolve`, `tcx.const_eval_instance`, or `tcx.const_eval_global_id`.
789 query eval_to_const_value_raw(key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>)
790 -> EvalToConstValueResult<'tcx> {
792 "simplifying constant for the type system `{}`",
793 key.value.display(tcx)
795 cache_on_disk_if { true }
798 /// Destructure a constant ADT or array into its variant index and its
800 query destructure_const(
801 key: ty::ParamEnvAnd<'tcx, &'tcx ty::Const<'tcx>>
802 ) -> mir::DestructuredConst<'tcx> {
803 desc { "destructure constant" }
806 /// Dereference a constant reference or raw pointer and turn the result into a constant
809 key: ty::ParamEnvAnd<'tcx, &'tcx ty::Const<'tcx>>
810 ) -> &'tcx ty::Const<'tcx> {
811 desc { "deref constant" }
814 query const_caller_location(key: (rustc_span::Symbol, u32, u32)) -> ConstValue<'tcx> {
815 desc { "get a &core::panic::Location referring to a span" }
819 key: LitToConstInput<'tcx>
820 ) -> Result<&'tcx ty::Const<'tcx>, LitToConstError> {
821 desc { "converting literal to const" }
824 query check_match(key: DefId) {
825 desc { |tcx| "match-checking `{}`", tcx.def_path_str(key) }
826 cache_on_disk_if { key.is_local() }
829 /// Performs part of the privacy check and computes "access levels".
830 query privacy_access_levels(_: CrateNum) -> &'tcx AccessLevels {
832 desc { "privacy access levels" }
834 query check_private_in_public(_: CrateNum) -> () {
836 desc { "checking for private elements in public interfaces" }
839 query reachable_set(_: CrateNum) -> FxHashSet<LocalDefId> {
840 storage(ArenaCacheSelector<'tcx>)
841 desc { "reachability" }
844 /// Per-body `region::ScopeTree`. The `DefId` should be the owner `DefId` for the body;
845 /// in the case of closures, this will be redirected to the enclosing function.
846 query region_scope_tree(def_id: DefId) -> &'tcx region::ScopeTree {
847 desc { |tcx| "computing drop scopes for `{}`", tcx.def_path_str(def_id) }
850 query mir_shims(key: ty::InstanceDef<'tcx>) -> mir::Body<'tcx> {
851 storage(ArenaCacheSelector<'tcx>)
852 desc { |tcx| "generating MIR shim for `{}`", tcx.def_path_str(key.def_id()) }
855 /// The `symbol_name` query provides the symbol name for calling a
856 /// given instance from the local crate. In particular, it will also
857 /// look up the correct symbol name of instances from upstream crates.
858 query symbol_name(key: ty::Instance<'tcx>) -> ty::SymbolName<'tcx> {
859 desc { "computing the symbol for `{}`", key }
860 cache_on_disk_if { true }
863 query opt_def_kind(def_id: DefId) -> Option<DefKind> {
864 desc { |tcx| "looking up definition kind of `{}`", tcx.def_path_str(def_id) }
867 query def_span(def_id: DefId) -> Span {
868 desc { |tcx| "looking up span for `{}`", tcx.def_path_str(def_id) }
869 // FIXME(mw): DefSpans are not really inputs since they are derived from
870 // HIR. But at the moment HIR hashing still contains some hacks that allow
871 // to make type debuginfo to be source location independent. Declaring
872 // DefSpan an input makes sure that changes to these are always detected
873 // regardless of HIR hashing.
877 query def_ident_span(def_id: DefId) -> Option<Span> {
878 desc { |tcx| "looking up span for `{}`'s identifier", tcx.def_path_str(def_id) }
881 query lookup_stability(def_id: DefId) -> Option<&'tcx attr::Stability> {
882 desc { |tcx| "looking up stability of `{}`", tcx.def_path_str(def_id) }
885 query lookup_const_stability(def_id: DefId) -> Option<&'tcx attr::ConstStability> {
886 desc { |tcx| "looking up const stability of `{}`", tcx.def_path_str(def_id) }
889 query lookup_deprecation_entry(def_id: DefId) -> Option<DeprecationEntry> {
890 desc { |tcx| "checking whether `{}` is deprecated", tcx.def_path_str(def_id) }
893 query item_attrs(def_id: DefId) -> &'tcx [ast::Attribute] {
894 desc { |tcx| "collecting attributes of `{}`", tcx.def_path_str(def_id) }
897 query codegen_fn_attrs(def_id: DefId) -> CodegenFnAttrs {
898 desc { |tcx| "computing codegen attributes of `{}`", tcx.def_path_str(def_id) }
899 storage(ArenaCacheSelector<'tcx>)
900 cache_on_disk_if { true }
903 query fn_arg_names(def_id: DefId) -> &'tcx [rustc_span::symbol::Ident] {
904 desc { |tcx| "looking up function parameter names for `{}`", tcx.def_path_str(def_id) }
906 /// Gets the rendered value of the specified constant or associated constant.
908 query rendered_const(def_id: DefId) -> String {
909 desc { |tcx| "rendering constant intializer of `{}`", tcx.def_path_str(def_id) }
911 query impl_parent(def_id: DefId) -> Option<DefId> {
912 desc { |tcx| "computing specialization parent impl of `{}`", tcx.def_path_str(def_id) }
915 /// Given an `associated_item`, find the trait it belongs to.
916 /// Return `None` if the `DefId` is not an associated item.
917 query trait_of_item(associated_item: DefId) -> Option<DefId> {
918 desc { |tcx| "finding trait defining `{}`", tcx.def_path_str(associated_item) }
921 query is_ctfe_mir_available(key: DefId) -> bool {
922 desc { |tcx| "checking if item has ctfe mir available: `{}`", tcx.def_path_str(key) }
924 query is_mir_available(key: DefId) -> bool {
925 desc { |tcx| "checking if item has mir available: `{}`", tcx.def_path_str(key) }
928 query vtable_methods(key: ty::PolyTraitRef<'tcx>)
929 -> &'tcx [Option<(DefId, SubstsRef<'tcx>)>] {
930 desc { |tcx| "finding all methods for trait {}", tcx.def_path_str(key.def_id()) }
933 query codegen_fulfill_obligation(
934 key: (ty::ParamEnv<'tcx>, ty::PolyTraitRef<'tcx>)
935 ) -> Result<ImplSource<'tcx, ()>, ErrorReported> {
936 cache_on_disk_if { true }
938 "checking if `{}` fulfills its obligations",
939 tcx.def_path_str(key.1.def_id())
943 /// Return all `impl` blocks in the current crate.
945 /// To allow caching this between crates, you must pass in [`LOCAL_CRATE`] as the crate number.
946 /// Passing in any other crate will cause an ICE.
948 /// [`LOCAL_CRATE`]: rustc_hir::def_id::LOCAL_CRATE
949 query all_local_trait_impls(local_crate: CrateNum) -> &'tcx BTreeMap<DefId, Vec<hir::HirId>> {
950 desc { "local trait impls" }
953 /// Given a trait `trait_id`, return all known `impl` blocks.
954 query trait_impls_of(trait_id: DefId) -> ty::trait_def::TraitImpls {
955 storage(ArenaCacheSelector<'tcx>)
956 desc { |tcx| "trait impls of `{}`", tcx.def_path_str(trait_id) }
959 query specialization_graph_of(trait_id: DefId) -> specialization_graph::Graph {
960 storage(ArenaCacheSelector<'tcx>)
961 desc { |tcx| "building specialization graph of trait `{}`", tcx.def_path_str(trait_id) }
962 cache_on_disk_if { true }
964 query object_safety_violations(trait_id: DefId) -> &'tcx [traits::ObjectSafetyViolation] {
965 desc { |tcx| "determine object safety of trait `{}`", tcx.def_path_str(trait_id) }
968 /// Gets the ParameterEnvironment for a given item; this environment
969 /// will be in "user-facing" mode, meaning that it is suitable for
970 /// type-checking etc, and it does not normalize specializable
971 /// associated types. This is almost always what you want,
972 /// unless you are doing MIR optimizations, in which case you
973 /// might want to use `reveal_all()` method to change modes.
974 query param_env(def_id: DefId) -> ty::ParamEnv<'tcx> {
975 desc { |tcx| "computing normalized predicates of `{}`", tcx.def_path_str(def_id) }
978 /// Like `param_env`, but returns the `ParamEnv in `Reveal::All` mode.
979 /// Prefer this over `tcx.param_env(def_id).with_reveal_all_normalized(tcx)`,
980 /// as this method is more efficient.
981 query param_env_reveal_all_normalized(def_id: DefId) -> ty::ParamEnv<'tcx> {
982 desc { |tcx| "computing revealed normalized predicates of `{}`", tcx.def_path_str(def_id) }
985 /// Trait selection queries. These are best used by invoking `ty.is_copy_modulo_regions()`,
986 /// `ty.is_copy()`, etc, since that will prune the environment where possible.
987 query is_copy_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
988 desc { "computing whether `{}` is `Copy`", env.value }
990 /// Query backing `TyS::is_sized`.
991 query is_sized_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
992 desc { "computing whether `{}` is `Sized`", env.value }
994 /// Query backing `TyS::is_freeze`.
995 query is_freeze_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
996 desc { "computing whether `{}` is freeze", env.value }
998 /// Query backing `TyS::needs_drop`.
999 query needs_drop_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1000 desc { "computing whether `{}` needs drop", env.value }
1003 /// Query backing `TyS::is_structural_eq_shallow`.
1005 /// This is only correct for ADTs. Call `is_structural_eq_shallow` to handle all types
1007 query has_structural_eq_impls(ty: Ty<'tcx>) -> bool {
1009 "computing whether `{:?}` implements `PartialStructuralEq` and `StructuralEq`",
1014 /// A list of types where the ADT requires drop if and only if any of
1015 /// those types require drop. If the ADT is known to always need drop
1016 /// then `Err(AlwaysRequiresDrop)` is returned.
1017 query adt_drop_tys(def_id: DefId) -> Result<&'tcx ty::List<Ty<'tcx>>, AlwaysRequiresDrop> {
1018 desc { |tcx| "computing when `{}` needs drop", tcx.def_path_str(def_id) }
1019 cache_on_disk_if { true }
1023 env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>
1024 ) -> Result<&'tcx rustc_target::abi::Layout, ty::layout::LayoutError<'tcx>> {
1025 desc { "computing layout of `{}`", env.value }
1028 query dylib_dependency_formats(_: CrateNum)
1029 -> &'tcx [(CrateNum, LinkagePreference)] {
1030 desc { "dylib dependency formats of crate" }
1033 query dependency_formats(_: CrateNum)
1034 -> Lrc<crate::middle::dependency_format::Dependencies>
1036 desc { "get the linkage format of all dependencies" }
1039 query is_compiler_builtins(_: CrateNum) -> bool {
1041 desc { "checking if the crate is_compiler_builtins" }
1043 query has_global_allocator(_: CrateNum) -> bool {
1045 desc { "checking if the crate has_global_allocator" }
1047 query has_panic_handler(_: CrateNum) -> bool {
1049 desc { "checking if the crate has_panic_handler" }
1051 query is_profiler_runtime(_: CrateNum) -> bool {
1053 desc { "query a crate is `#![profiler_runtime]`" }
1055 query panic_strategy(_: CrateNum) -> PanicStrategy {
1057 desc { "query a crate's configured panic strategy" }
1059 query is_no_builtins(_: CrateNum) -> bool {
1061 desc { "test whether a crate has `#![no_builtins]`" }
1063 query symbol_mangling_version(_: CrateNum) -> SymbolManglingVersion {
1065 desc { "query a crate's symbol mangling version" }
1068 query extern_crate(def_id: DefId) -> Option<&'tcx ExternCrate> {
1070 desc { "getting crate's ExternCrateData" }
1073 query specializes(_: (DefId, DefId)) -> bool {
1074 desc { "computing whether impls specialize one another" }
1076 query in_scope_traits_map(_: LocalDefId)
1077 -> Option<&'tcx FxHashMap<ItemLocalId, StableVec<TraitCandidate>>> {
1079 desc { "traits in scope at a block" }
1082 query module_exports(def_id: LocalDefId) -> Option<&'tcx [Export<LocalDefId>]> {
1083 desc { |tcx| "looking up items exported by `{}`", tcx.def_path_str(def_id.to_def_id()) }
1087 query impl_defaultness(def_id: DefId) -> hir::Defaultness {
1088 desc { |tcx| "looking up whether `{}` is a default impl", tcx.def_path_str(def_id) }
1091 query check_item_well_formed(key: LocalDefId) -> () {
1092 desc { |tcx| "checking that `{}` is well-formed", tcx.def_path_str(key.to_def_id()) }
1094 query check_trait_item_well_formed(key: LocalDefId) -> () {
1095 desc { |tcx| "checking that `{}` is well-formed", tcx.def_path_str(key.to_def_id()) }
1097 query check_impl_item_well_formed(key: LocalDefId) -> () {
1098 desc { |tcx| "checking that `{}` is well-formed", tcx.def_path_str(key.to_def_id()) }
1101 // The `DefId`s of all non-generic functions and statics in the given crate
1102 // that can be reached from outside the crate.
1104 // We expect this items to be available for being linked to.
1106 // This query can also be called for `LOCAL_CRATE`. In this case it will
1107 // compute which items will be reachable to other crates, taking into account
1108 // the kind of crate that is currently compiled. Crates with only a
1109 // C interface have fewer reachable things.
1111 // Does not include external symbols that don't have a corresponding DefId,
1112 // like the compiler-generated `main` function and so on.
1113 query reachable_non_generics(_: CrateNum)
1114 -> DefIdMap<SymbolExportLevel> {
1115 storage(ArenaCacheSelector<'tcx>)
1116 desc { "looking up the exported symbols of a crate" }
1118 query is_reachable_non_generic(def_id: DefId) -> bool {
1119 desc { |tcx| "checking whether `{}` is an exported symbol", tcx.def_path_str(def_id) }
1121 query is_unreachable_local_definition(def_id: DefId) -> bool {
1123 "checking whether `{}` is reachable from outside the crate",
1124 tcx.def_path_str(def_id),
1128 /// The entire set of monomorphizations the local crate can safely link
1129 /// to because they are exported from upstream crates. Do not depend on
1130 /// this directly, as its value changes anytime a monomorphization gets
1131 /// added or removed in any upstream crate. Instead use the narrower
1132 /// `upstream_monomorphizations_for`, `upstream_drop_glue_for`, or, even
1133 /// better, `Instance::upstream_monomorphization()`.
1134 query upstream_monomorphizations(
1136 ) -> DefIdMap<FxHashMap<SubstsRef<'tcx>, CrateNum>> {
1137 storage(ArenaCacheSelector<'tcx>)
1138 desc { "collecting available upstream monomorphizations `{:?}`", k }
1141 /// Returns the set of upstream monomorphizations available for the
1142 /// generic function identified by the given `def_id`. The query makes
1143 /// sure to make a stable selection if the same monomorphization is
1144 /// available in multiple upstream crates.
1146 /// You likely want to call `Instance::upstream_monomorphization()`
1147 /// instead of invoking this query directly.
1148 query upstream_monomorphizations_for(def_id: DefId)
1149 -> Option<&'tcx FxHashMap<SubstsRef<'tcx>, CrateNum>> {
1151 "collecting available upstream monomorphizations for `{}`",
1152 tcx.def_path_str(def_id),
1156 /// Returns the upstream crate that exports drop-glue for the given
1157 /// type (`substs` is expected to be a single-item list containing the
1158 /// type one wants drop-glue for).
1160 /// This is a subset of `upstream_monomorphizations_for` in order to
1161 /// increase dep-tracking granularity. Otherwise adding or removing any
1162 /// type with drop-glue in any upstream crate would invalidate all
1163 /// functions calling drop-glue of an upstream type.
1165 /// You likely want to call `Instance::upstream_monomorphization()`
1166 /// instead of invoking this query directly.
1168 /// NOTE: This query could easily be extended to also support other
1169 /// common functions that have are large set of monomorphizations
1170 /// (like `Clone::clone` for example).
1171 query upstream_drop_glue_for(substs: SubstsRef<'tcx>) -> Option<CrateNum> {
1172 desc { "available upstream drop-glue for `{:?}`", substs }
1175 query foreign_modules(_: CrateNum) -> Lrc<FxHashMap<DefId, ForeignModule>> {
1176 desc { "looking up the foreign modules of a linked crate" }
1179 /// Identifies the entry-point (e.g., the `main` function) for a given
1180 /// crate, returning `None` if there is no entry point (such as for library crates).
1181 query entry_fn(_: CrateNum) -> Option<(LocalDefId, EntryFnType)> {
1182 desc { "looking up the entry function of a crate" }
1184 query plugin_registrar_fn(_: CrateNum) -> Option<DefId> {
1185 desc { "looking up the plugin registrar for a crate" }
1187 query proc_macro_decls_static(_: CrateNum) -> Option<DefId> {
1188 desc { "looking up the derive registrar for a crate" }
1190 query crate_disambiguator(_: CrateNum) -> CrateDisambiguator {
1192 desc { "looking up the disambiguator a crate" }
1194 // The macro which defines `rustc_metadata::provide_extern` depends on this query's name.
1195 // Changing the name should cause a compiler error, but in case that changes, be aware.
1196 query crate_hash(_: CrateNum) -> Svh {
1198 desc { "looking up the hash a crate" }
1200 query crate_host_hash(_: CrateNum) -> Option<Svh> {
1202 desc { "looking up the hash of a host version of a crate" }
1204 query original_crate_name(_: CrateNum) -> Symbol {
1206 desc { "looking up the original name a crate" }
1208 query extra_filename(_: CrateNum) -> String {
1210 desc { "looking up the extra filename for a crate" }
1212 query crate_extern_paths(_: CrateNum) -> Vec<PathBuf> {
1214 desc { "looking up the paths for extern crates" }
1217 /// Given a crate and a trait, look up all impls of that trait in the crate.
1218 /// Return `(impl_id, self_ty)`.
1219 query implementations_of_trait(_: (CrateNum, DefId))
1220 -> &'tcx [(DefId, Option<ty::fast_reject::SimplifiedType>)] {
1221 desc { "looking up implementations of a trait in a crate" }
1224 /// Given a crate, look up all trait impls in that crate.
1225 /// Return `(impl_id, self_ty)`.
1226 query all_trait_implementations(_: CrateNum)
1227 -> &'tcx [(DefId, Option<ty::fast_reject::SimplifiedType>)] {
1228 desc { "looking up all (?) trait implementations" }
1231 query is_dllimport_foreign_item(def_id: DefId) -> bool {
1232 desc { |tcx| "is_dllimport_foreign_item({})", tcx.def_path_str(def_id) }
1234 query is_statically_included_foreign_item(def_id: DefId) -> bool {
1235 desc { |tcx| "is_statically_included_foreign_item({})", tcx.def_path_str(def_id) }
1237 query native_library_kind(def_id: DefId)
1238 -> Option<NativeLibKind> {
1239 desc { |tcx| "native_library_kind({})", tcx.def_path_str(def_id) }
1242 query link_args(_: CrateNum) -> Lrc<Vec<String>> {
1244 desc { "looking up link arguments for a crate" }
1247 /// Lifetime resolution. See `middle::resolve_lifetimes`.
1248 query resolve_lifetimes(_: CrateNum) -> ResolveLifetimes {
1249 storage(ArenaCacheSelector<'tcx>)
1250 desc { "resolving lifetimes" }
1252 query named_region_map(_: LocalDefId) ->
1253 Option<&'tcx FxHashMap<ItemLocalId, Region>> {
1254 desc { "looking up a named region" }
1256 query is_late_bound_map(_: LocalDefId) ->
1257 Option<(LocalDefId, &'tcx FxHashSet<ItemLocalId>)> {
1258 desc { "testing if a region is late bound" }
1260 query object_lifetime_defaults_map(_: LocalDefId)
1261 -> Option<&'tcx FxHashMap<ItemLocalId, Vec<ObjectLifetimeDefault>>> {
1262 desc { "looking up lifetime defaults for a region" }
1265 query visibility(def_id: DefId) -> ty::Visibility {
1267 desc { |tcx| "computing visibility of `{}`", tcx.def_path_str(def_id) }
1270 /// Computes the set of modules from which this type is visibly uninhabited.
1271 /// To check whether a type is uninhabited at all (not just from a given module), you could
1272 /// check whether the forest is empty.
1273 query type_uninhabited_from(
1274 key: ty::ParamEnvAnd<'tcx, Ty<'tcx>>
1275 ) -> ty::inhabitedness::DefIdForest {
1276 desc { "computing the inhabitedness of `{:?}`", key }
1279 query dep_kind(_: CrateNum) -> CrateDepKind {
1281 desc { "fetching what a dependency looks like" }
1283 query crate_name(_: CrateNum) -> Symbol {
1285 desc { "fetching what a crate is named" }
1287 query item_children(def_id: DefId) -> &'tcx [Export<hir::HirId>] {
1288 desc { |tcx| "collecting child items of `{}`", tcx.def_path_str(def_id) }
1290 query extern_mod_stmt_cnum(def_id: LocalDefId) -> Option<CrateNum> {
1291 desc { |tcx| "computing crate imported by `{}`", tcx.def_path_str(def_id.to_def_id()) }
1294 query get_lib_features(_: CrateNum) -> LibFeatures {
1295 storage(ArenaCacheSelector<'tcx>)
1297 desc { "calculating the lib features map" }
1299 query defined_lib_features(_: CrateNum)
1300 -> &'tcx [(Symbol, Option<Symbol>)] {
1301 desc { "calculating the lib features defined in a crate" }
1303 /// Returns the lang items defined in another crate by loading it from metadata.
1304 // FIXME: It is illegal to pass a `CrateNum` other than `LOCAL_CRATE` here, just get rid
1305 // of that argument?
1306 query get_lang_items(_: CrateNum) -> LanguageItems {
1307 storage(ArenaCacheSelector<'tcx>)
1309 desc { "calculating the lang items map" }
1312 /// Returns all diagnostic items defined in all crates.
1313 query all_diagnostic_items(_: CrateNum) -> FxHashMap<Symbol, DefId> {
1314 storage(ArenaCacheSelector<'tcx>)
1316 desc { "calculating the diagnostic items map" }
1319 /// Returns the lang items defined in another crate by loading it from metadata.
1320 query defined_lang_items(_: CrateNum) -> &'tcx [(DefId, usize)] {
1321 desc { "calculating the lang items defined in a crate" }
1324 /// Returns the diagnostic items defined in a crate.
1325 query diagnostic_items(_: CrateNum) -> FxHashMap<Symbol, DefId> {
1326 storage(ArenaCacheSelector<'tcx>)
1327 desc { "calculating the diagnostic items map in a crate" }
1330 query missing_lang_items(_: CrateNum) -> &'tcx [LangItem] {
1331 desc { "calculating the missing lang items in a crate" }
1333 query visible_parent_map(_: CrateNum)
1334 -> DefIdMap<DefId> {
1335 storage(ArenaCacheSelector<'tcx>)
1336 desc { "calculating the visible parent map" }
1338 query trimmed_def_paths(_: CrateNum)
1339 -> FxHashMap<DefId, Symbol> {
1340 storage(ArenaCacheSelector<'tcx>)
1341 desc { "calculating trimmed def paths" }
1343 query missing_extern_crate_item(_: CrateNum) -> bool {
1345 desc { "seeing if we're missing an `extern crate` item for this crate" }
1347 query used_crate_source(_: CrateNum) -> Lrc<CrateSource> {
1349 desc { "looking at the source for a crate" }
1351 query postorder_cnums(_: CrateNum) -> &'tcx [CrateNum] {
1353 desc { "generating a postorder list of CrateNums" }
1356 query upvars_mentioned(def_id: DefId) -> Option<&'tcx FxIndexMap<hir::HirId, hir::Upvar>> {
1357 desc { |tcx| "collecting upvars mentioned in `{}`", tcx.def_path_str(def_id) }
1360 query maybe_unused_trait_import(def_id: LocalDefId) -> bool {
1362 desc { |tcx| "maybe_unused_trait_import for `{}`", tcx.def_path_str(def_id.to_def_id()) }
1364 query maybe_unused_extern_crates(_: CrateNum)
1365 -> &'tcx [(LocalDefId, Span)] {
1367 desc { "looking up all possibly unused extern crates" }
1369 query names_imported_by_glob_use(def_id: LocalDefId)
1370 -> &'tcx FxHashSet<Symbol> {
1372 desc { |tcx| "names_imported_by_glob_use for `{}`", tcx.def_path_str(def_id.to_def_id()) }
1375 query stability_index(_: CrateNum) -> stability::Index<'tcx> {
1376 storage(ArenaCacheSelector<'tcx>)
1378 desc { "calculating the stability index for the local crate" }
1380 query all_crate_nums(_: CrateNum) -> &'tcx [CrateNum] {
1382 desc { "fetching all foreign CrateNum instances" }
1385 /// A vector of every trait accessible in the whole crate
1386 /// (i.e., including those from subcrates). This is used only for
1387 /// error reporting.
1388 query all_traits(_: CrateNum) -> &'tcx [DefId] {
1389 desc { "fetching all foreign and local traits" }
1392 /// The list of symbols exported from the given crate.
1394 /// - All names contained in `exported_symbols(cnum)` are guaranteed to
1395 /// correspond to a publicly visible symbol in `cnum` machine code.
1396 /// - The `exported_symbols` sets of different crates do not intersect.
1397 query exported_symbols(_: CrateNum)
1398 -> &'tcx [(ExportedSymbol<'tcx>, SymbolExportLevel)] {
1399 desc { "exported_symbols" }
1402 query collect_and_partition_mono_items(_: CrateNum)
1403 -> (&'tcx DefIdSet, &'tcx [CodegenUnit<'tcx>]) {
1405 desc { "collect_and_partition_mono_items" }
1407 query is_codegened_item(def_id: DefId) -> bool {
1408 desc { |tcx| "determining whether `{}` needs codegen", tcx.def_path_str(def_id) }
1410 query codegen_unit(_: Symbol) -> &'tcx CodegenUnit<'tcx> {
1411 desc { "codegen_unit" }
1413 query unused_generic_params(key: DefId) -> FiniteBitSet<u32> {
1414 cache_on_disk_if { key.is_local() }
1416 |tcx| "determining which generic parameters are unused by `{}`",
1417 tcx.def_path_str(key)
1420 query backend_optimization_level(_: CrateNum) -> OptLevel {
1421 desc { "optimization level used by backend" }
1424 query output_filenames(_: CrateNum) -> Arc<OutputFilenames> {
1426 desc { "output_filenames" }
1429 /// Do not call this query directly: invoke `normalize` instead.
1430 query normalize_projection_ty(
1431 goal: CanonicalProjectionGoal<'tcx>
1433 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, NormalizationResult<'tcx>>>,
1436 desc { "normalizing `{:?}`", goal }
1439 /// Do not call this query directly: invoke `normalize_erasing_regions` instead.
1440 query normalize_generic_arg_after_erasing_regions(
1441 goal: ParamEnvAnd<'tcx, GenericArg<'tcx>>
1442 ) -> GenericArg<'tcx> {
1443 desc { "normalizing `{}`", goal.value }
1446 query implied_outlives_bounds(
1447 goal: CanonicalTyGoal<'tcx>
1449 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, Vec<OutlivesBound<'tcx>>>>,
1452 desc { "computing implied outlives bounds for `{:?}`", goal }
1455 /// Do not call this query directly: invoke `infcx.at().dropck_outlives()` instead.
1456 query dropck_outlives(
1457 goal: CanonicalTyGoal<'tcx>
1459 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, DropckOutlivesResult<'tcx>>>,
1462 desc { "computing dropck types for `{:?}`", goal }
1465 /// Do not call this query directly: invoke `infcx.predicate_may_hold()` or
1466 /// `infcx.predicate_must_hold()` instead.
1467 query evaluate_obligation(
1468 goal: CanonicalPredicateGoal<'tcx>
1469 ) -> Result<traits::EvaluationResult, traits::OverflowError> {
1470 desc { "evaluating trait selection obligation `{}`", goal.value.value }
1473 query evaluate_goal(
1474 goal: traits::CanonicalChalkEnvironmentAndGoal<'tcx>
1476 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1479 desc { "evaluating trait selection obligation `{}`", goal.value }
1482 query type_implements_trait(
1483 key: (DefId, Ty<'tcx>, SubstsRef<'tcx>, ty::ParamEnv<'tcx>, )
1485 desc { "evaluating `type_implements_trait` `{:?}`", key }
1488 /// Do not call this query directly: part of the `Eq` type-op
1489 query type_op_ascribe_user_type(
1490 goal: CanonicalTypeOpAscribeUserTypeGoal<'tcx>
1492 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1495 desc { "evaluating `type_op_ascribe_user_type` `{:?}`", goal }
1498 /// Do not call this query directly: part of the `Eq` type-op
1500 goal: CanonicalTypeOpEqGoal<'tcx>
1502 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1505 desc { "evaluating `type_op_eq` `{:?}`", goal }
1508 /// Do not call this query directly: part of the `Subtype` type-op
1509 query type_op_subtype(
1510 goal: CanonicalTypeOpSubtypeGoal<'tcx>
1512 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1515 desc { "evaluating `type_op_subtype` `{:?}`", goal }
1518 /// Do not call this query directly: part of the `ProvePredicate` type-op
1519 query type_op_prove_predicate(
1520 goal: CanonicalTypeOpProvePredicateGoal<'tcx>
1522 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1525 desc { "evaluating `type_op_prove_predicate` `{:?}`", goal }
1528 /// Do not call this query directly: part of the `Normalize` type-op
1529 query type_op_normalize_ty(
1530 goal: CanonicalTypeOpNormalizeGoal<'tcx, Ty<'tcx>>
1532 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, Ty<'tcx>>>,
1535 desc { "normalizing `{:?}`", goal }
1538 /// Do not call this query directly: part of the `Normalize` type-op
1539 query type_op_normalize_predicate(
1540 goal: CanonicalTypeOpNormalizeGoal<'tcx, ty::Predicate<'tcx>>
1542 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ty::Predicate<'tcx>>>,
1545 desc { "normalizing `{:?}`", goal }
1548 /// Do not call this query directly: part of the `Normalize` type-op
1549 query type_op_normalize_poly_fn_sig(
1550 goal: CanonicalTypeOpNormalizeGoal<'tcx, ty::PolyFnSig<'tcx>>
1552 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ty::PolyFnSig<'tcx>>>,
1555 desc { "normalizing `{:?}`", goal }
1558 /// Do not call this query directly: part of the `Normalize` type-op
1559 query type_op_normalize_fn_sig(
1560 goal: CanonicalTypeOpNormalizeGoal<'tcx, ty::FnSig<'tcx>>
1562 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ty::FnSig<'tcx>>>,
1565 desc { "normalizing `{:?}`", goal }
1568 query subst_and_check_impossible_predicates(key: (DefId, SubstsRef<'tcx>)) -> bool {
1570 "impossible substituted predicates:`{}`",
1571 tcx.def_path_str(key.0)
1575 query method_autoderef_steps(
1576 goal: CanonicalTyGoal<'tcx>
1577 ) -> MethodAutoderefStepsResult<'tcx> {
1578 desc { "computing autoderef types for `{:?}`", goal }
1581 query supported_target_features(_: CrateNum) -> FxHashMap<String, Option<Symbol>> {
1582 storage(ArenaCacheSelector<'tcx>)
1584 desc { "looking up supported target features" }
1587 /// Get an estimate of the size of an InstanceDef based on its MIR for CGU partitioning.
1588 query instance_def_size_estimate(def: ty::InstanceDef<'tcx>)
1590 desc { |tcx| "estimating size for `{}`", tcx.def_path_str(def.def_id()) }
1593 query features_query(_: CrateNum) -> &'tcx rustc_feature::Features {
1595 desc { "looking up enabled feature gates" }
1598 /// Attempt to resolve the given `DefId` to an `Instance`, for the
1599 /// given generics args (`SubstsRef`), returning one of:
1600 /// * `Ok(Some(instance))` on success
1601 /// * `Ok(None)` when the `SubstsRef` are still too generic,
1602 /// and therefore don't allow finding the final `Instance`
1603 /// * `Err(ErrorReported)` when the `Instance` resolution process
1604 /// couldn't complete due to errors elsewhere - this is distinct
1605 /// from `Ok(None)` to avoid misleading diagnostics when an error
1606 /// has already been/will be emitted, for the original cause
1607 query resolve_instance(
1608 key: ty::ParamEnvAnd<'tcx, (DefId, SubstsRef<'tcx>)>
1609 ) -> Result<Option<ty::Instance<'tcx>>, ErrorReported> {
1610 desc { "resolving instance `{}`", ty::Instance::new(key.value.0, key.value.1) }
1613 query resolve_instance_of_const_arg(
1614 key: ty::ParamEnvAnd<'tcx, (LocalDefId, DefId, SubstsRef<'tcx>)>
1615 ) -> Result<Option<ty::Instance<'tcx>>, ErrorReported> {
1617 "resolving instance of the const argument `{}`",
1618 ty::Instance::new(key.value.0.to_def_id(), key.value.2),
1622 query normalize_opaque_types(key: &'tcx ty::List<ty::Predicate<'tcx>>) -> &'tcx ty::List<ty::Predicate<'tcx>> {
1623 desc { "normalizing opaque types in {:?}", key }