1
Fork 0

Rename tcx.ensure_with_value() to tcx.ensure_done()

This commit is contained in:
Zalathar 2025-01-30 16:28:44 +11:00
parent 24cdaa146a
commit 9e4f10db65
8 changed files with 37 additions and 25 deletions

View file

@ -91,7 +91,7 @@ pub use keys::{AsLocalKey, Key, LocalCrate};
pub mod on_disk_cache;
#[macro_use]
pub mod plumbing;
pub use plumbing::{IntoQueryParam, TyCtxtAt, TyCtxtEnsureOk, TyCtxtEnsureWithValue};
pub use plumbing::{IntoQueryParam, TyCtxtAt, TyCtxtEnsureDone, TyCtxtEnsureOk};
// Each of these queries corresponds to a function pointer field in the
// `Providers` struct for requesting a value of that type, and a method

View file

@ -93,7 +93,7 @@ pub struct TyCtxtEnsureOk<'tcx> {
}
#[derive(Copy, Clone)]
pub struct TyCtxtEnsureWithValue<'tcx> {
pub struct TyCtxtEnsureDone<'tcx> {
pub tcx: TyCtxt<'tcx>,
}
@ -123,13 +123,25 @@ impl<'tcx> TyCtxt<'tcx> {
TyCtxtEnsureOk { tcx: self }
}
/// Returns a transparent wrapper for `TyCtxt`, which ensures queries
/// are executed instead of just returning their results.
/// 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.
///
/// This version verifies that the computed result exists in the cache before returning.
/// 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.)
///
/// [`Steal`]: rustc_data_structures::steal::Steal
#[inline(always)]
pub fn ensure_with_value(self) -> TyCtxtEnsureWithValue<'tcx> {
TyCtxtEnsureWithValue { tcx: self }
pub fn ensure_done(self) -> TyCtxtEnsureDone<'tcx> {
TyCtxtEnsureDone { tcx: self }
}
/// Returns a transparent wrapper for `TyCtxt` which uses
@ -419,7 +431,7 @@ macro_rules! define_callbacks {
})*
}
impl<'tcx> TyCtxtEnsureWithValue<'tcx> {
impl<'tcx> TyCtxtEnsureDone<'tcx> {
$($(#[$attr])*
#[inline(always)]
pub fn $name(self, key: query_helper_param_ty!($($K)*)) {