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