Skip to content

Commit 3aafbd1

Browse files
authored
Merge pull request #193 from tiif/comment
Add comments
2 parents ce960b3 + f4945e8 commit 3aafbd1

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ use crate::{
77
};
88

99
judgment_fn! {
10+
/// Check whether the where-clause `via` (which is one of the `assumptions` that are in in scope)
11+
/// can be used to prove `goal` (the thing we are trying to prove).
12+
///
13+
/// This is equivalent to the "elaboration" of the environment that takes place in rustc,
14+
/// but done lazilly. For example, if you have `where T: Eq` then you can clearly prove `T: Eq`
15+
/// but you can also prove `T: PartialEq` because `trait Eq: PartialEq`.
1016
pub fn prove_via(
1117
_decls: Decls,
1218
env: Env,
@@ -17,7 +23,9 @@ judgment_fn! {
1723
debug(goal, via, assumptions, env)
1824

1925
(
26+
// `c` = "clause", the name for something that we are assuming is true.
2027
(let (skel_c, parameters_c) = pred_1.debone())
28+
// `g` = "goal, the name for something that we are trying to prove.
2129
(let (skel_g, parameters_g) = pred_2.debone())
2230
(if skel_c == skel_g)!
2331
(prove(decls, env, assumptions, Wcs::all_eq(parameters_c, parameters_g)) => c)
@@ -34,16 +42,21 @@ judgment_fn! {
3442
(prove_via(_decls, env, _assumptions, WcData::Relation(rel_1), WcData::Relation(rel_2)) => Constraints::none(env))
3543
)
3644

45+
// If you have `where for<'a> T: Trait<'a>` then you can prove `T: Trait<'b>` for any `'b`.
3746
(
3847
(let (env, subst) = env.existential_substitution(&binder))
3948
(let via1 = binder.instantiate_with(&subst).unwrap())
49+
// Try to prove `T: Trait<?a> == goal`.
4050
(prove_via(decls, env, assumptions, via1, goal) => c)
4151
----------------------------- ("forall")
4252
(prove_via(decls, env, assumptions, WcData::ForAll(binder), goal) => c.pop_subst(&subst))
4353
)
4454

55+
// If you have `where if (T: Debug) T: Foo` (not in Rust but it should be...)...
4556
(
57+
// if the goal is `T: Foo`...
4658
(prove_via(&decls, env, &assumptions, wc_consequence, goal) => c)
59+
// ...and we can prove `T: Debug`... then it holds.
4760
(prove_after(&decls, c, &assumptions, &wc_condition) => c)
4861
----------------------------- ("implies")
4962
(prove_via(decls, env, assumptions, WcData::Implies(wc_condition, wc_consequence), goal) => c)

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,16 @@ impl Wc {
121121

122122
#[term]
123123
pub enum WcData {
124+
/// Means the built-in relation holds.
124125
#[cast]
125126
Relation(Relation),
126127

128+
/// Means the predicate holds.
127129
#[cast]
128130
Predicate(Predicate),
129131

132+
// Equivalent to `for<'a>` except that it can also express `for<ty T>` and so forth:
133+
// means `$v0` is true for any value of the bound variables (e.g., `'a` or `T`).
130134
#[grammar(for $v0)]
131135
ForAll(Binder<Wc>),
132136

0 commit comments

Comments
 (0)