Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 4 additions & 12 deletions compiler/rustc_middle/src/query/plumbing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,12 @@ pub fn query_ensure<'tcx, Cache>(
execute_query: fn(TyCtxt<'tcx>, Span, Cache::Key, QueryMode) -> Option<Cache::Value>,
query_cache: &Cache,
key: Cache::Key,
check_cache: bool,
) where
Cache: QueryCache,
{
let key = key.into_query_param();
if try_get_cached(tcx, query_cache, &key).is_none() {
execute_query(tcx, DUMMY_SP, key, QueryMode::Ensure { check_cache });
execute_query(tcx, DUMMY_SP, key, QueryMode::Ensure);
}
}

Expand All @@ -166,7 +165,6 @@ pub fn query_ensure_error_guaranteed<'tcx, Cache, T>(
execute_query: fn(TyCtxt<'tcx>, Span, Cache::Key, QueryMode) -> Option<Cache::Value>,
query_cache: &Cache,
key: Cache::Key,
check_cache: bool,
) -> Result<(), ErrorGuaranteed>
where
Cache: QueryCache<Value = super::erase::Erase<Result<T, ErrorGuaranteed>>>,
Expand All @@ -176,7 +174,7 @@ where
if let Some(res) = try_get_cached(tcx, query_cache, &key) {
super::erase::restore(res).map(drop)
} else {
execute_query(tcx, DUMMY_SP, key, QueryMode::Ensure { check_cache })
execute_query(tcx, DUMMY_SP, key, QueryMode::Ensure)
.map(super::erase::restore)
.map(|res| res.map(drop))
// Either we actually executed the query, which means we got a full `Result`,
Expand Down Expand Up @@ -393,7 +391,6 @@ macro_rules! define_callbacks {
self.tcx.query_system.fns.engine.$name,
&self.tcx.query_system.caches.$name,
key.into_query_param(),
false,
)
})*
}
Expand All @@ -402,13 +399,8 @@ macro_rules! define_callbacks {
$($(#[$attr])*
#[inline(always)]
pub fn $name(self, key: query_helper_param_ty!($($K)*)) {
query_ensure(
self.tcx,
self.tcx.query_system.fns.engine.$name,
&self.tcx.query_system.caches.$name,
key.into_query_param(),
true,
);
// Just call the query normally, and discard its result.
let _ = self.tcx.$name(key);
})*
}

Expand Down
45 changes: 15 additions & 30 deletions compiler/rustc_query_system/src/query/plumbing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -743,12 +743,7 @@ fn incremental_verify_ich_failed<Tcx>(
///
/// Note: The optimization is only available during incr. comp.
#[inline(never)]
fn ensure_must_run<Q, Qcx>(
query: Q,
qcx: Qcx,
key: &Q::Key,
check_cache: bool,
) -> (bool, Option<DepNode>)
fn ensure_must_run<Q, Qcx>(query: Q, qcx: Qcx, key: &Q::Key) -> (bool, Option<DepNode>)
where
Q: QueryConfig<Qcx>,
Qcx: QueryContext,
Expand All @@ -763,7 +758,7 @@ where
let dep_node = query.construct_dep_node(*qcx.dep_context(), key);

let dep_graph = qcx.dep_context().dep_graph();
let serialized_dep_node_index = match dep_graph.try_mark_green(qcx, &dep_node) {
match dep_graph.try_mark_green(qcx, &dep_node) {
None => {
// A None return from `try_mark_green` means that this is either
// a new dep node or that the dep node has already been marked red.
Expand All @@ -773,26 +768,17 @@ where
// in-memory cache, or another query down the line will.
return (true, Some(dep_node));
}
Some((serialized_dep_node_index, dep_node_index)) => {
dep_graph.read_index(dep_node_index);
qcx.dep_context().profiler().query_cache_hit(dep_node_index.into());
serialized_dep_node_index
}
Some(_) => {}
};

// We do not need the value at all, so do not check the cache.
if !check_cache {
return (false, None);
}

let loadable = query.loadable_from_disk(qcx, key, serialized_dep_node_index);
(!loadable, Some(dep_node))
(false, None)
}

#[derive(Debug)]
pub enum QueryMode {
Get,
Ensure { check_cache: bool },
Ensure,
}

#[inline(always)]
Expand Down Expand Up @@ -820,19 +806,18 @@ where
{
debug_assert!(qcx.dep_context().dep_graph().is_fully_enabled());

let dep_node = if let QueryMode::Ensure { check_cache } = mode {
let (must_run, dep_node) = ensure_must_run(query, qcx, &key, check_cache);
if !must_run {
return None;
match mode {
QueryMode::Ensure => {
let (must_run, _) = ensure_must_run(query, qcx, &key);
if !must_run {
return None;
}
}
dep_node
} else {
None
};
QueryMode::Get => {}
}

let (result, dep_node_index) = ensure_sufficient_stack(|| {
try_execute_query::<_, _, true>(query, qcx, span, key, dep_node)
});
let (result, dep_node_index) =
ensure_sufficient_stack(|| try_execute_query::<_, _, true>(query, qcx, span, key, None));
if let Some(dep_node_index) = dep_node_index {
qcx.dep_context().dep_graph().read_index(dep_node_index)
}
Expand Down
Loading