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