Skip to content

Commit e8766aa

Browse files
authored
Merge pull request #122 from nikomatsakis/2023-02-explorations
revamp
2 parents 371cf12 + 5cca904 commit e8766aa

Some content is hidden

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

81 files changed

+1817
-2628
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,21 @@ rustc_private=true
1010

1111
[dev-dependencies]
1212
pretty_assertions = "1.3.0"
13+
expect-test = "1.4.0"
1314

1415
[dependencies]
16+
anyhow = "1"
1517
clap = { version = "4.0.9", features = ["derive"] }
1618
formality-rust = { version = "0.1.0", path = "crates/formality-rust" }
1719
formality-types = { version = "0.1.0", path = "crates/formality-types" }
18-
formality-core = { version = "0.1.0", path = "crates/formality-core" }
20+
formality-check = { version = "0.1.0", path = "crates/formality-check" }
1921

2022
[workspace]
2123
members = [
2224
"crates/formality-macros",
2325
"crates/formality-core",
2426
"crates/formality-types",
25-
"crates/formality-decl",
26-
"crates/formality-mir",
2727
"crates/formality-check",
2828
"crates/formality-rust",
29-
"crates/formality-main",
3029
"crates/formality-prove",
3130
]

crates/formality-check/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ edition = "2021"
99
formality-types = { path = "../formality-types" }
1010
formality-macros = { path = "../formality-macros" }
1111
formality-core = { path = "../formality-core" }
12-
formality-decl = { path = "../formality-decl" }
13-
formality-mir = { path = "../formality-mir" }
12+
formality-rust = { path = "../formality-rust" }
13+
formality-prove = { path = "../formality-prove" }
1414
tracing = "0.1"
1515
contracts = "0.6.3"
1616
anyhow = "1.0.66"

crates/formality-check/src/adts.rs

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
1-
use formality_decl::grammar::{Adt, AdtBoundData, AdtVariant, Field};
2-
use formality_types::{
3-
cast::To,
4-
grammar::{Fallible, Hypothesis},
5-
};
1+
use formality_prove::Env;
2+
use formality_rust::grammar::{Adt, AdtBoundData, Field, Variant};
3+
use formality_types::grammar::Fallible;
64

75
impl super::Check<'_> {
86
pub(super) fn check_adt(&self, adt: &Adt) -> Fallible<()> {
9-
let Adt {
10-
kind: _,
11-
id: _,
12-
binder,
13-
} = adt;
7+
let Adt { id: _, binder } = adt;
148

159
let mut env = Env::default();
1610

@@ -19,15 +13,13 @@ impl super::Check<'_> {
1913
variants,
2014
} = env.instantiate_universally(binder);
2115

22-
let assumptions: Vec<Hypothesis> = where_clauses.to();
23-
24-
self.prove_where_clauses_well_formed(&env, &assumptions, &where_clauses)?;
16+
self.prove_where_clauses_well_formed(&env, &where_clauses, &where_clauses)?;
2517

2618
// FIXME: check names are unique or integers from 0..n
2719

28-
for AdtVariant { name: _, fields } in &variants {
20+
for Variant { name: _, fields } in &variants {
2921
for Field { name: _, ty } in fields {
30-
self.prove_goal(&env, &assumptions, ty.well_formed())?;
22+
self.prove_goal(&env, &where_clauses, ty.well_formed())?;
3123
}
3224
}
3325

crates/formality-check/src/coherence.rs

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
use anyhow::bail;
2-
use formality_decl::grammar::{Crate, TraitImpl};
3-
use formality_types::{cast::Downcasted, grammar::Fallible};
2+
use formality_prove::Env;
3+
use formality_rust::grammar::{Crate, TraitImpl};
4+
use formality_types::{
5+
cast::Downcasted,
6+
grammar::{Fallible, Wcs},
7+
};
48
use itertools::Itertools;
59

610
use crate::Check;
@@ -38,7 +42,33 @@ impl Check<'_> {
3842
Ok(())
3943
}
4044

41-
fn overlap_check(&self, _impl_a: &TraitImpl, _impl_b: &TraitImpl) -> Fallible<()> {
42-
Ok(())
45+
fn overlap_check(&self, impl_a: &TraitImpl, impl_b: &TraitImpl) -> Fallible<()> {
46+
let mut env = Env::default();
47+
48+
let a = env.instantiate_universally(&impl_a.binder);
49+
let b = env.instantiate_universally(&impl_b.binder);
50+
51+
let trait_ref_a = a.trait_ref();
52+
let trait_ref_b = b.trait_ref();
53+
54+
// If the parameters from the two impls cannot be equal, then they do not overlap.
55+
if let Ok(()) = self.prove_not_goal(
56+
&env,
57+
(&a.where_clauses, &b.where_clauses),
58+
Wcs::all_eq(&trait_ref_a.parameters, &trait_ref_b.parameters),
59+
) {
60+
return Ok(());
61+
}
62+
63+
// If we can disprove the where clauses, then they do not overlap.
64+
if let Ok(()) = self.prove_not_goal(
65+
&env,
66+
Wcs::all_eq(&trait_ref_a.parameters, &trait_ref_b.parameters),
67+
(&a.where_clauses, &b.where_clauses),
68+
) {
69+
return Ok(());
70+
}
71+
72+
bail!("impls may overlap: `{impl_a:?}` vs `{impl_b:?}`")
4373
}
4474
}

crates/formality-check/src/fns.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
use formality_decl::grammar::{Fn, FnBoundData};
2-
use formality_logic::Env;
3-
use formality_types::{
4-
cast::Upcast,
5-
grammar::{Fallible, Hypothesis},
6-
};
1+
use formality_prove::Env;
2+
use formality_rust::grammar::{Fn, FnBoundData, WhereClause};
3+
use formality_types::{cast::Upcast, grammar::Fallible};
74

85
use crate::Check;
96

@@ -15,7 +12,7 @@ impl Check<'_> {
1512
pub(crate) fn check_fn(
1613
&self,
1714
in_env: &Env,
18-
in_assumptions: &[Hypothesis],
15+
in_assumptions: &[WhereClause],
1916
f: &Fn,
2017
) -> Fallible<()> {
2118
let mut env = in_env.clone();
@@ -26,9 +23,10 @@ impl Check<'_> {
2623
input_tys,
2724
output_ty,
2825
where_clauses,
26+
body: _,
2927
} = env.instantiate_universally(binder);
3028

31-
let assumptions: Vec<Hypothesis> = (in_assumptions, &where_clauses).upcast();
29+
let assumptions: Vec<WhereClause> = (in_assumptions, &where_clauses).upcast();
3230

3331
self.prove_where_clauses_well_formed(&env, &assumptions, &where_clauses)?;
3432

0 commit comments

Comments
 (0)