-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace QueryStruct
with arrays local to rustc_query_impl
#111808
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -81,8 +81,8 @@ impl QueryContext for QueryCtxt<'_> { | |||||
fn try_collect_active_jobs(self) -> Option<QueryMap<DepKind>> { | ||||||
let mut jobs = QueryMap::default(); | ||||||
|
||||||
for query in &self.query_system.fns.query_structs { | ||||||
(query.try_collect_active_jobs)(self.tcx, &mut jobs); | ||||||
for collect in super::TRY_COLLECT_ACTIVE_JOBS.iter() { | ||||||
collect(self.tcx, &mut jobs); | ||||||
} | ||||||
|
||||||
Some(jobs) | ||||||
|
@@ -183,10 +183,8 @@ pub(super) fn encode_all_query_results<'tcx>( | |||||
encoder: &mut CacheEncoder<'_, 'tcx>, | ||||||
query_result_index: &mut EncodedDepNodeIndex, | ||||||
) { | ||||||
for query in &tcx.query_system.fns.query_structs { | ||||||
if let Some(encode) = query.encode_query_results { | ||||||
encode(tcx, encoder, query_result_index); | ||||||
} | ||||||
for encode in super::ENCODE_QUERY_RESULTS.iter().copied().filter_map(|e| e) { | ||||||
encode(tcx, encoder, query_result_index); | ||||||
} | ||||||
} | ||||||
|
||||||
|
@@ -476,6 +474,16 @@ where | |||||
} | ||||||
} | ||||||
|
||||||
macro_rules! item_if_cached { | ||||||
([] $tokens:tt) => {}; | ||||||
([(cache) $($rest:tt)*] { $($tokens:tt)* }) => { | ||||||
$($tokens)* | ||||||
}; | ||||||
([$other:tt $($modifiers:tt)*] $tokens:tt) => { | ||||||
item_if_cached! { [$($modifiers)*] $tokens } | ||||||
}; | ||||||
} | ||||||
|
||||||
macro_rules! expand_if_cached { | ||||||
([], $tokens:expr) => {{ | ||||||
None | ||||||
|
@@ -633,6 +641,43 @@ macro_rules! define_queries { | |||||
restore::<queries::$name::Value<'tcx>>(value) | ||||||
} | ||||||
} | ||||||
|
||||||
pub fn try_collect_active_jobs<'tcx>(tcx: TyCtxt<'tcx>, qmap: &mut QueryMap<DepKind>) { | ||||||
let make_query = |tcx, key| { | ||||||
let kind = rustc_middle::dep_graph::DepKind::$name; | ||||||
let name = stringify!($name); | ||||||
$crate::plumbing::create_query_frame(tcx, rustc_middle::query::descs::$name, key, kind, name) | ||||||
}; | ||||||
tcx.query_system.states.$name.try_collect_active_jobs( | ||||||
tcx, | ||||||
make_query, | ||||||
qmap, | ||||||
).unwrap(); | ||||||
} | ||||||
|
||||||
pub fn alloc_self_profile_query_strings<'tcx>(tcx: TyCtxt<'tcx>, string_cache: &mut QueryKeyStringCache) { | ||||||
$crate::profiling_support::alloc_self_profile_query_strings_for_query_cache( | ||||||
tcx, | ||||||
stringify!($name), | ||||||
&tcx.query_system.caches.$name, | ||||||
string_cache, | ||||||
) | ||||||
} | ||||||
|
||||||
item_if_cached! { [$($modifiers)*] { | ||||||
pub fn encode_query_results<'tcx>( | ||||||
tcx: TyCtxt<'tcx>, | ||||||
encoder: &mut CacheEncoder<'_, 'tcx>, | ||||||
query_result_index: &mut EncodedDepNodeIndex | ||||||
) { | ||||||
$crate::plumbing::encode_query_results::<query_impl::$name::QueryType<'tcx>>( | ||||||
query_impl::$name::QueryType::config(tcx), | ||||||
QueryCtxt::new(tcx), | ||||||
encoder, | ||||||
query_result_index, | ||||||
) | ||||||
} | ||||||
}} | ||||||
})*} | ||||||
|
||||||
pub(crate) fn engine(incremental: bool) -> QueryEngine { | ||||||
|
@@ -655,6 +700,23 @@ macro_rules! define_queries { | |||||
} | ||||||
} | ||||||
|
||||||
// These arrays are used for iteration and can't be indexed by `DepKind`. | ||||||
|
||||||
const TRY_COLLECT_ACTIVE_JOBS: &[for<'tcx> fn(TyCtxt<'tcx>, &mut QueryMap<DepKind>)] = | ||||||
&[$(query_impl::$name::try_collect_active_jobs),*]; | ||||||
|
||||||
const ALLOC_SELF_PROFILE_QUERY_STRINGS: &[ | ||||||
for<'tcx> fn(TyCtxt<'tcx>, &mut QueryKeyStringCache) | ||||||
] = &[$(query_impl::$name::alloc_self_profile_query_strings),*]; | ||||||
|
||||||
const ENCODE_QUERY_RESULTS: &[ | ||||||
Option<for<'tcx> fn( | ||||||
TyCtxt<'tcx>, | ||||||
&mut CacheEncoder<'_, 'tcx>, | ||||||
&mut EncodedDepNodeIndex) | ||||||
> | ||||||
] = &[$(expand_if_cached!([$($modifiers)*], query_impl::$name::encode_query_results)),*]; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can this use
Suggested change
This will allow to remove the option. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The macro has to expand to a single expression, so it's not quite that simple. |
||||||
|
||||||
#[allow(nonstandard_style)] | ||||||
mod query_callbacks { | ||||||
use super::*; | ||||||
|
@@ -720,64 +782,6 @@ macro_rules! define_queries { | |||||
})* | ||||||
} | ||||||
|
||||||
mod query_structs { | ||||||
use super::*; | ||||||
use rustc_middle::query::plumbing::{QueryKeyStringCache, QueryStruct}; | ||||||
use rustc_middle::dep_graph::DepKind; | ||||||
use crate::QueryConfigRestored; | ||||||
|
||||||
pub(super) const fn dummy_query_struct<'tcx>() -> QueryStruct<'tcx> { | ||||||
fn noop_try_collect_active_jobs(_: TyCtxt<'_>, _: &mut QueryMap<DepKind>) -> Option<()> { | ||||||
None | ||||||
} | ||||||
fn noop_alloc_self_profile_query_strings(_: TyCtxt<'_>, _: &mut QueryKeyStringCache) {} | ||||||
|
||||||
QueryStruct { | ||||||
try_collect_active_jobs: noop_try_collect_active_jobs, | ||||||
alloc_self_profile_query_strings: noop_alloc_self_profile_query_strings, | ||||||
encode_query_results: None, | ||||||
} | ||||||
} | ||||||
|
||||||
pub(super) use dummy_query_struct as Null; | ||||||
pub(super) use dummy_query_struct as Red; | ||||||
pub(super) use dummy_query_struct as TraitSelect; | ||||||
pub(super) use dummy_query_struct as CompileCodegenUnit; | ||||||
pub(super) use dummy_query_struct as CompileMonoItem; | ||||||
|
||||||
$( | ||||||
pub(super) const fn $name<'tcx>() -> QueryStruct<'tcx> { QueryStruct { | ||||||
try_collect_active_jobs: |tcx, qmap| { | ||||||
let make_query = |tcx, key| { | ||||||
let kind = rustc_middle::dep_graph::DepKind::$name; | ||||||
let name = stringify!($name); | ||||||
$crate::plumbing::create_query_frame(tcx, rustc_middle::query::descs::$name, key, kind, name) | ||||||
}; | ||||||
tcx.query_system.states.$name.try_collect_active_jobs( | ||||||
tcx, | ||||||
make_query, | ||||||
qmap, | ||||||
) | ||||||
}, | ||||||
alloc_self_profile_query_strings: |tcx, string_cache| { | ||||||
$crate::profiling_support::alloc_self_profile_query_strings_for_query_cache( | ||||||
tcx, | ||||||
stringify!($name), | ||||||
&tcx.query_system.caches.$name, | ||||||
string_cache, | ||||||
) | ||||||
}, | ||||||
encode_query_results: expand_if_cached!([$($modifiers)*], |tcx, encoder, query_result_index| | ||||||
$crate::plumbing::encode_query_results::<query_impl::$name::QueryType<'tcx>>( | ||||||
query_impl::$name::QueryType::config(tcx), | ||||||
QueryCtxt::new(tcx), | ||||||
encoder, | ||||||
query_result_index, | ||||||
) | ||||||
), | ||||||
}})* | ||||||
} | ||||||
|
||||||
pub fn query_callbacks<'tcx>(arena: &'tcx Arena<'tcx>) -> &'tcx [DepKindStruct<'tcx>] { | ||||||
arena.alloc_from_iter(make_dep_kind_array!(query_callbacks)) | ||||||
} | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add a comment saying that those arrays are not indexed per
DepKind
, so should only be used for iteration?