Skip to content

Commit 2abb0ba

Browse files
committed
Remove ensure_done execution path
1 parent eb9d3ca commit 2abb0ba

5 files changed

Lines changed: 28 additions & 66 deletions

File tree

compiler/rustc_middle/src/query/inner.rs

Lines changed: 7 additions & 14 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
@@ -28,8 +28,8 @@ where
2828
}
2929
}
3030

31-
/// Shared implementation of `tcx.$query(..)` and `tcx.at(span).$query(..)`
32-
/// for all queries.
31+
/// Shared implementation of `tcx.$query(..)`, `tcx.at(span).$query(..)` and
32+
/// `tcx.ensure_done().$query(..)` for all queries.
3333
#[inline(always)]
3434
pub(crate) fn query_get_at<'tcx, C>(
3535
tcx: TyCtxt<'tcx>,
@@ -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::Ensure);
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::Ensure) {
9689
// We executed the query. Convert the successful result.
9790
Some(res) => convert(res),
9891

compiler/rustc_middle/src/query/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ pub use self::into_query_key::IntoQueryKey;
55
pub use self::job::{QueryJob, QueryJobId, QueryLatch, QueryWaiter};
66
pub use self::keys::{AsLocalQueryKey, LocalCrate, QueryKey};
77
pub use self::plumbing::{
8-
ActiveKeyStatus, CycleError, EnsureMode, QueryMode, QueryState, QuerySystem, QueryVTable,
9-
TyCtxtAt, TyCtxtEnsureDone, TyCtxtEnsureOk, TyCtxtEnsureResult,
8+
ActiveKeyStatus, CycleError, QueryMode, QueryState, QuerySystem, QueryVTable, TyCtxtAt,
9+
TyCtxtEnsureDone, TyCtxtEnsureOk, TyCtxtEnsureResult,
1010
};
1111
pub use self::stack::QueryStackFrame;
1212
pub use crate::queries::Providers;

compiler/rustc_middle/src/query/plumbing.rs

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -57,20 +57,10 @@ pub struct CycleError<'tcx> {
5757

5858
#[derive(Debug)]
5959
pub enum QueryMode {
60-
/// This is a normal query call to `tcx.$query(..)` or `tcx.at(span).$query(..)`.
60+
/// This is a query call to `tcx.$query(..)`, `tcx.at(span).$query(..)`or `tcx.ensure_done().$query(..)`.
6161
Get,
62-
/// This is a call to `tcx.ensure_ok().$query(..)` or `tcx.ensure_done().$query(..)`.
63-
Ensure { ensure_mode: EnsureMode },
64-
}
65-
66-
/// Distinguishes between `tcx.ensure_ok()` and `tcx.ensure_done()` in shared
67-
/// code paths that handle both modes.
68-
#[derive(Debug)]
69-
pub enum EnsureMode {
70-
/// Corresponds to [`TyCtxt::ensure_ok`].
71-
Ok,
72-
/// Corresponds to [`TyCtxt::ensure_done`].
73-
Done,
62+
/// This is a call to `tcx.ensure_ok().$query(..)`.
63+
Ensure,
7464
}
7565

7666
/// Stores data and metadata (e.g. function pointers) for a particular query.
@@ -578,11 +568,10 @@ macro_rules! define_callbacks {
578568
$(#[$attr])*
579569
#[inline(always)]
580570
pub fn $name(self, key: maybe_into_query_key!($($K)*)) {
581-
$crate::query::inner::query_ensure_ok_or_done(
571+
$crate::query::inner::query_ensure_ok(
582572
self.tcx,
583573
&self.tcx.query_system.query_vtables.$name,
584574
$crate::query::IntoQueryKey::into_query_key(key),
585-
$crate::query::EnsureMode::Ok,
586575
)
587576
}
588577
)*
@@ -612,11 +601,13 @@ macro_rules! define_callbacks {
612601
$(#[$attr])*
613602
#[inline(always)]
614603
pub fn $name(self, key: maybe_into_query_key!($($K)*)) {
615-
$crate::query::inner::query_ensure_ok_or_done(
604+
// This has the same implementation as `tcx.$query(..)` as it isn't currently
605+
// beneficial to have an optimized variant due to how promotion works.
606+
$crate::query::inner::query_get_at(
616607
self.tcx,
608+
DUMMY_SP,
617609
&self.tcx.query_system.query_vtables.$name,
618610
$crate::query::IntoQueryKey::into_query_key(key),
619-
$crate::query::EnsureMode::Done,
620611
);
621612
}
622613
)*

compiler/rustc_query_impl/src/execution.rs

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ use rustc_data_structures::{outline, sharded, sync};
88
use rustc_errors::FatalError;
99
use rustc_middle::dep_graph::{DepGraphData, DepNodeKey, SerializedDepNodeIndex};
1010
use rustc_middle::query::{
11-
ActiveKeyStatus, CycleError, EnsureMode, QueryCache, QueryJob, QueryJobId, QueryKey,
12-
QueryLatch, QueryMode, QueryState, QueryVTable,
11+
ActiveKeyStatus, CycleError, 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;
@@ -18,7 +18,7 @@ use tracing::warn;
1818

1919
use crate::dep_graph::{DepNode, DepNodeIndex};
2020
use crate::job::{QueryJobInfo, QueryJobMap, find_cycle_in_stack, report_cycle};
21-
use crate::plumbing::{current_query_job, loadable_from_disk, next_job_id, start_query};
21+
use crate::plumbing::{current_query_job, next_job_id, start_query};
2222
use crate::query_impl::for_each_query_vtable;
2323

2424
#[inline]
@@ -546,15 +546,15 @@ fn load_from_disk_or_invoke_provider_green<'tcx, C: QueryCache>(
546546

547547
/// Return value struct for [`check_if_ensure_can_skip_execution`].
548548
struct EnsureCanSkip {
549-
/// If true, the current `tcx.ensure_ok()` or `tcx.ensure_done()` query
549+
/// If true, the current `tcx.ensure_ok()` query
550550
/// can return early without actually trying to execute.
551551
skip_execution: bool,
552552
/// A dep node that was prepared while checking whether execution can be
553553
/// skipped, to be reused by execution itself if _not_ skipped.
554554
dep_node: Option<DepNode>,
555555
}
556556

557-
/// Checks whether a `tcx.ensure_ok()` or `tcx.ensure_done()` query call can
557+
/// Checks whether a `tcx.ensure_ok()` query call can
558558
/// return early without actually trying to execute.
559559
///
560560
/// This only makes sense during incremental compilation, because it relies
@@ -565,7 +565,6 @@ fn check_if_ensure_can_skip_execution<'tcx, C: QueryCache>(
565565
query: &'tcx QueryVTable<'tcx, C>,
566566
tcx: TyCtxt<'tcx>,
567567
key: C::Key,
568-
ensure_mode: EnsureMode,
569568
) -> EnsureCanSkip {
570569
// Queries with `eval_always` should never skip execution.
571570
if query.eval_always {
@@ -574,38 +573,25 @@ fn check_if_ensure_can_skip_execution<'tcx, C: QueryCache>(
574573

575574
let dep_node = DepNode::construct(tcx, query.dep_kind, &key);
576575

577-
let serialized_dep_node_index = match tcx.dep_graph.try_mark_green(tcx, &dep_node) {
576+
match tcx.dep_graph.try_mark_green(tcx, &dep_node) {
578577
None => {
579578
// A None return from `try_mark_green` means that this is either
580579
// a new dep node or that the dep node has already been marked red.
581580
// Either way, we can't call `dep_graph.read()` as we don't have the
582581
// DepNodeIndex. We must invoke the query itself. The performance cost
583582
// this introduces should be negligible as we'll immediately hit the
584583
// in-memory cache, or another query down the line will.
585-
return EnsureCanSkip { skip_execution: false, dep_node: Some(dep_node) };
584+
EnsureCanSkip { skip_execution: false, dep_node: Some(dep_node) }
586585
}
587-
Some((serialized_dep_node_index, dep_node_index)) => {
586+
Some((_, dep_node_index)) => {
588587
tcx.dep_graph.read_index(dep_node_index);
589588
tcx.prof.query_cache_hit(dep_node_index.into());
590-
serialized_dep_node_index
591-
}
592-
};
593589

594-
match ensure_mode {
595-
EnsureMode::Ok => {
596590
// In ensure-ok mode, we can skip execution for this key if the node
597591
// is green. It must have succeeded in the previous session, and
598592
// therefore would succeed in the current session if executed.
599593
EnsureCanSkip { skip_execution: true, dep_node: None }
600594
}
601-
EnsureMode::Done => {
602-
// In ensure-done mode, we can only skip execution for this key if
603-
// there's a disk-cached value available to load later if needed,
604-
// which guarantees the query provider will never run for this key.
605-
let is_loadable = (query.will_cache_on_disk_for_key_fn)(tcx, key)
606-
&& loadable_from_disk(tcx, serialized_dep_node_index);
607-
EnsureCanSkip { skip_execution: is_loadable, dep_node: Some(dep_node) }
608-
}
609595
}
610596
}
611597

@@ -635,13 +621,13 @@ pub(super) fn execute_query_incr_inner<'tcx, C: QueryCache>(
635621
) -> Option<C::Value> {
636622
debug_assert!(tcx.dep_graph.is_fully_enabled());
637623

638-
// Check if query execution can be skipped, for `ensure_ok` or `ensure_done`.
624+
// Check if query execution can be skipped, for `ensure_ok`.
639625
// This might have the side-effect of creating a suitable DepNode, which
640626
// we should reuse for execution instead of creating a new one.
641627
let dep_node: Option<DepNode> = match mode {
642-
QueryMode::Ensure { ensure_mode } => {
628+
QueryMode::Ensure => {
643629
let EnsureCanSkip { skip_execution, dep_node } =
644-
check_if_ensure_can_skip_execution(query, tcx, key, ensure_mode);
630+
check_if_ensure_can_skip_execution(query, tcx, key);
645631
if skip_execution {
646632
// Return early to skip execution.
647633
return None;

compiler/rustc_query_impl/src/plumbing.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -189,14 +189,6 @@ pub(crate) fn promote_from_disk_inner<'tcx, Q: GetQueryVTable<'tcx>>(
189189
}
190190
}
191191

192-
pub(crate) fn loadable_from_disk<'tcx>(tcx: TyCtxt<'tcx>, id: SerializedDepNodeIndex) -> bool {
193-
if let Some(cache) = tcx.query_system.on_disk_cache.as_ref() {
194-
cache.loadable_from_disk(id)
195-
} else {
196-
false
197-
}
198-
}
199-
200192
pub(crate) fn try_load_from_disk<'tcx, V>(
201193
tcx: TyCtxt<'tcx>,
202194
prev_index: SerializedDepNodeIndex,

0 commit comments

Comments
 (0)