1
1
use formality_types:: {
2
2
cast:: { Downcast , Upcast } ,
3
3
cast_impl,
4
- derive_links:: { DowncastTo , UpcastFrom } ,
4
+ derive_links:: UpcastFrom ,
5
5
fold:: Fold ,
6
6
grammar:: { InferenceVar , Parameter , Substitution , Variable } ,
7
- term:: Term ,
8
7
visit:: Visit ,
9
8
} ;
10
9
11
10
use super :: env:: Env ;
12
11
13
12
#[ derive( Clone , PartialEq , Eq , PartialOrd , Ord , Debug , Hash ) ]
14
- pub struct Constraints < R : Term = ( ) > {
15
- result : R ,
13
+ pub struct Constraints {
16
14
known_true : bool ,
17
15
substitution : Substitution ,
18
16
}
19
17
20
- cast_impl ! ( impl ( R : Term ) Constraints < R > ) ;
18
+ cast_impl ! ( Constraints ) ;
21
19
22
20
impl < A , B > UpcastFrom < ( A , B ) > for Constraints
23
21
where
28
26
Constraints {
29
27
substitution : term. upcast ( ) ,
30
28
known_true : true ,
31
- result : ( ) ,
32
29
}
33
30
}
34
31
}
43
40
let c2 = Constraints {
44
41
substitution,
45
42
known_true : true ,
46
- result : ( ) ,
47
43
} ;
48
44
c2. assert_valid ( ) ;
49
45
c2
@@ -53,19 +49,18 @@ where
53
49
impl Default for Constraints {
54
50
fn default ( ) -> Self {
55
51
Self {
56
- result : ( ) ,
57
52
known_true : true ,
58
53
substitution : Default :: default ( ) ,
59
54
}
60
55
}
61
56
}
62
57
63
- impl < R : Term > Constraints < R > {
58
+ impl Constraints {
64
59
pub fn substitution ( & self ) -> & Substitution {
65
60
& self . substitution
66
61
}
67
62
68
- pub fn ambiguous ( self ) -> Constraints < R > {
63
+ pub fn ambiguous ( self ) -> Constraints {
69
64
Self {
70
65
known_true : false ,
71
66
..self
@@ -78,11 +73,8 @@ impl<R: Term> Constraints<R> {
78
73
///
79
74
/// * `self` -- the constraints from solving `A`
80
75
/// * `c2` -- the constraints from solving `B` (after applying substitution from `self` to `B`)
81
- pub fn seq < R2 : Term > ( & self , c2 : impl Upcast < Constraints < R2 > > ) -> Constraints < R2 >
82
- where
83
- R : CombineResults < R2 > ,
84
- {
85
- let c2: Constraints < R2 > = c2. upcast ( ) ;
76
+ pub fn seq ( & self , c2 : impl Upcast < Constraints > ) -> Constraints {
77
+ let c2: Constraints = c2. upcast ( ) ;
86
78
87
79
self . assert_valid ( ) ;
88
80
c2. assert_valid ( ) ;
@@ -108,7 +100,6 @@ impl<R: Term> Constraints<R> {
108
100
109
101
Constraints {
110
102
known_true : self . known_true && c2. known_true ,
111
- result : R :: combine ( & self . result , c2. result ) ,
112
103
substitution : c1_substitution. into_iter ( ) . chain ( c2. substitution ) . collect ( ) ,
113
104
}
114
105
}
@@ -125,7 +116,7 @@ impl<R: Term> Constraints<R> {
125
116
}
126
117
}
127
118
128
- pub fn pop_subst < V > ( mut self , mut env : Env , v : & [ V ] ) -> ( Env , Constraints < R > )
119
+ pub fn pop_subst < V > ( mut self , mut env : Env , v : & [ V ] ) -> ( Env , Self )
129
120
where
130
121
V : Upcast < Variable > + Copy ,
131
122
{
@@ -142,12 +133,11 @@ impl<R: Term> Constraints<R> {
142
133
}
143
134
}
144
135
145
- impl < R : Term > Fold for Constraints < R > {
136
+ impl Fold for Constraints {
146
137
fn substitute ( & self , substitution_fn : formality_types:: fold:: SubstitutionFn < ' _ > ) -> Self {
147
138
let c2 = Constraints {
148
139
known_true : self . known_true ,
149
140
substitution : self . substitution . substitute ( substitution_fn) ,
150
- result : self . result . substitute ( substitution_fn) ,
151
141
} ;
152
142
153
143
// not all substitutions preserve the constraint set invariant
@@ -157,35 +147,28 @@ impl<R: Term> Fold for Constraints<R> {
157
147
}
158
148
}
159
149
160
- impl < R : Term > Visit for Constraints < R > {
150
+ impl Visit for Constraints {
161
151
fn free_variables ( & self ) -> Vec < Variable > {
162
152
let Constraints {
163
153
known_true : _,
164
154
substitution,
165
- result,
166
155
} = self ;
167
156
168
- substitution
169
- . free_variables ( )
170
- . into_iter ( )
171
- . chain ( result. free_variables ( ) )
172
- . collect ( )
157
+ substitution. free_variables ( ) . into_iter ( ) . collect ( )
173
158
}
174
159
175
160
fn size ( & self ) -> usize {
176
161
let Constraints {
177
162
known_true : _,
178
163
substitution,
179
- result,
180
164
} = self ;
181
- substitution. size ( ) + result . size ( )
165
+ substitution. size ( )
182
166
}
183
167
184
168
fn assert_valid ( & self ) {
185
169
let Constraints {
186
170
known_true : _,
187
171
substitution,
188
- result,
189
172
} = self ;
190
173
191
174
let domain = substitution. domain ( ) ;
@@ -200,8 +183,6 @@ impl<R: Term> Visit for Constraints<R> {
200
183
range
201
184
. iter ( )
202
185
. for_each ( |t| assert ! ( domain. iter( ) . all( |& v| !occurs_in( v, t) ) ) ) ;
203
-
204
- result. assert_valid ( ) ;
205
186
}
206
187
}
207
188
@@ -225,25 +206,7 @@ pub fn is_valid_binding(v: impl Upcast<Variable>, t: &impl Visit) -> bool {
225
206
226
207
pub fn no_constraints ( ) -> Constraints {
227
208
Constraints {
228
- result : ( ) ,
229
209
known_true : true ,
230
210
substitution : Substitution :: default ( ) ,
231
211
}
232
212
}
233
-
234
- pub trait CombineResults < R > {
235
- fn combine ( r0 : & Self , r1 : R ) -> R ;
236
- }
237
-
238
- impl < R > CombineResults < R > for ( ) {
239
- fn combine ( ( ) : & ( ) , r1 : R ) -> R {
240
- r1
241
- }
242
- }
243
-
244
- impl CombineResults < Vec < Parameter > > for Parameter {
245
- fn combine ( r0 : & Self , mut r1 : Vec < Parameter > ) -> Vec < Parameter > {
246
- r1. push ( r0. clone ( ) ) ;
247
- r1
248
- }
249
- }
0 commit comments