diff --git a/compiler/rustc_middle/src/query/inner.rs b/compiler/rustc_middle/src/query/inner.rs index 402c448a1fa3a..3124a9f76c655 100644 --- a/compiler/rustc_middle/src/query/inner.rs +++ b/compiler/rustc_middle/src/query/inner.rs @@ -6,7 +6,7 @@ use rustc_span::{DUMMY_SP, ErrorGuaranteed, Span}; use crate::dep_graph; use crate::dep_graph::DepNodeKey; use crate::query::erase::{self, Erasable, Erased}; -use crate::query::{EnsureMode, QueryCache, QueryMode, QueryVTable}; +use crate::query::{QueryCache, QueryMode, QueryVTable}; use crate::ty::TyCtxt; /// Checks whether there is already a value for this key in the in-memory @@ -28,8 +28,8 @@ where } } -/// Shared implementation of `tcx.$query(..)` and `tcx.at(span).$query(..)` -/// for all queries. +/// Shared implementation of `tcx.$query(..)`, `tcx.at(span).$query(..)` and +/// `tcx.ensure_done().$query(..)` for all queries. #[inline(always)] pub(crate) fn query_get_at<'tcx, C>( tcx: TyCtxt<'tcx>, @@ -46,21 +46,19 @@ where } } -/// Shared implementation of `tcx.ensure_ok().$query(..)` and -/// `tcx.ensure_done().$query(..)` for all queries. +/// Implementation of `tcx.ensure_ok().$query(..)` for all queries. #[inline] -pub(crate) fn query_ensure_ok_or_done<'tcx, C>( +pub(crate) fn query_ensure_ok<'tcx, C>( tcx: TyCtxt<'tcx>, query: &'tcx QueryVTable<'tcx, C>, key: C::Key, - ensure_mode: EnsureMode, ) where C: QueryCache, { match try_get_cached(tcx, &query.cache, key) { Some(_value) => {} None => { - (query.execute_query_fn)(tcx, DUMMY_SP, key, QueryMode::Ensure { ensure_mode }); + (query.execute_query_fn)(tcx, DUMMY_SP, key, QueryMode::Ensure); } } } @@ -87,12 +85,7 @@ where match try_get_cached(tcx, &query.cache, key) { Some(value) => convert(value), None => { - match (query.execute_query_fn)( - tcx, - DUMMY_SP, - key, - QueryMode::Ensure { ensure_mode: EnsureMode::Ok }, - ) { + match (query.execute_query_fn)(tcx, DUMMY_SP, key, QueryMode::Ensure) { // We executed the query. Convert the successful result. Some(res) => convert(res), diff --git a/compiler/rustc_middle/src/query/mod.rs b/compiler/rustc_middle/src/query/mod.rs index 9c012f2da4dfc..96533c944943f 100644 --- a/compiler/rustc_middle/src/query/mod.rs +++ b/compiler/rustc_middle/src/query/mod.rs @@ -5,8 +5,8 @@ pub use self::into_query_key::IntoQueryKey; pub use self::job::{QueryJob, QueryJobId, QueryLatch, QueryWaiter}; pub use self::keys::{AsLocalQueryKey, LocalCrate, QueryKey}; pub use self::plumbing::{ - ActiveKeyStatus, CycleError, EnsureMode, QueryMode, QueryState, QuerySystem, QueryVTable, - TyCtxtAt, TyCtxtEnsureDone, TyCtxtEnsureOk, TyCtxtEnsureResult, + ActiveKeyStatus, CycleError, QueryMode, QueryState, QuerySystem, QueryVTable, TyCtxtAt, + TyCtxtEnsureDone, TyCtxtEnsureOk, TyCtxtEnsureResult, }; pub use self::stack::QueryStackFrame; pub use crate::queries::Providers; diff --git a/compiler/rustc_middle/src/query/plumbing.rs b/compiler/rustc_middle/src/query/plumbing.rs index 7d94d60523fb1..84cd15f5b8083 100644 --- a/compiler/rustc_middle/src/query/plumbing.rs +++ b/compiler/rustc_middle/src/query/plumbing.rs @@ -57,20 +57,10 @@ pub struct CycleError<'tcx> { #[derive(Debug)] pub enum QueryMode { - /// This is a normal query call to `tcx.$query(..)` or `tcx.at(span).$query(..)`. + /// This is a query call to `tcx.$query(..)`, `tcx.at(span).$query(..)` or `tcx.ensure_done().$query(..)`. Get, - /// This is a call to `tcx.ensure_ok().$query(..)` or `tcx.ensure_done().$query(..)`. - Ensure { ensure_mode: EnsureMode }, -} - -/// Distinguishes between `tcx.ensure_ok()` and `tcx.ensure_done()` in shared -/// code paths that handle both modes. -#[derive(Debug)] -pub enum EnsureMode { - /// Corresponds to [`TyCtxt::ensure_ok`]. - Ok, - /// Corresponds to [`TyCtxt::ensure_done`]. - Done, + /// This is a call to `tcx.ensure_ok().$query(..)`. + Ensure, } /// Stores data and metadata (e.g. function pointers) for a particular query. @@ -240,20 +230,13 @@ impl<'tcx> TyCtxt<'tcx> { TyCtxtEnsureResult { tcx: self } } - /// Wrapper that calls queries in a special "ensure done" mode, for callers - /// that don't need the return value and just want to guarantee that the - /// query won't be executed in the future, by executing it now if necessary. + /// Wrapper that calls queries where callers don't need the return value and + /// just want to guarantee that the query won't be executed in the future. /// /// This is useful for queries that read from a [`Steal`] value, to ensure /// that they are executed before the query that will steal the value. /// - /// Unlike [`Self::ensure_ok`], a query with all-green inputs will only be - /// skipped if its return value is stored in the disk-cache. This is still - /// more efficient than a regular query, because in that situation the - /// return value doesn't necessarily need to be decoded. - /// - /// (As with all query calls, execution is also skipped if the query result - /// is already cached in memory.) + /// Currently this causes the query to be executed normally, but this behavior may change. /// /// [`Steal`]: rustc_data_structures::steal::Steal #[inline(always)] @@ -578,11 +561,10 @@ macro_rules! define_callbacks { $(#[$attr])* #[inline(always)] pub fn $name(self, key: maybe_into_query_key!($($K)*)) { - $crate::query::inner::query_ensure_ok_or_done( + $crate::query::inner::query_ensure_ok( self.tcx, &self.tcx.query_system.query_vtables.$name, $crate::query::IntoQueryKey::into_query_key(key), - $crate::query::EnsureMode::Ok, ) } )* @@ -612,11 +594,13 @@ macro_rules! define_callbacks { $(#[$attr])* #[inline(always)] pub fn $name(self, key: maybe_into_query_key!($($K)*)) { - $crate::query::inner::query_ensure_ok_or_done( + // This has the same implementation as `tcx.$query(..)` as it isn't currently + // beneficial to have an optimized variant due to how promotion works. + $crate::query::inner::query_get_at( self.tcx, + DUMMY_SP, &self.tcx.query_system.query_vtables.$name, $crate::query::IntoQueryKey::into_query_key(key), - $crate::query::EnsureMode::Done, ); } )* diff --git a/compiler/rustc_query_impl/src/execution.rs b/compiler/rustc_query_impl/src/execution.rs index 78ead0cf14f1b..d15bf2f0c8123 100644 --- a/compiler/rustc_query_impl/src/execution.rs +++ b/compiler/rustc_query_impl/src/execution.rs @@ -8,8 +8,8 @@ use rustc_data_structures::{outline, sharded, sync}; use rustc_errors::FatalError; use rustc_middle::dep_graph::{DepGraphData, DepNodeKey, SerializedDepNodeIndex}; use rustc_middle::query::{ - ActiveKeyStatus, CycleError, EnsureMode, QueryCache, QueryJob, QueryJobId, QueryKey, - QueryLatch, QueryMode, QueryState, QueryVTable, + ActiveKeyStatus, CycleError, QueryCache, QueryJob, QueryJobId, QueryKey, QueryLatch, QueryMode, + QueryState, QueryVTable, }; use rustc_middle::ty::TyCtxt; use rustc_middle::verify_ich::incremental_verify_ich; @@ -18,7 +18,7 @@ use tracing::warn; use crate::dep_graph::{DepNode, DepNodeIndex}; use crate::job::{QueryJobInfo, QueryJobMap, find_cycle_in_stack, report_cycle}; -use crate::plumbing::{current_query_job, loadable_from_disk, next_job_id, start_query}; +use crate::plumbing::{current_query_job, next_job_id, start_query}; use crate::query_impl::for_each_query_vtable; #[inline] @@ -546,7 +546,7 @@ fn load_from_disk_or_invoke_provider_green<'tcx, C: QueryCache>( /// Return value struct for [`check_if_ensure_can_skip_execution`]. struct EnsureCanSkip { - /// If true, the current `tcx.ensure_ok()` or `tcx.ensure_done()` query + /// If true, the current `tcx.ensure_ok()` query /// can return early without actually trying to execute. skip_execution: bool, /// A dep node that was prepared while checking whether execution can be @@ -554,7 +554,7 @@ struct EnsureCanSkip { dep_node: Option, } -/// Checks whether a `tcx.ensure_ok()` or `tcx.ensure_done()` query call can +/// Checks whether a `tcx.ensure_ok()` query call can /// return early without actually trying to execute. /// /// This only makes sense during incremental compilation, because it relies @@ -565,7 +565,6 @@ fn check_if_ensure_can_skip_execution<'tcx, C: QueryCache>( query: &'tcx QueryVTable<'tcx, C>, tcx: TyCtxt<'tcx>, key: C::Key, - ensure_mode: EnsureMode, ) -> EnsureCanSkip { // Queries with `eval_always` should never skip execution. if query.eval_always { @@ -574,7 +573,7 @@ fn check_if_ensure_can_skip_execution<'tcx, C: QueryCache>( let dep_node = DepNode::construct(tcx, query.dep_kind, &key); - let serialized_dep_node_index = match tcx.dep_graph.try_mark_green(tcx, &dep_node) { + match tcx.dep_graph.try_mark_green(tcx, &dep_node) { None => { // A None return from `try_mark_green` means that this is either // a new dep node or that the dep node has already been marked red. @@ -582,30 +581,17 @@ fn check_if_ensure_can_skip_execution<'tcx, C: QueryCache>( // DepNodeIndex. We must invoke the query itself. The performance cost // this introduces should be negligible as we'll immediately hit the // in-memory cache, or another query down the line will. - return EnsureCanSkip { skip_execution: false, dep_node: Some(dep_node) }; + EnsureCanSkip { skip_execution: false, dep_node: Some(dep_node) } } - Some((serialized_dep_node_index, dep_node_index)) => { + Some((_, dep_node_index)) => { tcx.dep_graph.read_index(dep_node_index); tcx.prof.query_cache_hit(dep_node_index.into()); - serialized_dep_node_index - } - }; - match ensure_mode { - EnsureMode::Ok => { // In ensure-ok mode, we can skip execution for this key if the node // is green. It must have succeeded in the previous session, and // therefore would succeed in the current session if executed. EnsureCanSkip { skip_execution: true, dep_node: None } } - EnsureMode::Done => { - // In ensure-done mode, we can only skip execution for this key if - // there's a disk-cached value available to load later if needed, - // which guarantees the query provider will never run for this key. - let is_loadable = (query.will_cache_on_disk_for_key_fn)(tcx, key) - && loadable_from_disk(tcx, serialized_dep_node_index); - EnsureCanSkip { skip_execution: is_loadable, dep_node: Some(dep_node) } - } } } @@ -635,13 +621,13 @@ pub(super) fn execute_query_incr_inner<'tcx, C: QueryCache>( ) -> Option { debug_assert!(tcx.dep_graph.is_fully_enabled()); - // Check if query execution can be skipped, for `ensure_ok` or `ensure_done`. + // Check if query execution can be skipped, for `ensure_ok`. // This might have the side-effect of creating a suitable DepNode, which // we should reuse for execution instead of creating a new one. let dep_node: Option = match mode { - QueryMode::Ensure { ensure_mode } => { + QueryMode::Ensure => { let EnsureCanSkip { skip_execution, dep_node } = - check_if_ensure_can_skip_execution(query, tcx, key, ensure_mode); + check_if_ensure_can_skip_execution(query, tcx, key); if skip_execution { // Return early to skip execution. return None; diff --git a/compiler/rustc_query_impl/src/plumbing.rs b/compiler/rustc_query_impl/src/plumbing.rs index b8aa125aaf96b..39a32345dcd85 100644 --- a/compiler/rustc_query_impl/src/plumbing.rs +++ b/compiler/rustc_query_impl/src/plumbing.rs @@ -189,14 +189,6 @@ pub(crate) fn promote_from_disk_inner<'tcx, Q: GetQueryVTable<'tcx>>( } } -pub(crate) fn loadable_from_disk<'tcx>(tcx: TyCtxt<'tcx>, id: SerializedDepNodeIndex) -> bool { - if let Some(cache) = tcx.query_system.on_disk_cache.as_ref() { - cache.loadable_from_disk(id) - } else { - false - } -} - pub(crate) fn try_load_from_disk<'tcx, V>( tcx: TyCtxt<'tcx>, prev_index: SerializedDepNodeIndex,