Skip to content

Commit 067bf2a

Browse files
committed
Move provider fields back to rustc_query_impl
1 parent 265e1e9 commit 067bf2a

File tree

7 files changed

+28
-39
lines changed

7 files changed

+28
-39
lines changed

compiler/rustc_interface/src/passes.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,9 @@ pub fn create_global_ctxt<'tcx>(
676676
callback(sess, &mut local_providers, &mut extern_providers);
677677
}
678678

679-
let queries = queries.get_or_init(|| TcxQueries::new(query_result_on_disk_cache));
679+
let queries = queries.get_or_init(|| {
680+
TcxQueries::new(local_providers, extern_providers, query_result_on_disk_cache)
681+
});
680682

681683
sess.time("setup_global_ctxt", || {
682684
gcx_cell.get_or_init(move || {
@@ -688,8 +690,6 @@ pub fn create_global_ctxt<'tcx>(
688690
untracked,
689691
dep_graph,
690692
queries.on_disk_cache.as_ref().map(OnDiskCache::as_dyn),
691-
local_providers,
692-
extern_providers,
693693
queries.as_dyn(),
694694
rustc_query_impl::query_callbacks(arena),
695695
)

compiler/rustc_middle/src/ty/context.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ use crate::mir::{
1818
use crate::thir::Thir;
1919
use crate::traits;
2020
use crate::traits::solve::{ExternalConstraints, ExternalConstraintsData};
21-
use crate::ty::query::ExternProviders;
22-
use crate::ty::query::Providers;
2321
use crate::ty::query::{self, TyCtxtAt};
2422
use crate::ty::{
2523
self, AdtDef, AdtDefData, AdtKind, Binder, Const, ConstData, DefIdTree, FloatTy, FloatVar,
@@ -641,8 +639,6 @@ impl<'tcx> TyCtxt<'tcx> {
641639
untracked: Untracked,
642640
dep_graph: DepGraph,
643641
on_disk_cache: Option<&'tcx dyn OnDiskCache<'tcx>>,
644-
local_providers: Providers,
645-
extern_providers: ExternProviders,
646642
queries: &'tcx dyn query::QueryEngine<'tcx>,
647643
query_kinds: &'tcx [DepKindStruct<'tcx>],
648644
) -> GlobalCtxt<'tcx> {
@@ -668,7 +664,7 @@ impl<'tcx> TyCtxt<'tcx> {
668664
untracked,
669665
on_disk_cache,
670666
queries,
671-
query_system: query::QuerySystem::new(local_providers, extern_providers),
667+
query_system: Default::default(),
672668
query_kinds,
673669
ty_rcache: Default::default(),
674670
pred_rcache: Default::default(),

compiler/rustc_middle/src/ty/query.rs

+1-13
Original file line numberDiff line numberDiff line change
@@ -71,24 +71,12 @@ use std::sync::Arc;
7171
pub(crate) use rustc_query_system::query::QueryJobId;
7272
use rustc_query_system::query::*;
7373

74+
#[derive(Default)]
7475
pub struct QuerySystem<'tcx> {
75-
pub local_providers: Box<Providers>,
76-
pub extern_providers: Box<ExternProviders>,
7776
pub arenas: QueryArenas<'tcx>,
7877
pub caches: QueryCaches<'tcx>,
7978
}
8079

81-
impl<'tcx> QuerySystem<'tcx> {
82-
pub fn new(local_providers: Providers, extern_providers: ExternProviders) -> Self {
83-
QuerySystem {
84-
local_providers: Box::new(local_providers),
85-
extern_providers: Box::new(extern_providers),
86-
arenas: Default::default(),
87-
caches: Default::default(),
88-
}
89-
}
90-
}
91-
9280
#[derive(Copy, Clone)]
9381
pub struct TyCtxtAt<'tcx> {
9482
pub tcx: TyCtxt<'tcx>,

compiler/rustc_query_impl/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ use rustc_data_structures::sync::AtomicU64;
2121
use rustc_middle::arena::Arena;
2222
use rustc_middle::dep_graph::{self, DepKindStruct};
2323
use rustc_middle::query::Key;
24-
use rustc_middle::ty::query::QueryEngine;
2524
use rustc_middle::ty::query::{
2625
query_keys, query_provided, query_provided_to_value, query_storage, query_values,
2726
};
27+
use rustc_middle::ty::query::{ExternProviders, Providers, QueryEngine};
2828
use rustc_middle::ty::TyCtxt;
2929
use rustc_span::Span;
3030

compiler/rustc_query_impl/src/plumbing.rs

+16-9
Original file line numberDiff line numberDiff line change
@@ -278,13 +278,13 @@ macro_rules! hash_result {
278278

279279
macro_rules! get_provider {
280280
([][$tcx:expr, $name:ident, $key:expr]) => {{
281-
$tcx.query_system.local_providers.$name
281+
$tcx.queries.local_providers.$name
282282
}};
283283
([(separate_provide_extern) $($rest:tt)*][$tcx:expr, $name:ident, $key:expr]) => {{
284284
if $key.query_crate_is_local() {
285-
$tcx.query_system.local_providers.$name
285+
$tcx.queries.local_providers.$name
286286
} else {
287-
$tcx.query_system.extern_providers.$name
287+
$tcx.queries.extern_providers.$name
288288
}
289289
}};
290290
([$other:tt $($modifiers:tt)*][$($args:tt)*]) => {
@@ -500,12 +500,11 @@ macro_rules! define_queries {
500500
}
501501

502502
#[inline]
503-
// key is only sometimes used
504503
#[allow(unused_variables)]
505-
fn compute(tcx: TyCtxt<'tcx>, key: Self::Key) -> Self::Value {
504+
fn compute(qcx: QueryCtxt<'tcx>, key: Self::Key) -> Self::Value {
506505
query_provided_to_value::$name(
507-
tcx,
508-
get_provider!([$($modifiers)*][tcx, $name, key])(tcx, key)
506+
qcx.tcx,
507+
get_provider!([$($modifiers)*][qcx, $name, key])(qcx.tcx, key)
509508
)
510509
}
511510

@@ -664,12 +663,18 @@ macro_rules! define_queries {
664663
}
665664
}
666665

667-
use crate::OnDiskCache;
666+
use crate::{ExternProviders, OnDiskCache, Providers};
668667

669668
impl<'tcx> Queries<'tcx> {
670-
pub fn new(on_disk_cache: Option<OnDiskCache<'tcx>>) -> Self {
669+
pub fn new(
670+
local_providers: Providers,
671+
extern_providers: ExternProviders,
672+
on_disk_cache: Option<OnDiskCache<'tcx>>,
673+
) -> Self {
671674
use crate::query_structs;
672675
Queries {
676+
local_providers: Box::new(local_providers),
677+
extern_providers: Box::new(extern_providers),
673678
query_structs: make_dep_kind_array!(query_structs).to_vec(),
674679
on_disk_cache,
675680
jobs: AtomicU64::new(1),
@@ -683,6 +688,8 @@ macro_rules! define_queries_struct {
683688
input: ($(([$($modifiers:tt)*] [$($attr:tt)*] [$name:ident]))*)) => {
684689
#[derive(Default)]
685690
pub struct Queries<'tcx> {
691+
local_providers: Box<Providers>,
692+
extern_providers: Box<ExternProviders>,
686693
query_structs: Vec<$crate::plumbing::QueryStruct<'tcx>>,
687694
pub on_disk_cache: Option<OnDiskCache<'tcx>>,
688695
jobs: AtomicU64,

compiler/rustc_query_system/src/query/config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub trait QueryConfig<Qcx: QueryContext> {
3939
// Don't use this method to compute query results, instead use the methods on TyCtxt
4040
fn execute_query(tcx: Qcx::DepContext, k: Self::Key) -> Self::Value;
4141

42-
fn compute(tcx: Qcx::DepContext, key: Self::Key) -> Self::Value;
42+
fn compute(tcx: Qcx, key: Self::Key) -> Self::Value;
4343

4444
fn try_load_from_disk(qcx: Qcx, idx: &Self::Key) -> TryLoadFromDisk<Qcx, Self>;
4545

compiler/rustc_query_system/src/query/plumbing.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -425,8 +425,7 @@ where
425425
// Fast path for when incr. comp. is off.
426426
if !dep_graph.is_fully_enabled() {
427427
let prof_timer = qcx.dep_context().profiler().query_provider();
428-
let result =
429-
qcx.start_query(job_id, Q::DEPTH_LIMIT, None, || Q::compute(*qcx.dep_context(), key));
428+
let result = qcx.start_query(job_id, Q::DEPTH_LIMIT, None, || Q::compute(qcx, key));
430429
let dep_node_index = dep_graph.next_virtual_depnode_index();
431430
prof_timer.finish_with_query_invocation_id(dep_node_index.into());
432431
return (result, dep_node_index);
@@ -452,16 +451,15 @@ where
452451
let (result, dep_node_index) =
453452
qcx.start_query(job_id, Q::DEPTH_LIMIT, Some(&diagnostics), || {
454453
if Q::ANON {
455-
return dep_graph.with_anon_task(*qcx.dep_context(), Q::DEP_KIND, || {
456-
Q::compute(*qcx.dep_context(), key)
457-
});
454+
return dep_graph
455+
.with_anon_task(*qcx.dep_context(), Q::DEP_KIND, || Q::compute(qcx, key));
458456
}
459457

460458
// `to_dep_node` is expensive for some `DepKind`s.
461459
let dep_node =
462460
dep_node_opt.unwrap_or_else(|| Q::construct_dep_node(*qcx.dep_context(), &key));
463461

464-
dep_graph.with_task(dep_node, *qcx.dep_context(), key, Q::compute, Q::HASH_RESULT)
462+
dep_graph.with_task(dep_node, qcx, key, Q::compute, Q::HASH_RESULT)
465463
});
466464

467465
prof_timer.finish_with_query_invocation_id(dep_node_index.into());
@@ -552,7 +550,7 @@ where
552550
let prof_timer = qcx.dep_context().profiler().query_provider();
553551

554552
// The dep-graph for this computation is already in-place.
555-
let result = dep_graph.with_ignore(|| Q::compute(*qcx.dep_context(), key.clone()));
553+
let result = dep_graph.with_ignore(|| Q::compute(qcx, key.clone()));
556554

557555
prof_timer.finish_with_query_invocation_id(dep_node_index.into());
558556

0 commit comments

Comments
 (0)