-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #56462 - Zoxc:query-macro, r=oli-obk
Define queries using a proc macro cc @rust-lang/compiler
- Loading branch information
Showing
20 changed files
with
760 additions
and
320 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
use crate::ty::query::QueryDescription; | ||
use crate::ty::query::queries; | ||
use crate::ty::TyCtxt; | ||
use crate::ty; | ||
use crate::hir::def_id::CrateNum; | ||
use crate::dep_graph::SerializedDepNodeIndex; | ||
use std::borrow::Cow; | ||
|
||
// Each of these queries corresponds to a function pointer field in the | ||
// `Providers` struct for requesting a value of that type, and a method | ||
// on `tcx: TyCtxt` (and `tcx.at(span)`) for doing that request in a way | ||
// which memoizes and does dep-graph tracking, wrapping around the actual | ||
// `Providers` that the driver creates (using several `rustc_*` crates). | ||
// | ||
// The result type of each query must implement `Clone`, and additionally | ||
// `ty::query::values::Value`, which produces an appropriate placeholder | ||
// (error) value if the query resulted in a query cycle. | ||
// Queries marked with `fatal_cycle` do not need the latter implementation, | ||
// as they will raise an fatal error on query cycles instead. | ||
rustc_queries! { | ||
Other { | ||
/// Records the type of every item. | ||
query type_of(key: DefId) -> Ty<'tcx> { | ||
cache { key.is_local() } | ||
} | ||
|
||
/// Maps from the `DefId` of an item (trait/struct/enum/fn) to its | ||
/// associated generics. | ||
query generics_of(key: DefId) -> &'tcx ty::Generics { | ||
cache { key.is_local() } | ||
load_cached(tcx, id) { | ||
let generics: Option<ty::Generics> = tcx.queries.on_disk_cache | ||
.try_load_query_result(tcx, id); | ||
generics.map(|x| tcx.alloc_generics(x)) | ||
} | ||
} | ||
|
||
/// Maps from the `DefId` of an item (trait/struct/enum/fn) to the | ||
/// predicates (where-clauses) that must be proven true in order | ||
/// to reference it. This is almost always the "predicates query" | ||
/// that you want. | ||
/// | ||
/// `predicates_of` builds on `predicates_defined_on` -- in fact, | ||
/// it is almost always the same as that query, except for the | ||
/// case of traits. For traits, `predicates_of` contains | ||
/// an additional `Self: Trait<...>` predicate that users don't | ||
/// actually write. This reflects the fact that to invoke the | ||
/// trait (e.g., via `Default::default`) you must supply types | ||
/// that actually implement the trait. (However, this extra | ||
/// predicate gets in the way of some checks, which are intended | ||
/// to operate over only the actual where-clauses written by the | ||
/// user.) | ||
query predicates_of(_: DefId) -> Lrc<ty::GenericPredicates<'tcx>> {} | ||
|
||
query native_libraries(_: CrateNum) -> Lrc<Vec<NativeLibrary>> { | ||
desc { "looking up the native libraries of a linked crate" } | ||
} | ||
} | ||
|
||
Codegen { | ||
query is_panic_runtime(_: CrateNum) -> bool { | ||
fatal_cycle | ||
desc { "checking if the crate is_panic_runtime" } | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.