]> git.lizzy.rs Git - rust.git/blob - src/librustc/query/mod.rs
Improve some compiletest documentation
[rust.git] / src / librustc / query / mod.rs
1 use crate::ty::query::QueryDescription;
2 use crate::ty::query::queries;
3 use crate::ty::TyCtxt;
4 use crate::ty;
5 use crate::hir::def_id::CrateNum;
6 use crate::dep_graph::SerializedDepNodeIndex;
7 use std::borrow::Cow;
8
9 // Each of these queries corresponds to a function pointer field in the
10 // `Providers` struct for requesting a value of that type, and a method
11 // on `tcx: TyCtxt` (and `tcx.at(span)`) for doing that request in a way
12 // which memoizes and does dep-graph tracking, wrapping around the actual
13 // `Providers` that the driver creates (using several `rustc_*` crates).
14 //
15 // The result type of each query must implement `Clone`, and additionally
16 // `ty::query::values::Value`, which produces an appropriate placeholder
17 // (error) value if the query resulted in a query cycle.
18 // Queries marked with `fatal_cycle` do not need the latter implementation,
19 // as they will raise an fatal error on query cycles instead.
20 rustc_queries! {
21     Other {
22         /// Records the type of every item.
23         query type_of(key: DefId) -> Ty<'tcx> {
24             cache { key.is_local() }
25         }
26
27         /// Maps from the `DefId` of an item (trait/struct/enum/fn) to its
28         /// associated generics.
29         query generics_of(key: DefId) -> &'tcx ty::Generics {
30             cache { key.is_local() }
31             load_cached(tcx, id) {
32                 let generics: Option<ty::Generics> = tcx.queries.on_disk_cache
33                                                         .try_load_query_result(tcx, id);
34                 generics.map(|x| tcx.alloc_generics(x))
35             }
36         }
37
38         /// Maps from the `DefId` of an item (trait/struct/enum/fn) to the
39         /// predicates (where-clauses) that must be proven true in order
40         /// to reference it. This is almost always the "predicates query"
41         /// that you want.
42         ///
43         /// `predicates_of` builds on `predicates_defined_on` -- in fact,
44         /// it is almost always the same as that query, except for the
45         /// case of traits. For traits, `predicates_of` contains
46         /// an additional `Self: Trait<...>` predicate that users don't
47         /// actually write. This reflects the fact that to invoke the
48         /// trait (e.g., via `Default::default`) you must supply types
49         /// that actually implement the trait. (However, this extra
50         /// predicate gets in the way of some checks, which are intended
51         /// to operate over only the actual where-clauses written by the
52         /// user.)
53         query predicates_of(_: DefId) -> Lrc<ty::GenericPredicates<'tcx>> {}
54
55         query native_libraries(_: CrateNum) -> Lrc<Vec<NativeLibrary>> {
56             desc { "looking up the native libraries of a linked crate" }
57         }
58     }
59
60     Codegen {
61         query is_panic_runtime(_: CrateNum) -> bool {
62             fatal_cycle
63             desc { "checking if the crate is_panic_runtime" }
64         }
65     }
66 }