Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 5bf1e29

Browse files
committed
[DO NOT MERGE] Make .ensure_with_value() just run the query normally
1 parent 122fb29 commit 5bf1e29

File tree

2 files changed

+19
-42
lines changed

2 files changed

+19
-42
lines changed

compiler/rustc_middle/src/query/plumbing.rs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -150,13 +150,12 @@ pub fn query_ensure<'tcx, Cache>(
150150
execute_query: fn(TyCtxt<'tcx>, Span, Cache::Key, QueryMode) -> Option<Cache::Value>,
151151
query_cache: &Cache,
152152
key: Cache::Key,
153-
check_cache: bool,
154153
) where
155154
Cache: QueryCache,
156155
{
157156
let key = key.into_query_param();
158157
if try_get_cached(tcx, query_cache, &key).is_none() {
159-
execute_query(tcx, DUMMY_SP, key, QueryMode::Ensure { check_cache });
158+
execute_query(tcx, DUMMY_SP, key, QueryMode::Ensure);
160159
}
161160
}
162161

@@ -166,7 +165,6 @@ pub fn query_ensure_error_guaranteed<'tcx, Cache, T>(
166165
execute_query: fn(TyCtxt<'tcx>, Span, Cache::Key, QueryMode) -> Option<Cache::Value>,
167166
query_cache: &Cache,
168167
key: Cache::Key,
169-
check_cache: bool,
170168
) -> Result<(), ErrorGuaranteed>
171169
where
172170
Cache: QueryCache<Value = super::erase::Erase<Result<T, ErrorGuaranteed>>>,
@@ -176,7 +174,7 @@ where
176174
if let Some(res) = try_get_cached(tcx, query_cache, &key) {
177175
super::erase::restore(res).map(drop)
178176
} else {
179-
execute_query(tcx, DUMMY_SP, key, QueryMode::Ensure { check_cache })
177+
execute_query(tcx, DUMMY_SP, key, QueryMode::Ensure)
180178
.map(super::erase::restore)
181179
.map(|res| res.map(drop))
182180
// Either we actually executed the query, which means we got a full `Result`,
@@ -393,7 +391,6 @@ macro_rules! define_callbacks {
393391
self.tcx.query_system.fns.engine.$name,
394392
&self.tcx.query_system.caches.$name,
395393
key.into_query_param(),
396-
false,
397394
)
398395
})*
399396
}
@@ -402,13 +399,8 @@ macro_rules! define_callbacks {
402399
$($(#[$attr])*
403400
#[inline(always)]
404401
pub fn $name(self, key: query_helper_param_ty!($($K)*)) {
405-
query_ensure(
406-
self.tcx,
407-
self.tcx.query_system.fns.engine.$name,
408-
&self.tcx.query_system.caches.$name,
409-
key.into_query_param(),
410-
true,
411-
);
402+
// Just call the query normally, and discard its result.
403+
let _ = self.tcx.$name(key);
412404
})*
413405
}
414406

compiler/rustc_query_system/src/query/plumbing.rs

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -743,12 +743,7 @@ fn incremental_verify_ich_failed<Tcx>(
743743
///
744744
/// Note: The optimization is only available during incr. comp.
745745
#[inline(never)]
746-
fn ensure_must_run<Q, Qcx>(
747-
query: Q,
748-
qcx: Qcx,
749-
key: &Q::Key,
750-
check_cache: bool,
751-
) -> (bool, Option<DepNode>)
746+
fn ensure_must_run<Q, Qcx>(query: Q, qcx: Qcx, key: &Q::Key) -> (bool, Option<DepNode>)
752747
where
753748
Q: QueryConfig<Qcx>,
754749
Qcx: QueryContext,
@@ -763,7 +758,7 @@ where
763758
let dep_node = query.construct_dep_node(*qcx.dep_context(), key);
764759

765760
let dep_graph = qcx.dep_context().dep_graph();
766-
let serialized_dep_node_index = match dep_graph.try_mark_green(qcx, &dep_node) {
761+
match dep_graph.try_mark_green(qcx, &dep_node) {
767762
None => {
768763
// A None return from `try_mark_green` means that this is either
769764
// a new dep node or that the dep node has already been marked red.
@@ -773,26 +768,17 @@ where
773768
// in-memory cache, or another query down the line will.
774769
return (true, Some(dep_node));
775770
}
776-
Some((serialized_dep_node_index, dep_node_index)) => {
777-
dep_graph.read_index(dep_node_index);
778-
qcx.dep_context().profiler().query_cache_hit(dep_node_index.into());
779-
serialized_dep_node_index
780-
}
771+
Some(_) => {}
781772
};
782773

783774
// We do not need the value at all, so do not check the cache.
784-
if !check_cache {
785-
return (false, None);
786-
}
787-
788-
let loadable = query.loadable_from_disk(qcx, key, serialized_dep_node_index);
789-
(!loadable, Some(dep_node))
775+
(false, None)
790776
}
791777

792778
#[derive(Debug)]
793779
pub enum QueryMode {
794780
Get,
795-
Ensure { check_cache: bool },
781+
Ensure,
796782
}
797783

798784
#[inline(always)]
@@ -820,19 +806,18 @@ where
820806
{
821807
debug_assert!(qcx.dep_context().dep_graph().is_fully_enabled());
822808

823-
let dep_node = if let QueryMode::Ensure { check_cache } = mode {
824-
let (must_run, dep_node) = ensure_must_run(query, qcx, &key, check_cache);
825-
if !must_run {
826-
return None;
809+
match mode {
810+
QueryMode::Ensure => {
811+
let (must_run, _) = ensure_must_run(query, qcx, &key);
812+
if !must_run {
813+
return None;
814+
}
827815
}
828-
dep_node
829-
} else {
830-
None
831-
};
816+
QueryMode::Get => {}
817+
}
832818

833-
let (result, dep_node_index) = ensure_sufficient_stack(|| {
834-
try_execute_query::<_, _, true>(query, qcx, span, key, dep_node)
835-
});
819+
let (result, dep_node_index) =
820+
ensure_sufficient_stack(|| try_execute_query::<_, _, true>(query, qcx, span, key, None));
836821
if let Some(dep_node_index) = dep_node_index {
837822
qcx.dep_context().dep_graph().read_index(dep_node_index)
838823
}

0 commit comments

Comments
 (0)