1- use super :: { CanonicalInput , QueryResult } ;
1+ use super :: { inspect , CanonicalInput , QueryResult } ;
22use crate :: ty:: TyCtxt ;
33use rustc_data_structures:: fx:: { FxHashMap , FxHashSet } ;
44use rustc_data_structures:: sync:: Lock ;
@@ -14,8 +14,10 @@ pub struct EvaluationCache<'tcx> {
1414 map : Lock < FxHashMap < CanonicalInput < ' tcx > , CacheEntry < ' tcx > > > ,
1515}
1616
17+ #[ derive( PartialEq , Eq ) ]
1718pub struct CacheData < ' tcx > {
1819 pub result : QueryResult < ' tcx > ,
20+ pub proof_tree : Option < & ' tcx [ inspect:: GoalEvaluationStep < ' tcx > ] > ,
1921 pub reached_depth : usize ,
2022 pub encountered_overflow : bool ,
2123}
@@ -24,22 +26,33 @@ impl<'tcx> EvaluationCache<'tcx> {
2426 /// Insert a final result into the global cache.
2527 pub fn insert (
2628 & self ,
29+ tcx : TyCtxt < ' tcx > ,
2730 key : CanonicalInput < ' tcx > ,
31+ proof_tree : Option < & ' tcx [ inspect:: GoalEvaluationStep < ' tcx > ] > ,
2832 reached_depth : usize ,
29- did_overflow : bool ,
33+ encountered_overflow : bool ,
3034 cycle_participants : FxHashSet < CanonicalInput < ' tcx > > ,
3135 dep_node : DepNodeIndex ,
3236 result : QueryResult < ' tcx > ,
3337 ) {
3438 let mut map = self . map . borrow_mut ( ) ;
3539 let entry = map. entry ( key) . or_default ( ) ;
36- let data = WithDepNode :: new ( dep_node, result) ;
40+ let data = WithDepNode :: new ( dep_node, QueryData { result, proof_tree } ) ;
3741 entry. cycle_participants . extend ( cycle_participants) ;
38- if did_overflow {
42+ if encountered_overflow {
3943 entry. with_overflow . insert ( reached_depth, data) ;
4044 } else {
4145 entry. success = Some ( Success { data, reached_depth } ) ;
4246 }
47+
48+ if cfg ! ( debug_assertions) {
49+ drop ( map) ;
50+ if Some ( CacheData { result, proof_tree, reached_depth, encountered_overflow } )
51+ != self . get ( tcx, key, |_| false , Limit ( reached_depth) )
52+ {
53+ bug ! ( "unable to retrieve inserted element from cache: {key:?}" ) ;
54+ }
55+ }
4356 }
4457
4558 /// Try to fetch a cached result, checking the recursion limit
@@ -62,27 +75,39 @@ impl<'tcx> EvaluationCache<'tcx> {
6275
6376 if let Some ( ref success) = entry. success {
6477 if available_depth. value_within_limit ( success. reached_depth ) {
78+ let QueryData { result, proof_tree } = success. data . get ( tcx) ;
6579 return Some ( CacheData {
66- result : success. data . get ( tcx) ,
80+ result,
81+ proof_tree,
6782 reached_depth : success. reached_depth ,
6883 encountered_overflow : false ,
6984 } ) ;
7085 }
7186 }
7287
73- entry. with_overflow . get ( & available_depth. 0 ) . map ( |e| CacheData {
74- result : e. get ( tcx) ,
75- reached_depth : available_depth. 0 ,
76- encountered_overflow : true ,
88+ entry. with_overflow . get ( & available_depth. 0 ) . map ( |e| {
89+ let QueryData { result, proof_tree } = e. get ( tcx) ;
90+ CacheData {
91+ result,
92+ proof_tree,
93+ reached_depth : available_depth. 0 ,
94+ encountered_overflow : true ,
95+ }
7796 } )
7897 }
7998}
8099
81100struct Success < ' tcx > {
82- data : WithDepNode < QueryResult < ' tcx > > ,
101+ data : WithDepNode < QueryData < ' tcx > > ,
83102 reached_depth : usize ,
84103}
85104
105+ #[ derive( Clone , Copy ) ]
106+ pub struct QueryData < ' tcx > {
107+ pub result : QueryResult < ' tcx > ,
108+ pub proof_tree : Option < & ' tcx [ inspect:: GoalEvaluationStep < ' tcx > ] > ,
109+ }
110+
86111/// The cache entry for a goal `CanonicalInput`.
87112///
88113/// This contains results whose computation never hit the
@@ -96,5 +121,5 @@ struct CacheEntry<'tcx> {
96121 /// See the doc comment of `StackEntry::cycle_participants` for more
97122 /// details.
98123 cycle_participants : FxHashSet < CanonicalInput < ' tcx > > ,
99- with_overflow : FxHashMap < usize , WithDepNode < QueryResult < ' tcx > > > ,
124+ with_overflow : FxHashMap < usize , WithDepNode < QueryData < ' tcx > > > ,
100125}
0 commit comments