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