Skip to content

Commit 08a5f07

Browse files
authored
Merge pull request #167 from nikomatsakis/file-extension
cleanup and fix coherence rules
2 parents 6290702 + d947bb8 commit 08a5f07

File tree

80 files changed

+1288
-1440
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+1288
-1440
lines changed

Cargo.lock

Lines changed: 19 additions & 745 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ formality-check = { version = "0.1.0", path = "crates/formality-check" }
3030
formality-prove = { version = "0.1.0", path = "crates/formality-prove" }
3131
formality-core = { version = "0.1.0", path = "crates/formality-core" }
3232
formality-smir = { version = "0.1.0", path = "crates/formality-smir" }
33-
ui_test = "0.12"
33+
expect-test = "1.4.0"
3434

3535
[workspace]
3636
members = [
@@ -42,7 +42,3 @@ members = [
4242
"crates/formality-prove",
4343
"crates/formality-smir",
4444
]
45-
46-
[[test]]
47-
name = "ui"
48-
harness = false

crates/formality-check/src/coherence.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ impl Check<'_> {
2424
self.orphan_check_neg(impl_a)?;
2525
}
2626

27-
// check for duplicate impls in the current crate
27+
// check for duplicate impls in the current crate;
28+
// the cartesian product below would otherwise consider every impl I
29+
// as overlapping with itself.
2830
for (impl_a, i) in current_crate_impls.iter().zip(0..) {
2931
if current_crate_impls[i + 1..].contains(impl_a) {
3032
bail!("duplicate impl in current crate: {:?}", impl_a)

crates/formality-check/src/lib.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ impl Check<'_> {
107107
bail!("failed to prove {goal:?} given {assumptions:?}, got {cs:?}")
108108
}
109109

110+
#[tracing::instrument(level = "Debug", skip(self, assumptions, goal))]
110111
fn prove_not_goal(
111112
&self,
112113
env: &Env,
@@ -116,6 +117,9 @@ impl Check<'_> {
116117
let goal: Wcs = goal.to_wcs();
117118
let assumptions: Wcs = assumptions.to_wcs();
118119

120+
tracing::debug!("assumptions = {assumptions:?}");
121+
tracing::debug!("goal = {goal:?}");
122+
119123
assert!(env.only_universal_variables());
120124
assert!(env.encloses((&assumptions, &goal)));
121125

@@ -146,10 +150,16 @@ impl Check<'_> {
146150
&existential_goal,
147151
);
148152

149-
if !cs.is_proven() {
150-
return Ok(());
153+
match cs.into_set() {
154+
Ok(proofs) => {
155+
bail!(
156+
"failed to disprove\n {goal:?}\ngiven\n {assumptions:?}\ngot\n{proofs:?}"
157+
)
158+
}
159+
Err(err) => {
160+
tracing::debug!("Proved not goal, error = {err}");
161+
return Ok(());
162+
}
151163
}
152-
153-
bail!("failed to disprove\n {goal:?}\ngiven\n {assumptions:?}\ngot\n{cs:?}")
154164
}
155165
}

crates/formality-core/src/judgment/proven_set.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ impl<T: Ord + Debug> ProvenSet<T> {
9191
}
9292
}
9393

94-
/// Convert to a non-empty set of proven results (if ok) or an error (otherwise).
94+
/// Iterate through all solutions.
9595
pub fn iter<'a>(&'a self) -> Box<dyn Iterator<Item = &'a T> + 'a> {
9696
match &self.data {
9797
Data::Failure(_) => Box::new(std::iter::empty()),

crates/formality-core/src/test_util.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,15 @@ pub trait ResultTestExt<T, E> {
5050
/// Given a `Fallible<T>` value, assert that its debug representation matches the expected value.
5151
/// If the result is an error it is propagated through to the return value.
5252
fn assert_ok(self, expect: expect_test::Expect);
53+
5354
/// Given a `Fallible<T>` value, assert that it is an error with the given string (after normalization).
5455
/// Returns `Ok(())` if the assertion succeeds, or panics if the assertion fails.
5556
fn assert_err(self, expect: expect_test::Expect);
57+
58+
/// Given a `Fallible<T>` value, assert that it is an error with the given string (after normalization).
59+
/// Also assert that each of the strings in `must_have` appears somewhere within.
60+
/// Returns `Ok(())` if the assertion succeeds, or panics if the assertion fails.
61+
fn assert_has_err(self, expect: expect_test::Expect, must_have: &[&str]);
5662
}
5763

5864
impl<T, E> ResultTestExt<T, E> for Result<T, E>
@@ -74,10 +80,21 @@ where
7480

7581
#[track_caller]
7682
fn assert_err(self, expect: expect_test::Expect) {
83+
self.assert_has_err(expect, &[]);
84+
}
85+
86+
#[track_caller]
87+
fn assert_has_err(self, expect: expect_test::Expect, must_have: &[&str]) {
7788
match self {
7889
Ok(v) => panic!("expected `Err`, got `Ok`: {v:?}"),
7990
Err(e) => {
80-
expect.assert_eq(&normalize_paths(format!("{e:?}")));
91+
let output = normalize_paths(format!("{e:?}"));
92+
93+
expect.assert_eq(&output);
94+
95+
for s in must_have {
96+
assert!(output.contains(s), "did not find {s:?} in the output");
97+
}
8198
}
8299
}
83100
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::decls::Decls;
2-
use formality_core::{ProvenSet, Upcast};
2+
use formality_core::ProvenSet;
33
use formality_types::rust::Term;
44

55
use super::{Constraints, Env};
@@ -20,7 +20,7 @@ where
2020
assert_eq!(a.len(), b.len());
2121

2222
if a.is_empty() && b.is_empty() {
23-
return ProvenSet::singleton(Constraints::none(env.upcast()));
23+
return ProvenSet::singleton(Constraints::none(env));
2424
}
2525

2626
let a0 = a.remove(0);
@@ -45,7 +45,7 @@ where
4545
C: Term,
4646
{
4747
if a.is_empty() {
48-
return ProvenSet::singleton(Constraints::none(env.upcast()));
48+
return ProvenSet::singleton(Constraints::none(env));
4949
}
5050

5151
let a0 = a[0].clone();

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ where
2525
}
2626

2727
impl Constraints {
28-
pub fn none(env: Env) -> Self {
28+
pub fn none(env: impl Upcast<Env>) -> Self {
2929
let v: Vec<(Variable, Parameter)> = vec![];
3030
Self::from(env, v)
3131
}
@@ -42,9 +42,10 @@ impl Constraints {
4242
}
4343

4444
pub fn from(
45-
env: Env,
45+
env: impl Upcast<Env>,
4646
iter: impl IntoIterator<Item = (impl Upcast<Variable>, impl Upcast<Parameter>)>,
4747
) -> Self {
48+
let env = env.upcast();
4849
let substitution: Substitution = iter.into_iter().collect();
4950
assert!(env.encloses(substitution.range()));
5051
assert!(env.encloses(substitution.domain()));
@@ -72,7 +73,7 @@ impl Constraints {
7273
}
7374
}
7475

75-
/// Given constraings from solving the subparts of `(A /\ B)`, yield combined constraints.
76+
/// Given constraints from solving the subparts of `(A /\ B)`, yield combined constraints.
7677
///
7778
/// # Parameters
7879
///

0 commit comments

Comments
 (0)