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};
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;
21 use crate::mir::interpret::GlobalId;
22 use crate::session::{CompileResult, 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,
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};
38 use crate::ty::steal::Steal;
39 use crate::ty::subst::Substs;
40 use crate::util::nodemap::{DefIdSet, DefIdMap, ItemLocalSet};
41 use crate::util::common::{ErrorReported};
42 use crate::util::profiling::ProfileCategory::*;
43 use crate::session::Session;
45 use errors::DiagnosticBuilder;
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;
58 use std::intrinsics::type_name;
59 use syntax_pos::{Span, DUMMY_SP};
60 use syntax_pos::symbol::InternedString;
63 use syntax::feature_gate;
64 use syntax::symbol::Symbol;
68 use self::plumbing::*;
69 pub use self::plumbing::{force_from_dep_node, CycleError};
72 pub use self::job::{QueryJob, QueryInfo};
73 #[cfg(parallel_compiler)]
74 pub use self::job::handle_deadlock;
80 use self::values::Value;
83 pub use self::config::QueryConfig;
84 use self::config::{QueryAccessors, QueryDescription};
87 pub use self::on_disk_cache::OnDiskCache;
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).
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>
102 /// Records the type of every item.
103 [] fn type_of: TypeOfItem(DefId) -> Ty<'tcx>,
105 /// Maps from the `DefId` of an item (trait/struct/enum/fn) to its
106 /// associated generics.
107 [] fn generics_of: GenericsOfItem(DefId) -> &'tcx ty::Generics,
109 /// Maps from the `DefId` 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"
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
124 [] fn predicates_of: PredicatesOfItem(DefId) -> Lrc<ty::GenericPredicates<'tcx>>,
126 /// Maps from the `DefId` 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)
131 -> Lrc<ty::GenericPredicates<'tcx>>,
133 /// Returns the predicates written explicit by the user.
134 [] fn explicit_predicates_of: ExplicitPredicatesOfItem(DefId)
135 -> Lrc<ty::GenericPredicates<'tcx>>,
137 /// Returns the inferred outlives predicates (e.g., for `struct
138 /// Foo<'a, T> { x: &'a T }`, this would return `T: 'a`).
139 [] fn inferred_outlives_of: InferredOutlivesOf(DefId) -> Lrc<Vec<ty::Predicate<'tcx>>>,
141 /// Maps from the `DefId` of a trait to the list of
142 /// super-predicates. This is a subset of the full list of
143 /// predicates. We store these in a separate map because we must
144 /// evaluate them even during type conversion, often before the
145 /// full predicates are available (note that supertraits have
146 /// additional acyclicity requirements).
147 [] fn super_predicates_of: SuperPredicatesOfItem(DefId) -> Lrc<ty::GenericPredicates<'tcx>>,
149 /// To avoid cycles within the predicates of a single item we compute
150 /// per-type-parameter predicates for resolving `T::AssocTy`.
151 [] fn type_param_predicates: type_param_predicates((DefId, DefId))
152 -> Lrc<ty::GenericPredicates<'tcx>>,
154 [] fn trait_def: TraitDefOfItem(DefId) -> &'tcx ty::TraitDef,
155 [] fn adt_def: AdtDefOfItem(DefId) -> &'tcx ty::AdtDef,
156 [] fn adt_destructor: AdtDestructor(DefId) -> Option<ty::Destructor>,
157 [] fn adt_sized_constraint: SizedConstraint(DefId) -> &'tcx [Ty<'tcx>],
158 [] fn adt_dtorck_constraint: DtorckConstraint(
160 ) -> Result<DtorckConstraint<'tcx>, NoSolution>,
162 /// True if this is a const fn, use the `is_const_fn` to know whether your crate actually
163 /// sees it as const fn (e.g., the const-fn-ness might be unstable and you might not have
164 /// the feature gate active)
166 /// **Do not call this function manually.** It is only meant to cache the base data for the
167 /// `is_const_fn` function.
168 [] fn is_const_fn_raw: IsConstFn(DefId) -> bool,
171 /// Returns true if calls to the function may be promoted
173 /// This is either because the function is e.g., a tuple-struct or tuple-variant
174 /// constructor, or because it has the `#[rustc_promotable]` attribute. The attribute should
175 /// be removed in the future in favour of some form of check which figures out whether the
176 /// function does not inspect the bits of any of its arguments (so is essentially just a
177 /// constructor function).
178 [] fn is_promotable_const_fn: IsPromotableConstFn(DefId) -> bool,
180 /// True if this is a foreign item (i.e., linked via `extern { ... }`).
181 [] fn is_foreign_item: IsForeignItem(DefId) -> bool,
183 /// Get a map with the variance of every item; use `item_variance`
185 [] fn crate_variances: crate_variances(CrateNum) -> Lrc<ty::CrateVariancesMap>,
187 /// Maps from def-id of a type or region parameter to its
188 /// (inferred) variance.
189 [] fn variances_of: ItemVariances(DefId) -> Lrc<Vec<ty::Variance>>,
193 /// Maps from def-id of a type to its (inferred) outlives.
194 [] fn inferred_outlives_crate: InferredOutlivesCrate(CrateNum)
195 -> Lrc<ty::CratePredicatesMap<'tcx>>,
199 /// Maps from an impl/trait def-id to a list of the def-ids of its items
200 [] fn associated_item_def_ids: AssociatedItemDefIds(DefId) -> Lrc<Vec<DefId>>,
202 /// Maps from a trait item to the trait item "descriptor"
203 [] fn associated_item: AssociatedItems(DefId) -> ty::AssociatedItem,
205 [] fn impl_trait_ref: ImplTraitRef(DefId) -> Option<ty::TraitRef<'tcx>>,
206 [] fn impl_polarity: ImplPolarity(DefId) -> hir::ImplPolarity,
208 [] fn issue33140_self_ty: Issue33140SelfTy(DefId) -> Option<ty::Ty<'tcx>>,
212 /// Maps a DefId of a type to a list of its inherent impls.
213 /// Contains implementations of methods that are inherent to a type.
214 /// Methods in these implementations don't need to be exported.
215 [] fn inherent_impls: InherentImpls(DefId) -> Lrc<Vec<DefId>>,
219 /// Set of all the `DefId`s in this crate that have MIR associated with
220 /// them. This includes all the body owners, but also things like struct
222 [] fn mir_keys: mir_keys(CrateNum) -> Lrc<DefIdSet>,
224 /// Maps DefId's that have an associated Mir to the result
225 /// of the MIR qualify_consts pass. The actual meaning of
226 /// the value isn't known except to the pass itself.
227 [] fn mir_const_qualif: MirConstQualif(DefId) -> (u8, Lrc<BitSet<mir::Local>>),
229 /// Fetch the MIR for a given `DefId` right after it's built - this includes
230 /// unreachable code.
231 [] fn mir_built: MirBuilt(DefId) -> &'tcx Steal<mir::Mir<'tcx>>,
233 /// Fetch the MIR for a given `DefId` up till the point where it is
234 /// ready for const evaluation.
236 /// See the README for the `mir` module for details.
237 [no_hash] fn mir_const: MirConst(DefId) -> &'tcx Steal<mir::Mir<'tcx>>,
239 [no_hash] fn mir_validated: MirValidated(DefId) -> &'tcx Steal<mir::Mir<'tcx>>,
241 /// MIR after our optimization passes have run. This is MIR that is ready
242 /// for codegen. This is also the only query that can fetch non-local MIR, at present.
243 [] fn optimized_mir: MirOptimized(DefId) -> &'tcx mir::Mir<'tcx>,
247 /// The result of unsafety-checking this `DefId`.
248 [] fn unsafety_check_result: UnsafetyCheckResult(DefId) -> mir::UnsafetyCheckResult,
250 /// HACK: when evaluated, this reports a "unsafe derive on repr(packed)" error
251 [] fn unsafe_derive_on_repr_packed: UnsafeDeriveOnReprPacked(DefId) -> (),
253 /// The signature of functions and closures.
254 [] fn fn_sig: FnSignature(DefId) -> ty::PolyFnSig<'tcx>,
258 /// Checks the attributes in the module
259 [] fn check_mod_attrs: CheckModAttrs(DefId) -> (),
261 [] fn check_mod_unstable_api_usage: CheckModUnstableApiUsage(DefId) -> (),
263 /// Checks the loops in the module
264 [] fn check_mod_loops: CheckModLoops(DefId) -> (),
266 [] fn check_mod_item_types: CheckModItemTypes(DefId) -> (),
268 [] fn check_mod_privacy: CheckModPrivacy(DefId) -> (),
270 [] fn check_mod_intrinsics: CheckModIntrinsics(DefId) -> (),
272 [] fn check_mod_liveness: CheckModLiveness(DefId) -> (),
274 [] fn check_mod_impl_wf: CheckModImplWf(DefId) -> (),
276 [] fn collect_mod_item_types: CollectModItemTypes(DefId) -> (),
278 /// Caches CoerceUnsized kinds for impls on custom types.
279 [] fn coerce_unsized_info: CoerceUnsizedInfo(DefId)
280 -> ty::adjustment::CoerceUnsizedInfo,
284 [] fn typeck_item_bodies: typeck_item_bodies_dep_node(CrateNum) -> CompileResult,
286 [] fn typeck_tables_of: TypeckTables(DefId) -> &'tcx ty::TypeckTables<'tcx>,
290 [] fn used_trait_imports: UsedTraitImports(DefId) -> Lrc<DefIdSet>,
294 [] fn has_typeck_tables: HasTypeckTables(DefId) -> bool,
296 [] fn coherent_trait: CoherenceCheckTrait(DefId) -> (),
300 [] fn borrowck: BorrowCheck(DefId) -> Lrc<BorrowCheckResult>,
302 /// Borrow checks the function body. If this is a closure, returns
303 /// additional requirements that the closure's creator must verify.
304 [] fn mir_borrowck: MirBorrowCheck(DefId) -> mir::BorrowCheckResult<'tcx>,
308 /// Gets a complete map from all types to their inherent impls.
309 /// Not meant to be used directly outside of coherence.
310 /// (Defined only for `LOCAL_CRATE`.)
311 [] fn crate_inherent_impls: crate_inherent_impls_dep_node(CrateNum)
312 -> Lrc<CrateInherentImpls>,
314 /// Checks all types in the crate for overlap in their inherent impls. Reports errors.
315 /// Not meant to be used directly outside of coherence.
316 /// (Defined only for `LOCAL_CRATE`.)
317 [] fn crate_inherent_impls_overlap_check: inherent_impls_overlap_check_dep_node(CrateNum)
322 /// Evaluate a constant without running sanity checks
324 /// **Do not use this** outside const eval. Const eval uses this to break query cycles
325 /// during validation. Please add a comment to every use site explaining why using
326 /// `const_eval` isn't sufficient
327 [] fn const_eval_raw: const_eval_raw_dep_node(ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>)
328 -> ConstEvalRawResult<'tcx>,
330 /// Results of evaluating const items or constants embedded in
331 /// other items (such as enum variant explicit discriminants).
332 [] fn const_eval: const_eval_dep_node(ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>)
333 -> ConstEvalResult<'tcx>,
337 [] fn check_match: CheckMatch(DefId)
338 -> Result<(), ErrorReported>,
340 /// Performs the privacy check and computes "access levels".
341 [] fn privacy_access_levels: PrivacyAccessLevels(CrateNum) -> Lrc<AccessLevels>,
345 [] fn reachable_set: reachability_dep_node(CrateNum) -> ReachableSet,
347 /// Per-body `region::ScopeTree`. The `DefId` should be the owner `DefId` for the body;
348 /// in the case of closures, this will be redirected to the enclosing function.
349 [] fn region_scope_tree: RegionScopeTree(DefId) -> Lrc<region::ScopeTree>,
351 [] fn mir_shims: mir_shim_dep_node(ty::InstanceDef<'tcx>) -> &'tcx mir::Mir<'tcx>,
353 [] fn def_symbol_name: SymbolName(DefId) -> ty::SymbolName,
354 [] fn symbol_name: symbol_name_dep_node(ty::Instance<'tcx>) -> ty::SymbolName,
356 [] fn describe_def: DescribeDef(DefId) -> Option<Def>,
357 [] fn def_span: DefSpan(DefId) -> Span,
358 [] fn lookup_stability: LookupStability(DefId) -> Option<&'tcx attr::Stability>,
359 [] fn lookup_deprecation_entry: LookupDeprecationEntry(DefId) -> Option<DeprecationEntry>,
360 [] fn item_attrs: ItemAttrs(DefId) -> Lrc<[ast::Attribute]>,
364 [] fn codegen_fn_attrs: codegen_fn_attrs(DefId) -> CodegenFnAttrs,
368 [] fn fn_arg_names: FnArgNames(DefId) -> Vec<ast::Name>,
369 /// Gets the rendered value of the specified constant or associated constant.
371 [] fn rendered_const: RenderedConst(DefId) -> String,
372 [] fn impl_parent: ImplParent(DefId) -> Option<DefId>,
376 [] fn trait_of_item: TraitOfItem(DefId) -> Option<DefId>,
377 [] fn const_is_rvalue_promotable_to_static: ConstIsRvaluePromotableToStatic(DefId) -> bool,
378 [] fn rvalue_promotable_map: RvaluePromotableMap(DefId) -> Lrc<ItemLocalSet>,
382 [] fn is_mir_available: IsMirAvailable(DefId) -> bool,
386 [] fn vtable_methods: vtable_methods_node(ty::PolyTraitRef<'tcx>)
387 -> Lrc<Vec<Option<(DefId, &'tcx Substs<'tcx>)>>>,
391 [] fn codegen_fulfill_obligation: fulfill_obligation_dep_node(
392 (ty::ParamEnv<'tcx>, ty::PolyTraitRef<'tcx>)) -> Vtable<'tcx, ()>,
396 [] fn trait_impls_of: TraitImpls(DefId) -> Lrc<ty::trait_def::TraitImpls>,
397 [] fn specialization_graph_of: SpecializationGraph(DefId)
398 -> Lrc<specialization_graph::Graph>,
399 [] fn is_object_safe: ObjectSafety(DefId) -> bool,
401 /// Gets the ParameterEnvironment for a given item; this environment
402 /// will be in "user-facing" mode, meaning that it is suitabe for
403 /// type-checking etc, and it does not normalize specializable
404 /// associated types. This is almost always what you want,
405 /// unless you are doing MIR optimizations, in which case you
406 /// might want to use `reveal_all()` method to change modes.
407 [] fn param_env: ParamEnv(DefId) -> ty::ParamEnv<'tcx>,
409 /// Trait selection queries. These are best used by invoking `ty.is_copy_modulo_regions()`,
410 /// `ty.is_copy()`, etc, since that will prune the environment where possible.
411 [] fn is_copy_raw: is_copy_dep_node(ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool,
412 [] fn is_sized_raw: is_sized_dep_node(ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool,
413 [] fn is_freeze_raw: is_freeze_dep_node(ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool,
414 [] fn needs_drop_raw: needs_drop_dep_node(ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool,
415 [] fn layout_raw: layout_dep_node(ty::ParamEnvAnd<'tcx, Ty<'tcx>>)
416 -> Result<&'tcx ty::layout::LayoutDetails,
417 ty::layout::LayoutError<'tcx>>,
421 [] fn dylib_dependency_formats: DylibDepFormats(CrateNum)
422 -> Lrc<Vec<(CrateNum, LinkagePreference)>>,
426 [fatal_cycle] fn is_panic_runtime: IsPanicRuntime(CrateNum) -> bool,
427 [fatal_cycle] fn is_compiler_builtins: IsCompilerBuiltins(CrateNum) -> bool,
428 [fatal_cycle] fn has_global_allocator: HasGlobalAllocator(CrateNum) -> bool,
429 [fatal_cycle] fn has_panic_handler: HasPanicHandler(CrateNum) -> bool,
430 [fatal_cycle] fn is_sanitizer_runtime: IsSanitizerRuntime(CrateNum) -> bool,
431 [fatal_cycle] fn is_profiler_runtime: IsProfilerRuntime(CrateNum) -> bool,
432 [fatal_cycle] fn panic_strategy: GetPanicStrategy(CrateNum) -> PanicStrategy,
433 [fatal_cycle] fn is_no_builtins: IsNoBuiltins(CrateNum) -> bool,
435 [] fn extern_crate: ExternCrate(DefId) -> Lrc<Option<ExternCrate>>,
439 [] fn specializes: specializes_node((DefId, DefId)) -> bool,
440 [] fn in_scope_traits_map: InScopeTraits(DefIndex)
441 -> Option<Lrc<FxHashMap<ItemLocalId, Lrc<StableVec<TraitCandidate>>>>>,
445 [] fn module_exports: ModuleExports(DefId) -> Option<Lrc<Vec<Export>>>,
446 [] fn lint_levels: lint_levels_node(CrateNum) -> Lrc<lint::LintLevelMap>,
450 [] fn impl_defaultness: ImplDefaultness(DefId) -> hir::Defaultness,
452 [] fn check_item_well_formed: CheckItemWellFormed(DefId) -> (),
453 [] fn check_trait_item_well_formed: CheckTraitItemWellFormed(DefId) -> (),
454 [] fn check_impl_item_well_formed: CheckImplItemWellFormed(DefId) -> (),
458 // The DefIds of all non-generic functions and statics in the given crate
459 // that can be reached from outside the crate.
461 // We expect this items to be available for being linked to.
463 // This query can also be called for LOCAL_CRATE. In this case it will
464 // compute which items will be reachable to other crates, taking into account
465 // the kind of crate that is currently compiled. Crates with only a
466 // C interface have fewer reachable things.
468 // Does not include external symbols that don't have a corresponding DefId,
469 // like the compiler-generated `main` function and so on.
470 [] fn reachable_non_generics: ReachableNonGenerics(CrateNum)
471 -> Lrc<DefIdMap<SymbolExportLevel>>,
472 [] fn is_reachable_non_generic: IsReachableNonGeneric(DefId) -> bool,
473 [] fn is_unreachable_local_definition: IsUnreachableLocalDefinition(DefId) -> bool,
477 [] fn upstream_monomorphizations: UpstreamMonomorphizations(CrateNum)
478 -> Lrc<DefIdMap<Lrc<FxHashMap<&'tcx Substs<'tcx>, CrateNum>>>>,
479 [] fn upstream_monomorphizations_for: UpstreamMonomorphizationsFor(DefId)
480 -> Option<Lrc<FxHashMap<&'tcx Substs<'tcx>, CrateNum>>>,
484 [] fn native_libraries: NativeLibraries(CrateNum) -> Lrc<Vec<NativeLibrary>>,
486 [] fn foreign_modules: ForeignModules(CrateNum) -> Lrc<Vec<ForeignModule>>,
488 /// Identifies the entry-point (e.g., the `main` function) for a given
489 /// crate, returning `None` if there is no entry point (such as for library crates).
490 [] fn entry_fn: EntryFn(CrateNum) -> Option<(DefId, EntryFnType)>,
491 [] fn plugin_registrar_fn: PluginRegistrarFn(CrateNum) -> Option<DefId>,
492 [] fn proc_macro_decls_static: ProcMacroDeclsStatic(CrateNum) -> Option<DefId>,
493 [] fn crate_disambiguator: CrateDisambiguator(CrateNum) -> CrateDisambiguator,
494 [] fn crate_hash: CrateHash(CrateNum) -> Svh,
495 [] fn original_crate_name: OriginalCrateName(CrateNum) -> Symbol,
496 [] fn extra_filename: ExtraFileName(CrateNum) -> String,
500 [] fn implementations_of_trait: implementations_of_trait_node((CrateNum, DefId))
502 [] fn all_trait_implementations: AllTraitImplementations(CrateNum)
507 [] fn dllimport_foreign_items: DllimportForeignItems(CrateNum)
508 -> Lrc<FxHashSet<DefId>>,
509 [] fn is_dllimport_foreign_item: IsDllimportForeignItem(DefId) -> bool,
510 [] fn is_statically_included_foreign_item: IsStaticallyIncludedForeignItem(DefId) -> bool,
511 [] fn native_library_kind: NativeLibraryKind(DefId)
512 -> Option<NativeLibraryKind>,
516 [] fn link_args: link_args_node(CrateNum) -> Lrc<Vec<String>>,
520 // Lifetime resolution. See `middle::resolve_lifetimes`.
521 [] fn resolve_lifetimes: ResolveLifetimes(CrateNum) -> Lrc<ResolveLifetimes>,
522 [] fn named_region_map: NamedRegion(DefIndex) ->
523 Option<Lrc<FxHashMap<ItemLocalId, Region>>>,
524 [] fn is_late_bound_map: IsLateBound(DefIndex) ->
525 Option<Lrc<FxHashSet<ItemLocalId>>>,
526 [] fn object_lifetime_defaults_map: ObjectLifetimeDefaults(DefIndex)
527 -> Option<Lrc<FxHashMap<ItemLocalId, Lrc<Vec<ObjectLifetimeDefault>>>>>,
531 [] fn visibility: Visibility(DefId) -> ty::Visibility,
535 [] fn dep_kind: DepKind(CrateNum) -> DepKind,
536 [] fn crate_name: CrateName(CrateNum) -> Symbol,
537 [] fn item_children: ItemChildren(DefId) -> Lrc<Vec<Export>>,
538 [] fn extern_mod_stmt_cnum: ExternModStmtCnum(DefId) -> Option<CrateNum>,
540 [] fn get_lib_features: get_lib_features_node(CrateNum) -> Lrc<LibFeatures>,
541 [] fn defined_lib_features: DefinedLibFeatures(CrateNum)
542 -> Lrc<Vec<(Symbol, Option<Symbol>)>>,
543 [] fn get_lang_items: get_lang_items_node(CrateNum) -> Lrc<LanguageItems>,
544 [] fn defined_lang_items: DefinedLangItems(CrateNum) -> Lrc<Vec<(DefId, usize)>>,
545 [] fn missing_lang_items: MissingLangItems(CrateNum) -> Lrc<Vec<LangItem>>,
546 [] fn visible_parent_map: visible_parent_map_node(CrateNum)
547 -> Lrc<DefIdMap<DefId>>,
548 [] fn missing_extern_crate_item: MissingExternCrateItem(CrateNum) -> bool,
549 [] fn used_crate_source: UsedCrateSource(CrateNum) -> Lrc<CrateSource>,
550 [] fn postorder_cnums: postorder_cnums_node(CrateNum) -> Lrc<Vec<CrateNum>>,
552 [] fn freevars: Freevars(DefId) -> Option<Lrc<Vec<hir::Freevar>>>,
553 [] fn maybe_unused_trait_import: MaybeUnusedTraitImport(DefId) -> bool,
554 [] fn maybe_unused_extern_crates: maybe_unused_extern_crates_node(CrateNum)
555 -> Lrc<Vec<(DefId, Span)>>,
556 [] fn names_imported_by_glob_use: NamesImportedByGlobUse(DefId)
557 -> Lrc<FxHashSet<ast::Name>>,
559 [] fn stability_index: stability_index_node(CrateNum) -> Lrc<stability::Index<'tcx>>,
560 [] fn all_crate_nums: all_crate_nums_node(CrateNum) -> Lrc<Vec<CrateNum>>,
562 /// A vector of every trait accessible in the whole crate
563 /// (i.e., including those from subcrates). This is used only for
565 [] fn all_traits: all_traits_node(CrateNum) -> Lrc<Vec<DefId>>,
569 [] fn exported_symbols: ExportedSymbols(CrateNum)
570 -> Arc<Vec<(ExportedSymbol<'tcx>, SymbolExportLevel)>>,
574 [] fn collect_and_partition_mono_items:
575 collect_and_partition_mono_items_node(CrateNum)
576 -> (Arc<DefIdSet>, Arc<Vec<Arc<CodegenUnit<'tcx>>>>),
577 [] fn is_codegened_item: IsCodegenedItem(DefId) -> bool,
578 [] fn codegen_unit: CodegenUnit(InternedString) -> Arc<CodegenUnit<'tcx>>,
579 [] fn backend_optimization_level: BackendOptimizationLevel(CrateNum) -> OptLevel,
583 [] fn output_filenames: output_filenames_node(CrateNum)
584 -> Arc<OutputFilenames>,
588 // Erases regions from `ty` to yield a new type.
589 // Normally you would just use `tcx.erase_regions(&value)`,
590 // however, which uses this query as a kind of cache.
591 [] fn erase_regions_ty: erase_regions_ty(Ty<'tcx>) -> Ty<'tcx>,
593 /// Do not call this query directly: invoke `normalize` instead.
594 [] fn normalize_projection_ty: NormalizeProjectionTy(
595 CanonicalProjectionGoal<'tcx>
597 Lrc<Canonical<'tcx, canonical::QueryResponse<'tcx, NormalizationResult<'tcx>>>>,
601 /// Do not call this query directly: invoke `normalize_erasing_regions` instead.
602 [] fn normalize_ty_after_erasing_regions: NormalizeTyAfterErasingRegions(
603 ParamEnvAnd<'tcx, Ty<'tcx>>
606 [] fn implied_outlives_bounds: ImpliedOutlivesBounds(
607 CanonicalTyGoal<'tcx>
609 Lrc<Canonical<'tcx, canonical::QueryResponse<'tcx, Vec<OutlivesBound<'tcx>>>>>,
613 /// Do not call this query directly: invoke `infcx.at().dropck_outlives()` instead.
614 [] fn dropck_outlives: DropckOutlives(
615 CanonicalTyGoal<'tcx>
617 Lrc<Canonical<'tcx, canonical::QueryResponse<'tcx, DropckOutlivesResult<'tcx>>>>,
621 /// Do not call this query directly: invoke `infcx.predicate_may_hold()` or
622 /// `infcx.predicate_must_hold()` instead.
623 [] fn evaluate_obligation: EvaluateObligation(
624 CanonicalPredicateGoal<'tcx>
625 ) -> Result<traits::EvaluationResult, traits::OverflowError>,
627 [] fn evaluate_goal: EvaluateGoal(
628 traits::ChalkCanonicalGoal<'tcx>
630 Lrc<Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>>,
634 /// Do not call this query directly: part of the `Eq` type-op
635 [] fn type_op_ascribe_user_type: TypeOpAscribeUserType(
636 CanonicalTypeOpAscribeUserTypeGoal<'tcx>
638 Lrc<Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>>,
642 /// Do not call this query directly: part of the `Eq` type-op
643 [] fn type_op_eq: TypeOpEq(
644 CanonicalTypeOpEqGoal<'tcx>
646 Lrc<Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>>,
650 /// Do not call this query directly: part of the `Subtype` type-op
651 [] fn type_op_subtype: TypeOpSubtype(
652 CanonicalTypeOpSubtypeGoal<'tcx>
654 Lrc<Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>>,
658 /// Do not call this query directly: part of the `ProvePredicate` type-op
659 [] fn type_op_prove_predicate: TypeOpProvePredicate(
660 CanonicalTypeOpProvePredicateGoal<'tcx>
662 Lrc<Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>>,
666 /// Do not call this query directly: part of the `Normalize` type-op
667 [] fn type_op_normalize_ty: TypeOpNormalizeTy(
668 CanonicalTypeOpNormalizeGoal<'tcx, Ty<'tcx>>
670 Lrc<Canonical<'tcx, canonical::QueryResponse<'tcx, Ty<'tcx>>>>,
674 /// Do not call this query directly: part of the `Normalize` type-op
675 [] fn type_op_normalize_predicate: TypeOpNormalizePredicate(
676 CanonicalTypeOpNormalizeGoal<'tcx, ty::Predicate<'tcx>>
678 Lrc<Canonical<'tcx, canonical::QueryResponse<'tcx, ty::Predicate<'tcx>>>>,
682 /// Do not call this query directly: part of the `Normalize` type-op
683 [] fn type_op_normalize_poly_fn_sig: TypeOpNormalizePolyFnSig(
684 CanonicalTypeOpNormalizeGoal<'tcx, ty::PolyFnSig<'tcx>>
686 Lrc<Canonical<'tcx, canonical::QueryResponse<'tcx, ty::PolyFnSig<'tcx>>>>,
690 /// Do not call this query directly: part of the `Normalize` type-op
691 [] fn type_op_normalize_fn_sig: TypeOpNormalizeFnSig(
692 CanonicalTypeOpNormalizeGoal<'tcx, ty::FnSig<'tcx>>
694 Lrc<Canonical<'tcx, canonical::QueryResponse<'tcx, ty::FnSig<'tcx>>>>,
698 [] fn substitute_normalize_and_test_predicates:
699 substitute_normalize_and_test_predicates_node((DefId, &'tcx Substs<'tcx>)) -> bool,
701 [] fn method_autoderef_steps: MethodAutoderefSteps(
702 CanonicalTyGoal<'tcx>
703 ) -> MethodAutoderefStepsResult<'tcx>,
707 [] fn target_features_whitelist:
708 target_features_whitelist_node(CrateNum) -> Lrc<FxHashMap<String, Option<String>>>,
710 // Get an estimate of the size of an InstanceDef based on its MIR for CGU partitioning.
711 [] fn instance_def_size_estimate: instance_def_size_estimate_dep_node(ty::InstanceDef<'tcx>)
714 [] fn features_query: features_node(CrateNum) -> Lrc<feature_gate::Features>,
718 [] fn program_clauses_for: ProgramClausesFor(DefId) -> Clauses<'tcx>,
720 [] fn program_clauses_for_env: ProgramClausesForEnv(
721 traits::Environment<'tcx>
724 // Get the chalk-style environment of the given item.
725 [] fn environment: Environment(DefId) -> traits::Environment<'tcx>,
729 [] fn wasm_import_module_map: WasmImportModuleMap(CrateNum)
730 -> Lrc<FxHashMap<DefId, String>>,
734 // `try_get_query` can't be public because it uses the private query
735 // implementation traits, so we provide access to it selectively.
736 impl<'a, 'tcx, 'lcx> TyCtxt<'a, 'tcx, 'lcx> {
737 pub fn try_adt_sized_constraint(
741 ) -> Result<&'tcx [Ty<'tcx>], Box<DiagnosticBuilder<'a>>> {
742 self.try_get_query::<queries::adt_sized_constraint<'_>>(span, key)
744 pub fn try_needs_drop_raw(
747 key: ty::ParamEnvAnd<'tcx, Ty<'tcx>>,
748 ) -> Result<bool, Box<DiagnosticBuilder<'a>>> {
749 self.try_get_query::<queries::needs_drop_raw<'_>>(span, key)
751 pub fn try_optimized_mir(
755 ) -> Result<&'tcx mir::Mir<'tcx>, Box<DiagnosticBuilder<'a>>> {
756 self.try_get_query::<queries::optimized_mir<'_>>(span, key)
760 //////////////////////////////////////////////////////////////////////
761 // These functions are little shims used to find the dep-node for a
762 // given query when there is not a *direct* mapping:
765 fn features_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
766 DepConstructor::Features
769 fn codegen_fn_attrs<'tcx>(id: DefId) -> DepConstructor<'tcx> {
770 DepConstructor::CodegenFnAttrs { 0: id }
773 fn erase_regions_ty<'tcx>(ty: Ty<'tcx>) -> DepConstructor<'tcx> {
774 DepConstructor::EraseRegionsTy { ty }
777 fn type_param_predicates<'tcx>((item_id, param_id): (DefId, DefId)) -> DepConstructor<'tcx> {
778 DepConstructor::TypeParamPredicates {
784 fn fulfill_obligation_dep_node<'tcx>((param_env, trait_ref):
785 (ty::ParamEnv<'tcx>, ty::PolyTraitRef<'tcx>)) -> DepConstructor<'tcx> {
786 DepConstructor::FulfillObligation {
792 fn crate_inherent_impls_dep_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
793 DepConstructor::Coherence
796 fn inherent_impls_overlap_check_dep_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
797 DepConstructor::CoherenceInherentImplOverlapCheck
800 fn reachability_dep_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
801 DepConstructor::Reachability
804 fn mir_shim_dep_node<'tcx>(instance_def: ty::InstanceDef<'tcx>) -> DepConstructor<'tcx> {
805 DepConstructor::MirShim {
810 fn symbol_name_dep_node<'tcx>(instance: ty::Instance<'tcx>) -> DepConstructor<'tcx> {
811 DepConstructor::InstanceSymbolName { instance }
814 fn typeck_item_bodies_dep_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
815 DepConstructor::TypeckBodiesKrate
818 fn const_eval_dep_node<'tcx>(param_env: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>)
819 -> DepConstructor<'tcx> {
820 DepConstructor::ConstEval { param_env }
822 fn const_eval_raw_dep_node<'tcx>(param_env: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>)
823 -> DepConstructor<'tcx> {
824 DepConstructor::ConstEvalRaw { param_env }
827 fn mir_keys<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
828 DepConstructor::MirKeys
831 fn crate_variances<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
832 DepConstructor::CrateVariances
835 fn is_copy_dep_node<'tcx>(param_env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> DepConstructor<'tcx> {
836 DepConstructor::IsCopy { param_env }
839 fn is_sized_dep_node<'tcx>(param_env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> DepConstructor<'tcx> {
840 DepConstructor::IsSized { param_env }
843 fn is_freeze_dep_node<'tcx>(param_env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> DepConstructor<'tcx> {
844 DepConstructor::IsFreeze { param_env }
847 fn needs_drop_dep_node<'tcx>(param_env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> DepConstructor<'tcx> {
848 DepConstructor::NeedsDrop { param_env }
851 fn layout_dep_node<'tcx>(param_env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> DepConstructor<'tcx> {
852 DepConstructor::Layout { param_env }
855 fn lint_levels_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
856 DepConstructor::LintLevels
859 fn specializes_node<'tcx>((a, b): (DefId, DefId)) -> DepConstructor<'tcx> {
860 DepConstructor::Specializes { impl1: a, impl2: b }
863 fn implementations_of_trait_node<'tcx>((krate, trait_id): (CrateNum, DefId))
864 -> DepConstructor<'tcx>
866 DepConstructor::ImplementationsOfTrait { krate, trait_id }
869 fn link_args_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
870 DepConstructor::LinkArgs
873 fn get_lib_features_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
874 DepConstructor::GetLibFeatures
877 fn get_lang_items_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
878 DepConstructor::GetLangItems
881 fn visible_parent_map_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
882 DepConstructor::VisibleParentMap
885 fn postorder_cnums_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
886 DepConstructor::PostorderCnums
889 fn maybe_unused_extern_crates_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
890 DepConstructor::MaybeUnusedExternCrates
893 fn stability_index_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
894 DepConstructor::StabilityIndex
897 fn all_crate_nums_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
898 DepConstructor::AllCrateNums
901 fn all_traits_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
902 DepConstructor::AllTraits
905 fn collect_and_partition_mono_items_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
906 DepConstructor::CollectAndPartitionMonoItems
909 fn output_filenames_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
910 DepConstructor::OutputFilenames
913 fn vtable_methods_node<'tcx>(trait_ref: ty::PolyTraitRef<'tcx>) -> DepConstructor<'tcx> {
914 DepConstructor::VtableMethods{ trait_ref }
917 fn substitute_normalize_and_test_predicates_node<'tcx>(key: (DefId, &'tcx Substs<'tcx>))
918 -> DepConstructor<'tcx> {
919 DepConstructor::SubstituteNormalizeAndTestPredicates { key }
922 fn target_features_whitelist_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
923 DepConstructor::TargetFeaturesWhitelist
926 fn instance_def_size_estimate_dep_node<'tcx>(instance_def: ty::InstanceDef<'tcx>)
927 -> DepConstructor<'tcx> {
928 DepConstructor::InstanceDefSizeEstimate {