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