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