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