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