Skip to content

Commit 9f81ffe

Browse files
committed
remove R type parameter from constraints
1 parent 31b3aeb commit 9f81ffe

File tree

1 file changed

+12
-49
lines changed

1 file changed

+12
-49
lines changed

crates/formality-prove/src/prove/constraints.rs

Lines changed: 12 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
11
use formality_types::{
22
cast::{Downcast, Upcast},
33
cast_impl,
4-
derive_links::{DowncastTo, UpcastFrom},
4+
derive_links::UpcastFrom,
55
fold::Fold,
66
grammar::{InferenceVar, Parameter, Substitution, Variable},
7-
term::Term,
87
visit::Visit,
98
};
109

1110
use super::env::Env;
1211

1312
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
14-
pub struct Constraints<R: Term = ()> {
15-
result: R,
13+
pub struct Constraints {
1614
known_true: bool,
1715
substitution: Substitution,
1816
}
1917

20-
cast_impl!(impl(R: Term) Constraints<R>);
18+
cast_impl!(Constraints);
2119

2220
impl<A, B> UpcastFrom<(A, B)> for Constraints
2321
where
@@ -28,7 +26,6 @@ where
2826
Constraints {
2927
substitution: term.upcast(),
3028
known_true: true,
31-
result: (),
3229
}
3330
}
3431
}
@@ -43,7 +40,6 @@ where
4340
let c2 = Constraints {
4441
substitution,
4542
known_true: true,
46-
result: (),
4743
};
4844
c2.assert_valid();
4945
c2
@@ -53,19 +49,18 @@ where
5349
impl Default for Constraints {
5450
fn default() -> Self {
5551
Self {
56-
result: (),
5752
known_true: true,
5853
substitution: Default::default(),
5954
}
6055
}
6156
}
6257

63-
impl<R: Term> Constraints<R> {
58+
impl Constraints {
6459
pub fn substitution(&self) -> &Substitution {
6560
&self.substitution
6661
}
6762

68-
pub fn ambiguous(self) -> Constraints<R> {
63+
pub fn ambiguous(self) -> Constraints {
6964
Self {
7065
known_true: false,
7166
..self
@@ -78,11 +73,8 @@ impl<R: Term> Constraints<R> {
7873
///
7974
/// * `self` -- the constraints from solving `A`
8075
/// * `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();
8678

8779
self.assert_valid();
8880
c2.assert_valid();
@@ -108,7 +100,6 @@ impl<R: Term> Constraints<R> {
108100

109101
Constraints {
110102
known_true: self.known_true && c2.known_true,
111-
result: R::combine(&self.result, c2.result),
112103
substitution: c1_substitution.into_iter().chain(c2.substitution).collect(),
113104
}
114105
}
@@ -125,7 +116,7 @@ impl<R: Term> Constraints<R> {
125116
}
126117
}
127118

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)
129120
where
130121
V: Upcast<Variable> + Copy,
131122
{
@@ -142,12 +133,11 @@ impl<R: Term> Constraints<R> {
142133
}
143134
}
144135

145-
impl<R: Term> Fold for Constraints<R> {
136+
impl Fold for Constraints {
146137
fn substitute(&self, substitution_fn: formality_types::fold::SubstitutionFn<'_>) -> Self {
147138
let c2 = Constraints {
148139
known_true: self.known_true,
149140
substitution: self.substitution.substitute(substitution_fn),
150-
result: self.result.substitute(substitution_fn),
151141
};
152142

153143
// not all substitutions preserve the constraint set invariant
@@ -157,35 +147,28 @@ impl<R: Term> Fold for Constraints<R> {
157147
}
158148
}
159149

160-
impl<R: Term> Visit for Constraints<R> {
150+
impl Visit for Constraints {
161151
fn free_variables(&self) -> Vec<Variable> {
162152
let Constraints {
163153
known_true: _,
164154
substitution,
165-
result,
166155
} = self;
167156

168-
substitution
169-
.free_variables()
170-
.into_iter()
171-
.chain(result.free_variables())
172-
.collect()
157+
substitution.free_variables().into_iter().collect()
173158
}
174159

175160
fn size(&self) -> usize {
176161
let Constraints {
177162
known_true: _,
178163
substitution,
179-
result,
180164
} = self;
181-
substitution.size() + result.size()
165+
substitution.size()
182166
}
183167

184168
fn assert_valid(&self) {
185169
let Constraints {
186170
known_true: _,
187171
substitution,
188-
result,
189172
} = self;
190173

191174
let domain = substitution.domain();
@@ -200,8 +183,6 @@ impl<R: Term> Visit for Constraints<R> {
200183
range
201184
.iter()
202185
.for_each(|t| assert!(domain.iter().all(|&v| !occurs_in(v, t))));
203-
204-
result.assert_valid();
205186
}
206187
}
207188

@@ -225,25 +206,7 @@ pub fn is_valid_binding(v: impl Upcast<Variable>, t: &impl Visit) -> bool {
225206

226207
pub fn no_constraints() -> Constraints {
227208
Constraints {
228-
result: (),
229209
known_true: true,
230210
substitution: Substitution::default(),
231211
}
232212
}
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

Comments
 (0)