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