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