Skip to content

Commit bc792c2

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 156f355 commit bc792c2

3 files changed

Lines changed: 16 additions & 32 deletions

File tree

compiler/rustc_middle/src/query/plumbing.rs

Lines changed: 6 additions & 14 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, 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};
@@ -136,10 +136,11 @@ pub struct QueryVTable<'tcx, C: QueryCache> {
136136
///
137137
/// Used when reporting query cycle errors and similar problems.
138138
pub description_fn: fn(TyCtxt<'tcx>, C::Key) -> String,
139+
140+
pub execute_query_fn: fn(TyCtxt<'tcx>, Span, C::Key, QueryMode) -> Option<C::Value>,
139141
}
140142

141143
pub struct QuerySystemFns {
142-
pub engine: QueryEngine,
143144
pub local_providers: Providers,
144145
pub extern_providers: ExternProviders,
145146
pub encode_query_results: for<'tcx> fn(
@@ -449,7 +450,7 @@ macro_rules! define_callbacks {
449450
query_ensure_select!(
450451
[$($modifiers)*]
451452
self.tcx,
452-
self.tcx.query_system.fns.engine.$name,
453+
self.tcx.query_system.query_vtables.$name.execute_query_fn,
453454
&self.tcx.query_system.query_vtables.$name.query_cache,
454455
$crate::query::IntoQueryParam::into_query_param(key),
455456
false,
@@ -463,7 +464,7 @@ macro_rules! define_callbacks {
463464
pub fn $name(self, key: query_helper_param_ty!($($K)*)) {
464465
crate::query::inner::query_ensure(
465466
self.tcx,
466-
self.tcx.query_system.fns.engine.$name,
467+
self.tcx.query_system.query_vtables.$name.execute_query_fn,
467468
&self.tcx.query_system.query_vtables.$name.query_cache,
468469
$crate::query::IntoQueryParam::into_query_param(key),
469470
true,
@@ -490,7 +491,7 @@ macro_rules! define_callbacks {
490491

491492
erase::restore_val::<$V>(inner::query_get_at(
492493
self.tcx,
493-
self.tcx.query_system.fns.engine.$name,
494+
self.tcx.query_system.query_vtables.$name.execute_query_fn,
494495
&self.tcx.query_system.query_vtables.$name.query_cache,
495496
self.span,
496497
$crate::query::IntoQueryParam::into_query_param(key),
@@ -547,15 +548,6 @@ macro_rules! define_callbacks {
547548
impl Clone for ExternProviders {
548549
fn clone(&self) -> Self { *self }
549550
}
550-
551-
pub struct QueryEngine {
552-
$(pub $name: for<'tcx> fn(
553-
TyCtxt<'tcx>,
554-
Span,
555-
$name::Key<'tcx>,
556-
$crate::query::QueryMode,
557-
) -> Option<$crate::query::erase::Erased<$V>>,)*
558-
}
559551
};
560552
}
561553

compiler/rustc_query_impl/src/lib.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use std::marker::ConstParamTy;
1414

1515
use rustc_data_structures::sync::AtomicU64;
1616
use rustc_middle::dep_graph::{self, DepKind, DepNode, DepNodeIndex, SerializedDepNodeIndex};
17-
use rustc_middle::queries::{self, ExternProviders, Providers, QueryEngine};
17+
use rustc_middle::queries::{self, ExternProviders, Providers};
1818
use rustc_middle::query::on_disk_cache::{CacheEncoder, EncodedDepNodeIndex, OnDiskCache};
1919
use rustc_middle::query::plumbing::{
2020
HashResult, QueryState, QuerySystem, QuerySystemFns, QueryVTable,
@@ -232,10 +232,9 @@ pub fn query_system<'tcx>(
232232
) -> QuerySystem<'tcx> {
233233
QuerySystem {
234234
arenas: Default::default(),
235-
query_vtables: make_query_vtables(),
235+
query_vtables: make_query_vtables(incremental),
236236
on_disk_cache,
237237
fns: QuerySystemFns {
238-
engine: engine(incremental),
239238
local_providers,
240239
extern_providers,
241240
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
@@ -568,7 +568,7 @@ macro_rules! define_queries {
568568
}
569569
}
570570

571-
pub(crate) fn make_query_vtable<'tcx>()
571+
pub(crate) fn make_query_vtable<'tcx>(incremental: bool)
572572
-> QueryVTable<'tcx, queries::$name::Storage<'tcx>>
573573
{
574574
QueryVTable {
@@ -620,6 +620,11 @@ macro_rules! define_queries {
620620
hash_result: hash_result!([$($modifiers)*][queries::$name::Value<'tcx>]),
621621
format_value: |value| format!("{:?}", erase::restore_val::<queries::$name::Value<'tcx>>(*value)),
622622
description_fn: $crate::queries::_description_fns::$name,
623+
execute_query_fn: if incremental {
624+
query_impl::$name::get_query_incr::__rust_end_short_backtrace
625+
} else {
626+
query_impl::$name::get_query_non_incr::__rust_end_short_backtrace
627+
},
623628
}
624629
}
625630

@@ -731,22 +736,10 @@ macro_rules! define_queries {
731736
}
732737
})*}
733738

734-
pub(crate) fn engine(incremental: bool) -> QueryEngine {
735-
if incremental {
736-
QueryEngine {
737-
$($name: query_impl::$name::get_query_incr::__rust_end_short_backtrace,)*
738-
}
739-
} else {
740-
QueryEngine {
741-
$($name: query_impl::$name::get_query_non_incr::__rust_end_short_backtrace,)*
742-
}
743-
}
744-
}
745-
746-
pub fn make_query_vtables<'tcx>() -> queries::PerQueryVTables<'tcx> {
739+
pub fn make_query_vtables<'tcx>(incremental: bool) -> queries::PerQueryVTables<'tcx> {
747740
queries::PerQueryVTables {
748741
$(
749-
$name: query_impl::$name::make_query_vtable(),
742+
$name: query_impl::$name::make_query_vtable(incremental),
750743
)*
751744
}
752745
}

0 commit comments

Comments
 (0)