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