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};
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::lang_items::{LanguageItems, LangItem};
28 use middle::exported_symbols::{SymbolExportLevel, ExportedSymbol};
29 use mir::interpret::ConstEvalResult;
30 use mir::mono::{CodegenUnit, Stats};
32 use mir::interpret::{GlobalId, Allocation};
33 use session::{CompileResult, CrateDisambiguator};
34 use session::config::OutputFilenames;
35 use traits::{self, Vtable};
36 use traits::query::{CanonicalPredicateGoal, CanonicalProjectionGoal,
37 CanonicalTyGoal, CanonicalTypeOpEqGoal, CanonicalTypeOpSubtypeGoal,
38 CanonicalTypeOpProvePredicateGoal, CanonicalTypeOpNormalizeGoal, NoSolution};
39 use traits::query::dropck_outlives::{DtorckConstraint, DropckOutlivesResult};
40 use traits::query::normalize::NormalizationResult;
41 use traits::specialization_graph;
43 use ty::{self, CrateInherentImpls, ParamEnvAnd, Ty, TyCtxt};
45 use ty::subst::Substs;
46 use util::nodemap::{DefIdSet, DefIdMap, ItemLocalSet};
47 use util::common::{ErrorReported};
49 use rustc_data_structures::indexed_set::IdxSetBuf;
50 use rustc_target::spec::PanicStrategy;
51 use rustc_data_structures::indexed_vec::IndexVec;
52 use rustc_data_structures::fx::{FxHashMap, FxHashSet};
53 use rustc_data_structures::stable_hasher::StableVec;
56 use rustc_data_structures::sync::Lrc;
58 use syntax_pos::{Span, DUMMY_SP};
59 use syntax_pos::symbol::InternedString;
62 use syntax::feature_gate;
63 use syntax::symbol::Symbol;
67 use self::plumbing::*;
68 pub use self::plumbing::{force_from_dep_node, CycleError};
71 pub use self::job::{QueryJob, QueryInfo};
72 #[cfg(parallel_queries)]
73 pub use self::job::handle_deadlock;
79 use self::values::Value;
82 pub use self::config::QueryConfig;
83 use self::config::{QueryAccessors, QueryDescription};
86 pub use self::on_disk_cache::OnDiskCache;
88 // Each of these quries corresponds to a function pointer field in the
89 // `Providers` struct for requesting a value of that type, and a method
90 // on `tcx: TyCtxt` (and `tcx.at(span)`) for doing that request in a way
91 // which memoizes and does dep-graph tracking, wrapping around the actual
92 // `Providers` that the driver creates (using several `rustc_*` crates).
94 // The result type of each query must implement `Clone`, and additionally
95 // `ty::query::values::Value`, which produces an appropriate placeholder
96 // (error) value if the query resulted in a query cycle.
97 // Queries marked with `fatal_cycle` do not need the latter implementation,
98 // as they will raise an fatal error on query cycles instead.
99 define_queries! { <'tcx>
100 /// Records the type of every item.
101 [] fn type_of: TypeOfItem(DefId) -> Ty<'tcx>,
103 /// Maps from the def-id of an item (trait/struct/enum/fn) to its
104 /// associated generics and predicates.
105 [] fn generics_of: GenericsOfItem(DefId) -> &'tcx ty::Generics,
106 [] fn predicates_of: PredicatesOfItem(DefId) -> ty::GenericPredicates<'tcx>,
107 [] fn explicit_predicates_of: ExplicitPredicatesOfItem(DefId) -> ty::GenericPredicates<'tcx>,
109 /// Maps from the def-id of a trait to the list of
110 /// super-predicates. This is a subset of the full list of
111 /// predicates. We store these in a separate map because we must
112 /// evaluate them even during type conversion, often before the
113 /// full predicates are available (note that supertraits have
114 /// additional acyclicity requirements).
115 [] fn super_predicates_of: SuperPredicatesOfItem(DefId) -> ty::GenericPredicates<'tcx>,
117 /// To avoid cycles within the predicates of a single item we compute
118 /// per-type-parameter predicates for resolving `T::AssocTy`.
119 [] fn type_param_predicates: type_param_predicates((DefId, DefId))
120 -> ty::GenericPredicates<'tcx>,
122 [] fn trait_def: TraitDefOfItem(DefId) -> &'tcx ty::TraitDef,
123 [] fn adt_def: AdtDefOfItem(DefId) -> &'tcx ty::AdtDef,
124 [] fn adt_destructor: AdtDestructor(DefId) -> Option<ty::Destructor>,
125 [] fn adt_sized_constraint: SizedConstraint(DefId) -> &'tcx [Ty<'tcx>],
126 [] fn adt_dtorck_constraint: DtorckConstraint(
128 ) -> Result<DtorckConstraint<'tcx>, NoSolution>,
130 /// True if this is a const fn
131 [] fn is_const_fn: IsConstFn(DefId) -> bool,
133 /// True if this is a foreign item (i.e., linked via `extern { ... }`).
134 [] fn is_foreign_item: IsForeignItem(DefId) -> bool,
136 /// Get a map with the variance of every item; use `item_variance`
138 [] fn crate_variances: crate_variances(CrateNum) -> Lrc<ty::CrateVariancesMap>,
140 /// Maps from def-id of a type or region parameter to its
141 /// (inferred) variance.
142 [] fn variances_of: ItemVariances(DefId) -> Lrc<Vec<ty::Variance>>,
144 /// Maps from def-id of a type to its (inferred) outlives.
145 [] fn inferred_outlives_of: InferredOutlivesOf(DefId) -> Lrc<Vec<ty::Predicate<'tcx>>>,
147 /// Maps from def-id of a type to its (inferred) outlives.
148 [] fn inferred_outlives_crate: InferredOutlivesCrate(CrateNum)
149 -> Lrc<ty::CratePredicatesMap<'tcx>>,
151 /// Maps from an impl/trait def-id to a list of the def-ids of its items
152 [] fn associated_item_def_ids: AssociatedItemDefIds(DefId) -> Lrc<Vec<DefId>>,
154 /// Maps from a trait item to the trait item "descriptor"
155 [] fn associated_item: AssociatedItems(DefId) -> ty::AssociatedItem,
157 [] fn impl_trait_ref: ImplTraitRef(DefId) -> Option<ty::TraitRef<'tcx>>,
158 [] fn impl_polarity: ImplPolarity(DefId) -> hir::ImplPolarity,
160 /// Maps a DefId of a type to a list of its inherent impls.
161 /// Contains implementations of methods that are inherent to a type.
162 /// Methods in these implementations don't need to be exported.
163 [] fn inherent_impls: InherentImpls(DefId) -> Lrc<Vec<DefId>>,
165 /// Set of all the def-ids in this crate that have MIR associated with
166 /// them. This includes all the body owners, but also things like struct
168 [] fn mir_keys: mir_keys(CrateNum) -> Lrc<DefIdSet>,
170 /// Maps DefId's that have an associated Mir to the result
171 /// of the MIR qualify_consts pass. The actual meaning of
172 /// the value isn't known except to the pass itself.
173 [] fn mir_const_qualif: MirConstQualif(DefId) -> (u8, Lrc<IdxSetBuf<mir::Local>>),
175 /// Fetch the MIR for a given def-id right after it's built - this includes
176 /// unreachable code.
177 [] fn mir_built: MirBuilt(DefId) -> &'tcx Steal<mir::Mir<'tcx>>,
179 /// Fetch the MIR for a given def-id up till the point where it is
180 /// ready for const evaluation.
182 /// See the README for the `mir` module for details.
183 [] fn mir_const: MirConst(DefId) -> &'tcx Steal<mir::Mir<'tcx>>,
185 [] fn mir_validated: MirValidated(DefId) -> &'tcx Steal<mir::Mir<'tcx>>,
187 /// MIR after our optimization passes have run. This is MIR that is ready
188 /// for codegen. This is also the only query that can fetch non-local MIR, at present.
189 [] fn optimized_mir: MirOptimized(DefId) -> &'tcx mir::Mir<'tcx>,
191 /// The result of unsafety-checking this def-id.
192 [] fn unsafety_check_result: UnsafetyCheckResult(DefId) -> mir::UnsafetyCheckResult,
194 /// HACK: when evaluated, this reports a "unsafe derive on repr(packed)" error
195 [] fn unsafe_derive_on_repr_packed: UnsafeDeriveOnReprPacked(DefId) -> (),
197 /// The signature of functions and closures.
198 [] fn fn_sig: FnSignature(DefId) -> ty::PolyFnSig<'tcx>,
200 /// Caches CoerceUnsized kinds for impls on custom types.
201 [] fn coerce_unsized_info: CoerceUnsizedInfo(DefId)
202 -> ty::adjustment::CoerceUnsizedInfo,
204 [] fn typeck_item_bodies: typeck_item_bodies_dep_node(CrateNum) -> CompileResult,
206 [] fn typeck_tables_of: TypeckTables(DefId) -> &'tcx ty::TypeckTables<'tcx>,
208 [] fn used_trait_imports: UsedTraitImports(DefId) -> Lrc<DefIdSet>,
210 [] fn has_typeck_tables: HasTypeckTables(DefId) -> bool,
212 [] fn coherent_trait: CoherenceCheckTrait(DefId) -> (),
214 [] fn borrowck: BorrowCheck(DefId) -> Lrc<BorrowCheckResult>,
216 /// Borrow checks the function body. If this is a closure, returns
217 /// additional requirements that the closure's creator must verify.
218 [] fn mir_borrowck: MirBorrowCheck(DefId) -> mir::BorrowCheckResult<'tcx>,
220 /// Gets a complete map from all types to their inherent impls.
221 /// Not meant to be used directly outside of coherence.
222 /// (Defined only for LOCAL_CRATE)
223 [] fn crate_inherent_impls: crate_inherent_impls_dep_node(CrateNum) -> CrateInherentImpls,
225 /// Checks all types in the krate for overlap in their inherent impls. Reports errors.
226 /// Not meant to be used directly outside of coherence.
227 /// (Defined only for LOCAL_CRATE)
228 [] fn crate_inherent_impls_overlap_check: inherent_impls_overlap_check_dep_node(CrateNum) -> (),
230 /// Results of evaluating const items or constants embedded in
231 /// other items (such as enum variant explicit discriminants).
232 [] fn const_eval: const_eval_dep_node(ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>)
233 -> ConstEvalResult<'tcx>,
235 /// Converts a constant value to an constant allocation
236 [] fn const_value_to_allocation: const_value_to_allocation(
237 &'tcx ty::Const<'tcx>
238 ) -> &'tcx Allocation,
240 [] fn check_match: CheckMatch(DefId)
241 -> Result<(), ErrorReported>,
243 /// Performs the privacy check and computes "access levels".
244 [] fn privacy_access_levels: PrivacyAccessLevels(CrateNum) -> Lrc<AccessLevels>,
246 [] fn reachable_set: reachability_dep_node(CrateNum) -> ReachableSet,
248 /// Per-body `region::ScopeTree`. The `DefId` should be the owner-def-id for the body;
249 /// in the case of closures, this will be redirected to the enclosing function.
250 [] fn region_scope_tree: RegionScopeTree(DefId) -> Lrc<region::ScopeTree>,
252 [] fn mir_shims: mir_shim_dep_node(ty::InstanceDef<'tcx>) -> &'tcx mir::Mir<'tcx>,
254 [] fn def_symbol_name: SymbolName(DefId) -> ty::SymbolName,
255 [] fn symbol_name: symbol_name_dep_node(ty::Instance<'tcx>) -> ty::SymbolName,
257 [] fn describe_def: DescribeDef(DefId) -> Option<Def>,
258 [] fn def_span: DefSpan(DefId) -> Span,
259 [] fn lookup_stability: LookupStability(DefId) -> Option<&'tcx attr::Stability>,
260 [] fn lookup_deprecation_entry: LookupDeprecationEntry(DefId) -> Option<DeprecationEntry>,
261 [] fn item_attrs: ItemAttrs(DefId) -> Lrc<[ast::Attribute]>,
262 [] fn codegen_fn_attrs: codegen_fn_attrs(DefId) -> CodegenFnAttrs,
263 [] fn fn_arg_names: FnArgNames(DefId) -> Vec<ast::Name>,
264 /// Gets the rendered value of the specified constant or associated constant.
266 [] fn rendered_const: RenderedConst(DefId) -> String,
267 [] fn impl_parent: ImplParent(DefId) -> Option<DefId>,
268 [] fn trait_of_item: TraitOfItem(DefId) -> Option<DefId>,
269 [] fn const_is_rvalue_promotable_to_static: ConstIsRvaluePromotableToStatic(DefId) -> bool,
270 [] fn rvalue_promotable_map: RvaluePromotableMap(DefId) -> Lrc<ItemLocalSet>,
271 [] fn is_mir_available: IsMirAvailable(DefId) -> bool,
272 [] fn vtable_methods: vtable_methods_node(ty::PolyTraitRef<'tcx>)
273 -> Lrc<Vec<Option<(DefId, &'tcx Substs<'tcx>)>>>,
275 [] fn codegen_fulfill_obligation: fulfill_obligation_dep_node(
276 (ty::ParamEnv<'tcx>, ty::PolyTraitRef<'tcx>)) -> Vtable<'tcx, ()>,
277 [] fn trait_impls_of: TraitImpls(DefId) -> Lrc<ty::trait_def::TraitImpls>,
278 [] fn specialization_graph_of: SpecializationGraph(DefId) -> Lrc<specialization_graph::Graph>,
279 [] fn is_object_safe: ObjectSafety(DefId) -> bool,
281 // Get the ParameterEnvironment for a given item; this environment
282 // will be in "user-facing" mode, meaning that it is suitabe for
283 // type-checking etc, and it does not normalize specializable
284 // associated types. This is almost always what you want,
285 // unless you are doing MIR optimizations, in which case you
286 // might want to use `reveal_all()` method to change modes.
287 [] fn param_env: ParamEnv(DefId) -> ty::ParamEnv<'tcx>,
289 // Trait selection queries. These are best used by invoking `ty.moves_by_default()`,
290 // `ty.is_copy()`, etc, since that will prune the environment where possible.
291 [] fn is_copy_raw: is_copy_dep_node(ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool,
292 [] fn is_sized_raw: is_sized_dep_node(ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool,
293 [] fn is_freeze_raw: is_freeze_dep_node(ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool,
294 [] fn needs_drop_raw: needs_drop_dep_node(ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool,
295 [] fn layout_raw: layout_dep_node(ty::ParamEnvAnd<'tcx, Ty<'tcx>>)
296 -> Result<&'tcx ty::layout::LayoutDetails,
297 ty::layout::LayoutError<'tcx>>,
299 [] fn dylib_dependency_formats: DylibDepFormats(CrateNum)
300 -> Lrc<Vec<(CrateNum, LinkagePreference)>>,
302 [fatal_cycle] fn is_panic_runtime: IsPanicRuntime(CrateNum) -> bool,
303 [fatal_cycle] fn is_compiler_builtins: IsCompilerBuiltins(CrateNum) -> bool,
304 [fatal_cycle] fn has_global_allocator: HasGlobalAllocator(CrateNum) -> bool,
305 [fatal_cycle] fn is_sanitizer_runtime: IsSanitizerRuntime(CrateNum) -> bool,
306 [fatal_cycle] fn is_profiler_runtime: IsProfilerRuntime(CrateNum) -> bool,
307 [fatal_cycle] fn panic_strategy: GetPanicStrategy(CrateNum) -> PanicStrategy,
308 [fatal_cycle] fn is_no_builtins: IsNoBuiltins(CrateNum) -> bool,
310 [] fn extern_crate: ExternCrate(DefId) -> Lrc<Option<ExternCrate>>,
312 [] fn specializes: specializes_node((DefId, DefId)) -> bool,
313 [] fn in_scope_traits_map: InScopeTraits(DefIndex)
314 -> Option<Lrc<FxHashMap<ItemLocalId, Lrc<StableVec<TraitCandidate>>>>>,
315 [] fn module_exports: ModuleExports(DefId) -> Option<Lrc<Vec<Export>>>,
316 [] fn lint_levels: lint_levels_node(CrateNum) -> Lrc<lint::LintLevelMap>,
318 [] fn impl_defaultness: ImplDefaultness(DefId) -> hir::Defaultness,
320 [] fn check_item_well_formed: CheckItemWellFormed(DefId) -> (),
321 [] fn check_trait_item_well_formed: CheckTraitItemWellFormed(DefId) -> (),
322 [] fn check_impl_item_well_formed: CheckImplItemWellFormed(DefId) -> (),
324 // The DefIds of all non-generic functions and statics in the given crate
325 // that can be reached from outside the crate.
327 // We expect this items to be available for being linked to.
329 // This query can also be called for LOCAL_CRATE. In this case it will
330 // compute which items will be reachable to other crates, taking into account
331 // the kind of crate that is currently compiled. Crates with only a
332 // C interface have fewer reachable things.
334 // Does not include external symbols that don't have a corresponding DefId,
335 // like the compiler-generated `main` function and so on.
336 [] fn reachable_non_generics: ReachableNonGenerics(CrateNum)
337 -> Lrc<DefIdMap<SymbolExportLevel>>,
338 [] fn is_reachable_non_generic: IsReachableNonGeneric(DefId) -> bool,
339 [] fn is_unreachable_local_definition: IsUnreachableLocalDefinition(DefId) -> bool,
341 [] fn upstream_monomorphizations: UpstreamMonomorphizations(CrateNum)
342 -> Lrc<DefIdMap<Lrc<FxHashMap<&'tcx Substs<'tcx>, CrateNum>>>>,
343 [] fn upstream_monomorphizations_for: UpstreamMonomorphizationsFor(DefId)
344 -> Option<Lrc<FxHashMap<&'tcx Substs<'tcx>, CrateNum>>>,
346 [] fn native_libraries: NativeLibraries(CrateNum) -> Lrc<Vec<NativeLibrary>>,
348 [] fn foreign_modules: ForeignModules(CrateNum) -> Lrc<Vec<ForeignModule>>,
350 [] fn plugin_registrar_fn: PluginRegistrarFn(CrateNum) -> Option<DefId>,
351 [] fn derive_registrar_fn: DeriveRegistrarFn(CrateNum) -> Option<DefId>,
352 [] fn crate_disambiguator: CrateDisambiguator(CrateNum) -> CrateDisambiguator,
353 [] fn crate_hash: CrateHash(CrateNum) -> Svh,
354 [] fn original_crate_name: OriginalCrateName(CrateNum) -> Symbol,
355 [] fn extra_filename: ExtraFileName(CrateNum) -> String,
357 [] fn implementations_of_trait: implementations_of_trait_node((CrateNum, DefId))
359 [] fn all_trait_implementations: AllTraitImplementations(CrateNum)
362 [] fn dllimport_foreign_items: DllimportForeignItems(CrateNum)
363 -> Lrc<FxHashSet<DefId>>,
364 [] fn is_dllimport_foreign_item: IsDllimportForeignItem(DefId) -> bool,
365 [] fn is_statically_included_foreign_item: IsStaticallyIncludedForeignItem(DefId) -> bool,
366 [] fn native_library_kind: NativeLibraryKind(DefId)
367 -> Option<NativeLibraryKind>,
368 [] fn link_args: link_args_node(CrateNum) -> Lrc<Vec<String>>,
370 // Lifetime resolution. See `middle::resolve_lifetimes`.
371 [] fn resolve_lifetimes: ResolveLifetimes(CrateNum) -> Lrc<ResolveLifetimes>,
372 [] fn named_region_map: NamedRegion(DefIndex) ->
373 Option<Lrc<FxHashMap<ItemLocalId, Region>>>,
374 [] fn is_late_bound_map: IsLateBound(DefIndex) ->
375 Option<Lrc<FxHashSet<ItemLocalId>>>,
376 [] fn object_lifetime_defaults_map: ObjectLifetimeDefaults(DefIndex)
377 -> Option<Lrc<FxHashMap<ItemLocalId, Lrc<Vec<ObjectLifetimeDefault>>>>>,
379 [] fn visibility: Visibility(DefId) -> ty::Visibility,
380 [] fn dep_kind: DepKind(CrateNum) -> DepKind,
381 [] fn crate_name: CrateName(CrateNum) -> Symbol,
382 [] fn item_children: ItemChildren(DefId) -> Lrc<Vec<Export>>,
383 [] fn extern_mod_stmt_cnum: ExternModStmtCnum(DefId) -> Option<CrateNum>,
385 [] fn get_lang_items: get_lang_items_node(CrateNum) -> Lrc<LanguageItems>,
386 [] fn defined_lang_items: DefinedLangItems(CrateNum) -> Lrc<Vec<(DefId, usize)>>,
387 [] fn missing_lang_items: MissingLangItems(CrateNum) -> Lrc<Vec<LangItem>>,
388 [] fn visible_parent_map: visible_parent_map_node(CrateNum)
389 -> Lrc<DefIdMap<DefId>>,
390 [] fn missing_extern_crate_item: MissingExternCrateItem(CrateNum) -> bool,
391 [] fn used_crate_source: UsedCrateSource(CrateNum) -> Lrc<CrateSource>,
392 [] fn postorder_cnums: postorder_cnums_node(CrateNum) -> Lrc<Vec<CrateNum>>,
394 [] fn freevars: Freevars(DefId) -> Option<Lrc<Vec<hir::Freevar>>>,
395 [] fn maybe_unused_trait_import: MaybeUnusedTraitImport(DefId) -> bool,
396 [] fn maybe_unused_extern_crates: maybe_unused_extern_crates_node(CrateNum)
397 -> Lrc<Vec<(DefId, Span)>>,
399 [] fn stability_index: stability_index_node(CrateNum) -> Lrc<stability::Index<'tcx>>,
400 [] fn all_crate_nums: all_crate_nums_node(CrateNum) -> Lrc<Vec<CrateNum>>,
402 /// A vector of every trait accessible in the whole crate
403 /// (i.e. including those from subcrates). This is used only for
405 [] fn all_traits: all_traits_node(CrateNum) -> Lrc<Vec<DefId>>,
407 [] fn exported_symbols: ExportedSymbols(CrateNum)
408 -> Arc<Vec<(ExportedSymbol<'tcx>, SymbolExportLevel)>>,
409 [] fn collect_and_partition_mono_items:
410 collect_and_partition_mono_items_node(CrateNum)
411 -> (Arc<DefIdSet>, Arc<Vec<Arc<CodegenUnit<'tcx>>>>),
412 [] fn is_codegened_item: IsCodegenedItem(DefId) -> bool,
413 [] fn codegen_unit: CodegenUnit(InternedString) -> Arc<CodegenUnit<'tcx>>,
414 [] fn compile_codegen_unit: CompileCodegenUnit(InternedString) -> Stats,
415 [] fn output_filenames: output_filenames_node(CrateNum)
416 -> Arc<OutputFilenames>,
418 // Erases regions from `ty` to yield a new type.
419 // Normally you would just use `tcx.erase_regions(&value)`,
420 // however, which uses this query as a kind of cache.
421 [] fn erase_regions_ty: erase_regions_ty(Ty<'tcx>) -> Ty<'tcx>,
423 /// Do not call this query directly: invoke `normalize` instead.
424 [] fn normalize_projection_ty: NormalizeProjectionTy(
425 CanonicalProjectionGoal<'tcx>
427 Lrc<Canonical<'tcx, canonical::QueryResult<'tcx, NormalizationResult<'tcx>>>>,
431 /// Do not call this query directly: invoke `normalize_erasing_regions` instead.
432 [] fn normalize_ty_after_erasing_regions: NormalizeTyAfterErasingRegions(
433 ParamEnvAnd<'tcx, Ty<'tcx>>
436 /// Do not call this query directly: invoke `infcx.at().dropck_outlives()` instead.
437 [] fn dropck_outlives: DropckOutlives(
438 CanonicalTyGoal<'tcx>
440 Lrc<Canonical<'tcx, canonical::QueryResult<'tcx, DropckOutlivesResult<'tcx>>>>,
444 /// Do not call this query directly: invoke `infcx.predicate_may_hold()` or
445 /// `infcx.predicate_must_hold()` instead.
446 [] fn evaluate_obligation: EvaluateObligation(
447 CanonicalPredicateGoal<'tcx>
448 ) -> Result<traits::EvaluationResult, traits::OverflowError>,
450 /// Do not call this query directly: part of the `Eq` type-op
451 [] fn type_op_eq: TypeOpEq(
452 CanonicalTypeOpEqGoal<'tcx>
454 Lrc<Canonical<'tcx, canonical::QueryResult<'tcx, ()>>>,
458 /// Do not call this query directly: part of the `Subtype` type-op
459 [] fn type_op_subtype: TypeOpSubtype(
460 CanonicalTypeOpSubtypeGoal<'tcx>
462 Lrc<Canonical<'tcx, canonical::QueryResult<'tcx, ()>>>,
466 /// Do not call this query directly: part of the `ProvePredicate` type-op
467 [] fn type_op_prove_predicate: TypeOpProvePredicate(
468 CanonicalTypeOpProvePredicateGoal<'tcx>
470 Lrc<Canonical<'tcx, canonical::QueryResult<'tcx, ()>>>,
474 /// Do not call this query directly: part of the `Normalize` type-op
475 [] fn type_op_normalize_ty: TypeOpNormalizeTy(
476 CanonicalTypeOpNormalizeGoal<'tcx, Ty<'tcx>>
478 Lrc<Canonical<'tcx, canonical::QueryResult<'tcx, Ty<'tcx>>>>,
482 /// Do not call this query directly: part of the `Normalize` type-op
483 [] fn type_op_normalize_predicate: TypeOpNormalizePredicate(
484 CanonicalTypeOpNormalizeGoal<'tcx, ty::Predicate<'tcx>>
486 Lrc<Canonical<'tcx, canonical::QueryResult<'tcx, ty::Predicate<'tcx>>>>,
490 /// Do not call this query directly: part of the `Normalize` type-op
491 [] fn type_op_normalize_poly_fn_sig: TypeOpNormalizePolyFnSig(
492 CanonicalTypeOpNormalizeGoal<'tcx, ty::PolyFnSig<'tcx>>
494 Lrc<Canonical<'tcx, canonical::QueryResult<'tcx, ty::PolyFnSig<'tcx>>>>,
498 /// Do not call this query directly: part of the `Normalize` type-op
499 [] fn type_op_normalize_fn_sig: TypeOpNormalizeFnSig(
500 CanonicalTypeOpNormalizeGoal<'tcx, ty::FnSig<'tcx>>
502 Lrc<Canonical<'tcx, canonical::QueryResult<'tcx, ty::FnSig<'tcx>>>>,
506 [] fn substitute_normalize_and_test_predicates:
507 substitute_normalize_and_test_predicates_node((DefId, &'tcx Substs<'tcx>)) -> bool,
509 [] fn target_features_whitelist:
510 target_features_whitelist_node(CrateNum) -> Lrc<FxHashMap<String, Option<String>>>,
512 // Get an estimate of the size of an InstanceDef based on its MIR for CGU partitioning.
513 [] fn instance_def_size_estimate: instance_def_size_estimate_dep_node(ty::InstanceDef<'tcx>)
516 [] fn features_query: features_node(CrateNum) -> Lrc<feature_gate::Features>,
518 [] fn program_clauses_for: ProgramClausesFor(DefId) -> Clauses<'tcx>,
520 [] fn program_clauses_for_env: ProgramClausesForEnv(
524 [] fn wasm_custom_sections: WasmCustomSections(CrateNum) -> Lrc<Vec<DefId>>,
525 [] fn wasm_import_module_map: WasmImportModuleMap(CrateNum)
526 -> Lrc<FxHashMap<DefId, String>>,
529 // `try_get_query` can't be public because it uses the private query
530 // implementation traits, so we provide access to it selectively.
531 impl<'a, 'tcx, 'lcx> TyCtxt<'a, 'tcx, 'lcx> {
532 pub fn try_adt_sized_constraint(
536 ) -> Result<&'tcx [Ty<'tcx>], DiagnosticBuilder<'a>> {
537 self.try_get_query::<queries::adt_sized_constraint>(span, key)
539 pub fn try_needs_drop_raw(
542 key: ty::ParamEnvAnd<'tcx, Ty<'tcx>>,
543 ) -> Result<bool, DiagnosticBuilder<'a>> {
544 self.try_get_query::<queries::needs_drop_raw>(span, key)
546 pub fn try_optimized_mir(
550 ) -> Result<&'tcx mir::Mir<'tcx>, DiagnosticBuilder<'a>> {
551 self.try_get_query::<queries::optimized_mir>(span, key)
555 //////////////////////////////////////////////////////////////////////
556 // These functions are little shims used to find the dep-node for a
557 // given query when there is not a *direct* mapping:
560 fn features_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
561 DepConstructor::Features
564 fn codegen_fn_attrs<'tcx>(id: DefId) -> DepConstructor<'tcx> {
565 DepConstructor::CodegenFnAttrs { 0: id }
568 fn erase_regions_ty<'tcx>(ty: Ty<'tcx>) -> DepConstructor<'tcx> {
569 DepConstructor::EraseRegionsTy { ty }
572 fn const_value_to_allocation<'tcx>(
573 val: &'tcx ty::Const<'tcx>,
574 ) -> DepConstructor<'tcx> {
575 DepConstructor::ConstValueToAllocation { val }
578 fn type_param_predicates<'tcx>((item_id, param_id): (DefId, DefId)) -> DepConstructor<'tcx> {
579 DepConstructor::TypeParamPredicates {
585 fn fulfill_obligation_dep_node<'tcx>((param_env, trait_ref):
586 (ty::ParamEnv<'tcx>, ty::PolyTraitRef<'tcx>)) -> DepConstructor<'tcx> {
587 DepConstructor::FulfillObligation {
593 fn crate_inherent_impls_dep_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
594 DepConstructor::Coherence
597 fn inherent_impls_overlap_check_dep_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
598 DepConstructor::CoherenceInherentImplOverlapCheck
601 fn reachability_dep_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
602 DepConstructor::Reachability
605 fn mir_shim_dep_node<'tcx>(instance_def: ty::InstanceDef<'tcx>) -> DepConstructor<'tcx> {
606 DepConstructor::MirShim {
611 fn symbol_name_dep_node<'tcx>(instance: ty::Instance<'tcx>) -> DepConstructor<'tcx> {
612 DepConstructor::InstanceSymbolName { instance }
615 fn typeck_item_bodies_dep_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
616 DepConstructor::TypeckBodiesKrate
619 fn const_eval_dep_node<'tcx>(param_env: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>)
620 -> DepConstructor<'tcx> {
621 DepConstructor::ConstEval { param_env }
624 fn mir_keys<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
625 DepConstructor::MirKeys
628 fn crate_variances<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
629 DepConstructor::CrateVariances
632 fn is_copy_dep_node<'tcx>(param_env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> DepConstructor<'tcx> {
633 DepConstructor::IsCopy { param_env }
636 fn is_sized_dep_node<'tcx>(param_env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> DepConstructor<'tcx> {
637 DepConstructor::IsSized { param_env }
640 fn is_freeze_dep_node<'tcx>(param_env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> DepConstructor<'tcx> {
641 DepConstructor::IsFreeze { param_env }
644 fn needs_drop_dep_node<'tcx>(param_env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> DepConstructor<'tcx> {
645 DepConstructor::NeedsDrop { param_env }
648 fn layout_dep_node<'tcx>(param_env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> DepConstructor<'tcx> {
649 DepConstructor::Layout { param_env }
652 fn lint_levels_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
653 DepConstructor::LintLevels
656 fn specializes_node<'tcx>((a, b): (DefId, DefId)) -> DepConstructor<'tcx> {
657 DepConstructor::Specializes { impl1: a, impl2: b }
660 fn implementations_of_trait_node<'tcx>((krate, trait_id): (CrateNum, DefId))
661 -> DepConstructor<'tcx>
663 DepConstructor::ImplementationsOfTrait { krate, trait_id }
666 fn link_args_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
667 DepConstructor::LinkArgs
670 fn get_lang_items_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
671 DepConstructor::GetLangItems
674 fn visible_parent_map_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
675 DepConstructor::VisibleParentMap
678 fn postorder_cnums_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
679 DepConstructor::PostorderCnums
682 fn maybe_unused_extern_crates_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
683 DepConstructor::MaybeUnusedExternCrates
686 fn stability_index_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
687 DepConstructor::StabilityIndex
690 fn all_crate_nums_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
691 DepConstructor::AllCrateNums
694 fn all_traits_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
695 DepConstructor::AllTraits
698 fn collect_and_partition_mono_items_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
699 DepConstructor::CollectAndPartitionMonoItems
702 fn output_filenames_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
703 DepConstructor::OutputFilenames
706 fn vtable_methods_node<'tcx>(trait_ref: ty::PolyTraitRef<'tcx>) -> DepConstructor<'tcx> {
707 DepConstructor::VtableMethods{ trait_ref }
710 fn substitute_normalize_and_test_predicates_node<'tcx>(key: (DefId, &'tcx Substs<'tcx>))
711 -> DepConstructor<'tcx> {
712 DepConstructor::SubstituteNormalizeAndTestPredicates { key }
715 fn target_features_whitelist_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
716 DepConstructor::TargetFeaturesWhitelist
719 fn instance_def_size_estimate_dep_node<'tcx>(instance_def: ty::InstanceDef<'tcx>)
720 -> DepConstructor<'tcx> {
721 DepConstructor::InstanceDefSizeEstimate {