]> git.lizzy.rs Git - rust.git/blob - src/librustc/ty/query/mod.rs
Rollup merge of #58273 - taiki-e:rename-dependency, r=matthewjasper
[rust.git] / src / librustc / ty / query / mod.rs
1 use crate::dep_graph::{self, DepConstructor, DepNode};
2 use crate::hir::def_id::{CrateNum, DefId, DefIndex};
3 use crate::hir::def::{Def, Export};
4 use crate::hir::{self, TraitCandidate, ItemLocalId, CodegenFnAttrs};
5 use crate::infer::canonical::{self, Canonical};
6 use crate::lint;
7 use crate::middle::borrowck::BorrowCheckResult;
8 use crate::middle::cstore::{ExternCrate, LinkagePreference, NativeLibrary, ForeignModule};
9 use crate::middle::cstore::{NativeLibraryKind, DepKind, CrateSource};
10 use crate::middle::privacy::AccessLevels;
11 use crate::middle::reachable::ReachableSet;
12 use crate::middle::region;
13 use crate::middle::resolve_lifetime::{ResolveLifetimes, Region, ObjectLifetimeDefault};
14 use crate::middle::stability::{self, DeprecationEntry};
15 use crate::middle::lib_features::LibFeatures;
16 use crate::middle::lang_items::{LanguageItems, LangItem};
17 use crate::middle::exported_symbols::{SymbolExportLevel, ExportedSymbol};
18 use crate::mir::interpret::{ConstEvalRawResult, ConstEvalResult};
19 use crate::mir::mono::CodegenUnit;
20 use crate::mir;
21 use crate::mir::interpret::GlobalId;
22 use crate::session::{CompileResult, CrateDisambiguator};
23 use crate::session::config::{EntryFnType, OutputFilenames, OptLevel};
24 use crate::traits::{self, Vtable};
25 use crate::traits::query::{
26     CanonicalPredicateGoal, CanonicalProjectionGoal,
27     CanonicalTyGoal, CanonicalTypeOpAscribeUserTypeGoal,
28     CanonicalTypeOpEqGoal, CanonicalTypeOpSubtypeGoal, CanonicalTypeOpProvePredicateGoal,
29     CanonicalTypeOpNormalizeGoal, NoSolution,
30 };
31 use crate::traits::query::method_autoderef::MethodAutoderefStepsResult;
32 use crate::traits::query::dropck_outlives::{DtorckConstraint, DropckOutlivesResult};
33 use crate::traits::query::normalize::NormalizationResult;
34 use crate::traits::query::outlives_bounds::OutlivesBound;
35 use crate::traits::specialization_graph;
36 use crate::traits::Clauses;
37 use crate::ty::{self, CrateInherentImpls, ParamEnvAnd, Ty, TyCtxt};
38 use crate::ty::steal::Steal;
39 use crate::ty::subst::Substs;
40 use crate::util::nodemap::{DefIdSet, DefIdMap, ItemLocalSet};
41 use crate::util::common::{ErrorReported};
42 use crate::util::profiling::ProfileCategory::*;
43 use crate::session::Session;
44
45 use errors::DiagnosticBuilder;
46 use rustc_data_structures::svh::Svh;
47 use rustc_data_structures::bit_set::BitSet;
48 use rustc_data_structures::indexed_vec::IndexVec;
49 use rustc_data_structures::fx::{FxHashMap, FxHashSet};
50 use rustc_data_structures::stable_hasher::StableVec;
51 use rustc_data_structures::sync::Lrc;
52 use rustc_data_structures::fingerprint::Fingerprint;
53 use rustc_target::spec::PanicStrategy;
54
55 use std::borrow::Cow;
56 use std::ops::Deref;
57 use std::sync::Arc;
58 use std::intrinsics::type_name;
59 use syntax_pos::{Span, DUMMY_SP};
60 use syntax_pos::symbol::InternedString;
61 use syntax::attr;
62 use syntax::ast;
63 use syntax::feature_gate;
64 use syntax::symbol::Symbol;
65
66 #[macro_use]
67 mod plumbing;
68 use self::plumbing::*;
69 pub use self::plumbing::{force_from_dep_node, CycleError};
70
71 mod job;
72 pub use self::job::{QueryJob, QueryInfo};
73 #[cfg(parallel_compiler)]
74 pub use self::job::handle_deadlock;
75
76 mod keys;
77 use self::keys::Key;
78
79 mod values;
80 use self::values::Value;
81
82 mod config;
83 pub use self::config::QueryConfig;
84 use self::config::{QueryAccessors, QueryDescription};
85
86 mod on_disk_cache;
87 pub use self::on_disk_cache::OnDiskCache;
88
89 // Each of these quries corresponds to a function pointer field in the
90 // `Providers` struct for requesting a value of that type, and a method
91 // on `tcx: TyCtxt` (and `tcx.at(span)`) for doing that request in a way
92 // which memoizes and does dep-graph tracking, wrapping around the actual
93 // `Providers` that the driver creates (using several `rustc_*` crates).
94 //
95 // The result type of each query must implement `Clone`, and additionally
96 // `ty::query::values::Value`, which produces an appropriate placeholder
97 // (error) value if the query resulted in a query cycle.
98 // Queries marked with `fatal_cycle` do not need the latter implementation,
99 // as they will raise an fatal error on query cycles instead.
100 define_queries! { <'tcx>
101     Other {
102         /// Records the type of every item.
103         [] fn type_of: TypeOfItem(DefId) -> Ty<'tcx>,
104
105         /// Maps from the `DefId` of an item (trait/struct/enum/fn) to its
106         /// associated generics.
107         [] fn generics_of: GenericsOfItem(DefId) -> &'tcx ty::Generics,
108
109         /// Maps from the `DefId` of an item (trait/struct/enum/fn) to the
110         /// predicates (where-clauses) that must be proven true in order
111         /// to reference it. This is almost always the "predicates query"
112         /// that you want.
113         ///
114         /// `predicates_of` builds on `predicates_defined_on` -- in fact,
115         /// it is almost always the same as that query, except for the
116         /// case of traits. For traits, `predicates_of` contains
117         /// an additional `Self: Trait<...>` predicate that users don't
118         /// actually write. This reflects the fact that to invoke the
119         /// trait (e.g., via `Default::default`) you must supply types
120         /// that actually implement the trait. (However, this extra
121         /// predicate gets in the way of some checks, which are intended
122         /// to operate over only the actual where-clauses written by the
123         /// user.)
124         [] fn predicates_of: PredicatesOfItem(DefId) -> Lrc<ty::GenericPredicates<'tcx>>,
125
126         /// Maps from the `DefId` of an item (trait/struct/enum/fn) to the
127         /// predicates (where-clauses) directly defined on it. This is
128         /// equal to the `explicit_predicates_of` predicates plus the
129         /// `inferred_outlives_of` predicates.
130         [] fn predicates_defined_on: PredicatesDefinedOnItem(DefId)
131             -> Lrc<ty::GenericPredicates<'tcx>>,
132
133         /// Returns the predicates written explicit by the user.
134         [] fn explicit_predicates_of: ExplicitPredicatesOfItem(DefId)
135             -> Lrc<ty::GenericPredicates<'tcx>>,
136
137         /// Returns the inferred outlives predicates (e.g., for `struct
138         /// Foo<'a, T> { x: &'a T }`, this would return `T: 'a`).
139         [] fn inferred_outlives_of: InferredOutlivesOf(DefId) -> Lrc<Vec<ty::Predicate<'tcx>>>,
140
141         /// Maps from the `DefId` of a trait to the list of
142         /// super-predicates. This is a subset of the full list of
143         /// predicates. We store these in a separate map because we must
144         /// evaluate them even during type conversion, often before the
145         /// full predicates are available (note that supertraits have
146         /// additional acyclicity requirements).
147         [] fn super_predicates_of: SuperPredicatesOfItem(DefId) -> Lrc<ty::GenericPredicates<'tcx>>,
148
149         /// To avoid cycles within the predicates of a single item we compute
150         /// per-type-parameter predicates for resolving `T::AssocTy`.
151         [] fn type_param_predicates: type_param_predicates((DefId, DefId))
152             -> Lrc<ty::GenericPredicates<'tcx>>,
153
154         [] fn trait_def: TraitDefOfItem(DefId) -> &'tcx ty::TraitDef,
155         [] fn adt_def: AdtDefOfItem(DefId) -> &'tcx ty::AdtDef,
156         [] fn adt_destructor: AdtDestructor(DefId) -> Option<ty::Destructor>,
157         [] fn adt_sized_constraint: SizedConstraint(DefId) -> &'tcx [Ty<'tcx>],
158         [] fn adt_dtorck_constraint: DtorckConstraint(
159             DefId
160         ) -> Result<DtorckConstraint<'tcx>, NoSolution>,
161
162         /// True if this is a const fn, use the `is_const_fn` to know whether your crate actually
163         /// sees it as const fn (e.g., the const-fn-ness might be unstable and you might not have
164         /// the feature gate active)
165         ///
166         /// **Do not call this function manually.** It is only meant to cache the base data for the
167         /// `is_const_fn` function.
168         [] fn is_const_fn_raw: IsConstFn(DefId) -> bool,
169
170
171         /// Returns true if calls to the function may be promoted
172         ///
173         /// This is either because the function is e.g., a tuple-struct or tuple-variant
174         /// constructor, or because it has the `#[rustc_promotable]` attribute. The attribute should
175         /// be removed in the future in favour of some form of check which figures out whether the
176         /// function does not inspect the bits of any of its arguments (so is essentially just a
177         /// constructor function).
178         [] fn is_promotable_const_fn: IsPromotableConstFn(DefId) -> bool,
179
180         /// True if this is a foreign item (i.e., linked via `extern { ... }`).
181         [] fn is_foreign_item: IsForeignItem(DefId) -> bool,
182
183         /// Get a map with the variance of every item; use `item_variance`
184         /// instead.
185         [] fn crate_variances: crate_variances(CrateNum) -> Lrc<ty::CrateVariancesMap>,
186
187         /// Maps from def-id of a type or region parameter to its
188         /// (inferred) variance.
189         [] fn variances_of: ItemVariances(DefId) -> Lrc<Vec<ty::Variance>>,
190     },
191
192     TypeChecking {
193         /// Maps from def-id of a type to its (inferred) outlives.
194         [] fn inferred_outlives_crate: InferredOutlivesCrate(CrateNum)
195             -> Lrc<ty::CratePredicatesMap<'tcx>>,
196     },
197
198     Other {
199         /// Maps from an impl/trait def-id to a list of the def-ids of its items
200         [] fn associated_item_def_ids: AssociatedItemDefIds(DefId) -> Lrc<Vec<DefId>>,
201
202         /// Maps from a trait item to the trait item "descriptor"
203         [] fn associated_item: AssociatedItems(DefId) -> ty::AssociatedItem,
204
205         [] fn impl_trait_ref: ImplTraitRef(DefId) -> Option<ty::TraitRef<'tcx>>,
206         [] fn impl_polarity: ImplPolarity(DefId) -> hir::ImplPolarity,
207
208         [] fn issue33140_self_ty: Issue33140SelfTy(DefId) -> Option<ty::Ty<'tcx>>,
209     },
210
211     TypeChecking {
212         /// Maps a DefId of a type to a list of its inherent impls.
213         /// Contains implementations of methods that are inherent to a type.
214         /// Methods in these implementations don't need to be exported.
215         [] fn inherent_impls: InherentImpls(DefId) -> Lrc<Vec<DefId>>,
216     },
217
218     Codegen {
219         /// Set of all the `DefId`s in this crate that have MIR associated with
220         /// them. This includes all the body owners, but also things like struct
221         /// constructors.
222         [] fn mir_keys: mir_keys(CrateNum) -> Lrc<DefIdSet>,
223
224         /// Maps DefId's that have an associated Mir to the result
225         /// of the MIR qualify_consts pass. The actual meaning of
226         /// the value isn't known except to the pass itself.
227         [] fn mir_const_qualif: MirConstQualif(DefId) -> (u8, Lrc<BitSet<mir::Local>>),
228
229         /// Fetch the MIR for a given `DefId` right after it's built - this includes
230         /// unreachable code.
231         [] fn mir_built: MirBuilt(DefId) -> &'tcx Steal<mir::Mir<'tcx>>,
232
233         /// Fetch the MIR for a given `DefId` up till the point where it is
234         /// ready for const evaluation.
235         ///
236         /// See the README for the `mir` module for details.
237         [no_hash] fn mir_const: MirConst(DefId) -> &'tcx Steal<mir::Mir<'tcx>>,
238
239         [no_hash] fn mir_validated: MirValidated(DefId) -> &'tcx Steal<mir::Mir<'tcx>>,
240
241         /// MIR after our optimization passes have run. This is MIR that is ready
242         /// for codegen. This is also the only query that can fetch non-local MIR, at present.
243         [] fn optimized_mir: MirOptimized(DefId) -> &'tcx mir::Mir<'tcx>,
244     },
245
246     TypeChecking {
247         /// The result of unsafety-checking this `DefId`.
248         [] fn unsafety_check_result: UnsafetyCheckResult(DefId) -> mir::UnsafetyCheckResult,
249
250         /// HACK: when evaluated, this reports a "unsafe derive on repr(packed)" error
251         [] fn unsafe_derive_on_repr_packed: UnsafeDeriveOnReprPacked(DefId) -> (),
252
253         /// The signature of functions and closures.
254         [] fn fn_sig: FnSignature(DefId) -> ty::PolyFnSig<'tcx>,
255     },
256
257     Other {
258         /// Checks the attributes in the module
259         [] fn check_mod_attrs: CheckModAttrs(DefId) -> (),
260
261         [] fn check_mod_unstable_api_usage: CheckModUnstableApiUsage(DefId) -> (),
262
263         /// Checks the loops in the module
264         [] fn check_mod_loops: CheckModLoops(DefId) -> (),
265
266         [] fn check_mod_item_types: CheckModItemTypes(DefId) -> (),
267
268         [] fn check_mod_privacy: CheckModPrivacy(DefId) -> (),
269
270         [] fn check_mod_intrinsics: CheckModIntrinsics(DefId) -> (),
271
272         [] fn check_mod_liveness: CheckModLiveness(DefId) -> (),
273
274         [] fn check_mod_impl_wf: CheckModImplWf(DefId) -> (),
275
276         [] fn collect_mod_item_types: CollectModItemTypes(DefId) -> (),
277
278         /// Caches CoerceUnsized kinds for impls on custom types.
279         [] fn coerce_unsized_info: CoerceUnsizedInfo(DefId)
280             -> ty::adjustment::CoerceUnsizedInfo,
281     },
282
283     TypeChecking {
284         [] fn typeck_item_bodies: typeck_item_bodies_dep_node(CrateNum) -> CompileResult,
285
286         [] fn typeck_tables_of: TypeckTables(DefId) -> &'tcx ty::TypeckTables<'tcx>,
287     },
288
289     Other {
290         [] fn used_trait_imports: UsedTraitImports(DefId) -> Lrc<DefIdSet>,
291     },
292
293     TypeChecking {
294         [] fn has_typeck_tables: HasTypeckTables(DefId) -> bool,
295
296         [] fn coherent_trait: CoherenceCheckTrait(DefId) -> (),
297     },
298
299     BorrowChecking {
300         [] fn borrowck: BorrowCheck(DefId) -> Lrc<BorrowCheckResult>,
301
302         /// Borrow checks the function body. If this is a closure, returns
303         /// additional requirements that the closure's creator must verify.
304         [] fn mir_borrowck: MirBorrowCheck(DefId) -> mir::BorrowCheckResult<'tcx>,
305     },
306
307     TypeChecking {
308         /// Gets a complete map from all types to their inherent impls.
309         /// Not meant to be used directly outside of coherence.
310         /// (Defined only for `LOCAL_CRATE`.)
311         [] fn crate_inherent_impls: crate_inherent_impls_dep_node(CrateNum)
312             -> Lrc<CrateInherentImpls>,
313
314         /// Checks all types in the crate for overlap in their inherent impls. Reports errors.
315         /// Not meant to be used directly outside of coherence.
316         /// (Defined only for `LOCAL_CRATE`.)
317         [] fn crate_inherent_impls_overlap_check: inherent_impls_overlap_check_dep_node(CrateNum)
318             -> (),
319     },
320
321     Other {
322         /// Evaluate a constant without running sanity checks
323         ///
324         /// **Do not use this** outside const eval. Const eval uses this to break query cycles
325         /// during validation. Please add a comment to every use site explaining why using
326         /// `const_eval` isn't sufficient
327         [] fn const_eval_raw: const_eval_raw_dep_node(ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>)
328             -> ConstEvalRawResult<'tcx>,
329
330         /// Results of evaluating const items or constants embedded in
331         /// other items (such as enum variant explicit discriminants).
332         [] fn const_eval: const_eval_dep_node(ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>)
333             -> ConstEvalResult<'tcx>,
334     },
335
336     TypeChecking {
337         [] fn check_match: CheckMatch(DefId)
338             -> Result<(), ErrorReported>,
339
340         /// Performs the privacy check and computes "access levels".
341         [] fn privacy_access_levels: PrivacyAccessLevels(CrateNum) -> Lrc<AccessLevels>,
342     },
343
344     Other {
345         [] fn reachable_set: reachability_dep_node(CrateNum) -> ReachableSet,
346
347         /// Per-body `region::ScopeTree`. The `DefId` should be the owner `DefId` for the body;
348         /// in the case of closures, this will be redirected to the enclosing function.
349         [] fn region_scope_tree: RegionScopeTree(DefId) -> Lrc<region::ScopeTree>,
350
351         [] fn mir_shims: mir_shim_dep_node(ty::InstanceDef<'tcx>) -> &'tcx mir::Mir<'tcx>,
352
353         [] fn def_symbol_name: SymbolName(DefId) -> ty::SymbolName,
354         [] fn symbol_name: symbol_name_dep_node(ty::Instance<'tcx>) -> ty::SymbolName,
355
356         [] fn describe_def: DescribeDef(DefId) -> Option<Def>,
357         [] fn def_span: DefSpan(DefId) -> Span,
358         [] fn lookup_stability: LookupStability(DefId) -> Option<&'tcx attr::Stability>,
359         [] fn lookup_deprecation_entry: LookupDeprecationEntry(DefId) -> Option<DeprecationEntry>,
360         [] fn item_attrs: ItemAttrs(DefId) -> Lrc<[ast::Attribute]>,
361     },
362
363     Codegen {
364         [] fn codegen_fn_attrs: codegen_fn_attrs(DefId) -> CodegenFnAttrs,
365     },
366
367     Other {
368         [] fn fn_arg_names: FnArgNames(DefId) -> Vec<ast::Name>,
369         /// Gets the rendered value of the specified constant or associated constant.
370         /// Used by rustdoc.
371         [] fn rendered_const: RenderedConst(DefId) -> String,
372         [] fn impl_parent: ImplParent(DefId) -> Option<DefId>,
373     },
374
375     TypeChecking {
376         [] fn trait_of_item: TraitOfItem(DefId) -> Option<DefId>,
377         [] fn const_is_rvalue_promotable_to_static: ConstIsRvaluePromotableToStatic(DefId) -> bool,
378         [] fn rvalue_promotable_map: RvaluePromotableMap(DefId) -> Lrc<ItemLocalSet>,
379     },
380
381     Codegen {
382         [] fn is_mir_available: IsMirAvailable(DefId) -> bool,
383     },
384
385     Other {
386         [] fn vtable_methods: vtable_methods_node(ty::PolyTraitRef<'tcx>)
387                             -> Lrc<Vec<Option<(DefId, &'tcx Substs<'tcx>)>>>,
388     },
389
390     Codegen {
391         [] fn codegen_fulfill_obligation: fulfill_obligation_dep_node(
392             (ty::ParamEnv<'tcx>, ty::PolyTraitRef<'tcx>)) -> Vtable<'tcx, ()>,
393     },
394
395     TypeChecking {
396         [] fn trait_impls_of: TraitImpls(DefId) -> Lrc<ty::trait_def::TraitImpls>,
397         [] fn specialization_graph_of: SpecializationGraph(DefId)
398             -> Lrc<specialization_graph::Graph>,
399         [] fn is_object_safe: ObjectSafety(DefId) -> bool,
400
401         /// Gets the ParameterEnvironment for a given item; this environment
402         /// will be in "user-facing" mode, meaning that it is suitabe for
403         /// type-checking etc, and it does not normalize specializable
404         /// associated types. This is almost always what you want,
405         /// unless you are doing MIR optimizations, in which case you
406         /// might want to use `reveal_all()` method to change modes.
407         [] fn param_env: ParamEnv(DefId) -> ty::ParamEnv<'tcx>,
408
409         /// Trait selection queries. These are best used by invoking `ty.is_copy_modulo_regions()`,
410         /// `ty.is_copy()`, etc, since that will prune the environment where possible.
411         [] fn is_copy_raw: is_copy_dep_node(ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool,
412         [] fn is_sized_raw: is_sized_dep_node(ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool,
413         [] fn is_freeze_raw: is_freeze_dep_node(ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool,
414         [] fn needs_drop_raw: needs_drop_dep_node(ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool,
415         [] fn layout_raw: layout_dep_node(ty::ParamEnvAnd<'tcx, Ty<'tcx>>)
416                                     -> Result<&'tcx ty::layout::LayoutDetails,
417                                                 ty::layout::LayoutError<'tcx>>,
418     },
419
420     Other {
421         [] fn dylib_dependency_formats: DylibDepFormats(CrateNum)
422                                         -> Lrc<Vec<(CrateNum, LinkagePreference)>>,
423     },
424
425     Codegen {
426         [fatal_cycle] fn is_panic_runtime: IsPanicRuntime(CrateNum) -> bool,
427         [fatal_cycle] fn is_compiler_builtins: IsCompilerBuiltins(CrateNum) -> bool,
428         [fatal_cycle] fn has_global_allocator: HasGlobalAllocator(CrateNum) -> bool,
429         [fatal_cycle] fn has_panic_handler: HasPanicHandler(CrateNum) -> bool,
430         [fatal_cycle] fn is_sanitizer_runtime: IsSanitizerRuntime(CrateNum) -> bool,
431         [fatal_cycle] fn is_profiler_runtime: IsProfilerRuntime(CrateNum) -> bool,
432         [fatal_cycle] fn panic_strategy: GetPanicStrategy(CrateNum) -> PanicStrategy,
433         [fatal_cycle] fn is_no_builtins: IsNoBuiltins(CrateNum) -> bool,
434
435         [] fn extern_crate: ExternCrate(DefId) -> Lrc<Option<ExternCrate>>,
436     },
437
438     TypeChecking {
439         [] fn specializes: specializes_node((DefId, DefId)) -> bool,
440         [] fn in_scope_traits_map: InScopeTraits(DefIndex)
441             -> Option<Lrc<FxHashMap<ItemLocalId, Lrc<StableVec<TraitCandidate>>>>>,
442     },
443
444     Other {
445         [] fn module_exports: ModuleExports(DefId) -> Option<Lrc<Vec<Export>>>,
446         [] fn lint_levels: lint_levels_node(CrateNum) -> Lrc<lint::LintLevelMap>,
447     },
448
449     TypeChecking {
450         [] fn impl_defaultness: ImplDefaultness(DefId) -> hir::Defaultness,
451
452         [] fn check_item_well_formed: CheckItemWellFormed(DefId) -> (),
453         [] fn check_trait_item_well_formed: CheckTraitItemWellFormed(DefId) -> (),
454         [] fn check_impl_item_well_formed: CheckImplItemWellFormed(DefId) -> (),
455     },
456
457     Linking {
458         // The DefIds of all non-generic functions and statics in the given crate
459         // that can be reached from outside the crate.
460         //
461         // We expect this items to be available for being linked to.
462         //
463         // This query can also be called for LOCAL_CRATE. In this case it will
464         // compute which items will be reachable to other crates, taking into account
465         // the kind of crate that is currently compiled. Crates with only a
466         // C interface have fewer reachable things.
467         //
468         // Does not include external symbols that don't have a corresponding DefId,
469         // like the compiler-generated `main` function and so on.
470         [] fn reachable_non_generics: ReachableNonGenerics(CrateNum)
471             -> Lrc<DefIdMap<SymbolExportLevel>>,
472         [] fn is_reachable_non_generic: IsReachableNonGeneric(DefId) -> bool,
473         [] fn is_unreachable_local_definition: IsUnreachableLocalDefinition(DefId) -> bool,
474     },
475
476     Codegen {
477         [] fn upstream_monomorphizations: UpstreamMonomorphizations(CrateNum)
478             -> Lrc<DefIdMap<Lrc<FxHashMap<&'tcx Substs<'tcx>, CrateNum>>>>,
479         [] fn upstream_monomorphizations_for: UpstreamMonomorphizationsFor(DefId)
480             -> Option<Lrc<FxHashMap<&'tcx Substs<'tcx>, CrateNum>>>,
481     },
482
483     Other {
484         [] fn native_libraries: NativeLibraries(CrateNum) -> Lrc<Vec<NativeLibrary>>,
485
486         [] fn foreign_modules: ForeignModules(CrateNum) -> Lrc<Vec<ForeignModule>>,
487
488         /// Identifies the entry-point (e.g., the `main` function) for a given
489         /// crate, returning `None` if there is no entry point (such as for library crates).
490         [] fn entry_fn: EntryFn(CrateNum) -> Option<(DefId, EntryFnType)>,
491         [] fn plugin_registrar_fn: PluginRegistrarFn(CrateNum) -> Option<DefId>,
492         [] fn proc_macro_decls_static: ProcMacroDeclsStatic(CrateNum) -> Option<DefId>,
493         [] fn crate_disambiguator: CrateDisambiguator(CrateNum) -> CrateDisambiguator,
494         [] fn crate_hash: CrateHash(CrateNum) -> Svh,
495         [] fn original_crate_name: OriginalCrateName(CrateNum) -> Symbol,
496         [] fn extra_filename: ExtraFileName(CrateNum) -> String,
497     },
498
499     TypeChecking {
500         [] fn implementations_of_trait: implementations_of_trait_node((CrateNum, DefId))
501             -> Lrc<Vec<DefId>>,
502         [] fn all_trait_implementations: AllTraitImplementations(CrateNum)
503             -> Lrc<Vec<DefId>>,
504     },
505
506     Other {
507         [] fn dllimport_foreign_items: DllimportForeignItems(CrateNum)
508             -> Lrc<FxHashSet<DefId>>,
509         [] fn is_dllimport_foreign_item: IsDllimportForeignItem(DefId) -> bool,
510         [] fn is_statically_included_foreign_item: IsStaticallyIncludedForeignItem(DefId) -> bool,
511         [] fn native_library_kind: NativeLibraryKind(DefId)
512             -> Option<NativeLibraryKind>,
513     },
514
515     Linking {
516         [] fn link_args: link_args_node(CrateNum) -> Lrc<Vec<String>>,
517     },
518
519     BorrowChecking {
520         // Lifetime resolution. See `middle::resolve_lifetimes`.
521         [] fn resolve_lifetimes: ResolveLifetimes(CrateNum) -> Lrc<ResolveLifetimes>,
522         [] fn named_region_map: NamedRegion(DefIndex) ->
523             Option<Lrc<FxHashMap<ItemLocalId, Region>>>,
524         [] fn is_late_bound_map: IsLateBound(DefIndex) ->
525             Option<Lrc<FxHashSet<ItemLocalId>>>,
526         [] fn object_lifetime_defaults_map: ObjectLifetimeDefaults(DefIndex)
527             -> Option<Lrc<FxHashMap<ItemLocalId, Lrc<Vec<ObjectLifetimeDefault>>>>>,
528     },
529
530     TypeChecking {
531         [] fn visibility: Visibility(DefId) -> ty::Visibility,
532     },
533
534     Other {
535         [] fn dep_kind: DepKind(CrateNum) -> DepKind,
536         [] fn crate_name: CrateName(CrateNum) -> Symbol,
537         [] fn item_children: ItemChildren(DefId) -> Lrc<Vec<Export>>,
538         [] fn extern_mod_stmt_cnum: ExternModStmtCnum(DefId) -> Option<CrateNum>,
539
540         [] fn get_lib_features: get_lib_features_node(CrateNum) -> Lrc<LibFeatures>,
541         [] fn defined_lib_features: DefinedLibFeatures(CrateNum)
542             -> Lrc<Vec<(Symbol, Option<Symbol>)>>,
543         [] fn get_lang_items: get_lang_items_node(CrateNum) -> Lrc<LanguageItems>,
544         [] fn defined_lang_items: DefinedLangItems(CrateNum) -> Lrc<Vec<(DefId, usize)>>,
545         [] fn missing_lang_items: MissingLangItems(CrateNum) -> Lrc<Vec<LangItem>>,
546         [] fn visible_parent_map: visible_parent_map_node(CrateNum)
547             -> Lrc<DefIdMap<DefId>>,
548         [] fn missing_extern_crate_item: MissingExternCrateItem(CrateNum) -> bool,
549         [] fn used_crate_source: UsedCrateSource(CrateNum) -> Lrc<CrateSource>,
550         [] fn postorder_cnums: postorder_cnums_node(CrateNum) -> Lrc<Vec<CrateNum>>,
551
552         [] fn freevars: Freevars(DefId) -> Option<Lrc<Vec<hir::Freevar>>>,
553         [] fn maybe_unused_trait_import: MaybeUnusedTraitImport(DefId) -> bool,
554         [] fn maybe_unused_extern_crates: maybe_unused_extern_crates_node(CrateNum)
555             -> Lrc<Vec<(DefId, Span)>>,
556         [] fn names_imported_by_glob_use: NamesImportedByGlobUse(DefId)
557             -> Lrc<FxHashSet<ast::Name>>,
558
559         [] fn stability_index: stability_index_node(CrateNum) -> Lrc<stability::Index<'tcx>>,
560         [] fn all_crate_nums: all_crate_nums_node(CrateNum) -> Lrc<Vec<CrateNum>>,
561
562         /// A vector of every trait accessible in the whole crate
563         /// (i.e., including those from subcrates). This is used only for
564         /// error reporting.
565         [] fn all_traits: all_traits_node(CrateNum) -> Lrc<Vec<DefId>>,
566     },
567
568     Linking {
569         [] fn exported_symbols: ExportedSymbols(CrateNum)
570             -> Arc<Vec<(ExportedSymbol<'tcx>, SymbolExportLevel)>>,
571     },
572
573     Codegen {
574         [] fn collect_and_partition_mono_items:
575             collect_and_partition_mono_items_node(CrateNum)
576             -> (Arc<DefIdSet>, Arc<Vec<Arc<CodegenUnit<'tcx>>>>),
577         [] fn is_codegened_item: IsCodegenedItem(DefId) -> bool,
578         [] fn codegen_unit: CodegenUnit(InternedString) -> Arc<CodegenUnit<'tcx>>,
579         [] fn backend_optimization_level: BackendOptimizationLevel(CrateNum) -> OptLevel,
580     },
581
582     Other {
583         [] fn output_filenames: output_filenames_node(CrateNum)
584             -> Arc<OutputFilenames>,
585     },
586
587     TypeChecking {
588         // Erases regions from `ty` to yield a new type.
589         // Normally you would just use `tcx.erase_regions(&value)`,
590         // however, which uses this query as a kind of cache.
591         [] fn erase_regions_ty: erase_regions_ty(Ty<'tcx>) -> Ty<'tcx>,
592
593         /// Do not call this query directly: invoke `normalize` instead.
594         [] fn normalize_projection_ty: NormalizeProjectionTy(
595             CanonicalProjectionGoal<'tcx>
596         ) -> Result<
597             Lrc<Canonical<'tcx, canonical::QueryResponse<'tcx, NormalizationResult<'tcx>>>>,
598             NoSolution,
599         >,
600
601         /// Do not call this query directly: invoke `normalize_erasing_regions` instead.
602         [] fn normalize_ty_after_erasing_regions: NormalizeTyAfterErasingRegions(
603             ParamEnvAnd<'tcx, Ty<'tcx>>
604         ) -> Ty<'tcx>,
605
606         [] fn implied_outlives_bounds: ImpliedOutlivesBounds(
607             CanonicalTyGoal<'tcx>
608         ) -> Result<
609             Lrc<Canonical<'tcx, canonical::QueryResponse<'tcx, Vec<OutlivesBound<'tcx>>>>>,
610             NoSolution,
611         >,
612
613         /// Do not call this query directly: invoke `infcx.at().dropck_outlives()` instead.
614         [] fn dropck_outlives: DropckOutlives(
615             CanonicalTyGoal<'tcx>
616         ) -> Result<
617             Lrc<Canonical<'tcx, canonical::QueryResponse<'tcx, DropckOutlivesResult<'tcx>>>>,
618             NoSolution,
619         >,
620
621         /// Do not call this query directly: invoke `infcx.predicate_may_hold()` or
622         /// `infcx.predicate_must_hold()` instead.
623         [] fn evaluate_obligation: EvaluateObligation(
624             CanonicalPredicateGoal<'tcx>
625         ) -> Result<traits::EvaluationResult, traits::OverflowError>,
626
627         [] fn evaluate_goal: EvaluateGoal(
628             traits::ChalkCanonicalGoal<'tcx>
629         ) -> Result<
630             Lrc<Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>>,
631             NoSolution
632         >,
633
634         /// Do not call this query directly: part of the `Eq` type-op
635         [] fn type_op_ascribe_user_type: TypeOpAscribeUserType(
636             CanonicalTypeOpAscribeUserTypeGoal<'tcx>
637         ) -> Result<
638             Lrc<Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>>,
639             NoSolution,
640         >,
641
642         /// Do not call this query directly: part of the `Eq` type-op
643         [] fn type_op_eq: TypeOpEq(
644             CanonicalTypeOpEqGoal<'tcx>
645         ) -> Result<
646             Lrc<Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>>,
647             NoSolution,
648         >,
649
650         /// Do not call this query directly: part of the `Subtype` type-op
651         [] fn type_op_subtype: TypeOpSubtype(
652             CanonicalTypeOpSubtypeGoal<'tcx>
653         ) -> Result<
654             Lrc<Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>>,
655             NoSolution,
656         >,
657
658         /// Do not call this query directly: part of the `ProvePredicate` type-op
659         [] fn type_op_prove_predicate: TypeOpProvePredicate(
660             CanonicalTypeOpProvePredicateGoal<'tcx>
661         ) -> Result<
662             Lrc<Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>>,
663             NoSolution,
664         >,
665
666         /// Do not call this query directly: part of the `Normalize` type-op
667         [] fn type_op_normalize_ty: TypeOpNormalizeTy(
668             CanonicalTypeOpNormalizeGoal<'tcx, Ty<'tcx>>
669         ) -> Result<
670             Lrc<Canonical<'tcx, canonical::QueryResponse<'tcx, Ty<'tcx>>>>,
671             NoSolution,
672         >,
673
674         /// Do not call this query directly: part of the `Normalize` type-op
675         [] fn type_op_normalize_predicate: TypeOpNormalizePredicate(
676             CanonicalTypeOpNormalizeGoal<'tcx, ty::Predicate<'tcx>>
677         ) -> Result<
678             Lrc<Canonical<'tcx, canonical::QueryResponse<'tcx, ty::Predicate<'tcx>>>>,
679             NoSolution,
680         >,
681
682         /// Do not call this query directly: part of the `Normalize` type-op
683         [] fn type_op_normalize_poly_fn_sig: TypeOpNormalizePolyFnSig(
684             CanonicalTypeOpNormalizeGoal<'tcx, ty::PolyFnSig<'tcx>>
685         ) -> Result<
686             Lrc<Canonical<'tcx, canonical::QueryResponse<'tcx, ty::PolyFnSig<'tcx>>>>,
687             NoSolution,
688         >,
689
690         /// Do not call this query directly: part of the `Normalize` type-op
691         [] fn type_op_normalize_fn_sig: TypeOpNormalizeFnSig(
692             CanonicalTypeOpNormalizeGoal<'tcx, ty::FnSig<'tcx>>
693         ) -> Result<
694             Lrc<Canonical<'tcx, canonical::QueryResponse<'tcx, ty::FnSig<'tcx>>>>,
695             NoSolution,
696         >,
697
698         [] fn substitute_normalize_and_test_predicates:
699             substitute_normalize_and_test_predicates_node((DefId, &'tcx Substs<'tcx>)) -> bool,
700
701         [] fn method_autoderef_steps: MethodAutoderefSteps(
702             CanonicalTyGoal<'tcx>
703         ) -> MethodAutoderefStepsResult<'tcx>,
704     },
705
706     Other {
707         [] fn target_features_whitelist:
708             target_features_whitelist_node(CrateNum) -> Lrc<FxHashMap<String, Option<String>>>,
709
710         // Get an estimate of the size of an InstanceDef based on its MIR for CGU partitioning.
711         [] fn instance_def_size_estimate: instance_def_size_estimate_dep_node(ty::InstanceDef<'tcx>)
712             -> usize,
713
714         [] fn features_query: features_node(CrateNum) -> Lrc<feature_gate::Features>,
715     },
716
717     TypeChecking {
718         [] fn program_clauses_for: ProgramClausesFor(DefId) -> Clauses<'tcx>,
719
720         [] fn program_clauses_for_env: ProgramClausesForEnv(
721             traits::Environment<'tcx>
722         ) -> Clauses<'tcx>,
723
724         // Get the chalk-style environment of the given item.
725         [] fn environment: Environment(DefId) -> traits::Environment<'tcx>,
726     },
727
728     Linking {
729         [] fn wasm_import_module_map: WasmImportModuleMap(CrateNum)
730             -> Lrc<FxHashMap<DefId, String>>,
731     },
732 }
733
734 // `try_get_query` can't be public because it uses the private query
735 // implementation traits, so we provide access to it selectively.
736 impl<'a, 'tcx, 'lcx> TyCtxt<'a, 'tcx, 'lcx> {
737     pub fn try_adt_sized_constraint(
738         self,
739         span: Span,
740         key: DefId,
741     ) -> Result<&'tcx [Ty<'tcx>], Box<DiagnosticBuilder<'a>>> {
742         self.try_get_query::<queries::adt_sized_constraint<'_>>(span, key)
743     }
744     pub fn try_needs_drop_raw(
745         self,
746         span: Span,
747         key: ty::ParamEnvAnd<'tcx, Ty<'tcx>>,
748     ) -> Result<bool, Box<DiagnosticBuilder<'a>>> {
749         self.try_get_query::<queries::needs_drop_raw<'_>>(span, key)
750     }
751     pub fn try_optimized_mir(
752         self,
753         span: Span,
754         key: DefId,
755     ) -> Result<&'tcx mir::Mir<'tcx>, Box<DiagnosticBuilder<'a>>> {
756         self.try_get_query::<queries::optimized_mir<'_>>(span, key)
757     }
758 }
759
760 //////////////////////////////////////////////////////////////////////
761 // These functions are little shims used to find the dep-node for a
762 // given query when there is not a *direct* mapping:
763
764
765 fn features_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
766     DepConstructor::Features
767 }
768
769 fn codegen_fn_attrs<'tcx>(id: DefId) -> DepConstructor<'tcx> {
770     DepConstructor::CodegenFnAttrs { 0: id }
771 }
772
773 fn erase_regions_ty<'tcx>(ty: Ty<'tcx>) -> DepConstructor<'tcx> {
774     DepConstructor::EraseRegionsTy { ty }
775 }
776
777 fn type_param_predicates<'tcx>((item_id, param_id): (DefId, DefId)) -> DepConstructor<'tcx> {
778     DepConstructor::TypeParamPredicates {
779         item_id,
780         param_id
781     }
782 }
783
784 fn fulfill_obligation_dep_node<'tcx>((param_env, trait_ref):
785     (ty::ParamEnv<'tcx>, ty::PolyTraitRef<'tcx>)) -> DepConstructor<'tcx> {
786     DepConstructor::FulfillObligation {
787         param_env,
788         trait_ref
789     }
790 }
791
792 fn crate_inherent_impls_dep_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
793     DepConstructor::Coherence
794 }
795
796 fn inherent_impls_overlap_check_dep_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
797     DepConstructor::CoherenceInherentImplOverlapCheck
798 }
799
800 fn reachability_dep_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
801     DepConstructor::Reachability
802 }
803
804 fn mir_shim_dep_node<'tcx>(instance_def: ty::InstanceDef<'tcx>) -> DepConstructor<'tcx> {
805     DepConstructor::MirShim {
806         instance_def
807     }
808 }
809
810 fn symbol_name_dep_node<'tcx>(instance: ty::Instance<'tcx>) -> DepConstructor<'tcx> {
811     DepConstructor::InstanceSymbolName { instance }
812 }
813
814 fn typeck_item_bodies_dep_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
815     DepConstructor::TypeckBodiesKrate
816 }
817
818 fn const_eval_dep_node<'tcx>(param_env: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>)
819                              -> DepConstructor<'tcx> {
820     DepConstructor::ConstEval { param_env }
821 }
822 fn const_eval_raw_dep_node<'tcx>(param_env: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>)
823                              -> DepConstructor<'tcx> {
824     DepConstructor::ConstEvalRaw { param_env }
825 }
826
827 fn mir_keys<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
828     DepConstructor::MirKeys
829 }
830
831 fn crate_variances<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
832     DepConstructor::CrateVariances
833 }
834
835 fn is_copy_dep_node<'tcx>(param_env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> DepConstructor<'tcx> {
836     DepConstructor::IsCopy { param_env }
837 }
838
839 fn is_sized_dep_node<'tcx>(param_env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> DepConstructor<'tcx> {
840     DepConstructor::IsSized { param_env }
841 }
842
843 fn is_freeze_dep_node<'tcx>(param_env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> DepConstructor<'tcx> {
844     DepConstructor::IsFreeze { param_env }
845 }
846
847 fn needs_drop_dep_node<'tcx>(param_env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> DepConstructor<'tcx> {
848     DepConstructor::NeedsDrop { param_env }
849 }
850
851 fn layout_dep_node<'tcx>(param_env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> DepConstructor<'tcx> {
852     DepConstructor::Layout { param_env }
853 }
854
855 fn lint_levels_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
856     DepConstructor::LintLevels
857 }
858
859 fn specializes_node<'tcx>((a, b): (DefId, DefId)) -> DepConstructor<'tcx> {
860     DepConstructor::Specializes { impl1: a, impl2: b }
861 }
862
863 fn implementations_of_trait_node<'tcx>((krate, trait_id): (CrateNum, DefId))
864     -> DepConstructor<'tcx>
865 {
866     DepConstructor::ImplementationsOfTrait { krate, trait_id }
867 }
868
869 fn link_args_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
870     DepConstructor::LinkArgs
871 }
872
873 fn get_lib_features_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
874     DepConstructor::GetLibFeatures
875 }
876
877 fn get_lang_items_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
878     DepConstructor::GetLangItems
879 }
880
881 fn visible_parent_map_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
882     DepConstructor::VisibleParentMap
883 }
884
885 fn postorder_cnums_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
886     DepConstructor::PostorderCnums
887 }
888
889 fn maybe_unused_extern_crates_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
890     DepConstructor::MaybeUnusedExternCrates
891 }
892
893 fn stability_index_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
894     DepConstructor::StabilityIndex
895 }
896
897 fn all_crate_nums_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
898     DepConstructor::AllCrateNums
899 }
900
901 fn all_traits_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
902     DepConstructor::AllTraits
903 }
904
905 fn collect_and_partition_mono_items_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
906     DepConstructor::CollectAndPartitionMonoItems
907 }
908
909 fn output_filenames_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
910     DepConstructor::OutputFilenames
911 }
912
913 fn vtable_methods_node<'tcx>(trait_ref: ty::PolyTraitRef<'tcx>) -> DepConstructor<'tcx> {
914     DepConstructor::VtableMethods{ trait_ref }
915 }
916
917 fn substitute_normalize_and_test_predicates_node<'tcx>(key: (DefId, &'tcx Substs<'tcx>))
918                                             -> DepConstructor<'tcx> {
919     DepConstructor::SubstituteNormalizeAndTestPredicates { key }
920 }
921
922 fn target_features_whitelist_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
923     DepConstructor::TargetFeaturesWhitelist
924 }
925
926 fn instance_def_size_estimate_dep_node<'tcx>(instance_def: ty::InstanceDef<'tcx>)
927                                               -> DepConstructor<'tcx> {
928     DepConstructor::InstanceDefSizeEstimate {
929         instance_def
930     }
931 }