]> git.proxmox.com Git - rustc.git/blame - src/librustc_middle/query/mod.rs
New upstream version 1.45.0+dfsg1
[rustc.git] / src / librustc_middle / query / mod.rs
CommitLineData
74b04a01 1use crate::dep_graph::SerializedDepNodeIndex;
dfeec247 2use crate::mir::interpret::{GlobalId, LitToConstInput};
532ac7d7
XL
3use crate::traits;
4use crate::traits::query::{
dfeec247
XL
5 CanonicalPredicateGoal, CanonicalProjectionGoal, CanonicalTyGoal,
6 CanonicalTypeOpAscribeUserTypeGoal, CanonicalTypeOpEqGoal, CanonicalTypeOpNormalizeGoal,
7 CanonicalTypeOpProvePredicateGoal, CanonicalTypeOpSubtypeGoal,
532ac7d7 8};
dfeec247 9use crate::ty::query::queries;
ba9703b0 10use crate::ty::subst::{GenericArg, SubstsRef};
dfeec247 11use crate::ty::{self, ParamEnvAnd, Ty, TyCtxt};
ba9703b0 12use rustc_hir::def_id::{CrateNum, DefId, LocalDefId};
f9f354fc 13use rustc_query_system::query::QueryDescription;
532ac7d7 14
dfeec247 15use rustc_span::symbol::Symbol;
532ac7d7 16use std::borrow::Cow;
dfeec247
XL
17
18fn describe_as_module(def_id: DefId, tcx: TyCtxt<'_>) -> String {
19 if def_id.is_top_level_module() {
74b04a01 20 "top-level module".to_string()
dfeec247
XL
21 } else {
22 format!("module `{}`", tcx.def_path_str(def_id))
23 }
24}
532ac7d7 25
532ac7d7
XL
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).
31//
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.
37rustc_queries! {
60c5eb7d
XL
38 Other {
39 query trigger_delay_span_bug(key: DefId) -> () {
40 desc { "trigger a delay span bug" }
41 }
42 }
43
532ac7d7 44 Other {
74b04a01
XL
45 // Represents crate as a whole (as distinct from the top-level crate module).
46 // If you call `hir_crate` (e.g., indirectly by calling `tcx.hir().krate()`),
47 // we will have to assume that any change means that you need to be recompiled.
48 // This is because the `hir_crate` query gives you access to all other items.
49 // To avoid this fate, do not call `tcx.hir().krate()`; instead,
50 // prefer wrappers like `tcx.visit_all_items_in_krate()`.
51 query hir_crate(key: CrateNum) -> &'tcx Crate<'tcx> {
52 eval_always
53 no_hash
54 desc { "get the crate HIR" }
55 }
56
ba9703b0
XL
57 // The indexed HIR. This can be conveniently accessed by `tcx.hir()`.
58 // Avoid calling this query directly.
59 query index_hir(_: CrateNum) -> &'tcx map::IndexedHir<'tcx> {
60 eval_always
61 no_hash
62 desc { "index HIR" }
63 }
64
65 // The items in a module.
66 //
67 // This can be conveniently accessed by `tcx.hir().visit_item_likes_in_module`.
68 // Avoid calling this query directly.
69 query hir_module_items(key: LocalDefId) -> &'tcx hir::ModuleItems {
70 eval_always
71 desc { |tcx| "HIR module items in `{}`", tcx.def_path_str(key.to_def_id()) }
72 }
73
74 // Gives access to the HIR node for the HIR owner `key`.
75 //
76 // This can be conveniently accessed by methods on `tcx.hir()`.
77 // Avoid calling this query directly.
78 query hir_owner(key: LocalDefId) -> Option<&'tcx crate::hir::Owner<'tcx>> {
79 eval_always
80 desc { |tcx| "HIR owner of `{}`", tcx.def_path_str(key.to_def_id()) }
81 }
82
83 // Gives access to the HIR nodes and bodies inside the HIR owner `key`.
84 //
85 // This can be conveniently accessed by methods on `tcx.hir()`.
86 // Avoid calling this query directly.
87 query hir_owner_nodes(key: LocalDefId) -> Option<&'tcx crate::hir::OwnerNodes<'tcx>> {
88 eval_always
89 desc { |tcx| "HIR owner items in `{}`", tcx.def_path_str(key.to_def_id()) }
90 }
91
532ac7d7
XL
92 /// Records the type of every item.
93 query type_of(key: DefId) -> Ty<'tcx> {
f9f354fc 94 desc { |tcx| "computing type of `{}`", tcx.def_path_str(key) }
dc9dc135 95 cache_on_disk_if { key.is_local() }
532ac7d7
XL
96 }
97
74b04a01
XL
98 query analysis(key: CrateNum) -> Result<(), ErrorReported> {
99 eval_always
100 desc { "running analysis passes on this crate" }
101 }
102
532ac7d7
XL
103 /// Maps from the `DefId` of an item (trait/struct/enum/fn) to its
104 /// associated generics.
f9f354fc
XL
105 query generics_of(key: DefId) -> ty::Generics {
106 desc { |tcx| "computing generics of `{}`", tcx.def_path_str(key) }
107 storage(ArenaCacheSelector<'tcx>)
dc9dc135 108 cache_on_disk_if { key.is_local() }
532ac7d7
XL
109 load_cached(tcx, id) {
110 let generics: Option<ty::Generics> = tcx.queries.on_disk_cache
111 .try_load_query_result(tcx, id);
f9f354fc 112 generics
532ac7d7
XL
113 }
114 }
115
116 /// Maps from the `DefId` of an item (trait/struct/enum/fn) to the
117 /// predicates (where-clauses) that must be proven true in order
118 /// to reference it. This is almost always the "predicates query"
119 /// that you want.
120 ///
121 /// `predicates_of` builds on `predicates_defined_on` -- in fact,
122 /// it is almost always the same as that query, except for the
123 /// case of traits. For traits, `predicates_of` contains
124 /// an additional `Self: Trait<...>` predicate that users don't
125 /// actually write. This reflects the fact that to invoke the
126 /// trait (e.g., via `Default::default`) you must supply types
127 /// that actually implement the trait. (However, this extra
128 /// predicate gets in the way of some checks, which are intended
129 /// to operate over only the actual where-clauses written by the
130 /// user.)
e74abb32 131 query predicates_of(key: DefId) -> ty::GenericPredicates<'tcx> {
f9f354fc 132 desc { |tcx| "computing predicates of `{}`", tcx.def_path_str(key) }
dc9dc135
XL
133 cache_on_disk_if { key.is_local() }
134 }
532ac7d7 135
f9f354fc 136 query native_libraries(_: CrateNum) -> Lrc<Vec<NativeLib>> {
532ac7d7
XL
137 desc { "looking up the native libraries of a linked crate" }
138 }
139
f9f354fc
XL
140 query lint_levels(_: CrateNum) -> LintLevelMap {
141 storage(ArenaCacheSelector<'tcx>)
532ac7d7
XL
142 eval_always
143 desc { "computing the lint levels for items in this crate" }
144 }
74b04a01 145
ba9703b0 146 query parent_module_from_def_id(key: LocalDefId) -> LocalDefId {
74b04a01 147 eval_always
ba9703b0 148 desc { |tcx| "parent module of `{}`", tcx.def_path_str(key.to_def_id()) }
74b04a01 149 }
532ac7d7
XL
150 }
151
152 Codegen {
153 query is_panic_runtime(_: CrateNum) -> bool {
154 fatal_cycle
155 desc { "checking if the crate is_panic_runtime" }
156 }
157 }
158
159 Codegen {
160 /// Set of all the `DefId`s in this crate that have MIR associated with
161 /// them. This includes all the body owners, but also things like struct
162 /// constructors.
f9f354fc
XL
163 query mir_keys(_: CrateNum) -> FxHashSet<LocalDefId> {
164 storage(ArenaCacheSelector<'tcx>)
532ac7d7
XL
165 desc { "getting a list of all mir_keys" }
166 }
167
dc9dc135 168 /// Maps DefId's that have an associated `mir::Body` to the result
60c5eb7d
XL
169 /// of the MIR const-checking pass. This is the set of qualifs in
170 /// the final value of a `const`.
171 query mir_const_qualif(key: DefId) -> mir::ConstQualifs {
e74abb32 172 desc { |tcx| "const checking `{}`", tcx.def_path_str(key) }
dc9dc135 173 cache_on_disk_if { key.is_local() }
532ac7d7
XL
174 }
175
176 /// Fetch the MIR for a given `DefId` right after it's built - this includes
177 /// unreachable code.
f9f354fc
XL
178 query mir_built(key: LocalDefId) -> Steal<mir::Body<'tcx>> {
179 storage(ArenaCacheSelector<'tcx>)
180 desc { |tcx| "building MIR for `{}`", tcx.def_path_str(key.to_def_id()) }
74b04a01 181 }
532ac7d7
XL
182
183 /// Fetch the MIR for a given `DefId` up till the point where it is
f9f354fc 184 /// ready for const qualification.
532ac7d7
XL
185 ///
186 /// See the README for the `mir` module for details.
f9f354fc
XL
187 query mir_const(key: DefId) -> Steal<mir::Body<'tcx>> {
188 desc { |tcx| "processing MIR for `{}`", tcx.def_path_str(key) }
189 storage(ArenaCacheSelector<'tcx>)
532ac7d7
XL
190 no_hash
191 }
192
f9f354fc 193 query mir_validated(key: LocalDefId) ->
e1599b0c 194 (
f9f354fc
XL
195 Steal<mir::Body<'tcx>>,
196 Steal<IndexVec<mir::Promoted, mir::Body<'tcx>>>
e1599b0c 197 ) {
f9f354fc 198 storage(ArenaCacheSelector<'tcx>)
532ac7d7 199 no_hash
f9f354fc 200 desc { |tcx| "processing `{}`", tcx.def_path_str(key.to_def_id()) }
532ac7d7
XL
201 }
202
203 /// MIR after our optimization passes have run. This is MIR that is ready
204 /// for codegen. This is also the only query that can fetch non-local MIR, at present.
f9f354fc
XL
205 query optimized_mir(key: DefId) -> mir::Body<'tcx> {
206 desc { |tcx| "optimizing MIR for `{}`", tcx.def_path_str(key) }
207 storage(ArenaCacheSelector<'tcx>)
dc9dc135 208 cache_on_disk_if { key.is_local() }
532ac7d7 209 }
416331ca 210
f9f354fc
XL
211 query promoted_mir(key: DefId) -> IndexVec<mir::Promoted, mir::Body<'tcx>> {
212 desc { |tcx| "optimizing promoted MIR for `{}`", tcx.def_path_str(key) }
213 storage(ArenaCacheSelector<'tcx>)
e1599b0c 214 cache_on_disk_if { key.is_local() }
e1599b0c 215 }
532ac7d7
XL
216 }
217
218 TypeChecking {
219 // Erases regions from `ty` to yield a new type.
220 // Normally you would just use `tcx.erase_regions(&value)`,
221 // however, which uses this query as a kind of cache.
222 query erase_regions_ty(ty: Ty<'tcx>) -> Ty<'tcx> {
223 // This query is not expected to have input -- as a result, it
224 // is not a good candidates for "replay" because it is essentially a
225 // pure function of its input (and hence the expectation is that
226 // no caller would be green **apart** from just these
227 // queries). Making it anonymous avoids hashing the result, which
228 // may save a bit of time.
229 anon
532ac7d7
XL
230 desc { "erasing regions from `{:?}`", ty }
231 }
532ac7d7
XL
232 }
233
234 Linking {
f9f354fc
XL
235 query wasm_import_module_map(_: CrateNum) -> FxHashMap<DefId, String> {
236 storage(ArenaCacheSelector<'tcx>)
532ac7d7
XL
237 desc { "wasm import module map" }
238 }
239 }
240
241 Other {
242 /// Maps from the `DefId` of an item (trait/struct/enum/fn) to the
243 /// predicates (where-clauses) directly defined on it. This is
244 /// equal to the `explicit_predicates_of` predicates plus the
245 /// `inferred_outlives_of` predicates.
f9f354fc
XL
246 query predicates_defined_on(key: DefId) -> ty::GenericPredicates<'tcx> {
247 desc { |tcx| "computing predicates of `{}`", tcx.def_path_str(key) }
248 }
532ac7d7 249
dc9dc135 250 /// Returns the predicates written explicitly by the user.
f9f354fc
XL
251 query explicit_predicates_of(key: DefId) -> ty::GenericPredicates<'tcx> {
252 desc { |tcx| "computing explicit predicates of `{}`", tcx.def_path_str(key) }
253 }
532ac7d7
XL
254
255 /// Returns the inferred outlives predicates (e.g., for `struct
256 /// Foo<'a, T> { x: &'a T }`, this would return `T: 'a`).
f9f354fc
XL
257 query inferred_outlives_of(key: DefId) -> &'tcx [(ty::Predicate<'tcx>, Span)] {
258 desc { |tcx| "computing inferred outlives predicates of `{}`", tcx.def_path_str(key) }
259 }
532ac7d7
XL
260
261 /// Maps from the `DefId` of a trait to the list of
262 /// super-predicates. This is a subset of the full list of
263 /// predicates. We store these in a separate map because we must
264 /// evaluate them even during type conversion, often before the
265 /// full predicates are available (note that supertraits have
266 /// additional acyclicity requirements).
e74abb32 267 query super_predicates_of(key: DefId) -> ty::GenericPredicates<'tcx> {
532ac7d7
XL
268 desc { |tcx| "computing the supertraits of `{}`", tcx.def_path_str(key) }
269 }
270
271 /// To avoid cycles within the predicates of a single item we compute
272 /// per-type-parameter predicates for resolving `T::AssocTy`.
f9f354fc 273 query type_param_predicates(key: (DefId, LocalDefId)) -> ty::GenericPredicates<'tcx> {
532ac7d7 274 desc { |tcx| "computing the bounds for type parameter `{}`", {
f9f354fc 275 let id = tcx.hir().as_local_hir_id(key.1);
532ac7d7
XL
276 tcx.hir().ty_param_name(id)
277 }}
278 }
279
f9f354fc
XL
280 query trait_def(key: DefId) -> ty::TraitDef {
281 desc { |tcx| "computing trait definition for `{}`", tcx.def_path_str(key) }
282 storage(ArenaCacheSelector<'tcx>)
283 }
284 query adt_def(key: DefId) -> &'tcx ty::AdtDef {
285 desc { |tcx| "computing ADT definition for `{}`", tcx.def_path_str(key) }
286 }
287 query adt_destructor(key: DefId) -> Option<ty::Destructor> {
288 desc { |tcx| "computing `Drop` impl for `{}`", tcx.def_path_str(key) }
289 }
532ac7d7
XL
290
291 // The cycle error here should be reported as an error by `check_representable`.
292 // We consider the type as Sized in the meanwhile to avoid
293 // further errors (done in impl Value for AdtSizedConstraint).
294 // Use `cycle_delay_bug` to delay the cycle error here to be emitted later
295 // in case we accidentally otherwise don't emit an error.
296 query adt_sized_constraint(
f9f354fc 297 key: DefId
532ac7d7 298 ) -> AdtSizedConstraint<'tcx> {
f9f354fc 299 desc { |tcx| "computing `Sized` constraints for `{}`", tcx.def_path_str(key) }
532ac7d7
XL
300 cycle_delay_bug
301 }
302
303 query adt_dtorck_constraint(
f9f354fc
XL
304 key: DefId
305 ) -> Result<DtorckConstraint<'tcx>, NoSolution> {
306 desc { |tcx| "computing drop-check constraints for `{}`", tcx.def_path_str(key) }
307 }
532ac7d7 308
dc9dc135
XL
309 /// Returns `true` if this is a const fn, use the `is_const_fn` to know whether your crate
310 /// actually sees it as const fn (e.g., the const-fn-ness might be unstable and you might
311 /// not have the feature gate active).
532ac7d7
XL
312 ///
313 /// **Do not call this function manually.** It is only meant to cache the base data for the
314 /// `is_const_fn` function.
315 query is_const_fn_raw(key: DefId) -> bool {
316 desc { |tcx| "checking if item is const fn: `{}`", tcx.def_path_str(key) }
317 }
318
74b04a01
XL
319 /// Returns `true` if this is a const `impl`. **Do not call this function manually.**
320 ///
321 /// This query caches the base data for the `is_const_impl` helper function, which also
322 /// takes into account stability attributes (e.g., `#[rustc_const_unstable]`).
323 query is_const_impl_raw(key: DefId) -> bool {
324 desc { |tcx| "checking if item is const impl: `{}`", tcx.def_path_str(key) }
325 }
326
e1599b0c
XL
327 query asyncness(key: DefId) -> hir::IsAsync {
328 desc { |tcx| "checking if the function is async: `{}`", tcx.def_path_str(key) }
329 }
330
dc9dc135 331 /// Returns `true` if calls to the function may be promoted.
532ac7d7
XL
332 ///
333 /// This is either because the function is e.g., a tuple-struct or tuple-variant
334 /// constructor, or because it has the `#[rustc_promotable]` attribute. The attribute should
335 /// be removed in the future in favour of some form of check which figures out whether the
336 /// function does not inspect the bits of any of its arguments (so is essentially just a
337 /// constructor function).
f9f354fc
XL
338 query is_promotable_const_fn(key: DefId) -> bool {
339 desc { |tcx| "checking if item is promotable: `{}`", tcx.def_path_str(key) }
340 }
532ac7d7 341
f9f354fc
XL
342 query const_fn_is_allowed_fn_ptr(key: DefId) -> bool {
343 desc { |tcx| "checking if const fn allows `fn()` types: `{}`", tcx.def_path_str(key) }
344 }
48663c56 345
dc9dc135 346 /// Returns `true` if this is a foreign item (i.e., linked via `extern { ... }`).
f9f354fc
XL
347 query is_foreign_item(key: DefId) -> bool {
348 desc { |tcx| "checking if `{}` is a foreign item", tcx.def_path_str(key) }
349 }
532ac7d7 350
48663c56 351 /// Returns `Some(mutability)` if the node pointed to by `def_id` is a static item.
f9f354fc
XL
352 query static_mutability(def_id: DefId) -> Option<hir::Mutability> {
353 desc { |tcx| "looking up static mutability of `{}`", tcx.def_path_str(def_id) }
354 }
48663c56 355
74b04a01 356 /// Returns `Some(generator_kind)` if the node pointed to by `def_id` is a generator.
f9f354fc
XL
357 query generator_kind(def_id: DefId) -> Option<hir::GeneratorKind> {
358 desc { |tcx| "looking up generator kind of `{}`", tcx.def_path_str(def_id) }
359 }
74b04a01 360
dc9dc135 361 /// Gets a map with the variance of every item; use `item_variance` instead.
f9f354fc
XL
362 query crate_variances(_: CrateNum) -> ty::CrateVariancesMap<'tcx> {
363 storage(ArenaCacheSelector<'tcx>)
532ac7d7
XL
364 desc { "computing the variances for items in this crate" }
365 }
366
dc9dc135 367 /// Maps from the `DefId` of a type or region parameter to its (inferred) variance.
f9f354fc
XL
368 query variances_of(def_id: DefId) -> &'tcx [ty::Variance] {
369 desc { |tcx| "computing the variances of `{}`", tcx.def_path_str(def_id) }
370 }
532ac7d7
XL
371 }
372
373 TypeChecking {
dc9dc135 374 /// Maps from thee `DefId` of a type to its (inferred) outlives.
532ac7d7 375 query inferred_outlives_crate(_: CrateNum)
f9f354fc
XL
376 -> ty::CratePredicatesMap<'tcx> {
377 storage(ArenaCacheSelector<'tcx>)
532ac7d7
XL
378 desc { "computing the inferred outlives predicates for items in this crate" }
379 }
380 }
381
382 Other {
dc9dc135 383 /// Maps from an impl/trait `DefId to a list of the `DefId`s of its items.
f9f354fc
XL
384 query associated_item_def_ids(key: DefId) -> &'tcx [DefId] {
385 desc { |tcx| "collecting associated items of `{}`", tcx.def_path_str(key) }
386 }
532ac7d7 387
dc9dc135 388 /// Maps from a trait item to the trait item "descriptor".
f9f354fc
XL
389 query associated_item(key: DefId) -> ty::AssocItem {
390 desc { |tcx| "computing associated item data for `{}`", tcx.def_path_str(key) }
391 storage(ArenaCacheSelector<'tcx>)
392 }
532ac7d7 393
74b04a01 394 /// Collects the associated items defined on a trait or impl.
f9f354fc
XL
395 query associated_items(key: DefId) -> ty::AssociatedItems<'tcx> {
396 storage(ArenaCacheSelector<'tcx>)
74b04a01
XL
397 desc { |tcx| "collecting associated items of {}", tcx.def_path_str(key) }
398 }
399
f9f354fc
XL
400 query impl_trait_ref(key: DefId) -> Option<ty::TraitRef<'tcx>> {
401 desc { |tcx| "computing trait implemented by `{}`", tcx.def_path_str(key) }
402 }
403 query impl_polarity(key: DefId) -> ty::ImplPolarity {
404 desc { |tcx| "computing implementation polarity of `{}`", tcx.def_path_str(key) }
405 }
532ac7d7 406
f9f354fc
XL
407 query issue33140_self_ty(key: DefId) -> Option<ty::Ty<'tcx>> {
408 desc { |tcx| "computing Self type wrt issue #33140 `{}`", tcx.def_path_str(key) }
409 }
532ac7d7
XL
410 }
411
412 TypeChecking {
dc9dc135 413 /// Maps a `DefId` of a type to a list of its inherent impls.
532ac7d7
XL
414 /// Contains implementations of methods that are inherent to a type.
415 /// Methods in these implementations don't need to be exported.
f9f354fc
XL
416 query inherent_impls(key: DefId) -> &'tcx [DefId] {
417 desc { |tcx| "collecting inherent impls for `{}`", tcx.def_path_str(key) }
532ac7d7
XL
418 eval_always
419 }
420 }
421
422 TypeChecking {
423 /// The result of unsafety-checking this `DefId`.
f9f354fc
XL
424 query unsafety_check_result(key: LocalDefId) -> mir::UnsafetyCheckResult {
425 desc { |tcx| "unsafety-checking `{}`", tcx.def_path_str(key.to_def_id()) }
426 cache_on_disk_if { true }
427 storage(ArenaCacheSelector<'tcx>)
dc9dc135 428 }
532ac7d7 429
f9f354fc
XL
430 /// HACK: when evaluated, this reports a "unsafe derive on repr(packed)" error.
431 ///
432 /// Unsafety checking is executed for each method separately, but we only want
433 /// to emit this error once per derive. As there are some impls with multiple
434 /// methods, we use a query for deduplication.
435 query unsafe_derive_on_repr_packed(key: LocalDefId) -> () {
436 desc { |tcx| "processing `{}`", tcx.def_path_str(key.to_def_id()) }
437 }
532ac7d7 438
f9f354fc
XL
439 /// The signature of functions.
440 query fn_sig(key: DefId) -> ty::PolyFnSig<'tcx> {
441 desc { |tcx| "computing function signature of `{}`", tcx.def_path_str(key) }
442 }
532ac7d7
XL
443 }
444
445 Other {
f9f354fc
XL
446 query lint_mod(key: LocalDefId) -> () {
447 desc { |tcx| "linting {}", describe_as_module(key.to_def_id(), tcx) }
532ac7d7
XL
448 }
449
dc9dc135 450 /// Checks the attributes in the module.
532ac7d7 451 query check_mod_attrs(key: DefId) -> () {
dfeec247 452 desc { |tcx| "checking attributes in {}", describe_as_module(key, tcx) }
532ac7d7
XL
453 }
454
455 query check_mod_unstable_api_usage(key: DefId) -> () {
dfeec247 456 desc { |tcx| "checking for unstable API usage in {}", describe_as_module(key, tcx) }
532ac7d7
XL
457 }
458
60c5eb7d
XL
459 /// Checks the const bodies in the module for illegal operations (e.g. `if` or `loop`).
460 query check_mod_const_bodies(key: DefId) -> () {
dfeec247 461 desc { |tcx| "checking consts in {}", describe_as_module(key, tcx) }
60c5eb7d
XL
462 }
463
dc9dc135 464 /// Checks the loops in the module.
532ac7d7 465 query check_mod_loops(key: DefId) -> () {
dfeec247 466 desc { |tcx| "checking loops in {}", describe_as_module(key, tcx) }
532ac7d7
XL
467 }
468
469 query check_mod_item_types(key: DefId) -> () {
dfeec247 470 desc { |tcx| "checking item types in {}", describe_as_module(key, tcx) }
532ac7d7
XL
471 }
472
f9f354fc
XL
473 query check_mod_privacy(key: LocalDefId) -> () {
474 desc { |tcx| "checking privacy in {}", describe_as_module(key.to_def_id(), tcx) }
532ac7d7
XL
475 }
476
477 query check_mod_intrinsics(key: DefId) -> () {
dfeec247 478 desc { |tcx| "checking intrinsics in {}", describe_as_module(key, tcx) }
532ac7d7
XL
479 }
480
481 query check_mod_liveness(key: DefId) -> () {
dfeec247 482 desc { |tcx| "checking liveness of variables in {}", describe_as_module(key, tcx) }
532ac7d7
XL
483 }
484
485 query check_mod_impl_wf(key: DefId) -> () {
dfeec247 486 desc { |tcx| "checking that impls are well-formed in {}", describe_as_module(key, tcx) }
532ac7d7
XL
487 }
488
489 query collect_mod_item_types(key: DefId) -> () {
dfeec247 490 desc { |tcx| "collecting item types in {}", describe_as_module(key, tcx) }
532ac7d7
XL
491 }
492
dc9dc135 493 /// Caches `CoerceUnsized` kinds for impls on custom types.
f9f354fc
XL
494 query coerce_unsized_info(key: DefId)
495 -> ty::adjustment::CoerceUnsizedInfo {
496 desc { |tcx| "computing CoerceUnsized info for `{}`", tcx.def_path_str(key) }
497 }
532ac7d7
XL
498 }
499
500 TypeChecking {
501 query typeck_item_bodies(_: CrateNum) -> () {
502 desc { "type-checking all item bodies" }
503 }
504
f9f354fc
XL
505 query typeck_tables_of(key: LocalDefId) -> &'tcx ty::TypeckTables<'tcx> {
506 desc { |tcx| "type-checking `{}`", tcx.def_path_str(key.to_def_id()) }
507 cache_on_disk_if { true }
532ac7d7 508 }
f9f354fc
XL
509 query diagnostic_only_typeck_tables_of(key: LocalDefId) -> &'tcx ty::TypeckTables<'tcx> {
510 desc { |tcx| "type-checking `{}`", tcx.def_path_str(key.to_def_id()) }
511 cache_on_disk_if { true }
dfeec247
XL
512 load_cached(tcx, id) {
513 let typeck_tables: Option<ty::TypeckTables<'tcx>> = tcx
514 .queries.on_disk_cache
515 .try_load_query_result(tcx, id);
516
f9f354fc 517 typeck_tables.map(|x| &*tcx.arena.alloc(x))
dfeec247
XL
518 }
519 }
532ac7d7
XL
520 }
521
522 Other {
f9f354fc
XL
523 query used_trait_imports(key: LocalDefId) -> &'tcx DefIdSet {
524 desc { |tcx| "used_trait_imports `{}`", tcx.def_path_str(key.to_def_id()) }
525 cache_on_disk_if { true }
dc9dc135 526 }
532ac7d7
XL
527 }
528
529 TypeChecking {
f9f354fc
XL
530 query has_typeck_tables(def_id: DefId) -> bool {
531 desc { |tcx| "checking whether `{}` has a body", tcx.def_path_str(def_id) }
532 }
532ac7d7
XL
533
534 query coherent_trait(def_id: DefId) -> () {
535 desc { |tcx| "coherence checking all impls of trait `{}`", tcx.def_path_str(def_id) }
536 }
537 }
538
539 BorrowChecking {
dc9dc135 540 /// Borrow-checks the function body. If this is a closure, returns
532ac7d7 541 /// additional requirements that the closure's creator must verify.
f9f354fc
XL
542 query mir_borrowck(key: LocalDefId) -> mir::BorrowCheckResult<'tcx> {
543 storage(ArenaCacheSelector<'tcx>)
544 desc { |tcx| "borrow-checking `{}`", tcx.def_path_str(key.to_def_id()) }
74b04a01 545 cache_on_disk_if(tcx, opt_result) {
f9f354fc
XL
546 tcx.is_closure(key.to_def_id())
547 || opt_result.map_or(false, |r| !r.concrete_opaque_types.is_empty())
74b04a01 548 }
dc9dc135 549 }
532ac7d7
XL
550 }
551
552 TypeChecking {
553 /// Gets a complete map from all types to their inherent impls.
554 /// Not meant to be used directly outside of coherence.
555 /// (Defined only for `LOCAL_CRATE`.)
556 query crate_inherent_impls(k: CrateNum)
f9f354fc
XL
557 -> CrateInherentImpls {
558 storage(ArenaCacheSelector<'tcx>)
532ac7d7
XL
559 eval_always
560 desc { "all inherent impls defined in crate `{:?}`", k }
561 }
562
563 /// Checks all types in the crate for overlap in their inherent impls. Reports errors.
564 /// Not meant to be used directly outside of coherence.
565 /// (Defined only for `LOCAL_CRATE`.)
566 query crate_inherent_impls_overlap_check(_: CrateNum)
567 -> () {
568 eval_always
569 desc { "check for overlap between inherent impls defined in this crate" }
570 }
571 }
572
573 Other {
dc9dc135 574 /// Evaluates a constant without running sanity checks.
532ac7d7
XL
575 ///
576 /// **Do not use this** outside const eval. Const eval uses this to break query cycles
577 /// during validation. Please add a comment to every use site explaining why using
dfeec247
XL
578 /// `const_eval_validated` isn't sufficient. The returned constant also isn't in a suitable
579 /// form to be used outside of const eval.
532ac7d7
XL
580 query const_eval_raw(key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>)
581 -> ConstEvalRawResult<'tcx> {
532ac7d7
XL
582 desc { |tcx|
583 "const-evaluating `{}`",
584 tcx.def_path_str(key.value.instance.def.def_id())
585 }
532ac7d7
XL
586 }
587
588 /// Results of evaluating const items or constants embedded in
589 /// other items (such as enum variant explicit discriminants).
dfeec247
XL
590 ///
591 /// In contrast to `const_eval_raw` this performs some validation on the constant, and
592 /// returns a proper constant that is usable by the rest of the compiler.
593 ///
594 /// **Do not use this** directly, use one of the following wrappers: `tcx.const_eval_poly`,
74b04a01 595 /// `tcx.const_eval_resolve`, `tcx.const_eval_instance`, or `tcx.const_eval_global_id`.
dfeec247 596 query const_eval_validated(key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>)
532ac7d7 597 -> ConstEvalResult<'tcx> {
532ac7d7
XL
598 desc { |tcx|
599 "const-evaluating + checking `{}`",
600 tcx.def_path_str(key.value.instance.def.def_id())
601 }
dc9dc135
XL
602 cache_on_disk_if(_, opt_result) {
603 // Only store results without errors
604 opt_result.map_or(true, |r| r.is_ok())
532ac7d7
XL
605 }
606 }
dc9dc135 607
ba9703b0 608 /// Destructure a constant ADT or array into its variant index and its
dfeec247
XL
609 /// field values.
610 query destructure_const(
611 key: ty::ParamEnvAnd<'tcx, &'tcx ty::Const<'tcx>>
612 ) -> mir::DestructuredConst<'tcx> {
dfeec247
XL
613 desc { "destructure constant" }
614 }
615
74b04a01 616 query const_caller_location(key: (rustc_span::Symbol, u32, u32)) -> ConstValue<'tcx> {
e74abb32
XL
617 desc { "get a &core::panic::Location referring to a span" }
618 }
dfeec247
XL
619
620 query lit_to_const(
621 key: LitToConstInput<'tcx>
622 ) -> Result<&'tcx ty::Const<'tcx>, LitToConstError> {
dfeec247
XL
623 desc { "converting literal to const" }
624 }
532ac7d7
XL
625 }
626
627 TypeChecking {
e74abb32 628 query check_match(key: DefId) {
f9f354fc 629 desc { |tcx| "match-checking `{}`", tcx.def_path_str(key) }
dc9dc135
XL
630 cache_on_disk_if { key.is_local() }
631 }
532ac7d7
XL
632
633 /// Performs part of the privacy check and computes "access levels".
dc9dc135 634 query privacy_access_levels(_: CrateNum) -> &'tcx AccessLevels {
532ac7d7
XL
635 eval_always
636 desc { "privacy access levels" }
637 }
638 query check_private_in_public(_: CrateNum) -> () {
639 eval_always
640 desc { "checking for private elements in public interfaces" }
641 }
642 }
643
644 Other {
ba9703b0 645 query reachable_set(_: CrateNum) -> &'tcx HirIdSet {
532ac7d7
XL
646 desc { "reachability" }
647 }
648
649 /// Per-body `region::ScopeTree`. The `DefId` should be the owner `DefId` for the body;
650 /// in the case of closures, this will be redirected to the enclosing function.
f9f354fc
XL
651 query region_scope_tree(def_id: DefId) -> &'tcx region::ScopeTree {
652 desc { |tcx| "computing drop scopes for `{}`", tcx.def_path_str(def_id) }
653 }
532ac7d7 654
f9f354fc
XL
655 query mir_shims(key: ty::InstanceDef<'tcx>) -> mir::Body<'tcx> {
656 storage(ArenaCacheSelector<'tcx>)
532ac7d7
XL
657 desc { |tcx| "generating MIR shim for `{}`", tcx.def_path_str(key.def_id()) }
658 }
659
dfeec247
XL
660 /// The `symbol_name` query provides the symbol name for calling a
661 /// given instance from the local crate. In particular, it will also
662 /// look up the correct symbol name of instances from upstream crates.
532ac7d7 663 query symbol_name(key: ty::Instance<'tcx>) -> ty::SymbolName {
532ac7d7 664 desc { "computing the symbol for `{}`", key }
dc9dc135 665 cache_on_disk_if { true }
532ac7d7
XL
666 }
667
f9f354fc
XL
668 query def_kind(def_id: DefId) -> DefKind {
669 desc { |tcx| "looking up definition kind of `{}`", tcx.def_path_str(def_id) }
670 }
671 query def_span(def_id: DefId) -> Span {
672 desc { |tcx| "looking up span for `{}`", tcx.def_path_str(def_id) }
532ac7d7
XL
673 // FIXME(mw): DefSpans are not really inputs since they are derived from
674 // HIR. But at the moment HIR hashing still contains some hacks that allow
675 // to make type debuginfo to be source location independent. Declaring
676 // DefSpan an input makes sure that changes to these are always detected
677 // regardless of HIR hashing.
678 eval_always
679 }
f9f354fc
XL
680 query lookup_stability(def_id: DefId) -> Option<&'tcx attr::Stability> {
681 desc { |tcx| "looking up stability of `{}`", tcx.def_path_str(def_id) }
682 }
683 query lookup_const_stability(def_id: DefId) -> Option<&'tcx attr::ConstStability> {
684 desc { |tcx| "looking up const stability of `{}`", tcx.def_path_str(def_id) }
685 }
686 query lookup_deprecation_entry(def_id: DefId) -> Option<DeprecationEntry> {
687 desc { |tcx| "checking whether `{}` is deprecated", tcx.def_path_str(def_id) }
688 }
689 query item_attrs(def_id: DefId) -> &'tcx [ast::Attribute] {
690 desc { |tcx| "collecting attributes of `{}`", tcx.def_path_str(def_id) }
691 }
532ac7d7
XL
692 }
693
694 Codegen {
f9f354fc
XL
695 query codegen_fn_attrs(def_id: DefId) -> CodegenFnAttrs {
696 desc { |tcx| "computing codegen attributes of `{}`", tcx.def_path_str(def_id) }
697 storage(ArenaCacheSelector<'tcx>)
dc9dc135
XL
698 cache_on_disk_if { true }
699 }
532ac7d7
XL
700 }
701
702 Other {
f9f354fc
XL
703 query fn_arg_names(def_id: DefId) -> &'tcx [Symbol] {
704 desc { |tcx| "looking up function parameter names for `{}`", tcx.def_path_str(def_id) }
705 }
532ac7d7
XL
706 /// Gets the rendered value of the specified constant or associated constant.
707 /// Used by rustdoc.
f9f354fc
XL
708 query rendered_const(def_id: DefId) -> String {
709 desc { |tcx| "rendering constant intializer of `{}`", tcx.def_path_str(def_id) }
710 }
711 query impl_parent(def_id: DefId) -> Option<DefId> {
712 desc { |tcx| "computing specialization parent impl of `{}`", tcx.def_path_str(def_id) }
713 }
532ac7d7
XL
714 }
715
716 TypeChecking {
f9f354fc
XL
717 query trait_of_item(def_id: DefId) -> Option<DefId> {
718 desc { |tcx| "finding trait defining `{}`", tcx.def_path_str(def_id) }
719 }
532ac7d7
XL
720 }
721
722 Codegen {
723 query is_mir_available(key: DefId) -> bool {
724 desc { |tcx| "checking if item has mir available: `{}`", tcx.def_path_str(key) }
725 }
726 }
727
728 Other {
729 query vtable_methods(key: ty::PolyTraitRef<'tcx>)
48663c56 730 -> &'tcx [Option<(DefId, SubstsRef<'tcx>)>] {
532ac7d7
XL
731 desc { |tcx| "finding all methods for trait {}", tcx.def_path_str(key.def_id()) }
732 }
733 }
734
735 Codegen {
736 query codegen_fulfill_obligation(
737 key: (ty::ParamEnv<'tcx>, ty::PolyTraitRef<'tcx>)
f9f354fc 738 ) -> Result<Vtable<'tcx, ()>, ErrorReported> {
dc9dc135 739 cache_on_disk_if { true }
532ac7d7
XL
740 desc { |tcx|
741 "checking if `{}` fulfills its obligations",
742 tcx.def_path_str(key.1.def_id())
743 }
744 }
745 }
746
747 TypeChecking {
ba9703b0
XL
748 query all_local_trait_impls(key: CrateNum) -> &'tcx BTreeMap<DefId, Vec<hir::HirId>> {
749 desc { "local trait impls" }
750 }
f9f354fc
XL
751 query trait_impls_of(key: DefId) -> ty::trait_def::TraitImpls {
752 storage(ArenaCacheSelector<'tcx>)
532ac7d7
XL
753 desc { |tcx| "trait impls of `{}`", tcx.def_path_str(key) }
754 }
f9f354fc
XL
755 query specialization_graph_of(key: DefId) -> specialization_graph::Graph {
756 storage(ArenaCacheSelector<'tcx>)
74b04a01 757 desc { |tcx| "building specialization graph of trait `{}`", tcx.def_path_str(key) }
dc9dc135
XL
758 cache_on_disk_if { true }
759 }
ba9703b0 760 query object_safety_violations(key: DefId) -> &'tcx [traits::ObjectSafetyViolation] {
532ac7d7
XL
761 desc { |tcx| "determine object safety of trait `{}`", tcx.def_path_str(key) }
762 }
763
764 /// Gets the ParameterEnvironment for a given item; this environment
f9f354fc 765 /// will be in "user-facing" mode, meaning that it is suitable for
532ac7d7
XL
766 /// type-checking etc, and it does not normalize specializable
767 /// associated types. This is almost always what you want,
768 /// unless you are doing MIR optimizations, in which case you
769 /// might want to use `reveal_all()` method to change modes.
f9f354fc
XL
770 query param_env(def_id: DefId) -> ty::ParamEnv<'tcx> {
771 desc { |tcx| "computing normalized predicates of `{}`", tcx.def_path_str(def_id) }
772 }
532ac7d7
XL
773
774 /// Trait selection queries. These are best used by invoking `ty.is_copy_modulo_regions()`,
775 /// `ty.is_copy()`, etc, since that will prune the environment where possible.
776 query is_copy_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
532ac7d7
XL
777 desc { "computing whether `{}` is `Copy`", env.value }
778 }
74b04a01 779 /// Query backing `TyS::is_sized`.
532ac7d7 780 query is_sized_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
532ac7d7
XL
781 desc { "computing whether `{}` is `Sized`", env.value }
782 }
74b04a01 783 /// Query backing `TyS::is_freeze`.
532ac7d7 784 query is_freeze_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
532ac7d7
XL
785 desc { "computing whether `{}` is freeze", env.value }
786 }
74b04a01
XL
787 /// Query backing `TyS::needs_drop`.
788 query needs_drop_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
532ac7d7
XL
789 desc { "computing whether `{}` needs drop", env.value }
790 }
791
74b04a01
XL
792 /// A list of types where the ADT requires drop if and only if any of
793 /// those types require drop. If the ADT is known to always need drop
794 /// then `Err(AlwaysRequiresDrop)` is returned.
f9f354fc
XL
795 query adt_drop_tys(def_id: DefId) -> Result<&'tcx ty::List<Ty<'tcx>>, AlwaysRequiresDrop> {
796 desc { |tcx| "computing when `{}` needs drop", tcx.def_path_str(def_id) }
74b04a01
XL
797 cache_on_disk_if { true }
798 }
799
532ac7d7
XL
800 query layout_raw(
801 env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>
ba9703b0 802 ) -> Result<&'tcx rustc_target::abi::Layout, ty::layout::LayoutError<'tcx>> {
532ac7d7
XL
803 desc { "computing layout of `{}`", env.value }
804 }
805 }
806
807 Other {
808 query dylib_dependency_formats(_: CrateNum)
dc9dc135 809 -> &'tcx [(CrateNum, LinkagePreference)] {
532ac7d7
XL
810 desc { "dylib dependency formats of crate" }
811 }
e74abb32
XL
812
813 query dependency_formats(_: CrateNum)
814 -> Lrc<crate::middle::dependency_format::Dependencies>
815 {
816 desc { "get the linkage format of all dependencies" }
817 }
532ac7d7
XL
818 }
819
820 Codegen {
821 query is_compiler_builtins(_: CrateNum) -> bool {
822 fatal_cycle
823 desc { "checking if the crate is_compiler_builtins" }
824 }
825 query has_global_allocator(_: CrateNum) -> bool {
826 fatal_cycle
827 desc { "checking if the crate has_global_allocator" }
828 }
829 query has_panic_handler(_: CrateNum) -> bool {
830 fatal_cycle
831 desc { "checking if the crate has_panic_handler" }
832 }
532ac7d7
XL
833 query is_profiler_runtime(_: CrateNum) -> bool {
834 fatal_cycle
416331ca 835 desc { "query a crate is `#![profiler_runtime]`" }
532ac7d7
XL
836 }
837 query panic_strategy(_: CrateNum) -> PanicStrategy {
838 fatal_cycle
839 desc { "query a crate's configured panic strategy" }
840 }
841 query is_no_builtins(_: CrateNum) -> bool {
842 fatal_cycle
416331ca 843 desc { "test whether a crate has `#![no_builtins]`" }
532ac7d7 844 }
dc9dc135
XL
845 query symbol_mangling_version(_: CrateNum) -> SymbolManglingVersion {
846 fatal_cycle
847 desc { "query a crate's symbol mangling version" }
848 }
532ac7d7 849
f9f354fc 850 query extern_crate(def_id: DefId) -> Option<&'tcx ExternCrate> {
532ac7d7
XL
851 eval_always
852 desc { "getting crate's ExternCrateData" }
853 }
854 }
855
856 TypeChecking {
857 query specializes(_: (DefId, DefId)) -> bool {
532ac7d7
XL
858 desc { "computing whether impls specialize one another" }
859 }
ba9703b0 860 query in_scope_traits_map(_: LocalDefId)
dc9dc135 861 -> Option<&'tcx FxHashMap<ItemLocalId, StableVec<TraitCandidate>>> {
532ac7d7
XL
862 eval_always
863 desc { "traits in scope at a block" }
864 }
865 }
866
867 Other {
f9f354fc
XL
868 query module_exports(def_id: DefId) -> Option<&'tcx [Export<hir::HirId>]> {
869 desc { |tcx| "looking up items exported by `{}`", tcx.def_path_str(def_id) }
532ac7d7
XL
870 eval_always
871 }
872 }
873
874 TypeChecking {
f9f354fc
XL
875 query impl_defaultness(def_id: DefId) -> hir::Defaultness {
876 desc { |tcx| "looking up whether `{}` is a default impl", tcx.def_path_str(def_id) }
877 }
532ac7d7 878
f9f354fc
XL
879 query check_item_well_formed(key: LocalDefId) -> () {
880 desc { |tcx| "checking that `{}` is well-formed", tcx.def_path_str(key.to_def_id()) }
881 }
882 query check_trait_item_well_formed(key: LocalDefId) -> () {
883 desc { |tcx| "checking that `{}` is well-formed", tcx.def_path_str(key.to_def_id()) }
884 }
885 query check_impl_item_well_formed(key: LocalDefId) -> () {
886 desc { |tcx| "checking that `{}` is well-formed", tcx.def_path_str(key.to_def_id()) }
887 }
532ac7d7
XL
888 }
889
f9f354fc 890
532ac7d7 891 Linking {
dc9dc135 892 // The `DefId`s of all non-generic functions and statics in the given crate
532ac7d7
XL
893 // that can be reached from outside the crate.
894 //
895 // We expect this items to be available for being linked to.
896 //
dc9dc135 897 // This query can also be called for `LOCAL_CRATE`. In this case it will
532ac7d7
XL
898 // compute which items will be reachable to other crates, taking into account
899 // the kind of crate that is currently compiled. Crates with only a
900 // C interface have fewer reachable things.
901 //
902 // Does not include external symbols that don't have a corresponding DefId,
903 // like the compiler-generated `main` function and so on.
904 query reachable_non_generics(_: CrateNum)
f9f354fc
XL
905 -> DefIdMap<SymbolExportLevel> {
906 storage(ArenaCacheSelector<'tcx>)
532ac7d7
XL
907 desc { "looking up the exported symbols of a crate" }
908 }
f9f354fc
XL
909 query is_reachable_non_generic(def_id: DefId) -> bool {
910 desc { |tcx| "checking whether `{}` is an exported symbol", tcx.def_path_str(def_id) }
911 }
912 query is_unreachable_local_definition(def_id: DefId) -> bool {
913 desc { |tcx|
914 "checking whether `{}` is reachable from outside the crate",
915 tcx.def_path_str(def_id),
916 }
917 }
532ac7d7
XL
918 }
919
920 Codegen {
dfeec247
XL
921 /// The entire set of monomorphizations the local crate can safely link
922 /// to because they are exported from upstream crates. Do not depend on
923 /// this directly, as its value changes anytime a monomorphization gets
924 /// added or removed in any upstream crate. Instead use the narrower
925 /// `upstream_monomorphizations_for`, `upstream_drop_glue_for`, or, even
926 /// better, `Instance::upstream_monomorphization()`.
532ac7d7
XL
927 query upstream_monomorphizations(
928 k: CrateNum
f9f354fc
XL
929 ) -> DefIdMap<FxHashMap<SubstsRef<'tcx>, CrateNum>> {
930 storage(ArenaCacheSelector<'tcx>)
532ac7d7
XL
931 desc { "collecting available upstream monomorphizations `{:?}`", k }
932 }
dfeec247
XL
933
934 /// Returns the set of upstream monomorphizations available for the
935 /// generic function identified by the given `def_id`. The query makes
936 /// sure to make a stable selection if the same monomorphization is
937 /// available in multiple upstream crates.
938 ///
939 /// You likely want to call `Instance::upstream_monomorphization()`
940 /// instead of invoking this query directly.
f9f354fc
XL
941 query upstream_monomorphizations_for(def_id: DefId)
942 -> Option<&'tcx FxHashMap<SubstsRef<'tcx>, CrateNum>> {
943 desc { |tcx|
944 "collecting available upstream monomorphizations for `{}`",
945 tcx.def_path_str(def_id),
946 }
947 }
dfeec247
XL
948
949 /// Returns the upstream crate that exports drop-glue for the given
950 /// type (`substs` is expected to be a single-item list containing the
951 /// type one wants drop-glue for).
952 ///
953 /// This is a subset of `upstream_monomorphizations_for` in order to
954 /// increase dep-tracking granularity. Otherwise adding or removing any
955 /// type with drop-glue in any upstream crate would invalidate all
956 /// functions calling drop-glue of an upstream type.
957 ///
958 /// You likely want to call `Instance::upstream_monomorphization()`
959 /// instead of invoking this query directly.
960 ///
961 /// NOTE: This query could easily be extended to also support other
962 /// common functions that have are large set of monomorphizations
963 /// (like `Clone::clone` for example).
964 query upstream_drop_glue_for(substs: SubstsRef<'tcx>) -> Option<CrateNum> {
965 desc { "available upstream drop-glue for `{:?}`", substs }
dfeec247 966 }
532ac7d7
XL
967 }
968
969 Other {
dc9dc135 970 query foreign_modules(_: CrateNum) -> &'tcx [ForeignModule] {
532ac7d7
XL
971 desc { "looking up the foreign modules of a linked crate" }
972 }
973
974 /// Identifies the entry-point (e.g., the `main` function) for a given
975 /// crate, returning `None` if there is no entry point (such as for library crates).
f9f354fc 976 query entry_fn(_: CrateNum) -> Option<(LocalDefId, EntryFnType)> {
532ac7d7
XL
977 desc { "looking up the entry function of a crate" }
978 }
979 query plugin_registrar_fn(_: CrateNum) -> Option<DefId> {
980 desc { "looking up the plugin registrar for a crate" }
981 }
982 query proc_macro_decls_static(_: CrateNum) -> Option<DefId> {
983 desc { "looking up the derive registrar for a crate" }
984 }
985 query crate_disambiguator(_: CrateNum) -> CrateDisambiguator {
986 eval_always
987 desc { "looking up the disambiguator a crate" }
988 }
989 query crate_hash(_: CrateNum) -> Svh {
990 eval_always
991 desc { "looking up the hash a crate" }
992 }
e74abb32
XL
993 query crate_host_hash(_: CrateNum) -> Option<Svh> {
994 eval_always
995 desc { "looking up the hash of a host version of a crate" }
996 }
532ac7d7
XL
997 query original_crate_name(_: CrateNum) -> Symbol {
998 eval_always
999 desc { "looking up the original name a crate" }
1000 }
1001 query extra_filename(_: CrateNum) -> String {
1002 eval_always
1003 desc { "looking up the extra filename for a crate" }
1004 }
1005 }
1006
1007 TypeChecking {
1008 query implementations_of_trait(_: (CrateNum, DefId))
dc9dc135 1009 -> &'tcx [DefId] {
532ac7d7
XL
1010 desc { "looking up implementations of a trait in a crate" }
1011 }
1012 query all_trait_implementations(_: CrateNum)
dc9dc135 1013 -> &'tcx [DefId] {
532ac7d7
XL
1014 desc { "looking up all (?) trait implementations" }
1015 }
1016 }
1017
1018 Other {
1019 query dllimport_foreign_items(_: CrateNum)
f9f354fc
XL
1020 -> FxHashSet<DefId> {
1021 storage(ArenaCacheSelector<'tcx>)
532ac7d7
XL
1022 desc { "dllimport_foreign_items" }
1023 }
f9f354fc
XL
1024 query is_dllimport_foreign_item(def_id: DefId) -> bool {
1025 desc { |tcx| "is_dllimport_foreign_item({})", tcx.def_path_str(def_id) }
1026 }
1027 query is_statically_included_foreign_item(def_id: DefId) -> bool {
1028 desc { |tcx| "is_statically_included_foreign_item({})", tcx.def_path_str(def_id) }
1029 }
1030 query native_library_kind(def_id: DefId)
1031 -> Option<NativeLibKind> {
1032 desc { |tcx| "native_library_kind({})", tcx.def_path_str(def_id) }
1033 }
532ac7d7
XL
1034 }
1035
1036 Linking {
1037 query link_args(_: CrateNum) -> Lrc<Vec<String>> {
1038 eval_always
1039 desc { "looking up link arguments for a crate" }
1040 }
1041 }
1042
1043 BorrowChecking {
e1599b0c 1044 /// Lifetime resolution. See `middle::resolve_lifetimes`.
f9f354fc
XL
1045 query resolve_lifetimes(_: CrateNum) -> ResolveLifetimes {
1046 storage(ArenaCacheSelector<'tcx>)
532ac7d7
XL
1047 desc { "resolving lifetimes" }
1048 }
ba9703b0 1049 query named_region_map(_: LocalDefId) ->
dc9dc135 1050 Option<&'tcx FxHashMap<ItemLocalId, Region>> {
532ac7d7
XL
1051 desc { "looking up a named region" }
1052 }
ba9703b0 1053 query is_late_bound_map(_: LocalDefId) ->
dc9dc135 1054 Option<&'tcx FxHashSet<ItemLocalId>> {
532ac7d7
XL
1055 desc { "testing if a region is late bound" }
1056 }
ba9703b0 1057 query object_lifetime_defaults_map(_: LocalDefId)
dc9dc135 1058 -> Option<&'tcx FxHashMap<ItemLocalId, Vec<ObjectLifetimeDefault>>> {
532ac7d7
XL
1059 desc { "looking up lifetime defaults for a region" }
1060 }
1061 }
1062
1063 TypeChecking {
f9f354fc
XL
1064 query visibility(def_id: DefId) -> ty::Visibility {
1065 desc { |tcx| "computing visibility of `{}`", tcx.def_path_str(def_id) }
1066 }
532ac7d7
XL
1067 }
1068
1069 Other {
1070 query dep_kind(_: CrateNum) -> DepKind {
1071 eval_always
1072 desc { "fetching what a dependency looks like" }
1073 }
1074 query crate_name(_: CrateNum) -> Symbol {
1075 eval_always
1076 desc { "fetching what a crate is named" }
1077 }
f9f354fc
XL
1078 query item_children(def_id: DefId) -> &'tcx [Export<hir::HirId>] {
1079 desc { |tcx| "collecting child items of `{}`", tcx.def_path_str(def_id) }
1080 }
1081 query extern_mod_stmt_cnum(def_id: LocalDefId) -> Option<CrateNum> {
1082 desc { |tcx| "computing crate imported by `{}`", tcx.def_path_str(def_id.to_def_id()) }
1083 }
532ac7d7 1084
f9f354fc
XL
1085 query get_lib_features(_: CrateNum) -> LibFeatures {
1086 storage(ArenaCacheSelector<'tcx>)
532ac7d7
XL
1087 eval_always
1088 desc { "calculating the lib features map" }
1089 }
1090 query defined_lib_features(_: CrateNum)
dc9dc135 1091 -> &'tcx [(Symbol, Option<Symbol>)] {
532ac7d7
XL
1092 desc { "calculating the lib features defined in a crate" }
1093 }
e1599b0c
XL
1094 /// Returns the lang items defined in another crate by loading it from metadata.
1095 // FIXME: It is illegal to pass a `CrateNum` other than `LOCAL_CRATE` here, just get rid
1096 // of that argument?
f9f354fc
XL
1097 query get_lang_items(_: CrateNum) -> LanguageItems {
1098 storage(ArenaCacheSelector<'tcx>)
532ac7d7
XL
1099 eval_always
1100 desc { "calculating the lang items map" }
1101 }
e1599b0c
XL
1102
1103 /// Returns all diagnostic items defined in all crates.
f9f354fc
XL
1104 query all_diagnostic_items(_: CrateNum) -> FxHashMap<Symbol, DefId> {
1105 storage(ArenaCacheSelector<'tcx>)
e1599b0c
XL
1106 eval_always
1107 desc { "calculating the diagnostic items map" }
1108 }
1109
1110 /// Returns the lang items defined in another crate by loading it from metadata.
dc9dc135 1111 query defined_lang_items(_: CrateNum) -> &'tcx [(DefId, usize)] {
532ac7d7
XL
1112 desc { "calculating the lang items defined in a crate" }
1113 }
e1599b0c
XL
1114
1115 /// Returns the diagnostic items defined in a crate.
f9f354fc
XL
1116 query diagnostic_items(_: CrateNum) -> FxHashMap<Symbol, DefId> {
1117 storage(ArenaCacheSelector<'tcx>)
e1599b0c
XL
1118 desc { "calculating the diagnostic items map in a crate" }
1119 }
1120
dc9dc135 1121 query missing_lang_items(_: CrateNum) -> &'tcx [LangItem] {
532ac7d7
XL
1122 desc { "calculating the missing lang items in a crate" }
1123 }
1124 query visible_parent_map(_: CrateNum)
f9f354fc
XL
1125 -> DefIdMap<DefId> {
1126 storage(ArenaCacheSelector<'tcx>)
532ac7d7
XL
1127 desc { "calculating the visible parent map" }
1128 }
1129 query missing_extern_crate_item(_: CrateNum) -> bool {
1130 eval_always
1131 desc { "seeing if we're missing an `extern crate` item for this crate" }
1132 }
1133 query used_crate_source(_: CrateNum) -> Lrc<CrateSource> {
1134 eval_always
1135 desc { "looking at the source for a crate" }
1136 }
dc9dc135 1137 query postorder_cnums(_: CrateNum) -> &'tcx [CrateNum] {
532ac7d7
XL
1138 eval_always
1139 desc { "generating a postorder list of CrateNums" }
1140 }
1141
f9f354fc
XL
1142 query upvars_mentioned(def_id: DefId) -> Option<&'tcx FxIndexMap<hir::HirId, hir::Upvar>> {
1143 desc { |tcx| "collecting upvars mentioned in `{}`", tcx.def_path_str(def_id) }
532ac7d7
XL
1144 eval_always
1145 }
f9f354fc 1146 query maybe_unused_trait_import(def_id: LocalDefId) -> bool {
532ac7d7 1147 eval_always
f9f354fc 1148 desc { |tcx| "maybe_unused_trait_import for `{}`", tcx.def_path_str(def_id.to_def_id()) }
532ac7d7
XL
1149 }
1150 query maybe_unused_extern_crates(_: CrateNum)
f9f354fc 1151 -> &'tcx [(LocalDefId, Span)] {
532ac7d7
XL
1152 eval_always
1153 desc { "looking up all possibly unused extern crates" }
1154 }
f9f354fc
XL
1155 query names_imported_by_glob_use(def_id: LocalDefId)
1156 -> &'tcx FxHashSet<Symbol> {
532ac7d7 1157 eval_always
f9f354fc 1158 desc { |tcx| "names_imported_by_glob_use for `{}`", tcx.def_path_str(def_id.to_def_id()) }
532ac7d7
XL
1159 }
1160
f9f354fc
XL
1161 query stability_index(_: CrateNum) -> stability::Index<'tcx> {
1162 storage(ArenaCacheSelector<'tcx>)
532ac7d7
XL
1163 eval_always
1164 desc { "calculating the stability index for the local crate" }
1165 }
dc9dc135 1166 query all_crate_nums(_: CrateNum) -> &'tcx [CrateNum] {
532ac7d7
XL
1167 eval_always
1168 desc { "fetching all foreign CrateNum instances" }
1169 }
1170
1171 /// A vector of every trait accessible in the whole crate
1172 /// (i.e., including those from subcrates). This is used only for
1173 /// error reporting.
dc9dc135 1174 query all_traits(_: CrateNum) -> &'tcx [DefId] {
532ac7d7
XL
1175 desc { "fetching all foreign and local traits" }
1176 }
1177 }
1178
1179 Linking {
dfeec247
XL
1180 /// The list of symbols exported from the given crate.
1181 ///
1182 /// - All names contained in `exported_symbols(cnum)` are guaranteed to
1183 /// correspond to a publicly visible symbol in `cnum` machine code.
1184 /// - The `exported_symbols` sets of different crates do not intersect.
532ac7d7 1185 query exported_symbols(_: CrateNum)
ba9703b0 1186 -> &'tcx [(ExportedSymbol<'tcx>, SymbolExportLevel)] {
532ac7d7
XL
1187 desc { "exported_symbols" }
1188 }
1189 }
1190
1191 Codegen {
1192 query collect_and_partition_mono_items(_: CrateNum)
ba9703b0 1193 -> (&'tcx DefIdSet, &'tcx [CodegenUnit<'tcx>]) {
532ac7d7
XL
1194 eval_always
1195 desc { "collect_and_partition_mono_items" }
1196 }
f9f354fc
XL
1197 query is_codegened_item(def_id: DefId) -> bool {
1198 desc { |tcx| "determining whether `{}` needs codegen", tcx.def_path_str(def_id) }
1199 }
ba9703b0 1200 query codegen_unit(_: Symbol) -> &'tcx CodegenUnit<'tcx> {
532ac7d7
XL
1201 desc { "codegen_unit" }
1202 }
1203 query backend_optimization_level(_: CrateNum) -> OptLevel {
1204 desc { "optimization level used by backend" }
1205 }
1206 }
1207
1208 Other {
1209 query output_filenames(_: CrateNum) -> Arc<OutputFilenames> {
1210 eval_always
1211 desc { "output_filenames" }
1212 }
1213 }
1214
1215 TypeChecking {
1216 /// Do not call this query directly: invoke `normalize` instead.
1217 query normalize_projection_ty(
1218 goal: CanonicalProjectionGoal<'tcx>
1219 ) -> Result<
48663c56 1220 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, NormalizationResult<'tcx>>>,
532ac7d7
XL
1221 NoSolution,
1222 > {
532ac7d7
XL
1223 desc { "normalizing `{:?}`", goal }
1224 }
1225
1226 /// Do not call this query directly: invoke `normalize_erasing_regions` instead.
ba9703b0
XL
1227 query normalize_generic_arg_after_erasing_regions(
1228 goal: ParamEnvAnd<'tcx, GenericArg<'tcx>>
1229 ) -> GenericArg<'tcx> {
1230 desc { "normalizing `{}`", goal.value }
532ac7d7
XL
1231 }
1232
1233 query implied_outlives_bounds(
1234 goal: CanonicalTyGoal<'tcx>
1235 ) -> Result<
48663c56 1236 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, Vec<OutlivesBound<'tcx>>>>,
532ac7d7
XL
1237 NoSolution,
1238 > {
532ac7d7
XL
1239 desc { "computing implied outlives bounds for `{:?}`", goal }
1240 }
1241
1242 /// Do not call this query directly: invoke `infcx.at().dropck_outlives()` instead.
1243 query dropck_outlives(
1244 goal: CanonicalTyGoal<'tcx>
1245 ) -> Result<
48663c56 1246 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, DropckOutlivesResult<'tcx>>>,
532ac7d7
XL
1247 NoSolution,
1248 > {
532ac7d7
XL
1249 desc { "computing dropck types for `{:?}`", goal }
1250 }
1251
1252 /// Do not call this query directly: invoke `infcx.predicate_may_hold()` or
1253 /// `infcx.predicate_must_hold()` instead.
1254 query evaluate_obligation(
1255 goal: CanonicalPredicateGoal<'tcx>
1256 ) -> Result<traits::EvaluationResult, traits::OverflowError> {
532ac7d7
XL
1257 desc { "evaluating trait selection obligation `{}`", goal.value.value }
1258 }
1259
f9f354fc
XL
1260 query evaluate_goal(
1261 goal: traits::ChalkCanonicalGoal<'tcx>
1262 ) -> Result<
1263 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1264 NoSolution
1265 > {
1266 desc { "evaluating trait selection obligation `{}`", goal.value }
1267 }
1268
1269 query type_implements_trait(
1270 key: (DefId, Ty<'tcx>, SubstsRef<'tcx>, ty::ParamEnv<'tcx>, )
1271 ) -> bool {
1272 desc { "evaluating `type_implements_trait` `{:?}`", key }
1273 }
1274
532ac7d7
XL
1275 /// Do not call this query directly: part of the `Eq` type-op
1276 query type_op_ascribe_user_type(
1277 goal: CanonicalTypeOpAscribeUserTypeGoal<'tcx>
1278 ) -> Result<
48663c56 1279 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
532ac7d7
XL
1280 NoSolution,
1281 > {
532ac7d7
XL
1282 desc { "evaluating `type_op_ascribe_user_type` `{:?}`", goal }
1283 }
1284
1285 /// Do not call this query directly: part of the `Eq` type-op
1286 query type_op_eq(
1287 goal: CanonicalTypeOpEqGoal<'tcx>
1288 ) -> Result<
48663c56 1289 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
532ac7d7
XL
1290 NoSolution,
1291 > {
532ac7d7
XL
1292 desc { "evaluating `type_op_eq` `{:?}`", goal }
1293 }
1294
1295 /// Do not call this query directly: part of the `Subtype` type-op
1296 query type_op_subtype(
1297 goal: CanonicalTypeOpSubtypeGoal<'tcx>
1298 ) -> Result<
48663c56 1299 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
532ac7d7
XL
1300 NoSolution,
1301 > {
532ac7d7
XL
1302 desc { "evaluating `type_op_subtype` `{:?}`", goal }
1303 }
1304
1305 /// Do not call this query directly: part of the `ProvePredicate` type-op
1306 query type_op_prove_predicate(
1307 goal: CanonicalTypeOpProvePredicateGoal<'tcx>
1308 ) -> Result<
48663c56 1309 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
532ac7d7
XL
1310 NoSolution,
1311 > {
532ac7d7
XL
1312 desc { "evaluating `type_op_prove_predicate` `{:?}`", goal }
1313 }
1314
1315 /// Do not call this query directly: part of the `Normalize` type-op
1316 query type_op_normalize_ty(
1317 goal: CanonicalTypeOpNormalizeGoal<'tcx, Ty<'tcx>>
1318 ) -> Result<
48663c56 1319 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, Ty<'tcx>>>,
532ac7d7
XL
1320 NoSolution,
1321 > {
532ac7d7
XL
1322 desc { "normalizing `{:?}`", goal }
1323 }
1324
1325 /// Do not call this query directly: part of the `Normalize` type-op
1326 query type_op_normalize_predicate(
1327 goal: CanonicalTypeOpNormalizeGoal<'tcx, ty::Predicate<'tcx>>
1328 ) -> Result<
48663c56 1329 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ty::Predicate<'tcx>>>,
532ac7d7
XL
1330 NoSolution,
1331 > {
532ac7d7
XL
1332 desc { "normalizing `{:?}`", goal }
1333 }
1334
1335 /// Do not call this query directly: part of the `Normalize` type-op
1336 query type_op_normalize_poly_fn_sig(
1337 goal: CanonicalTypeOpNormalizeGoal<'tcx, ty::PolyFnSig<'tcx>>
1338 ) -> Result<
48663c56 1339 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ty::PolyFnSig<'tcx>>>,
532ac7d7
XL
1340 NoSolution,
1341 > {
532ac7d7
XL
1342 desc { "normalizing `{:?}`", goal }
1343 }
1344
1345 /// Do not call this query directly: part of the `Normalize` type-op
1346 query type_op_normalize_fn_sig(
1347 goal: CanonicalTypeOpNormalizeGoal<'tcx, ty::FnSig<'tcx>>
1348 ) -> Result<
48663c56 1349 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ty::FnSig<'tcx>>>,
532ac7d7
XL
1350 NoSolution,
1351 > {
532ac7d7
XL
1352 desc { "normalizing `{:?}`", goal }
1353 }
1354
1355 query substitute_normalize_and_test_predicates(key: (DefId, SubstsRef<'tcx>)) -> bool {
532ac7d7
XL
1356 desc { |tcx|
1357 "testing substituted normalized predicates:`{}`",
1358 tcx.def_path_str(key.0)
1359 }
1360 }
1361
1362 query method_autoderef_steps(
1363 goal: CanonicalTyGoal<'tcx>
1364 ) -> MethodAutoderefStepsResult<'tcx> {
532ac7d7
XL
1365 desc { "computing autoderef types for `{:?}`", goal }
1366 }
1367 }
1368
1369 Other {
f9f354fc
XL
1370 query target_features_whitelist(_: CrateNum) -> FxHashMap<String, Option<Symbol>> {
1371 storage(ArenaCacheSelector<'tcx>)
532ac7d7
XL
1372 eval_always
1373 desc { "looking up the whitelist of target features" }
1374 }
1375
1376 // Get an estimate of the size of an InstanceDef based on its MIR for CGU partitioning.
1377 query instance_def_size_estimate(def: ty::InstanceDef<'tcx>)
1378 -> usize {
532ac7d7
XL
1379 desc { |tcx| "estimating size for `{}`", tcx.def_path_str(def.def_id()) }
1380 }
1381
60c5eb7d 1382 query features_query(_: CrateNum) -> &'tcx rustc_feature::Features {
532ac7d7
XL
1383 eval_always
1384 desc { "looking up enabled feature gates" }
1385 }
ba9703b0 1386
f9f354fc
XL
1387 /// Attempt to resolve the given `DefId` to an `Instance`, for the
1388 /// given generics args (`SubstsRef`), returning one of:
1389 /// * `Ok(Some(instance))` on success
1390 /// * `Ok(None)` when the `SubstsRef` are still too generic,
1391 /// and therefore don't allow finding the final `Instance`
1392 /// * `Err(ErrorReported)` when the `Instance` resolution process
1393 /// couldn't complete due to errors elsewhere - this is distinct
1394 /// from `Ok(None)` to avoid misleading diagnostics when an error
1395 /// has already been/will be emitted, for the original cause
1396 query resolve_instance(
1397 key: ty::ParamEnvAnd<'tcx, (DefId, SubstsRef<'tcx>)>
1398 ) -> Result<Option<ty::Instance<'tcx>>, ErrorReported> {
1399 desc { "resolving instance `{}`", ty::Instance::new(key.value.0, key.value.1) }
ba9703b0 1400 }
532ac7d7
XL
1401 }
1402}