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::{DepNode, DepTrackingMapConfig};
12 use hir::def_id::{CrateNum, CRATE_DEF_INDEX, DefId, LOCAL_CRATE};
15 use middle::const_val;
16 use middle::privacy::AccessLevels;
17 use middle::region::RegionMaps;
19 use mir::transform::{MirSuite, MirPassIndex};
20 use session::CompileResult;
21 use traits::specialization_graph;
22 use ty::{self, CrateInherentImpls, Ty, TyCtxt};
23 use ty::layout::{Layout, LayoutError};
26 use ty::subst::Substs;
27 use ty::fast_reject::SimplifiedType;
28 use util::nodemap::{DefIdSet, NodeSet};
30 use rustc_data_structures::indexed_vec::IndexVec;
31 use rustc_data_structures::fx::FxHashMap;
32 use std::cell::{RefCell, RefMut};
35 use std::marker::PhantomData;
37 use std::collections::BTreeMap;
40 use syntax_pos::{Span, DUMMY_SP};
43 use syntax::symbol::Symbol;
45 pub trait Key: Clone + Hash + Eq + Debug {
46 fn map_crate(&self) -> CrateNum;
47 fn default_span(&self, tcx: TyCtxt) -> Span;
50 impl<'tcx> Key for ty::InstanceDef<'tcx> {
51 fn map_crate(&self) -> CrateNum {
55 fn default_span(&self, tcx: TyCtxt) -> Span {
56 tcx.def_span(self.def_id())
60 impl<'tcx> Key for ty::Instance<'tcx> {
61 fn map_crate(&self) -> CrateNum {
65 fn default_span(&self, tcx: TyCtxt) -> Span {
66 tcx.def_span(self.def_id())
70 impl Key for CrateNum {
71 fn map_crate(&self) -> CrateNum {
74 fn default_span(&self, _: TyCtxt) -> Span {
80 fn map_crate(&self) -> CrateNum {
83 fn default_span(&self, tcx: TyCtxt) -> Span {
88 impl Key for (DefId, DefId) {
89 fn map_crate(&self) -> CrateNum {
92 fn default_span(&self, tcx: TyCtxt) -> Span {
93 self.1.default_span(tcx)
97 impl Key for (CrateNum, DefId) {
98 fn map_crate(&self) -> CrateNum {
101 fn default_span(&self, tcx: TyCtxt) -> Span {
102 self.1.default_span(tcx)
106 impl Key for (DefId, SimplifiedType) {
107 fn map_crate(&self) -> CrateNum {
110 fn default_span(&self, tcx: TyCtxt) -> Span {
111 self.0.default_span(tcx)
115 impl<'tcx> Key for (DefId, &'tcx Substs<'tcx>) {
116 fn map_crate(&self) -> CrateNum {
119 fn default_span(&self, tcx: TyCtxt) -> Span {
120 self.0.default_span(tcx)
124 impl Key for (MirSuite, DefId) {
125 fn map_crate(&self) -> CrateNum {
128 fn default_span(&self, tcx: TyCtxt) -> Span {
129 self.1.default_span(tcx)
133 impl Key for (MirSuite, MirPassIndex, DefId) {
134 fn map_crate(&self) -> CrateNum {
137 fn default_span(&self, tcx: TyCtxt) -> Span {
138 self.2.default_span(tcx)
142 impl<'tcx, T: Clone + Hash + Eq + Debug> Key for ty::ParamEnvAnd<'tcx, T> {
143 fn map_crate(&self) -> CrateNum {
146 fn default_span(&self, _: TyCtxt) -> Span {
151 trait Value<'tcx>: Sized {
152 fn from_cycle_error<'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> Self;
155 impl<'tcx, T> Value<'tcx> for T {
156 default fn from_cycle_error<'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> T {
157 tcx.sess.abort_if_errors();
158 bug!("Value::from_cycle_error called without errors");
162 impl<'tcx, T: Default> Value<'tcx> for T {
163 default fn from_cycle_error<'a>(_: TyCtxt<'a, 'tcx, 'tcx>) -> T {
168 impl<'tcx> Value<'tcx> for Ty<'tcx> {
169 fn from_cycle_error<'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> Ty<'tcx> {
174 impl<'tcx> Value<'tcx> for ty::DtorckConstraint<'tcx> {
175 fn from_cycle_error<'a>(_: TyCtxt<'a, 'tcx, 'tcx>) -> Self {
180 impl<'tcx> Value<'tcx> for ty::SymbolName {
181 fn from_cycle_error<'a>(_: TyCtxt<'a, 'tcx, 'tcx>) -> Self {
182 ty::SymbolName { name: Symbol::intern("<error>").as_str() }
186 struct QueryMap<D: QueryDescription> {
187 phantom: PhantomData<D>,
188 map: FxHashMap<D::Key, D::Value>,
191 impl<M: QueryDescription> QueryMap<M> {
192 fn new() -> QueryMap<M> {
194 phantom: PhantomData,
200 pub struct CycleError<'a, 'tcx: 'a> {
202 cycle: RefMut<'a, [(Span, Query<'tcx>)]>,
205 impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
206 pub fn report_cycle(self, CycleError { span, cycle }: CycleError) {
207 // Subtle: release the refcell lock before invoking `describe()`
208 // below by dropping `cycle`.
209 let stack = cycle.to_vec();
212 assert!(!stack.is_empty());
214 // Disable naming impls with types in this path, since that
215 // sometimes cycles itself, leading to extra cycle errors.
216 // (And cycle errors around impls tend to occur during the
217 // collect/coherence phases anyhow.)
218 item_path::with_forced_impl_filename_line(|| {
220 struct_span_err!(self.sess, span, E0391,
221 "unsupported cyclic reference between types/traits detected");
222 err.span_label(span, "cyclic reference");
224 err.span_note(stack[0].0, &format!("the cycle begins when {}...",
225 stack[0].1.describe(self)));
227 for &(span, ref query) in &stack[1..] {
228 err.span_note(span, &format!("...which then requires {}...",
229 query.describe(self)));
232 err.note(&format!("...which then again requires {}, completing the cycle.",
233 stack[0].1.describe(self)));
239 fn cycle_check<F, R>(self, span: Span, query: Query<'gcx>, compute: F)
240 -> Result<R, CycleError<'a, 'gcx>>
241 where F: FnOnce() -> R
244 let mut stack = self.maps.query_stack.borrow_mut();
245 if let Some((i, _)) = stack.iter().enumerate().rev()
246 .find(|&(_, &(_, ref q))| *q == query) {
247 return Err(CycleError {
249 cycle: RefMut::map(stack, |stack| &mut stack[i..])
252 stack.push((span, query));
255 let result = compute();
257 self.maps.query_stack.borrow_mut().pop();
263 trait QueryDescription: DepTrackingMapConfig {
264 fn describe(tcx: TyCtxt, key: Self::Key) -> String;
267 impl<M: DepTrackingMapConfig<Key=DefId>> QueryDescription for M {
268 default fn describe(tcx: TyCtxt, def_id: DefId) -> String {
269 format!("processing `{}`", tcx.item_path_str(def_id))
273 impl<'tcx> QueryDescription for queries::is_copy_raw<'tcx> {
274 fn describe(_tcx: TyCtxt, env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> String {
275 format!("computing whether `{}` is `Copy`", env.value)
279 impl<'tcx> QueryDescription for queries::is_sized_raw<'tcx> {
280 fn describe(_tcx: TyCtxt, env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> String {
281 format!("computing whether `{}` is `Sized`", env.value)
285 impl<'tcx> QueryDescription for queries::is_freeze_raw<'tcx> {
286 fn describe(_tcx: TyCtxt, env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> String {
287 format!("computing whether `{}` is freeze", env.value)
291 impl<'tcx> QueryDescription for queries::needs_drop_raw<'tcx> {
292 fn describe(_tcx: TyCtxt, env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> String {
293 format!("computing whether `{}` needs drop", env.value)
297 impl<'tcx> QueryDescription for queries::layout_raw<'tcx> {
298 fn describe(_tcx: TyCtxt, env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> String {
299 format!("computing layout of `{}`", env.value)
303 impl<'tcx> QueryDescription for queries::super_predicates_of<'tcx> {
304 fn describe(tcx: TyCtxt, def_id: DefId) -> String {
305 format!("computing the supertraits of `{}`",
306 tcx.item_path_str(def_id))
310 impl<'tcx> QueryDescription for queries::type_param_predicates<'tcx> {
311 fn describe(tcx: TyCtxt, (_, def_id): (DefId, DefId)) -> String {
312 let id = tcx.hir.as_local_node_id(def_id).unwrap();
313 format!("computing the bounds for type parameter `{}`",
314 tcx.hir.ty_param_name(id))
318 impl<'tcx> QueryDescription for queries::coherent_trait<'tcx> {
319 fn describe(tcx: TyCtxt, (_, def_id): (CrateNum, DefId)) -> String {
320 format!("coherence checking all impls of trait `{}`",
321 tcx.item_path_str(def_id))
325 impl<'tcx> QueryDescription for queries::crate_inherent_impls<'tcx> {
326 fn describe(_: TyCtxt, k: CrateNum) -> String {
327 format!("all inherent impls defined in crate `{:?}`", k)
331 impl<'tcx> QueryDescription for queries::crate_inherent_impls_overlap_check<'tcx> {
332 fn describe(_: TyCtxt, _: CrateNum) -> String {
333 format!("check for overlap between inherent impls defined in this crate")
337 impl<'tcx> QueryDescription for queries::crate_variances<'tcx> {
338 fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
339 format!("computing the variances for items in this crate")
343 impl<'tcx> QueryDescription for queries::mir_shims<'tcx> {
344 fn describe(tcx: TyCtxt, def: ty::InstanceDef<'tcx>) -> String {
345 format!("generating MIR shim for `{}`",
346 tcx.item_path_str(def.def_id()))
350 impl<'tcx> QueryDescription for queries::privacy_access_levels<'tcx> {
351 fn describe(_: TyCtxt, _: CrateNum) -> String {
352 format!("privacy access levels")
356 impl<'tcx> QueryDescription for queries::typeck_item_bodies<'tcx> {
357 fn describe(_: TyCtxt, _: CrateNum) -> String {
358 format!("type-checking all item bodies")
362 impl<'tcx> QueryDescription for queries::reachable_set<'tcx> {
363 fn describe(_: TyCtxt, _: CrateNum) -> String {
364 format!("reachability")
368 impl<'tcx> QueryDescription for queries::const_eval<'tcx> {
369 fn describe(tcx: TyCtxt, (def_id, _): (DefId, &'tcx Substs<'tcx>)) -> String {
370 format!("const-evaluating `{}`", tcx.item_path_str(def_id))
374 impl<'tcx> QueryDescription for queries::mir_keys<'tcx> {
375 fn describe(_: TyCtxt, _: CrateNum) -> String {
376 format!("getting a list of all mir_keys")
380 impl<'tcx> QueryDescription for queries::symbol_name<'tcx> {
381 fn describe(_tcx: TyCtxt, instance: ty::Instance<'tcx>) -> String {
382 format!("computing the symbol for `{}`", instance)
386 impl<'tcx> QueryDescription for queries::describe_def<'tcx> {
387 fn describe(_: TyCtxt, _: DefId) -> String {
392 impl<'tcx> QueryDescription for queries::def_span<'tcx> {
393 fn describe(_: TyCtxt, _: DefId) -> String {
399 impl<'tcx> QueryDescription for queries::stability<'tcx> {
400 fn describe(_: TyCtxt, _: DefId) -> String {
405 impl<'tcx> QueryDescription for queries::deprecation<'tcx> {
406 fn describe(_: TyCtxt, _: DefId) -> String {
411 impl<'tcx> QueryDescription for queries::item_attrs<'tcx> {
412 fn describe(_: TyCtxt, _: DefId) -> String {
417 impl<'tcx> QueryDescription for queries::is_exported_symbol<'tcx> {
418 fn describe(_: TyCtxt, _: DefId) -> String {
419 bug!("is_exported_symbol")
423 impl<'tcx> QueryDescription for queries::fn_arg_names<'tcx> {
424 fn describe(_: TyCtxt, _: DefId) -> String {
429 impl<'tcx> QueryDescription for queries::impl_parent<'tcx> {
430 fn describe(_: TyCtxt, _: DefId) -> String {
435 impl<'tcx> QueryDescription for queries::trait_of_item<'tcx> {
436 fn describe(_: TyCtxt, _: DefId) -> String {
437 bug!("trait_of_item")
441 impl<'tcx> QueryDescription for queries::item_body_nested_bodies<'tcx> {
442 fn describe(tcx: TyCtxt, def_id: DefId) -> String {
443 format!("nested item bodies of `{}`", tcx.item_path_str(def_id))
447 impl<'tcx> QueryDescription for queries::const_is_rvalue_promotable_to_static<'tcx> {
448 fn describe(tcx: TyCtxt, def_id: DefId) -> String {
449 format!("const checking if rvalue is promotable to static `{}`",
450 tcx.item_path_str(def_id))
454 impl<'tcx> QueryDescription for queries::is_mir_available<'tcx> {
455 fn describe(tcx: TyCtxt, def_id: DefId) -> String {
456 format!("checking if item is mir available: `{}`",
457 tcx.item_path_str(def_id))
461 impl<'tcx> QueryDescription for queries::trait_impls_of<'tcx> {
462 fn describe(tcx: TyCtxt, def_id: DefId) -> String {
463 format!("trait impls of `{}`", tcx.item_path_str(def_id))
467 impl<'tcx> QueryDescription for queries::relevant_trait_impls_for<'tcx> {
468 fn describe(tcx: TyCtxt, (def_id, ty): (DefId, SimplifiedType)) -> String {
469 format!("relevant impls for: `({}, {:?})`", tcx.item_path_str(def_id), ty)
473 impl<'tcx> QueryDescription for queries::is_object_safe<'tcx> {
474 fn describe(tcx: TyCtxt, def_id: DefId) -> String {
475 format!("determine object safety of trait `{}`", tcx.item_path_str(def_id))
479 macro_rules! define_maps {
482 [$($modifiers:tt)*] $name:ident: $node:ident($K:ty) -> $V:ty,)*) => {
485 input: ($(([$($modifiers)*] [$($attr)*] [$name]))*)
488 impl<$tcx> Maps<$tcx> {
489 pub fn new(providers: IndexVec<CrateNum, Providers<$tcx>>)
493 query_stack: RefCell::new(vec![]),
494 $($name: RefCell::new(QueryMap::new())),*
500 #[derive(Copy, Clone, Debug, PartialEq, Eq)]
501 pub enum Query<$tcx> {
502 $($(#[$attr])* $name($K)),*
505 impl<$tcx> Query<$tcx> {
506 pub fn describe(&self, tcx: TyCtxt) -> String {
508 $(Query::$name(key) => queries::$name::describe(tcx, key)),*
514 use std::marker::PhantomData;
516 $(#[allow(bad_style)]
517 pub struct $name<$tcx> {
518 data: PhantomData<&$tcx ()>
522 $(impl<$tcx> DepTrackingMapConfig for queries::$name<$tcx> {
527 fn to_dep_node(key: &$K) -> DepNode<DefId> {
528 use dep_graph::DepNode::*;
533 impl<'a, $tcx, 'lcx> queries::$name<$tcx> {
534 fn try_get_with<F, R>(tcx: TyCtxt<'a, $tcx, 'lcx>,
538 -> Result<R, CycleError<'a, $tcx>>
539 where F: FnOnce(&$V) -> R
541 debug!("ty::queries::{}::try_get_with(key={:?}, span={:?})",
546 if let Some(result) = tcx.maps.$name.borrow().map.get(&key) {
547 return Ok(f(result));
550 // FIXME(eddyb) Get more valid Span's on queries.
551 // def_span guard is necesary to prevent a recursive loop,
552 // default_span calls def_span query internally.
553 if span == DUMMY_SP && stringify!($name) != "def_span" {
554 span = key.default_span(tcx)
557 let _task = tcx.dep_graph.in_task(Self::to_dep_node(&key));
559 let result = tcx.cycle_check(span, Query::$name(key), || {
560 let provider = tcx.maps.providers[key.map_crate()].$name;
561 provider(tcx.global_tcx(), key)
564 Ok(f(tcx.maps.$name.borrow_mut().map.entry(key).or_insert(result)))
567 pub fn try_get(tcx: TyCtxt<'a, $tcx, 'lcx>, span: Span, key: $K)
568 -> Result<$V, CycleError<'a, $tcx>> {
569 // We register the `read` here, but not in `force`, since
570 // `force` does not give access to the value produced (and thus
571 // we actually don't read it).
572 tcx.dep_graph.read(Self::to_dep_node(&key));
573 Self::try_get_with(tcx, span, key, Clone::clone)
576 pub fn force(tcx: TyCtxt<'a, $tcx, 'lcx>, span: Span, key: $K) {
577 match Self::try_get_with(tcx, span, key, |_| ()) {
579 Err(e) => tcx.report_cycle(e)
584 #[derive(Copy, Clone)]
585 pub struct TyCtxtAt<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
586 pub tcx: TyCtxt<'a, 'gcx, 'tcx>,
590 impl<'a, 'gcx, 'tcx> Deref for TyCtxtAt<'a, 'gcx, 'tcx> {
591 type Target = TyCtxt<'a, 'gcx, 'tcx>;
592 fn deref(&self) -> &Self::Target {
597 impl<'a, $tcx, 'lcx> TyCtxt<'a, $tcx, 'lcx> {
598 /// Return a transparent wrapper for `TyCtxt` which uses
599 /// `span` as the location of queries performed through it.
600 pub fn at(self, span: Span) -> TyCtxtAt<'a, $tcx, 'lcx> {
608 pub fn $name(self, key: $K) -> $V {
609 self.at(DUMMY_SP).$name(key)
613 impl<'a, $tcx, 'lcx> TyCtxtAt<'a, $tcx, 'lcx> {
615 pub fn $name(self, key: $K) -> $V {
616 queries::$name::try_get(self.tcx, self.span, key).unwrap_or_else(|e| {
617 self.report_cycle(e);
618 Value::from_cycle_error(self.global_tcx())
623 define_provider_struct! {
625 input: ($(([$($modifiers)*] [$name] [$K] [$V]))*),
629 impl<$tcx> Copy for Providers<$tcx> {}
630 impl<$tcx> Clone for Providers<$tcx> {
631 fn clone(&self) -> Self { *self }
636 macro_rules! define_map_struct {
639 input: $input:tt) => {
650 output: ($($output:tt)*)) => {
651 pub struct Maps<$tcx> {
652 providers: IndexVec<CrateNum, Providers<$tcx>>,
653 query_stack: RefCell<Vec<(Span, Query<$tcx>)>>,
658 // Field recognized and ready to shift into the output
660 ready: ([$($pub:tt)*] [$($attr:tt)*] [$name:ident]),
662 output: ($($output:tt)*)) => {
667 $(#[$attr])* $($pub)* $name: RefCell<QueryMap<queries::$name<$tcx>>>,)
671 // No modifiers left? This is a private item.
673 input: (([] $attrs:tt $name:tt) $($input:tt)*),
674 output: $output:tt) => {
677 ready: ([] $attrs $name),
683 // Skip other modifiers
685 input: (([$other_modifier:tt $($modifiers:tt)*] $($fields:tt)*) $($input:tt)*),
686 output: $output:tt) => {
689 input: (([$($modifiers)*] $($fields)*) $($input)*),
695 macro_rules! define_provider_struct {
697 (tcx: $tcx:tt, input: $input:tt) => {
698 define_provider_struct! {
708 output: ($(([$name:ident] [$K:ty] [$R:ty]))*)) => {
709 pub struct Providers<$tcx> {
710 $(pub $name: for<'a> fn(TyCtxt<'a, $tcx, $tcx>, $K) -> $R,)*
713 impl<$tcx> Default for Providers<$tcx> {
714 fn default() -> Self {
715 $(fn $name<'a, $tcx>(_: TyCtxt<'a, $tcx, $tcx>, key: $K) -> $R {
716 bug!("tcx.maps.{}({:?}) unsupported by its crate",
717 stringify!($name), key);
719 Providers { $($name),* }
724 // Something ready to shift:
726 ready: ($name:tt $K:tt $V:tt),
728 output: ($($output:tt)*)) => {
729 define_provider_struct! {
732 output: ($($output)* ($name $K $V))
736 // Regular queries produce a `V` only.
738 input: (([] $name:tt $K:tt $V:tt) $($input:tt)*),
739 output: $output:tt) => {
740 define_provider_struct! {
742 ready: ($name $K $V),
750 input: (([$other_modifier:tt $($modifiers:tt)*] $($fields:tt)*) $($input:tt)*),
751 output: $output:tt) => {
752 define_provider_struct! {
754 input: (([$($modifiers)*] $($fields)*) $($input)*),
760 // Each of these maps also corresponds to a method on a
761 // `Provider` trait for requesting a value of that type,
762 // and a method on `Maps` itself for doing that in a
763 // a way that memoizes and does dep-graph tracking,
764 // wrapping around the actual chain of providers that
765 // the driver creates (using several `rustc_*` crates).
766 define_maps! { <'tcx>
767 /// Records the type of every item.
768 [] type_of: ItemSignature(DefId) -> Ty<'tcx>,
770 /// Maps from the def-id of an item (trait/struct/enum/fn) to its
771 /// associated generics and predicates.
772 [] generics_of: ItemSignature(DefId) -> &'tcx ty::Generics,
773 [] predicates_of: ItemSignature(DefId) -> ty::GenericPredicates<'tcx>,
775 /// Maps from the def-id of a trait to the list of
776 /// super-predicates. This is a subset of the full list of
777 /// predicates. We store these in a separate map because we must
778 /// evaluate them even during type conversion, often before the
779 /// full predicates are available (note that supertraits have
780 /// additional acyclicity requirements).
781 [] super_predicates_of: ItemSignature(DefId) -> ty::GenericPredicates<'tcx>,
783 /// To avoid cycles within the predicates of a single item we compute
784 /// per-type-parameter predicates for resolving `T::AssocTy`.
785 [] type_param_predicates: TypeParamPredicates((DefId, DefId))
786 -> ty::GenericPredicates<'tcx>,
788 [] trait_def: ItemSignature(DefId) -> &'tcx ty::TraitDef,
789 [] adt_def: ItemSignature(DefId) -> &'tcx ty::AdtDef,
790 [] adt_destructor: AdtDestructor(DefId) -> Option<ty::Destructor>,
791 [] adt_sized_constraint: SizedConstraint(DefId) -> &'tcx [Ty<'tcx>],
792 [] adt_dtorck_constraint: DtorckConstraint(DefId) -> ty::DtorckConstraint<'tcx>,
794 /// True if this is a foreign item (i.e., linked via `extern { ... }`).
795 [] is_foreign_item: IsForeignItem(DefId) -> bool,
797 /// True if this is a default impl (aka impl Foo for ..)
798 [] is_default_impl: ItemSignature(DefId) -> bool,
800 /// Get a map with the variance of every item; use `item_variance`
802 [] crate_variances: crate_variances(CrateNum) -> Rc<ty::CrateVariancesMap>,
804 /// Maps from def-id of a type or region parameter to its
805 /// (inferred) variance.
806 [] variances_of: ItemVariances(DefId) -> Rc<Vec<ty::Variance>>,
808 /// Maps from an impl/trait def-id to a list of the def-ids of its items
809 [] associated_item_def_ids: AssociatedItemDefIds(DefId) -> Rc<Vec<DefId>>,
811 /// Maps from a trait item to the trait item "descriptor"
812 [] associated_item: AssociatedItems(DefId) -> ty::AssociatedItem,
814 [] impl_trait_ref: ItemSignature(DefId) -> Option<ty::TraitRef<'tcx>>,
815 [] impl_polarity: ItemSignature(DefId) -> hir::ImplPolarity,
817 /// Maps a DefId of a type to a list of its inherent impls.
818 /// Contains implementations of methods that are inherent to a type.
819 /// Methods in these implementations don't need to be exported.
820 [] inherent_impls: InherentImpls(DefId) -> Rc<Vec<DefId>>,
822 /// Set of all the def-ids in this crate that have MIR associated with
823 /// them. This includes all the body owners, but also things like struct
825 [] mir_keys: mir_keys(CrateNum) -> Rc<DefIdSet>,
827 /// Maps DefId's that have an associated Mir to the result
828 /// of the MIR qualify_consts pass. The actual meaning of
829 /// the value isn't known except to the pass itself.
830 [] mir_const_qualif: Mir(DefId) -> u8,
832 /// Fetch the MIR for a given def-id up till the point where it is
833 /// ready for const evaluation.
835 /// See the README for the `mir` module for details.
836 [] mir_const: Mir(DefId) -> &'tcx Steal<mir::Mir<'tcx>>,
838 [] mir_validated: Mir(DefId) -> &'tcx Steal<mir::Mir<'tcx>>,
840 /// MIR after our optimization passes have run. This is MIR that is ready
841 /// for trans. This is also the only query that can fetch non-local MIR, at present.
842 [] optimized_mir: Mir(DefId) -> &'tcx mir::Mir<'tcx>,
844 /// Records the type of each closure. The def ID is the ID of the
845 /// expression defining the closure.
846 [] closure_kind: ItemSignature(DefId) -> ty::ClosureKind,
848 /// Records the type of each closure. The def ID is the ID of the
849 /// expression defining the closure.
850 [] closure_type: ItemSignature(DefId) -> ty::PolyFnSig<'tcx>,
852 /// Caches CoerceUnsized kinds for impls on custom types.
853 [] coerce_unsized_info: ItemSignature(DefId)
854 -> ty::adjustment::CoerceUnsizedInfo,
856 [] typeck_item_bodies: typeck_item_bodies_dep_node(CrateNum) -> CompileResult,
858 [] typeck_tables_of: TypeckTables(DefId) -> &'tcx ty::TypeckTables<'tcx>,
860 [] has_typeck_tables: TypeckTables(DefId) -> bool,
862 [] coherent_trait: coherent_trait_dep_node((CrateNum, DefId)) -> (),
864 [] borrowck: BorrowCheck(DefId) -> (),
866 /// Gets a complete map from all types to their inherent impls.
867 /// Not meant to be used directly outside of coherence.
868 /// (Defined only for LOCAL_CRATE)
869 [] crate_inherent_impls: crate_inherent_impls_dep_node(CrateNum) -> CrateInherentImpls,
871 /// Checks all types in the krate for overlap in their inherent impls. Reports errors.
872 /// Not meant to be used directly outside of coherence.
873 /// (Defined only for LOCAL_CRATE)
874 [] crate_inherent_impls_overlap_check: crate_inherent_impls_dep_node(CrateNum) -> (),
876 /// Results of evaluating const items or constants embedded in
877 /// other items (such as enum variant explicit discriminants).
878 [] const_eval: const_eval_dep_node((DefId, &'tcx Substs<'tcx>))
879 -> const_val::EvalResult<'tcx>,
881 /// Performs the privacy check and computes "access levels".
882 [] privacy_access_levels: PrivacyAccessLevels(CrateNum) -> Rc<AccessLevels>,
884 [] reachable_set: reachability_dep_node(CrateNum) -> Rc<NodeSet>,
886 /// Per-function `RegionMaps`. The `DefId` should be the owner-def-id for the fn body;
887 /// in the case of closures or "inline" expressions, this will be redirected to the enclosing
889 [] region_maps: RegionMaps(DefId) -> Rc<RegionMaps>,
891 [] mir_shims: mir_shim_dep_node(ty::InstanceDef<'tcx>) -> &'tcx mir::Mir<'tcx>,
893 [] def_symbol_name: SymbolName(DefId) -> ty::SymbolName,
894 [] symbol_name: symbol_name_dep_node(ty::Instance<'tcx>) -> ty::SymbolName,
896 [] describe_def: DescribeDef(DefId) -> Option<Def>,
897 [] def_span: DefSpan(DefId) -> Span,
898 [] stability: Stability(DefId) -> Option<attr::Stability>,
899 [] deprecation: Deprecation(DefId) -> Option<attr::Deprecation>,
900 [] item_attrs: ItemAttrs(DefId) -> Rc<[ast::Attribute]>,
901 [] fn_arg_names: FnArgNames(DefId) -> Vec<ast::Name>,
902 [] impl_parent: ImplParent(DefId) -> Option<DefId>,
903 [] trait_of_item: TraitOfItem(DefId) -> Option<DefId>,
904 [] is_exported_symbol: IsExportedSymbol(DefId) -> bool,
905 [] item_body_nested_bodies: ItemBodyNestedBodies(DefId) -> Rc<BTreeMap<hir::BodyId, hir::Body>>,
906 [] const_is_rvalue_promotable_to_static: ConstIsRvaluePromotableToStatic(DefId) -> bool,
907 [] is_mir_available: IsMirAvailable(DefId) -> bool,
909 [] trait_impls_of: TraitImpls(DefId) -> ty::trait_def::TraitImpls,
910 // Note that TraitDef::for_each_relevant_impl() will do type simplication for you.
911 [] relevant_trait_impls_for: relevant_trait_impls_for((DefId, SimplifiedType))
912 -> ty::trait_def::TraitImpls,
913 [] specialization_graph_of: SpecializationGraph(DefId) -> Rc<specialization_graph::Graph>,
914 [] is_object_safe: ObjectSafety(DefId) -> bool,
916 // Get the ParameterEnvironment for a given item; this environment
917 // will be in "user-facing" mode, meaning that it is suitabe for
918 // type-checking etc, and it does not normalize specializable
919 // associated types. This is almost always what you want,
920 // unless you are doing MIR optimizations, in which case you
921 // might want to use `reveal_all()` method to change modes.
922 [] param_env: ParamEnv(DefId) -> ty::ParamEnv<'tcx>,
924 // Trait selection queries. These are best used by invoking `ty.moves_by_default()`,
925 // `ty.is_copy()`, etc, since that will prune the environment where possible.
926 [] is_copy_raw: is_copy_dep_node(ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool,
927 [] is_sized_raw: is_sized_dep_node(ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool,
928 [] is_freeze_raw: is_freeze_dep_node(ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool,
929 [] needs_drop_raw: needs_drop_dep_node(ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool,
930 [] layout_raw: layout_dep_node(ty::ParamEnvAnd<'tcx, Ty<'tcx>>)
931 -> Result<&'tcx Layout, LayoutError<'tcx>>,
934 fn coherent_trait_dep_node((_, def_id): (CrateNum, DefId)) -> DepNode<DefId> {
935 DepNode::CoherenceCheckTrait(def_id)
938 fn crate_inherent_impls_dep_node(_: CrateNum) -> DepNode<DefId> {
942 fn reachability_dep_node(_: CrateNum) -> DepNode<DefId> {
943 DepNode::Reachability
946 fn mir_shim_dep_node(instance: ty::InstanceDef) -> DepNode<DefId> {
950 fn symbol_name_dep_node(instance: ty::Instance) -> DepNode<DefId> {
951 // symbol_name uses the substs only to traverse them to find the
952 // hash, and that does not create any new dep-nodes.
953 DepNode::SymbolName(instance.def.def_id())
956 fn typeck_item_bodies_dep_node(_: CrateNum) -> DepNode<DefId> {
957 DepNode::TypeckBodiesKrate
960 fn const_eval_dep_node((def_id, _): (DefId, &Substs)) -> DepNode<DefId> {
961 DepNode::ConstEval(def_id)
964 fn mir_keys(_: CrateNum) -> DepNode<DefId> {
968 fn crate_variances(_: CrateNum) -> DepNode<DefId> {
969 DepNode::CrateVariances
972 fn relevant_trait_impls_for((def_id, _): (DefId, SimplifiedType)) -> DepNode<DefId> {
973 DepNode::TraitImpls(def_id)
976 fn is_copy_dep_node<'tcx>(key: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> DepNode<DefId> {
977 let def_id = ty::item_path::characteristic_def_id_of_type(key.value)
978 .unwrap_or(DefId::local(CRATE_DEF_INDEX));
979 DepNode::IsCopy(def_id)
982 fn is_sized_dep_node<'tcx>(key: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> DepNode<DefId> {
983 let def_id = ty::item_path::characteristic_def_id_of_type(key.value)
984 .unwrap_or(DefId::local(CRATE_DEF_INDEX));
985 DepNode::IsSized(def_id)
988 fn is_freeze_dep_node<'tcx>(key: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> DepNode<DefId> {
989 let def_id = ty::item_path::characteristic_def_id_of_type(key.value)
990 .unwrap_or(DefId::local(CRATE_DEF_INDEX));
991 DepNode::IsFreeze(def_id)
994 fn needs_drop_dep_node<'tcx>(key: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> DepNode<DefId> {
995 let def_id = ty::item_path::characteristic_def_id_of_type(key.value)
996 .unwrap_or(DefId::local(CRATE_DEF_INDEX));
997 DepNode::NeedsDrop(def_id)
1000 fn layout_dep_node<'tcx>(key: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> DepNode<DefId> {
1001 let def_id = ty::item_path::characteristic_def_id_of_type(key.value)
1002 .unwrap_or(DefId::local(CRATE_DEF_INDEX));
1003 DepNode::Layout(def_id)