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::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) -> 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) -> ty::GenericPredicates<'tcx>,
138 /// Returns the predicates written explicit by the user.
139 [] fn explicit_predicates_of: ExplicitPredicatesOfItem(DefId)
140 -> ty::GenericPredicates<'tcx>,
142 /// Returns the inferred outlives predicates (e.g., for `struct
143 /// Foo<'a, T> { x: &'a T }`, this would return `T: 'a`).
144 [] fn inferred_outlives_of: InferredOutlivesOf(DefId) -> Lrc<Vec<ty::Predicate<'tcx>>>,
146 /// Maps from the def-id of a trait to the list of
147 /// super-predicates. This is a subset of the full list of
148 /// predicates. We store these in a separate map because we must
149 /// evaluate them even during type conversion, often before the
150 /// full predicates are available (note that supertraits have
151 /// additional acyclicity requirements).
152 [] fn super_predicates_of: SuperPredicatesOfItem(DefId) -> ty::GenericPredicates<'tcx>,
154 /// To avoid cycles within the predicates of a single item we compute
155 /// per-type-parameter predicates for resolving `T::AssocTy`.
156 [] fn type_param_predicates: type_param_predicates((DefId, DefId))
157 -> ty::GenericPredicates<'tcx>,
159 [] fn trait_def: TraitDefOfItem(DefId) -> &'tcx ty::TraitDef,
160 [] fn adt_def: AdtDefOfItem(DefId) -> &'tcx ty::AdtDef,
161 [] fn adt_destructor: AdtDestructor(DefId) -> Option<ty::Destructor>,
162 [] fn adt_sized_constraint: SizedConstraint(DefId) -> &'tcx [Ty<'tcx>],
163 [] fn adt_dtorck_constraint: DtorckConstraint(
165 ) -> Result<DtorckConstraint<'tcx>, NoSolution>,
167 /// True if this is a const fn, use the `is_const_fn` to know whether your crate actually
168 /// sees it as const fn (e.g. the const-fn-ness might be unstable and you might not have
169 /// the feature gate active)
171 /// DO NOT CALL MANUALLY, it is only meant to cache the base data for the `is_const_fn`
173 [] fn is_const_fn_raw: IsConstFn(DefId) -> bool,
176 /// Returns true if calls to the function may be promoted
178 /// This is either because the function is e.g. a tuple-struct or tuple-variant constructor,
179 /// or because it has the `#[rustc_promotable]` attribute. The attribute should be removed
180 /// in the future in favour of some form of check which figures out whether the function
181 /// does not inspect the bits of any of its arguments (so is essentially just a constructor
183 [] fn is_promotable_const_fn: IsPromotableConstFn(DefId) -> bool,
185 /// True if this is a foreign item (i.e., linked via `extern { ... }`).
186 [] fn is_foreign_item: IsForeignItem(DefId) -> bool,
188 /// Get a map with the variance of every item; use `item_variance`
190 [] fn crate_variances: crate_variances(CrateNum) -> Lrc<ty::CrateVariancesMap>,
192 /// Maps from def-id of a type or region parameter to its
193 /// (inferred) variance.
194 [] fn variances_of: ItemVariances(DefId) -> Lrc<Vec<ty::Variance>>,
198 /// Maps from def-id of a type to its (inferred) outlives.
199 [] fn inferred_outlives_crate: InferredOutlivesCrate(CrateNum)
200 -> Lrc<ty::CratePredicatesMap<'tcx>>,
204 /// Maps from an impl/trait def-id to a list of the def-ids of its items
205 [] fn associated_item_def_ids: AssociatedItemDefIds(DefId) -> Lrc<Vec<DefId>>,
207 /// Maps from a trait item to the trait item "descriptor"
208 [] fn associated_item: AssociatedItems(DefId) -> ty::AssociatedItem,
210 [] fn impl_trait_ref: ImplTraitRef(DefId) -> Option<ty::TraitRef<'tcx>>,
211 [] fn impl_polarity: ImplPolarity(DefId) -> hir::ImplPolarity,
215 /// Maps a DefId of a type to a list of its inherent impls.
216 /// Contains implementations of methods that are inherent to a type.
217 /// Methods in these implementations don't need to be exported.
218 [] fn inherent_impls: InherentImpls(DefId) -> Lrc<Vec<DefId>>,
222 /// Set of all the def-ids in this crate that have MIR associated with
223 /// them. This includes all the body owners, but also things like struct
225 [] fn mir_keys: mir_keys(CrateNum) -> Lrc<DefIdSet>,
227 /// Maps DefId's that have an associated Mir to the result
228 /// of the MIR qualify_consts pass. The actual meaning of
229 /// the value isn't known except to the pass itself.
230 [] fn mir_const_qualif: MirConstQualif(DefId) -> (u8, Lrc<BitSet<mir::Local>>),
232 /// Fetch the MIR for a given def-id right after it's built - this includes
233 /// unreachable code.
234 [] fn mir_built: MirBuilt(DefId) -> &'tcx Steal<mir::Mir<'tcx>>,
236 /// Fetch the MIR for a given def-id up till the point where it is
237 /// ready for const evaluation.
239 /// See the README for the `mir` module for details.
240 [] fn mir_const: MirConst(DefId) -> &'tcx Steal<mir::Mir<'tcx>>,
242 [] fn mir_validated: MirValidated(DefId) -> &'tcx Steal<mir::Mir<'tcx>>,
244 /// MIR after our optimization passes have run. This is MIR that is ready
245 /// for codegen. This is also the only query that can fetch non-local MIR, at present.
246 [] fn optimized_mir: MirOptimized(DefId) -> &'tcx mir::Mir<'tcx>,
250 /// The result of unsafety-checking this def-id.
251 [] fn unsafety_check_result: UnsafetyCheckResult(DefId) -> mir::UnsafetyCheckResult,
253 /// HACK: when evaluated, this reports a "unsafe derive on repr(packed)" error
254 [] fn unsafe_derive_on_repr_packed: UnsafeDeriveOnReprPacked(DefId) -> (),
256 /// The signature of functions and closures.
257 [] fn fn_sig: FnSignature(DefId) -> ty::PolyFnSig<'tcx>,
261 /// Caches CoerceUnsized kinds for impls on custom types.
262 [] fn coerce_unsized_info: CoerceUnsizedInfo(DefId)
263 -> ty::adjustment::CoerceUnsizedInfo,
267 [] fn typeck_item_bodies: typeck_item_bodies_dep_node(CrateNum) -> CompileResult,
269 [] fn typeck_tables_of: TypeckTables(DefId) -> &'tcx ty::TypeckTables<'tcx>,
273 [] fn used_trait_imports: UsedTraitImports(DefId) -> Lrc<DefIdSet>,
277 [] fn has_typeck_tables: HasTypeckTables(DefId) -> bool,
279 [] fn coherent_trait: CoherenceCheckTrait(DefId) -> (),
283 [] fn borrowck: BorrowCheck(DefId) -> Lrc<BorrowCheckResult>,
285 /// Borrow checks the function body. If this is a closure, returns
286 /// additional requirements that the closure's creator must verify.
287 [] fn mir_borrowck: MirBorrowCheck(DefId) -> mir::BorrowCheckResult<'tcx>,
291 /// Gets a complete map from all types to their inherent impls.
292 /// Not meant to be used directly outside of coherence.
293 /// (Defined only for LOCAL_CRATE)
294 [] fn crate_inherent_impls: crate_inherent_impls_dep_node(CrateNum) -> CrateInherentImpls,
296 /// Checks all types in the krate for overlap in their inherent impls. Reports errors.
297 /// Not meant to be used directly outside of coherence.
298 /// (Defined only for LOCAL_CRATE)
299 [] fn crate_inherent_impls_overlap_check: inherent_impls_overlap_check_dep_node(CrateNum)
304 /// Evaluate a constant without running sanity checks
306 /// DO NOT USE THIS outside const eval. Const eval uses this to break query cycles during
307 /// validation. Please add a comment to every use site explaining why using `const_eval`
309 [] fn const_eval_raw: const_eval_raw_dep_node(ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>)
310 -> ConstEvalResult<'tcx>,
312 /// Results of evaluating const items or constants embedded in
313 /// other items (such as enum variant explicit discriminants).
314 [] fn const_eval: const_eval_dep_node(ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>)
315 -> ConstEvalResult<'tcx>,
319 [] fn check_match: CheckMatch(DefId)
320 -> Result<(), ErrorReported>,
322 /// Performs the privacy check and computes "access levels".
323 [] fn privacy_access_levels: PrivacyAccessLevels(CrateNum) -> Lrc<AccessLevels>,
327 [] fn reachable_set: reachability_dep_node(CrateNum) -> ReachableSet,
329 /// Per-body `region::ScopeTree`. The `DefId` should be the owner-def-id for the body;
330 /// in the case of closures, this will be redirected to the enclosing function.
331 [] fn region_scope_tree: RegionScopeTree(DefId) -> Lrc<region::ScopeTree>,
333 [] fn mir_shims: mir_shim_dep_node(ty::InstanceDef<'tcx>) -> &'tcx mir::Mir<'tcx>,
335 [] fn def_symbol_name: SymbolName(DefId) -> ty::SymbolName,
336 [] fn symbol_name: symbol_name_dep_node(ty::Instance<'tcx>) -> ty::SymbolName,
338 [] fn describe_def: DescribeDef(DefId) -> Option<Def>,
339 [] fn def_span: DefSpan(DefId) -> Span,
340 [] fn lookup_stability: LookupStability(DefId) -> Option<&'tcx attr::Stability>,
341 [] fn lookup_deprecation_entry: LookupDeprecationEntry(DefId) -> Option<DeprecationEntry>,
342 [] fn item_attrs: ItemAttrs(DefId) -> Lrc<[ast::Attribute]>,
346 [] fn codegen_fn_attrs: codegen_fn_attrs(DefId) -> CodegenFnAttrs,
350 [] fn fn_arg_names: FnArgNames(DefId) -> Vec<ast::Name>,
351 /// Gets the rendered value of the specified constant or associated constant.
353 [] fn rendered_const: RenderedConst(DefId) -> String,
354 [] fn impl_parent: ImplParent(DefId) -> Option<DefId>,
358 [] fn trait_of_item: TraitOfItem(DefId) -> Option<DefId>,
359 [] fn const_is_rvalue_promotable_to_static: ConstIsRvaluePromotableToStatic(DefId) -> bool,
360 [] fn rvalue_promotable_map: RvaluePromotableMap(DefId) -> Lrc<ItemLocalSet>,
364 [] fn is_mir_available: IsMirAvailable(DefId) -> bool,
368 [] fn vtable_methods: vtable_methods_node(ty::PolyTraitRef<'tcx>)
369 -> Lrc<Vec<Option<(DefId, &'tcx Substs<'tcx>)>>>,
373 [] fn codegen_fulfill_obligation: fulfill_obligation_dep_node(
374 (ty::ParamEnv<'tcx>, ty::PolyTraitRef<'tcx>)) -> Vtable<'tcx, ()>,
378 [] fn trait_impls_of: TraitImpls(DefId) -> Lrc<ty::trait_def::TraitImpls>,
379 [] fn specialization_graph_of: SpecializationGraph(DefId)
380 -> Lrc<specialization_graph::Graph>,
381 [] fn is_object_safe: ObjectSafety(DefId) -> bool,
383 /// Get the ParameterEnvironment for a given item; this environment
384 /// will be in "user-facing" mode, meaning that it is suitabe for
385 /// type-checking etc, and it does not normalize specializable
386 /// associated types. This is almost always what you want,
387 /// unless you are doing MIR optimizations, in which case you
388 /// might want to use `reveal_all()` method to change modes.
389 [] fn param_env: ParamEnv(DefId) -> ty::ParamEnv<'tcx>,
391 /// Trait selection queries. These are best used by invoking `ty.moves_by_default()`,
392 /// `ty.is_copy()`, etc, since that will prune the environment where possible.
393 [] fn is_copy_raw: is_copy_dep_node(ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool,
394 [] fn is_sized_raw: is_sized_dep_node(ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool,
395 [] fn is_freeze_raw: is_freeze_dep_node(ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool,
396 [] fn needs_drop_raw: needs_drop_dep_node(ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool,
397 [] fn layout_raw: layout_dep_node(ty::ParamEnvAnd<'tcx, Ty<'tcx>>)
398 -> Result<&'tcx ty::layout::LayoutDetails,
399 ty::layout::LayoutError<'tcx>>,
403 [] fn dylib_dependency_formats: DylibDepFormats(CrateNum)
404 -> Lrc<Vec<(CrateNum, LinkagePreference)>>,
408 [fatal_cycle] fn is_panic_runtime: IsPanicRuntime(CrateNum) -> bool,
409 [fatal_cycle] fn is_compiler_builtins: IsCompilerBuiltins(CrateNum) -> bool,
410 [fatal_cycle] fn has_global_allocator: HasGlobalAllocator(CrateNum) -> bool,
411 [fatal_cycle] fn has_panic_handler: HasPanicHandler(CrateNum) -> bool,
412 [fatal_cycle] fn is_sanitizer_runtime: IsSanitizerRuntime(CrateNum) -> bool,
413 [fatal_cycle] fn is_profiler_runtime: IsProfilerRuntime(CrateNum) -> bool,
414 [fatal_cycle] fn panic_strategy: GetPanicStrategy(CrateNum) -> PanicStrategy,
415 [fatal_cycle] fn is_no_builtins: IsNoBuiltins(CrateNum) -> bool,
417 [] fn extern_crate: ExternCrate(DefId) -> Lrc<Option<ExternCrate>>,
421 [] fn specializes: specializes_node((DefId, DefId)) -> bool,
422 [] fn in_scope_traits_map: InScopeTraits(DefIndex)
423 -> Option<Lrc<FxHashMap<ItemLocalId, Lrc<StableVec<TraitCandidate>>>>>,
427 [] fn module_exports: ModuleExports(DefId) -> Option<Lrc<Vec<Export>>>,
428 [] fn lint_levels: lint_levels_node(CrateNum) -> Lrc<lint::LintLevelMap>,
432 [] fn impl_defaultness: ImplDefaultness(DefId) -> hir::Defaultness,
434 [] fn check_item_well_formed: CheckItemWellFormed(DefId) -> (),
435 [] fn check_trait_item_well_formed: CheckTraitItemWellFormed(DefId) -> (),
436 [] fn check_impl_item_well_formed: CheckImplItemWellFormed(DefId) -> (),
440 // The DefIds of all non-generic functions and statics in the given crate
441 // that can be reached from outside the crate.
443 // We expect this items to be available for being linked to.
445 // This query can also be called for LOCAL_CRATE. In this case it will
446 // compute which items will be reachable to other crates, taking into account
447 // the kind of crate that is currently compiled. Crates with only a
448 // C interface have fewer reachable things.
450 // Does not include external symbols that don't have a corresponding DefId,
451 // like the compiler-generated `main` function and so on.
452 [] fn reachable_non_generics: ReachableNonGenerics(CrateNum)
453 -> Lrc<DefIdMap<SymbolExportLevel>>,
454 [] fn is_reachable_non_generic: IsReachableNonGeneric(DefId) -> bool,
455 [] fn is_unreachable_local_definition: IsUnreachableLocalDefinition(DefId) -> bool,
459 [] fn upstream_monomorphizations: UpstreamMonomorphizations(CrateNum)
460 -> Lrc<DefIdMap<Lrc<FxHashMap<&'tcx Substs<'tcx>, CrateNum>>>>,
461 [] fn upstream_monomorphizations_for: UpstreamMonomorphizationsFor(DefId)
462 -> Option<Lrc<FxHashMap<&'tcx Substs<'tcx>, CrateNum>>>,
466 [] fn native_libraries: NativeLibraries(CrateNum) -> Lrc<Vec<NativeLibrary>>,
468 [] fn foreign_modules: ForeignModules(CrateNum) -> Lrc<Vec<ForeignModule>>,
470 [] fn plugin_registrar_fn: PluginRegistrarFn(CrateNum) -> Option<DefId>,
471 [] fn derive_registrar_fn: DeriveRegistrarFn(CrateNum) -> Option<DefId>,
472 [] fn crate_disambiguator: CrateDisambiguator(CrateNum) -> CrateDisambiguator,
473 [] fn crate_hash: CrateHash(CrateNum) -> Svh,
474 [] fn original_crate_name: OriginalCrateName(CrateNum) -> Symbol,
475 [] fn extra_filename: ExtraFileName(CrateNum) -> String,
479 [] fn implementations_of_trait: implementations_of_trait_node((CrateNum, DefId))
481 [] fn all_trait_implementations: AllTraitImplementations(CrateNum)
486 [] fn dllimport_foreign_items: DllimportForeignItems(CrateNum)
487 -> Lrc<FxHashSet<DefId>>,
488 [] fn is_dllimport_foreign_item: IsDllimportForeignItem(DefId) -> bool,
489 [] fn is_statically_included_foreign_item: IsStaticallyIncludedForeignItem(DefId) -> bool,
490 [] fn native_library_kind: NativeLibraryKind(DefId)
491 -> Option<NativeLibraryKind>,
495 [] fn link_args: link_args_node(CrateNum) -> Lrc<Vec<String>>,
499 // Lifetime resolution. See `middle::resolve_lifetimes`.
500 [] fn resolve_lifetimes: ResolveLifetimes(CrateNum) -> Lrc<ResolveLifetimes>,
501 [] fn named_region_map: NamedRegion(DefIndex) ->
502 Option<Lrc<FxHashMap<ItemLocalId, Region>>>,
503 [] fn is_late_bound_map: IsLateBound(DefIndex) ->
504 Option<Lrc<FxHashSet<ItemLocalId>>>,
505 [] fn object_lifetime_defaults_map: ObjectLifetimeDefaults(DefIndex)
506 -> Option<Lrc<FxHashMap<ItemLocalId, Lrc<Vec<ObjectLifetimeDefault>>>>>,
510 [] fn visibility: Visibility(DefId) -> ty::Visibility,
514 [] fn dep_kind: DepKind(CrateNum) -> DepKind,
515 [] fn crate_name: CrateName(CrateNum) -> Symbol,
516 [] fn item_children: ItemChildren(DefId) -> Lrc<Vec<Export>>,
517 [] fn extern_mod_stmt_cnum: ExternModStmtCnum(DefId) -> Option<CrateNum>,
519 [] fn get_lib_features: get_lib_features_node(CrateNum) -> Lrc<LibFeatures>,
520 [] fn defined_lib_features: DefinedLibFeatures(CrateNum)
521 -> Lrc<Vec<(Symbol, Option<Symbol>)>>,
522 [] fn get_lang_items: get_lang_items_node(CrateNum) -> Lrc<LanguageItems>,
523 [] fn defined_lang_items: DefinedLangItems(CrateNum) -> Lrc<Vec<(DefId, usize)>>,
524 [] fn missing_lang_items: MissingLangItems(CrateNum) -> Lrc<Vec<LangItem>>,
525 [] fn visible_parent_map: visible_parent_map_node(CrateNum)
526 -> Lrc<DefIdMap<DefId>>,
527 [] fn missing_extern_crate_item: MissingExternCrateItem(CrateNum) -> bool,
528 [] fn used_crate_source: UsedCrateSource(CrateNum) -> Lrc<CrateSource>,
529 [] fn postorder_cnums: postorder_cnums_node(CrateNum) -> Lrc<Vec<CrateNum>>,
531 [] fn freevars: Freevars(DefId) -> Option<Lrc<Vec<hir::Freevar>>>,
532 [] fn maybe_unused_trait_import: MaybeUnusedTraitImport(DefId) -> bool,
533 [] fn maybe_unused_extern_crates: maybe_unused_extern_crates_node(CrateNum)
534 -> Lrc<Vec<(DefId, Span)>>,
536 [] fn stability_index: stability_index_node(CrateNum) -> Lrc<stability::Index<'tcx>>,
537 [] fn all_crate_nums: all_crate_nums_node(CrateNum) -> Lrc<Vec<CrateNum>>,
539 /// A vector of every trait accessible in the whole crate
540 /// (i.e. including those from subcrates). This is used only for
542 [] fn all_traits: all_traits_node(CrateNum) -> Lrc<Vec<DefId>>,
546 [] fn exported_symbols: ExportedSymbols(CrateNum)
547 -> Arc<Vec<(ExportedSymbol<'tcx>, SymbolExportLevel)>>,
551 [] fn collect_and_partition_mono_items:
552 collect_and_partition_mono_items_node(CrateNum)
553 -> (Arc<DefIdSet>, Arc<Vec<Arc<CodegenUnit<'tcx>>>>),
554 [] fn is_codegened_item: IsCodegenedItem(DefId) -> bool,
555 [] fn codegen_unit: CodegenUnit(InternedString) -> Arc<CodegenUnit<'tcx>>,
559 [] fn output_filenames: output_filenames_node(CrateNum)
560 -> Arc<OutputFilenames>,
564 // Erases regions from `ty` to yield a new type.
565 // Normally you would just use `tcx.erase_regions(&value)`,
566 // however, which uses this query as a kind of cache.
567 [] fn erase_regions_ty: erase_regions_ty(Ty<'tcx>) -> Ty<'tcx>,
569 /// Do not call this query directly: invoke `normalize` instead.
570 [] fn normalize_projection_ty: NormalizeProjectionTy(
571 CanonicalProjectionGoal<'tcx>
573 Lrc<Canonical<'tcx, canonical::QueryResponse<'tcx, NormalizationResult<'tcx>>>>,
577 /// Do not call this query directly: invoke `normalize_erasing_regions` instead.
578 [] fn normalize_ty_after_erasing_regions: NormalizeTyAfterErasingRegions(
579 ParamEnvAnd<'tcx, Ty<'tcx>>
582 [] fn implied_outlives_bounds: ImpliedOutlivesBounds(
583 CanonicalTyGoal<'tcx>
585 Lrc<Canonical<'tcx, canonical::QueryResponse<'tcx, Vec<OutlivesBound<'tcx>>>>>,
589 /// Do not call this query directly: invoke `infcx.at().dropck_outlives()` instead.
590 [] fn dropck_outlives: DropckOutlives(
591 CanonicalTyGoal<'tcx>
593 Lrc<Canonical<'tcx, canonical::QueryResponse<'tcx, DropckOutlivesResult<'tcx>>>>,
597 /// Do not call this query directly: invoke `infcx.predicate_may_hold()` or
598 /// `infcx.predicate_must_hold()` instead.
599 [] fn evaluate_obligation: EvaluateObligation(
600 CanonicalPredicateGoal<'tcx>
601 ) -> Result<traits::EvaluationResult, traits::OverflowError>,
603 /// Do not call this query directly: part of the `Eq` type-op
604 [] fn type_op_ascribe_user_type: TypeOpAscribeUserType(
605 CanonicalTypeOpAscribeUserTypeGoal<'tcx>
607 Lrc<Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>>,
611 /// Do not call this query directly: part of the `Eq` type-op
612 [] fn type_op_eq: TypeOpEq(
613 CanonicalTypeOpEqGoal<'tcx>
615 Lrc<Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>>,
619 /// Do not call this query directly: part of the `Subtype` type-op
620 [] fn type_op_subtype: TypeOpSubtype(
621 CanonicalTypeOpSubtypeGoal<'tcx>
623 Lrc<Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>>,
627 /// Do not call this query directly: part of the `ProvePredicate` type-op
628 [] fn type_op_prove_predicate: TypeOpProvePredicate(
629 CanonicalTypeOpProvePredicateGoal<'tcx>
631 Lrc<Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>>,
635 /// Do not call this query directly: part of the `Normalize` type-op
636 [] fn type_op_normalize_ty: TypeOpNormalizeTy(
637 CanonicalTypeOpNormalizeGoal<'tcx, Ty<'tcx>>
639 Lrc<Canonical<'tcx, canonical::QueryResponse<'tcx, Ty<'tcx>>>>,
643 /// Do not call this query directly: part of the `Normalize` type-op
644 [] fn type_op_normalize_predicate: TypeOpNormalizePredicate(
645 CanonicalTypeOpNormalizeGoal<'tcx, ty::Predicate<'tcx>>
647 Lrc<Canonical<'tcx, canonical::QueryResponse<'tcx, ty::Predicate<'tcx>>>>,
651 /// Do not call this query directly: part of the `Normalize` type-op
652 [] fn type_op_normalize_poly_fn_sig: TypeOpNormalizePolyFnSig(
653 CanonicalTypeOpNormalizeGoal<'tcx, ty::PolyFnSig<'tcx>>
655 Lrc<Canonical<'tcx, canonical::QueryResponse<'tcx, ty::PolyFnSig<'tcx>>>>,
659 /// Do not call this query directly: part of the `Normalize` type-op
660 [] fn type_op_normalize_fn_sig: TypeOpNormalizeFnSig(
661 CanonicalTypeOpNormalizeGoal<'tcx, ty::FnSig<'tcx>>
663 Lrc<Canonical<'tcx, canonical::QueryResponse<'tcx, ty::FnSig<'tcx>>>>,
667 [] fn substitute_normalize_and_test_predicates:
668 substitute_normalize_and_test_predicates_node((DefId, &'tcx Substs<'tcx>)) -> bool,
672 [] fn target_features_whitelist:
673 target_features_whitelist_node(CrateNum) -> Lrc<FxHashMap<String, Option<String>>>,
675 // Get an estimate of the size of an InstanceDef based on its MIR for CGU partitioning.
676 [] fn instance_def_size_estimate: instance_def_size_estimate_dep_node(ty::InstanceDef<'tcx>)
679 [] fn features_query: features_node(CrateNum) -> Lrc<feature_gate::Features>,
683 [] fn program_clauses_for: ProgramClausesFor(DefId) -> Clauses<'tcx>,
685 [] fn program_clauses_for_env: ProgramClausesForEnv(
686 traits::Environment<'tcx>
689 // Get the chalk-style environment of the given item.
690 [] fn environment: Environment(DefId) -> traits::Environment<'tcx>,
694 [] fn wasm_import_module_map: WasmImportModuleMap(CrateNum)
695 -> Lrc<FxHashMap<DefId, String>>,
699 // `try_get_query` can't be public because it uses the private query
700 // implementation traits, so we provide access to it selectively.
701 impl<'a, 'tcx, 'lcx> TyCtxt<'a, 'tcx, 'lcx> {
702 pub fn try_adt_sized_constraint(
706 ) -> Result<&'tcx [Ty<'tcx>], DiagnosticBuilder<'a>> {
707 self.try_get_query::<queries::adt_sized_constraint<'_>>(span, key)
709 pub fn try_needs_drop_raw(
712 key: ty::ParamEnvAnd<'tcx, Ty<'tcx>>,
713 ) -> Result<bool, DiagnosticBuilder<'a>> {
714 self.try_get_query::<queries::needs_drop_raw<'_>>(span, key)
716 pub fn try_optimized_mir(
720 ) -> Result<&'tcx mir::Mir<'tcx>, DiagnosticBuilder<'a>> {
721 self.try_get_query::<queries::optimized_mir<'_>>(span, key)
725 //////////////////////////////////////////////////////////////////////
726 // These functions are little shims used to find the dep-node for a
727 // given query when there is not a *direct* mapping:
730 fn features_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
731 DepConstructor::Features
734 fn codegen_fn_attrs<'tcx>(id: DefId) -> DepConstructor<'tcx> {
735 DepConstructor::CodegenFnAttrs { 0: id }
738 fn erase_regions_ty<'tcx>(ty: Ty<'tcx>) -> DepConstructor<'tcx> {
739 DepConstructor::EraseRegionsTy { ty }
742 fn type_param_predicates<'tcx>((item_id, param_id): (DefId, DefId)) -> DepConstructor<'tcx> {
743 DepConstructor::TypeParamPredicates {
749 fn fulfill_obligation_dep_node<'tcx>((param_env, trait_ref):
750 (ty::ParamEnv<'tcx>, ty::PolyTraitRef<'tcx>)) -> DepConstructor<'tcx> {
751 DepConstructor::FulfillObligation {
757 fn crate_inherent_impls_dep_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
758 DepConstructor::Coherence
761 fn inherent_impls_overlap_check_dep_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
762 DepConstructor::CoherenceInherentImplOverlapCheck
765 fn reachability_dep_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
766 DepConstructor::Reachability
769 fn mir_shim_dep_node<'tcx>(instance_def: ty::InstanceDef<'tcx>) -> DepConstructor<'tcx> {
770 DepConstructor::MirShim {
775 fn symbol_name_dep_node<'tcx>(instance: ty::Instance<'tcx>) -> DepConstructor<'tcx> {
776 DepConstructor::InstanceSymbolName { instance }
779 fn typeck_item_bodies_dep_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
780 DepConstructor::TypeckBodiesKrate
783 fn const_eval_dep_node<'tcx>(param_env: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>)
784 -> DepConstructor<'tcx> {
785 DepConstructor::ConstEval { param_env }
787 fn const_eval_raw_dep_node<'tcx>(param_env: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>)
788 -> DepConstructor<'tcx> {
789 DepConstructor::ConstEvalRaw { param_env }
792 fn mir_keys<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
793 DepConstructor::MirKeys
796 fn crate_variances<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
797 DepConstructor::CrateVariances
800 fn is_copy_dep_node<'tcx>(param_env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> DepConstructor<'tcx> {
801 DepConstructor::IsCopy { param_env }
804 fn is_sized_dep_node<'tcx>(param_env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> DepConstructor<'tcx> {
805 DepConstructor::IsSized { param_env }
808 fn is_freeze_dep_node<'tcx>(param_env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> DepConstructor<'tcx> {
809 DepConstructor::IsFreeze { param_env }
812 fn needs_drop_dep_node<'tcx>(param_env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> DepConstructor<'tcx> {
813 DepConstructor::NeedsDrop { param_env }
816 fn layout_dep_node<'tcx>(param_env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> DepConstructor<'tcx> {
817 DepConstructor::Layout { param_env }
820 fn lint_levels_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
821 DepConstructor::LintLevels
824 fn specializes_node<'tcx>((a, b): (DefId, DefId)) -> DepConstructor<'tcx> {
825 DepConstructor::Specializes { impl1: a, impl2: b }
828 fn implementations_of_trait_node<'tcx>((krate, trait_id): (CrateNum, DefId))
829 -> DepConstructor<'tcx>
831 DepConstructor::ImplementationsOfTrait { krate, trait_id }
834 fn link_args_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
835 DepConstructor::LinkArgs
838 fn get_lib_features_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
839 DepConstructor::GetLibFeatures
842 fn get_lang_items_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
843 DepConstructor::GetLangItems
846 fn visible_parent_map_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
847 DepConstructor::VisibleParentMap
850 fn postorder_cnums_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
851 DepConstructor::PostorderCnums
854 fn maybe_unused_extern_crates_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
855 DepConstructor::MaybeUnusedExternCrates
858 fn stability_index_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
859 DepConstructor::StabilityIndex
862 fn all_crate_nums_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
863 DepConstructor::AllCrateNums
866 fn all_traits_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
867 DepConstructor::AllTraits
870 fn collect_and_partition_mono_items_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
871 DepConstructor::CollectAndPartitionMonoItems
874 fn output_filenames_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
875 DepConstructor::OutputFilenames
878 fn vtable_methods_node<'tcx>(trait_ref: ty::PolyTraitRef<'tcx>) -> DepConstructor<'tcx> {
879 DepConstructor::VtableMethods{ trait_ref }
882 fn substitute_normalize_and_test_predicates_node<'tcx>(key: (DefId, &'tcx Substs<'tcx>))
883 -> DepConstructor<'tcx> {
884 DepConstructor::SubstituteNormalizeAndTestPredicates { key }
887 fn target_features_whitelist_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
888 DepConstructor::TargetFeaturesWhitelist
891 fn instance_def_size_estimate_dep_node<'tcx>(instance_def: ty::InstanceDef<'tcx>)
892 -> DepConstructor<'tcx> {
893 DepConstructor::InstanceDefSizeEstimate {