1
- use super :: { CanonicalInput , QueryResult } ;
1
+ use super :: { inspect , CanonicalInput , QueryResult } ;
2
2
use crate :: ty:: TyCtxt ;
3
3
use rustc_data_structures:: fx:: { FxHashMap , FxHashSet } ;
4
4
use rustc_data_structures:: sync:: Lock ;
@@ -14,8 +14,10 @@ pub struct EvaluationCache<'tcx> {
14
14
map : Lock < FxHashMap < CanonicalInput < ' tcx > , CacheEntry < ' tcx > > > ,
15
15
}
16
16
17
+ #[ derive( PartialEq , Eq ) ]
17
18
pub struct CacheData < ' tcx > {
18
19
pub result : QueryResult < ' tcx > ,
20
+ pub proof_tree : Option < & ' tcx [ inspect:: GoalEvaluationStep < ' tcx > ] > ,
19
21
pub reached_depth : usize ,
20
22
pub encountered_overflow : bool ,
21
23
}
@@ -24,22 +26,33 @@ impl<'tcx> EvaluationCache<'tcx> {
24
26
/// Insert a final result into the global cache.
25
27
pub fn insert (
26
28
& self ,
29
+ tcx : TyCtxt < ' tcx > ,
27
30
key : CanonicalInput < ' tcx > ,
31
+ proof_tree : Option < & ' tcx [ inspect:: GoalEvaluationStep < ' tcx > ] > ,
28
32
reached_depth : usize ,
29
- did_overflow : bool ,
33
+ encountered_overflow : bool ,
30
34
cycle_participants : FxHashSet < CanonicalInput < ' tcx > > ,
31
35
dep_node : DepNodeIndex ,
32
36
result : QueryResult < ' tcx > ,
33
37
) {
34
38
let mut map = self . map . borrow_mut ( ) ;
35
39
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 } ) ;
37
41
entry. cycle_participants . extend ( cycle_participants) ;
38
- if did_overflow {
42
+ if encountered_overflow {
39
43
entry. with_overflow . insert ( reached_depth, data) ;
40
44
} else {
41
45
entry. success = Some ( Success { data, reached_depth } ) ;
42
46
}
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
+ }
43
56
}
44
57
45
58
/// Try to fetch a cached result, checking the recursion limit
@@ -62,27 +75,39 @@ impl<'tcx> EvaluationCache<'tcx> {
62
75
63
76
if let Some ( ref success) = entry. success {
64
77
if available_depth. value_within_limit ( success. reached_depth ) {
78
+ let QueryData { result, proof_tree } = success. data . get ( tcx) ;
65
79
return Some ( CacheData {
66
- result : success. data . get ( tcx) ,
80
+ result,
81
+ proof_tree,
67
82
reached_depth : success. reached_depth ,
68
83
encountered_overflow : false ,
69
84
} ) ;
70
85
}
71
86
}
72
87
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
+ }
77
96
} )
78
97
}
79
98
}
80
99
81
100
struct Success < ' tcx > {
82
- data : WithDepNode < QueryResult < ' tcx > > ,
101
+ data : WithDepNode < QueryData < ' tcx > > ,
83
102
reached_depth : usize ,
84
103
}
85
104
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
+
86
111
/// The cache entry for a goal `CanonicalInput`.
87
112
///
88
113
/// This contains results whose computation never hit the
@@ -96,5 +121,5 @@ struct CacheEntry<'tcx> {
96
121
/// See the doc comment of `StackEntry::cycle_participants` for more
97
122
/// details.
98
123
cycle_participants : FxHashSet < CanonicalInput < ' tcx > > ,
99
- with_overflow : FxHashMap < usize , WithDepNode < QueryResult < ' tcx > > > ,
124
+ with_overflow : FxHashMap < usize , WithDepNode < QueryData < ' tcx > > > ,
100
125
}
0 commit comments