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