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