diff --git a/compiler/rustc_query_impl/src/execution.rs b/compiler/rustc_query_impl/src/execution.rs index e58e626a7dfae..5f771f6cd6298 100644 --- a/compiler/rustc_query_impl/src/execution.rs +++ b/compiler/rustc_query_impl/src/execution.rs @@ -7,7 +7,7 @@ use rustc_data_structures::{outline, sharded, sync}; use rustc_errors::{Diag, FatalError, StashKey}; use rustc_middle::dep_graph::DepsType; use rustc_middle::ty::TyCtxt; -use rustc_query_system::dep_graph::{DepGraphData, DepNodeKey, HasDepContext}; +use rustc_query_system::dep_graph::{DepGraphData, DepNodeKey}; use rustc_query_system::query::{ ActiveKeyStatus, CycleError, CycleErrorHandling, QueryCache, QueryContext, QueryDispatcher, QueryJob, QueryJobId, QueryJobInfo, QueryLatch, QueryMap, QueryMode, QueryStackDeferred, @@ -482,6 +482,7 @@ where dep_graph_data.with_task( dep_node, + qcx.tcx, (qcx, query), key, |(qcx, query), key| query.compute(qcx, key), diff --git a/compiler/rustc_query_impl/src/plumbing.rs b/compiler/rustc_query_impl/src/plumbing.rs index 676d01be3385b..d4eb73906a0d1 100644 --- a/compiler/rustc_query_impl/src/plumbing.rs +++ b/compiler/rustc_query_impl/src/plumbing.rs @@ -26,7 +26,7 @@ use rustc_middle::ty::codec::TyEncoder; use rustc_middle::ty::print::with_reduced_queries; use rustc_middle::ty::tls::{self, ImplicitCtxt}; use rustc_middle::ty::{self, TyCtxt}; -use rustc_query_system::dep_graph::{DepNodeKey, FingerprintStyle, HasDepContext}; +use rustc_query_system::dep_graph::{DepNodeKey, FingerprintStyle}; use rustc_query_system::ich::StableHashingContext; use rustc_query_system::query::{ QueryCache, QueryContext, QueryDispatcher, QueryJobId, QueryMap, QuerySideEffect, @@ -119,7 +119,7 @@ impl<'tcx> QueryCtxt<'tcx> { } } -impl<'tcx> HasDepContext for QueryCtxt<'tcx> { +impl<'tcx> QueryContext<'tcx> for QueryCtxt<'tcx> { type Deps = DepsType; type DepContext = TyCtxt<'tcx>; @@ -127,9 +127,7 @@ impl<'tcx> HasDepContext for QueryCtxt<'tcx> { fn dep_context(&self) -> &Self::DepContext { &self.tcx } -} -impl<'tcx> QueryContext<'tcx> for QueryCtxt<'tcx> { #[inline] fn jobserver_proxy(&self) -> &Proxy { &self.tcx.jobserver_proxy diff --git a/compiler/rustc_query_system/src/dep_graph/graph.rs b/compiler/rustc_query_system/src/dep_graph/graph.rs index 151bddc3f067b..39a75bb45b30d 100644 --- a/compiler/rustc_query_system/src/dep_graph/graph.rs +++ b/compiler/rustc_query_system/src/dep_graph/graph.rs @@ -23,7 +23,7 @@ use {super::debug::EdgeFilter, std::env}; use super::query::DepGraphQuery; use super::serialized::{GraphEncoder, SerializedDepGraph, SerializedDepNodeIndex}; -use super::{DepContext, DepKind, DepNode, Deps, HasDepContext, WorkProductId}; +use super::{DepContext, DepKind, DepNode, Deps, WorkProductId}; use crate::dep_graph::edges::EdgesVec; use crate::ich::StableHashingContext; use crate::query::{QueryContext, QuerySideEffect}; @@ -260,7 +260,7 @@ impl DepGraph { } #[inline(always)] - pub fn with_task, A: Debug, R>( + pub fn with_task, A: Debug, R>( &self, key: DepNode, cx: Ctxt, @@ -269,7 +269,7 @@ impl DepGraph { hash_result: Option, &R) -> Fingerprint>, ) -> (R, DepNodeIndex) { match self.data() { - Some(data) => data.with_task(key, cx, arg, task, hash_result), + Some(data) => data.with_task(key, cx, cx, arg, task, hash_result), None => (task(cx, arg), self.next_virtual_depnode_index()), } } @@ -323,12 +323,13 @@ impl DepGraphData { /// /// [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/queries/incremental-compilation.html #[inline(always)] - pub fn with_task, A: Debug, R>( + pub fn with_task, A: Debug, C: Copy, R>( &self, key: DepNode, cx: Ctxt, + task_context: C, arg: A, - task: fn(Ctxt, A) -> R, + task: fn(C, A) -> R, hash_result: Option, &R) -> Fingerprint>, ) -> (R, DepNodeIndex) { // If the following assertion triggers, it can have two reasons: @@ -336,20 +337,16 @@ impl DepGraphData { // in `DepGraph::try_mark_green()`. // 2. Two distinct query keys get mapped to the same `DepNode` // (see for example #48923). - self.assert_dep_node_not_yet_allocated_in_current_session( - cx.dep_context().sess(), - &key, - || { - format!( - "forcing query with already existing `DepNode`\n\ + self.assert_dep_node_not_yet_allocated_in_current_session(cx.sess(), &key, || { + format!( + "forcing query with already existing `DepNode`\n\ - query-key: {arg:?}\n\ - dep-node: {key:?}" - ) - }, - ); + ) + }); - let with_deps = |task_deps| D::with_deps(task_deps, || task(cx, arg)); - let (result, edges) = if cx.dep_context().is_eval_always(key.kind) { + let with_deps = |task_deps| D::with_deps(task_deps, || task(task_context, arg)); + let (result, edges) = if cx.is_eval_always(key.kind) { (with_deps(TaskDepsRef::EvalAlways), EdgesVec::new()) } else { let task_deps = Lock::new(TaskDeps::new( @@ -360,8 +357,7 @@ impl DepGraphData { (with_deps(TaskDepsRef::Allow(&task_deps)), task_deps.into_inner().reads) }; - let dcx = cx.dep_context(); - let dep_node_index = self.hash_result_and_alloc_node(dcx, key, edges, &result, hash_result); + let dep_node_index = self.hash_result_and_alloc_node(cx, key, edges, &result, hash_result); (result, dep_node_index) } @@ -448,7 +444,7 @@ impl DepGraphData { /// Intern the new `DepNode` with the dependencies up-to-now. fn hash_result_and_alloc_node, R>( &self, - cx: &Ctxt, + cx: Ctxt, node: DepNode, edges: EdgesVec, result: &R, @@ -617,7 +613,7 @@ impl DepGraph { } }); - data.hash_result_and_alloc_node(&cx, node, edges, result, hash_result) + data.hash_result_and_alloc_node(cx, node, edges, result, hash_result) } else { // Incremental compilation is turned off. We just execute the task // without tracking. We still provide a dep-node index that uniquely diff --git a/compiler/rustc_query_system/src/dep_graph/mod.rs b/compiler/rustc_query_system/src/dep_graph/mod.rs index da110ad2c77c3..2be1d89d5c2e9 100644 --- a/compiler/rustc_query_system/src/dep_graph/mod.rs +++ b/compiler/rustc_query_system/src/dep_graph/mod.rs @@ -119,31 +119,6 @@ pub trait Deps: DynSync { const DEP_KIND_MAX: u16; } -pub trait HasDepContext: Copy { - type Deps: self::Deps; - type DepContext: self::DepContext; - - fn dep_context(&self) -> &Self::DepContext; -} - -impl HasDepContext for T { - type Deps = T::Deps; - type DepContext = Self; - - fn dep_context(&self) -> &Self::DepContext { - self - } -} - -impl HasDepContext for (T, Q) { - type Deps = T::Deps; - type DepContext = T::DepContext; - - fn dep_context(&self) -> &Self::DepContext { - self.0.dep_context() - } -} - /// Describes the contents of the fingerprint generated by a given query. /// /// This is mainly for determining whether and how we can reconstruct a key diff --git a/compiler/rustc_query_system/src/query/dispatcher.rs b/compiler/rustc_query_system/src/query/dispatcher.rs index 840b09024ffa9..0c8e41fe074b0 100644 --- a/compiler/rustc_query_system/src/query/dispatcher.rs +++ b/compiler/rustc_query_system/src/query/dispatcher.rs @@ -5,17 +5,17 @@ use rustc_data_structures::fingerprint::Fingerprint; use rustc_span::ErrorGuaranteed; use super::QueryStackFrameExtra; -use crate::dep_graph::{DepKind, DepNode, DepNodeKey, HasDepContext, SerializedDepNodeIndex}; +use crate::dep_graph::{DepKind, DepNode, DepNodeKey, SerializedDepNodeIndex}; use crate::ich::StableHashingContext; use crate::query::caches::QueryCache; use crate::query::{CycleError, CycleErrorHandling, DepNodeIndex, QueryContext, QueryState}; pub type HashResult = Option, &V) -> Fingerprint>; -/// Unambiguous shorthand for `::DepContext`. +/// Unambiguous shorthand for `>::DepContext`. #[expect(type_alias_bounds)] type DepContextOf<'tcx, This: QueryDispatcher<'tcx>> = - <>::Qcx as HasDepContext>::DepContext; + <>::Qcx as QueryContext<'tcx>>::DepContext; /// Trait that can be used as a vtable for a single query, providing operations /// and metadata for that query. diff --git a/compiler/rustc_query_system/src/query/mod.rs b/compiler/rustc_query_system/src/query/mod.rs index 29a572b726f0c..4c05d455aac91 100644 --- a/compiler/rustc_query_system/src/query/mod.rs +++ b/compiler/rustc_query_system/src/query/mod.rs @@ -19,7 +19,7 @@ pub use self::job::{ print_query_stack, report_cycle, }; pub use self::plumbing::*; -use crate::dep_graph::{DepKind, DepNodeIndex, HasDepContext, SerializedDepNodeIndex}; +use crate::dep_graph::{DepContext, DepKind, DepNodeIndex, Deps, SerializedDepNodeIndex}; mod caches; mod dispatcher; @@ -156,7 +156,12 @@ pub enum QuerySideEffect { Diagnostic(DiagInner), } -pub trait QueryContext<'tcx>: HasDepContext { +pub trait QueryContext<'tcx>: Copy { + type Deps: Deps; + type DepContext: DepContext; + + fn dep_context(&self) -> &Self::DepContext; + /// Gets a jobserver reference which is used to release then acquire /// a token while waiting on a query. fn jobserver_proxy(&self) -> &Proxy;