@@ -83,20 +83,59 @@ judgment_fn! {
83
83
) => Constraints {
84
84
debug( v, b, assumptions, env)
85
85
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.
86
93
(
87
94
( if let None = t. downcast:: <Variable >( ) )
88
95
( equate_variable( decls, env, assumptions, v, t) => c)
89
96
----------------------------- ( "existential-nonvar" )
90
97
( prove_existential_var_eq( decls, env, assumptions, v, t) => c)
91
98
)
92
99
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.
93
118
(
94
119
// Map the higher rank variable to the lower rank one.
95
120
( let ( a, b) = env. order_by_universe( l, r) )
96
121
----------------------------- ( "existential-existential" )
97
122
( prove_existential_var_eq( _decls, env, _assumptions, l, Variable :: ExistentialVar ( r) ) => ( env, ( b, a) ) )
98
123
)
99
124
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.
100
139
(
101
140
( if env. universe( p) < env. universe( v) )
102
141
----------------------------- ( "existential-universal" )
0 commit comments