Skip to content

Commit ae30d7b

Browse files
committed
add more tests, rewrite equals notation
1 parent a1139b8 commit ae30d7b

File tree

4 files changed

+60
-26
lines changed

4 files changed

+60
-26
lines changed

crates/formality-prove/src/program.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,16 @@ impl Program {
5555
.flat_map(|td| td.trait_invariants())
5656
.collect()
5757
}
58+
59+
pub fn empty() -> Self {
60+
Self {
61+
max_size: Program::DEFAULT_MAX_SIZE,
62+
trait_decls: vec![],
63+
impl_decls: vec![],
64+
alias_eq_decls: vec![],
65+
alias_bound_decls: vec![],
66+
}
67+
}
5868
}
5969

6070
#[term(impl $binder)]

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

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,41 @@ fn program() -> Program {
2020
/// Test that `X = Vec<X>` cannot be solved
2121
#[test]
2222
fn direct_cycle() {
23-
let constraints = test_prove(program(), term("<ty A> ({}, {equals(A, Vec<A>)})"));
23+
let constraints = test_prove(program(), term("<ty A> ({}, {A = Vec<A>})"));
2424
expect![[r#"
2525
{}
2626
"#]]
2727
.assert_debug_eq(&constraints);
2828
}
2929

30+
/// Test that `X = Vec<Y>` can be solved
31+
#[test]
32+
fn eq_variable_to_rigid() {
33+
let constraints = test_prove(program(), term("<ty X, ty Y> ({}, {X = Vec<Y>})"));
34+
expect![[r#"
35+
{
36+
<> Constraints { known_true: true, substitution: Substitution { map: {?ty_0: (rigid (adt Vec) ?ty_1)} } },
37+
}
38+
"#]]
39+
.assert_debug_eq(&constraints);
40+
}
41+
42+
/// Test that `Vec<Y> = X` can be solved
43+
#[test]
44+
fn eq_rigid_to_variable() {
45+
let constraints = test_prove(program(), term("<ty X, ty Y> ({}, {Vec<Y> = X})"));
46+
expect![[r#"
47+
{
48+
<> Constraints { known_true: true, substitution: Substitution { map: {?ty_0: (rigid (adt Vec) ?ty_1)} } },
49+
}
50+
"#]]
51+
.assert_debug_eq(&constraints);
52+
}
53+
3054
/// Test that `X = Vec<X>` cannot be solved (when constructed over several steps)
3155
#[test]
3256
fn indirect_cycle_1() {
33-
let constraints = test_prove(
34-
program(),
35-
term("<ty A, ty B> ({}, {equals(A, Vec<B>), equals(B, A)})"),
36-
);
57+
let constraints = test_prove(program(), term("<ty A, ty B> ({}, {A = Vec<B>, B = A})"));
3758
expect![[r#"
3859
{}
3960
"#]]
@@ -43,10 +64,7 @@ fn indirect_cycle_1() {
4364
/// Test that `X = Vec<X>` cannot be solved (when constructed over several steps)
4465
#[test]
4566
fn indirect_cycle_2() {
46-
let constraints = test_prove(
47-
program(),
48-
term("<ty A, ty B> ({}, {equals(B, A), equals(A, Vec<B>)})"),
49-
);
67+
let constraints = test_prove(program(), term("<ty A, ty B> ({}, {B = A, A = Vec<B>})"));
5068
expect![[r#"
5169
{}
5270
"#]]

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

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,33 @@ use formality_types::parse::term;
44

55
use crate::program::Program;
66

7-
/// Simple example program consisting only of two trait declarations.
8-
fn program() -> Program {
9-
Program {
10-
max_size: Program::DEFAULT_MAX_SIZE,
11-
trait_decls: vec![],
12-
impl_decls: vec![],
13-
alias_eq_decls: vec![],
14-
alias_bound_decls: vec![],
15-
}
16-
}
17-
187
/// There is no U that is equal to all T.
198
#[test]
209
fn exists_u_for_t() {
21-
let constraints = super::test_prove(program(), term("<ty U> ({}, {for<ty T> equals(T, U)})"));
10+
let program = Program::empty();
11+
let constraints = super::test_prove(program, term("<ty U> ({}, {for<ty T> T = U})"));
2212
expect![[r#"
2313
{}
2414
"#]]
2515
.assert_debug_eq(&constraints);
2616
}
17+
18+
/// There is U that is equal to some T.
19+
#[test]
20+
fn for_t_exists_u() {
21+
let program = Program {
22+
max_size: Program::DEFAULT_MAX_SIZE,
23+
trait_decls: vec![term("trait Test<ty Self, ty T> where {}")],
24+
impl_decls: vec![term("impl<ty X, ty Y> Test(X, Y) where {X = Y}")],
25+
alias_eq_decls: vec![],
26+
alias_bound_decls: vec![],
27+
};
28+
29+
let constraints = super::test_prove(program, term("<> ({}, {for<ty T> Test(T, T)})"));
30+
expect![[r#"
31+
{
32+
<> Constraints { known_true: true, substitution: Substitution { map: {} } },
33+
}
34+
"#]]
35+
.assert_debug_eq(&constraints);
36+
}

crates/formality-types/src/grammar/formulas.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,19 +189,15 @@ impl AdtId {
189189
/// Relations are built-in goals which are implemented in custom Rust logic.
190190
#[term]
191191
pub enum AtomicRelation {
192-
/// `T1 == T2` etc
193-
#[grammar($v0 == $v1)]
192+
#[grammar($v0 = $v1)]
194193
Equals(Parameter, Parameter),
195194

196-
/// `T1 <: T2` or `L1 <: L2`
197195
#[grammar($v0 <: $v1)]
198196
Sub(Parameter, Parameter),
199197

200-
/// `P : P`
201198
#[grammar($v0 : $v1)]
202199
Outlives(Parameter, Parameter),
203200

204-
/// `WF(Parameter)`
205201
#[grammar(@wf($v0))]
206202
WellFormed(Parameter),
207203
}

0 commit comments

Comments
 (0)