]> git.lizzy.rs Git - rust.git/blob - src/librustc/ty/maps.rs
20b082552d52a6fbb080f5f8ed851c6b864e9f7c
[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::{DepConstructor, DepNode, DepNodeIndex};
12 use errors::{Diagnostic, DiagnosticBuilder};
13 use hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
14 use hir::def::{Def, Export};
15 use hir::{self, TraitCandidate, HirId};
16 use lint;
17 use middle::const_val;
18 use middle::cstore::{ExternCrate, LinkagePreference};
19 use middle::privacy::AccessLevels;
20 use middle::region;
21 use mir;
22 use mir::transform::{MirSuite, MirPassIndex};
23 use session::CompileResult;
24 use traits::specialization_graph;
25 use ty::{self, CrateInherentImpls, Ty, TyCtxt};
26 use ty::layout::{Layout, LayoutError};
27 use ty::item_path;
28 use ty::steal::Steal;
29 use ty::subst::Substs;
30 use ty::fast_reject::SimplifiedType;
31 use util::nodemap::{DefIdSet, NodeSet};
32 use util::common::{profq_msg, ProfileQueriesMsg};
33
34 use rustc_data_structures::indexed_set::IdxSetBuf;
35 use rustc_back::PanicStrategy;
36 use rustc_data_structures::indexed_vec::IndexVec;
37 use rustc_data_structures::fx::FxHashMap;
38 use std::cell::{RefCell, RefMut, Cell};
39 use std::fmt::Debug;
40 use std::hash::Hash;
41 use std::marker::PhantomData;
42 use std::mem;
43 use std::collections::BTreeMap;
44 use std::ops::Deref;
45 use std::rc::Rc;
46 use syntax_pos::{Span, DUMMY_SP};
47 use syntax::attr;
48 use syntax::ast;
49 use syntax::symbol::Symbol;
50
51 pub trait Key: Clone + Hash + Eq + Debug {
52     fn map_crate(&self) -> CrateNum;
53     fn default_span(&self, tcx: TyCtxt) -> Span;
54 }
55
56 impl<'tcx> Key for ty::InstanceDef<'tcx> {
57     fn map_crate(&self) -> CrateNum {
58         LOCAL_CRATE
59     }
60
61     fn default_span(&self, tcx: TyCtxt) -> Span {
62         tcx.def_span(self.def_id())
63     }
64 }
65
66 impl<'tcx> Key for ty::Instance<'tcx> {
67     fn map_crate(&self) -> CrateNum {
68         LOCAL_CRATE
69     }
70
71     fn default_span(&self, tcx: TyCtxt) -> Span {
72         tcx.def_span(self.def_id())
73     }
74 }
75
76 impl Key for CrateNum {
77     fn map_crate(&self) -> CrateNum {
78         *self
79     }
80     fn default_span(&self, _: TyCtxt) -> Span {
81         DUMMY_SP
82     }
83 }
84
85 impl Key for HirId {
86     fn map_crate(&self) -> CrateNum {
87         LOCAL_CRATE
88     }
89     fn default_span(&self, _tcx: TyCtxt) -> Span {
90         DUMMY_SP
91     }
92 }
93
94 impl Key for DefId {
95     fn map_crate(&self) -> CrateNum {
96         self.krate
97     }
98     fn default_span(&self, tcx: TyCtxt) -> Span {
99         tcx.def_span(*self)
100     }
101 }
102
103 impl Key for (DefId, DefId) {
104     fn map_crate(&self) -> CrateNum {
105         self.0.krate
106     }
107     fn default_span(&self, tcx: TyCtxt) -> Span {
108         self.1.default_span(tcx)
109     }
110 }
111
112 impl Key for (CrateNum, DefId) {
113     fn map_crate(&self) -> CrateNum {
114         self.0
115     }
116     fn default_span(&self, tcx: TyCtxt) -> Span {
117         self.1.default_span(tcx)
118     }
119 }
120
121 impl Key for (DefId, SimplifiedType) {
122     fn map_crate(&self) -> CrateNum {
123         self.0.krate
124     }
125     fn default_span(&self, tcx: TyCtxt) -> Span {
126         self.0.default_span(tcx)
127     }
128 }
129
130 impl<'tcx> Key for (DefId, &'tcx Substs<'tcx>) {
131     fn map_crate(&self) -> CrateNum {
132         self.0.krate
133     }
134     fn default_span(&self, tcx: TyCtxt) -> Span {
135         self.0.default_span(tcx)
136     }
137 }
138
139 impl Key for (MirSuite, DefId) {
140     fn map_crate(&self) -> CrateNum {
141         self.1.map_crate()
142     }
143     fn default_span(&self, tcx: TyCtxt) -> Span {
144         self.1.default_span(tcx)
145     }
146 }
147
148 impl Key for (MirSuite, MirPassIndex, DefId) {
149     fn map_crate(&self) -> CrateNum {
150         self.2.map_crate()
151     }
152     fn default_span(&self, tcx: TyCtxt) -> Span {
153         self.2.default_span(tcx)
154     }
155 }
156
157 impl<'tcx, T: Clone + Hash + Eq + Debug> Key for ty::ParamEnvAnd<'tcx, T> {
158     fn map_crate(&self) -> CrateNum {
159         LOCAL_CRATE
160     }
161     fn default_span(&self, _: TyCtxt) -> Span {
162         DUMMY_SP
163     }
164 }
165
166 trait Value<'tcx>: Sized {
167     fn from_cycle_error<'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> Self;
168 }
169
170 impl<'tcx, T> Value<'tcx> for T {
171     default fn from_cycle_error<'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> T {
172         tcx.sess.abort_if_errors();
173         bug!("Value::from_cycle_error called without errors");
174     }
175 }
176
177 impl<'tcx, T: Default> Value<'tcx> for T {
178     default fn from_cycle_error<'a>(_: TyCtxt<'a, 'tcx, 'tcx>) -> T {
179         T::default()
180     }
181 }
182
183 impl<'tcx> Value<'tcx> for Ty<'tcx> {
184     fn from_cycle_error<'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> Ty<'tcx> {
185         tcx.types.err
186     }
187 }
188
189 impl<'tcx> Value<'tcx> for ty::DtorckConstraint<'tcx> {
190     fn from_cycle_error<'a>(_: TyCtxt<'a, 'tcx, 'tcx>) -> Self {
191         Self::empty()
192     }
193 }
194
195 impl<'tcx> Value<'tcx> for ty::SymbolName {
196     fn from_cycle_error<'a>(_: TyCtxt<'a, 'tcx, 'tcx>) -> Self {
197         ty::SymbolName { name: Symbol::intern("<error>").as_str() }
198     }
199 }
200
201 struct QueryMap<D: QueryDescription> {
202     phantom: PhantomData<D>,
203     map: FxHashMap<D::Key, QueryValue<D::Value>>,
204 }
205
206 struct QueryValue<T> {
207     value: T,
208     index: DepNodeIndex,
209     diagnostics: Option<Box<QueryDiagnostics>>,
210 }
211
212 struct QueryDiagnostics {
213     diagnostics: Vec<Diagnostic>,
214     emitted_diagnostics: Cell<bool>,
215 }
216
217 impl<M: QueryDescription> QueryMap<M> {
218     fn new() -> QueryMap<M> {
219         QueryMap {
220             phantom: PhantomData,
221             map: FxHashMap(),
222         }
223     }
224 }
225
226 struct CycleError<'a, 'tcx: 'a> {
227     span: Span,
228     cycle: RefMut<'a, [(Span, Query<'tcx>)]>,
229 }
230
231 impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
232     fn report_cycle(self, CycleError { span, cycle }: CycleError)
233         -> DiagnosticBuilder<'a>
234     {
235         // Subtle: release the refcell lock before invoking `describe()`
236         // below by dropping `cycle`.
237         let stack = cycle.to_vec();
238         mem::drop(cycle);
239
240         assert!(!stack.is_empty());
241
242         // Disable naming impls with types in this path, since that
243         // sometimes cycles itself, leading to extra cycle errors.
244         // (And cycle errors around impls tend to occur during the
245         // collect/coherence phases anyhow.)
246         item_path::with_forced_impl_filename_line(|| {
247             let mut err =
248                 struct_span_err!(self.sess, span, E0391,
249                                  "unsupported cyclic reference between types/traits detected");
250             err.span_label(span, "cyclic reference");
251
252             err.span_note(stack[0].0, &format!("the cycle begins when {}...",
253                                                stack[0].1.describe(self)));
254
255             for &(span, ref query) in &stack[1..] {
256                 err.span_note(span, &format!("...which then requires {}...",
257                                              query.describe(self)));
258             }
259
260             err.note(&format!("...which then again requires {}, completing the cycle.",
261                               stack[0].1.describe(self)));
262
263             return err
264         })
265     }
266
267     fn cycle_check<F, R>(self, span: Span, query: Query<'gcx>, compute: F)
268                          -> Result<R, CycleError<'a, 'gcx>>
269         where F: FnOnce() -> R
270     {
271         {
272             let mut stack = self.maps.query_stack.borrow_mut();
273             if let Some((i, _)) = stack.iter().enumerate().rev()
274                                        .find(|&(_, &(_, ref q))| *q == query) {
275                 return Err(CycleError {
276                     span,
277                     cycle: RefMut::map(stack, |stack| &mut stack[i..])
278                 });
279             }
280             stack.push((span, query));
281         }
282
283         let result = compute();
284
285         self.maps.query_stack.borrow_mut().pop();
286
287         Ok(result)
288     }
289 }
290
291 pub trait QueryConfig {
292     type Key: Eq + Hash + Clone;
293     type Value;
294 }
295
296 trait QueryDescription: QueryConfig {
297     fn describe(tcx: TyCtxt, key: Self::Key) -> String;
298 }
299
300 impl<M: QueryConfig<Key=DefId>> QueryDescription for M {
301     default fn describe(tcx: TyCtxt, def_id: DefId) -> String {
302         format!("processing `{}`", tcx.item_path_str(def_id))
303     }
304 }
305
306 impl<'tcx> QueryDescription for queries::is_copy_raw<'tcx> {
307     fn describe(_tcx: TyCtxt, env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> String {
308         format!("computing whether `{}` is `Copy`", env.value)
309     }
310 }
311
312 impl<'tcx> QueryDescription for queries::is_sized_raw<'tcx> {
313     fn describe(_tcx: TyCtxt, env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> String {
314         format!("computing whether `{}` is `Sized`", env.value)
315     }
316 }
317
318 impl<'tcx> QueryDescription for queries::is_freeze_raw<'tcx> {
319     fn describe(_tcx: TyCtxt, env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> String {
320         format!("computing whether `{}` is freeze", env.value)
321     }
322 }
323
324 impl<'tcx> QueryDescription for queries::needs_drop_raw<'tcx> {
325     fn describe(_tcx: TyCtxt, env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> String {
326         format!("computing whether `{}` needs drop", env.value)
327     }
328 }
329
330 impl<'tcx> QueryDescription for queries::layout_raw<'tcx> {
331     fn describe(_tcx: TyCtxt, env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> String {
332         format!("computing layout of `{}`", env.value)
333     }
334 }
335
336 impl<'tcx> QueryDescription for queries::super_predicates_of<'tcx> {
337     fn describe(tcx: TyCtxt, def_id: DefId) -> String {
338         format!("computing the supertraits of `{}`",
339                 tcx.item_path_str(def_id))
340     }
341 }
342
343 impl<'tcx> QueryDescription for queries::type_param_predicates<'tcx> {
344     fn describe(tcx: TyCtxt, (_, def_id): (DefId, DefId)) -> String {
345         let id = tcx.hir.as_local_node_id(def_id).unwrap();
346         format!("computing the bounds for type parameter `{}`",
347                 tcx.hir.ty_param_name(id))
348     }
349 }
350
351 impl<'tcx> QueryDescription for queries::coherent_trait<'tcx> {
352     fn describe(tcx: TyCtxt, (_, def_id): (CrateNum, DefId)) -> String {
353         format!("coherence checking all impls of trait `{}`",
354                 tcx.item_path_str(def_id))
355     }
356 }
357
358 impl<'tcx> QueryDescription for queries::crate_inherent_impls<'tcx> {
359     fn describe(_: TyCtxt, k: CrateNum) -> String {
360         format!("all inherent impls defined in crate `{:?}`", k)
361     }
362 }
363
364 impl<'tcx> QueryDescription for queries::crate_inherent_impls_overlap_check<'tcx> {
365     fn describe(_: TyCtxt, _: CrateNum) -> String {
366         format!("check for overlap between inherent impls defined in this crate")
367     }
368 }
369
370 impl<'tcx> QueryDescription for queries::crate_variances<'tcx> {
371     fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
372         format!("computing the variances for items in this crate")
373     }
374 }
375
376 impl<'tcx> QueryDescription for queries::mir_shims<'tcx> {
377     fn describe(tcx: TyCtxt, def: ty::InstanceDef<'tcx>) -> String {
378         format!("generating MIR shim for `{}`",
379                 tcx.item_path_str(def.def_id()))
380     }
381 }
382
383 impl<'tcx> QueryDescription for queries::privacy_access_levels<'tcx> {
384     fn describe(_: TyCtxt, _: CrateNum) -> String {
385         format!("privacy access levels")
386     }
387 }
388
389 impl<'tcx> QueryDescription for queries::typeck_item_bodies<'tcx> {
390     fn describe(_: TyCtxt, _: CrateNum) -> String {
391         format!("type-checking all item bodies")
392     }
393 }
394
395 impl<'tcx> QueryDescription for queries::reachable_set<'tcx> {
396     fn describe(_: TyCtxt, _: CrateNum) -> String {
397         format!("reachability")
398     }
399 }
400
401 impl<'tcx> QueryDescription for queries::const_eval<'tcx> {
402     fn describe(tcx: TyCtxt, key: ty::ParamEnvAnd<'tcx, (DefId, &'tcx Substs<'tcx>)>) -> String {
403         format!("const-evaluating `{}`", tcx.item_path_str(key.value.0))
404     }
405 }
406
407 impl<'tcx> QueryDescription for queries::mir_keys<'tcx> {
408     fn describe(_: TyCtxt, _: CrateNum) -> String {
409         format!("getting a list of all mir_keys")
410     }
411 }
412
413 impl<'tcx> QueryDescription for queries::symbol_name<'tcx> {
414     fn describe(_tcx: TyCtxt, instance: ty::Instance<'tcx>) -> String {
415         format!("computing the symbol for `{}`", instance)
416     }
417 }
418
419 impl<'tcx> QueryDescription for queries::describe_def<'tcx> {
420     fn describe(_: TyCtxt, _: DefId) -> String {
421         bug!("describe_def")
422     }
423 }
424
425 impl<'tcx> QueryDescription for queries::def_span<'tcx> {
426     fn describe(_: TyCtxt, _: DefId) -> String {
427         bug!("def_span")
428     }
429 }
430
431
432 impl<'tcx> QueryDescription for queries::stability<'tcx> {
433     fn describe(_: TyCtxt, _: DefId) -> String {
434         bug!("stability")
435     }
436 }
437
438 impl<'tcx> QueryDescription for queries::deprecation<'tcx> {
439     fn describe(_: TyCtxt, _: DefId) -> String {
440         bug!("deprecation")
441     }
442 }
443
444 impl<'tcx> QueryDescription for queries::item_attrs<'tcx> {
445     fn describe(_: TyCtxt, _: DefId) -> String {
446         bug!("item_attrs")
447     }
448 }
449
450 impl<'tcx> QueryDescription for queries::is_exported_symbol<'tcx> {
451     fn describe(_: TyCtxt, _: DefId) -> String {
452         bug!("is_exported_symbol")
453     }
454 }
455
456 impl<'tcx> QueryDescription for queries::fn_arg_names<'tcx> {
457     fn describe(_: TyCtxt, _: DefId) -> String {
458         bug!("fn_arg_names")
459     }
460 }
461
462 impl<'tcx> QueryDescription for queries::impl_parent<'tcx> {
463     fn describe(_: TyCtxt, _: DefId) -> String {
464         bug!("impl_parent")
465     }
466 }
467
468 impl<'tcx> QueryDescription for queries::trait_of_item<'tcx> {
469     fn describe(_: TyCtxt, _: DefId) -> String {
470         bug!("trait_of_item")
471     }
472 }
473
474 impl<'tcx> QueryDescription for queries::item_body_nested_bodies<'tcx> {
475     fn describe(tcx: TyCtxt, def_id: DefId) -> String {
476         format!("nested item bodies of `{}`", tcx.item_path_str(def_id))
477     }
478 }
479
480 impl<'tcx> QueryDescription for queries::const_is_rvalue_promotable_to_static<'tcx> {
481     fn describe(tcx: TyCtxt, def_id: DefId) -> String {
482         format!("const checking if rvalue is promotable to static `{}`",
483             tcx.item_path_str(def_id))
484     }
485 }
486
487 impl<'tcx> QueryDescription for queries::is_mir_available<'tcx> {
488     fn describe(tcx: TyCtxt, def_id: DefId) -> String {
489         format!("checking if item is mir available: `{}`",
490             tcx.item_path_str(def_id))
491     }
492 }
493
494 impl<'tcx> QueryDescription for queries::trait_impls_of<'tcx> {
495     fn describe(tcx: TyCtxt, def_id: DefId) -> String {
496         format!("trait impls of `{}`", tcx.item_path_str(def_id))
497     }
498 }
499
500 impl<'tcx> QueryDescription for queries::is_object_safe<'tcx> {
501     fn describe(tcx: TyCtxt, def_id: DefId) -> String {
502         format!("determine object safety of trait `{}`", tcx.item_path_str(def_id))
503     }
504 }
505
506 impl<'tcx> QueryDescription for queries::is_const_fn<'tcx> {
507     fn describe(tcx: TyCtxt, def_id: DefId) -> String {
508         format!("checking if item is const fn: `{}`", tcx.item_path_str(def_id))
509     }
510 }
511
512 impl<'tcx> QueryDescription for queries::dylib_dependency_formats<'tcx> {
513     fn describe(_: TyCtxt, _: CrateNum) -> String {
514         "dylib dependency formats of crate".to_string()
515     }
516 }
517
518 impl<'tcx> QueryDescription for queries::is_panic_runtime<'tcx> {
519     fn describe(_: TyCtxt, _: CrateNum) -> String {
520         "checking if the crate is_panic_runtime".to_string()
521     }
522 }
523
524 impl<'tcx> QueryDescription for queries::is_compiler_builtins<'tcx> {
525     fn describe(_: TyCtxt, _: CrateNum) -> String {
526         "checking if the crate is_compiler_builtins".to_string()
527     }
528 }
529
530 impl<'tcx> QueryDescription for queries::has_global_allocator<'tcx> {
531     fn describe(_: TyCtxt, _: CrateNum) -> String {
532         "checking if the crate has_global_allocator".to_string()
533     }
534 }
535
536 impl<'tcx> QueryDescription for queries::extern_crate<'tcx> {
537     fn describe(_: TyCtxt, _: DefId) -> String {
538         "getting crate's ExternCrateData".to_string()
539     }
540 }
541
542 impl<'tcx> QueryDescription for queries::lint_levels<'tcx> {
543     fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
544         format!("computing the lint levels for items in this crate")
545     }
546 }
547
548 impl<'tcx> QueryDescription for queries::specializes<'tcx> {
549     fn describe(_tcx: TyCtxt, _: (DefId, DefId)) -> String {
550         format!("computing whether impls specialize one another")
551     }
552 }
553
554 impl<'tcx> QueryDescription for queries::in_scope_traits<'tcx> {
555     fn describe(_tcx: TyCtxt, _: HirId) -> String {
556         format!("fetching the traits in scope at a particular ast node")
557     }
558 }
559
560 impl<'tcx> QueryDescription for queries::module_exports<'tcx> {
561     fn describe(_tcx: TyCtxt, _: HirId) -> String {
562         format!("fetching the exported items for a module")
563     }
564 }
565
566 impl<'tcx> QueryDescription for queries::is_no_builtins<'tcx> {
567     fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
568         format!("test whether a crate has #![no_builtins]")
569     }
570 }
571
572 impl<'tcx> QueryDescription for queries::panic_strategy<'tcx> {
573     fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
574         format!("query a crate's configured panic strategy")
575     }
576 }
577
578 impl<'tcx> QueryDescription for queries::is_profiler_runtime<'tcx> {
579     fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
580         format!("query a crate is #![profiler_runtime]")
581     }
582 }
583
584 impl<'tcx> QueryDescription for queries::is_sanitizer_runtime<'tcx> {
585     fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
586         format!("query a crate is #![sanitizer_runtime]")
587     }
588 }
589
590 // If enabled, send a message to the profile-queries thread
591 macro_rules! profq_msg {
592     ($tcx:expr, $msg:expr) => {
593         if cfg!(debug_assertions) {
594             if  $tcx.sess.profile_queries() {
595                 profq_msg($msg)
596             }
597         }
598     }
599 }
600
601 // If enabled, format a key using its debug string, which can be
602 // expensive to compute (in terms of time).
603 macro_rules! profq_key {
604     ($tcx:expr, $key:expr) => {
605         if cfg!(debug_assertions) {
606             if $tcx.sess.profile_queries_and_keys() {
607                 Some(format!("{:?}", $key))
608             } else { None }
609         } else { None }
610     }
611 }
612
613 macro_rules! define_maps {
614     (<$tcx:tt>
615      $($(#[$attr:meta])*
616        [$($modifiers:tt)*] fn $name:ident: $node:ident($K:ty) -> $V:ty,)*) => {
617         define_map_struct! {
618             tcx: $tcx,
619             input: ($(([$($modifiers)*] [$($attr)*] [$name]))*)
620         }
621
622         impl<$tcx> Maps<$tcx> {
623             pub fn new(providers: IndexVec<CrateNum, Providers<$tcx>>)
624                        -> Self {
625                 Maps {
626                     providers,
627                     query_stack: RefCell::new(vec![]),
628                     $($name: RefCell::new(QueryMap::new())),*
629                 }
630             }
631         }
632
633         #[allow(bad_style)]
634         #[derive(Copy, Clone, Debug, PartialEq, Eq)]
635         pub enum Query<$tcx> {
636             $($(#[$attr])* $name($K)),*
637         }
638
639         #[allow(bad_style)]
640         #[derive(Clone, Debug, PartialEq, Eq)]
641         pub enum QueryMsg {
642             $($name(Option<String>)),*
643         }
644
645         impl<$tcx> Query<$tcx> {
646             pub fn describe(&self, tcx: TyCtxt) -> String {
647                 let (r, name) = match *self {
648                     $(Query::$name(key) => {
649                         (queries::$name::describe(tcx, key), stringify!($name))
650                     })*
651                 };
652                 if tcx.sess.verbose() {
653                     format!("{} [{}]", r, name)
654                 } else {
655                     r
656                 }
657             }
658         }
659
660         pub mod queries {
661             use std::marker::PhantomData;
662
663             $(#[allow(bad_style)]
664             pub struct $name<$tcx> {
665                 data: PhantomData<&$tcx ()>
666             })*
667         }
668
669         $(impl<$tcx> QueryConfig for queries::$name<$tcx> {
670             type Key = $K;
671             type Value = $V;
672         }
673
674         impl<'a, $tcx, 'lcx> queries::$name<$tcx> {
675             #[allow(unused)]
676             fn to_dep_node(tcx: TyCtxt<'a, $tcx, 'lcx>, key: &$K) -> DepNode {
677                 use dep_graph::DepConstructor::*;
678
679                 DepNode::new(tcx, $node(*key))
680             }
681
682             fn try_get_with<F, R>(tcx: TyCtxt<'a, $tcx, 'lcx>,
683                                   mut span: Span,
684                                   key: $K,
685                                   f: F)
686                                   -> Result<R, CycleError<'a, $tcx>>
687                 where F: FnOnce(&$V) -> R
688             {
689                 debug!("ty::queries::{}::try_get_with(key={:?}, span={:?})",
690                        stringify!($name),
691                        key,
692                        span);
693
694                 profq_msg!(tcx,
695                     ProfileQueriesMsg::QueryBegin(
696                         span.clone(),
697                         QueryMsg::$name(profq_key!(tcx, key))
698                     )
699                 );
700
701                 if let Some(value) = tcx.maps.$name.borrow().map.get(&key) {
702                     if let Some(ref d) = value.diagnostics {
703                         if !d.emitted_diagnostics.get() {
704                             d.emitted_diagnostics.set(true);
705                             let handle = tcx.sess.diagnostic();
706                             for diagnostic in d.diagnostics.iter() {
707                                 DiagnosticBuilder::new_diagnostic(handle, diagnostic.clone())
708                                     .emit();
709                             }
710                         }
711                     }
712                     profq_msg!(tcx, ProfileQueriesMsg::CacheHit);
713                     tcx.dep_graph.read_index(value.index);
714                     return Ok(f(&value.value));
715                 }
716                 // else, we are going to run the provider:
717                 profq_msg!(tcx, ProfileQueriesMsg::ProviderBegin);
718
719                 // FIXME(eddyb) Get more valid Span's on queries.
720                 // def_span guard is necessary to prevent a recursive loop,
721                 // default_span calls def_span query internally.
722                 if span == DUMMY_SP && stringify!($name) != "def_span" {
723                     span = key.default_span(tcx)
724                 }
725
726                 let res = tcx.cycle_check(span, Query::$name(key), || {
727                     let dep_node = Self::to_dep_node(tcx, &key);
728
729                     tcx.sess.diagnostic().track_diagnostics(|| {
730                         if dep_node.kind.is_anon() {
731                             tcx.dep_graph.with_anon_task(dep_node.kind, || {
732                                 let provider = tcx.maps.providers[key.map_crate()].$name;
733                                 provider(tcx.global_tcx(), key)
734                             })
735                         } else {
736                             fn run_provider<'a, 'tcx, 'lcx>(tcx: TyCtxt<'a, 'tcx, 'lcx>,
737                                                             key: $K)
738                                                             -> $V {
739                                 let provider = tcx.maps.providers[key.map_crate()].$name;
740                                 provider(tcx.global_tcx(), key)
741                             }
742
743                             tcx.dep_graph.with_task(dep_node, tcx, key, run_provider)
744                         }
745                     })
746                 })?;
747                 profq_msg!(tcx, ProfileQueriesMsg::ProviderEnd);
748                 let ((result, dep_node_index), diagnostics) = res;
749
750                 tcx.dep_graph.read_index(dep_node_index);
751
752                 let value = QueryValue {
753                     value: result,
754                     index: dep_node_index,
755                     diagnostics: if diagnostics.len() == 0 {
756                         None
757                     } else {
758                         Some(Box::new(QueryDiagnostics {
759                             diagnostics,
760                             emitted_diagnostics: Cell::new(true),
761                         }))
762                     },
763                 };
764
765                 Ok(f(&tcx.maps
766                          .$name
767                          .borrow_mut()
768                          .map
769                          .entry(key)
770                          .or_insert(value)
771                          .value))
772             }
773
774             pub fn try_get(tcx: TyCtxt<'a, $tcx, 'lcx>, span: Span, key: $K)
775                            -> Result<$V, DiagnosticBuilder<'a>> {
776                 match Self::try_get_with(tcx, span, key, Clone::clone) {
777                     Ok(e) => Ok(e),
778                     Err(e) => Err(tcx.report_cycle(e)),
779                 }
780             }
781
782             pub fn force(tcx: TyCtxt<'a, $tcx, 'lcx>, span: Span, key: $K) {
783                 // Ignore dependencies, since we not reading the computed value
784                 let _task = tcx.dep_graph.in_ignore();
785
786                 match Self::try_get_with(tcx, span, key, |_| ()) {
787                     Ok(()) => {}
788                     Err(e) => tcx.report_cycle(e).emit(),
789                 }
790             }
791         })*
792
793         #[derive(Copy, Clone)]
794         pub struct TyCtxtAt<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
795             pub tcx: TyCtxt<'a, 'gcx, 'tcx>,
796             pub span: Span,
797         }
798
799         impl<'a, 'gcx, 'tcx> Deref for TyCtxtAt<'a, 'gcx, 'tcx> {
800             type Target = TyCtxt<'a, 'gcx, 'tcx>;
801             fn deref(&self) -> &Self::Target {
802                 &self.tcx
803             }
804         }
805
806         impl<'a, $tcx, 'lcx> TyCtxt<'a, $tcx, 'lcx> {
807             /// Return a transparent wrapper for `TyCtxt` which uses
808             /// `span` as the location of queries performed through it.
809             pub fn at(self, span: Span) -> TyCtxtAt<'a, $tcx, 'lcx> {
810                 TyCtxtAt {
811                     tcx: self,
812                     span
813                 }
814             }
815
816             $($(#[$attr])*
817             pub fn $name(self, key: $K) -> $V {
818                 self.at(DUMMY_SP).$name(key)
819             })*
820         }
821
822         impl<'a, $tcx, 'lcx> TyCtxtAt<'a, $tcx, 'lcx> {
823             $($(#[$attr])*
824             pub fn $name(self, key: $K) -> $V {
825                 queries::$name::try_get(self.tcx, self.span, key).unwrap_or_else(|mut e| {
826                     e.emit();
827                     Value::from_cycle_error(self.global_tcx())
828                 })
829             })*
830         }
831
832         define_provider_struct! {
833             tcx: $tcx,
834             input: ($(([$($modifiers)*] [$name] [$K] [$V]))*),
835             output: ()
836         }
837
838         impl<$tcx> Copy for Providers<$tcx> {}
839         impl<$tcx> Clone for Providers<$tcx> {
840             fn clone(&self) -> Self { *self }
841         }
842     }
843 }
844
845 macro_rules! define_map_struct {
846     // Initial state
847     (tcx: $tcx:tt,
848      input: $input:tt) => {
849         define_map_struct! {
850             tcx: $tcx,
851             input: $input,
852             output: ()
853         }
854     };
855
856     // Final output
857     (tcx: $tcx:tt,
858      input: (),
859      output: ($($output:tt)*)) => {
860         pub struct Maps<$tcx> {
861             providers: IndexVec<CrateNum, Providers<$tcx>>,
862             query_stack: RefCell<Vec<(Span, Query<$tcx>)>>,
863             $($output)*
864         }
865     };
866
867     // Field recognized and ready to shift into the output
868     (tcx: $tcx:tt,
869      ready: ([$($pub:tt)*] [$($attr:tt)*] [$name:ident]),
870      input: $input:tt,
871      output: ($($output:tt)*)) => {
872         define_map_struct! {
873             tcx: $tcx,
874             input: $input,
875             output: ($($output)*
876                      $(#[$attr])* $($pub)* $name: RefCell<QueryMap<queries::$name<$tcx>>>,)
877         }
878     };
879
880     // No modifiers left? This is a private item.
881     (tcx: $tcx:tt,
882      input: (([] $attrs:tt $name:tt) $($input:tt)*),
883      output: $output:tt) => {
884         define_map_struct! {
885             tcx: $tcx,
886             ready: ([] $attrs $name),
887             input: ($($input)*),
888             output: $output
889         }
890     };
891
892     // Skip other modifiers
893     (tcx: $tcx:tt,
894      input: (([$other_modifier:tt $($modifiers:tt)*] $($fields:tt)*) $($input:tt)*),
895      output: $output:tt) => {
896         define_map_struct! {
897             tcx: $tcx,
898             input: (([$($modifiers)*] $($fields)*) $($input)*),
899             output: $output
900         }
901     };
902 }
903
904 macro_rules! define_provider_struct {
905     // Initial state:
906     (tcx: $tcx:tt, input: $input:tt) => {
907         define_provider_struct! {
908             tcx: $tcx,
909             input: $input,
910             output: ()
911         }
912     };
913
914     // Final state:
915     (tcx: $tcx:tt,
916      input: (),
917      output: ($(([$name:ident] [$K:ty] [$R:ty]))*)) => {
918         pub struct Providers<$tcx> {
919             $(pub $name: for<'a> fn(TyCtxt<'a, $tcx, $tcx>, $K) -> $R,)*
920         }
921
922         impl<$tcx> Default for Providers<$tcx> {
923             fn default() -> Self {
924                 $(fn $name<'a, $tcx>(_: TyCtxt<'a, $tcx, $tcx>, key: $K) -> $R {
925                     bug!("tcx.maps.{}({:?}) unsupported by its crate",
926                          stringify!($name), key);
927                 })*
928                 Providers { $($name),* }
929             }
930         }
931     };
932
933     // Something ready to shift:
934     (tcx: $tcx:tt,
935      ready: ($name:tt $K:tt $V:tt),
936      input: $input:tt,
937      output: ($($output:tt)*)) => {
938         define_provider_struct! {
939             tcx: $tcx,
940             input: $input,
941             output: ($($output)* ($name $K $V))
942         }
943     };
944
945     // Regular queries produce a `V` only.
946     (tcx: $tcx:tt,
947      input: (([] $name:tt $K:tt $V:tt) $($input:tt)*),
948      output: $output:tt) => {
949         define_provider_struct! {
950             tcx: $tcx,
951             ready: ($name $K $V),
952             input: ($($input)*),
953             output: $output
954         }
955     };
956
957     // Skip modifiers.
958     (tcx: $tcx:tt,
959      input: (([$other_modifier:tt $($modifiers:tt)*] $($fields:tt)*) $($input:tt)*),
960      output: $output:tt) => {
961         define_provider_struct! {
962             tcx: $tcx,
963             input: (([$($modifiers)*] $($fields)*) $($input)*),
964             output: $output
965         }
966     };
967 }
968
969 // Each of these maps also corresponds to a method on a
970 // `Provider` trait for requesting a value of that type,
971 // and a method on `Maps` itself for doing that in a
972 // a way that memoizes and does dep-graph tracking,
973 // wrapping around the actual chain of providers that
974 // the driver creates (using several `rustc_*` crates).
975 define_maps! { <'tcx>
976     /// Records the type of every item.
977     [] fn type_of: TypeOfItem(DefId) -> Ty<'tcx>,
978
979     /// Maps from the def-id of an item (trait/struct/enum/fn) to its
980     /// associated generics and predicates.
981     [] fn generics_of: GenericsOfItem(DefId) -> &'tcx ty::Generics,
982     [] fn predicates_of: PredicatesOfItem(DefId) -> ty::GenericPredicates<'tcx>,
983
984     /// Maps from the def-id of a trait to the list of
985     /// super-predicates. This is a subset of the full list of
986     /// predicates. We store these in a separate map because we must
987     /// evaluate them even during type conversion, often before the
988     /// full predicates are available (note that supertraits have
989     /// additional acyclicity requirements).
990     [] fn super_predicates_of: SuperPredicatesOfItem(DefId) -> ty::GenericPredicates<'tcx>,
991
992     /// To avoid cycles within the predicates of a single item we compute
993     /// per-type-parameter predicates for resolving `T::AssocTy`.
994     [] fn type_param_predicates: type_param_predicates((DefId, DefId))
995         -> ty::GenericPredicates<'tcx>,
996
997     [] fn trait_def: TraitDefOfItem(DefId) -> &'tcx ty::TraitDef,
998     [] fn adt_def: AdtDefOfItem(DefId) -> &'tcx ty::AdtDef,
999     [] fn adt_destructor: AdtDestructor(DefId) -> Option<ty::Destructor>,
1000     [] fn adt_sized_constraint: SizedConstraint(DefId) -> &'tcx [Ty<'tcx>],
1001     [] fn adt_dtorck_constraint: DtorckConstraint(DefId) -> ty::DtorckConstraint<'tcx>,
1002
1003     /// True if this is a const fn
1004     [] fn is_const_fn: IsConstFn(DefId) -> bool,
1005
1006     /// True if this is a foreign item (i.e., linked via `extern { ... }`).
1007     [] fn is_foreign_item: IsForeignItem(DefId) -> bool,
1008
1009     /// True if this is a default impl (aka impl Foo for ..)
1010     [] fn is_default_impl: IsDefaultImpl(DefId) -> bool,
1011
1012     /// Get a map with the variance of every item; use `item_variance`
1013     /// instead.
1014     [] fn crate_variances: crate_variances(CrateNum) -> Rc<ty::CrateVariancesMap>,
1015
1016     /// Maps from def-id of a type or region parameter to its
1017     /// (inferred) variance.
1018     [] fn variances_of: ItemVariances(DefId) -> Rc<Vec<ty::Variance>>,
1019
1020     /// Maps from an impl/trait def-id to a list of the def-ids of its items
1021     [] fn associated_item_def_ids: AssociatedItemDefIds(DefId) -> Rc<Vec<DefId>>,
1022
1023     /// Maps from a trait item to the trait item "descriptor"
1024     [] fn associated_item: AssociatedItems(DefId) -> ty::AssociatedItem,
1025
1026     [] fn impl_trait_ref: ImplTraitRef(DefId) -> Option<ty::TraitRef<'tcx>>,
1027     [] fn impl_polarity: ImplPolarity(DefId) -> hir::ImplPolarity,
1028
1029     /// Maps a DefId of a type to a list of its inherent impls.
1030     /// Contains implementations of methods that are inherent to a type.
1031     /// Methods in these implementations don't need to be exported.
1032     [] fn inherent_impls: InherentImpls(DefId) -> Rc<Vec<DefId>>,
1033
1034     /// Set of all the def-ids in this crate that have MIR associated with
1035     /// them. This includes all the body owners, but also things like struct
1036     /// constructors.
1037     [] fn mir_keys: mir_keys(CrateNum) -> Rc<DefIdSet>,
1038
1039     /// Maps DefId's that have an associated Mir to the result
1040     /// of the MIR qualify_consts pass. The actual meaning of
1041     /// the value isn't known except to the pass itself.
1042     [] fn mir_const_qualif: MirConstQualif(DefId) -> (u8, Rc<IdxSetBuf<mir::Local>>),
1043
1044     /// Fetch the MIR for a given def-id up till the point where it is
1045     /// ready for const evaluation.
1046     ///
1047     /// See the README for the `mir` module for details.
1048     [] fn mir_const: MirConst(DefId) -> &'tcx Steal<mir::Mir<'tcx>>,
1049
1050     [] fn mir_validated: MirValidated(DefId) -> &'tcx Steal<mir::Mir<'tcx>>,
1051
1052     /// MIR after our optimization passes have run. This is MIR that is ready
1053     /// for trans. This is also the only query that can fetch non-local MIR, at present.
1054     [] fn optimized_mir: MirOptimized(DefId) -> &'tcx mir::Mir<'tcx>,
1055
1056     /// Type of each closure. The def ID is the ID of the
1057     /// expression defining the closure.
1058     [] fn closure_kind: ClosureKind(DefId) -> ty::ClosureKind,
1059
1060     /// The signature of functions and closures.
1061     [] fn fn_sig: FnSignature(DefId) -> ty::PolyFnSig<'tcx>,
1062
1063     /// Records the signature of each generator. The def ID is the ID of the
1064     /// expression defining the closure.
1065     [] fn generator_sig: GenSignature(DefId) -> Option<ty::PolyGenSig<'tcx>>,
1066
1067     /// Caches CoerceUnsized kinds for impls on custom types.
1068     [] fn coerce_unsized_info: CoerceUnsizedInfo(DefId)
1069         -> ty::adjustment::CoerceUnsizedInfo,
1070
1071     [] fn typeck_item_bodies: typeck_item_bodies_dep_node(CrateNum) -> CompileResult,
1072
1073     [] fn typeck_tables_of: TypeckTables(DefId) -> &'tcx ty::TypeckTables<'tcx>,
1074
1075     [] fn has_typeck_tables: HasTypeckTables(DefId) -> bool,
1076
1077     [] fn coherent_trait: coherent_trait_dep_node((CrateNum, DefId)) -> (),
1078
1079     [] fn borrowck: BorrowCheck(DefId) -> (),
1080     // FIXME: shouldn't this return a `Result<(), BorrowckErrors>` instead?
1081     [] fn mir_borrowck: MirBorrowCheck(DefId) -> (),
1082
1083     /// Gets a complete map from all types to their inherent impls.
1084     /// Not meant to be used directly outside of coherence.
1085     /// (Defined only for LOCAL_CRATE)
1086     [] fn crate_inherent_impls: crate_inherent_impls_dep_node(CrateNum) -> CrateInherentImpls,
1087
1088     /// Checks all types in the krate for overlap in their inherent impls. Reports errors.
1089     /// Not meant to be used directly outside of coherence.
1090     /// (Defined only for LOCAL_CRATE)
1091     [] fn crate_inherent_impls_overlap_check: inherent_impls_overlap_check_dep_node(CrateNum) -> (),
1092
1093     /// Results of evaluating const items or constants embedded in
1094     /// other items (such as enum variant explicit discriminants).
1095     [] fn const_eval: const_eval_dep_node(ty::ParamEnvAnd<'tcx, (DefId, &'tcx Substs<'tcx>)>)
1096         -> const_val::EvalResult<'tcx>,
1097
1098     /// Performs the privacy check and computes "access levels".
1099     [] fn privacy_access_levels: PrivacyAccessLevels(CrateNum) -> Rc<AccessLevels>,
1100
1101     [] fn reachable_set: reachability_dep_node(CrateNum) -> Rc<NodeSet>,
1102
1103     /// Per-body `region::ScopeTree`. The `DefId` should be the owner-def-id for the body;
1104     /// in the case of closures, this will be redirected to the enclosing function.
1105     [] fn region_scope_tree: RegionScopeTree(DefId) -> Rc<region::ScopeTree>,
1106
1107     [] fn mir_shims: mir_shim_dep_node(ty::InstanceDef<'tcx>) -> &'tcx mir::Mir<'tcx>,
1108
1109     [] fn def_symbol_name: SymbolName(DefId) -> ty::SymbolName,
1110     [] fn symbol_name: symbol_name_dep_node(ty::Instance<'tcx>) -> ty::SymbolName,
1111
1112     [] fn describe_def: DescribeDef(DefId) -> Option<Def>,
1113     [] fn def_span: DefSpan(DefId) -> Span,
1114     [] fn stability: Stability(DefId) -> Option<attr::Stability>,
1115     [] fn deprecation: Deprecation(DefId) -> Option<attr::Deprecation>,
1116     [] fn item_attrs: ItemAttrs(DefId) -> Rc<[ast::Attribute]>,
1117     [] fn fn_arg_names: FnArgNames(DefId) -> Vec<ast::Name>,
1118     [] fn impl_parent: ImplParent(DefId) -> Option<DefId>,
1119     [] fn trait_of_item: TraitOfItem(DefId) -> Option<DefId>,
1120     [] fn is_exported_symbol: IsExportedSymbol(DefId) -> bool,
1121     [] fn item_body_nested_bodies: ItemBodyNestedBodies(DefId)
1122         -> Rc<BTreeMap<hir::BodyId, hir::Body>>,
1123     [] fn const_is_rvalue_promotable_to_static: ConstIsRvaluePromotableToStatic(DefId) -> bool,
1124     [] fn is_mir_available: IsMirAvailable(DefId) -> bool,
1125
1126     [] fn trait_impls_of: TraitImpls(DefId) -> Rc<ty::trait_def::TraitImpls>,
1127     [] fn specialization_graph_of: SpecializationGraph(DefId) -> Rc<specialization_graph::Graph>,
1128     [] fn is_object_safe: ObjectSafety(DefId) -> bool,
1129
1130     // Get the ParameterEnvironment for a given item; this environment
1131     // will be in "user-facing" mode, meaning that it is suitabe for
1132     // type-checking etc, and it does not normalize specializable
1133     // associated types. This is almost always what you want,
1134     // unless you are doing MIR optimizations, in which case you
1135     // might want to use `reveal_all()` method to change modes.
1136     [] fn param_env: ParamEnv(DefId) -> ty::ParamEnv<'tcx>,
1137
1138     // Trait selection queries. These are best used by invoking `ty.moves_by_default()`,
1139     // `ty.is_copy()`, etc, since that will prune the environment where possible.
1140     [] fn is_copy_raw: is_copy_dep_node(ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool,
1141     [] fn is_sized_raw: is_sized_dep_node(ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool,
1142     [] fn is_freeze_raw: is_freeze_dep_node(ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool,
1143     [] fn needs_drop_raw: needs_drop_dep_node(ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool,
1144     [] fn layout_raw: layout_dep_node(ty::ParamEnvAnd<'tcx, Ty<'tcx>>)
1145                                   -> Result<&'tcx Layout, LayoutError<'tcx>>,
1146
1147     [] fn dylib_dependency_formats: DylibDepFormats(CrateNum)
1148                                     -> Rc<Vec<(CrateNum, LinkagePreference)>>,
1149
1150     [] fn is_panic_runtime: IsPanicRuntime(CrateNum) -> bool,
1151     [] fn is_compiler_builtins: IsCompilerBuiltins(CrateNum) -> bool,
1152     [] fn has_global_allocator: HasGlobalAllocator(CrateNum) -> bool,
1153     [] fn is_sanitizer_runtime: IsSanitizerRuntime(CrateNum) -> bool,
1154     [] fn is_profiler_runtime: IsProfilerRuntime(CrateNum) -> bool,
1155     [] fn panic_strategy: GetPanicStrategy(CrateNum) -> PanicStrategy,
1156     [] fn is_no_builtins: IsNoBuiltins(CrateNum) -> bool,
1157
1158     [] fn extern_crate: ExternCrate(DefId) -> Rc<Option<ExternCrate>>,
1159
1160     [] fn specializes: specializes_node((DefId, DefId)) -> bool,
1161     [] fn in_scope_traits: InScopeTraits(HirId) -> Option<Rc<Vec<TraitCandidate>>>,
1162     [] fn module_exports: ModuleExports(HirId) -> Option<Rc<Vec<Export>>>,
1163     [] fn lint_levels: lint_levels_node(CrateNum) -> Rc<lint::LintLevelMap>,
1164 }
1165
1166 fn type_param_predicates<'tcx>((item_id, param_id): (DefId, DefId)) -> DepConstructor<'tcx> {
1167     DepConstructor::TypeParamPredicates {
1168         item_id,
1169         param_id
1170     }
1171 }
1172
1173 fn coherent_trait_dep_node<'tcx>((_, def_id): (CrateNum, DefId)) -> DepConstructor<'tcx> {
1174     DepConstructor::CoherenceCheckTrait(def_id)
1175 }
1176
1177 fn crate_inherent_impls_dep_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
1178     DepConstructor::Coherence
1179 }
1180
1181 fn inherent_impls_overlap_check_dep_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
1182     DepConstructor::CoherenceInherentImplOverlapCheck
1183 }
1184
1185 fn reachability_dep_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
1186     DepConstructor::Reachability
1187 }
1188
1189 fn mir_shim_dep_node<'tcx>(instance_def: ty::InstanceDef<'tcx>) -> DepConstructor<'tcx> {
1190     DepConstructor::MirShim {
1191         instance_def
1192     }
1193 }
1194
1195 fn symbol_name_dep_node<'tcx>(instance: ty::Instance<'tcx>) -> DepConstructor<'tcx> {
1196     DepConstructor::InstanceSymbolName { instance }
1197 }
1198
1199 fn typeck_item_bodies_dep_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
1200     DepConstructor::TypeckBodiesKrate
1201 }
1202
1203 fn const_eval_dep_node<'tcx>(_: ty::ParamEnvAnd<'tcx, (DefId, &'tcx Substs<'tcx>)>)
1204                              -> DepConstructor<'tcx> {
1205     DepConstructor::ConstEval
1206 }
1207
1208 fn mir_keys<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
1209     DepConstructor::MirKeys
1210 }
1211
1212 fn crate_variances<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
1213     DepConstructor::CrateVariances
1214 }
1215
1216 fn is_copy_dep_node<'tcx>(_: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> DepConstructor<'tcx> {
1217     DepConstructor::IsCopy
1218 }
1219
1220 fn is_sized_dep_node<'tcx>(_: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> DepConstructor<'tcx> {
1221     DepConstructor::IsSized
1222 }
1223
1224 fn is_freeze_dep_node<'tcx>(_: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> DepConstructor<'tcx> {
1225     DepConstructor::IsFreeze
1226 }
1227
1228 fn needs_drop_dep_node<'tcx>(_: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> DepConstructor<'tcx> {
1229     DepConstructor::NeedsDrop
1230 }
1231
1232 fn layout_dep_node<'tcx>(_: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> DepConstructor<'tcx> {
1233     DepConstructor::Layout
1234 }
1235
1236 fn lint_levels_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
1237     DepConstructor::LintLevels
1238 }
1239
1240 fn specializes_node<'tcx>((a, b): (DefId, DefId)) -> DepConstructor<'tcx> {
1241     DepConstructor::Specializes { impl1: a, impl2: b }
1242 }