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, DepTrackingMapConfig};
12 use hir::def_id::{CrateNum, CRATE_DEF_INDEX, DefId, LOCAL_CRATE};
15 use middle::const_val;
16 use middle::cstore::{ExternCrate, LinkagePreference};
17 use middle::privacy::AccessLevels;
18 use middle::region::RegionMaps;
20 use mir::transform::{MirSuite, MirPassIndex};
21 use session::CompileResult;
22 use traits::specialization_graph;
23 use ty::{self, CrateInherentImpls, Ty, TyCtxt};
24 use ty::layout::{Layout, LayoutError};
27 use ty::subst::Substs;
28 use ty::fast_reject::SimplifiedType;
29 use util::nodemap::{DefIdSet, NodeSet};
31 use rustc_data_structures::indexed_vec::IndexVec;
32 use rustc_data_structures::fx::FxHashMap;
33 use std::cell::{RefCell, RefMut};
36 use std::marker::PhantomData;
38 use std::collections::BTreeMap;
41 use syntax_pos::{Span, DUMMY_SP};
44 use syntax::symbol::Symbol;
46 pub trait Key: Clone + Hash + Eq + Debug {
47 fn map_crate(&self) -> CrateNum;
48 fn default_span(&self, tcx: TyCtxt) -> Span;
51 impl<'tcx> Key for ty::InstanceDef<'tcx> {
52 fn map_crate(&self) -> CrateNum {
56 fn default_span(&self, tcx: TyCtxt) -> Span {
57 tcx.def_span(self.def_id())
61 impl<'tcx> Key for ty::Instance<'tcx> {
62 fn map_crate(&self) -> CrateNum {
66 fn default_span(&self, tcx: TyCtxt) -> Span {
67 tcx.def_span(self.def_id())
71 impl Key for CrateNum {
72 fn map_crate(&self) -> CrateNum {
75 fn default_span(&self, _: TyCtxt) -> Span {
81 fn map_crate(&self) -> CrateNum {
84 fn default_span(&self, tcx: TyCtxt) -> Span {
89 impl Key for (DefId, DefId) {
90 fn map_crate(&self) -> CrateNum {
93 fn default_span(&self, tcx: TyCtxt) -> Span {
94 self.1.default_span(tcx)
98 impl Key for (CrateNum, DefId) {
99 fn map_crate(&self) -> CrateNum {
102 fn default_span(&self, tcx: TyCtxt) -> Span {
103 self.1.default_span(tcx)
107 impl Key for (DefId, SimplifiedType) {
108 fn map_crate(&self) -> CrateNum {
111 fn default_span(&self, tcx: TyCtxt) -> Span {
112 self.0.default_span(tcx)
116 impl<'tcx> Key for (DefId, &'tcx Substs<'tcx>) {
117 fn map_crate(&self) -> CrateNum {
120 fn default_span(&self, tcx: TyCtxt) -> Span {
121 self.0.default_span(tcx)
125 impl Key for (MirSuite, DefId) {
126 fn map_crate(&self) -> CrateNum {
129 fn default_span(&self, tcx: TyCtxt) -> Span {
130 self.1.default_span(tcx)
134 impl Key for (MirSuite, MirPassIndex, DefId) {
135 fn map_crate(&self) -> CrateNum {
138 fn default_span(&self, tcx: TyCtxt) -> Span {
139 self.2.default_span(tcx)
143 impl<'tcx, T: Clone + Hash + Eq + Debug> Key for ty::ParamEnvAnd<'tcx, T> {
144 fn map_crate(&self) -> CrateNum {
147 fn default_span(&self, _: TyCtxt) -> Span {
152 trait Value<'tcx>: Sized {
153 fn from_cycle_error<'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> Self;
156 impl<'tcx, T> Value<'tcx> for T {
157 default fn from_cycle_error<'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> T {
158 tcx.sess.abort_if_errors();
159 bug!("Value::from_cycle_error called without errors");
163 impl<'tcx, T: Default> Value<'tcx> for T {
164 default fn from_cycle_error<'a>(_: TyCtxt<'a, 'tcx, 'tcx>) -> T {
169 impl<'tcx> Value<'tcx> for Ty<'tcx> {
170 fn from_cycle_error<'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> Ty<'tcx> {
175 impl<'tcx> Value<'tcx> for ty::DtorckConstraint<'tcx> {
176 fn from_cycle_error<'a>(_: TyCtxt<'a, 'tcx, 'tcx>) -> Self {
181 impl<'tcx> Value<'tcx> for ty::SymbolName {
182 fn from_cycle_error<'a>(_: TyCtxt<'a, 'tcx, 'tcx>) -> Self {
183 ty::SymbolName { name: Symbol::intern("<error>").as_str() }
187 struct QueryMap<D: QueryDescription> {
188 phantom: PhantomData<D>,
189 map: FxHashMap<D::Key, D::Value>,
192 impl<M: QueryDescription> QueryMap<M> {
193 fn new() -> QueryMap<M> {
195 phantom: PhantomData,
201 pub struct CycleError<'a, 'tcx: 'a> {
203 cycle: RefMut<'a, [(Span, Query<'tcx>)]>,
206 impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
207 pub fn report_cycle(self, CycleError { span, cycle }: CycleError) {
208 // Subtle: release the refcell lock before invoking `describe()`
209 // below by dropping `cycle`.
210 let stack = cycle.to_vec();
213 assert!(!stack.is_empty());
215 // Disable naming impls with types in this path, since that
216 // sometimes cycles itself, leading to extra cycle errors.
217 // (And cycle errors around impls tend to occur during the
218 // collect/coherence phases anyhow.)
219 item_path::with_forced_impl_filename_line(|| {
221 struct_span_err!(self.sess, span, E0391,
222 "unsupported cyclic reference between types/traits detected");
223 err.span_label(span, "cyclic reference");
225 err.span_note(stack[0].0, &format!("the cycle begins when {}...",
226 stack[0].1.describe(self)));
228 for &(span, ref query) in &stack[1..] {
229 err.span_note(span, &format!("...which then requires {}...",
230 query.describe(self)));
233 err.note(&format!("...which then again requires {}, completing the cycle.",
234 stack[0].1.describe(self)));
240 fn cycle_check<F, R>(self, span: Span, query: Query<'gcx>, compute: F)
241 -> Result<R, CycleError<'a, 'gcx>>
242 where F: FnOnce() -> R
245 let mut stack = self.maps.query_stack.borrow_mut();
246 if let Some((i, _)) = stack.iter().enumerate().rev()
247 .find(|&(_, &(_, ref q))| *q == query) {
248 return Err(CycleError {
250 cycle: RefMut::map(stack, |stack| &mut stack[i..])
253 stack.push((span, query));
256 let result = compute();
258 self.maps.query_stack.borrow_mut().pop();
264 trait QueryDescription: DepTrackingMapConfig {
265 fn describe(tcx: TyCtxt, key: Self::Key) -> String;
268 impl<M: DepTrackingMapConfig<Key=DefId>> QueryDescription for M {
269 default fn describe(tcx: TyCtxt, def_id: DefId) -> String {
270 format!("processing `{}`", tcx.item_path_str(def_id))
274 impl<'tcx> QueryDescription for queries::is_copy_raw<'tcx> {
275 fn describe(_tcx: TyCtxt, env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> String {
276 format!("computing whether `{}` is `Copy`", env.value)
280 impl<'tcx> QueryDescription for queries::is_sized_raw<'tcx> {
281 fn describe(_tcx: TyCtxt, env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> String {
282 format!("computing whether `{}` is `Sized`", env.value)
286 impl<'tcx> QueryDescription for queries::is_freeze_raw<'tcx> {
287 fn describe(_tcx: TyCtxt, env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> String {
288 format!("computing whether `{}` is freeze", env.value)
292 impl<'tcx> QueryDescription for queries::needs_drop_raw<'tcx> {
293 fn describe(_tcx: TyCtxt, env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> String {
294 format!("computing whether `{}` needs drop", env.value)
298 impl<'tcx> QueryDescription for queries::layout_raw<'tcx> {
299 fn describe(_tcx: TyCtxt, env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> String {
300 format!("computing layout of `{}`", env.value)
304 impl<'tcx> QueryDescription for queries::super_predicates_of<'tcx> {
305 fn describe(tcx: TyCtxt, def_id: DefId) -> String {
306 format!("computing the supertraits of `{}`",
307 tcx.item_path_str(def_id))
311 impl<'tcx> QueryDescription for queries::type_param_predicates<'tcx> {
312 fn describe(tcx: TyCtxt, (_, def_id): (DefId, DefId)) -> String {
313 let id = tcx.hir.as_local_node_id(def_id).unwrap();
314 format!("computing the bounds for type parameter `{}`",
315 tcx.hir.ty_param_name(id))
319 impl<'tcx> QueryDescription for queries::coherent_trait<'tcx> {
320 fn describe(tcx: TyCtxt, (_, def_id): (CrateNum, DefId)) -> String {
321 format!("coherence checking all impls of trait `{}`",
322 tcx.item_path_str(def_id))
326 impl<'tcx> QueryDescription for queries::crate_inherent_impls<'tcx> {
327 fn describe(_: TyCtxt, k: CrateNum) -> String {
328 format!("all inherent impls defined in crate `{:?}`", k)
332 impl<'tcx> QueryDescription for queries::crate_inherent_impls_overlap_check<'tcx> {
333 fn describe(_: TyCtxt, _: CrateNum) -> String {
334 format!("check for overlap between inherent impls defined in this crate")
338 impl<'tcx> QueryDescription for queries::crate_variances<'tcx> {
339 fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
340 format!("computing the variances for items in this crate")
344 impl<'tcx> QueryDescription for queries::mir_shims<'tcx> {
345 fn describe(tcx: TyCtxt, def: ty::InstanceDef<'tcx>) -> String {
346 format!("generating MIR shim for `{}`",
347 tcx.item_path_str(def.def_id()))
351 impl<'tcx> QueryDescription for queries::privacy_access_levels<'tcx> {
352 fn describe(_: TyCtxt, _: CrateNum) -> String {
353 format!("privacy access levels")
357 impl<'tcx> QueryDescription for queries::typeck_item_bodies<'tcx> {
358 fn describe(_: TyCtxt, _: CrateNum) -> String {
359 format!("type-checking all item bodies")
363 impl<'tcx> QueryDescription for queries::reachable_set<'tcx> {
364 fn describe(_: TyCtxt, _: CrateNum) -> String {
365 format!("reachability")
369 impl<'tcx> QueryDescription for queries::const_eval<'tcx> {
370 fn describe(tcx: TyCtxt, (def_id, _): (DefId, &'tcx Substs<'tcx>)) -> String {
371 format!("const-evaluating `{}`", tcx.item_path_str(def_id))
375 impl<'tcx> QueryDescription for queries::mir_keys<'tcx> {
376 fn describe(_: TyCtxt, _: CrateNum) -> String {
377 format!("getting a list of all mir_keys")
381 impl<'tcx> QueryDescription for queries::symbol_name<'tcx> {
382 fn describe(_tcx: TyCtxt, instance: ty::Instance<'tcx>) -> String {
383 format!("computing the symbol for `{}`", instance)
387 impl<'tcx> QueryDescription for queries::describe_def<'tcx> {
388 fn describe(_: TyCtxt, _: DefId) -> String {
393 impl<'tcx> QueryDescription for queries::def_span<'tcx> {
394 fn describe(_: TyCtxt, _: DefId) -> String {
400 impl<'tcx> QueryDescription for queries::stability<'tcx> {
401 fn describe(_: TyCtxt, _: DefId) -> String {
406 impl<'tcx> QueryDescription for queries::deprecation<'tcx> {
407 fn describe(_: TyCtxt, _: DefId) -> String {
412 impl<'tcx> QueryDescription for queries::item_attrs<'tcx> {
413 fn describe(_: TyCtxt, _: DefId) -> String {
418 impl<'tcx> QueryDescription for queries::is_exported_symbol<'tcx> {
419 fn describe(_: TyCtxt, _: DefId) -> String {
420 bug!("is_exported_symbol")
424 impl<'tcx> QueryDescription for queries::fn_arg_names<'tcx> {
425 fn describe(_: TyCtxt, _: DefId) -> String {
430 impl<'tcx> QueryDescription for queries::impl_parent<'tcx> {
431 fn describe(_: TyCtxt, _: DefId) -> String {
436 impl<'tcx> QueryDescription for queries::trait_of_item<'tcx> {
437 fn describe(_: TyCtxt, _: DefId) -> String {
438 bug!("trait_of_item")
442 impl<'tcx> QueryDescription for queries::item_body_nested_bodies<'tcx> {
443 fn describe(tcx: TyCtxt, def_id: DefId) -> String {
444 format!("nested item bodies of `{}`", tcx.item_path_str(def_id))
448 impl<'tcx> QueryDescription for queries::const_is_rvalue_promotable_to_static<'tcx> {
449 fn describe(tcx: TyCtxt, def_id: DefId) -> String {
450 format!("const checking if rvalue is promotable to static `{}`",
451 tcx.item_path_str(def_id))
455 impl<'tcx> QueryDescription for queries::is_mir_available<'tcx> {
456 fn describe(tcx: TyCtxt, def_id: DefId) -> String {
457 format!("checking if item is mir available: `{}`",
458 tcx.item_path_str(def_id))
462 impl<'tcx> QueryDescription for queries::trait_impls_of<'tcx> {
463 fn describe(tcx: TyCtxt, def_id: DefId) -> String {
464 format!("trait impls of `{}`", tcx.item_path_str(def_id))
468 impl<'tcx> QueryDescription for queries::relevant_trait_impls_for<'tcx> {
469 fn describe(tcx: TyCtxt, (def_id, ty): (DefId, SimplifiedType)) -> String {
470 format!("relevant impls for: `({}, {:?})`", tcx.item_path_str(def_id), ty)
474 impl<'tcx> QueryDescription for queries::is_object_safe<'tcx> {
475 fn describe(tcx: TyCtxt, def_id: DefId) -> String {
476 format!("determine object safety of trait `{}`", tcx.item_path_str(def_id))
480 impl<'tcx> QueryDescription for queries::is_const_fn<'tcx> {
481 fn describe(tcx: TyCtxt, def_id: DefId) -> String {
482 format!("checking if item is const fn: `{}`", tcx.item_path_str(def_id))
486 impl<'tcx> QueryDescription for queries::dylib_dependency_formats<'tcx> {
487 fn describe(_: TyCtxt, _: DefId) -> String {
488 "dylib dependency formats of crate".to_string()
492 impl<'tcx> QueryDescription for queries::is_allocator<'tcx> {
493 fn describe(_: TyCtxt, _: DefId) -> String {
494 "checking if the crate is_allocator".to_string()
498 impl<'tcx> QueryDescription for queries::is_panic_runtime<'tcx> {
499 fn describe(_: TyCtxt, _: DefId) -> String {
500 "checking if the crate is_panic_runtime".to_string()
504 impl<'tcx> QueryDescription for queries::extern_crate<'tcx> {
505 fn describe(_: TyCtxt, _: DefId) -> String {
506 "getting crate's ExternCrateData".to_string()
510 macro_rules! define_maps {
513 [$($modifiers:tt)*] $name:ident: $node:ident($K:ty) -> $V:ty,)*) => {
516 input: ($(([$($modifiers)*] [$($attr)*] [$name]))*)
519 impl<$tcx> Maps<$tcx> {
520 pub fn new(providers: IndexVec<CrateNum, Providers<$tcx>>)
524 query_stack: RefCell::new(vec![]),
525 $($name: RefCell::new(QueryMap::new())),*
531 #[derive(Copy, Clone, Debug, PartialEq, Eq)]
532 pub enum Query<$tcx> {
533 $($(#[$attr])* $name($K)),*
536 impl<$tcx> Query<$tcx> {
537 pub fn describe(&self, tcx: TyCtxt) -> String {
539 $(Query::$name(key) => queries::$name::describe(tcx, key)),*
545 use std::marker::PhantomData;
547 $(#[allow(bad_style)]
548 pub struct $name<$tcx> {
549 data: PhantomData<&$tcx ()>
553 $(impl<$tcx> DepTrackingMapConfig for queries::$name<$tcx> {
558 fn to_dep_node(tcx: TyCtxt, key: &$K) -> DepNode {
559 use dep_graph::DepConstructor::*;
561 DepNode::new(tcx, $node(*key))
564 impl<'a, $tcx, 'lcx> queries::$name<$tcx> {
565 fn try_get_with<F, R>(tcx: TyCtxt<'a, $tcx, 'lcx>,
569 -> Result<R, CycleError<'a, $tcx>>
570 where F: FnOnce(&$V) -> R
572 debug!("ty::queries::{}::try_get_with(key={:?}, span={:?})",
577 if let Some(result) = tcx.maps.$name.borrow().map.get(&key) {
578 return Ok(f(result));
581 // FIXME(eddyb) Get more valid Span's on queries.
582 // def_span guard is necesary to prevent a recursive loop,
583 // default_span calls def_span query internally.
584 if span == DUMMY_SP && stringify!($name) != "def_span" {
585 span = key.default_span(tcx)
588 let _task = tcx.dep_graph.in_task(Self::to_dep_node(tcx, &key));
590 let result = tcx.cycle_check(span, Query::$name(key), || {
591 let provider = tcx.maps.providers[key.map_crate()].$name;
592 provider(tcx.global_tcx(), key)
595 Ok(f(tcx.maps.$name.borrow_mut().map.entry(key).or_insert(result)))
598 pub fn try_get(tcx: TyCtxt<'a, $tcx, 'lcx>, span: Span, key: $K)
599 -> Result<$V, CycleError<'a, $tcx>> {
600 // We register the `read` here, but not in `force`, since
601 // `force` does not give access to the value produced (and thus
602 // we actually don't read it).
603 tcx.dep_graph.read(Self::to_dep_node(tcx, &key));
604 Self::try_get_with(tcx, span, key, Clone::clone)
607 pub fn force(tcx: TyCtxt<'a, $tcx, 'lcx>, span: Span, key: $K) {
608 match Self::try_get_with(tcx, span, key, |_| ()) {
610 Err(e) => tcx.report_cycle(e)
615 #[derive(Copy, Clone)]
616 pub struct TyCtxtAt<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
617 pub tcx: TyCtxt<'a, 'gcx, 'tcx>,
621 impl<'a, 'gcx, 'tcx> Deref for TyCtxtAt<'a, 'gcx, 'tcx> {
622 type Target = TyCtxt<'a, 'gcx, 'tcx>;
623 fn deref(&self) -> &Self::Target {
628 impl<'a, $tcx, 'lcx> TyCtxt<'a, $tcx, 'lcx> {
629 /// Return a transparent wrapper for `TyCtxt` which uses
630 /// `span` as the location of queries performed through it.
631 pub fn at(self, span: Span) -> TyCtxtAt<'a, $tcx, 'lcx> {
639 pub fn $name(self, key: $K) -> $V {
640 self.at(DUMMY_SP).$name(key)
644 impl<'a, $tcx, 'lcx> TyCtxtAt<'a, $tcx, 'lcx> {
646 pub fn $name(self, key: $K) -> $V {
647 queries::$name::try_get(self.tcx, self.span, key).unwrap_or_else(|e| {
648 self.report_cycle(e);
649 Value::from_cycle_error(self.global_tcx())
654 define_provider_struct! {
656 input: ($(([$($modifiers)*] [$name] [$K] [$V]))*),
660 impl<$tcx> Copy for Providers<$tcx> {}
661 impl<$tcx> Clone for Providers<$tcx> {
662 fn clone(&self) -> Self { *self }
667 macro_rules! define_map_struct {
670 input: $input:tt) => {
681 output: ($($output:tt)*)) => {
682 pub struct Maps<$tcx> {
683 providers: IndexVec<CrateNum, Providers<$tcx>>,
684 query_stack: RefCell<Vec<(Span, Query<$tcx>)>>,
689 // Field recognized and ready to shift into the output
691 ready: ([$($pub:tt)*] [$($attr:tt)*] [$name:ident]),
693 output: ($($output:tt)*)) => {
698 $(#[$attr])* $($pub)* $name: RefCell<QueryMap<queries::$name<$tcx>>>,)
702 // No modifiers left? This is a private item.
704 input: (([] $attrs:tt $name:tt) $($input:tt)*),
705 output: $output:tt) => {
708 ready: ([] $attrs $name),
714 // Skip other modifiers
716 input: (([$other_modifier:tt $($modifiers:tt)*] $($fields:tt)*) $($input:tt)*),
717 output: $output:tt) => {
720 input: (([$($modifiers)*] $($fields)*) $($input)*),
726 macro_rules! define_provider_struct {
728 (tcx: $tcx:tt, input: $input:tt) => {
729 define_provider_struct! {
739 output: ($(([$name:ident] [$K:ty] [$R:ty]))*)) => {
740 pub struct Providers<$tcx> {
741 $(pub $name: for<'a> fn(TyCtxt<'a, $tcx, $tcx>, $K) -> $R,)*
744 impl<$tcx> Default for Providers<$tcx> {
745 fn default() -> Self {
746 $(fn $name<'a, $tcx>(_: TyCtxt<'a, $tcx, $tcx>, key: $K) -> $R {
747 bug!("tcx.maps.{}({:?}) unsupported by its crate",
748 stringify!($name), key);
750 Providers { $($name),* }
755 // Something ready to shift:
757 ready: ($name:tt $K:tt $V:tt),
759 output: ($($output:tt)*)) => {
760 define_provider_struct! {
763 output: ($($output)* ($name $K $V))
767 // Regular queries produce a `V` only.
769 input: (([] $name:tt $K:tt $V:tt) $($input:tt)*),
770 output: $output:tt) => {
771 define_provider_struct! {
773 ready: ($name $K $V),
781 input: (([$other_modifier:tt $($modifiers:tt)*] $($fields:tt)*) $($input:tt)*),
782 output: $output:tt) => {
783 define_provider_struct! {
785 input: (([$($modifiers)*] $($fields)*) $($input)*),
791 // Each of these maps also corresponds to a method on a
792 // `Provider` trait for requesting a value of that type,
793 // and a method on `Maps` itself for doing that in a
794 // a way that memoizes and does dep-graph tracking,
795 // wrapping around the actual chain of providers that
796 // the driver creates (using several `rustc_*` crates).
797 define_maps! { <'tcx>
798 /// Records the type of every item.
799 [] type_of: ItemSignature(DefId) -> Ty<'tcx>,
801 /// Maps from the def-id of an item (trait/struct/enum/fn) to its
802 /// associated generics and predicates.
803 [] generics_of: ItemSignature(DefId) -> &'tcx ty::Generics,
804 [] predicates_of: ItemSignature(DefId) -> ty::GenericPredicates<'tcx>,
806 /// Maps from the def-id of a trait to the list of
807 /// super-predicates. This is a subset of the full list of
808 /// predicates. We store these in a separate map because we must
809 /// evaluate them even during type conversion, often before the
810 /// full predicates are available (note that supertraits have
811 /// additional acyclicity requirements).
812 [] super_predicates_of: ItemSignature(DefId) -> ty::GenericPredicates<'tcx>,
814 /// To avoid cycles within the predicates of a single item we compute
815 /// per-type-parameter predicates for resolving `T::AssocTy`.
816 [] type_param_predicates: type_param_predicates((DefId, DefId))
817 -> ty::GenericPredicates<'tcx>,
819 [] trait_def: ItemSignature(DefId) -> &'tcx ty::TraitDef,
820 [] adt_def: ItemSignature(DefId) -> &'tcx ty::AdtDef,
821 [] adt_destructor: AdtDestructor(DefId) -> Option<ty::Destructor>,
822 [] adt_sized_constraint: SizedConstraint(DefId) -> &'tcx [Ty<'tcx>],
823 [] adt_dtorck_constraint: DtorckConstraint(DefId) -> ty::DtorckConstraint<'tcx>,
825 /// True if this is a const fn
826 [] is_const_fn: IsConstFn(DefId) -> bool,
828 /// True if this is a foreign item (i.e., linked via `extern { ... }`).
829 [] is_foreign_item: IsForeignItem(DefId) -> bool,
831 /// True if this is a default impl (aka impl Foo for ..)
832 [] is_default_impl: ItemSignature(DefId) -> bool,
834 /// Get a map with the variance of every item; use `item_variance`
836 [] crate_variances: crate_variances(CrateNum) -> Rc<ty::CrateVariancesMap>,
838 /// Maps from def-id of a type or region parameter to its
839 /// (inferred) variance.
840 [] variances_of: ItemVariances(DefId) -> Rc<Vec<ty::Variance>>,
842 /// Maps from an impl/trait def-id to a list of the def-ids of its items
843 [] associated_item_def_ids: AssociatedItemDefIds(DefId) -> Rc<Vec<DefId>>,
845 /// Maps from a trait item to the trait item "descriptor"
846 [] associated_item: AssociatedItems(DefId) -> ty::AssociatedItem,
848 [] impl_trait_ref: ItemSignature(DefId) -> Option<ty::TraitRef<'tcx>>,
849 [] impl_polarity: ItemSignature(DefId) -> hir::ImplPolarity,
851 /// Maps a DefId of a type to a list of its inherent impls.
852 /// Contains implementations of methods that are inherent to a type.
853 /// Methods in these implementations don't need to be exported.
854 [] inherent_impls: InherentImpls(DefId) -> Rc<Vec<DefId>>,
856 /// Set of all the def-ids in this crate that have MIR associated with
857 /// them. This includes all the body owners, but also things like struct
859 [] mir_keys: mir_keys(CrateNum) -> Rc<DefIdSet>,
861 /// Maps DefId's that have an associated Mir to the result
862 /// of the MIR qualify_consts pass. The actual meaning of
863 /// the value isn't known except to the pass itself.
864 [] mir_const_qualif: Mir(DefId) -> u8,
866 /// Fetch the MIR for a given def-id up till the point where it is
867 /// ready for const evaluation.
869 /// See the README for the `mir` module for details.
870 [] mir_const: Mir(DefId) -> &'tcx Steal<mir::Mir<'tcx>>,
872 [] mir_validated: Mir(DefId) -> &'tcx Steal<mir::Mir<'tcx>>,
874 /// MIR after our optimization passes have run. This is MIR that is ready
875 /// for trans. This is also the only query that can fetch non-local MIR, at present.
876 [] optimized_mir: Mir(DefId) -> &'tcx mir::Mir<'tcx>,
878 /// Type of each closure. The def ID is the ID of the
879 /// expression defining the closure.
880 [] closure_kind: ItemSignature(DefId) -> ty::ClosureKind,
882 /// The signature of functions and closures.
883 [] fn_sig: ItemSignature(DefId) -> ty::PolyFnSig<'tcx>,
885 /// Caches CoerceUnsized kinds for impls on custom types.
886 [] coerce_unsized_info: ItemSignature(DefId)
887 -> ty::adjustment::CoerceUnsizedInfo,
889 [] typeck_item_bodies: typeck_item_bodies_dep_node(CrateNum) -> CompileResult,
891 [] typeck_tables_of: TypeckTables(DefId) -> &'tcx ty::TypeckTables<'tcx>,
893 [] has_typeck_tables: TypeckTables(DefId) -> bool,
895 [] coherent_trait: coherent_trait_dep_node((CrateNum, DefId)) -> (),
897 [] borrowck: BorrowCheck(DefId) -> (),
899 /// Gets a complete map from all types to their inherent impls.
900 /// Not meant to be used directly outside of coherence.
901 /// (Defined only for LOCAL_CRATE)
902 [] crate_inherent_impls: crate_inherent_impls_dep_node(CrateNum) -> CrateInherentImpls,
904 /// Checks all types in the krate for overlap in their inherent impls. Reports errors.
905 /// Not meant to be used directly outside of coherence.
906 /// (Defined only for LOCAL_CRATE)
907 [] crate_inherent_impls_overlap_check: crate_inherent_impls_dep_node(CrateNum) -> (),
909 /// Results of evaluating const items or constants embedded in
910 /// other items (such as enum variant explicit discriminants).
911 [] const_eval: const_eval_dep_node((DefId, &'tcx Substs<'tcx>))
912 -> const_val::EvalResult<'tcx>,
914 /// Performs the privacy check and computes "access levels".
915 [] privacy_access_levels: PrivacyAccessLevels(CrateNum) -> Rc<AccessLevels>,
917 [] reachable_set: reachability_dep_node(CrateNum) -> Rc<NodeSet>,
919 /// Per-function `RegionMaps`. The `DefId` should be the owner-def-id for the fn body;
920 /// in the case of closures or "inline" expressions, this will be redirected to the enclosing
922 [] region_maps: RegionMaps(DefId) -> Rc<RegionMaps>,
924 [] mir_shims: mir_shim_dep_node(ty::InstanceDef<'tcx>) -> &'tcx mir::Mir<'tcx>,
926 [] def_symbol_name: SymbolName(DefId) -> ty::SymbolName,
927 [] symbol_name: symbol_name_dep_node(ty::Instance<'tcx>) -> ty::SymbolName,
929 [] describe_def: DescribeDef(DefId) -> Option<Def>,
930 [] def_span: DefSpan(DefId) -> Span,
931 [] stability: Stability(DefId) -> Option<attr::Stability>,
932 [] deprecation: Deprecation(DefId) -> Option<attr::Deprecation>,
933 [] item_attrs: ItemAttrs(DefId) -> Rc<[ast::Attribute]>,
934 [] fn_arg_names: FnArgNames(DefId) -> Vec<ast::Name>,
935 [] impl_parent: ImplParent(DefId) -> Option<DefId>,
936 [] trait_of_item: TraitOfItem(DefId) -> Option<DefId>,
937 [] is_exported_symbol: IsExportedSymbol(DefId) -> bool,
938 [] item_body_nested_bodies: ItemBodyNestedBodies(DefId) -> Rc<BTreeMap<hir::BodyId, hir::Body>>,
939 [] const_is_rvalue_promotable_to_static: ConstIsRvaluePromotableToStatic(DefId) -> bool,
940 [] is_mir_available: IsMirAvailable(DefId) -> bool,
942 [] trait_impls_of: TraitImpls(DefId) -> ty::trait_def::TraitImpls,
943 // Note that TraitDef::for_each_relevant_impl() will do type simplication for you.
944 [] relevant_trait_impls_for: relevant_trait_impls_for((DefId, SimplifiedType))
945 -> ty::trait_def::TraitImpls,
946 [] specialization_graph_of: SpecializationGraph(DefId) -> Rc<specialization_graph::Graph>,
947 [] is_object_safe: ObjectSafety(DefId) -> bool,
949 // Get the ParameterEnvironment for a given item; this environment
950 // will be in "user-facing" mode, meaning that it is suitabe for
951 // type-checking etc, and it does not normalize specializable
952 // associated types. This is almost always what you want,
953 // unless you are doing MIR optimizations, in which case you
954 // might want to use `reveal_all()` method to change modes.
955 [] param_env: ParamEnv(DefId) -> ty::ParamEnv<'tcx>,
957 // Trait selection queries. These are best used by invoking `ty.moves_by_default()`,
958 // `ty.is_copy()`, etc, since that will prune the environment where possible.
959 [] is_copy_raw: is_copy_dep_node(ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool,
960 [] is_sized_raw: is_sized_dep_node(ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool,
961 [] is_freeze_raw: is_freeze_dep_node(ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool,
962 [] needs_drop_raw: needs_drop_dep_node(ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool,
963 [] layout_raw: layout_dep_node(ty::ParamEnvAnd<'tcx, Ty<'tcx>>)
964 -> Result<&'tcx Layout, LayoutError<'tcx>>,
966 [] dylib_dependency_formats: DylibDepFormats(DefId)
967 -> Rc<Vec<(CrateNum, LinkagePreference)>>,
969 [] is_allocator: IsAllocator(DefId) -> bool,
970 [] is_panic_runtime: IsPanicRuntime(DefId) -> bool,
972 [] extern_crate: ExternCrate(DefId) -> Rc<Option<ExternCrate>>,
975 fn type_param_predicates((item_id, param_id): (DefId, DefId)) -> DepConstructor {
976 DepConstructor::TypeParamPredicates {
982 fn coherent_trait_dep_node((_, def_id): (CrateNum, DefId)) -> DepConstructor {
983 DepConstructor::CoherenceCheckTrait(def_id)
986 fn crate_inherent_impls_dep_node(_: CrateNum) -> DepConstructor {
987 DepConstructor::Coherence
990 fn reachability_dep_node(_: CrateNum) -> DepConstructor {
991 DepConstructor::Reachability
994 fn mir_shim_dep_node(instance: ty::InstanceDef) -> DepConstructor {
998 fn symbol_name_dep_node(instance: ty::Instance) -> DepConstructor {
999 // symbol_name uses the substs only to traverse them to find the
1000 // hash, and that does not create any new dep-nodes.
1001 DepConstructor::SymbolName(instance.def.def_id())
1004 fn typeck_item_bodies_dep_node(_: CrateNum) -> DepConstructor {
1005 DepConstructor::TypeckBodiesKrate
1008 fn const_eval_dep_node((def_id, _): (DefId, &Substs)) -> DepConstructor {
1009 DepConstructor::ConstEval(def_id)
1012 fn mir_keys(_: CrateNum) -> DepConstructor {
1013 DepConstructor::MirKeys
1016 fn crate_variances(_: CrateNum) -> DepConstructor {
1017 DepConstructor::CrateVariances
1020 fn relevant_trait_impls_for((def_id, _): (DefId, SimplifiedType)) -> DepConstructor {
1021 DepConstructor::TraitImpls(def_id)
1024 fn is_copy_dep_node<'tcx>(key: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> DepConstructor {
1025 let def_id = ty::item_path::characteristic_def_id_of_type(key.value)
1026 .unwrap_or(DefId::local(CRATE_DEF_INDEX));
1027 DepConstructor::IsCopy(def_id)
1030 fn is_sized_dep_node<'tcx>(key: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> DepConstructor {
1031 let def_id = ty::item_path::characteristic_def_id_of_type(key.value)
1032 .unwrap_or(DefId::local(CRATE_DEF_INDEX));
1033 DepConstructor::IsSized(def_id)
1036 fn is_freeze_dep_node<'tcx>(key: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> DepConstructor {
1037 let def_id = ty::item_path::characteristic_def_id_of_type(key.value)
1038 .unwrap_or(DefId::local(CRATE_DEF_INDEX));
1039 DepConstructor::IsFreeze(def_id)
1042 fn needs_drop_dep_node<'tcx>(key: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> DepConstructor {
1043 let def_id = ty::item_path::characteristic_def_id_of_type(key.value)
1044 .unwrap_or(DefId::local(CRATE_DEF_INDEX));
1045 DepConstructor::NeedsDrop(def_id)
1048 fn layout_dep_node<'tcx>(key: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> DepConstructor {
1049 let def_id = ty::item_path::characteristic_def_id_of_type(key.value)
1050 .unwrap_or(DefId::local(CRATE_DEF_INDEX));
1051 DepConstructor::Layout(def_id)