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