Skip to content

Commit 3d2c2fc

Browse files
committed
Remove ensure_done execution path
1 parent 700cfa8 commit 3d2c2fc

File tree

5 files changed

+29
-77
lines changed

5 files changed

+29
-77
lines changed

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::{AsLocalQueryKey, 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.
@@ -260,20 +250,13 @@ impl<'tcx> TyCtxt<'tcx> {
260250
TyCtxtEnsureResult { tcx: self }
261251
}
262252

263-
/// Wrapper that calls queries in a special "ensure done" mode, for callers
264-
/// that don't need the return value and just want to guarantee that the
265-
/// query won't be executed in the future, by executing it now if necessary.
253+
/// Wrapper that calls queries where callers don't need the return value and
254+
/// just want to guarantee that the query won't be executed in the future.
266255
///
267256
/// This is useful for queries that read from a [`Steal`] value, to ensure
268257
/// that they are executed before the query that will steal the value.
269258
///
270-
/// Unlike [`Self::ensure_ok`], a query with all-green inputs will only be
271-
/// skipped if its return value is stored in the disk-cache. This is still
272-
/// more efficient than a regular query, because in that situation the
273-
/// return value doesn't necessarily need to be decoded.
274-
///
275-
/// (As with all query calls, execution is also skipped if the query result
276-
/// is already cached in memory.)
259+
/// Currently this causes the query to be executed normally, but this behavior may change.
277260
///
278261
/// [`Steal`]: rustc_data_structures::steal::Steal
279262
#[inline(always)]
@@ -598,11 +581,10 @@ macro_rules! define_callbacks {
598581
$(#[$attr])*
599582
#[inline(always)]
600583
pub fn $name(self, key: maybe_into_query_key!($($K)*)) {
601-
$crate::query::inner::query_ensure_ok_or_done(
584+
$crate::query::inner::query_ensure_ok(
602585
self.tcx,
603586
&self.tcx.query_system.query_vtables.$name,
604587
$crate::query::IntoQueryKey::into_query_key(key),
605-
$crate::query::EnsureMode::Ok,
606588
)
607589
}
608590
)*
@@ -632,12 +614,9 @@ macro_rules! define_callbacks {
632614
$(#[$attr])*
633615
#[inline(always)]
634616
pub fn $name(self, key: maybe_into_query_key!($($K)*)) {
635-
$crate::query::inner::query_ensure_ok_or_done(
636-
self.tcx,
637-
&self.tcx.query_system.query_vtables.$name,
638-
$crate::query::IntoQueryKey::into_query_key(key),
639-
$crate::query::EnsureMode::Done,
640-
);
617+
// This has the same implementation as `tcx.$query(..)` as it isn't currently
618+
// beneficial to have an optimized variant due to how promotion works.
619+
let _ = self.tcx.$name(key);
641620
}
642621
)*
643622
}

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::{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;
@@ -18,7 +18,7 @@ use tracing::warn;
1818

1919
use crate::dep_graph::{DepNode, DepNodeIndex};
2020
use crate::job::{QueryJobInfo, QueryJobMap, create_cycle_error, find_cycle_in_stack};
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]
@@ -532,7 +532,7 @@ fn load_from_disk_or_invoke_provider_green<'tcx, C: QueryCache>(
532532
value
533533
}
534534

535-
/// Checks whether a `tcx.ensure_ok()` or `tcx.ensure_done()` query call can
535+
/// Checks whether a `tcx.ensure_ok()` query call can
536536
/// return early without actually trying to execute.
537537
///
538538
/// This only makes sense during incremental compilation, because it relies
@@ -542,9 +542,7 @@ fn load_from_disk_or_invoke_provider_green<'tcx, C: QueryCache>(
542542
fn ensure_can_skip_execution<'tcx, C: QueryCache>(
543543
query: &'tcx QueryVTable<'tcx, C>,
544544
tcx: TyCtxt<'tcx>,
545-
key: C::Key,
546545
dep_node: DepNode,
547-
ensure_mode: EnsureMode,
548546
) -> bool {
549547
// Queries with `eval_always` should never skip execution.
550548
if query.eval_always {
@@ -561,25 +559,15 @@ fn ensure_can_skip_execution<'tcx, C: QueryCache>(
561559
// in-memory cache, or another query down the line will.
562560
false
563561
}
564-
Some((serialized_dep_node_index, dep_node_index)) => {
562+
Some((_, dep_node_index)) => {
565563
tcx.dep_graph.read_index(dep_node_index);
566564
tcx.prof.query_cache_hit(dep_node_index.into());
567-
match ensure_mode {
568-
// In ensure-ok mode, we can skip execution for this key if the
569-
// node is green. It must have succeeded in the previous
570-
// session, and therefore would succeed in the current session
571-
// if executed.
572-
EnsureMode::Ok => true,
573-
574-
// In ensure-done mode, we can only skip execution for this key
575-
// if there's a disk-cached value available to load later if
576-
// needed, which guarantees the query provider will never run
577-
// for this key.
578-
EnsureMode::Done => {
579-
(query.will_cache_on_disk_for_key_fn)(key)
580-
&& loadable_from_disk(tcx, serialized_dep_node_index)
581-
}
582-
}
565+
566+
// We can skip execution for this key if the
567+
// node is green. It must have succeeded in the previous
568+
// session, and therefore would succeed in the current session
569+
// if executed.
570+
true
583571
}
584572
}
585573
}
@@ -608,9 +596,9 @@ pub(super) fn execute_query_incr_inner<'tcx, C: QueryCache>(
608596
) -> Option<C::Value> {
609597
let dep_node = DepNode::construct(tcx, query.dep_kind, &key);
610598

611-
// Check if query execution can be skipped, for `ensure_ok` or `ensure_done`.
612-
if let QueryMode::Ensure { ensure_mode } = mode
613-
&& ensure_can_skip_execution(query, tcx, key, dep_node, ensure_mode)
599+
// Check if query execution can be skipped, for `ensure_ok`.
600+
if let QueryMode::EnsureOk = mode
601+
&& ensure_can_skip_execution(query, tcx, dep_node)
614602
{
615603
return None;
616604
}

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)