1
+ use super :: stack:: StackDepth ;
2
+ use crate :: { Cache , Minimums } ;
3
+ use chalk_ir:: ClausePriority ;
4
+ use rustc_hash:: FxHashMap ;
5
+ use std:: fmt:: Debug ;
6
+ use std:: hash:: Hash ;
1
7
use std:: ops:: Add ;
2
8
use std:: ops:: Index ;
3
9
use std:: ops:: IndexMut ;
4
10
use std:: usize;
5
-
6
- use super :: stack:: StackDepth ;
7
- use crate :: { Cache , Minimums , UCanonicalGoal } ;
8
- use chalk_ir:: {
9
- interner:: Interner , Canonical , ClausePriority , ConstrainedSubst , Constraints , Fallible ,
10
- NoSolution ,
11
- } ;
12
- use chalk_solve:: Solution ;
13
- use rustc_hash:: FxHashMap ;
14
11
use tracing:: { debug, instrument} ;
15
12
16
13
/// The "search graph" stores in-progress goals that are still
17
14
/// being solved.
18
- pub ( super ) struct SearchGraph < I : Interner > {
19
- indices : FxHashMap < UCanonicalGoal < I > , DepthFirstNumber > ,
20
- nodes : Vec < Node < I > > ,
15
+ pub ( super ) struct SearchGraph < K , V >
16
+ where
17
+ K : Hash + Eq + Debug + Clone ,
18
+ V : Debug + Clone ,
19
+ {
20
+ indices : FxHashMap < K , DepthFirstNumber > ,
21
+ nodes : Vec < Node < K , V > > ,
21
22
}
22
23
23
24
#[ derive( Copy , Clone , Debug , PartialOrd , Ord , PartialEq , Eq , Hash ) ]
24
25
pub ( super ) struct DepthFirstNumber {
25
26
index : usize ,
26
27
}
27
28
28
- pub ( super ) struct Node < I : Interner > {
29
- pub ( crate ) goal : UCanonicalGoal < I > ,
29
+ pub ( super ) struct Node < K , V > {
30
+ pub ( crate ) goal : K ,
30
31
31
- pub ( crate ) solution : Fallible < Solution < I > > ,
32
+ pub ( crate ) solution : V ,
32
33
pub ( crate ) solution_priority : ClausePriority ,
33
34
34
35
/// This is `Some(X)` if we are actively exploring this node, or
@@ -42,15 +43,19 @@ pub(super) struct Node<I: Interner> {
42
43
pub ( crate ) links : Minimums ,
43
44
}
44
45
45
- impl < I : Interner > SearchGraph < I > {
46
+ impl < K , V > SearchGraph < K , V >
47
+ where
48
+ K : Hash + Eq + Debug + Clone ,
49
+ V : Debug + Clone ,
50
+ {
46
51
pub ( crate ) fn new ( ) -> Self {
47
52
SearchGraph {
48
53
indices : FxHashMap :: default ( ) ,
49
54
nodes : vec ! [ ] ,
50
55
}
51
56
}
52
57
53
- pub ( crate ) fn lookup ( & self , goal : & UCanonicalGoal < I > ) -> Option < DepthFirstNumber > {
58
+ pub ( crate ) fn lookup ( & self , goal : & K ) -> Option < DepthFirstNumber > {
54
59
self . indices . get ( goal) . cloned ( )
55
60
}
56
61
@@ -63,10 +68,9 @@ impl<I: Interner> SearchGraph<I> {
63
68
/// or `NoSolution` for other goals
64
69
pub ( crate ) fn insert (
65
70
& mut self ,
66
- goal : & UCanonicalGoal < I > ,
71
+ goal : & K ,
67
72
stack_depth : StackDepth ,
68
- coinductive : bool ,
69
- solution : Fallible < Solution < I > > ,
73
+ solution : V ,
70
74
) -> DepthFirstNumber {
71
75
let dfn = DepthFirstNumber {
72
76
index : self . nodes . len ( ) ,
@@ -94,7 +98,7 @@ impl<I: Interner> SearchGraph<I> {
94
98
/// Removes all nodes with a depth-first-number greater than or
95
99
/// equal to `dfn`, adding their final solutions into the cache.
96
100
#[ instrument( level = "debug" , skip( self , cache) ) ]
97
- pub ( crate ) fn move_to_cache ( & mut self , dfn : DepthFirstNumber , cache : & Cache < I > ) {
101
+ pub ( crate ) fn move_to_cache ( & mut self , dfn : DepthFirstNumber , cache : & Cache < K , V > ) {
98
102
self . indices . retain ( |_key, value| * value < dfn) ;
99
103
for node in self . nodes . drain ( dfn. index ..) {
100
104
assert ! ( node. stack_depth. is_none( ) ) ;
@@ -105,16 +109,24 @@ impl<I: Interner> SearchGraph<I> {
105
109
}
106
110
}
107
111
108
- impl < I : Interner > Index < DepthFirstNumber > for SearchGraph < I > {
109
- type Output = Node < I > ;
112
+ impl < K , V > Index < DepthFirstNumber > for SearchGraph < K , V >
113
+ where
114
+ K : Hash + Eq + Debug + Clone ,
115
+ V : Debug + Clone ,
116
+ {
117
+ type Output = Node < K , V > ;
110
118
111
- fn index ( & self , table_index : DepthFirstNumber ) -> & Node < I > {
119
+ fn index ( & self , table_index : DepthFirstNumber ) -> & Node < K , V > {
112
120
& self . nodes [ table_index. index ]
113
121
}
114
122
}
115
123
116
- impl < I : Interner > IndexMut < DepthFirstNumber > for SearchGraph < I > {
117
- fn index_mut ( & mut self , table_index : DepthFirstNumber ) -> & mut Node < I > {
124
+ impl < K , V > IndexMut < DepthFirstNumber > for SearchGraph < K , V >
125
+ where
126
+ K : Hash + Eq + Debug + Clone ,
127
+ V : Debug + Clone ,
128
+ {
129
+ fn index_mut ( & mut self , table_index : DepthFirstNumber ) -> & mut Node < K , V > {
118
130
& mut self . nodes [ table_index. index ]
119
131
}
120
132
}
0 commit comments