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