Auto merge of #104940 - cjgillot:query-feed-simple, r=oli-obk
Allow to feed a value in another query's cache Restricted version of https://github.com/rust-lang/rust/pull/96840 A query can create new definitions. If those definitions are created after HIR lowering, they do not appear in the initial HIR map, and information for them cannot be provided in the normal pull-based way. In order to make those definitions useful, we allow to feed values as query results for the newly created definition. The API is as follows: ```rust let feed = tcx.create_def(<parent def id>, <DefPathData>); // `feed` is a TyCtxtFeed<'tcx>. // Access the created definition. let def_id: LocalDefId = feed.def_id; // Assign `my_query(def_id) := my_value`. feed.my_query(my_value). ``` This PR keeps the consistency checks introduced by https://github.com/rust-lang/rust/pull/96840, even if they are not reachable. This allows to extend the behaviour later without forgetting them. cc `@oli-obk` `@spastorino`
This commit is contained in:
commit
c97b539e40
11 changed files with 298 additions and 53 deletions
|
@ -252,6 +252,18 @@ macro_rules! depth_limit {
|
|||
};
|
||||
}
|
||||
|
||||
macro_rules! feedable {
|
||||
([]) => {{
|
||||
false
|
||||
}};
|
||||
([(feedable) $($rest:tt)*]) => {{
|
||||
true
|
||||
}};
|
||||
([$other:tt $($modifiers:tt)*]) => {
|
||||
feedable!([$($modifiers)*])
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! hash_result {
|
||||
([]) => {{
|
||||
Some(dep_graph::hash_result)
|
||||
|
@ -309,7 +321,7 @@ pub(crate) fn create_query_frame<
|
|||
ty::print::with_forced_impl_filename_line!(do_describe(tcx.tcx, key))
|
||||
);
|
||||
let description =
|
||||
if tcx.sess.verbose() { format!("{} [{}]", description, name) } else { description };
|
||||
if tcx.sess.verbose() { format!("{} [{:?}]", description, name) } else { description };
|
||||
let span = if kind == dep_graph::DepKind::def_span {
|
||||
// The `def_span` query is used to calculate `default_span`,
|
||||
// so exit to avoid infinite recursion.
|
||||
|
@ -491,6 +503,7 @@ macro_rules! define_queries {
|
|||
anon: is_anon!([$($modifiers)*]),
|
||||
eval_always: is_eval_always!([$($modifiers)*]),
|
||||
depth_limit: depth_limit!([$($modifiers)*]),
|
||||
feedable: feedable!([$($modifiers)*]),
|
||||
dep_kind: dep_graph::DepKind::$name,
|
||||
hash_result: hash_result!([$($modifiers)*]),
|
||||
handle_cycle_error: handle_cycle_error!([$($modifiers)*]),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue