Skip to content

Commit 42d7d52

Browse files
committed
Auto merge of #153472 - Zoxc:rem-ensure_done, r=petrochenkov
Remove `ensure_done` execution path This removes the `ensure_done` execution path as it doesn't have a performance impact. `ensure_done` calls are left as markers still.
2 parents 5930afc + 218a075 commit 42d7d52

5 files changed

Lines changed: 29 additions & 77 deletions

File tree

compiler/rustc_middle/src/query/inner.rs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_span::{DUMMY_SP, ErrorGuaranteed, Span};
66
use crate::dep_graph;
77
use crate::dep_graph::DepNodeKey;
88
use crate::query::erase::{self, Erasable, Erased};
9-
use crate::query::{EnsureMode, QueryCache, QueryMode, QueryVTable};
9+
use crate::query::{QueryCache, QueryMode, QueryVTable};
1010
use crate::ty::TyCtxt;
1111

1212
/// Checks whether there is already a value for this key in the in-memory
@@ -46,21 +46,19 @@ where
4646
}
4747
}
4848

49-
/// Shared implementation of `tcx.ensure_ok().$query(..)` and
50-
/// `tcx.ensure_done().$query(..)` for all queries.
49+
/// Implementation of `tcx.ensure_ok().$query(..)` for all queries.
5150
#[inline]
52-
pub(crate) fn query_ensure_ok_or_done<'tcx, C>(
51+
pub(crate) fn query_ensure_ok<'tcx, C>(
5352
tcx: TyCtxt<'tcx>,
5453
query: &'tcx QueryVTable<'tcx, C>,
5554
key: C::Key,
56-
ensure_mode: EnsureMode,
5755
) where
5856
C: QueryCache,
5957
{
6058
match try_get_cached(tcx, &query.cache, key) {
6159
Some(_value) => {}
6260
None => {
63-
(query.execute_query_fn)(tcx, DUMMY_SP, key, QueryMode::Ensure { ensure_mode });
61+
(query.execute_query_fn)(tcx, DUMMY_SP, key, QueryMode::EnsureOk);
6462
}
6563
}
6664
}
@@ -87,12 +85,7 @@ where
8785
match try_get_cached(tcx, &query.cache, key) {
8886
Some(value) => convert(value),
8987
None => {
90-
match (query.execute_query_fn)(
91-
tcx,
92-
DUMMY_SP,
93-
key,
94-
QueryMode::Ensure { ensure_mode: EnsureMode::Ok },
95-
) {
88+
match (query.execute_query_fn)(tcx, DUMMY_SP, key, QueryMode::EnsureOk) {
9689
// We executed the query. Convert the successful result.
9790
Some(res) => convert(res),
9891

compiler/rustc_middle/src/query/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ pub use self::into_query_key::IntoQueryKey;
55
pub use self::job::{QueryJob, QueryJobId, QueryLatch, QueryWaiter};
66
pub use self::keys::{LocalCrate, QueryKey};
77
pub use self::plumbing::{
8-
ActiveKeyStatus, Cycle, EnsureMode, QueryMode, QueryState, QuerySystem, QueryVTable, TyCtxtAt,
8+
ActiveKeyStatus, Cycle, QueryMode, QueryState, QuerySystem, QueryVTable, TyCtxtAt,
99
TyCtxtEnsureDone, TyCtxtEnsureOk, TyCtxtEnsureResult,
1010
};
1111
pub use self::stack::QueryStackFrame;

compiler/rustc_middle/src/query/plumbing.rs

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,8 @@ pub struct Cycle<'tcx> {
6161
pub enum QueryMode {
6262
/// This is a normal query call to `tcx.$query(..)` or `tcx.at(span).$query(..)`.
6363
Get,
64-
/// This is a call to `tcx.ensure_ok().$query(..)` or `tcx.ensure_done().$query(..)`.
65-
Ensure { ensure_mode: EnsureMode },
66-
}
67-
68-
/// Distinguishes between `tcx.ensure_ok()` and `tcx.ensure_done()` in shared
69-
/// code paths that handle both modes.
70-
#[derive(Debug)]
71-
pub enum EnsureMode {
72-
/// Corresponds to [`TyCtxt::ensure_ok`].
73-
Ok,
74-
/// Corresponds to [`TyCtxt::ensure_done`].
75-
Done,
64+
/// This is a call to `tcx.ensure_ok().$query(..)`.
65+
EnsureOk,
7666
}
7767

7868
/// Stores data and metadata (e.g. function pointers) for a particular query.
@@ -268,20 +258,13 @@ impl<'tcx> TyCtxt<'tcx> {
268258
TyCtxtEnsureResult { tcx: self }
269259
}
270260

271-
/// Wrapper that calls queries in a special "ensure done" mode, for callers
272-
/// that don't need the return value and just want to guarantee that the
273-
/// query won't be executed in the future, by executing it now if necessary.
261+
/// Wrapper that calls queries where callers don't need the return value and
262+
/// just want to guarantee that the query won't be executed in the future.
274263
///
275264
/// This is useful for queries that read from a [`Steal`] value, to ensure
276265
/// that they are executed before the query that will steal the value.
277266
///
278-
/// Unlike [`Self::ensure_ok`], a query with all-green inputs will only be
279-
/// skipped if its return value is stored in the disk-cache. This is still
280-
/// more efficient than a regular query, because in that situation the
281-
/// return value doesn't necessarily need to be decoded.
282-
///
283-
/// (As with all query calls, execution is also skipped if the query result
284-
/// is already cached in memory.)
267+
/// Currently this causes the query to be executed normally, but this behavior may change.
285268
///
286269
/// [`Steal`]: rustc_data_structures::steal::Steal
287270
#[inline(always)]
@@ -593,11 +576,10 @@ macro_rules! define_callbacks {
593576
$(#[$attr])*
594577
#[inline(always)]
595578
pub fn $name(self, key: maybe_into_query_key!($($K)*)) {
596-
$crate::query::inner::query_ensure_ok_or_done(
579+
$crate::query::inner::query_ensure_ok(
597580
self.tcx,
598581
&self.tcx.query_system.query_vtables.$name,
599582
$crate::query::IntoQueryKey::into_query_key(key),
600-
$crate::query::EnsureMode::Ok,
601583
)
602584
}
603585
)*
@@ -627,12 +609,9 @@ macro_rules! define_callbacks {
627609
$(#[$attr])*
628610
#[inline(always)]
629611
pub fn $name(self, key: maybe_into_query_key!($($K)*)) {
630-
$crate::query::inner::query_ensure_ok_or_done(
631-
self.tcx,
632-
&self.tcx.query_system.query_vtables.$name,
633-
$crate::query::IntoQueryKey::into_query_key(key),
634-
$crate::query::EnsureMode::Done,
635-
);
612+
// This has the same implementation as `tcx.$query(..)` as it isn't currently
613+
// beneficial to have an optimized variant due to how promotion works.
614+
let _ = self.tcx.$name(key);
636615
}
637616
)*
638617
}

compiler/rustc_query_impl/src/execution.rs

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ use rustc_data_structures::{defer, outline, sharded, sync};
88
use rustc_errors::FatalError;
99
use rustc_middle::dep_graph::{DepGraphData, DepNodeKey, SerializedDepNodeIndex};
1010
use rustc_middle::query::{
11-
ActiveKeyStatus, Cycle, EnsureMode, QueryCache, QueryJob, QueryJobId, QueryKey, QueryLatch,
12-
QueryMode, QueryState, QueryVTable,
11+
ActiveKeyStatus, Cycle, QueryCache, QueryJob, QueryJobId, QueryKey, QueryLatch, QueryMode,
12+
QueryState, QueryVTable,
1313
};
1414
use rustc_middle::ty::TyCtxt;
1515
use rustc_middle::verify_ich::incremental_verify_ich;
@@ -19,7 +19,7 @@ use tracing::debug;
1919
use crate::dep_graph::{DepNode, DepNodeIndex};
2020
use crate::handle_cycle_error;
2121
use crate::job::{QueryJobInfo, QueryJobMap, create_cycle_error, find_cycle_in_stack};
22-
use crate::plumbing::{current_query_job, loadable_from_disk, next_job_id, start_query};
22+
use crate::plumbing::{current_query_job, next_job_id, start_query};
2323
use crate::query_impl::for_each_query_vtable;
2424

2525
#[inline]
@@ -564,7 +564,7 @@ fn load_from_disk_or_invoke_provider_green<'tcx, C: QueryCache>(
564564
value
565565
}
566566

567-
/// Checks whether a `tcx.ensure_ok()` or `tcx.ensure_done()` query call can
567+
/// Checks whether a `tcx.ensure_ok()` query call can
568568
/// return early without actually trying to execute.
569569
///
570570
/// This only makes sense during incremental compilation, because it relies
@@ -574,9 +574,7 @@ fn load_from_disk_or_invoke_provider_green<'tcx, C: QueryCache>(
574574
fn ensure_can_skip_execution<'tcx, C: QueryCache>(
575575
query: &'tcx QueryVTable<'tcx, C>,
576576
tcx: TyCtxt<'tcx>,
577-
key: C::Key,
578577
dep_node: DepNode,
579-
ensure_mode: EnsureMode,
580578
) -> bool {
581579
// Queries with `eval_always` should never skip execution.
582580
if query.eval_always {
@@ -593,25 +591,15 @@ fn ensure_can_skip_execution<'tcx, C: QueryCache>(
593591
// in-memory cache, or another query down the line will.
594592
false
595593
}
596-
Some((serialized_dep_node_index, dep_node_index)) => {
594+
Some((_, dep_node_index)) => {
597595
tcx.dep_graph.read_index(dep_node_index);
598596
tcx.prof.query_cache_hit(dep_node_index.into());
599-
match ensure_mode {
600-
// In ensure-ok mode, we can skip execution for this key if the
601-
// node is green. It must have succeeded in the previous
602-
// session, and therefore would succeed in the current session
603-
// if executed.
604-
EnsureMode::Ok => true,
605-
606-
// In ensure-done mode, we can only skip execution for this key
607-
// if there's a disk-cached value available to load later if
608-
// needed, which guarantees the query provider will never run
609-
// for this key.
610-
EnsureMode::Done => {
611-
query.will_cache_on_disk_for_key(key)
612-
&& loadable_from_disk(tcx, serialized_dep_node_index)
613-
}
614-
}
597+
598+
// We can skip execution for this key if the
599+
// node is green. It must have succeeded in the previous
600+
// session, and therefore would succeed in the current session
601+
// if executed.
602+
true
615603
}
616604
}
617605
}
@@ -640,9 +628,9 @@ pub(super) fn execute_query_incr_inner<'tcx, C: QueryCache>(
640628
) -> Option<C::Value> {
641629
let dep_node = DepNode::construct(tcx, query.dep_kind, &key);
642630

643-
// Check if query execution can be skipped, for `ensure_ok` or `ensure_done`.
644-
if let QueryMode::Ensure { ensure_mode } = mode
645-
&& ensure_can_skip_execution(query, tcx, key, dep_node, ensure_mode)
631+
// Check if query execution can be skipped, for `ensure_ok`.
632+
if let QueryMode::EnsureOk = mode
633+
&& ensure_can_skip_execution(query, tcx, dep_node)
646634
{
647635
return None;
648636
}

compiler/rustc_query_impl/src/plumbing.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -173,14 +173,6 @@ pub(crate) fn promote_from_disk_inner<'tcx, C: QueryCache>(
173173
}
174174
}
175175

176-
pub(crate) fn loadable_from_disk<'tcx>(tcx: TyCtxt<'tcx>, id: SerializedDepNodeIndex) -> bool {
177-
if let Some(cache) = tcx.query_system.on_disk_cache.as_ref() {
178-
cache.loadable_from_disk(id)
179-
} else {
180-
false
181-
}
182-
}
183-
184176
pub(crate) fn try_load_from_disk<'tcx, V>(
185177
tcx: TyCtxt<'tcx>,
186178
prev_index: SerializedDepNodeIndex,

0 commit comments

Comments
 (0)