Skip to content

Commit e9b188f

Browse files
authored
Unrolled build for #152841
Rollup merge of #152841 - Zalathar:unerased, r=nnethercote Streamline `QueryVTableUnerased` into `GetQueryVTable` *[View all comments](https://triagebot.infra.rust-lang.org/gh-comments/rust-lang/rust/pull/152841)* `QueryDispatcherUnerased` is an awkward name for an awkward trait. We can make it a bit more straightforward by removing its responsibility for erasing query values, and by observing that its only real responsibility beyond that is to know how to obtain the vtable for a particlar query from `tcx`.
2 parents 0028f34 + 16fbd29 commit e9b188f

File tree

3 files changed

+25
-47
lines changed

3 files changed

+25
-47
lines changed

compiler/rustc_query_impl/src/dep_kind_vtables.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use rustc_middle::bug;
22
use rustc_middle::dep_graph::{DepKindVTable, DepNodeKey, KeyFingerprintStyle};
33
use rustc_middle::query::QueryCache;
44

5-
use crate::QueryDispatcherUnerased;
5+
use crate::GetQueryVTable;
66
use crate::plumbing::{force_from_dep_node_inner, try_load_from_on_disk_cache_inner};
77

88
/// [`DepKindVTable`] constructors for special dep kinds that aren't queries.
@@ -102,18 +102,17 @@ mod non_query {
102102

103103
/// Shared implementation of the [`DepKindVTable`] constructor for queries.
104104
/// Called from macro-generated code for each query.
105-
pub(crate) fn make_dep_kind_vtable_for_query<'tcx, Q, Cache>(
105+
pub(crate) fn make_dep_kind_vtable_for_query<'tcx, Q>(
106106
is_anon: bool,
107107
is_eval_always: bool,
108108
) -> DepKindVTable<'tcx>
109109
where
110-
Q: QueryDispatcherUnerased<'tcx, Cache>,
111-
Cache: QueryCache + 'tcx,
110+
Q: GetQueryVTable<'tcx>,
112111
{
113112
let key_fingerprint_style = if is_anon {
114113
KeyFingerprintStyle::Opaque
115114
} else {
116-
<Cache::Key as DepNodeKey<'tcx>>::key_fingerprint_style()
115+
<Q::Cache as QueryCache>::Key::key_fingerprint_style()
117116
};
118117

119118
if is_anon || !key_fingerprint_style.reconstructible() {

compiler/rustc_query_impl/src/lib.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,18 @@ mod job;
3737
mod profiling_support;
3838
mod values;
3939

40-
/// Provides access to vtable-like operations for a query (by obtaining a
41-
/// `QueryVTable`), but also keeps track of the "unerased" value type of the
42-
/// query (i.e. the actual result type in the query declaration).
40+
/// Trait that knows how to look up the [`QueryVTable`] for a particular query.
4341
///
4442
/// This trait allows some per-query code to be defined in generic functions
4543
/// with a trait bound, instead of having to be defined inline within a macro
4644
/// expansion.
4745
///
4846
/// There is one macro-generated implementation of this trait for each query,
49-
/// on the type `rustc_query_impl::query_impl::$name::QueryType`.
50-
trait QueryDispatcherUnerased<'tcx, C: QueryCache> {
51-
type UnerasedValue;
47+
/// on the type `rustc_query_impl::query_impl::$name::VTableGetter`.
48+
trait GetQueryVTable<'tcx> {
49+
type Cache: QueryCache + 'tcx;
5250

53-
fn query_vtable(tcx: TyCtxt<'tcx>) -> &'tcx QueryVTable<'tcx, C>;
54-
55-
fn restore_val(value: C::Value) -> Self::UnerasedValue;
51+
fn query_vtable(tcx: TyCtxt<'tcx>) -> &'tcx QueryVTable<'tcx, Self::Cache>;
5652
}
5753

5854
pub fn query_system<'tcx>(

compiler/rustc_query_impl/src/plumbing.rs

Lines changed: 16 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@ use rustc_middle::bug;
1313
#[expect(unused_imports, reason = "used by doc comments")]
1414
use rustc_middle::dep_graph::DepKindVTable;
1515
use rustc_middle::dep_graph::{DepKind, DepNode, DepNodeIndex, DepNodeKey, SerializedDepNodeIndex};
16+
use rustc_middle::query::erase::{Erasable, Erased};
1617
use rustc_middle::query::on_disk_cache::{
1718
AbsoluteBytePos, CacheDecoder, CacheEncoder, EncodedDepNodeIndex,
1819
};
1920
use rustc_middle::query::plumbing::QueryVTable;
2021
use rustc_middle::query::{
21-
Key, QueryCache, QueryJobId, QueryStackDeferred, QueryStackFrame, QueryStackFrameExtra,
22+
Key, QueryCache, QueryJobId, QueryStackDeferred, QueryStackFrame, QueryStackFrameExtra, erase,
2223
};
2324
use rustc_middle::ty::codec::TyEncoder;
2425
use rustc_middle::ty::print::with_reduced_queries;
@@ -27,7 +28,6 @@ use rustc_middle::ty::{self, TyCtxt};
2728
use rustc_serialize::{Decodable, Encodable};
2829
use rustc_span::def_id::LOCAL_CRATE;
2930

30-
use crate::QueryDispatcherUnerased;
3131
use crate::error::{QueryOverflow, QueryOverflowNote};
3232
use crate::execution::{all_inactive, force_query};
3333
use crate::job::{QueryJobMap, find_dep_kind_root};
@@ -324,14 +324,14 @@ where
324324
QueryStackFrame::new(info, kind, def_id, def_id_for_ty_in_cycle)
325325
}
326326

327-
pub(crate) fn encode_query_results<'a, 'tcx, Q, C: QueryCache>(
328-
query: &'tcx QueryVTable<'tcx, C>,
327+
pub(crate) fn encode_query_results_inner<'a, 'tcx, C, V>(
329328
tcx: TyCtxt<'tcx>,
329+
query: &'tcx QueryVTable<'tcx, C>,
330330
encoder: &mut CacheEncoder<'a, 'tcx>,
331331
query_result_index: &mut EncodedDepNodeIndex,
332332
) where
333-
Q: QueryDispatcherUnerased<'tcx, C>,
334-
Q::UnerasedValue: Encodable<CacheEncoder<'a, 'tcx>>,
333+
C: QueryCache<Value = Erased<V>>,
334+
V: Erasable + Encodable<CacheEncoder<'a, 'tcx>>,
335335
{
336336
let _timer = tcx.prof.generic_activity_with_arg("encode_query_results_for", query.name);
337337

@@ -346,7 +346,7 @@ pub(crate) fn encode_query_results<'a, 'tcx, Q, C: QueryCache>(
346346

347347
// Encode the type check tables with the `SerializedDepNodeIndex`
348348
// as tag.
349-
encoder.encode_tagged(dep_node, &Q::restore_val(*value));
349+
encoder.encode_tagged(dep_node, &erase::restore_val::<V>(*value));
350350
}
351351
});
352352
}
@@ -473,7 +473,6 @@ macro_rules! define_queries {
473473

474474
pub(crate) mod query_impl { $(pub(crate) mod $name {
475475
use super::super::*;
476-
use std::marker::PhantomData;
477476
use ::rustc_middle::query::erase::{self, Erased};
478477

479478
pub(crate) mod get_query_incr {
@@ -607,29 +606,16 @@ macro_rules! define_queries {
607606
}
608607
}
609608

610-
#[derive(Copy, Clone, Default)]
611-
pub(crate) struct QueryType<'tcx> {
612-
data: PhantomData<&'tcx ()>
613-
}
609+
/// Marker type that implements [`GetQueryVTable`] for this query.
610+
pub(crate) enum VTableGetter {}
614611

615-
impl<'tcx> QueryDispatcherUnerased<'tcx, queries::$name::Storage<'tcx>>
616-
for QueryType<'tcx>
617-
{
618-
type UnerasedValue = queries::$name::Value<'tcx>;
612+
impl<'tcx> GetQueryVTable<'tcx> for VTableGetter {
613+
type Cache = rustc_middle::queries::$name::Storage<'tcx>;
619614

620615
#[inline(always)]
621-
fn query_vtable(tcx: TyCtxt<'tcx>)
622-
-> &'tcx QueryVTable<'tcx, queries::$name::Storage<'tcx>>
623-
{
616+
fn query_vtable(tcx: TyCtxt<'tcx>) -> &'tcx QueryVTable<'tcx, Self::Cache> {
624617
&tcx.query_system.query_vtables.$name
625618
}
626-
627-
#[inline(always)]
628-
fn restore_val(value: <queries::$name::Storage<'tcx> as QueryCache>::Value)
629-
-> Self::UnerasedValue
630-
{
631-
erase::restore_val::<queries::$name::Value<'tcx>>(value)
632-
}
633619
}
634620

635621
/// Internal per-query plumbing for collecting the set of active jobs for this query.
@@ -683,12 +669,9 @@ macro_rules! define_queries {
683669
encoder: &mut CacheEncoder<'_, 'tcx>,
684670
query_result_index: &mut EncodedDepNodeIndex
685671
) {
686-
$crate::plumbing::encode_query_results::<
687-
query_impl::$name::QueryType<'tcx>,
688-
_
689-
> (
690-
&tcx.query_system.query_vtables.$name,
672+
$crate::plumbing::encode_query_results_inner(
691673
tcx,
674+
&tcx.query_system.query_vtables.$name,
692675
encoder,
693676
query_result_index,
694677
)
@@ -773,8 +756,8 @@ macro_rules! define_queries {
773756
$(
774757
/// `DepKindVTable` constructor for this query.
775758
pub(crate) fn $name<'tcx>() -> DepKindVTable<'tcx> {
776-
use $crate::query_impl::$name::QueryType;
777-
make_dep_kind_vtable_for_query::<QueryType<'tcx>, _>(
759+
use $crate::query_impl::$name::VTableGetter;
760+
make_dep_kind_vtable_for_query::<VTableGetter>(
778761
is_anon!([$($modifiers)*]),
779762
is_eval_always!([$($modifiers)*]),
780763
)

0 commit comments

Comments
 (0)