From 8b0dc1ece0a6fd515b7bdb5c3d28f2fdd54bef61 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Wed, 11 Feb 2026 13:16:31 +1100 Subject: [PATCH] Move `rustc_query_system::query::job` to `rustc_middle`. This includes the types `QueryInfo`, `QueryJob`, `QueryJobId`, `QueryWaiter`, `QueryLatch`, and `QueryLatchInfo`. `CycleError` and `QueryStack*` had to come along too, due to type interdependencies. The `QueryStack*` types are put into a new submodule `rustc_middle::query::stack`. --- Cargo.lock | 4 +- compiler/rustc_middle/Cargo.toml | 1 + .../src/query/job.rs | 15 ++- compiler/rustc_middle/src/query/mod.rs | 7 +- compiler/rustc_middle/src/query/plumbing.rs | 21 +++- compiler/rustc_middle/src/query/stack.rs | 112 ++++++++++++++++++ compiler/rustc_middle/src/ty/context/tls.rs | 2 +- compiler/rustc_query_impl/src/execution.rs | 10 +- compiler/rustc_query_impl/src/job.rs | 2 +- compiler/rustc_query_impl/src/lib.rs | 4 +- compiler/rustc_query_impl/src/plumbing.rs | 9 +- compiler/rustc_query_impl/src/values.rs | 2 +- compiler/rustc_query_system/Cargo.toml | 3 - compiler/rustc_query_system/src/query/mod.rs | 112 +----------------- .../rustc_query_system/src/query/plumbing.rs | 21 +--- 15 files changed, 163 insertions(+), 162 deletions(-) rename compiler/{rustc_query_system => rustc_middle}/src/query/job.rs (92%) create mode 100644 compiler/rustc_middle/src/query/stack.rs diff --git a/Cargo.lock b/Cargo.lock index 4f98a3facf9b..9b8506c25473 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4226,6 +4226,7 @@ dependencies = [ "bitflags", "either", "gsgdt", + "parking_lot", "polonius-engine", "rustc_abi", "rustc_apfloat", @@ -4512,20 +4513,17 @@ dependencies = [ name = "rustc_query_system" version = "0.0.0" dependencies = [ - "parking_lot", "rustc_abi", "rustc_ast", "rustc_data_structures", "rustc_errors", "rustc_feature", - "rustc_hashes", "rustc_hir", "rustc_index", "rustc_macros", "rustc_serialize", "rustc_session", "rustc_span", - "rustc_thread_pool", "smallvec", "tracing", ] diff --git a/compiler/rustc_middle/Cargo.toml b/compiler/rustc_middle/Cargo.toml index f9d5e7c02789..121e77614725 100644 --- a/compiler/rustc_middle/Cargo.toml +++ b/compiler/rustc_middle/Cargo.toml @@ -8,6 +8,7 @@ edition = "2024" bitflags = "2.4.1" either = "1.5.0" gsgdt = "0.1.2" +parking_lot = "0.12" polonius-engine = "0.13.0" rustc_abi = { path = "../rustc_abi" } rustc_apfloat = "0.2.0" diff --git a/compiler/rustc_query_system/src/query/job.rs b/compiler/rustc_middle/src/query/job.rs similarity index 92% rename from compiler/rustc_query_system/src/query/job.rs rename to compiler/rustc_middle/src/query/job.rs index 7349fe223ef9..f1a2b3a34d0e 100644 --- a/compiler/rustc_query_system/src/query/job.rs +++ b/compiler/rustc_middle/src/query/job.rs @@ -6,9 +6,9 @@ use std::sync::Arc; use parking_lot::{Condvar, Mutex}; use rustc_span::Span; -use super::{QueryStackDeferred, QueryStackFrameExtra}; use crate::query::plumbing::CycleError; -use crate::query::{QueryContext, QueryStackFrame}; +use crate::query::stack::{QueryStackDeferred, QueryStackFrame, QueryStackFrameExtra}; +use crate::ty::TyCtxt; /// Represents a span and a query key. #[derive(Clone, Debug)] @@ -98,13 +98,13 @@ impl<'tcx> QueryLatch<'tcx> { /// Awaits for the query job to complete. pub fn wait_on( &self, - qcx: impl QueryContext<'tcx>, + tcx: TyCtxt<'tcx>, query: Option, span: Span, ) -> Result<(), CycleError>> { let waiter = Arc::new(QueryWaiter { query, span, cycle: Mutex::new(None), condvar: Condvar::new() }); - self.wait_on_inner(qcx, &waiter); + self.wait_on_inner(tcx, &waiter); // FIXME: Get rid of this lock. We have ownership of the QueryWaiter // although another thread may still have a Arc reference so we cannot // use Arc::get_mut @@ -116,7 +116,7 @@ impl<'tcx> QueryLatch<'tcx> { } /// Awaits the caller on this latch by blocking the current thread. - fn wait_on_inner(&self, qcx: impl QueryContext<'tcx>, waiter: &Arc>) { + fn wait_on_inner(&self, tcx: TyCtxt<'tcx>, waiter: &Arc>) { let mut info = self.info.lock(); if !info.complete { // We push the waiter on to the `waiters` list. It can be accessed inside @@ -129,12 +129,11 @@ impl<'tcx> QueryLatch<'tcx> { // we have to be in the `wait` call. This is ensured by the deadlock handler // getting the self.info lock. rustc_thread_pool::mark_blocked(); - let proxy = qcx.jobserver_proxy(); - proxy.release_thread(); + tcx.jobserver_proxy.release_thread(); waiter.condvar.wait(&mut info); // Release the lock before we potentially block in `acquire_thread` drop(info); - proxy.acquire_thread(); + tcx.jobserver_proxy.acquire_thread(); } } diff --git a/compiler/rustc_middle/src/query/mod.rs b/compiler/rustc_middle/src/query/mod.rs index eea809db1230..7083f160bd77 100644 --- a/compiler/rustc_middle/src/query/mod.rs +++ b/compiler/rustc_middle/src/query/mod.rs @@ -1,21 +1,26 @@ use rustc_hir::def_id::LocalDefId; pub use rustc_query_system::query::QueryMode; +pub use self::job::{QueryInfo, QueryJob, QueryJobId, QueryLatch, QueryWaiter}; pub use self::keys::{AsLocalKey, Key, LocalCrate}; pub use self::plumbing::{ - ActiveKeyStatus, IntoQueryParam, QueryState, TyCtxtAt, TyCtxtEnsureDone, TyCtxtEnsureOk, + ActiveKeyStatus, CycleError, IntoQueryParam, QueryState, TyCtxtAt, TyCtxtEnsureDone, + TyCtxtEnsureOk, }; +pub use self::stack::{QueryStackDeferred, QueryStackFrame, QueryStackFrameExtra}; pub use crate::queries::Providers; use crate::ty::TyCtxt; pub(crate) mod arena_cached; pub mod erase; pub(crate) mod inner; +mod job; mod keys; pub mod on_disk_cache; #[macro_use] pub mod plumbing; pub(crate) mod modifiers; +mod stack; pub fn describe_as_module(def_id: impl Into, tcx: TyCtxt<'_>) -> String { let def_id = def_id.into(); diff --git a/compiler/rustc_middle/src/query/plumbing.rs b/compiler/rustc_middle/src/query/plumbing.rs index 2b093b4be033..f2021978aad7 100644 --- a/compiler/rustc_middle/src/query/plumbing.rs +++ b/compiler/rustc_middle/src/query/plumbing.rs @@ -9,8 +9,7 @@ use rustc_hir::hir_id::OwnerId; use rustc_macros::HashStable; use rustc_query_system::dep_graph::{DepNodeIndex, SerializedDepNodeIndex}; use rustc_query_system::ich::StableHashingContext; -pub(crate) use rustc_query_system::query::QueryJobId; -use rustc_query_system::query::{CycleError, CycleErrorHandling, QueryCache, QueryJob}; +use rustc_query_system::query::{CycleErrorHandling, QueryCache}; use rustc_span::{ErrorGuaranteed, Span}; pub use sealed::IntoQueryParam; @@ -20,6 +19,8 @@ use crate::queries::{ ExternProviders, PerQueryVTables, Providers, QueryArenas, QueryCaches, QueryEngine, QueryStates, }; use crate::query::on_disk_cache::{CacheEncoder, EncodedDepNodeIndex, OnDiskCache}; +use crate::query::stack::{QueryStackDeferred, QueryStackFrame, QueryStackFrameExtra}; +use crate::query::{QueryInfo, QueryJob}; use crate::ty::TyCtxt; /// For a particular query, keeps track of "active" keys, i.e. keys whose @@ -67,6 +68,22 @@ pub type IsLoadableFromDiskFn<'tcx, Key> = pub type HashResult = Option, &V) -> Fingerprint>; +#[derive(Clone, Debug)] +pub struct CycleError { + /// The query and related span that uses the cycle. + pub usage: Option<(Span, QueryStackFrame)>, + pub cycle: Vec>, +} + +impl<'tcx> CycleError> { + pub fn lift(&self) -> CycleError { + CycleError { + usage: self.usage.as_ref().map(|(span, frame)| (*span, frame.lift())), + cycle: self.cycle.iter().map(|info| info.lift()).collect(), + } + } +} + /// Stores function pointers and other metadata for a particular query. /// /// Used indirectly by query plumbing in `rustc_query_system` via a trait, diff --git a/compiler/rustc_middle/src/query/stack.rs b/compiler/rustc_middle/src/query/stack.rs new file mode 100644 index 000000000000..b2b01517b7ee --- /dev/null +++ b/compiler/rustc_middle/src/query/stack.rs @@ -0,0 +1,112 @@ +use std::fmt::Debug; +use std::marker::PhantomData; +use std::mem::transmute; +use std::sync::Arc; + +use rustc_data_structures::sync::{DynSend, DynSync}; +use rustc_hashes::Hash64; +use rustc_hir::def::DefKind; +use rustc_span::Span; +use rustc_span::def_id::DefId; + +use crate::dep_graph::DepKind; + +/// Description of a frame in the query stack. +/// +/// This is mostly used in case of cycles for error reporting. +#[derive(Clone, Debug)] +pub struct QueryStackFrame { + /// This field initially stores a `QueryStackDeferred` during collection, + /// but can later be changed to `QueryStackFrameExtra` containing concrete information + /// by calling `lift`. This is done so that collecting query does not need to invoke + /// queries, instead `lift` will call queries in a more appropriate location. + pub info: I, + + pub dep_kind: DepKind, + /// This hash is used to deterministically pick + /// a query to remove cycles in the parallel compiler. + pub hash: Hash64, + pub def_id: Option, + /// A def-id that is extracted from a `Ty` in a query key + pub def_id_for_ty_in_cycle: Option, +} + +impl<'tcx> QueryStackFrame> { + #[inline] + pub fn new( + info: QueryStackDeferred<'tcx>, + dep_kind: DepKind, + hash: Hash64, + def_id: Option, + def_id_for_ty_in_cycle: Option, + ) -> Self { + Self { info, def_id, dep_kind, hash, def_id_for_ty_in_cycle } + } + + pub fn lift(&self) -> QueryStackFrame { + QueryStackFrame { + info: self.info.extract(), + dep_kind: self.dep_kind, + hash: self.hash, + def_id: self.def_id, + def_id_for_ty_in_cycle: self.def_id_for_ty_in_cycle, + } + } +} + +#[derive(Clone, Debug)] +pub struct QueryStackFrameExtra { + pub description: String, + pub span: Option, + pub def_kind: Option, +} + +impl QueryStackFrameExtra { + #[inline] + pub fn new(description: String, span: Option, def_kind: Option) -> Self { + Self { description, span, def_kind } + } + + // FIXME(eddyb) Get more valid `Span`s on queries. + #[inline] + pub fn default_span(&self, span: Span) -> Span { + if !span.is_dummy() { + return span; + } + self.span.unwrap_or(span) + } +} + +/// Track a 'side effect' for a particular query. +/// This is used to hold a closure which can create `QueryStackFrameExtra`. +#[derive(Clone)] +pub struct QueryStackDeferred<'tcx> { + _dummy: PhantomData<&'tcx ()>, + + // `extract` may contain references to 'tcx, but we can't tell drop checking that it won't + // access it in the destructor. + extract: Arc QueryStackFrameExtra + DynSync + DynSend>, +} + +impl<'tcx> QueryStackDeferred<'tcx> { + pub fn new( + context: C, + extract: fn(C) -> QueryStackFrameExtra, + ) -> Self { + let extract: Arc QueryStackFrameExtra + DynSync + DynSend + 'tcx> = + Arc::new(move || extract(context)); + // SAFETY: The `extract` closure does not access 'tcx in its destructor as the only + // captured variable is `context` which is Copy and cannot have a destructor. + Self { _dummy: PhantomData, extract: unsafe { transmute(extract) } } + } + + pub fn extract(&self) -> QueryStackFrameExtra { + (self.extract)() + } +} + +impl<'tcx> Debug for QueryStackDeferred<'tcx> { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.write_str("QueryStackDeferred") + } +} diff --git a/compiler/rustc_middle/src/ty/context/tls.rs b/compiler/rustc_middle/src/ty/context/tls.rs index a06f92792820..d37ad56c2e83 100644 --- a/compiler/rustc_middle/src/ty/context/tls.rs +++ b/compiler/rustc_middle/src/ty/context/tls.rs @@ -4,7 +4,7 @@ use rustc_data_structures::sync; use super::{GlobalCtxt, TyCtxt}; use crate::dep_graph::TaskDepsRef; -use crate::query::plumbing::QueryJobId; +use crate::query::QueryJobId; /// This is the implicit state of rustc. It contains the current /// `TyCtxt` and query. It is updated when creating a local interner or diff --git a/compiler/rustc_query_impl/src/execution.rs b/compiler/rustc_query_impl/src/execution.rs index 7e1c2faa18df..38150c154e08 100644 --- a/compiler/rustc_query_impl/src/execution.rs +++ b/compiler/rustc_query_impl/src/execution.rs @@ -6,12 +6,14 @@ use rustc_data_structures::stack::ensure_sufficient_stack; use rustc_data_structures::{outline, sharded, sync}; use rustc_errors::{Diag, FatalError, StashKey}; use rustc_middle::dep_graph::DepsType; -use rustc_middle::query::{ActiveKeyStatus, QueryState}; +use rustc_middle::query::{ + ActiveKeyStatus, CycleError, QueryJob, QueryJobId, QueryLatch, QueryStackDeferred, + QueryStackFrame, QueryState, +}; use rustc_middle::ty::TyCtxt; use rustc_query_system::dep_graph::{DepGraphData, DepNodeKey, HasDepContext}; use rustc_query_system::query::{ - CycleError, CycleErrorHandling, QueryCache, QueryJob, QueryJobId, QueryLatch, QueryMode, - QueryStackDeferred, QueryStackFrame, incremental_verify_ich, + CycleErrorHandling, QueryCache, QueryMode, incremental_verify_ich, }; use rustc_span::{DUMMY_SP, Span}; @@ -239,7 +241,7 @@ fn wait_for_query<'tcx, C: QueryCache, const FLAGS: QueryFlags>( // With parallel queries we might just have to wait on some other // thread. - let result = latch.wait_on(qcx, current, span); + let result = latch.wait_on(qcx.tcx, current, span); match result { Ok(()) => { diff --git a/compiler/rustc_query_impl/src/job.rs b/compiler/rustc_query_impl/src/job.rs index 19b8245b97e7..8e554d4ed4e6 100644 --- a/compiler/rustc_query_impl/src/job.rs +++ b/compiler/rustc_query_impl/src/job.rs @@ -5,7 +5,7 @@ use std::sync::Arc; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_errors::{Diag, DiagCtxtHandle}; use rustc_hir::def::DefKind; -use rustc_query_system::query::{ +use rustc_middle::query::{ CycleError, QueryInfo, QueryJob, QueryJobId, QueryLatch, QueryStackDeferred, QueryStackFrame, QueryWaiter, }; diff --git a/compiler/rustc_query_impl/src/lib.rs b/compiler/rustc_query_impl/src/lib.rs index 0ec4d94bcf72..02a86b5a4c65 100644 --- a/compiler/rustc_query_impl/src/lib.rs +++ b/compiler/rustc_query_impl/src/lib.rs @@ -16,14 +16,14 @@ use rustc_middle::dep_graph::{self, DepKind, DepNode, DepNodeIndex}; use rustc_middle::queries::{ self, ExternProviders, Providers, QueryCaches, QueryEngine, QueryStates, }; -use rustc_middle::query::AsLocalKey; use rustc_middle::query::on_disk_cache::{CacheEncoder, EncodedDepNodeIndex, OnDiskCache}; use rustc_middle::query::plumbing::{ HashResult, QueryState, QuerySystem, QuerySystemFns, QueryVTable, }; +use rustc_middle::query::{AsLocalKey, CycleError}; use rustc_middle::ty::TyCtxt; use rustc_query_system::dep_graph::SerializedDepNodeIndex; -use rustc_query_system::query::{CycleError, CycleErrorHandling, QueryCache, QueryMode}; +use rustc_query_system::query::{CycleErrorHandling, QueryCache, QueryMode}; use rustc_span::{ErrorGuaranteed, Span}; pub use crate::dep_kind_vtables::make_dep_kind_vtables; diff --git a/compiler/rustc_query_impl/src/plumbing.rs b/compiler/rustc_query_impl/src/plumbing.rs index 12cef31f58bb..1d549c6ecc69 100644 --- a/compiler/rustc_query_impl/src/plumbing.rs +++ b/compiler/rustc_query_impl/src/plumbing.rs @@ -18,20 +18,19 @@ use rustc_middle::dep_graph::DepKindVTable; use rustc_middle::dep_graph::{ self, DepContext, DepNode, DepNodeIndex, DepsType, SerializedDepNodeIndex, dep_kinds, }; -use rustc_middle::query::Key; use rustc_middle::query::on_disk_cache::{ AbsoluteBytePos, CacheDecoder, CacheEncoder, EncodedDepNodeIndex, }; use rustc_middle::query::plumbing::QueryVTable; +use rustc_middle::query::{ + Key, QueryJobId, QueryStackDeferred, QueryStackFrame, QueryStackFrameExtra, +}; 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, HasDepContext}; -use rustc_query_system::query::{ - QueryCache, QueryContext, QueryJobId, QuerySideEffect, QueryStackDeferred, QueryStackFrame, - QueryStackFrameExtra, -}; +use rustc_query_system::query::{QueryCache, QueryContext, QuerySideEffect}; use rustc_serialize::{Decodable, Encodable}; use rustc_span::def_id::LOCAL_CRATE; diff --git a/compiler/rustc_query_impl/src/values.rs b/compiler/rustc_query_impl/src/values.rs index 783e7a10d12a..67bc6893a320 100644 --- a/compiler/rustc_query_impl/src/values.rs +++ b/compiler/rustc_query_impl/src/values.rs @@ -8,10 +8,10 @@ use rustc_errors::{Applicability, MultiSpan, pluralize, struct_span_code_err}; use rustc_hir as hir; use rustc_hir::def::{DefKind, Res}; use rustc_middle::dep_graph::dep_kinds; +use rustc_middle::query::CycleError; use rustc_middle::query::plumbing::CyclePlaceholder; use rustc_middle::ty::{self, Representability, Ty, TyCtxt}; use rustc_middle::{bug, span_bug}; -use rustc_query_system::query::CycleError; use rustc_span::def_id::LocalDefId; use rustc_span::{ErrorGuaranteed, Span}; diff --git a/compiler/rustc_query_system/Cargo.toml b/compiler/rustc_query_system/Cargo.toml index 761a299eab77..d2a58b341048 100644 --- a/compiler/rustc_query_system/Cargo.toml +++ b/compiler/rustc_query_system/Cargo.toml @@ -5,20 +5,17 @@ edition = "2024" [dependencies] # tidy-alphabetical-start -parking_lot = "0.12" rustc_abi = { path = "../rustc_abi" } rustc_ast = { path = "../rustc_ast" } rustc_data_structures = { path = "../rustc_data_structures" } rustc_errors = { path = "../rustc_errors" } rustc_feature = { path = "../rustc_feature" } -rustc_hashes = { path = "../rustc_hashes" } rustc_hir = { path = "../rustc_hir" } rustc_index = { path = "../rustc_index" } rustc_macros = { path = "../rustc_macros" } rustc_serialize = { path = "../rustc_serialize" } rustc_session = { path = "../rustc_session" } rustc_span = { path = "../rustc_span" } -rustc_thread_pool = { path = "../rustc_thread_pool" } smallvec = { version = "1.8.1", features = ["union", "may_dangle"] } tracing = "0.1" # tidy-alphabetical-end diff --git a/compiler/rustc_query_system/src/query/mod.rs b/compiler/rustc_query_system/src/query/mod.rs index c33af941f802..8b84c1023b01 100644 --- a/compiler/rustc_query_system/src/query/mod.rs +++ b/compiler/rustc_query_system/src/query/mod.rs @@ -1,26 +1,16 @@ use std::fmt::Debug; -use std::marker::PhantomData; -use std::mem::transmute; -use std::sync::Arc; use rustc_data_structures::jobserver::Proxy; -use rustc_data_structures::sync::{DynSend, DynSync}; use rustc_errors::DiagInner; -use rustc_hashes::Hash64; -use rustc_hir::def::DefKind; use rustc_macros::{Decodable, Encodable}; -use rustc_span::Span; -use rustc_span::def_id::DefId; pub use self::caches::{ DefIdCache, DefaultCache, QueryCache, QueryCacheKey, SingleCache, VecCache, }; -pub use self::job::{QueryInfo, QueryJob, QueryJobId, QueryLatch, QueryWaiter}; pub use self::plumbing::*; -use crate::dep_graph::{DepKind, DepNodeIndex, HasDepContext, SerializedDepNodeIndex}; +use crate::dep_graph::{DepNodeIndex, HasDepContext, SerializedDepNodeIndex}; mod caches; -mod job; mod plumbing; /// How a particular query deals with query cycle errors. @@ -35,106 +25,6 @@ pub enum CycleErrorHandling { Stash, } -/// Description of a frame in the query stack. -/// -/// This is mostly used in case of cycles for error reporting. -#[derive(Clone, Debug)] -pub struct QueryStackFrame { - /// This field initially stores a `QueryStackDeferred` during collection, - /// but can later be changed to `QueryStackFrameExtra` containing concrete information - /// by calling `lift`. This is done so that collecting query does not need to invoke - /// queries, instead `lift` will call queries in a more appropriate location. - pub info: I, - - pub dep_kind: DepKind, - /// This hash is used to deterministically pick - /// a query to remove cycles in the parallel compiler. - pub hash: Hash64, - pub def_id: Option, - /// A def-id that is extracted from a `Ty` in a query key - pub def_id_for_ty_in_cycle: Option, -} - -impl<'tcx> QueryStackFrame> { - #[inline] - pub fn new( - info: QueryStackDeferred<'tcx>, - dep_kind: DepKind, - hash: Hash64, - def_id: Option, - def_id_for_ty_in_cycle: Option, - ) -> Self { - Self { info, def_id, dep_kind, hash, def_id_for_ty_in_cycle } - } - - fn lift(&self) -> QueryStackFrame { - QueryStackFrame { - info: self.info.extract(), - dep_kind: self.dep_kind, - hash: self.hash, - def_id: self.def_id, - def_id_for_ty_in_cycle: self.def_id_for_ty_in_cycle, - } - } -} - -#[derive(Clone, Debug)] -pub struct QueryStackFrameExtra { - pub description: String, - pub span: Option, - pub def_kind: Option, -} - -impl QueryStackFrameExtra { - #[inline] - pub fn new(description: String, span: Option, def_kind: Option) -> Self { - Self { description, span, def_kind } - } - - // FIXME(eddyb) Get more valid `Span`s on queries. - #[inline] - pub fn default_span(&self, span: Span) -> Span { - if !span.is_dummy() { - return span; - } - self.span.unwrap_or(span) - } -} - -/// Track a 'side effect' for a particular query. -/// This is used to hold a closure which can create `QueryStackFrameExtra`. -#[derive(Clone)] -pub struct QueryStackDeferred<'tcx> { - _dummy: PhantomData<&'tcx ()>, - - // `extract` may contain references to 'tcx, but we can't tell drop checking that it won't - // access it in the destructor. - extract: Arc QueryStackFrameExtra + DynSync + DynSend>, -} - -impl<'tcx> QueryStackDeferred<'tcx> { - pub fn new( - context: C, - extract: fn(C) -> QueryStackFrameExtra, - ) -> Self { - let extract: Arc QueryStackFrameExtra + DynSync + DynSend + 'tcx> = - Arc::new(move || extract(context)); - // SAFETY: The `extract` closure does not access 'tcx in its destructor as the only - // captured variable is `context` which is Copy and cannot have a destructor. - Self { _dummy: PhantomData, extract: unsafe { transmute(extract) } } - } - - pub fn extract(&self) -> QueryStackFrameExtra { - (self.extract)() - } -} - -impl<'tcx> Debug for QueryStackDeferred<'tcx> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.write_str("QueryStackDeferred") - } -} - /// Tracks 'side effects' for a particular query. /// This struct is saved to disk along with the query result, /// and loaded from disk if we mark the query as green. diff --git a/compiler/rustc_query_system/src/query/plumbing.rs b/compiler/rustc_query_system/src/query/plumbing.rs index 0cdc94cf4d88..d53b4a430b79 100644 --- a/compiler/rustc_query_system/src/query/plumbing.rs +++ b/compiler/rustc_query_system/src/query/plumbing.rs @@ -2,30 +2,11 @@ use std::cell::Cell; use std::fmt::Debug; use rustc_data_structures::fingerprint::Fingerprint; -use rustc_span::Span; use tracing::instrument; -use super::{QueryStackDeferred, QueryStackFrameExtra}; use crate::dep_graph::{DepContext, DepGraphData}; use crate::ich::StableHashingContext; -use crate::query::job::QueryInfo; -use crate::query::{QueryStackFrame, SerializedDepNodeIndex}; - -#[derive(Clone, Debug)] -pub struct CycleError { - /// The query and related span that uses the cycle. - pub usage: Option<(Span, QueryStackFrame)>, - pub cycle: Vec>, -} - -impl<'tcx> CycleError> { - pub fn lift(&self) -> CycleError { - CycleError { - usage: self.usage.as_ref().map(|(span, frame)| (*span, frame.lift())), - cycle: self.cycle.iter().map(|info| info.lift()).collect(), - } - } -} +use crate::query::SerializedDepNodeIndex; #[inline] #[instrument(skip(tcx, dep_graph_data, result, hash_result, format_value), level = "debug")]