summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_middle/src/traits/solve/cache.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-07 05:48:48 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-07 05:48:48 +0000
commitef24de24a82fe681581cc130f342363c47c0969a (patch)
tree0d494f7e1a38b95c92426f58fe6eaa877303a86c /compiler/rustc_middle/src/traits/solve/cache.rs
parentReleasing progress-linux version 1.74.1+dfsg1-1~progress7.99u1. (diff)
downloadrustc-ef24de24a82fe681581cc130f342363c47c0969a.tar.xz
rustc-ef24de24a82fe681581cc130f342363c47c0969a.zip
Merging upstream version 1.75.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'compiler/rustc_middle/src/traits/solve/cache.rs')
-rw-r--r--compiler/rustc_middle/src/traits/solve/cache.rs47
1 files changed, 36 insertions, 11 deletions
diff --git a/compiler/rustc_middle/src/traits/solve/cache.rs b/compiler/rustc_middle/src/traits/solve/cache.rs
index 9898b0019..e9e9cc418 100644
--- a/compiler/rustc_middle/src/traits/solve/cache.rs
+++ b/compiler/rustc_middle/src/traits/solve/cache.rs
@@ -1,4 +1,4 @@
-use super::{CanonicalInput, QueryResult};
+use super::{inspect, CanonicalInput, QueryResult};
use crate::ty::TyCtxt;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::sync::Lock;
@@ -14,8 +14,10 @@ pub struct EvaluationCache<'tcx> {
map: Lock<FxHashMap<CanonicalInput<'tcx>, CacheEntry<'tcx>>>,
}
+#[derive(PartialEq, Eq)]
pub struct CacheData<'tcx> {
pub result: QueryResult<'tcx>,
+ pub proof_tree: Option<&'tcx [inspect::GoalEvaluationStep<'tcx>]>,
pub reached_depth: usize,
pub encountered_overflow: bool,
}
@@ -24,22 +26,33 @@ impl<'tcx> EvaluationCache<'tcx> {
/// Insert a final result into the global cache.
pub fn insert(
&self,
+ tcx: TyCtxt<'tcx>,
key: CanonicalInput<'tcx>,
+ proof_tree: Option<&'tcx [inspect::GoalEvaluationStep<'tcx>]>,
reached_depth: usize,
- did_overflow: bool,
+ encountered_overflow: bool,
cycle_participants: FxHashSet<CanonicalInput<'tcx>>,
dep_node: DepNodeIndex,
result: QueryResult<'tcx>,
) {
let mut map = self.map.borrow_mut();
let entry = map.entry(key).or_default();
- let data = WithDepNode::new(dep_node, result);
+ let data = WithDepNode::new(dep_node, QueryData { result, proof_tree });
entry.cycle_participants.extend(cycle_participants);
- if did_overflow {
+ if encountered_overflow {
entry.with_overflow.insert(reached_depth, data);
} else {
entry.success = Some(Success { data, reached_depth });
}
+
+ if cfg!(debug_assertions) {
+ drop(map);
+ if Some(CacheData { result, proof_tree, reached_depth, encountered_overflow })
+ != self.get(tcx, key, |_| false, Limit(reached_depth))
+ {
+ bug!("unable to retrieve inserted element from cache: {key:?}");
+ }
+ }
}
/// Try to fetch a cached result, checking the recursion limit
@@ -62,27 +75,39 @@ impl<'tcx> EvaluationCache<'tcx> {
if let Some(ref success) = entry.success {
if available_depth.value_within_limit(success.reached_depth) {
+ let QueryData { result, proof_tree } = success.data.get(tcx);
return Some(CacheData {
- result: success.data.get(tcx),
+ result,
+ proof_tree,
reached_depth: success.reached_depth,
encountered_overflow: false,
});
}
}
- entry.with_overflow.get(&available_depth.0).map(|e| CacheData {
- result: e.get(tcx),
- reached_depth: available_depth.0,
- encountered_overflow: true,
+ entry.with_overflow.get(&available_depth.0).map(|e| {
+ let QueryData { result, proof_tree } = e.get(tcx);
+ CacheData {
+ result,
+ proof_tree,
+ reached_depth: available_depth.0,
+ encountered_overflow: true,
+ }
})
}
}
struct Success<'tcx> {
- data: WithDepNode<QueryResult<'tcx>>,
+ data: WithDepNode<QueryData<'tcx>>,
reached_depth: usize,
}
+#[derive(Clone, Copy)]
+pub struct QueryData<'tcx> {
+ pub result: QueryResult<'tcx>,
+ pub proof_tree: Option<&'tcx [inspect::GoalEvaluationStep<'tcx>]>,
+}
+
/// The cache entry for a goal `CanonicalInput`.
///
/// This contains results whose computation never hit the
@@ -96,5 +121,5 @@ struct CacheEntry<'tcx> {
/// See the doc comment of `StackEntry::cycle_participants` for more
/// details.
cycle_participants: FxHashSet<CanonicalInput<'tcx>>,
- with_overflow: FxHashMap<usize, WithDepNode<QueryResult<'tcx>>>,
+ with_overflow: FxHashMap<usize, WithDepNode<QueryData<'tcx>>>,
}