Skip to content

Commit 3ca921e

Browse files
committed
wrong univrese ordering
1 parent c821bbc commit 3ca921e

File tree

8 files changed

+47
-29
lines changed

8 files changed

+47
-29
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ fn equate_variable(
111111
) -> Option<(Env, Constraints)> {
112112
let p: Parameter = p.upcast();
113113

114+
let span = tracing::debug_span!("equate_variable", ?x, ?p, ?env);
115+
let _guard = span.enter();
116+
114117
let fvs = p.free_variables().deduplicate();
115118

116119
// Ensure that `x` passes the occurs check for the free variables in `p`.
@@ -146,6 +149,7 @@ fn equate_variable(
146149
.chain(Some((x, universe_subst.apply(&p)).upcast()))
147150
.collect();
148151

152+
tracing::debug!("success: env={:?}, constraints={:?}", env, constraints);
149153
Some((env, constraints))
150154
}
151155

@@ -161,7 +165,7 @@ fn passes_occurs_check(env: &Env, x: InferenceVar, fvs: &[Variable]) -> bool {
161165
for fv in fvs {
162166
match fv {
163167
Variable::PlaceholderVar(pv) => {
164-
if env.universe(pv) < universe_x {
168+
if universe_x < env.universe(pv) {
165169
return false;
166170
} else {
167171
}

crates/formality-prove/src/test/eq_assumptions.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ fn test_a() {
2121
Constraints {
2222
result: (),
2323
known_true: true,
24-
substitution: Substitution {
25-
map: {},
26-
},
24+
substitution: {},
2725
},
2826
),
2927
}

crates/formality-prove/src/test/exists_constraints.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,8 @@ fn exists_u_for_t() {
3333
Constraints {
3434
result: (),
3535
known_true: true,
36-
substitution: Substitution {
37-
map: {
38-
?ty_1_U(0): (rigid (adt Vec) ?ty_3_U(0)),
39-
},
36+
substitution: {
37+
?ty_1_U(0) => (rigid (adt Vec) ?ty_3_U(0)),
4038
},
4139
},
4240
),

crates/formality-prove/src/test/expanding.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ fn expanding() {
3030
Constraints {
3131
result: (),
3232
known_true: false,
33-
substitution: Substitution {
34-
map: {},
35-
},
33+
substitution: {},
3634
},
3735
),
3836
}

crates/formality-prove/src/test/occurs_check.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,9 @@ fn eq_variable_to_rigid() {
4444
Constraints {
4545
result: (),
4646
known_true: true,
47-
substitution: Substitution {
48-
map: {
49-
?ty_1_U(0): (rigid (adt Vec) ?ty_3_U(0)),
50-
?ty_2_U(0): ?ty_3_U(0),
51-
},
47+
substitution: {
48+
?ty_1_U(0) => (rigid (adt Vec) ?ty_3_U(0)),
49+
?ty_2_U(0) => ?ty_3_U(0),
5250
},
5351
},
5452
),
@@ -74,11 +72,9 @@ fn eq_rigid_to_variable() {
7472
Constraints {
7573
result: (),
7674
known_true: true,
77-
substitution: Substitution {
78-
map: {
79-
?ty_1_U(0): (rigid (adt Vec) ?ty_3_U(0)),
80-
?ty_2_U(0): ?ty_3_U(0),
81-
},
75+
substitution: {
76+
?ty_1_U(0) => (rigid (adt Vec) ?ty_3_U(0)),
77+
?ty_2_U(0) => ?ty_3_U(0),
8278
},
8379
},
8480
),

crates/formality-prove/src/test/simple_impl.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@ fn vec_u32_debug() {
3131
Constraints {
3232
result: (),
3333
known_true: true,
34-
substitution: Substitution {
35-
map: {},
36-
},
34+
substitution: {},
3735
},
3836
),
3937
}
@@ -54,9 +52,7 @@ fn vec_vec_u32_debug() {
5452
Constraints {
5553
result: (),
5654
known_true: true,
57-
substitution: Substitution {
58-
map: {},
59-
},
55+
substitution: {},
6056
},
6157
),
6258
}

crates/formality-prove/src/test/universes.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,16 @@ fn for_t_exists_u() {
2929
let constraints = super::test_prove(program, term("<> ({}, {for<ty T> Test(T, T)})"));
3030
expect![[r#"
3131
{
32-
<> Constraints { result: (), known_true: true, substitution: Substitution { map: {} } },
32+
(
33+
Env {
34+
variables: [],
35+
},
36+
Constraints {
37+
result: (),
38+
known_true: true,
39+
substitution: {},
40+
},
41+
),
3342
}
3443
"#]]
3544
.assert_debug_eq(&constraints);

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,7 @@ impl std::ops::Add<usize> for VarIndex {
628628
}
629629
}
630630

631-
#[derive(Clone, Default, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
631+
#[derive(Clone, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
632632
pub struct Substitution {
633633
map: Map<Variable, Parameter>,
634634
}
@@ -654,6 +654,25 @@ impl Substitution {
654654
}
655655
}
656656

657+
impl std::fmt::Debug for Substitution {
658+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
659+
let mut f = f.debug_set();
660+
for (v, p) in self.iter() {
661+
f.entry(&Entry { v, p });
662+
struct Entry {
663+
v: Variable,
664+
p: Parameter,
665+
}
666+
impl std::fmt::Debug for Entry {
667+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
668+
write!(f, "{:?} => {:?}", self.v, self.p)
669+
}
670+
}
671+
}
672+
f.finish()
673+
}
674+
}
675+
657676
impl<Vs> std::ops::SubAssign<Vs> for Substitution
658677
where
659678
Vs: Upcast<Vec<Variable>>,

0 commit comments

Comments
 (0)