Skip to content

Commit 2bc5167

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 06cd823 commit 2bc5167

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};
@@ -157,6 +157,8 @@ pub struct QueryVTable<'tcx, C: QueryCache> {
157157
///
158158
/// Used when reporting query cycle errors and similar problems.
159159
pub description_fn: fn(TyCtxt<'tcx>, C::Key) -> String,
160+
161+
pub execute_query_fn: fn(TyCtxt<'tcx>, Span, C::Key, QueryMode) -> Option<C::Value>,
160162
}
161163

162164
impl<'tcx, C: QueryCache> fmt::Debug for QueryVTable<'tcx, C> {
@@ -215,7 +217,6 @@ impl<'tcx, C: QueryCache> QueryVTable<'tcx, C> {
215217
}
216218

217219
pub struct QuerySystemFns {
218-
pub engine: QueryEngine,
219220
pub local_providers: Providers,
220221
pub extern_providers: ExternProviders,
221222
pub encode_query_results: for<'tcx> fn(
@@ -509,7 +510,7 @@ macro_rules! define_callbacks {
509510
(crate::query::inner::query_ensure)
510511
)(
511512
self.tcx,
512-
self.tcx.query_system.fns.engine.$name,
513+
self.tcx.query_system.query_vtables.$name.execute_query_fn,
513514
&self.tcx.query_system.query_vtables.$name.cache,
514515
$crate::query::IntoQueryParam::into_query_param(key),
515516
$crate::query::EnsureMode::Ok,
@@ -525,7 +526,7 @@ macro_rules! define_callbacks {
525526
pub fn $name(self, key: query_helper_param_ty!($($K)*)) {
526527
crate::query::inner::query_ensure(
527528
self.tcx,
528-
self.tcx.query_system.fns.engine.$name,
529+
self.tcx.query_system.query_vtables.$name.execute_query_fn,
529530
&self.tcx.query_system.query_vtables.$name.cache,
530531
$crate::query::IntoQueryParam::into_query_param(key),
531532
$crate::query::EnsureMode::Done,
@@ -554,7 +555,7 @@ macro_rules! define_callbacks {
554555

555556
erase::restore_val::<$V>(inner::query_get_at(
556557
self.tcx,
557-
self.tcx.query_system.fns.engine.$name,
558+
self.tcx.query_system.query_vtables.$name.execute_query_fn,
558559
&self.tcx.query_system.query_vtables.$name.cache,
559560
self.span,
560561
$crate::query::IntoQueryParam::into_query_param(key),
@@ -654,17 +655,6 @@ macro_rules! define_callbacks {
654655
impl Clone for ExternProviders {
655656
fn clone(&self) -> Self { *self }
656657
}
657-
658-
pub struct QueryEngine {
659-
$(
660-
pub $name: for<'tcx> fn(
661-
TyCtxt<'tcx>,
662-
Span,
663-
$name::Key<'tcx>,
664-
$crate::query::QueryMode,
665-
) -> Option<$crate::query::erase::Erased<$V>>,
666-
)*
667-
}
668658
};
669659
}
670660

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};
@@ -57,10 +57,9 @@ pub fn query_system<'tcx>(
5757
) -> QuerySystem<'tcx> {
5858
QuerySystem {
5959
arenas: Default::default(),
60-
query_vtables: make_query_vtables(),
60+
query_vtables: make_query_vtables(incremental),
6161
on_disk_cache,
6262
fns: QuerySystemFns {
63-
engine: engine(incremental),
6463
local_providers,
6564
extern_providers,
6665
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
@@ -548,7 +548,7 @@ macro_rules! define_queries {
548548
}
549549
}
550550

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

@@ -687,22 +692,10 @@ macro_rules! define_queries {
687692
}
688693
})*}
689694

690-
pub(crate) fn engine(incremental: bool) -> QueryEngine {
691-
if incremental {
692-
QueryEngine {
693-
$($name: query_impl::$name::get_query_incr::__rust_end_short_backtrace,)*
694-
}
695-
} else {
696-
QueryEngine {
697-
$($name: query_impl::$name::get_query_non_incr::__rust_end_short_backtrace,)*
698-
}
699-
}
700-
}
701-
702-
pub fn make_query_vtables<'tcx>() -> queries::PerQueryVTables<'tcx> {
695+
pub fn make_query_vtables<'tcx>(incremental: bool) -> queries::PerQueryVTables<'tcx> {
703696
queries::PerQueryVTables {
704697
$(
705-
$name: query_impl::$name::make_query_vtable(),
698+
$name: query_impl::$name::make_query_vtable(incremental),
706699
)*
707700
}
708701
}

0 commit comments

Comments
 (0)