Skip to content

Commit 167aee2

Browse files
committed
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.
1 parent 84b9b13 commit 167aee2

3 files changed

Lines changed: 16 additions & 34 deletions

File tree

compiler/rustc_middle/src/query/plumbing.rs

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub use sealed::IntoQueryParam;
1414
use crate::dep_graph;
1515
use crate::dep_graph::{DepKind, DepNode, DepNodeIndex, SerializedDepNodeIndex};
1616
use crate::ich::StableHashingContext;
17-
use crate::queries::{ExternProviders, PerQueryVTables, Providers, QueryArenas, QueryEngine};
17+
use crate::queries::{ExternProviders, PerQueryVTables, Providers, QueryArenas};
1818
use crate::query::on_disk_cache::{CacheEncoder, EncodedDepNodeIndex, OnDiskCache};
1919
use crate::query::stack::{QueryStackDeferred, QueryStackFrame, QueryStackFrameExtra};
2020
use crate::query::{QueryCache, QueryInfo, QueryJob};
@@ -145,6 +145,8 @@ pub struct QueryVTable<'tcx, C: QueryCache> {
145145
///
146146
/// Used when reporting query cycle errors and similar problems.
147147
pub description_fn: fn(TyCtxt<'tcx>, C::Key) -> String,
148+
149+
pub execute_query_fn: fn(TyCtxt<'tcx>, Span, C::Key, QueryMode) -> Option<C::Value>,
148150
}
149151

150152
impl<'tcx, C: QueryCache> fmt::Debug for QueryVTable<'tcx, C> {
@@ -203,7 +205,6 @@ impl<'tcx, C: QueryCache> QueryVTable<'tcx, C> {
203205
}
204206

205207
pub struct QuerySystemFns {
206-
pub engine: QueryEngine,
207208
pub local_providers: Providers,
208209
pub extern_providers: ExternProviders,
209210
pub encode_query_results: for<'tcx> fn(
@@ -486,7 +487,7 @@ macro_rules! define_callbacks {
486487
(crate::query::inner::query_ensure)
487488
)(
488489
self.tcx,
489-
self.tcx.query_system.fns.engine.$name,
490+
self.tcx.query_system.query_vtables.$name.execute_query_fn,
490491
&self.tcx.query_system.query_vtables.$name.cache,
491492
$crate::query::IntoQueryParam::into_query_param(key),
492493
false,
@@ -502,7 +503,7 @@ macro_rules! define_callbacks {
502503
pub fn $name(self, key: query_helper_param_ty!($($K)*)) {
503504
crate::query::inner::query_ensure(
504505
self.tcx,
505-
self.tcx.query_system.fns.engine.$name,
506+
self.tcx.query_system.query_vtables.$name.execute_query_fn,
506507
&self.tcx.query_system.query_vtables.$name.cache,
507508
$crate::query::IntoQueryParam::into_query_param(key),
508509
true,
@@ -531,7 +532,7 @@ macro_rules! define_callbacks {
531532

532533
erase::restore_val::<$V>(inner::query_get_at(
533534
self.tcx,
534-
self.tcx.query_system.fns.engine.$name,
535+
self.tcx.query_system.query_vtables.$name.execute_query_fn,
535536
&self.tcx.query_system.query_vtables.$name.cache,
536537
self.span,
537538
$crate::query::IntoQueryParam::into_query_param(key),
@@ -608,17 +609,6 @@ macro_rules! define_callbacks {
608609
impl Clone for ExternProviders {
609610
fn clone(&self) -> Self { *self }
610611
}
611-
612-
pub struct QueryEngine {
613-
$(
614-
pub $name: for<'tcx> fn(
615-
TyCtxt<'tcx>,
616-
Span,
617-
$name::Key<'tcx>,
618-
$crate::query::QueryMode,
619-
) -> Option<$crate::query::erase::Erased<$V>>,
620-
)*
621-
}
622612
};
623613
}
624614

compiler/rustc_query_impl/src/lib.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
use rustc_data_structures::sync::AtomicU64;
1212
use rustc_middle::dep_graph;
13-
use rustc_middle::queries::{self, ExternProviders, Providers, QueryEngine};
13+
use rustc_middle::queries::{self, ExternProviders, Providers};
1414
use rustc_middle::query::on_disk_cache::{CacheEncoder, EncodedDepNodeIndex, OnDiskCache};
1515
use rustc_middle::query::plumbing::{QuerySystem, QuerySystemFns, QueryVTable};
1616
use rustc_middle::query::{AsLocalKey, QueryCache, QueryMode};
@@ -61,10 +61,9 @@ pub fn query_system<'tcx>(
6161
) -> QuerySystem<'tcx> {
6262
QuerySystem {
6363
arenas: Default::default(),
64-
query_vtables: make_query_vtables(),
64+
query_vtables: make_query_vtables(incremental),
6565
on_disk_cache,
6666
fns: QuerySystemFns {
67-
engine: engine(incremental),
6867
local_providers,
6968
extern_providers,
7069
encode_query_results: encode_all_query_results,

compiler/rustc_query_impl/src/plumbing.rs

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ macro_rules! define_queries {
549549
}
550550
}
551551

552-
pub(crate) fn make_query_vtable<'tcx>()
552+
pub(crate) fn make_query_vtable<'tcx>(incremental: bool)
553553
-> QueryVTable<'tcx, queries::$name::Storage<'tcx>>
554554
{
555555
QueryVTable {
@@ -604,6 +604,11 @@ macro_rules! define_queries {
604604
hash_result: hash_result!([$($modifiers)*][queries::$name::Value<'tcx>]),
605605
format_value: |value| format!("{:?}", erase::restore_val::<queries::$name::Value<'tcx>>(*value)),
606606
description_fn: $crate::queries::_description_fns::$name,
607+
execute_query_fn: if incremental {
608+
query_impl::$name::get_query_incr::__rust_end_short_backtrace
609+
} else {
610+
query_impl::$name::get_query_non_incr::__rust_end_short_backtrace
611+
},
607612
}
608613
}
609614

@@ -704,22 +709,10 @@ macro_rules! define_queries {
704709
}
705710
})*}
706711

707-
pub(crate) fn engine(incremental: bool) -> QueryEngine {
708-
if incremental {
709-
QueryEngine {
710-
$($name: query_impl::$name::get_query_incr::__rust_end_short_backtrace,)*
711-
}
712-
} else {
713-
QueryEngine {
714-
$($name: query_impl::$name::get_query_non_incr::__rust_end_short_backtrace,)*
715-
}
716-
}
717-
}
718-
719-
pub fn make_query_vtables<'tcx>() -> queries::PerQueryVTables<'tcx> {
712+
pub fn make_query_vtables<'tcx>(incremental: bool) -> queries::PerQueryVTables<'tcx> {
720713
queries::PerQueryVTables {
721714
$(
722-
$name: query_impl::$name::make_query_vtable(),
715+
$name: query_impl::$name::make_query_vtable(incremental),
723716
)*
724717
}
725718
}

0 commit comments

Comments
 (0)