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.
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.
11 use dep_graph::{DepConstructor, DepNode};
12 use errors::DiagnosticBuilder;
13 use hir::def_id::{CrateNum, DefId, DefIndex};
14 use hir::def::{Def, Export};
15 use hir::{self, TraitCandidate, ItemLocalId, CodegenFnAttrs};
16 use rustc_data_structures::svh::Svh;
17 use infer::canonical::{self, Canonical};
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;
25 use middle::resolve_lifetime::{ResolveLifetimes, Region, ObjectLifetimeDefault};
26 use middle::stability::{self, DeprecationEntry};
27 use middle::lib_features::LibFeatures;
28 use middle::lang_items::{LanguageItems, LangItem};
29 use middle::exported_symbols::{SymbolExportLevel, ExportedSymbol};
30 use mir::interpret::{ConstEvalRawResult, ConstEvalResult};
31 use mir::mono::CodegenUnit;
33 use mir::interpret::GlobalId;
34 use session::{CompileResult, CrateDisambiguator};
35 use session::config::OutputFilenames;
36 use traits::{self, Vtable};
38 CanonicalPredicateGoal, CanonicalProjectionGoal,
39 CanonicalTyGoal, CanonicalTypeOpAscribeUserTypeGoal, CanonicalTypeOpEqGoal,
40 CanonicalTypeOpSubtypeGoal, CanonicalTypeOpProvePredicateGoal,
41 CanonicalTypeOpNormalizeGoal, NoSolution,
43 use traits::query::dropck_outlives::{DtorckConstraint, DropckOutlivesResult};
44 use traits::query::normalize::NormalizationResult;
45 use traits::query::outlives_bounds::OutlivesBound;
46 use traits::specialization_graph;
48 use ty::{self, CrateInherentImpls, ParamEnvAnd, Ty, TyCtxt};
50 use ty::subst::Substs;
51 use util::nodemap::{DefIdSet, DefIdMap, ItemLocalSet};
52 use util::common::{ErrorReported};
53 use util::profiling::ProfileCategory::*;
55 use rustc_data_structures::bit_set::BitSet;
56 use rustc_data_structures::indexed_vec::IndexVec;
57 use rustc_data_structures::fx::{FxHashMap, FxHashSet};
58 use rustc_data_structures::stable_hasher::StableVec;
59 use rustc_data_structures::sync::Lrc;
60 use rustc_target::spec::PanicStrategy;
65 use syntax_pos::{Span, DUMMY_SP};
66 use syntax_pos::symbol::InternedString;
69 use syntax::feature_gate;
70 use syntax::symbol::Symbol;
74 use self::plumbing::*;
75 pub use self::plumbing::{force_from_dep_node, CycleError};
78 pub use self::job::{QueryJob, QueryInfo};
79 #[cfg(parallel_queries)]
80 pub use self::job::handle_deadlock;
86 use self::values::Value;
89 pub use self::config::QueryConfig;
90 use self::config::{QueryAccessors, QueryDescription};
93 pub use self::on_disk_cache::OnDiskCache;
95 // Each of these quries corresponds to a function pointer field in the
96 // `Providers` struct for requesting a value of that type, and a method
97 // on `tcx: TyCtxt` (and `tcx.at(span)`) for doing that request in a way
98 // which memoizes and does dep-graph tracking, wrapping around the actual
99 // `Providers` that the driver creates (using several `rustc_*` crates).
101 // The result type of each query must implement `Clone`, and additionally
102 // `ty::query::values::Value`, which produces an appropriate placeholder
103 // (error) value if the query resulted in a query cycle.
104 // Queries marked with `fatal_cycle` do not need the latter implementation,
105 // as they will raise an fatal error on query cycles instead.
106 define_queries! { <'tcx>
108 /// Records the type of every item.
109 [] fn type_of: TypeOfItem(DefId) -> Ty<'tcx>,
111 /// Maps from the def-id of an item (trait/struct/enum/fn) to its
112 /// associated generics.
113 [] fn generics_of: GenericsOfItem(DefId) -> &'tcx ty::Generics,
115 /// Maps from the def-id of an item (trait/struct/enum/fn) to the
116 /// predicates (where clauses) that must be proven true in order
117 /// to reference it. This is almost always the "predicates query"
120 /// `predicates_of` builds on `predicates_defined_on` -- in fact,
121 /// it is almost always the same as that query, except for the
122 /// case of traits. For traits, `predicates_of` contains
123 /// an additional `Self: Trait<...>` predicate that users don't
124 /// actually write. This reflects the fact that to invoke the
125 /// trait (e.g., via `Default::default`) you must supply types
126 /// that actually implement the trait. (However, this extra
127 /// predicate gets in the way of some checks, which are intended
128 /// to operate over only the actual where-clauses written by the
130 [] fn predicates_of: PredicatesOfItem(DefId) -> Lrc<ty::GenericPredicates<'tcx>>,
132 /// Maps from the def-id of an item (trait/struct/enum/fn) to the
133 /// predicates (where clauses) directly defined on it. This is
134 /// equal to the `explicit_predicates_of` predicates plus the
135 /// `inferred_outlives_of` predicates.
136 [] fn predicates_defined_on: PredicatesDefinedOnItem(DefId)
137 -> Lrc<ty::GenericPredicates<'tcx>>,
139 /// Returns the predicates written explicit by the user.
140 [] fn explicit_predicates_of: ExplicitPredicatesOfItem(DefId)
141 -> Lrc<ty::GenericPredicates<'tcx>>,
143 /// Returns the inferred outlives predicates (e.g., for `struct
144 /// Foo<'a, T> { x: &'a T }`, this would return `T: 'a`).
145 [] fn inferred_outlives_of: InferredOutlivesOf(DefId) -> Lrc<Vec<ty::Predicate<'tcx>>>,
147 /// Maps from the def-id of a trait to the list of
148 /// super-predicates. This is a subset of the full list of
149 /// predicates. We store these in a separate map because we must
150 /// evaluate them even during type conversion, often before the
151 /// full predicates are available (note that supertraits have
152 /// additional acyclicity requirements).
153 [] fn super_predicates_of: SuperPredicatesOfItem(DefId) -> Lrc<ty::GenericPredicates<'tcx>>,
155 /// To avoid cycles within the predicates of a single item we compute
156 /// per-type-parameter predicates for resolving `T::AssocTy`.
157 [] fn type_param_predicates: type_param_predicates((DefId, DefId))
158 -> Lrc<ty::GenericPredicates<'tcx>>,
160 [] fn trait_def: TraitDefOfItem(DefId) -> &'tcx ty::TraitDef,
161 [] fn adt_def: AdtDefOfItem(DefId) -> &'tcx ty::AdtDef,
162 [] fn adt_destructor: AdtDestructor(DefId) -> Option<ty::Destructor>,
163 [] fn adt_sized_constraint: SizedConstraint(DefId) -> &'tcx [Ty<'tcx>],
164 [] fn adt_dtorck_constraint: DtorckConstraint(
166 ) -> Result<DtorckConstraint<'tcx>, NoSolution>,
168 /// True if this is a const fn, use the `is_const_fn` to know whether your crate actually
169 /// sees it as const fn (e.g., the const-fn-ness might be unstable and you might not have
170 /// the feature gate active)
172 /// **Do not call this function manually.** It is only meant to cache the base data for the
173 /// `is_const_fn` function.
174 [] fn is_const_fn_raw: IsConstFn(DefId) -> bool,
177 /// Returns true if calls to the function may be promoted
179 /// This is either because the function is e.g., a tuple-struct or tuple-variant
180 /// constructor, or because it has the `#[rustc_promotable]` attribute. The attribute should
181 /// be removed in the future in favour of some form of check which figures out whether the
182 /// function does not inspect the bits of any of its arguments (so is essentially just a
183 /// constructor function).
184 [] fn is_promotable_const_fn: IsPromotableConstFn(DefId) -> bool,
186 /// True if this is a foreign item (i.e., linked via `extern { ... }`).
187 [] fn is_foreign_item: IsForeignItem(DefId) -> bool,
189 /// Get a map with the variance of every item; use `item_variance`
191 [] fn crate_variances: crate_variances(CrateNum) -> Lrc<ty::CrateVariancesMap>,
193 /// Maps from def-id of a type or region parameter to its
194 /// (inferred) variance.
195 [] fn variances_of: ItemVariances(DefId) -> Lrc<Vec<ty::Variance>>,
199 /// Maps from def-id of a type to its (inferred) outlives.
200 [] fn inferred_outlives_crate: InferredOutlivesCrate(CrateNum)
201 -> Lrc<ty::CratePredicatesMap<'tcx>>,
205 /// Maps from an impl/trait def-id to a list of the def-ids of its items
206 [] fn associated_item_def_ids: AssociatedItemDefIds(DefId) -> Lrc<Vec<DefId>>,
208 /// Maps from a trait item to the trait item "descriptor"
209 [] fn associated_item: AssociatedItems(DefId) -> ty::AssociatedItem,
211 [] fn impl_trait_ref: ImplTraitRef(DefId) -> Option<ty::TraitRef<'tcx>>,
212 [] fn impl_polarity: ImplPolarity(DefId) -> hir::ImplPolarity,
216 /// Maps a DefId of a type to a list of its inherent impls.
217 /// Contains implementations of methods that are inherent to a type.
218 /// Methods in these implementations don't need to be exported.
219 [] fn inherent_impls: InherentImpls(DefId) -> Lrc<Vec<DefId>>,
223 /// Set of all the def-ids in this crate that have MIR associated with
224 /// them. This includes all the body owners, but also things like struct
226 [] fn mir_keys: mir_keys(CrateNum) -> Lrc<DefIdSet>,
228 /// Maps DefId's that have an associated Mir to the result
229 /// of the MIR qualify_consts pass. The actual meaning of
230 /// the value isn't known except to the pass itself.
231 [] fn mir_const_qualif: MirConstQualif(DefId) -> (u8, Lrc<BitSet<mir::Local>>),
233 /// Fetch the MIR for a given def-id right after it's built - this includes
234 /// unreachable code.
235 [] fn mir_built: MirBuilt(DefId) -> &'tcx Steal<mir::Mir<'tcx>>,
237 /// Fetch the MIR for a given def-id up till the point where it is
238 /// ready for const evaluation.
240 /// See the README for the `mir` module for details.
241 [] fn mir_const: MirConst(DefId) -> &'tcx Steal<mir::Mir<'tcx>>,
243 [] fn mir_validated: MirValidated(DefId) -> &'tcx Steal<mir::Mir<'tcx>>,
245 /// MIR after our optimization passes have run. This is MIR that is ready
246 /// for codegen. This is also the only query that can fetch non-local MIR, at present.
247 [] fn optimized_mir: MirOptimized(DefId) -> &'tcx mir::Mir<'tcx>,
251 /// The result of unsafety-checking this def-id.
252 [] fn unsafety_check_result: UnsafetyCheckResult(DefId) -> mir::UnsafetyCheckResult,
254 /// HACK: when evaluated, this reports a "unsafe derive on repr(packed)" error
255 [] fn unsafe_derive_on_repr_packed: UnsafeDeriveOnReprPacked(DefId) -> (),
257 /// The signature of functions and closures.
258 [] fn fn_sig: FnSignature(DefId) -> ty::PolyFnSig<'tcx>,
262 /// Caches CoerceUnsized kinds for impls on custom types.
263 [] fn coerce_unsized_info: CoerceUnsizedInfo(DefId)
264 -> ty::adjustment::CoerceUnsizedInfo,
268 [] fn typeck_item_bodies: typeck_item_bodies_dep_node(CrateNum) -> CompileResult,
270 [] fn typeck_tables_of: TypeckTables(DefId) -> &'tcx ty::TypeckTables<'tcx>,
274 [] fn used_trait_imports: UsedTraitImports(DefId) -> Lrc<DefIdSet>,
278 [] fn has_typeck_tables: HasTypeckTables(DefId) -> bool,
280 [] fn coherent_trait: CoherenceCheckTrait(DefId) -> (),
284 [] fn borrowck: BorrowCheck(DefId) -> Lrc<BorrowCheckResult>,
286 /// Borrow checks the function body. If this is a closure, returns
287 /// additional requirements that the closure's creator must verify.
288 [] fn mir_borrowck: MirBorrowCheck(DefId) -> mir::BorrowCheckResult<'tcx>,
292 /// Gets a complete map from all types to their inherent impls.
293 /// Not meant to be used directly outside of coherence.
294 /// (Defined only for LOCAL_CRATE)
295 [] fn crate_inherent_impls: crate_inherent_impls_dep_node(CrateNum)
296 -> Lrc<CrateInherentImpls>,
298 /// Checks all types in the krate for overlap in their inherent impls. Reports errors.
299 /// Not meant to be used directly outside of coherence.
300 /// (Defined only for LOCAL_CRATE)
301 [] fn crate_inherent_impls_overlap_check: inherent_impls_overlap_check_dep_node(CrateNum)
306 /// Evaluate a constant without running sanity checks
308 /// DO NOT USE THIS outside const eval. Const eval uses this to break query cycles during
309 /// validation. Please add a comment to every use site explaining why using `const_eval`
311 [] fn const_eval_raw: const_eval_raw_dep_node(ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>)
312 -> ConstEvalRawResult<'tcx>,
314 /// Results of evaluating const items or constants embedded in
315 /// other items (such as enum variant explicit discriminants).
316 [] fn const_eval: const_eval_dep_node(ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>)
317 -> ConstEvalResult<'tcx>,
321 [] fn check_match: CheckMatch(DefId)
322 -> Result<(), ErrorReported>,
324 /// Performs the privacy check and computes "access levels".
325 [] fn privacy_access_levels: PrivacyAccessLevels(CrateNum) -> Lrc<AccessLevels>,
329 [] fn reachable_set: reachability_dep_node(CrateNum) -> ReachableSet,
331 /// Per-body `region::ScopeTree`. The `DefId` should be the owner-def-id for the body;
332 /// in the case of closures, this will be redirected to the enclosing function.
333 [] fn region_scope_tree: RegionScopeTree(DefId) -> Lrc<region::ScopeTree>,
335 [] fn mir_shims: mir_shim_dep_node(ty::InstanceDef<'tcx>) -> &'tcx mir::Mir<'tcx>,
337 [] fn def_symbol_name: SymbolName(DefId) -> ty::SymbolName,
338 [] fn symbol_name: symbol_name_dep_node(ty::Instance<'tcx>) -> ty::SymbolName,
340 [] fn describe_def: DescribeDef(DefId) -> Option<Def>,
341 [] fn def_span: DefSpan(DefId) -> Span,
342 [] fn lookup_stability: LookupStability(DefId) -> Option<&'tcx attr::Stability>,
343 [] fn lookup_deprecation_entry: LookupDeprecationEntry(DefId) -> Option<DeprecationEntry>,
344 [] fn item_attrs: ItemAttrs(DefId) -> Lrc<[ast::Attribute]>,
348 [] fn codegen_fn_attrs: codegen_fn_attrs(DefId) -> CodegenFnAttrs,
352 [] fn fn_arg_names: FnArgNames(DefId) -> Vec<ast::Name>,
353 /// Gets the rendered value of the specified constant or associated constant.
355 [] fn rendered_const: RenderedConst(DefId) -> String,
356 [] fn impl_parent: ImplParent(DefId) -> Option<DefId>,
360 [] fn trait_of_item: TraitOfItem(DefId) -> Option<DefId>,
361 [] fn const_is_rvalue_promotable_to_static: ConstIsRvaluePromotableToStatic(DefId) -> bool,
362 [] fn rvalue_promotable_map: RvaluePromotableMap(DefId) -> Lrc<ItemLocalSet>,
366 [] fn is_mir_available: IsMirAvailable(DefId) -> bool,
370 [] fn vtable_methods: vtable_methods_node(ty::PolyTraitRef<'tcx>)
371 -> Lrc<Vec<Option<(DefId, &'tcx Substs<'tcx>)>>>,
375 [] fn codegen_fulfill_obligation: fulfill_obligation_dep_node(
376 (ty::ParamEnv<'tcx>, ty::PolyTraitRef<'tcx>)) -> Vtable<'tcx, ()>,
380 [] fn trait_impls_of: TraitImpls(DefId) -> Lrc<ty::trait_def::TraitImpls>,
381 [] fn specialization_graph_of: SpecializationGraph(DefId)
382 -> Lrc<specialization_graph::Graph>,
383 [] fn is_object_safe: ObjectSafety(DefId) -> bool,
385 /// Get the ParameterEnvironment for a given item; this environment
386 /// will be in "user-facing" mode, meaning that it is suitabe for
387 /// type-checking etc, and it does not normalize specializable
388 /// associated types. This is almost always what you want,
389 /// unless you are doing MIR optimizations, in which case you
390 /// might want to use `reveal_all()` method to change modes.
391 [] fn param_env: ParamEnv(DefId) -> ty::ParamEnv<'tcx>,
393 /// Trait selection queries. These are best used by invoking `ty.moves_by_default()`,
394 /// `ty.is_copy()`, etc, since that will prune the environment where possible.
395 [] fn is_copy_raw: is_copy_dep_node(ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool,
396 [] fn is_sized_raw: is_sized_dep_node(ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool,
397 [] fn is_freeze_raw: is_freeze_dep_node(ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool,
398 [] fn needs_drop_raw: needs_drop_dep_node(ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool,
399 [] fn layout_raw: layout_dep_node(ty::ParamEnvAnd<'tcx, Ty<'tcx>>)
400 -> Result<&'tcx ty::layout::LayoutDetails,
401 ty::layout::LayoutError<'tcx>>,
405 [] fn dylib_dependency_formats: DylibDepFormats(CrateNum)
406 -> Lrc<Vec<(CrateNum, LinkagePreference)>>,
410 [fatal_cycle] fn is_panic_runtime: IsPanicRuntime(CrateNum) -> bool,
411 [fatal_cycle] fn is_compiler_builtins: IsCompilerBuiltins(CrateNum) -> bool,
412 [fatal_cycle] fn has_global_allocator: HasGlobalAllocator(CrateNum) -> bool,
413 [fatal_cycle] fn has_panic_handler: HasPanicHandler(CrateNum) -> bool,
414 [fatal_cycle] fn is_sanitizer_runtime: IsSanitizerRuntime(CrateNum) -> bool,
415 [fatal_cycle] fn is_profiler_runtime: IsProfilerRuntime(CrateNum) -> bool,
416 [fatal_cycle] fn panic_strategy: GetPanicStrategy(CrateNum) -> PanicStrategy,
417 [fatal_cycle] fn is_no_builtins: IsNoBuiltins(CrateNum) -> bool,
419 [] fn extern_crate: ExternCrate(DefId) -> Lrc<Option<ExternCrate>>,
423 [] fn specializes: specializes_node((DefId, DefId)) -> bool,
424 [] fn in_scope_traits_map: InScopeTraits(DefIndex)
425 -> Option<Lrc<FxHashMap<ItemLocalId, Lrc<StableVec<TraitCandidate>>>>>,
429 [] fn module_exports: ModuleExports(DefId) -> Option<Lrc<Vec<Export>>>,
430 [] fn lint_levels: lint_levels_node(CrateNum) -> Lrc<lint::LintLevelMap>,
434 [] fn impl_defaultness: ImplDefaultness(DefId) -> hir::Defaultness,
436 [] fn check_item_well_formed: CheckItemWellFormed(DefId) -> (),
437 [] fn check_trait_item_well_formed: CheckTraitItemWellFormed(DefId) -> (),
438 [] fn check_impl_item_well_formed: CheckImplItemWellFormed(DefId) -> (),
442 // The DefIds of all non-generic functions and statics in the given crate
443 // that can be reached from outside the crate.
445 // We expect this items to be available for being linked to.
447 // This query can also be called for LOCAL_CRATE. In this case it will
448 // compute which items will be reachable to other crates, taking into account
449 // the kind of crate that is currently compiled. Crates with only a
450 // C interface have fewer reachable things.
452 // Does not include external symbols that don't have a corresponding DefId,
453 // like the compiler-generated `main` function and so on.
454 [] fn reachable_non_generics: ReachableNonGenerics(CrateNum)
455 -> Lrc<DefIdMap<SymbolExportLevel>>,
456 [] fn is_reachable_non_generic: IsReachableNonGeneric(DefId) -> bool,
457 [] fn is_unreachable_local_definition: IsUnreachableLocalDefinition(DefId) -> bool,
461 [] fn upstream_monomorphizations: UpstreamMonomorphizations(CrateNum)
462 -> Lrc<DefIdMap<Lrc<FxHashMap<&'tcx Substs<'tcx>, CrateNum>>>>,
463 [] fn upstream_monomorphizations_for: UpstreamMonomorphizationsFor(DefId)
464 -> Option<Lrc<FxHashMap<&'tcx Substs<'tcx>, CrateNum>>>,
468 [] fn native_libraries: NativeLibraries(CrateNum) -> Lrc<Vec<NativeLibrary>>,
470 [] fn foreign_modules: ForeignModules(CrateNum) -> Lrc<Vec<ForeignModule>>,
472 [] fn plugin_registrar_fn: PluginRegistrarFn(CrateNum) -> Option<DefId>,
473 [] fn proc_macro_decls_static: ProcMacroDeclsStatic(CrateNum) -> Option<DefId>,
474 [] fn crate_disambiguator: CrateDisambiguator(CrateNum) -> CrateDisambiguator,
475 [] fn crate_hash: CrateHash(CrateNum) -> Svh,
476 [] fn original_crate_name: OriginalCrateName(CrateNum) -> Symbol,
477 [] fn extra_filename: ExtraFileName(CrateNum) -> String,
481 [] fn implementations_of_trait: implementations_of_trait_node((CrateNum, DefId))
483 [] fn all_trait_implementations: AllTraitImplementations(CrateNum)
488 [] fn dllimport_foreign_items: DllimportForeignItems(CrateNum)
489 -> Lrc<FxHashSet<DefId>>,
490 [] fn is_dllimport_foreign_item: IsDllimportForeignItem(DefId) -> bool,
491 [] fn is_statically_included_foreign_item: IsStaticallyIncludedForeignItem(DefId) -> bool,
492 [] fn native_library_kind: NativeLibraryKind(DefId)
493 -> Option<NativeLibraryKind>,
497 [] fn link_args: link_args_node(CrateNum) -> Lrc<Vec<String>>,
501 // Lifetime resolution. See `middle::resolve_lifetimes`.
502 [] fn resolve_lifetimes: ResolveLifetimes(CrateNum) -> Lrc<ResolveLifetimes>,
503 [] fn named_region_map: NamedRegion(DefIndex) ->
504 Option<Lrc<FxHashMap<ItemLocalId, Region>>>,
505 [] fn is_late_bound_map: IsLateBound(DefIndex) ->
506 Option<Lrc<FxHashSet<ItemLocalId>>>,
507 [] fn object_lifetime_defaults_map: ObjectLifetimeDefaults(DefIndex)
508 -> Option<Lrc<FxHashMap<ItemLocalId, Lrc<Vec<ObjectLifetimeDefault>>>>>,
512 [] fn visibility: Visibility(DefId) -> ty::Visibility,
516 [] fn dep_kind: DepKind(CrateNum) -> DepKind,
517 [] fn crate_name: CrateName(CrateNum) -> Symbol,
518 [] fn item_children: ItemChildren(DefId) -> Lrc<Vec<Export>>,
519 [] fn extern_mod_stmt_cnum: ExternModStmtCnum(DefId) -> Option<CrateNum>,
521 [] fn get_lib_features: get_lib_features_node(CrateNum) -> Lrc<LibFeatures>,
522 [] fn defined_lib_features: DefinedLibFeatures(CrateNum)
523 -> Lrc<Vec<(Symbol, Option<Symbol>)>>,
524 [] fn get_lang_items: get_lang_items_node(CrateNum) -> Lrc<LanguageItems>,
525 [] fn defined_lang_items: DefinedLangItems(CrateNum) -> Lrc<Vec<(DefId, usize)>>,
526 [] fn missing_lang_items: MissingLangItems(CrateNum) -> Lrc<Vec<LangItem>>,
527 [] fn visible_parent_map: visible_parent_map_node(CrateNum)
528 -> Lrc<DefIdMap<DefId>>,
529 [] fn missing_extern_crate_item: MissingExternCrateItem(CrateNum) -> bool,
530 [] fn used_crate_source: UsedCrateSource(CrateNum) -> Lrc<CrateSource>,
531 [] fn postorder_cnums: postorder_cnums_node(CrateNum) -> Lrc<Vec<CrateNum>>,
533 [] fn freevars: Freevars(DefId) -> Option<Lrc<Vec<hir::Freevar>>>,
534 [] fn maybe_unused_trait_import: MaybeUnusedTraitImport(DefId) -> bool,
535 [] fn maybe_unused_extern_crates: maybe_unused_extern_crates_node(CrateNum)
536 -> Lrc<Vec<(DefId, Span)>>,
538 [] fn stability_index: stability_index_node(CrateNum) -> Lrc<stability::Index<'tcx>>,
539 [] fn all_crate_nums: all_crate_nums_node(CrateNum) -> Lrc<Vec<CrateNum>>,
541 /// A vector of every trait accessible in the whole crate
542 /// (i.e., including those from subcrates). This is used only for
544 [] fn all_traits: all_traits_node(CrateNum) -> Lrc<Vec<DefId>>,
548 [] fn exported_symbols: ExportedSymbols(CrateNum)
549 -> Arc<Vec<(ExportedSymbol<'tcx>, SymbolExportLevel)>>,
553 [] fn collect_and_partition_mono_items:
554 collect_and_partition_mono_items_node(CrateNum)
555 -> (Arc<DefIdSet>, Arc<Vec<Arc<CodegenUnit<'tcx>>>>),
556 [] fn is_codegened_item: IsCodegenedItem(DefId) -> bool,
557 [] fn codegen_unit: CodegenUnit(InternedString) -> Arc<CodegenUnit<'tcx>>,
561 [] fn output_filenames: output_filenames_node(CrateNum)
562 -> Arc<OutputFilenames>,
566 // Erases regions from `ty` to yield a new type.
567 // Normally you would just use `tcx.erase_regions(&value)`,
568 // however, which uses this query as a kind of cache.
569 [] fn erase_regions_ty: erase_regions_ty(Ty<'tcx>) -> Ty<'tcx>,
571 /// Do not call this query directly: invoke `normalize` instead.
572 [] fn normalize_projection_ty: NormalizeProjectionTy(
573 CanonicalProjectionGoal<'tcx>
575 Lrc<Canonical<'tcx, canonical::QueryResponse<'tcx, NormalizationResult<'tcx>>>>,
579 /// Do not call this query directly: invoke `normalize_erasing_regions` instead.
580 [] fn normalize_ty_after_erasing_regions: NormalizeTyAfterErasingRegions(
581 ParamEnvAnd<'tcx, Ty<'tcx>>
584 [] fn implied_outlives_bounds: ImpliedOutlivesBounds(
585 CanonicalTyGoal<'tcx>
587 Lrc<Canonical<'tcx, canonical::QueryResponse<'tcx, Vec<OutlivesBound<'tcx>>>>>,
591 /// Do not call this query directly: invoke `infcx.at().dropck_outlives()` instead.
592 [] fn dropck_outlives: DropckOutlives(
593 CanonicalTyGoal<'tcx>
595 Lrc<Canonical<'tcx, canonical::QueryResponse<'tcx, DropckOutlivesResult<'tcx>>>>,
599 /// Do not call this query directly: invoke `infcx.predicate_may_hold()` or
600 /// `infcx.predicate_must_hold()` instead.
601 [] fn evaluate_obligation: EvaluateObligation(
602 CanonicalPredicateGoal<'tcx>
603 ) -> Result<traits::EvaluationResult, traits::OverflowError>,
605 /// Do not call this query directly: part of the `Eq` type-op
606 [] fn type_op_ascribe_user_type: TypeOpAscribeUserType(
607 CanonicalTypeOpAscribeUserTypeGoal<'tcx>
609 Lrc<Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>>,
613 /// Do not call this query directly: part of the `Eq` type-op
614 [] fn type_op_eq: TypeOpEq(
615 CanonicalTypeOpEqGoal<'tcx>
617 Lrc<Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>>,
621 /// Do not call this query directly: part of the `Subtype` type-op
622 [] fn type_op_subtype: TypeOpSubtype(
623 CanonicalTypeOpSubtypeGoal<'tcx>
625 Lrc<Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>>,
629 /// Do not call this query directly: part of the `ProvePredicate` type-op
630 [] fn type_op_prove_predicate: TypeOpProvePredicate(
631 CanonicalTypeOpProvePredicateGoal<'tcx>
633 Lrc<Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>>,
637 /// Do not call this query directly: part of the `Normalize` type-op
638 [] fn type_op_normalize_ty: TypeOpNormalizeTy(
639 CanonicalTypeOpNormalizeGoal<'tcx, Ty<'tcx>>
641 Lrc<Canonical<'tcx, canonical::QueryResponse<'tcx, Ty<'tcx>>>>,
645 /// Do not call this query directly: part of the `Normalize` type-op
646 [] fn type_op_normalize_predicate: TypeOpNormalizePredicate(
647 CanonicalTypeOpNormalizeGoal<'tcx, ty::Predicate<'tcx>>
649 Lrc<Canonical<'tcx, canonical::QueryResponse<'tcx, ty::Predicate<'tcx>>>>,
653 /// Do not call this query directly: part of the `Normalize` type-op
654 [] fn type_op_normalize_poly_fn_sig: TypeOpNormalizePolyFnSig(
655 CanonicalTypeOpNormalizeGoal<'tcx, ty::PolyFnSig<'tcx>>
657 Lrc<Canonical<'tcx, canonical::QueryResponse<'tcx, ty::PolyFnSig<'tcx>>>>,
661 /// Do not call this query directly: part of the `Normalize` type-op
662 [] fn type_op_normalize_fn_sig: TypeOpNormalizeFnSig(
663 CanonicalTypeOpNormalizeGoal<'tcx, ty::FnSig<'tcx>>
665 Lrc<Canonical<'tcx, canonical::QueryResponse<'tcx, ty::FnSig<'tcx>>>>,
669 [] fn substitute_normalize_and_test_predicates:
670 substitute_normalize_and_test_predicates_node((DefId, &'tcx Substs<'tcx>)) -> bool,
674 [] fn target_features_whitelist:
675 target_features_whitelist_node(CrateNum) -> Lrc<FxHashMap<String, Option<String>>>,
677 // Get an estimate of the size of an InstanceDef based on its MIR for CGU partitioning.
678 [] fn instance_def_size_estimate: instance_def_size_estimate_dep_node(ty::InstanceDef<'tcx>)
681 [] fn features_query: features_node(CrateNum) -> Lrc<feature_gate::Features>,
685 [] fn program_clauses_for: ProgramClausesFor(DefId) -> Clauses<'tcx>,
687 [] fn program_clauses_for_env: ProgramClausesForEnv(
688 traits::Environment<'tcx>
691 // Get the chalk-style environment of the given item.
692 [] fn environment: Environment(DefId) -> ty::Binder<traits::Environment<'tcx>>,
696 [] fn wasm_import_module_map: WasmImportModuleMap(CrateNum)
697 -> Lrc<FxHashMap<DefId, String>>,
701 // `try_get_query` can't be public because it uses the private query
702 // implementation traits, so we provide access to it selectively.
703 impl<'a, 'tcx, 'lcx> TyCtxt<'a, 'tcx, 'lcx> {
704 pub fn try_adt_sized_constraint(
708 ) -> Result<&'tcx [Ty<'tcx>], DiagnosticBuilder<'a>> {
709 self.try_get_query::<queries::adt_sized_constraint<'_>>(span, key)
711 pub fn try_needs_drop_raw(
714 key: ty::ParamEnvAnd<'tcx, Ty<'tcx>>,
715 ) -> Result<bool, DiagnosticBuilder<'a>> {
716 self.try_get_query::<queries::needs_drop_raw<'_>>(span, key)
718 pub fn try_optimized_mir(
722 ) -> Result<&'tcx mir::Mir<'tcx>, DiagnosticBuilder<'a>> {
723 self.try_get_query::<queries::optimized_mir<'_>>(span, key)
727 //////////////////////////////////////////////////////////////////////
728 // These functions are little shims used to find the dep-node for a
729 // given query when there is not a *direct* mapping:
732 fn features_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
733 DepConstructor::Features
736 fn codegen_fn_attrs<'tcx>(id: DefId) -> DepConstructor<'tcx> {
737 DepConstructor::CodegenFnAttrs { 0: id }
740 fn erase_regions_ty<'tcx>(ty: Ty<'tcx>) -> DepConstructor<'tcx> {
741 DepConstructor::EraseRegionsTy { ty }
744 fn type_param_predicates<'tcx>((item_id, param_id): (DefId, DefId)) -> DepConstructor<'tcx> {
745 DepConstructor::TypeParamPredicates {
751 fn fulfill_obligation_dep_node<'tcx>((param_env, trait_ref):
752 (ty::ParamEnv<'tcx>, ty::PolyTraitRef<'tcx>)) -> DepConstructor<'tcx> {
753 DepConstructor::FulfillObligation {
759 fn crate_inherent_impls_dep_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
760 DepConstructor::Coherence
763 fn inherent_impls_overlap_check_dep_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
764 DepConstructor::CoherenceInherentImplOverlapCheck
767 fn reachability_dep_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
768 DepConstructor::Reachability
771 fn mir_shim_dep_node<'tcx>(instance_def: ty::InstanceDef<'tcx>) -> DepConstructor<'tcx> {
772 DepConstructor::MirShim {
777 fn symbol_name_dep_node<'tcx>(instance: ty::Instance<'tcx>) -> DepConstructor<'tcx> {
778 DepConstructor::InstanceSymbolName { instance }
781 fn typeck_item_bodies_dep_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
782 DepConstructor::TypeckBodiesKrate
785 fn const_eval_dep_node<'tcx>(param_env: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>)
786 -> DepConstructor<'tcx> {
787 DepConstructor::ConstEval { param_env }
789 fn const_eval_raw_dep_node<'tcx>(param_env: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>)
790 -> DepConstructor<'tcx> {
791 DepConstructor::ConstEvalRaw { param_env }
794 fn mir_keys<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
795 DepConstructor::MirKeys
798 fn crate_variances<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
799 DepConstructor::CrateVariances
802 fn is_copy_dep_node<'tcx>(param_env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> DepConstructor<'tcx> {
803 DepConstructor::IsCopy { param_env }
806 fn is_sized_dep_node<'tcx>(param_env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> DepConstructor<'tcx> {
807 DepConstructor::IsSized { param_env }
810 fn is_freeze_dep_node<'tcx>(param_env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> DepConstructor<'tcx> {
811 DepConstructor::IsFreeze { param_env }
814 fn needs_drop_dep_node<'tcx>(param_env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> DepConstructor<'tcx> {
815 DepConstructor::NeedsDrop { param_env }
818 fn layout_dep_node<'tcx>(param_env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> DepConstructor<'tcx> {
819 DepConstructor::Layout { param_env }
822 fn lint_levels_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
823 DepConstructor::LintLevels
826 fn specializes_node<'tcx>((a, b): (DefId, DefId)) -> DepConstructor<'tcx> {
827 DepConstructor::Specializes { impl1: a, impl2: b }
830 fn implementations_of_trait_node<'tcx>((krate, trait_id): (CrateNum, DefId))
831 -> DepConstructor<'tcx>
833 DepConstructor::ImplementationsOfTrait { krate, trait_id }
836 fn link_args_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
837 DepConstructor::LinkArgs
840 fn get_lib_features_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
841 DepConstructor::GetLibFeatures
844 fn get_lang_items_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
845 DepConstructor::GetLangItems
848 fn visible_parent_map_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
849 DepConstructor::VisibleParentMap
852 fn postorder_cnums_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
853 DepConstructor::PostorderCnums
856 fn maybe_unused_extern_crates_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
857 DepConstructor::MaybeUnusedExternCrates
860 fn stability_index_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
861 DepConstructor::StabilityIndex
864 fn all_crate_nums_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
865 DepConstructor::AllCrateNums
868 fn all_traits_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
869 DepConstructor::AllTraits
872 fn collect_and_partition_mono_items_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
873 DepConstructor::CollectAndPartitionMonoItems
876 fn output_filenames_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
877 DepConstructor::OutputFilenames
880 fn vtable_methods_node<'tcx>(trait_ref: ty::PolyTraitRef<'tcx>) -> DepConstructor<'tcx> {
881 DepConstructor::VtableMethods{ trait_ref }
884 fn substitute_normalize_and_test_predicates_node<'tcx>(key: (DefId, &'tcx Substs<'tcx>))
885 -> DepConstructor<'tcx> {
886 DepConstructor::SubstituteNormalizeAndTestPredicates { key }
889 fn target_features_whitelist_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
890 DepConstructor::TargetFeaturesWhitelist
893 fn instance_def_size_estimate_dep_node<'tcx>(instance_def: ty::InstanceDef<'tcx>)
894 -> DepConstructor<'tcx> {
895 DepConstructor::InstanceDefSizeEstimate {