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