Skip to content

Commit f7acec3

Browse files
committed
more comments
1 parent 3232de6 commit f7acec3

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,20 +83,59 @@ judgment_fn! {
8383
) => Constraints {
8484
debug(v, b, assumptions, env)
8585

86+
// If the RHS is *not* a variable, e.g., we are trying to prove something like this
87+
//
88+
// * `?A = u32`
89+
// * `?A = 'static`
90+
//
91+
// then we have learned something about what `?A` must be. The
92+
// `equate_variable` judgment manages that case.
8693
(
8794
(if let None = t.downcast::<Variable>())
8895
(equate_variable(decls, env, assumptions, v, t) => c)
8996
----------------------------- ("existential-nonvar")
9097
(prove_existential_var_eq(decls, env, assumptions, v, t) => c)
9198
)
9299

100+
// If the RHS IS an existential variable, e.g., we are trying to prove something like this
101+
//
102+
// * `?A = ?B`
103+
//
104+
// then we can either map `?A` to `?B` or vice versa.
105+
// Whichever way, they must be the same.
106+
//
107+
// We pick the variable with the higher universe and map it to the one with the lower universe,
108+
// which makes sense, consider:
109+
//
110+
// exists<A> { forall<C> { exists<B> { A = B } } && A = u32 }
111+
// --------- --------- ---------
112+
// | | |
113+
// | universe 1 universe 1
114+
// universe 0
115+
//
116+
// B is not in scope everywhere that A is in scope, so we can't replace
117+
// A with B universally. But we CAN replace B with a universally.
93118
(
94119
// Map the higher rank variable to the lower rank one.
95120
(let (a, b) = env.order_by_universe(l, r))
96121
----------------------------- ("existential-existential")
97122
(prove_existential_var_eq(_decls, env, _assumptions, l, Variable::ExistentialVar(r)) => (env, (b, a)))
98123
)
99124

125+
// If the RHS IS a universal variable, e.g., we are trying to prove something like this
126+
//
127+
// * `?A = !B`
128+
//
129+
// then we can map `?A` to `!B`, so long as the universes work out:
130+
//
131+
// exists<A> { exists<B> { A = B } && A = u32 }
132+
// --------- ---------
133+
// | |
134+
// | universe 2
135+
// universe 1
136+
//
137+
// B is not in scope everywhere that A is in scope, so we can't replace
138+
// A with B universally. But we CAN replace B with a universally.
100139
(
101140
(if env.universe(p) < env.universe(v))
102141
----------------------------- ("existential-universal")

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ judgment_fn! {
6161
(if let Ty(_) = param1.clone())!
6262
(if let Ty(_) = param2.clone())!
6363
(if param1 == param2)!
64-
----------------------------- ("subtype - reflexive")
64+
----------------------------- ("subtype - reflexive")
6565
(prove_wc(_decls, env, _assumptions, WcData::Relation(Relation::Sub(param1, param2))) => Constraints::none(env))
6666
)
6767

0 commit comments

Comments
 (0)