Skip to content

Commit 6804280

Browse files
committed
check wf'd ness of placeholders
1 parent 2099cb1 commit 6804280

File tree

4 files changed

+64
-6
lines changed

4 files changed

+64
-6
lines changed

crates/formality-prove/src/prove.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ mod prove_normalize;
88
mod prove_via;
99
mod prove_wc;
1010
mod prove_wc_list;
11+
mod prove_wf;
1112
mod combinators;
1213

1314
pub use constraints::Constraints;

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use crate::{
1212
prove_after::prove_after,
1313
prove_eq::prove_eq,
1414
prove_via::prove_via,
15+
prove_wf::prove_wf,
1516
},
1617
};
1718

@@ -106,5 +107,12 @@ judgment_fn! {
106107
----------------------------- ("trait ref is local")
107108
(prove_wc(decls, env, assumptions, Predicate::IsLocal(trait_ref)) => c)
108109
)
110+
111+
112+
(
113+
(prove_wf(decls, env, assumptions, p) => c)
114+
----------------------------- ("trait ref is local")
115+
(prove_wc(decls, env, assumptions, Relation::WellFormed(p)) => c)
116+
)
109117
}
110118
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
use formality_types::{
2+
grammar::{Parameter, PlaceholderVar, Wcs},
3+
judgment_fn,
4+
};
5+
6+
use crate::decls::Decls;
7+
8+
use super::{constraints::Constraints, env::Env};
9+
10+
judgment_fn! {
11+
pub fn prove_wf(
12+
decls: Decls,
13+
env: Env,
14+
assumptions: Wcs,
15+
goal: Parameter,
16+
) => Constraints {
17+
debug(goal, assumptions, env, decls)
18+
19+
assert(env.encloses((&assumptions, &goal)))
20+
21+
(
22+
// Always assume that universal variables are WF. This is debatable, it implies
23+
// that we ensure by construction that the values we infer for existential variables
24+
// are WF. An alternative would be to add explicit assumptions into the environment
25+
// for every universal variable. That just seems tedious.
26+
--- ("universal variables")
27+
(prove_wf(_decls, env, _assumptions, PlaceholderVar { .. }) => Constraints::none(env))
28+
)
29+
}
30+
}

tests/associated_type_normalization.rs

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,31 @@ fn test_mirror_normalizes_u32_to_u32() {
66
// where there is a negative impl, so it is accepted.
77

88
expect_test::expect![[r#"
9-
Err(
10-
Error {
11-
context: "check_trait_impl(impl <ty> Mirror < > for ^ty0_0 where [] { type Assoc <> = ^ty1_0 where [] ; })",
12-
source: Error {
13-
context: "check_associated_ty_value(type Assoc <> = !ty_1 where [] ;)",
14-
source: "failed to prove {@ wf(!ty_1)} given {}, got {}",
9+
Ok(
10+
{
11+
Constraints {
12+
env: Env {
13+
variables: [
14+
?ty_1,
15+
],
16+
coherence_mode: false,
17+
},
18+
known_true: true,
19+
substitution: {
20+
?ty_1 => (rigid (scalar u32)),
21+
},
22+
},
23+
Constraints {
24+
env: Env {
25+
variables: [
26+
?ty_1,
27+
],
28+
coherence_mode: false,
29+
},
30+
known_true: true,
31+
substitution: {
32+
?ty_1 => (alias (Mirror :: Assoc) (rigid (scalar u32))),
33+
},
1534
},
1635
},
1736
)

0 commit comments

Comments
 (0)