Skip to content

Commit c98a93a

Browse files
committed
introduce "known true" into constraints
1 parent 55d704d commit c98a93a

File tree

4 files changed

+32
-6
lines changed

4 files changed

+32
-6
lines changed

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

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ use formality_types::{
99
visit::Visit,
1010
};
1111

12-
#[derive(Clone, Default, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
12+
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
1313
pub struct Constraints {
14+
known_true: bool,
1415
substitution: Substitution,
1516
}
1617

@@ -24,6 +25,16 @@ where
2425
fn upcast_from(term: (A, B)) -> Self {
2526
Constraints {
2627
substitution: term.upcast(),
28+
known_true: true,
29+
}
30+
}
31+
}
32+
33+
impl Default for Constraints {
34+
fn default() -> Self {
35+
Self {
36+
known_true: true,
37+
substitution: Default::default(),
2738
}
2839
}
2940
}
@@ -53,6 +64,13 @@ impl Constraints {
5364
.map(|(v, p)| AtomicRelation::eq(v, p))
5465
.collect()
5566
}
67+
68+
pub fn ambiguous(self) -> Constraints {
69+
Self {
70+
known_true: false,
71+
..self
72+
}
73+
}
5674
}
5775

5876
pub fn merge_constraints(
@@ -89,12 +107,20 @@ pub fn merge_constraints(
89107
.filter(|(v, _)| !existentials.contains(&v.upcast()))
90108
.collect();
91109

92-
Binder::mentioned((c1_bound_vars, existentials), Constraints { substitution })
110+
let known_true = c0.known_true && c1.known_true;
111+
Binder::mentioned(
112+
(c1_bound_vars, existentials),
113+
Constraints {
114+
known_true,
115+
substitution,
116+
},
117+
)
93118
}
94119

95120
impl Fold for Constraints {
96121
fn substitute(&self, substitution_fn: formality_types::fold::SubstitutionFn<'_>) -> Self {
97122
let c = Constraints {
123+
known_true: self.known_true,
98124
substitution: self.substitution.substitute(substitution_fn),
99125
};
100126

crates/formality-prove/src/test/eq_partial_eq.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ fn eq_implies_partial_eq() {
2626
let constraints = prove_wc_list(program, assumptions, goal);
2727
expect![[r#"
2828
{
29-
<> Constraints { substitution: Substitution { map: {} } },
29+
<> Constraints { known_true: true, substitution: Substitution { map: {} } },
3030
}
3131
"#]]
3232
.assert_debug_eq(&constraints);

crates/formality-prove/src/test/exists_constraints.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ fn exists_u_for_t() {
2323
let constraints = test_prove(&program, term("<ty U> ({}, {is_implemented(Foo(U))})"));
2424
expect![[r#"
2525
{
26-
<ty> Constraints { substitution: Substitution { map: {?ty_0: (rigid (adt Vec) ^ty0_0)} } },
26+
<ty> Constraints { known_true: true, substitution: Substitution { map: {?ty_0: (rigid (adt Vec) ^ty0_0)} } },
2727
}
2828
"#]]
2929
.assert_debug_eq(&constraints);

crates/formality-prove/src/test/simple_impl.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ fn vec_u32_debug() {
3030
let constraints = prove_wc_list(program, assumptions, goal);
3131
expect![[r#"
3232
{
33-
<> Constraints { substitution: Substitution { map: {} } },
33+
<> Constraints { known_true: true, substitution: Substitution { map: {} } },
3434
}
3535
"#]]
3636
.assert_debug_eq(&constraints);
@@ -44,7 +44,7 @@ fn vec_vec_u32_debug() {
4444
let constraints = prove_wc_list(program, assumptions, goal);
4545
expect![[r#"
4646
{
47-
<> Constraints { substitution: Substitution { map: {} } },
47+
<> Constraints { known_true: true, substitution: Substitution { map: {} } },
4848
}
4949
"#]]
5050
.assert_debug_eq(&constraints);

0 commit comments

Comments
 (0)