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