]> git.lizzy.rs Git - rust.git/blob - src/librustc/ty/maps.rs
fn_arg_names
[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::item_body_nested_bodies<'tcx> {
351     fn describe(tcx: TyCtxt, def_id: DefId) -> String {
352         format!("nested item bodies of `{}`", tcx.item_path_str(def_id))
353     }
354 }
355
356 impl<'tcx> QueryDescription for queries::const_is_rvalue_promotable_to_static<'tcx> {
357     fn describe(tcx: TyCtxt, def_id: DefId) -> String {
358         format!("const checking if rvalue is promotable to static `{}`",
359             tcx.item_path_str(def_id))
360     }
361 }
362
363 impl<'tcx> QueryDescription for queries::is_mir_available<'tcx> {
364     fn describe(tcx: TyCtxt, def_id: DefId) -> String {
365         format!("checking if item is mir available: `{}`",
366             tcx.item_path_str(def_id))
367     }
368 }
369
370 macro_rules! define_maps {
371     (<$tcx:tt>
372      $($(#[$attr:meta])*
373        [$($modifiers:tt)*] $name:ident: $node:ident($K:ty) -> $V:ty,)*) => {
374         define_map_struct! {
375             tcx: $tcx,
376             input: ($(([$($modifiers)*] [$($attr)*] [$name]))*)
377         }
378
379         impl<$tcx> Maps<$tcx> {
380             pub fn new(dep_graph: DepGraph,
381                        providers: IndexVec<CrateNum, Providers<$tcx>>)
382                        -> Self {
383                 Maps {
384                     providers,
385                     query_stack: RefCell::new(vec![]),
386                     $($name: RefCell::new(DepTrackingMap::new(dep_graph.clone()))),*
387                 }
388             }
389         }
390
391         #[allow(bad_style)]
392         #[derive(Copy, Clone, Debug, PartialEq, Eq)]
393         pub enum Query<$tcx> {
394             $($(#[$attr])* $name($K)),*
395         }
396
397         impl<$tcx> Query<$tcx> {
398             pub fn describe(&self, tcx: TyCtxt) -> String {
399                 match *self {
400                     $(Query::$name(key) => queries::$name::describe(tcx, key)),*
401                 }
402             }
403         }
404
405         pub mod queries {
406             use std::marker::PhantomData;
407
408             $(#[allow(bad_style)]
409             pub struct $name<$tcx> {
410                 data: PhantomData<&$tcx ()>
411             })*
412         }
413
414         $(impl<$tcx> DepTrackingMapConfig for queries::$name<$tcx> {
415             type Key = $K;
416             type Value = $V;
417
418             #[allow(unused)]
419             fn to_dep_node(key: &$K) -> DepNode<DefId> {
420                 use dep_graph::DepNode::*;
421
422                 $node(*key)
423             }
424         }
425         impl<'a, $tcx, 'lcx> queries::$name<$tcx> {
426             fn try_get_with<F, R>(tcx: TyCtxt<'a, $tcx, 'lcx>,
427                                   mut span: Span,
428                                   key: $K,
429                                   f: F)
430                                   -> Result<R, CycleError<'a, $tcx>>
431                 where F: FnOnce(&$V) -> R
432             {
433                 debug!("ty::queries::{}::try_get_with(key={:?}, span={:?})",
434                        stringify!($name),
435                        key,
436                        span);
437
438                 if let Some(result) = tcx.maps.$name.borrow().get(&key) {
439                     return Ok(f(result));
440                 }
441
442                 // FIXME(eddyb) Get more valid Span's on queries.
443                 // def_span guard is necesary to prevent a recursive loop,
444                 // default_span calls def_span query internally.
445                 if span == DUMMY_SP && stringify!($name) != "def_span" {
446                     span = key.default_span(tcx)
447                 }
448
449                 let _task = tcx.dep_graph.in_task(Self::to_dep_node(&key));
450
451                 let result = tcx.cycle_check(span, Query::$name(key), || {
452                     let provider = tcx.maps.providers[key.map_crate()].$name;
453                     provider(tcx.global_tcx(), key)
454                 })?;
455
456                 Ok(f(tcx.maps.$name.borrow_mut().entry(key).or_insert(result)))
457             }
458
459             pub fn try_get(tcx: TyCtxt<'a, $tcx, 'lcx>, span: Span, key: $K)
460                            -> Result<$V, CycleError<'a, $tcx>> {
461                 Self::try_get_with(tcx, span, key, Clone::clone)
462             }
463
464             pub fn force(tcx: TyCtxt<'a, $tcx, 'lcx>, span: Span, key: $K) {
465                 // FIXME(eddyb) Move away from using `DepTrackingMap`
466                 // so we don't have to explicitly ignore a false edge:
467                 // we can't observe a value dependency, only side-effects,
468                 // through `force`, and once everything has been updated,
469                 // perhaps only diagnostics, if those, will remain.
470                 let _ignore = tcx.dep_graph.in_ignore();
471                 match Self::try_get_with(tcx, span, key, |_| ()) {
472                     Ok(()) => {}
473                     Err(e) => tcx.report_cycle(e)
474                 }
475             }
476         })*
477
478         #[derive(Copy, Clone)]
479         pub struct TyCtxtAt<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
480             pub tcx: TyCtxt<'a, 'gcx, 'tcx>,
481             pub span: Span,
482         }
483
484         impl<'a, 'gcx, 'tcx> Deref for TyCtxtAt<'a, 'gcx, 'tcx> {
485             type Target = TyCtxt<'a, 'gcx, 'tcx>;
486             fn deref(&self) -> &Self::Target {
487                 &self.tcx
488             }
489         }
490
491         impl<'a, $tcx, 'lcx> TyCtxt<'a, $tcx, 'lcx> {
492             /// Return a transparent wrapper for `TyCtxt` which uses
493             /// `span` as the location of queries performed through it.
494             pub fn at(self, span: Span) -> TyCtxtAt<'a, $tcx, 'lcx> {
495                 TyCtxtAt {
496                     tcx: self,
497                     span
498                 }
499             }
500
501             $($(#[$attr])*
502             pub fn $name(self, key: $K) -> $V {
503                 self.at(DUMMY_SP).$name(key)
504             })*
505         }
506
507         impl<'a, $tcx, 'lcx> TyCtxtAt<'a, $tcx, 'lcx> {
508             $($(#[$attr])*
509             pub fn $name(self, key: $K) -> $V {
510                 queries::$name::try_get(self.tcx, self.span, key).unwrap_or_else(|e| {
511                     self.report_cycle(e);
512                     Value::from_cycle_error(self.global_tcx())
513                 })
514             })*
515         }
516
517         define_provider_struct! {
518             tcx: $tcx,
519             input: ($(([$($modifiers)*] [$name] [$K] [$V]))*),
520             output: ()
521         }
522
523         impl<$tcx> Copy for Providers<$tcx> {}
524         impl<$tcx> Clone for Providers<$tcx> {
525             fn clone(&self) -> Self { *self }
526         }
527     }
528 }
529
530 macro_rules! define_map_struct {
531     // Initial state
532     (tcx: $tcx:tt,
533      input: $input:tt) => {
534         define_map_struct! {
535             tcx: $tcx,
536             input: $input,
537             output: ()
538         }
539     };
540
541     // Final output
542     (tcx: $tcx:tt,
543      input: (),
544      output: ($($output:tt)*)) => {
545         pub struct Maps<$tcx> {
546             providers: IndexVec<CrateNum, Providers<$tcx>>,
547             query_stack: RefCell<Vec<(Span, Query<$tcx>)>>,
548             $($output)*
549         }
550     };
551
552     // Field recognized and ready to shift into the output
553     (tcx: $tcx:tt,
554      ready: ([$($pub:tt)*] [$($attr:tt)*] [$name:ident]),
555      input: $input:tt,
556      output: ($($output:tt)*)) => {
557         define_map_struct! {
558             tcx: $tcx,
559             input: $input,
560             output: ($($output)*
561                      $(#[$attr])* $($pub)* $name: RefCell<DepTrackingMap<queries::$name<$tcx>>>,)
562         }
563     };
564
565     // Detect things with the `pub` modifier
566     (tcx: $tcx:tt,
567      input: (([pub $($other_modifiers:tt)*] $attrs:tt $name:tt) $($input:tt)*),
568      output: $output:tt) => {
569         define_map_struct! {
570             tcx: $tcx,
571             ready: ([pub] $attrs $name),
572             input: ($($input)*),
573             output: $output
574         }
575     };
576
577     // No modifiers left? This is a private item.
578     (tcx: $tcx:tt,
579      input: (([] $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     // Skip other modifiers
590     (tcx: $tcx:tt,
591      input: (([$other_modifier:tt $($modifiers:tt)*] $($fields:tt)*) $($input:tt)*),
592      output: $output:tt) => {
593         define_map_struct! {
594             tcx: $tcx,
595             input: (([$($modifiers)*] $($fields)*) $($input)*),
596             output: $output
597         }
598     };
599 }
600
601 macro_rules! define_provider_struct {
602     // Initial state:
603     (tcx: $tcx:tt, input: $input:tt) => {
604         define_provider_struct! {
605             tcx: $tcx,
606             input: $input,
607             output: ()
608         }
609     };
610
611     // Final state:
612     (tcx: $tcx:tt,
613      input: (),
614      output: ($(([$name:ident] [$K:ty] [$R:ty]))*)) => {
615         pub struct Providers<$tcx> {
616             $(pub $name: for<'a> fn(TyCtxt<'a, $tcx, $tcx>, $K) -> $R,)*
617         }
618
619         impl<$tcx> Default for Providers<$tcx> {
620             fn default() -> Self {
621                 $(fn $name<'a, $tcx>(_: TyCtxt<'a, $tcx, $tcx>, key: $K) -> $R {
622                     bug!("tcx.maps.{}({:?}) unsupported by its crate",
623                          stringify!($name), key);
624                 })*
625                 Providers { $($name),* }
626             }
627         }
628     };
629
630     // Something ready to shift:
631     (tcx: $tcx:tt,
632      ready: ($name:tt $K:tt $V:tt),
633      input: $input:tt,
634      output: ($($output:tt)*)) => {
635         define_provider_struct! {
636             tcx: $tcx,
637             input: $input,
638             output: ($($output)* ($name $K $V))
639         }
640     };
641
642     // Regular queries produce a `V` only.
643     (tcx: $tcx:tt,
644      input: (([] $name:tt $K:tt $V:tt) $($input:tt)*),
645      output: $output:tt) => {
646         define_provider_struct! {
647             tcx: $tcx,
648             ready: ($name $K $V),
649             input: ($($input)*),
650             output: $output
651         }
652     };
653
654     // Skip modifiers.
655     (tcx: $tcx:tt,
656      input: (([$other_modifier:tt $($modifiers:tt)*] $($fields:tt)*) $($input:tt)*),
657      output: $output:tt) => {
658         define_provider_struct! {
659             tcx: $tcx,
660             input: (([$($modifiers)*] $($fields)*) $($input)*),
661             output: $output
662         }
663     };
664 }
665
666 // Each of these maps also corresponds to a method on a
667 // `Provider` trait for requesting a value of that type,
668 // and a method on `Maps` itself for doing that in a
669 // a way that memoizes and does dep-graph tracking,
670 // wrapping around the actual chain of providers that
671 // the driver creates (using several `rustc_*` crates).
672 define_maps! { <'tcx>
673     /// Records the type of every item.
674     [] type_of: ItemSignature(DefId) -> Ty<'tcx>,
675
676     /// Maps from the def-id of an item (trait/struct/enum/fn) to its
677     /// associated generics and predicates.
678     [] generics_of: ItemSignature(DefId) -> &'tcx ty::Generics,
679     [] predicates_of: ItemSignature(DefId) -> ty::GenericPredicates<'tcx>,
680
681     /// Maps from the def-id of a trait to the list of
682     /// super-predicates. This is a subset of the full list of
683     /// predicates. We store these in a separate map because we must
684     /// evaluate them even during type conversion, often before the
685     /// full predicates are available (note that supertraits have
686     /// additional acyclicity requirements).
687     [] super_predicates_of: ItemSignature(DefId) -> ty::GenericPredicates<'tcx>,
688
689     /// To avoid cycles within the predicates of a single item we compute
690     /// per-type-parameter predicates for resolving `T::AssocTy`.
691     [] type_param_predicates: TypeParamPredicates((DefId, DefId))
692         -> ty::GenericPredicates<'tcx>,
693
694     [] trait_def: ItemSignature(DefId) -> &'tcx ty::TraitDef,
695     [] adt_def: ItemSignature(DefId) -> &'tcx ty::AdtDef,
696     [] adt_destructor: AdtDestructor(DefId) -> Option<ty::Destructor>,
697     [] adt_sized_constraint: SizedConstraint(DefId) -> &'tcx [Ty<'tcx>],
698     [] adt_dtorck_constraint: DtorckConstraint(DefId) -> ty::DtorckConstraint<'tcx>,
699
700     /// True if this is a foreign item (i.e., linked via `extern { ... }`).
701     [] is_foreign_item: IsForeignItem(DefId) -> bool,
702
703     /// Maps from def-id of a type or region parameter to its
704     /// (inferred) variance.
705     [pub] variances_of: ItemSignature(DefId) -> Rc<Vec<ty::Variance>>,
706
707     /// Maps from an impl/trait def-id to a list of the def-ids of its items
708     [] associated_item_def_ids: AssociatedItemDefIds(DefId) -> Rc<Vec<DefId>>,
709
710     /// Maps from a trait item to the trait item "descriptor"
711     [] associated_item: AssociatedItems(DefId) -> ty::AssociatedItem,
712
713     [] impl_trait_ref: ItemSignature(DefId) -> Option<ty::TraitRef<'tcx>>,
714     [] impl_polarity: ItemSignature(DefId) -> hir::ImplPolarity,
715
716     /// Maps a DefId of a type to a list of its inherent impls.
717     /// Contains implementations of methods that are inherent to a type.
718     /// Methods in these implementations don't need to be exported.
719     [] inherent_impls: InherentImpls(DefId) -> Rc<Vec<DefId>>,
720
721     /// Set of all the def-ids in this crate that have MIR associated with
722     /// them. This includes all the body owners, but also things like struct
723     /// constructors.
724     [] mir_keys: mir_keys(CrateNum) -> Rc<DefIdSet>,
725
726     /// Maps DefId's that have an associated Mir to the result
727     /// of the MIR qualify_consts pass. The actual meaning of
728     /// the value isn't known except to the pass itself.
729     [] mir_const_qualif: Mir(DefId) -> u8,
730
731     /// Fetch the MIR for a given def-id up till the point where it is
732     /// ready for const evaluation.
733     ///
734     /// See the README for the `mir` module for details.
735     [] mir_const: Mir(DefId) -> &'tcx Steal<mir::Mir<'tcx>>,
736
737     [] mir_validated: Mir(DefId) -> &'tcx Steal<mir::Mir<'tcx>>,
738
739     /// MIR after our optimization passes have run. This is MIR that is ready
740     /// for trans. This is also the only query that can fetch non-local MIR, at present.
741     [] optimized_mir: Mir(DefId) -> &'tcx mir::Mir<'tcx>,
742
743     /// Records the type of each closure. The def ID is the ID of the
744     /// expression defining the closure.
745     [] closure_kind: ItemSignature(DefId) -> ty::ClosureKind,
746
747     /// Records the type of each closure. The def ID is the ID of the
748     /// expression defining the closure.
749     [] closure_type: ItemSignature(DefId) -> ty::PolyFnSig<'tcx>,
750
751     /// Caches CoerceUnsized kinds for impls on custom types.
752     [] coerce_unsized_info: ItemSignature(DefId)
753         -> ty::adjustment::CoerceUnsizedInfo,
754
755     [] typeck_item_bodies: typeck_item_bodies_dep_node(CrateNum) -> CompileResult,
756
757     [] typeck_tables_of: TypeckTables(DefId) -> &'tcx ty::TypeckTables<'tcx>,
758
759     [] has_typeck_tables: TypeckTables(DefId) -> bool,
760
761     [] coherent_trait: coherent_trait_dep_node((CrateNum, DefId)) -> (),
762
763     [] borrowck: BorrowCheck(DefId) -> (),
764
765     /// Gets a complete map from all types to their inherent impls.
766     /// Not meant to be used directly outside of coherence.
767     /// (Defined only for LOCAL_CRATE)
768     [] crate_inherent_impls: crate_inherent_impls_dep_node(CrateNum) -> CrateInherentImpls,
769
770     /// Checks all types in the krate for overlap in their inherent impls. Reports errors.
771     /// Not meant to be used directly outside of coherence.
772     /// (Defined only for LOCAL_CRATE)
773     [] crate_inherent_impls_overlap_check: crate_inherent_impls_dep_node(CrateNum) -> (),
774
775     /// Results of evaluating const items or constants embedded in
776     /// other items (such as enum variant explicit discriminants).
777     [] const_eval: const_eval_dep_node((DefId, &'tcx Substs<'tcx>))
778         -> const_val::EvalResult<'tcx>,
779
780     /// Performs the privacy check and computes "access levels".
781     [] privacy_access_levels: PrivacyAccessLevels(CrateNum) -> Rc<AccessLevels>,
782
783     [] reachable_set: reachability_dep_node(CrateNum) -> Rc<NodeSet>,
784
785     /// Per-function `RegionMaps`. The `DefId` should be the owner-def-id for the fn body;
786     /// in the case of closures or "inline" expressions, this will be redirected to the enclosing
787     /// fn item.
788     [] region_maps: RegionMaps(DefId) -> Rc<RegionMaps<'tcx>>,
789
790     [] mir_shims: mir_shim_dep_node(ty::InstanceDef<'tcx>) -> &'tcx mir::Mir<'tcx>,
791
792     [] def_symbol_name: SymbolName(DefId) -> ty::SymbolName,
793     [] symbol_name: symbol_name_dep_node(ty::Instance<'tcx>) -> ty::SymbolName,
794
795     [] describe_def: DescribeDef(DefId) -> Option<Def>,
796     [] def_span: DefSpan(DefId) -> Span,
797     [] stability: Stability(DefId) -> Option<attr::Stability>,
798     [] deprecation: Deprecation(DefId) -> Option<attr::Deprecation>,
799     [] item_attrs: ItemAttrs(DefId) -> Rc<[ast::Attribute]>,
800     [] fn_arg_names: FnArgNames(DefId) -> Vec<ast::Name>,
801     [] item_body_nested_bodies: ItemBodyNestedBodies(DefId) -> Rc<BTreeMap<hir::BodyId, hir::Body>>,
802     [] const_is_rvalue_promotable_to_static: ConstIsRvaluePromotableToStatic(DefId) -> bool,
803     [] is_mir_available: IsMirAvailable(DefId) -> bool,
804 }
805
806 fn coherent_trait_dep_node((_, def_id): (CrateNum, DefId)) -> DepNode<DefId> {
807     DepNode::CoherenceCheckTrait(def_id)
808 }
809
810 fn crate_inherent_impls_dep_node(_: CrateNum) -> DepNode<DefId> {
811     DepNode::Coherence
812 }
813
814 fn reachability_dep_node(_: CrateNum) -> DepNode<DefId> {
815     DepNode::Reachability
816 }
817
818 fn mir_shim_dep_node(instance: ty::InstanceDef) -> DepNode<DefId> {
819     instance.dep_node()
820 }
821
822 fn symbol_name_dep_node(instance: ty::Instance) -> DepNode<DefId> {
823     // symbol_name uses the substs only to traverse them to find the
824     // hash, and that does not create any new dep-nodes.
825     DepNode::SymbolName(instance.def.def_id())
826 }
827
828 fn typeck_item_bodies_dep_node(_: CrateNum) -> DepNode<DefId> {
829     DepNode::TypeckBodiesKrate
830 }
831
832 fn const_eval_dep_node((def_id, _): (DefId, &Substs)) -> DepNode<DefId> {
833     DepNode::ConstEval(def_id)
834 }
835
836 fn mir_keys(_: CrateNum) -> DepNode<DefId> {
837     DepNode::MirKeys
838 }