Move provider fields back to rustc_query_impl

This commit is contained in:
John Kåre Alsaker 2023-02-14 14:17:04 +01:00
parent 265e1e968d
commit 067bf2ac13
7 changed files with 28 additions and 39 deletions

View file

@ -676,7 +676,9 @@ pub fn create_global_ctxt<'tcx>(
callback(sess, &mut local_providers, &mut extern_providers);
}
let queries = queries.get_or_init(|| TcxQueries::new(query_result_on_disk_cache));
let queries = queries.get_or_init(|| {
TcxQueries::new(local_providers, extern_providers, query_result_on_disk_cache)
});
sess.time("setup_global_ctxt", || {
gcx_cell.get_or_init(move || {
@ -688,8 +690,6 @@ pub fn create_global_ctxt<'tcx>(
untracked,
dep_graph,
queries.on_disk_cache.as_ref().map(OnDiskCache::as_dyn),
local_providers,
extern_providers,
queries.as_dyn(),
rustc_query_impl::query_callbacks(arena),
)

View file

@ -18,8 +18,6 @@
use crate::thir::Thir;
use crate::traits;
use crate::traits::solve::{ExternalConstraints, ExternalConstraintsData};
use crate::ty::query::ExternProviders;
use crate::ty::query::Providers;
use crate::ty::query::{self, TyCtxtAt};
use crate::ty::{
self, AdtDef, AdtDefData, AdtKind, Binder, Const, ConstData, DefIdTree, FloatTy, FloatVar,
@ -641,8 +639,6 @@ pub fn create_global_ctxt(
untracked: Untracked,
dep_graph: DepGraph,
on_disk_cache: Option<&'tcx dyn OnDiskCache<'tcx>>,
local_providers: Providers,
extern_providers: ExternProviders,
queries: &'tcx dyn query::QueryEngine<'tcx>,
query_kinds: &'tcx [DepKindStruct<'tcx>],
) -> GlobalCtxt<'tcx> {
@ -668,7 +664,7 @@ pub fn create_global_ctxt(
untracked,
on_disk_cache,
queries,
query_system: query::QuerySystem::new(local_providers, extern_providers),
query_system: Default::default(),
query_kinds,
ty_rcache: Default::default(),
pred_rcache: Default::default(),

View file

@ -71,24 +71,12 @@
pub(crate) use rustc_query_system::query::QueryJobId;
use rustc_query_system::query::*;
#[derive(Default)]
pub struct QuerySystem<'tcx> {
pub local_providers: Box<Providers>,
pub extern_providers: Box<ExternProviders>,
pub arenas: QueryArenas<'tcx>,
pub caches: QueryCaches<'tcx>,
}
impl<'tcx> QuerySystem<'tcx> {
pub fn new(local_providers: Providers, extern_providers: ExternProviders) -> Self {
QuerySystem {
local_providers: Box::new(local_providers),
extern_providers: Box::new(extern_providers),
arenas: Default::default(),
caches: Default::default(),
}
}
}
#[derive(Copy, Clone)]
pub struct TyCtxtAt<'tcx> {
pub tcx: TyCtxt<'tcx>,

View file

@ -21,10 +21,10 @@
use rustc_middle::arena::Arena;
use rustc_middle::dep_graph::{self, DepKindStruct};
use rustc_middle::query::Key;
use rustc_middle::ty::query::QueryEngine;
use rustc_middle::ty::query::{
query_keys, query_provided, query_provided_to_value, query_storage, query_values,
};
use rustc_middle::ty::query::{ExternProviders, Providers, QueryEngine};
use rustc_middle::ty::TyCtxt;
use rustc_span::Span;

View file

@ -278,13 +278,13 @@ macro_rules! hash_result {
macro_rules! get_provider {
([][$tcx:expr, $name:ident, $key:expr]) => {{
$tcx.query_system.local_providers.$name
$tcx.queries.local_providers.$name
}};
([(separate_provide_extern) $($rest:tt)*][$tcx:expr, $name:ident, $key:expr]) => {{
if $key.query_crate_is_local() {
$tcx.query_system.local_providers.$name
$tcx.queries.local_providers.$name
} else {
$tcx.query_system.extern_providers.$name
$tcx.queries.extern_providers.$name
}
}};
([$other:tt $($modifiers:tt)*][$($args:tt)*]) => {
@ -500,12 +500,11 @@ fn execute_query(tcx: TyCtxt<'tcx>, key: Self::Key) -> Self::Value {
}
#[inline]
// key is only sometimes used
#[allow(unused_variables)]
fn compute(tcx: TyCtxt<'tcx>, key: Self::Key) -> Self::Value {
fn compute(qcx: QueryCtxt<'tcx>, key: Self::Key) -> Self::Value {
query_provided_to_value::$name(
tcx,
get_provider!([$($modifiers)*][tcx, $name, key])(tcx, key)
qcx.tcx,
get_provider!([$($modifiers)*][qcx, $name, key])(qcx.tcx, key)
)
}
@ -664,12 +663,18 @@ pub fn query_callbacks<'tcx>(arena: &'tcx Arena<'tcx>) -> &'tcx [DepKindStruct<'
}
}
use crate::OnDiskCache;
use crate::{ExternProviders, OnDiskCache, Providers};
impl<'tcx> Queries<'tcx> {
pub fn new(on_disk_cache: Option<OnDiskCache<'tcx>>) -> Self {
pub fn new(
local_providers: Providers,
extern_providers: ExternProviders,
on_disk_cache: Option<OnDiskCache<'tcx>>,
) -> Self {
use crate::query_structs;
Queries {
local_providers: Box::new(local_providers),
extern_providers: Box::new(extern_providers),
query_structs: make_dep_kind_array!(query_structs).to_vec(),
on_disk_cache,
jobs: AtomicU64::new(1),
@ -683,6 +688,8 @@ macro_rules! define_queries_struct {
input: ($(([$($modifiers:tt)*] [$($attr:tt)*] [$name:ident]))*)) => {
#[derive(Default)]
pub struct Queries<'tcx> {
local_providers: Box<Providers>,
extern_providers: Box<ExternProviders>,
query_structs: Vec<$crate::plumbing::QueryStruct<'tcx>>,
pub on_disk_cache: Option<OnDiskCache<'tcx>>,
jobs: AtomicU64,

View file

@ -39,7 +39,7 @@ fn query_cache<'a>(tcx: Qcx) -> &'a Self::Cache
// Don't use this method to compute query results, instead use the methods on TyCtxt
fn execute_query(tcx: Qcx::DepContext, k: Self::Key) -> Self::Value;
fn compute(tcx: Qcx::DepContext, key: Self::Key) -> Self::Value;
fn compute(tcx: Qcx, key: Self::Key) -> Self::Value;
fn try_load_from_disk(qcx: Qcx, idx: &Self::Key) -> TryLoadFromDisk<Qcx, Self>;

View file

@ -425,8 +425,7 @@ fn execute_job<Q, Qcx>(
// Fast path for when incr. comp. is off.
if !dep_graph.is_fully_enabled() {
let prof_timer = qcx.dep_context().profiler().query_provider();
let result =
qcx.start_query(job_id, Q::DEPTH_LIMIT, None, || Q::compute(*qcx.dep_context(), key));
let result = qcx.start_query(job_id, Q::DEPTH_LIMIT, None, || Q::compute(qcx, key));
let dep_node_index = dep_graph.next_virtual_depnode_index();
prof_timer.finish_with_query_invocation_id(dep_node_index.into());
return (result, dep_node_index);
@ -452,16 +451,15 @@ fn execute_job<Q, Qcx>(
let (result, dep_node_index) =
qcx.start_query(job_id, Q::DEPTH_LIMIT, Some(&diagnostics), || {
if Q::ANON {
return dep_graph.with_anon_task(*qcx.dep_context(), Q::DEP_KIND, || {
Q::compute(*qcx.dep_context(), key)
});
return dep_graph
.with_anon_task(*qcx.dep_context(), Q::DEP_KIND, || Q::compute(qcx, key));
}
// `to_dep_node` is expensive for some `DepKind`s.
let dep_node =
dep_node_opt.unwrap_or_else(|| Q::construct_dep_node(*qcx.dep_context(), &key));
dep_graph.with_task(dep_node, *qcx.dep_context(), key, Q::compute, Q::HASH_RESULT)
dep_graph.with_task(dep_node, qcx, key, Q::compute, Q::HASH_RESULT)
});
prof_timer.finish_with_query_invocation_id(dep_node_index.into());
@ -552,7 +550,7 @@ fn try_load_from_disk_and_cache_in_memory<Q, Qcx>(
let prof_timer = qcx.dep_context().profiler().query_provider();
// The dep-graph for this computation is already in-place.
let result = dep_graph.with_ignore(|| Q::compute(*qcx.dep_context(), key.clone()));
let result = dep_graph.with_ignore(|| Q::compute(qcx, key.clone()));
prof_timer.finish_with_query_invocation_id(dep_node_index.into());