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