mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
Merge QueryEngine into QueryVTable.
`QueryEngine` is a struct with one function pointer per query. This commit removes it by moving each function pointer into the relevant query's vtable, which is already a collection of function pointers for that query. This makes things simpler.
This commit is contained in:
@@ -14,7 +14,7 @@
|
||||
use crate::dep_graph;
|
||||
use crate::dep_graph::{DepKind, DepNode, DepNodeIndex, SerializedDepNodeIndex};
|
||||
use crate::ich::StableHashingContext;
|
||||
use crate::queries::{ExternProviders, PerQueryVTables, Providers, QueryArenas, QueryEngine};
|
||||
use crate::queries::{ExternProviders, PerQueryVTables, Providers, QueryArenas};
|
||||
use crate::query::on_disk_cache::{CacheEncoder, EncodedDepNodeIndex, OnDiskCache};
|
||||
use crate::query::stack::{QueryStackDeferred, QueryStackFrame, QueryStackFrameExtra};
|
||||
use crate::query::{QueryCache, QueryInfo, QueryJob};
|
||||
@@ -157,6 +157,8 @@ pub struct QueryVTable<'tcx, C: QueryCache> {
|
||||
///
|
||||
/// Used when reporting query cycle errors and similar problems.
|
||||
pub description_fn: fn(TyCtxt<'tcx>, C::Key) -> String,
|
||||
|
||||
pub execute_query_fn: fn(TyCtxt<'tcx>, Span, C::Key, QueryMode) -> Option<C::Value>,
|
||||
}
|
||||
|
||||
impl<'tcx, C: QueryCache> fmt::Debug for QueryVTable<'tcx, C> {
|
||||
@@ -215,7 +217,6 @@ pub fn construct_dep_node(&self, tcx: TyCtxt<'tcx>, key: &C::Key) -> DepNode {
|
||||
}
|
||||
|
||||
pub struct QuerySystemFns {
|
||||
pub engine: QueryEngine,
|
||||
pub local_providers: Providers,
|
||||
pub extern_providers: ExternProviders,
|
||||
pub encode_query_results: for<'tcx> fn(
|
||||
@@ -509,7 +510,7 @@ pub fn $name(
|
||||
(crate::query::inner::query_ensure)
|
||||
)(
|
||||
self.tcx,
|
||||
self.tcx.query_system.fns.engine.$name,
|
||||
self.tcx.query_system.query_vtables.$name.execute_query_fn,
|
||||
&self.tcx.query_system.query_vtables.$name.cache,
|
||||
$crate::query::IntoQueryParam::into_query_param(key),
|
||||
$crate::query::EnsureMode::Ok,
|
||||
@@ -525,7 +526,7 @@ impl<'tcx> $crate::query::TyCtxtEnsureDone<'tcx> {
|
||||
pub fn $name(self, key: query_helper_param_ty!($($K)*)) {
|
||||
crate::query::inner::query_ensure(
|
||||
self.tcx,
|
||||
self.tcx.query_system.fns.engine.$name,
|
||||
self.tcx.query_system.query_vtables.$name.execute_query_fn,
|
||||
&self.tcx.query_system.query_vtables.$name.cache,
|
||||
$crate::query::IntoQueryParam::into_query_param(key),
|
||||
$crate::query::EnsureMode::Done,
|
||||
@@ -554,7 +555,7 @@ pub fn $name(self, key: query_helper_param_ty!($($K)*)) -> $V {
|
||||
|
||||
erase::restore_val::<$V>(inner::query_get_at(
|
||||
self.tcx,
|
||||
self.tcx.query_system.fns.engine.$name,
|
||||
self.tcx.query_system.query_vtables.$name.execute_query_fn,
|
||||
&self.tcx.query_system.query_vtables.$name.cache,
|
||||
self.span,
|
||||
$crate::query::IntoQueryParam::into_query_param(key),
|
||||
@@ -654,17 +655,6 @@ impl Copy for ExternProviders {}
|
||||
impl Clone for ExternProviders {
|
||||
fn clone(&self) -> Self { *self }
|
||||
}
|
||||
|
||||
pub struct QueryEngine {
|
||||
$(
|
||||
pub $name: for<'tcx> fn(
|
||||
TyCtxt<'tcx>,
|
||||
Span,
|
||||
$name::Key<'tcx>,
|
||||
$crate::query::QueryMode,
|
||||
) -> Option<$crate::query::erase::Erased<$V>>,
|
||||
)*
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
use rustc_data_structures::sync::AtomicU64;
|
||||
use rustc_middle::dep_graph;
|
||||
use rustc_middle::queries::{self, ExternProviders, Providers, QueryEngine};
|
||||
use rustc_middle::queries::{self, ExternProviders, Providers};
|
||||
use rustc_middle::query::on_disk_cache::{CacheEncoder, EncodedDepNodeIndex, OnDiskCache};
|
||||
use rustc_middle::query::plumbing::{QuerySystem, QuerySystemFns, QueryVTable};
|
||||
use rustc_middle::query::{AsLocalKey, QueryCache, QueryMode};
|
||||
@@ -57,10 +57,9 @@ pub fn query_system<'tcx>(
|
||||
) -> QuerySystem<'tcx> {
|
||||
QuerySystem {
|
||||
arenas: Default::default(),
|
||||
query_vtables: make_query_vtables(),
|
||||
query_vtables: make_query_vtables(incremental),
|
||||
on_disk_cache,
|
||||
fns: QuerySystemFns {
|
||||
engine: engine(incremental),
|
||||
local_providers,
|
||||
extern_providers,
|
||||
encode_query_results: encode_all_query_results,
|
||||
|
||||
@@ -548,7 +548,7 @@ pub(crate) fn __rust_begin_short_backtrace<'tcx>(
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn make_query_vtable<'tcx>()
|
||||
pub(crate) fn make_query_vtable<'tcx>(incremental: bool)
|
||||
-> QueryVTable<'tcx, queries::$name::Storage<'tcx>>
|
||||
{
|
||||
QueryVTable {
|
||||
@@ -603,6 +603,11 @@ pub(crate) fn make_query_vtable<'tcx>()
|
||||
hash_result: hash_result!([$($modifiers)*][queries::$name::Value<'tcx>]),
|
||||
format_value: |value| format!("{:?}", erase::restore_val::<queries::$name::Value<'tcx>>(*value)),
|
||||
description_fn: $crate::queries::_description_fns::$name,
|
||||
execute_query_fn: if incremental {
|
||||
query_impl::$name::get_query_incr::__rust_end_short_backtrace
|
||||
} else {
|
||||
query_impl::$name::get_query_non_incr::__rust_end_short_backtrace
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -687,22 +692,10 @@ pub(crate) fn query_key_hash_verify<'tcx>(tcx: TyCtxt<'tcx>) {
|
||||
}
|
||||
})*}
|
||||
|
||||
pub(crate) fn engine(incremental: bool) -> QueryEngine {
|
||||
if incremental {
|
||||
QueryEngine {
|
||||
$($name: query_impl::$name::get_query_incr::__rust_end_short_backtrace,)*
|
||||
}
|
||||
} else {
|
||||
QueryEngine {
|
||||
$($name: query_impl::$name::get_query_non_incr::__rust_end_short_backtrace,)*
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn make_query_vtables<'tcx>() -> queries::PerQueryVTables<'tcx> {
|
||||
pub fn make_query_vtables<'tcx>(incremental: bool) -> queries::PerQueryVTables<'tcx> {
|
||||
queries::PerQueryVTables {
|
||||
$(
|
||||
$name: query_impl::$name::make_query_vtable(),
|
||||
$name: query_impl::$name::make_query_vtable(incremental),
|
||||
)*
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user