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::method_autoderef::MethodAutoderefStepsResult;
44 use traits::query::dropck_outlives::{DtorckConstraint, DropckOutlivesResult};
45 use traits::query::normalize::NormalizationResult;
46 use traits::query::outlives_bounds::OutlivesBound;
47 use traits::specialization_graph;
49 use ty::{self, CrateInherentImpls, ParamEnvAnd, Ty, TyCtxt};
51 use ty::subst::Substs;
52 use util::nodemap::{DefIdSet, DefIdMap, ItemLocalSet};
53 use util::common::{ErrorReported};
54 use util::profiling::ProfileCategory::*;
56 use rustc_data_structures::bit_set::BitSet;
57 use rustc_data_structures::indexed_vec::IndexVec;
58 use rustc_data_structures::fx::{FxHashMap, FxHashSet};
59 use rustc_data_structures::stable_hasher::StableVec;
60 use rustc_data_structures::sync::Lrc;
61 use rustc_target::spec::PanicStrategy;
66 use syntax_pos::{Span, DUMMY_SP};
67 use syntax_pos::symbol::InternedString;
70 use syntax::feature_gate;
71 use syntax::symbol::Symbol;
75 use self::plumbing::*;
76 pub use self::plumbing::{force_from_dep_node, CycleError};
79 pub use self::job::{QueryJob, QueryInfo};
80 #[cfg(parallel_queries)]
81 pub use self::job::handle_deadlock;
87 use self::values::Value;
90 pub use self::config::QueryConfig;
91 use self::config::{QueryAccessors, QueryDescription};
94 pub use self::on_disk_cache::OnDiskCache;
96 // Each of these quries corresponds to a function pointer field in the
97 // `Providers` struct for requesting a value of that type, and a method
98 // on `tcx: TyCtxt` (and `tcx.at(span)`) for doing that request in a way
99 // which memoizes and does dep-graph tracking, wrapping around the actual
100 // `Providers` that the driver creates (using several `rustc_*` crates).
102 // The result type of each query must implement `Clone`, and additionally
103 // `ty::query::values::Value`, which produces an appropriate placeholder
104 // (error) value if the query resulted in a query cycle.
105 // Queries marked with `fatal_cycle` do not need the latter implementation,
106 // as they will raise an fatal error on query cycles instead.
107 define_queries! { <'tcx>
109 /// Records the type of every item.
110 [] fn type_of: TypeOfItem(DefId) -> Ty<'tcx>,
112 /// Maps from the def-id of an item (trait/struct/enum/fn) to its
113 /// associated generics.
114 [] fn generics_of: GenericsOfItem(DefId) -> &'tcx ty::Generics,
116 /// Maps from the def-id of an item (trait/struct/enum/fn) to the
117 /// predicates (where clauses) that must be proven true in order
118 /// to reference it. This is almost always the "predicates query"
121 /// `predicates_of` builds on `predicates_defined_on` -- in fact,
122 /// it is almost always the same as that query, except for the
123 /// case of traits. For traits, `predicates_of` contains
124 /// an additional `Self: Trait<...>` predicate that users don't
125 /// actually write. This reflects the fact that to invoke the
126 /// trait (e.g., via `Default::default`) you must supply types
127 /// that actually implement the trait. (However, this extra
128 /// predicate gets in the way of some checks, which are intended
129 /// to operate over only the actual where-clauses written by the
131 [] fn predicates_of: PredicatesOfItem(DefId) -> Lrc<ty::GenericPredicates<'tcx>>,
133 /// Maps from the def-id of an item (trait/struct/enum/fn) to the
134 /// predicates (where clauses) directly defined on it. This is
135 /// equal to the `explicit_predicates_of` predicates plus the
136 /// `inferred_outlives_of` predicates.
137 [] fn predicates_defined_on: PredicatesDefinedOnItem(DefId)
138 -> Lrc<ty::GenericPredicates<'tcx>>,
140 /// Returns the predicates written explicit by the user.
141 [] fn explicit_predicates_of: ExplicitPredicatesOfItem(DefId)
142 -> Lrc<ty::GenericPredicates<'tcx>>,
144 /// Returns the inferred outlives predicates (e.g., for `struct
145 /// Foo<'a, T> { x: &'a T }`, this would return `T: 'a`).
146 [] fn inferred_outlives_of: InferredOutlivesOf(DefId) -> Lrc<Vec<ty::Predicate<'tcx>>>,
148 /// Maps from the def-id of a trait to the list of
149 /// super-predicates. This is a subset of the full list of
150 /// predicates. We store these in a separate map because we must
151 /// evaluate them even during type conversion, often before the
152 /// full predicates are available (note that supertraits have
153 /// additional acyclicity requirements).
154 [] fn super_predicates_of: SuperPredicatesOfItem(DefId) -> Lrc<ty::GenericPredicates<'tcx>>,
156 /// To avoid cycles within the predicates of a single item we compute
157 /// per-type-parameter predicates for resolving `T::AssocTy`.
158 [] fn type_param_predicates: type_param_predicates((DefId, DefId))
159 -> Lrc<ty::GenericPredicates<'tcx>>,
161 [] fn trait_def: TraitDefOfItem(DefId) -> &'tcx ty::TraitDef,
162 [] fn adt_def: AdtDefOfItem(DefId) -> &'tcx ty::AdtDef,
163 [] fn adt_destructor: AdtDestructor(DefId) -> Option<ty::Destructor>,
164 [] fn adt_sized_constraint: SizedConstraint(DefId) -> &'tcx [Ty<'tcx>],
165 [] fn adt_dtorck_constraint: DtorckConstraint(
167 ) -> Result<DtorckConstraint<'tcx>, NoSolution>,
169 /// True if this is a const fn, use the `is_const_fn` to know whether your crate actually
170 /// sees it as const fn (e.g., the const-fn-ness might be unstable and you might not have
171 /// the feature gate active)
173 /// **Do not call this function manually.** It is only meant to cache the base data for the
174 /// `is_const_fn` function.
175 [] fn is_const_fn_raw: IsConstFn(DefId) -> bool,
178 /// Returns true if calls to the function may be promoted
180 /// This is either because the function is e.g., a tuple-struct or tuple-variant
181 /// constructor, or because it has the `#[rustc_promotable]` attribute. The attribute should
182 /// be removed in the future in favour of some form of check which figures out whether the
183 /// function does not inspect the bits of any of its arguments (so is essentially just a
184 /// constructor function).
185 [] fn is_promotable_const_fn: IsPromotableConstFn(DefId) -> bool,
187 /// True if this is a foreign item (i.e., linked via `extern { ... }`).
188 [] fn is_foreign_item: IsForeignItem(DefId) -> bool,
190 /// Get a map with the variance of every item; use `item_variance`
192 [] fn crate_variances: crate_variances(CrateNum) -> Lrc<ty::CrateVariancesMap>,
194 /// Maps from def-id of a type or region parameter to its
195 /// (inferred) variance.
196 [] fn variances_of: ItemVariances(DefId) -> Lrc<Vec<ty::Variance>>,
200 /// Maps from def-id of a type to its (inferred) outlives.
201 [] fn inferred_outlives_crate: InferredOutlivesCrate(CrateNum)
202 -> Lrc<ty::CratePredicatesMap<'tcx>>,
206 /// Maps from an impl/trait def-id to a list of the def-ids of its items
207 [] fn associated_item_def_ids: AssociatedItemDefIds(DefId) -> Lrc<Vec<DefId>>,
209 /// Maps from a trait item to the trait item "descriptor"
210 [] fn associated_item: AssociatedItems(DefId) -> ty::AssociatedItem,
212 [] fn impl_trait_ref: ImplTraitRef(DefId) -> Option<ty::TraitRef<'tcx>>,
213 [] fn impl_polarity: ImplPolarity(DefId) -> hir::ImplPolarity,
217 /// Maps a DefId of a type to a list of its inherent impls.
218 /// Contains implementations of methods that are inherent to a type.
219 /// Methods in these implementations don't need to be exported.
220 [] fn inherent_impls: InherentImpls(DefId) -> Lrc<Vec<DefId>>,
224 /// Set of all the def-ids in this crate that have MIR associated with
225 /// them. This includes all the body owners, but also things like struct
227 [] fn mir_keys: mir_keys(CrateNum) -> Lrc<DefIdSet>,
229 /// Maps DefId's that have an associated Mir to the result
230 /// of the MIR qualify_consts pass. The actual meaning of
231 /// the value isn't known except to the pass itself.
232 [] fn mir_const_qualif: MirConstQualif(DefId) -> (u8, Lrc<BitSet<mir::Local>>),
234 /// Fetch the MIR for a given def-id right after it's built - this includes
235 /// unreachable code.
236 [] fn mir_built: MirBuilt(DefId) -> &'tcx Steal<mir::Mir<'tcx>>,
238 /// Fetch the MIR for a given def-id up till the point where it is
239 /// ready for const evaluation.
241 /// See the README for the `mir` module for details.
242 [] fn mir_const: MirConst(DefId) -> &'tcx Steal<mir::Mir<'tcx>>,
244 [] fn mir_validated: MirValidated(DefId) -> &'tcx Steal<mir::Mir<'tcx>>,
246 /// MIR after our optimization passes have run. This is MIR that is ready
247 /// for codegen. This is also the only query that can fetch non-local MIR, at present.
248 [] fn optimized_mir: MirOptimized(DefId) -> &'tcx mir::Mir<'tcx>,
252 /// The result of unsafety-checking this def-id.
253 [] fn unsafety_check_result: UnsafetyCheckResult(DefId) -> mir::UnsafetyCheckResult,
255 /// HACK: when evaluated, this reports a "unsafe derive on repr(packed)" error
256 [] fn unsafe_derive_on_repr_packed: UnsafeDeriveOnReprPacked(DefId) -> (),
258 /// The signature of functions and closures.
259 [] fn fn_sig: FnSignature(DefId) -> ty::PolyFnSig<'tcx>,
263 /// Caches CoerceUnsized kinds for impls on custom types.
264 [] fn coerce_unsized_info: CoerceUnsizedInfo(DefId)
265 -> ty::adjustment::CoerceUnsizedInfo,
269 [] fn typeck_item_bodies: typeck_item_bodies_dep_node(CrateNum) -> CompileResult,
271 [] fn typeck_tables_of: TypeckTables(DefId) -> &'tcx ty::TypeckTables<'tcx>,
275 [] fn used_trait_imports: UsedTraitImports(DefId) -> Lrc<DefIdSet>,
279 [] fn has_typeck_tables: HasTypeckTables(DefId) -> bool,
281 [] fn coherent_trait: CoherenceCheckTrait(DefId) -> (),
285 [] fn borrowck: BorrowCheck(DefId) -> Lrc<BorrowCheckResult>,
287 /// Borrow checks the function body. If this is a closure, returns
288 /// additional requirements that the closure's creator must verify.
289 [] fn mir_borrowck: MirBorrowCheck(DefId) -> mir::BorrowCheckResult<'tcx>,
293 /// Gets a complete map from all types to their inherent impls.
294 /// Not meant to be used directly outside of coherence.
295 /// (Defined only for LOCAL_CRATE)
296 [] fn crate_inherent_impls: crate_inherent_impls_dep_node(CrateNum)
297 -> Lrc<CrateInherentImpls>,
299 /// Checks all types in the krate for overlap in their inherent impls. Reports errors.
300 /// Not meant to be used directly outside of coherence.
301 /// (Defined only for LOCAL_CRATE)
302 [] fn crate_inherent_impls_overlap_check: inherent_impls_overlap_check_dep_node(CrateNum)
307 /// Evaluate a constant without running sanity checks
309 /// DO NOT USE THIS outside const eval. Const eval uses this to break query cycles during
310 /// validation. Please add a comment to every use site explaining why using `const_eval`
312 [] fn const_eval_raw: const_eval_raw_dep_node(ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>)
313 -> ConstEvalRawResult<'tcx>,
315 /// Results of evaluating const items or constants embedded in
316 /// other items (such as enum variant explicit discriminants).
317 [] fn const_eval: const_eval_dep_node(ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>)
318 -> ConstEvalResult<'tcx>,
322 [] fn check_match: CheckMatch(DefId)
323 -> Result<(), ErrorReported>,
325 /// Performs the privacy check and computes "access levels".
326 [] fn privacy_access_levels: PrivacyAccessLevels(CrateNum) -> Lrc<AccessLevels>,
330 [] fn reachable_set: reachability_dep_node(CrateNum) -> ReachableSet,
332 /// Per-body `region::ScopeTree`. The `DefId` should be the owner-def-id for the body;
333 /// in the case of closures, this will be redirected to the enclosing function.
334 [] fn region_scope_tree: RegionScopeTree(DefId) -> Lrc<region::ScopeTree>,
336 [] fn mir_shims: mir_shim_dep_node(ty::InstanceDef<'tcx>) -> &'tcx mir::Mir<'tcx>,
338 [] fn def_symbol_name: SymbolName(DefId) -> ty::SymbolName,
339 [] fn symbol_name: symbol_name_dep_node(ty::Instance<'tcx>) -> ty::SymbolName,
341 [] fn describe_def: DescribeDef(DefId) -> Option<Def>,
342 [] fn def_span: DefSpan(DefId) -> Span,
343 [] fn lookup_stability: LookupStability(DefId) -> Option<&'tcx attr::Stability>,
344 [] fn lookup_deprecation_entry: LookupDeprecationEntry(DefId) -> Option<DeprecationEntry>,
345 [] fn item_attrs: ItemAttrs(DefId) -> Lrc<[ast::Attribute]>,
349 [] fn codegen_fn_attrs: codegen_fn_attrs(DefId) -> CodegenFnAttrs,
353 [] fn fn_arg_names: FnArgNames(DefId) -> Vec<ast::Name>,
354 /// Gets the rendered value of the specified constant or associated constant.
356 [] fn rendered_const: RenderedConst(DefId) -> String,
357 [] fn impl_parent: ImplParent(DefId) -> Option<DefId>,
361 [] fn trait_of_item: TraitOfItem(DefId) -> Option<DefId>,
362 [] fn const_is_rvalue_promotable_to_static: ConstIsRvaluePromotableToStatic(DefId) -> bool,
363 [] fn rvalue_promotable_map: RvaluePromotableMap(DefId) -> Lrc<ItemLocalSet>,
367 [] fn is_mir_available: IsMirAvailable(DefId) -> bool,
371 [] fn vtable_methods: vtable_methods_node(ty::PolyTraitRef<'tcx>)
372 -> Lrc<Vec<Option<(DefId, &'tcx Substs<'tcx>)>>>,
376 [] fn codegen_fulfill_obligation: fulfill_obligation_dep_node(
377 (ty::ParamEnv<'tcx>, ty::PolyTraitRef<'tcx>)) -> Vtable<'tcx, ()>,
381 [] fn trait_impls_of: TraitImpls(DefId) -> Lrc<ty::trait_def::TraitImpls>,
382 [] fn specialization_graph_of: SpecializationGraph(DefId)
383 -> Lrc<specialization_graph::Graph>,
384 [] fn is_object_safe: ObjectSafety(DefId) -> bool,
386 /// Get the ParameterEnvironment for a given item; this environment
387 /// will be in "user-facing" mode, meaning that it is suitabe for
388 /// type-checking etc, and it does not normalize specializable
389 /// associated types. This is almost always what you want,
390 /// unless you are doing MIR optimizations, in which case you
391 /// might want to use `reveal_all()` method to change modes.
392 [] fn param_env: ParamEnv(DefId) -> ty::ParamEnv<'tcx>,
394 /// Trait selection queries. These are best used by invoking `ty.moves_by_default()`,
395 /// `ty.is_copy()`, etc, since that will prune the environment where possible.
396 [] fn is_copy_raw: is_copy_dep_node(ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool,
397 [] fn is_sized_raw: is_sized_dep_node(ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool,
398 [] fn is_freeze_raw: is_freeze_dep_node(ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool,
399 [] fn needs_drop_raw: needs_drop_dep_node(ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool,
400 [] fn layout_raw: layout_dep_node(ty::ParamEnvAnd<'tcx, Ty<'tcx>>)
401 -> Result<&'tcx ty::layout::LayoutDetails,
402 ty::layout::LayoutError<'tcx>>,
406 [] fn dylib_dependency_formats: DylibDepFormats(CrateNum)
407 -> Lrc<Vec<(CrateNum, LinkagePreference)>>,
411 [fatal_cycle] fn is_panic_runtime: IsPanicRuntime(CrateNum) -> bool,
412 [fatal_cycle] fn is_compiler_builtins: IsCompilerBuiltins(CrateNum) -> bool,
413 [fatal_cycle] fn has_global_allocator: HasGlobalAllocator(CrateNum) -> bool,
414 [fatal_cycle] fn has_panic_handler: HasPanicHandler(CrateNum) -> bool,
415 [fatal_cycle] fn is_sanitizer_runtime: IsSanitizerRuntime(CrateNum) -> bool,
416 [fatal_cycle] fn is_profiler_runtime: IsProfilerRuntime(CrateNum) -> bool,
417 [fatal_cycle] fn panic_strategy: GetPanicStrategy(CrateNum) -> PanicStrategy,
418 [fatal_cycle] fn is_no_builtins: IsNoBuiltins(CrateNum) -> bool,
420 [] fn extern_crate: ExternCrate(DefId) -> Lrc<Option<ExternCrate>>,
424 [] fn specializes: specializes_node((DefId, DefId)) -> bool,
425 [] fn in_scope_traits_map: InScopeTraits(DefIndex)
426 -> Option<Lrc<FxHashMap<ItemLocalId, Lrc<StableVec<TraitCandidate>>>>>,
430 [] fn module_exports: ModuleExports(DefId) -> Option<Lrc<Vec<Export>>>,
431 [] fn lint_levels: lint_levels_node(CrateNum) -> Lrc<lint::LintLevelMap>,
435 [] fn impl_defaultness: ImplDefaultness(DefId) -> hir::Defaultness,
437 [] fn check_item_well_formed: CheckItemWellFormed(DefId) -> (),
438 [] fn check_trait_item_well_formed: CheckTraitItemWellFormed(DefId) -> (),
439 [] fn check_impl_item_well_formed: CheckImplItemWellFormed(DefId) -> (),
443 // The DefIds of all non-generic functions and statics in the given crate
444 // that can be reached from outside the crate.
446 // We expect this items to be available for being linked to.
448 // This query can also be called for LOCAL_CRATE. In this case it will
449 // compute which items will be reachable to other crates, taking into account
450 // the kind of crate that is currently compiled. Crates with only a
451 // C interface have fewer reachable things.
453 // Does not include external symbols that don't have a corresponding DefId,
454 // like the compiler-generated `main` function and so on.
455 [] fn reachable_non_generics: ReachableNonGenerics(CrateNum)
456 -> Lrc<DefIdMap<SymbolExportLevel>>,
457 [] fn is_reachable_non_generic: IsReachableNonGeneric(DefId) -> bool,
458 [] fn is_unreachable_local_definition: IsUnreachableLocalDefinition(DefId) -> bool,
462 [] fn upstream_monomorphizations: UpstreamMonomorphizations(CrateNum)
463 -> Lrc<DefIdMap<Lrc<FxHashMap<&'tcx Substs<'tcx>, CrateNum>>>>,
464 [] fn upstream_monomorphizations_for: UpstreamMonomorphizationsFor(DefId)
465 -> Option<Lrc<FxHashMap<&'tcx Substs<'tcx>, CrateNum>>>,
469 [] fn native_libraries: NativeLibraries(CrateNum) -> Lrc<Vec<NativeLibrary>>,
471 [] fn foreign_modules: ForeignModules(CrateNum) -> Lrc<Vec<ForeignModule>>,
473 [] fn plugin_registrar_fn: PluginRegistrarFn(CrateNum) -> Option<DefId>,
474 [] fn proc_macro_decls_static: ProcMacroDeclsStatic(CrateNum) -> Option<DefId>,
475 [] fn crate_disambiguator: CrateDisambiguator(CrateNum) -> CrateDisambiguator,
476 [] fn crate_hash: CrateHash(CrateNum) -> Svh,
477 [] fn original_crate_name: OriginalCrateName(CrateNum) -> Symbol,
478 [] fn extra_filename: ExtraFileName(CrateNum) -> String,
482 [] fn implementations_of_trait: implementations_of_trait_node((CrateNum, DefId))
484 [] fn all_trait_implementations: AllTraitImplementations(CrateNum)
489 [] fn dllimport_foreign_items: DllimportForeignItems(CrateNum)
490 -> Lrc<FxHashSet<DefId>>,
491 [] fn is_dllimport_foreign_item: IsDllimportForeignItem(DefId) -> bool,
492 [] fn is_statically_included_foreign_item: IsStaticallyIncludedForeignItem(DefId) -> bool,
493 [] fn native_library_kind: NativeLibraryKind(DefId)
494 -> Option<NativeLibraryKind>,
498 [] fn link_args: link_args_node(CrateNum) -> Lrc<Vec<String>>,
502 // Lifetime resolution. See `middle::resolve_lifetimes`.
503 [] fn resolve_lifetimes: ResolveLifetimes(CrateNum) -> Lrc<ResolveLifetimes>,
504 [] fn named_region_map: NamedRegion(DefIndex) ->
505 Option<Lrc<FxHashMap<ItemLocalId, Region>>>,
506 [] fn is_late_bound_map: IsLateBound(DefIndex) ->
507 Option<Lrc<FxHashSet<ItemLocalId>>>,
508 [] fn object_lifetime_defaults_map: ObjectLifetimeDefaults(DefIndex)
509 -> Option<Lrc<FxHashMap<ItemLocalId, Lrc<Vec<ObjectLifetimeDefault>>>>>,
513 [] fn visibility: Visibility(DefId) -> ty::Visibility,
517 [] fn dep_kind: DepKind(CrateNum) -> DepKind,
518 [] fn crate_name: CrateName(CrateNum) -> Symbol,
519 [] fn item_children: ItemChildren(DefId) -> Lrc<Vec<Export>>,
520 [] fn extern_mod_stmt_cnum: ExternModStmtCnum(DefId) -> Option<CrateNum>,
522 [] fn get_lib_features: get_lib_features_node(CrateNum) -> Lrc<LibFeatures>,
523 [] fn defined_lib_features: DefinedLibFeatures(CrateNum)
524 -> Lrc<Vec<(Symbol, Option<Symbol>)>>,
525 [] fn get_lang_items: get_lang_items_node(CrateNum) -> Lrc<LanguageItems>,
526 [] fn defined_lang_items: DefinedLangItems(CrateNum) -> Lrc<Vec<(DefId, usize)>>,
527 [] fn missing_lang_items: MissingLangItems(CrateNum) -> Lrc<Vec<LangItem>>,
528 [] fn visible_parent_map: visible_parent_map_node(CrateNum)
529 -> Lrc<DefIdMap<DefId>>,
530 [] fn missing_extern_crate_item: MissingExternCrateItem(CrateNum) -> bool,
531 [] fn used_crate_source: UsedCrateSource(CrateNum) -> Lrc<CrateSource>,
532 [] fn postorder_cnums: postorder_cnums_node(CrateNum) -> Lrc<Vec<CrateNum>>,
534 [] fn freevars: Freevars(DefId) -> Option<Lrc<Vec<hir::Freevar>>>,
535 [] fn maybe_unused_trait_import: MaybeUnusedTraitImport(DefId) -> bool,
536 [] fn maybe_unused_extern_crates: maybe_unused_extern_crates_node(CrateNum)
537 -> Lrc<Vec<(DefId, Span)>>,
539 [] fn stability_index: stability_index_node(CrateNum) -> Lrc<stability::Index<'tcx>>,
540 [] fn all_crate_nums: all_crate_nums_node(CrateNum) -> Lrc<Vec<CrateNum>>,
542 /// A vector of every trait accessible in the whole crate
543 /// (i.e., including those from subcrates). This is used only for
545 [] fn all_traits: all_traits_node(CrateNum) -> Lrc<Vec<DefId>>,
549 [] fn exported_symbols: ExportedSymbols(CrateNum)
550 -> Arc<Vec<(ExportedSymbol<'tcx>, SymbolExportLevel)>>,
554 [] fn collect_and_partition_mono_items:
555 collect_and_partition_mono_items_node(CrateNum)
556 -> (Arc<DefIdSet>, Arc<Vec<Arc<CodegenUnit<'tcx>>>>),
557 [] fn is_codegened_item: IsCodegenedItem(DefId) -> bool,
558 [] fn codegen_unit: CodegenUnit(InternedString) -> Arc<CodegenUnit<'tcx>>,
562 [] fn output_filenames: output_filenames_node(CrateNum)
563 -> Arc<OutputFilenames>,
567 // Erases regions from `ty` to yield a new type.
568 // Normally you would just use `tcx.erase_regions(&value)`,
569 // however, which uses this query as a kind of cache.
570 [] fn erase_regions_ty: erase_regions_ty(Ty<'tcx>) -> Ty<'tcx>,
572 /// Do not call this query directly: invoke `normalize` instead.
573 [] fn normalize_projection_ty: NormalizeProjectionTy(
574 CanonicalProjectionGoal<'tcx>
576 Lrc<Canonical<'tcx, canonical::QueryResponse<'tcx, NormalizationResult<'tcx>>>>,
580 /// Do not call this query directly: invoke `normalize_erasing_regions` instead.
581 [] fn normalize_ty_after_erasing_regions: NormalizeTyAfterErasingRegions(
582 ParamEnvAnd<'tcx, Ty<'tcx>>
585 [] fn implied_outlives_bounds: ImpliedOutlivesBounds(
586 CanonicalTyGoal<'tcx>
588 Lrc<Canonical<'tcx, canonical::QueryResponse<'tcx, Vec<OutlivesBound<'tcx>>>>>,
592 /// Do not call this query directly: invoke `infcx.at().dropck_outlives()` instead.
593 [] fn dropck_outlives: DropckOutlives(
594 CanonicalTyGoal<'tcx>
596 Lrc<Canonical<'tcx, canonical::QueryResponse<'tcx, DropckOutlivesResult<'tcx>>>>,
600 /// Do not call this query directly: invoke `infcx.predicate_may_hold()` or
601 /// `infcx.predicate_must_hold()` instead.
602 [] fn evaluate_obligation: EvaluateObligation(
603 CanonicalPredicateGoal<'tcx>
604 ) -> Result<traits::EvaluationResult, traits::OverflowError>,
606 /// Do not call this query directly: part of the `Eq` type-op
607 [] fn type_op_ascribe_user_type: TypeOpAscribeUserType(
608 CanonicalTypeOpAscribeUserTypeGoal<'tcx>
610 Lrc<Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>>,
614 /// Do not call this query directly: part of the `Eq` type-op
615 [] fn type_op_eq: TypeOpEq(
616 CanonicalTypeOpEqGoal<'tcx>
618 Lrc<Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>>,
622 /// Do not call this query directly: part of the `Subtype` type-op
623 [] fn type_op_subtype: TypeOpSubtype(
624 CanonicalTypeOpSubtypeGoal<'tcx>
626 Lrc<Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>>,
630 /// Do not call this query directly: part of the `ProvePredicate` type-op
631 [] fn type_op_prove_predicate: TypeOpProvePredicate(
632 CanonicalTypeOpProvePredicateGoal<'tcx>
634 Lrc<Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>>,
638 /// Do not call this query directly: part of the `Normalize` type-op
639 [] fn type_op_normalize_ty: TypeOpNormalizeTy(
640 CanonicalTypeOpNormalizeGoal<'tcx, Ty<'tcx>>
642 Lrc<Canonical<'tcx, canonical::QueryResponse<'tcx, Ty<'tcx>>>>,
646 /// Do not call this query directly: part of the `Normalize` type-op
647 [] fn type_op_normalize_predicate: TypeOpNormalizePredicate(
648 CanonicalTypeOpNormalizeGoal<'tcx, ty::Predicate<'tcx>>
650 Lrc<Canonical<'tcx, canonical::QueryResponse<'tcx, ty::Predicate<'tcx>>>>,
654 /// Do not call this query directly: part of the `Normalize` type-op
655 [] fn type_op_normalize_poly_fn_sig: TypeOpNormalizePolyFnSig(
656 CanonicalTypeOpNormalizeGoal<'tcx, ty::PolyFnSig<'tcx>>
658 Lrc<Canonical<'tcx, canonical::QueryResponse<'tcx, ty::PolyFnSig<'tcx>>>>,
662 /// Do not call this query directly: part of the `Normalize` type-op
663 [] fn type_op_normalize_fn_sig: TypeOpNormalizeFnSig(
664 CanonicalTypeOpNormalizeGoal<'tcx, ty::FnSig<'tcx>>
666 Lrc<Canonical<'tcx, canonical::QueryResponse<'tcx, ty::FnSig<'tcx>>>>,
670 [] fn substitute_normalize_and_test_predicates:
671 substitute_normalize_and_test_predicates_node((DefId, &'tcx Substs<'tcx>)) -> bool,
673 [] fn method_autoderef_steps: MethodAutoderefSteps(
674 CanonicalTyGoal<'tcx>
675 ) -> MethodAutoderefStepsResult<'tcx>,
679 [] fn target_features_whitelist:
680 target_features_whitelist_node(CrateNum) -> Lrc<FxHashMap<String, Option<String>>>,
682 // Get an estimate of the size of an InstanceDef based on its MIR for CGU partitioning.
683 [] fn instance_def_size_estimate: instance_def_size_estimate_dep_node(ty::InstanceDef<'tcx>)
686 [] fn features_query: features_node(CrateNum) -> Lrc<feature_gate::Features>,
690 [] fn program_clauses_for: ProgramClausesFor(DefId) -> Clauses<'tcx>,
692 [] fn program_clauses_for_env: ProgramClausesForEnv(
693 traits::Environment<'tcx>
696 // Get the chalk-style environment of the given item.
697 [] fn environment: Environment(DefId) -> ty::Binder<traits::Environment<'tcx>>,
701 [] fn wasm_import_module_map: WasmImportModuleMap(CrateNum)
702 -> Lrc<FxHashMap<DefId, String>>,
706 // `try_get_query` can't be public because it uses the private query
707 // implementation traits, so we provide access to it selectively.
708 impl<'a, 'tcx, 'lcx> TyCtxt<'a, 'tcx, 'lcx> {
709 pub fn try_adt_sized_constraint(
713 ) -> Result<&'tcx [Ty<'tcx>], Box<DiagnosticBuilder<'a>>> {
714 self.try_get_query::<queries::adt_sized_constraint<'_>>(span, key)
716 pub fn try_needs_drop_raw(
719 key: ty::ParamEnvAnd<'tcx, Ty<'tcx>>,
720 ) -> Result<bool, Box<DiagnosticBuilder<'a>>> {
721 self.try_get_query::<queries::needs_drop_raw<'_>>(span, key)
723 pub fn try_optimized_mir(
727 ) -> Result<&'tcx mir::Mir<'tcx>, Box<DiagnosticBuilder<'a>>> {
728 self.try_get_query::<queries::optimized_mir<'_>>(span, key)
732 //////////////////////////////////////////////////////////////////////
733 // These functions are little shims used to find the dep-node for a
734 // given query when there is not a *direct* mapping:
737 fn features_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
738 DepConstructor::Features
741 fn codegen_fn_attrs<'tcx>(id: DefId) -> DepConstructor<'tcx> {
742 DepConstructor::CodegenFnAttrs { 0: id }
745 fn erase_regions_ty<'tcx>(ty: Ty<'tcx>) -> DepConstructor<'tcx> {
746 DepConstructor::EraseRegionsTy { ty }
749 fn type_param_predicates<'tcx>((item_id, param_id): (DefId, DefId)) -> DepConstructor<'tcx> {
750 DepConstructor::TypeParamPredicates {
756 fn fulfill_obligation_dep_node<'tcx>((param_env, trait_ref):
757 (ty::ParamEnv<'tcx>, ty::PolyTraitRef<'tcx>)) -> DepConstructor<'tcx> {
758 DepConstructor::FulfillObligation {
764 fn crate_inherent_impls_dep_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
765 DepConstructor::Coherence
768 fn inherent_impls_overlap_check_dep_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
769 DepConstructor::CoherenceInherentImplOverlapCheck
772 fn reachability_dep_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
773 DepConstructor::Reachability
776 fn mir_shim_dep_node<'tcx>(instance_def: ty::InstanceDef<'tcx>) -> DepConstructor<'tcx> {
777 DepConstructor::MirShim {
782 fn symbol_name_dep_node<'tcx>(instance: ty::Instance<'tcx>) -> DepConstructor<'tcx> {
783 DepConstructor::InstanceSymbolName { instance }
786 fn typeck_item_bodies_dep_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
787 DepConstructor::TypeckBodiesKrate
790 fn const_eval_dep_node<'tcx>(param_env: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>)
791 -> DepConstructor<'tcx> {
792 DepConstructor::ConstEval { param_env }
794 fn const_eval_raw_dep_node<'tcx>(param_env: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>)
795 -> DepConstructor<'tcx> {
796 DepConstructor::ConstEvalRaw { param_env }
799 fn mir_keys<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
800 DepConstructor::MirKeys
803 fn crate_variances<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
804 DepConstructor::CrateVariances
807 fn is_copy_dep_node<'tcx>(param_env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> DepConstructor<'tcx> {
808 DepConstructor::IsCopy { param_env }
811 fn is_sized_dep_node<'tcx>(param_env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> DepConstructor<'tcx> {
812 DepConstructor::IsSized { param_env }
815 fn is_freeze_dep_node<'tcx>(param_env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> DepConstructor<'tcx> {
816 DepConstructor::IsFreeze { param_env }
819 fn needs_drop_dep_node<'tcx>(param_env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> DepConstructor<'tcx> {
820 DepConstructor::NeedsDrop { param_env }
823 fn layout_dep_node<'tcx>(param_env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> DepConstructor<'tcx> {
824 DepConstructor::Layout { param_env }
827 fn lint_levels_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
828 DepConstructor::LintLevels
831 fn specializes_node<'tcx>((a, b): (DefId, DefId)) -> DepConstructor<'tcx> {
832 DepConstructor::Specializes { impl1: a, impl2: b }
835 fn implementations_of_trait_node<'tcx>((krate, trait_id): (CrateNum, DefId))
836 -> DepConstructor<'tcx>
838 DepConstructor::ImplementationsOfTrait { krate, trait_id }
841 fn link_args_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
842 DepConstructor::LinkArgs
845 fn get_lib_features_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
846 DepConstructor::GetLibFeatures
849 fn get_lang_items_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
850 DepConstructor::GetLangItems
853 fn visible_parent_map_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
854 DepConstructor::VisibleParentMap
857 fn postorder_cnums_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
858 DepConstructor::PostorderCnums
861 fn maybe_unused_extern_crates_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
862 DepConstructor::MaybeUnusedExternCrates
865 fn stability_index_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
866 DepConstructor::StabilityIndex
869 fn all_crate_nums_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
870 DepConstructor::AllCrateNums
873 fn all_traits_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
874 DepConstructor::AllTraits
877 fn collect_and_partition_mono_items_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
878 DepConstructor::CollectAndPartitionMonoItems
881 fn output_filenames_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
882 DepConstructor::OutputFilenames
885 fn vtable_methods_node<'tcx>(trait_ref: ty::PolyTraitRef<'tcx>) -> DepConstructor<'tcx> {
886 DepConstructor::VtableMethods{ trait_ref }
889 fn substitute_normalize_and_test_predicates_node<'tcx>(key: (DefId, &'tcx Substs<'tcx>))
890 -> DepConstructor<'tcx> {
891 DepConstructor::SubstituteNormalizeAndTestPredicates { key }
894 fn target_features_whitelist_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
895 DepConstructor::TargetFeaturesWhitelist
898 fn instance_def_size_estimate_dep_node<'tcx>(instance_def: ty::InstanceDef<'tcx>)
899 -> DepConstructor<'tcx> {
900 DepConstructor::InstanceDefSizeEstimate {