]> git.lizzy.rs Git - rust.git/blob - src/librustc/ty/maps.rs
impl_parent
[rust.git] / src / librustc / ty / maps.rs
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.
4 //
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.
10
11 use dep_graph::{DepGraph, DepNode, DepTrackingMap, DepTrackingMapConfig};
12 use hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
13 use hir::def::Def;
14 use hir;
15 use middle::const_val;
16 use middle::privacy::AccessLevels;
17 use middle::region::RegionMaps;
18 use mir;
19 use mir::transform::{MirSuite, MirPassIndex};
20 use session::CompileResult;
21 use ty::{self, CrateInherentImpls, Ty, TyCtxt};
22 use ty::item_path;
23 use ty::steal::Steal;
24 use ty::subst::Substs;
25 use util::nodemap::{DefIdSet, NodeSet};
26
27 use rustc_data_structures::indexed_vec::IndexVec;
28 use std::cell::{RefCell, RefMut};
29 use std::fmt::Debug;
30 use std::hash::Hash;
31 use std::mem;
32 use std::collections::BTreeMap;
33 use std::ops::Deref;
34 use std::rc::Rc;
35 use syntax_pos::{Span, DUMMY_SP};
36 use syntax::attr;
37 use syntax::ast;
38 use syntax::symbol::Symbol;
39
40 pub trait Key: Clone + Hash + Eq + Debug {
41     fn map_crate(&self) -> CrateNum;
42     fn default_span(&self, tcx: TyCtxt) -> Span;
43 }
44
45 impl<'tcx> Key for ty::InstanceDef<'tcx> {
46     fn map_crate(&self) -> CrateNum {
47         LOCAL_CRATE
48     }
49
50     fn default_span(&self, tcx: TyCtxt) -> Span {
51         tcx.def_span(self.def_id())
52     }
53 }
54
55 impl<'tcx> Key for ty::Instance<'tcx> {
56     fn map_crate(&self) -> CrateNum {
57         LOCAL_CRATE
58     }
59
60     fn default_span(&self, tcx: TyCtxt) -> Span {
61         tcx.def_span(self.def_id())
62     }
63 }
64
65 impl Key for CrateNum {
66     fn map_crate(&self) -> CrateNum {
67         *self
68     }
69     fn default_span(&self, _: TyCtxt) -> Span {
70         DUMMY_SP
71     }
72 }
73
74 impl Key for DefId {
75     fn map_crate(&self) -> CrateNum {
76         self.krate
77     }
78     fn default_span(&self, tcx: TyCtxt) -> Span {
79         tcx.def_span(*self)
80     }
81 }
82
83 impl Key for (DefId, DefId) {
84     fn map_crate(&self) -> CrateNum {
85         self.0.krate
86     }
87     fn default_span(&self, tcx: TyCtxt) -> Span {
88         self.1.default_span(tcx)
89     }
90 }
91
92 impl Key for (CrateNum, DefId) {
93     fn map_crate(&self) -> CrateNum {
94         self.0
95     }
96     fn default_span(&self, tcx: TyCtxt) -> Span {
97         self.1.default_span(tcx)
98     }
99 }
100
101 impl<'tcx> Key for (DefId, &'tcx Substs<'tcx>) {
102     fn map_crate(&self) -> CrateNum {
103         self.0.krate
104     }
105     fn default_span(&self, tcx: TyCtxt) -> Span {
106         self.0.default_span(tcx)
107     }
108 }
109
110 impl Key for (MirSuite, DefId) {
111     fn map_crate(&self) -> CrateNum {
112         self.1.map_crate()
113     }
114     fn default_span(&self, tcx: TyCtxt) -> Span {
115         self.1.default_span(tcx)
116     }
117 }
118
119 impl Key for (MirSuite, MirPassIndex, DefId) {
120     fn map_crate(&self) -> CrateNum {
121         self.2.map_crate()
122     }
123     fn default_span(&self, tcx: TyCtxt) -> Span {
124         self.2.default_span(tcx)
125     }
126 }
127
128 trait Value<'tcx>: Sized {
129     fn from_cycle_error<'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> Self;
130 }
131
132 impl<'tcx, T> Value<'tcx> for T {
133     default fn from_cycle_error<'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> T {
134         tcx.sess.abort_if_errors();
135         bug!("Value::from_cycle_error called without errors");
136     }
137 }
138
139 impl<'tcx, T: Default> Value<'tcx> for T {
140     default fn from_cycle_error<'a>(_: TyCtxt<'a, 'tcx, 'tcx>) -> T {
141         T::default()
142     }
143 }
144
145 impl<'tcx> Value<'tcx> for Ty<'tcx> {
146     fn from_cycle_error<'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> Ty<'tcx> {
147         tcx.types.err
148     }
149 }
150
151 impl<'tcx> Value<'tcx> for ty::DtorckConstraint<'tcx> {
152     fn from_cycle_error<'a>(_: TyCtxt<'a, 'tcx, 'tcx>) -> Self {
153         Self::empty()
154     }
155 }
156
157 impl<'tcx> Value<'tcx> for ty::SymbolName {
158     fn from_cycle_error<'a>(_: TyCtxt<'a, 'tcx, 'tcx>) -> Self {
159         ty::SymbolName { name: Symbol::intern("<error>").as_str() }
160     }
161 }
162
163 pub struct CycleError<'a, 'tcx: 'a> {
164     span: Span,
165     cycle: RefMut<'a, [(Span, Query<'tcx>)]>,
166 }
167
168 impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
169     pub fn report_cycle(self, CycleError { span, cycle }: CycleError) {
170         // Subtle: release the refcell lock before invoking `describe()`
171         // below by dropping `cycle`.
172         let stack = cycle.to_vec();
173         mem::drop(cycle);
174
175         assert!(!stack.is_empty());
176
177         // Disable naming impls with types in this path, since that
178         // sometimes cycles itself, leading to extra cycle errors.
179         // (And cycle errors around impls tend to occur during the
180         // collect/coherence phases anyhow.)
181         item_path::with_forced_impl_filename_line(|| {
182             let mut err =
183                 struct_span_err!(self.sess, span, E0391,
184                                  "unsupported cyclic reference between types/traits detected");
185             err.span_label(span, &format!("cyclic reference"));
186
187             err.span_note(stack[0].0, &format!("the cycle begins when {}...",
188                                                stack[0].1.describe(self)));
189
190             for &(span, ref query) in &stack[1..] {
191                 err.span_note(span, &format!("...which then requires {}...",
192                                              query.describe(self)));
193             }
194
195             err.note(&format!("...which then again requires {}, completing the cycle.",
196                               stack[0].1.describe(self)));
197
198             err.emit();
199         });
200     }
201
202     fn cycle_check<F, R>(self, span: Span, query: Query<'gcx>, compute: F)
203                          -> Result<R, CycleError<'a, 'gcx>>
204         where F: FnOnce() -> R
205     {
206         {
207             let mut stack = self.maps.query_stack.borrow_mut();
208             if let Some((i, _)) = stack.iter().enumerate().rev()
209                                        .find(|&(_, &(_, ref q))| *q == query) {
210                 return Err(CycleError {
211                     span: span,
212                     cycle: RefMut::map(stack, |stack| &mut stack[i..])
213                 });
214             }
215             stack.push((span, query));
216         }
217
218         let result = compute();
219
220         self.maps.query_stack.borrow_mut().pop();
221
222         Ok(result)
223     }
224 }
225
226 trait QueryDescription: DepTrackingMapConfig {
227     fn describe(tcx: TyCtxt, key: Self::Key) -> String;
228 }
229
230 impl<M: DepTrackingMapConfig<Key=DefId>> QueryDescription for M {
231     default fn describe(tcx: TyCtxt, def_id: DefId) -> String {
232         format!("processing `{}`", tcx.item_path_str(def_id))
233     }
234 }
235
236 impl<'tcx> QueryDescription for queries::super_predicates_of<'tcx> {
237     fn describe(tcx: TyCtxt, def_id: DefId) -> String {
238         format!("computing the supertraits of `{}`",
239                 tcx.item_path_str(def_id))
240     }
241 }
242
243 impl<'tcx> QueryDescription for queries::type_param_predicates<'tcx> {
244     fn describe(tcx: TyCtxt, (_, def_id): (DefId, DefId)) -> String {
245         let id = tcx.hir.as_local_node_id(def_id).unwrap();
246         format!("computing the bounds for type parameter `{}`",
247                 tcx.hir.ty_param_name(id))
248     }
249 }
250
251 impl<'tcx> QueryDescription for queries::coherent_trait<'tcx> {
252     fn describe(tcx: TyCtxt, (_, def_id): (CrateNum, DefId)) -> String {
253         format!("coherence checking all impls of trait `{}`",
254                 tcx.item_path_str(def_id))
255     }
256 }
257
258 impl<'tcx> QueryDescription for queries::crate_inherent_impls<'tcx> {
259     fn describe(_: TyCtxt, k: CrateNum) -> String {
260         format!("all inherent impls defined in crate `{:?}`", k)
261     }
262 }
263
264 impl<'tcx> QueryDescription for queries::crate_inherent_impls_overlap_check<'tcx> {
265     fn describe(_: TyCtxt, _: CrateNum) -> String {
266         format!("check for overlap between inherent impls defined in this crate")
267     }
268 }
269
270 impl<'tcx> QueryDescription for queries::mir_shims<'tcx> {
271     fn describe(tcx: TyCtxt, def: ty::InstanceDef<'tcx>) -> String {
272         format!("generating MIR shim for `{}`",
273                 tcx.item_path_str(def.def_id()))
274     }
275 }
276
277 impl<'tcx> QueryDescription for queries::privacy_access_levels<'tcx> {
278     fn describe(_: TyCtxt, _: CrateNum) -> String {
279         format!("privacy access levels")
280     }
281 }
282
283 impl<'tcx> QueryDescription for queries::typeck_item_bodies<'tcx> {
284     fn describe(_: TyCtxt, _: CrateNum) -> String {
285         format!("type-checking all item bodies")
286     }
287 }
288
289 impl<'tcx> QueryDescription for queries::reachable_set<'tcx> {
290     fn describe(_: TyCtxt, _: CrateNum) -> String {
291         format!("reachability")
292     }
293 }
294
295 impl<'tcx> QueryDescription for queries::const_eval<'tcx> {
296     fn describe(tcx: TyCtxt, (def_id, _): (DefId, &'tcx Substs<'tcx>)) -> String {
297         format!("const-evaluating `{}`", tcx.item_path_str(def_id))
298     }
299 }
300
301 impl<'tcx> QueryDescription for queries::mir_keys<'tcx> {
302     fn describe(_: TyCtxt, _: CrateNum) -> String {
303         format!("getting a list of all mir_keys")
304     }
305 }
306
307 impl<'tcx> QueryDescription for queries::symbol_name<'tcx> {
308     fn describe(_tcx: TyCtxt, instance: ty::Instance<'tcx>) -> String {
309         format!("computing the symbol for `{}`", instance)
310     }
311 }
312
313 impl<'tcx> QueryDescription for queries::describe_def<'tcx> {
314     fn describe(_: TyCtxt, _: DefId) -> String {
315         bug!("describe_def")
316     }
317 }
318
319 impl<'tcx> QueryDescription for queries::def_span<'tcx> {
320     fn describe(_: TyCtxt, _: DefId) -> String {
321         bug!("def_span")
322     }
323 }
324
325
326 impl<'tcx> QueryDescription for queries::stability<'tcx> {
327     fn describe(_: TyCtxt, _: DefId) -> String {
328         bug!("stability")
329     }
330 }
331
332 impl<'tcx> QueryDescription for queries::deprecation<'tcx> {
333     fn describe(_: TyCtxt, _: DefId) -> String {
334         bug!("deprecation")
335     }
336 }
337
338 impl<'tcx> QueryDescription for queries::item_attrs<'tcx> {
339     fn describe(_: TyCtxt, _: DefId) -> String {
340         bug!("item_attrs")
341     }
342 }
343
344 impl<'tcx> QueryDescription for queries::fn_arg_names<'tcx> {
345     fn describe(_: TyCtxt, _: DefId) -> String {
346         bug!("fn_arg_names")
347     }
348 }
349
350 impl<'tcx> QueryDescription for queries::impl_parent<'tcx> {
351     fn describe(_: TyCtxt, _: DefId) -> String {
352         bug!("impl_parent")
353     }
354 }
355
356 impl<'tcx> QueryDescription for queries::trait_of_item<'tcx> {
357     fn describe(_: TyCtxt, _: DefId) -> String {
358         bug!("trait_of_item")
359     }
360 }
361
362 impl<'tcx> QueryDescription for queries::item_body_nested_bodies<'tcx> {
363     fn describe(tcx: TyCtxt, def_id: DefId) -> String {
364         format!("nested item bodies of `{}`", tcx.item_path_str(def_id))
365     }
366 }
367
368 impl<'tcx> QueryDescription for queries::const_is_rvalue_promotable_to_static<'tcx> {
369     fn describe(tcx: TyCtxt, def_id: DefId) -> String {
370         format!("const checking if rvalue is promotable to static `{}`",
371             tcx.item_path_str(def_id))
372     }
373 }
374
375 impl<'tcx> QueryDescription for queries::is_mir_available<'tcx> {
376     fn describe(tcx: TyCtxt, def_id: DefId) -> String {
377         format!("checking if item is mir available: `{}`",
378             tcx.item_path_str(def_id))
379     }
380 }
381
382 macro_rules! define_maps {
383     (<$tcx:tt>
384      $($(#[$attr:meta])*
385        [$($modifiers:tt)*] $name:ident: $node:ident($K:ty) -> $V:ty,)*) => {
386         define_map_struct! {
387             tcx: $tcx,
388             input: ($(([$($modifiers)*] [$($attr)*] [$name]))*)
389         }
390
391         impl<$tcx> Maps<$tcx> {
392             pub fn new(dep_graph: DepGraph,
393                        providers: IndexVec<CrateNum, Providers<$tcx>>)
394                        -> Self {
395                 Maps {
396                     providers,
397                     query_stack: RefCell::new(vec![]),
398                     $($name: RefCell::new(DepTrackingMap::new(dep_graph.clone()))),*
399                 }
400             }
401         }
402
403         #[allow(bad_style)]
404         #[derive(Copy, Clone, Debug, PartialEq, Eq)]
405         pub enum Query<$tcx> {
406             $($(#[$attr])* $name($K)),*
407         }
408
409         impl<$tcx> Query<$tcx> {
410             pub fn describe(&self, tcx: TyCtxt) -> String {
411                 match *self {
412                     $(Query::$name(key) => queries::$name::describe(tcx, key)),*
413                 }
414             }
415         }
416
417         pub mod queries {
418             use std::marker::PhantomData;
419
420             $(#[allow(bad_style)]
421             pub struct $name<$tcx> {
422                 data: PhantomData<&$tcx ()>
423             })*
424         }
425
426         $(impl<$tcx> DepTrackingMapConfig for queries::$name<$tcx> {
427             type Key = $K;
428             type Value = $V;
429
430             #[allow(unused)]
431             fn to_dep_node(key: &$K) -> DepNode<DefId> {
432                 use dep_graph::DepNode::*;
433
434                 $node(*key)
435             }
436         }
437         impl<'a, $tcx, 'lcx> queries::$name<$tcx> {
438             fn try_get_with<F, R>(tcx: TyCtxt<'a, $tcx, 'lcx>,
439                                   mut span: Span,
440                                   key: $K,
441                                   f: F)
442                                   -> Result<R, CycleError<'a, $tcx>>
443                 where F: FnOnce(&$V) -> R
444             {
445                 debug!("ty::queries::{}::try_get_with(key={:?}, span={:?})",
446                        stringify!($name),
447                        key,
448                        span);
449
450                 if let Some(result) = tcx.maps.$name.borrow().get(&key) {
451                     return Ok(f(result));
452                 }
453
454                 // FIXME(eddyb) Get more valid Span's on queries.
455                 // def_span guard is necesary to prevent a recursive loop,
456                 // default_span calls def_span query internally.
457                 if span == DUMMY_SP && stringify!($name) != "def_span" {
458                     span = key.default_span(tcx)
459                 }
460
461                 let _task = tcx.dep_graph.in_task(Self::to_dep_node(&key));
462
463                 let result = tcx.cycle_check(span, Query::$name(key), || {
464                     let provider = tcx.maps.providers[key.map_crate()].$name;
465                     provider(tcx.global_tcx(), key)
466                 })?;
467
468                 Ok(f(tcx.maps.$name.borrow_mut().entry(key).or_insert(result)))
469             }
470
471             pub fn try_get(tcx: TyCtxt<'a, $tcx, 'lcx>, span: Span, key: $K)
472                            -> Result<$V, CycleError<'a, $tcx>> {
473                 Self::try_get_with(tcx, span, key, Clone::clone)
474             }
475
476             pub fn force(tcx: TyCtxt<'a, $tcx, 'lcx>, span: Span, key: $K) {
477                 // FIXME(eddyb) Move away from using `DepTrackingMap`
478                 // so we don't have to explicitly ignore a false edge:
479                 // we can't observe a value dependency, only side-effects,
480                 // through `force`, and once everything has been updated,
481                 // perhaps only diagnostics, if those, will remain.
482                 let _ignore = tcx.dep_graph.in_ignore();
483                 match Self::try_get_with(tcx, span, key, |_| ()) {
484                     Ok(()) => {}
485                     Err(e) => tcx.report_cycle(e)
486                 }
487             }
488         })*
489
490         #[derive(Copy, Clone)]
491         pub struct TyCtxtAt<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
492             pub tcx: TyCtxt<'a, 'gcx, 'tcx>,
493             pub span: Span,
494         }
495
496         impl<'a, 'gcx, 'tcx> Deref for TyCtxtAt<'a, 'gcx, 'tcx> {
497             type Target = TyCtxt<'a, 'gcx, 'tcx>;
498             fn deref(&self) -> &Self::Target {
499                 &self.tcx
500             }
501         }
502
503         impl<'a, $tcx, 'lcx> TyCtxt<'a, $tcx, 'lcx> {
504             /// Return a transparent wrapper for `TyCtxt` which uses
505             /// `span` as the location of queries performed through it.
506             pub fn at(self, span: Span) -> TyCtxtAt<'a, $tcx, 'lcx> {
507                 TyCtxtAt {
508                     tcx: self,
509                     span
510                 }
511             }
512
513             $($(#[$attr])*
514             pub fn $name(self, key: $K) -> $V {
515                 self.at(DUMMY_SP).$name(key)
516             })*
517         }
518
519         impl<'a, $tcx, 'lcx> TyCtxtAt<'a, $tcx, 'lcx> {
520             $($(#[$attr])*
521             pub fn $name(self, key: $K) -> $V {
522                 queries::$name::try_get(self.tcx, self.span, key).unwrap_or_else(|e| {
523                     self.report_cycle(e);
524                     Value::from_cycle_error(self.global_tcx())
525                 })
526             })*
527         }
528
529         define_provider_struct! {
530             tcx: $tcx,
531             input: ($(([$($modifiers)*] [$name] [$K] [$V]))*),
532             output: ()
533         }
534
535         impl<$tcx> Copy for Providers<$tcx> {}
536         impl<$tcx> Clone for Providers<$tcx> {
537             fn clone(&self) -> Self { *self }
538         }
539     }
540 }
541
542 macro_rules! define_map_struct {
543     // Initial state
544     (tcx: $tcx:tt,
545      input: $input:tt) => {
546         define_map_struct! {
547             tcx: $tcx,
548             input: $input,
549             output: ()
550         }
551     };
552
553     // Final output
554     (tcx: $tcx:tt,
555      input: (),
556      output: ($($output:tt)*)) => {
557         pub struct Maps<$tcx> {
558             providers: IndexVec<CrateNum, Providers<$tcx>>,
559             query_stack: RefCell<Vec<(Span, Query<$tcx>)>>,
560             $($output)*
561         }
562     };
563
564     // Field recognized and ready to shift into the output
565     (tcx: $tcx:tt,
566      ready: ([$($pub:tt)*] [$($attr:tt)*] [$name:ident]),
567      input: $input:tt,
568      output: ($($output:tt)*)) => {
569         define_map_struct! {
570             tcx: $tcx,
571             input: $input,
572             output: ($($output)*
573                      $(#[$attr])* $($pub)* $name: RefCell<DepTrackingMap<queries::$name<$tcx>>>,)
574         }
575     };
576
577     // Detect things with the `pub` modifier
578     (tcx: $tcx:tt,
579      input: (([pub $($other_modifiers:tt)*] $attrs:tt $name:tt) $($input:tt)*),
580      output: $output:tt) => {
581         define_map_struct! {
582             tcx: $tcx,
583             ready: ([pub] $attrs $name),
584             input: ($($input)*),
585             output: $output
586         }
587     };
588
589     // No modifiers left? This is a private item.
590     (tcx: $tcx:tt,
591      input: (([] $attrs:tt $name:tt) $($input:tt)*),
592      output: $output:tt) => {
593         define_map_struct! {
594             tcx: $tcx,
595             ready: ([pub] $attrs $name),
596             input: ($($input)*),
597             output: $output
598         }
599     };
600
601     // Skip other modifiers
602     (tcx: $tcx:tt,
603      input: (([$other_modifier:tt $($modifiers:tt)*] $($fields:tt)*) $($input:tt)*),
604      output: $output:tt) => {
605         define_map_struct! {
606             tcx: $tcx,
607             input: (([$($modifiers)*] $($fields)*) $($input)*),
608             output: $output
609         }
610     };
611 }
612
613 macro_rules! define_provider_struct {
614     // Initial state:
615     (tcx: $tcx:tt, input: $input:tt) => {
616         define_provider_struct! {
617             tcx: $tcx,
618             input: $input,
619             output: ()
620         }
621     };
622
623     // Final state:
624     (tcx: $tcx:tt,
625      input: (),
626      output: ($(([$name:ident] [$K:ty] [$R:ty]))*)) => {
627         pub struct Providers<$tcx> {
628             $(pub $name: for<'a> fn(TyCtxt<'a, $tcx, $tcx>, $K) -> $R,)*
629         }
630
631         impl<$tcx> Default for Providers<$tcx> {
632             fn default() -> Self {
633                 $(fn $name<'a, $tcx>(_: TyCtxt<'a, $tcx, $tcx>, key: $K) -> $R {
634                     bug!("tcx.maps.{}({:?}) unsupported by its crate",
635                          stringify!($name), key);
636                 })*
637                 Providers { $($name),* }
638             }
639         }
640     };
641
642     // Something ready to shift:
643     (tcx: $tcx:tt,
644      ready: ($name:tt $K:tt $V:tt),
645      input: $input:tt,
646      output: ($($output:tt)*)) => {
647         define_provider_struct! {
648             tcx: $tcx,
649             input: $input,
650             output: ($($output)* ($name $K $V))
651         }
652     };
653
654     // Regular queries produce a `V` only.
655     (tcx: $tcx:tt,
656      input: (([] $name:tt $K:tt $V:tt) $($input:tt)*),
657      output: $output:tt) => {
658         define_provider_struct! {
659             tcx: $tcx,
660             ready: ($name $K $V),
661             input: ($($input)*),
662             output: $output
663         }
664     };
665
666     // Skip modifiers.
667     (tcx: $tcx:tt,
668      input: (([$other_modifier:tt $($modifiers:tt)*] $($fields:tt)*) $($input:tt)*),
669      output: $output:tt) => {
670         define_provider_struct! {
671             tcx: $tcx,
672             input: (([$($modifiers)*] $($fields)*) $($input)*),
673             output: $output
674         }
675     };
676 }
677
678 // Each of these maps also corresponds to a method on a
679 // `Provider` trait for requesting a value of that type,
680 // and a method on `Maps` itself for doing that in a
681 // a way that memoizes and does dep-graph tracking,
682 // wrapping around the actual chain of providers that
683 // the driver creates (using several `rustc_*` crates).
684 define_maps! { <'tcx>
685     /// Records the type of every item.
686     [] type_of: ItemSignature(DefId) -> Ty<'tcx>,
687
688     /// Maps from the def-id of an item (trait/struct/enum/fn) to its
689     /// associated generics and predicates.
690     [] generics_of: ItemSignature(DefId) -> &'tcx ty::Generics,
691     [] predicates_of: ItemSignature(DefId) -> ty::GenericPredicates<'tcx>,
692
693     /// Maps from the def-id of a trait to the list of
694     /// super-predicates. This is a subset of the full list of
695     /// predicates. We store these in a separate map because we must
696     /// evaluate them even during type conversion, often before the
697     /// full predicates are available (note that supertraits have
698     /// additional acyclicity requirements).
699     [] super_predicates_of: ItemSignature(DefId) -> ty::GenericPredicates<'tcx>,
700
701     /// To avoid cycles within the predicates of a single item we compute
702     /// per-type-parameter predicates for resolving `T::AssocTy`.
703     [] type_param_predicates: TypeParamPredicates((DefId, DefId))
704         -> ty::GenericPredicates<'tcx>,
705
706     [] trait_def: ItemSignature(DefId) -> &'tcx ty::TraitDef,
707     [] adt_def: ItemSignature(DefId) -> &'tcx ty::AdtDef,
708     [] adt_destructor: AdtDestructor(DefId) -> Option<ty::Destructor>,
709     [] adt_sized_constraint: SizedConstraint(DefId) -> &'tcx [Ty<'tcx>],
710     [] adt_dtorck_constraint: DtorckConstraint(DefId) -> ty::DtorckConstraint<'tcx>,
711
712     /// True if this is a foreign item (i.e., linked via `extern { ... }`).
713     [] is_foreign_item: IsForeignItem(DefId) -> bool,
714
715     /// Maps from def-id of a type or region parameter to its
716     /// (inferred) variance.
717     [pub] variances_of: ItemSignature(DefId) -> Rc<Vec<ty::Variance>>,
718
719     /// Maps from an impl/trait def-id to a list of the def-ids of its items
720     [] associated_item_def_ids: AssociatedItemDefIds(DefId) -> Rc<Vec<DefId>>,
721
722     /// Maps from a trait item to the trait item "descriptor"
723     [] associated_item: AssociatedItems(DefId) -> ty::AssociatedItem,
724
725     [] impl_trait_ref: ItemSignature(DefId) -> Option<ty::TraitRef<'tcx>>,
726     [] impl_polarity: ItemSignature(DefId) -> hir::ImplPolarity,
727
728     /// Maps a DefId of a type to a list of its inherent impls.
729     /// Contains implementations of methods that are inherent to a type.
730     /// Methods in these implementations don't need to be exported.
731     [] inherent_impls: InherentImpls(DefId) -> Rc<Vec<DefId>>,
732
733     /// Set of all the def-ids in this crate that have MIR associated with
734     /// them. This includes all the body owners, but also things like struct
735     /// constructors.
736     [] mir_keys: mir_keys(CrateNum) -> Rc<DefIdSet>,
737
738     /// Maps DefId's that have an associated Mir to the result
739     /// of the MIR qualify_consts pass. The actual meaning of
740     /// the value isn't known except to the pass itself.
741     [] mir_const_qualif: Mir(DefId) -> u8,
742
743     /// Fetch the MIR for a given def-id up till the point where it is
744     /// ready for const evaluation.
745     ///
746     /// See the README for the `mir` module for details.
747     [] mir_const: Mir(DefId) -> &'tcx Steal<mir::Mir<'tcx>>,
748
749     [] mir_validated: Mir(DefId) -> &'tcx Steal<mir::Mir<'tcx>>,
750
751     /// MIR after our optimization passes have run. This is MIR that is ready
752     /// for trans. This is also the only query that can fetch non-local MIR, at present.
753     [] optimized_mir: Mir(DefId) -> &'tcx mir::Mir<'tcx>,
754
755     /// Records the type of each closure. The def ID is the ID of the
756     /// expression defining the closure.
757     [] closure_kind: ItemSignature(DefId) -> ty::ClosureKind,
758
759     /// Records the type of each closure. The def ID is the ID of the
760     /// expression defining the closure.
761     [] closure_type: ItemSignature(DefId) -> ty::PolyFnSig<'tcx>,
762
763     /// Caches CoerceUnsized kinds for impls on custom types.
764     [] coerce_unsized_info: ItemSignature(DefId)
765         -> ty::adjustment::CoerceUnsizedInfo,
766
767     [] typeck_item_bodies: typeck_item_bodies_dep_node(CrateNum) -> CompileResult,
768
769     [] typeck_tables_of: TypeckTables(DefId) -> &'tcx ty::TypeckTables<'tcx>,
770
771     [] has_typeck_tables: TypeckTables(DefId) -> bool,
772
773     [] coherent_trait: coherent_trait_dep_node((CrateNum, DefId)) -> (),
774
775     [] borrowck: BorrowCheck(DefId) -> (),
776
777     /// Gets a complete map from all types to their inherent impls.
778     /// Not meant to be used directly outside of coherence.
779     /// (Defined only for LOCAL_CRATE)
780     [] crate_inherent_impls: crate_inherent_impls_dep_node(CrateNum) -> CrateInherentImpls,
781
782     /// Checks all types in the krate for overlap in their inherent impls. Reports errors.
783     /// Not meant to be used directly outside of coherence.
784     /// (Defined only for LOCAL_CRATE)
785     [] crate_inherent_impls_overlap_check: crate_inherent_impls_dep_node(CrateNum) -> (),
786
787     /// Results of evaluating const items or constants embedded in
788     /// other items (such as enum variant explicit discriminants).
789     [] const_eval: const_eval_dep_node((DefId, &'tcx Substs<'tcx>))
790         -> const_val::EvalResult<'tcx>,
791
792     /// Performs the privacy check and computes "access levels".
793     [] privacy_access_levels: PrivacyAccessLevels(CrateNum) -> Rc<AccessLevels>,
794
795     [] reachable_set: reachability_dep_node(CrateNum) -> Rc<NodeSet>,
796
797     /// Per-function `RegionMaps`. The `DefId` should be the owner-def-id for the fn body;
798     /// in the case of closures or "inline" expressions, this will be redirected to the enclosing
799     /// fn item.
800     [] region_maps: RegionMaps(DefId) -> Rc<RegionMaps<'tcx>>,
801
802     [] mir_shims: mir_shim_dep_node(ty::InstanceDef<'tcx>) -> &'tcx mir::Mir<'tcx>,
803
804     [] def_symbol_name: SymbolName(DefId) -> ty::SymbolName,
805     [] symbol_name: symbol_name_dep_node(ty::Instance<'tcx>) -> ty::SymbolName,
806
807     [] describe_def: DescribeDef(DefId) -> Option<Def>,
808     [] def_span: DefSpan(DefId) -> Span,
809     [] stability: Stability(DefId) -> Option<attr::Stability>,
810     [] deprecation: Deprecation(DefId) -> Option<attr::Deprecation>,
811     [] item_attrs: ItemAttrs(DefId) -> Rc<[ast::Attribute]>,
812     [] fn_arg_names: FnArgNames(DefId) -> Vec<ast::Name>,
813     [] impl_parent: ImplParent(DefId) -> Option<DefId>,
814     [] trait_of_item: TraitOfItem(DefId) -> Option<DefId>,
815     [] item_body_nested_bodies: ItemBodyNestedBodies(DefId) -> Rc<BTreeMap<hir::BodyId, hir::Body>>,
816     [] const_is_rvalue_promotable_to_static: ConstIsRvaluePromotableToStatic(DefId) -> bool,
817     [] is_mir_available: IsMirAvailable(DefId) -> bool,
818 }
819
820 fn coherent_trait_dep_node((_, def_id): (CrateNum, DefId)) -> DepNode<DefId> {
821     DepNode::CoherenceCheckTrait(def_id)
822 }
823
824 fn crate_inherent_impls_dep_node(_: CrateNum) -> DepNode<DefId> {
825     DepNode::Coherence
826 }
827
828 fn reachability_dep_node(_: CrateNum) -> DepNode<DefId> {
829     DepNode::Reachability
830 }
831
832 fn mir_shim_dep_node(instance: ty::InstanceDef) -> DepNode<DefId> {
833     instance.dep_node()
834 }
835
836 fn symbol_name_dep_node(instance: ty::Instance) -> DepNode<DefId> {
837     // symbol_name uses the substs only to traverse them to find the
838     // hash, and that does not create any new dep-nodes.
839     DepNode::SymbolName(instance.def.def_id())
840 }
841
842 fn typeck_item_bodies_dep_node(_: CrateNum) -> DepNode<DefId> {
843     DepNode::TypeckBodiesKrate
844 }
845
846 fn const_eval_dep_node((def_id, _): (DefId, &Substs)) -> DepNode<DefId> {
847     DepNode::ConstEval(def_id)
848 }
849
850 fn mir_keys(_: CrateNum) -> DepNode<DefId> {
851     DepNode::MirKeys
852 }