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