|
1 |
| -use formality_core::judgment_fn; |
2 |
| -use formality_types::grammar::{Predicate, Relation, Wc, WcData, Wcs}; |
3 |
| - |
4 |
| -use crate::{ |
5 |
| - decls::Decls, |
6 |
| - prove::{ |
7 |
| - env::Env, |
8 |
| - is_local::{is_local_trait_ref, may_be_remote}, |
9 |
| - prove, |
10 |
| - prove_after::prove_after, |
11 |
| - prove_eq::prove_eq, |
12 |
| - prove_via::prove_via, |
13 |
| - prove_wf::prove_wf, |
14 |
| - }, |
| 1 | +use crate::prove; |
| 2 | +use crate::prove::prove_eq::prove_eq; |
| 3 | +use crate::prove::prove_wf::prove_wf; |
| 4 | +use crate::prove::prove_after::prove_after; |
| 5 | +use crate::prove::is_local::is_local_trait_ref; |
| 6 | +use crate::prove::prove_via::prove_via; |
| 7 | +use crate::prove::is_local::may_be_remote; |
| 8 | +use crate::Env; |
| 9 | +use crate::Decls; |
| 10 | + |
| 11 | +use crate::Constraints; |
| 12 | +use formality_core::{judgment_fn, Upcasted, ProvenSet}; |
| 13 | +use formality_types::grammar::{ |
| 14 | + Const, ExhaustiveState, Parameter, Predicate, Relation, Scalar, Ty, Wc, WcData, Wcs, |
15 | 15 | };
|
16 | 16 |
|
17 |
| -use super::constraints::Constraints; |
| 17 | +pub fn is_covering(vals: &[ExhaustiveState], params: &[Parameter]) -> Wcs { |
| 18 | + assert_eq!(vals.len(), params.len()); |
| 19 | + vals.iter() |
| 20 | + .zip(params.iter()) |
| 21 | + .filter_map(|(a, b)| match a { |
| 22 | + ExhaustiveState::ExactMatch => None, |
| 23 | + ExhaustiveState::ConstCover(cs) => { |
| 24 | + let Parameter::Const(c) = b else { |
| 25 | + todo!(); |
| 26 | + }; |
| 27 | + Some(Predicate::Covers(cs.clone(), c.clone())) |
| 28 | + } |
| 29 | + }) |
| 30 | + .upcasted() |
| 31 | + .collect() |
| 32 | +} |
18 | 33 |
|
19 | 34 | judgment_fn! {
|
20 | 35 | pub fn prove_wc(
|
@@ -46,6 +61,38 @@ judgment_fn! {
|
46 | 61 | (prove_wc(decls, env, assumptions, WcData::PR(goal)) => c)
|
47 | 62 | )
|
48 | 63 |
|
| 64 | + /* |
| 65 | + ( |
| 66 | + (let mut covering_consts = vec![ExhaustiveState::ExactMatch; trait_ref.parameters.len()]) |
| 67 | + (let asmp = &assumptions) |
| 68 | + (let d = &decls) |
| 69 | + (d.impl_decls(&trait_ref.trait_id).flat_map(|i| { |
| 70 | +
|
| 71 | + let (env, subst) = env.clone().existential_substitution(&i.binder); |
| 72 | + let i = i.binder.instantiate_with(&subst).unwrap(); |
| 73 | + let co_assumptions = (asmp, &trait_ref); |
| 74 | + let cs = prove( |
| 75 | + &decls, env, &co_assumptions, |
| 76 | + Wcs::eq_or_cover( |
| 77 | + &i.trait_ref.parameters, &trait_ref.parameters, &mut covering_consts |
| 78 | + ) |
| 79 | + ); |
| 80 | + let cs = cs.flat_map(move |c| { |
| 81 | + prove_after(d, c, &co_assumptions, &i.where_clause) |
| 82 | + }); |
| 83 | + let cs = cs.flat_map(move |c| { |
| 84 | + let t = d.trait_decl(&i.trait_ref.trait_id) |
| 85 | + .binder.instantiate_with(&i.trait_ref.parameters).unwrap(); |
| 86 | + prove_after(d, c, asmp, &t.where_clause) |
| 87 | + }); |
| 88 | + cs.into_iter() |
| 89 | + }).into_iter().collect::<ProvenSet<_>>() => c) |
| 90 | + (prove_after(d, c, asmp, is_covering(&covering_consts, &trait_ref.parameters)) => _c) |
| 91 | + ----------------------------- ("exhaustive positive impl") |
| 92 | + (prove_wc(_d, env, _asmp, Predicate::IsImplemented(trait_ref)) => Constraints::none(env.clone())) |
| 93 | + ) |
| 94 | + */ |
| 95 | + |
49 | 96 | (
|
50 | 97 | (decls.impl_decls(&trait_ref.trait_id) => i)!
|
51 | 98 | (let (env, subst) = env.existential_substitution(&i.binder))
|
@@ -112,6 +159,25 @@ judgment_fn! {
|
112 | 159 | (prove_wc(decls, env, assumptions, Predicate::IsLocal(trait_ref)) => c)
|
113 | 160 | )
|
114 | 161 |
|
| 162 | + ( |
| 163 | + (let () = vals.sort_unstable()) |
| 164 | + (prove(&decls, env, &assumptions, Predicate::ConstHasType(var, Ty::bool())) => c) |
| 165 | + (vals.iter().cloned() => v) |
| 166 | + (prove_after(&decls, &c, &assumptions, Predicate::ConstHasType(v, Ty::bool())) => c) |
| 167 | + (if vals.len() == 2) |
| 168 | + (let mut i = 0) |
| 169 | + (vals.clone().into_iter().flat_map(|v| { |
| 170 | + i += 1; |
| 171 | + prove_after( |
| 172 | + &decls, &c, &assumptions, |
| 173 | + Relation::Equals(Parameter::Const(Const::valtree(Scalar::new(i as u128), |
| 174 | + Ty::bool())), Parameter::Const(v)) |
| 175 | + ).into_iter() |
| 176 | + }).collect::<ProvenSet<_>>() => c) |
| 177 | + ----------------------------- ("exhaustive bool values cover variable") |
| 178 | + (prove_wc(decls, env, assumptions, Predicate::Covers(mut vals, var)) => c) |
| 179 | + ) |
| 180 | + |
115 | 181 |
|
116 | 182 | (
|
117 | 183 | (prove_wf(decls, env, assumptions, p) => c)
|
|
0 commit comments