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