Skip to content

Commit d6f99e5

Browse files
committed
Auto merge of #106307 - Nilstrieb:dynamic->static, r=cjgillot
Abolish `QueryVTable` in favour of more assoc items on `QueryConfig` This may introduce additional mono _but_ may help const fold things better and especially may help not constructing a `QueryVTable` anymore which is cheap but not free.
2 parents 23b1cc1 + 9fe4efe commit d6f99e5

File tree

5 files changed

+95
-114
lines changed

5 files changed

+95
-114
lines changed

compiler/rustc_query_impl/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ use rustc_query_system::query::*;
3434
pub use rustc_query_system::query::{deadlock, QueryContext};
3535

3636
pub use rustc_query_system::query::QueryConfig;
37-
pub(crate) use rustc_query_system::query::QueryVTable;
3837

3938
mod on_disk_cache;
4039
pub use on_disk_cache::OnDiskCache;

compiler/rustc_query_impl/src/plumbing.rs

+22-18
Original file line numberDiff line numberDiff line change
@@ -493,28 +493,32 @@ macro_rules! define_queries {
493493
&tcx.query_caches.$name
494494
}
495495

496+
fn execute_query(tcx: TyCtxt<'tcx>, key: Self::Key) -> Self::Stored {
497+
tcx.$name(key)
498+
}
499+
496500
#[inline]
497-
fn make_vtable(tcx: QueryCtxt<'tcx>, key: &Self::Key) ->
498-
QueryVTable<QueryCtxt<'tcx>, Self::Key, Self::Value>
499-
{
500-
let compute = get_provider!([$($modifiers)*][tcx, $name, key]);
501-
let cache_on_disk = Self::cache_on_disk(tcx.tcx, key);
502-
QueryVTable {
503-
anon: is_anon!([$($modifiers)*]),
504-
eval_always: is_eval_always!([$($modifiers)*]),
505-
depth_limit: depth_limit!([$($modifiers)*]),
506-
feedable: feedable!([$($modifiers)*]),
507-
dep_kind: dep_graph::DepKind::$name,
508-
hash_result: hash_result!([$($modifiers)*]),
509-
handle_cycle_error: handle_cycle_error!([$($modifiers)*]),
510-
compute,
511-
try_load_from_disk: if cache_on_disk { should_ever_cache_on_disk!([$($modifiers)*]) } else { None },
512-
}
501+
// key is only sometimes used
502+
#[allow(unused_variables)]
503+
fn compute(qcx: QueryCtxt<'tcx>, key: &Self::Key) -> fn(TyCtxt<'tcx>, Self::Key) -> Self::Value {
504+
get_provider!([$($modifiers)*][qcx, $name, key])
513505
}
514506

515-
fn execute_query(tcx: TyCtxt<'tcx>, k: Self::Key) -> Self::Stored {
516-
tcx.$name(k)
507+
#[inline]
508+
fn try_load_from_disk(qcx: QueryCtxt<'tcx>, key: &Self::Key) -> rustc_query_system::query::TryLoadFromDisk<QueryCtxt<'tcx>, Self> {
509+
let cache_on_disk = Self::cache_on_disk(qcx.tcx, key);
510+
if cache_on_disk { should_ever_cache_on_disk!([$($modifiers)*]) } else { None }
517511
}
512+
513+
const ANON: bool = is_anon!([$($modifiers)*]);
514+
const EVAL_ALWAYS: bool = is_eval_always!([$($modifiers)*]);
515+
const DEPTH_LIMIT: bool = depth_limit!([$($modifiers)*]);
516+
const FEEDABLE: bool = feedable!([$($modifiers)*]);
517+
518+
const DEP_KIND: rustc_middle::dep_graph::DepKind = dep_graph::DepKind::$name;
519+
const HANDLE_CYCLE_ERROR: rustc_query_system::HandleCycleError = handle_cycle_error!([$($modifiers)*]);
520+
521+
const HASH_RESULT: rustc_query_system::query::HashResult<QueryCtxt<'tcx>, Self> = hash_result!([$($modifiers)*]);
518522
})*
519523

520524
#[allow(nonstandard_style)]
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
//! Query configuration and description traits.
22
3-
use crate::dep_graph::DepNode;
4-
use crate::dep_graph::SerializedDepNodeIndex;
3+
use crate::dep_graph::{DepNode, DepNodeParams, SerializedDepNodeIndex};
54
use crate::error::HandleCycleError;
65
use crate::ich::StableHashingContext;
76
use crate::query::caches::QueryCache;
@@ -11,10 +10,16 @@ use rustc_data_structures::fingerprint::Fingerprint;
1110
use std::fmt::Debug;
1211
use std::hash::Hash;
1312

13+
pub type HashResult<Qcx, Q> =
14+
Option<fn(&mut StableHashingContext<'_>, &<Q as QueryConfig<Qcx>>::Value) -> Fingerprint>;
15+
16+
pub type TryLoadFromDisk<Qcx, Q> =
17+
Option<fn(Qcx, SerializedDepNodeIndex) -> Option<<Q as QueryConfig<Qcx>>::Value>>;
18+
1419
pub trait QueryConfig<Qcx: QueryContext> {
1520
const NAME: &'static str;
1621

17-
type Key: Eq + Hash + Clone + Debug;
22+
type Key: DepNodeParams<Qcx::DepContext> + Eq + Hash + Clone + Debug;
1823
type Value: Debug;
1924
type Stored: Debug + Clone + std::borrow::Borrow<Self::Value>;
2025

@@ -30,39 +35,27 @@ pub trait QueryConfig<Qcx: QueryContext> {
3035
where
3136
Qcx: 'a;
3237

33-
// Don't use this method to compute query results, instead use the methods on TyCtxt
34-
fn make_vtable(tcx: Qcx, key: &Self::Key) -> QueryVTable<Qcx, Self::Key, Self::Value>;
35-
3638
fn cache_on_disk(tcx: Qcx::DepContext, key: &Self::Key) -> bool;
3739

3840
// Don't use this method to compute query results, instead use the methods on TyCtxt
3941
fn execute_query(tcx: Qcx::DepContext, k: Self::Key) -> Self::Stored;
40-
}
4142

42-
#[derive(Copy, Clone)]
43-
pub struct QueryVTable<Qcx: QueryContext, K, V> {
44-
pub anon: bool,
45-
pub dep_kind: Qcx::DepKind,
46-
pub eval_always: bool,
47-
pub depth_limit: bool,
48-
pub feedable: bool,
49-
50-
pub compute: fn(Qcx::DepContext, K) -> V,
51-
pub hash_result: Option<fn(&mut StableHashingContext<'_>, &V) -> Fingerprint>,
52-
pub handle_cycle_error: HandleCycleError,
53-
// NOTE: this is also `None` if `cache_on_disk()` returns false, not just if it's unsupported by the query
54-
pub try_load_from_disk: Option<fn(Qcx, SerializedDepNodeIndex) -> Option<V>>,
55-
}
43+
fn compute(tcx: Qcx, key: &Self::Key) -> fn(Qcx::DepContext, Self::Key) -> Self::Value;
5644

57-
impl<Qcx: QueryContext, K, V> QueryVTable<Qcx, K, V> {
58-
pub(crate) fn to_dep_node(&self, tcx: Qcx::DepContext, key: &K) -> DepNode<Qcx::DepKind>
59-
where
60-
K: crate::dep_graph::DepNodeParams<Qcx::DepContext>,
61-
{
62-
DepNode::construct(tcx, self.dep_kind, key)
63-
}
45+
fn try_load_from_disk(qcx: Qcx, idx: &Self::Key) -> TryLoadFromDisk<Qcx, Self>;
46+
47+
const ANON: bool;
48+
const EVAL_ALWAYS: bool;
49+
const DEPTH_LIMIT: bool;
50+
const FEEDABLE: bool;
51+
52+
const DEP_KIND: Qcx::DepKind;
53+
const HANDLE_CYCLE_ERROR: HandleCycleError;
54+
55+
const HASH_RESULT: HashResult<Qcx, Self>;
6456

65-
pub(crate) fn compute(&self, tcx: Qcx::DepContext, key: K) -> V {
66-
(self.compute)(tcx, key)
57+
// Just here for convernience and checking that the key matches the kind, don't override this.
58+
fn construct_dep_node(tcx: Qcx::DepContext, key: &Self::Key) -> DepNode<Qcx::DepKind> {
59+
DepNode::construct(tcx, Self::DEP_KIND, key)
6760
}
6861
}

compiler/rustc_query_system/src/query/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub use self::caches::{
1212
};
1313

1414
mod config;
15-
pub use self::config::{QueryConfig, QueryVTable};
15+
pub use self::config::{HashResult, QueryConfig, TryLoadFromDisk};
1616

1717
use crate::dep_graph::DepKind;
1818
use crate::dep_graph::{DepNodeIndex, HasDepContext, SerializedDepNodeIndex};

0 commit comments

Comments
 (0)