Skip to content

Commit 57d196c

Browse files
committed
Rename tcx.ensure_with_value() to tcx.ensure_done()
1 parent 0a9f6fe commit 57d196c

File tree

8 files changed

+37
-25
lines changed

8 files changed

+37
-25
lines changed

compiler/rustc_ast_lowering/src/lib.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -418,10 +418,10 @@ fn compute_hir_hash(
418418
pub fn lower_to_hir(tcx: TyCtxt<'_>, (): ()) -> hir::Crate<'_> {
419419
let sess = tcx.sess;
420420
// Queries that borrow `resolver_for_lowering`.
421-
tcx.ensure_with_value().output_filenames(());
422-
tcx.ensure_with_value().early_lint_checks(());
423-
tcx.ensure_with_value().debugger_visualizers(LOCAL_CRATE);
424-
tcx.ensure_with_value().get_lang_items(());
421+
tcx.ensure_done().output_filenames(());
422+
tcx.ensure_done().early_lint_checks(());
423+
tcx.ensure_done().debugger_visualizers(LOCAL_CRATE);
424+
tcx.ensure_done().get_lang_items(());
425425
let (mut resolver, krate) = tcx.resolver_for_lowering().steal();
426426

427427
let ast_index = index_crate(&resolver.node_id_to_def_id, &krate);

compiler/rustc_interface/src/passes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,7 @@ fn run_required_analyses(tcx: TyCtxt<'_>) {
869869
sess.time("MIR_coroutine_by_move_body", || {
870870
tcx.hir().par_body_owners(|def_id| {
871871
if tcx.needs_coroutine_by_move_body_def_id(def_id.to_def_id()) {
872-
tcx.ensure_with_value().coroutine_by_move_body_def_id(def_id);
872+
tcx.ensure_done().coroutine_by_move_body_def_id(def_id);
873873
}
874874
});
875875
});

compiler/rustc_metadata/src/rmeta/encoder.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2191,13 +2191,13 @@ fn prefetch_mir(tcx: TyCtxt<'_>) {
21912191
let (encode_const, encode_opt) = should_encode_mir(tcx, reachable_set, def_id);
21922192

21932193
if encode_const {
2194-
tcx.ensure_with_value().mir_for_ctfe(def_id);
2194+
tcx.ensure_done().mir_for_ctfe(def_id);
21952195
}
21962196
if encode_opt {
2197-
tcx.ensure_with_value().optimized_mir(def_id);
2197+
tcx.ensure_done().optimized_mir(def_id);
21982198
}
21992199
if encode_opt || encode_const {
2200-
tcx.ensure_with_value().promoted_mir(def_id);
2200+
tcx.ensure_done().promoted_mir(def_id);
22012201
}
22022202
})
22032203
}

compiler/rustc_middle/src/query/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ pub use keys::{AsLocalKey, Key, LocalCrate};
9191
pub mod on_disk_cache;
9292
#[macro_use]
9393
pub mod plumbing;
94-
pub use plumbing::{IntoQueryParam, TyCtxtAt, TyCtxtEnsureOk, TyCtxtEnsureWithValue};
94+
pub use plumbing::{IntoQueryParam, TyCtxtAt, TyCtxtEnsureDone, TyCtxtEnsureOk};
9595

9696
// Each of these queries corresponds to a function pointer field in the
9797
// `Providers` struct for requesting a value of that type, and a method

compiler/rustc_middle/src/query/plumbing.rs

+19-7
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ pub struct TyCtxtEnsureOk<'tcx> {
9393
}
9494

9595
#[derive(Copy, Clone)]
96-
pub struct TyCtxtEnsureWithValue<'tcx> {
96+
pub struct TyCtxtEnsureDone<'tcx> {
9797
pub tcx: TyCtxt<'tcx>,
9898
}
9999

@@ -123,13 +123,25 @@ impl<'tcx> TyCtxt<'tcx> {
123123
TyCtxtEnsureOk { tcx: self }
124124
}
125125

126-
/// Returns a transparent wrapper for `TyCtxt`, which ensures queries
127-
/// are executed instead of just returning their results.
126+
/// Wrapper that calls queries in a special "ensure done" mode, for callers
127+
/// that don't need the return value and just want to guarantee that the
128+
/// query won't be executed in the future, by executing it now if necessary.
128129
///
129-
/// This version verifies that the computed result exists in the cache before returning.
130+
/// This is useful for queries that read from a [`Steal`] value, to ensure
131+
/// that they are executed before the query that will steal the value.
132+
///
133+
/// Unlike [`Self::ensure_ok`], a query with all-green inputs will only be
134+
/// skipped if its return value is stored in the disk-cache. This is still
135+
/// more efficient than a regular query, because in that situation the
136+
/// return value doesn't necessarily need to be decoded.
137+
///
138+
/// (As with all query calls, execution is also skipped if the query result
139+
/// is already cached in memory.)
140+
///
141+
/// [`Steal`]: rustc_data_structures::steal::Steal
130142
#[inline(always)]
131-
pub fn ensure_with_value(self) -> TyCtxtEnsureWithValue<'tcx> {
132-
TyCtxtEnsureWithValue { tcx: self }
143+
pub fn ensure_done(self) -> TyCtxtEnsureDone<'tcx> {
144+
TyCtxtEnsureDone { tcx: self }
133145
}
134146

135147
/// Returns a transparent wrapper for `TyCtxt` which uses
@@ -419,7 +431,7 @@ macro_rules! define_callbacks {
419431
})*
420432
}
421433

422-
impl<'tcx> TyCtxtEnsureWithValue<'tcx> {
434+
impl<'tcx> TyCtxtEnsureDone<'tcx> {
423435
$($(#[$attr])*
424436
#[inline(always)]
425437
pub fn $name(self, key: query_helper_param_ty!($($K)*)) {

compiler/rustc_mir_build/src/builder/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ pub(crate) fn closure_saved_names_of_captured_variables<'tcx>(
4848
/// Construct the MIR for a given `DefId`.
4949
pub(crate) fn build_mir<'tcx>(tcx: TyCtxtAt<'tcx>, def: LocalDefId) -> Body<'tcx> {
5050
let tcx = tcx.tcx;
51-
tcx.ensure_with_value().thir_abstract_const(def);
51+
tcx.ensure_done().thir_abstract_const(def);
5252
if let Err(e) = tcx.check_match(def) {
5353
return construct_error(tcx, def, e);
5454
}

compiler/rustc_mir_build/src/check_unsafety.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ impl<'tcx> UnsafetyVisitor<'_, 'tcx> {
200200
fn visit_inner_body(&mut self, def: LocalDefId) {
201201
if let Ok((inner_thir, expr)) = self.tcx.thir_body(def) {
202202
// Runs all other queries that depend on THIR.
203-
self.tcx.ensure_with_value().mir_built(def);
203+
self.tcx.ensure_done().mir_built(def);
204204
let inner_thir = &inner_thir.steal();
205205
let hir_context = self.tcx.local_def_id_to_hir_id(def);
206206
let safety_context = mem::replace(&mut self.safety_context, SafetyContext::Safe);
@@ -1112,7 +1112,7 @@ pub(crate) fn check_unsafety(tcx: TyCtxt<'_>, def: LocalDefId) {
11121112

11131113
let Ok((thir, expr)) = tcx.thir_body(def) else { return };
11141114
// Runs all other queries that depend on THIR.
1115-
tcx.ensure_with_value().mir_built(def);
1115+
tcx.ensure_done().mir_built(def);
11161116
let thir = &thir.steal();
11171117

11181118
let hir_id = tcx.local_def_id_to_hir_id(def);

compiler/rustc_mir_transform/src/lib.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -418,11 +418,11 @@ fn mir_promoted(
418418
};
419419

420420
// the `has_ffi_unwind_calls` query uses the raw mir, so make sure it is run.
421-
tcx.ensure_with_value().has_ffi_unwind_calls(def);
421+
tcx.ensure_done().has_ffi_unwind_calls(def);
422422

423423
// the `by_move_body` query uses the raw mir, so make sure it is run.
424424
if tcx.needs_coroutine_by_move_body_def_id(def.to_def_id()) {
425-
tcx.ensure_with_value().coroutine_by_move_body_def_id(def);
425+
tcx.ensure_done().coroutine_by_move_body_def_id(def);
426426
}
427427

428428
let mut body = tcx.mir_built(def).steal();
@@ -485,7 +485,7 @@ fn inner_mir_for_ctfe(tcx: TyCtxt<'_>, def: LocalDefId) -> Body<'_> {
485485
/// end up missing the source MIR due to stealing happening.
486486
fn mir_drops_elaborated_and_const_checked(tcx: TyCtxt<'_>, def: LocalDefId) -> &Steal<Body<'_>> {
487487
if tcx.is_coroutine(def.to_def_id()) {
488-
tcx.ensure_with_value().mir_coroutine_witnesses(def);
488+
tcx.ensure_done().mir_coroutine_witnesses(def);
489489
}
490490

491491
// We only need to borrowck non-synthetic MIR.
@@ -498,7 +498,7 @@ fn mir_drops_elaborated_and_const_checked(tcx: TyCtxt<'_>, def: LocalDefId) -> &
498498
if pm::should_run_pass(tcx, &inline::Inline, pm::Optimizations::Allowed)
499499
|| inline::ForceInline::should_run_pass_for_callee(tcx, def.to_def_id())
500500
{
501-
tcx.ensure_with_value().mir_inliner_callees(ty::InstanceKind::Item(def.to_def_id()));
501+
tcx.ensure_done().mir_inliner_callees(ty::InstanceKind::Item(def.to_def_id()));
502502
}
503503
}
504504

@@ -729,7 +729,7 @@ fn inner_optimized_mir(tcx: TyCtxt<'_>, did: LocalDefId) -> Body<'_> {
729729
// Run the `mir_for_ctfe` query, which depends on `mir_drops_elaborated_and_const_checked`
730730
// which we are going to steal below. Thus we need to run `mir_for_ctfe` first, so it
731731
// computes and caches its result.
732-
Some(hir::ConstContext::ConstFn) => tcx.ensure_with_value().mir_for_ctfe(did),
732+
Some(hir::ConstContext::ConstFn) => tcx.ensure_done().mir_for_ctfe(did),
733733
None => {}
734734
Some(other) => panic!("do not use `optimized_mir` for constants: {other:?}"),
735735
}
@@ -768,7 +768,7 @@ fn promoted_mir(tcx: TyCtxt<'_>, def: LocalDefId) -> &IndexVec<Promoted, Body<'_
768768
}
769769

770770
if !tcx.is_synthetic_mir(def) {
771-
tcx.ensure_with_value().mir_borrowck(def);
771+
tcx.ensure_done().mir_borrowck(def);
772772
}
773773
let mut promoted = tcx.mir_promoted(def).1.steal();
774774

0 commit comments

Comments
 (0)