Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(Mostly) add AliasEq and start porting chalk projection tests #145

Merged
merged 2 commits into from
Oct 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions crates/formality-check/src/where_clauses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ impl super::Check<'_> {
assumptions,
trait_id.with(self_ty, parameters),
),
WhereClauseData::AliasEq(alias_ty, ty) => {
self.prove_parameter_well_formed(in_env, &assumptions, alias_ty)?;
self.prove_parameter_well_formed(in_env, &assumptions, ty)
}
WhereClauseData::Outlives(a, b) => {
self.prove_parameter_well_formed(in_env, &assumptions, a)?;
self.prove_parameter_well_formed(in_env, assumptions, b)
Expand Down
6 changes: 6 additions & 0 deletions crates/formality-prove/src/prove/prove_wc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ judgment_fn! {
(prove_wc(decls, env, assumptions, Predicate::NotImplemented(trait_ref)) => c.pop_subst(&subst))
)

(
(prove_eq(decls, env, assumptions, alias_ty, ty) => c)
----------------------------- ("alias eq")
(prove_wc(decls, env, assumptions, Predicate::AliasEq(alias_ty, ty)) => c)
)

(
(decls.trait_invariants() => ti)
(let (env, subst) = env.existential_substitution(&ti.binder))
Expand Down
27 changes: 25 additions & 2 deletions crates/formality-prove/src/prove/prove_wf.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use formality_types::{
grammar::{ConstData, Parameter, RigidName, RigidTy, UniversalVar, Wcs},
judgment_fn,
grammar::{ConstData, Parameter, RigidName, RigidTy, UniversalVar, Wcs, AliasTy, Parameters, AliasName},
judgment_fn, collections::Set,
};

use crate::{decls::Decls, prove::combinators::for_all};
Expand Down Expand Up @@ -39,10 +39,33 @@ judgment_fn! {
(prove_wf(decls, env, assumptions, RigidTy { name: RigidName::ScalarId(_), parameters }) => c)
)

(
(for_all(&decls, &env, &assumptions, &parameters, &prove_wf) => c)
--- ("ADT")
(prove_wf(decls, env, assumptions, RigidTy { name: RigidName::AdtId(_), parameters }) => c)
)

(
(prove_wf(&decls, &env, &assumptions, ty) => c)
--- ("rigid constants")
(prove_wf(decls, env, assumptions, ConstData::Value(_, ty)) => c)
)

(
(prove_alias_wf(&decls, &env, &assumptions, name, parameters) => c)
--- ("aliases")
(prove_wf(decls, env, assumptions, AliasTy { name, parameters }) => c)
)
}
}

pub fn prove_alias_wf(
decls: &Decls,
env: &Env,
assumptions: &Wcs,
_name: AliasName,
parameters: Parameters,
) -> Set<Constraints> {
// FIXME: verify self type implements trait
for_all(decls, env, assumptions, &parameters, &prove_wf)
}
6 changes: 5 additions & 1 deletion crates/formality-rust/src/grammar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use formality_types::{
cast::Upcast,
grammar::{
AdtId, AssociatedItemId, Binder, Const, CrateId, Fallible, FieldId, FnId, Lt, Parameter,
TraitId, TraitRef, Ty, Wc,
TraitId, TraitRef, Ty, Wc, AliasTy,
},
term::Term,
};
Expand Down Expand Up @@ -325,6 +325,7 @@ impl WhereClause {
.not_implemented()
.upcast(),
),
WhereClauseData::AliasEq(_, _) => None,
WhereClauseData::Outlives(_, _) => None,
WhereClauseData::ForAll(binder) => {
let (vars, where_clause) = binder.open();
Expand All @@ -341,6 +342,9 @@ pub enum WhereClauseData {
#[grammar($v0 : $v1 < $,v2 >)]
IsImplemented(Ty, TraitId, Vec<Parameter>),

#[grammar($v0 => $v1)]
AliasEq(AliasTy, Ty),

#[grammar($v0 : $v1)]
Outlives(Parameter, Lt),

Expand Down
3 changes: 3 additions & 0 deletions crates/formality-rust/src/prove.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,9 @@ impl ToWcs for WhereClause {
WhereClauseData::IsImplemented(self_ty, trait_id, parameters) => {
trait_id.with(self_ty, parameters).upcast()
}
WhereClauseData::AliasEq(alias_ty, ty) => {
Predicate::AliasEq(alias_ty.clone(), ty.clone()).upcast()
}
WhereClauseData::Outlives(a, b) => Relation::outlives(a, b).upcast(),
WhereClauseData::ForAll(binder) => {
let (vars, wc) = binder.open();
Expand Down
2 changes: 1 addition & 1 deletion crates/formality-types/src/grammar/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl Const {
}
}

#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Visit)]
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Visit)]
pub enum ConstData {
Value(ValTree, Ty),
Variable(Variable),
Expand Down
15 changes: 15 additions & 0 deletions crates/formality-types/src/grammar/formulas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use crate::cast::To;
use crate::cast::Upcast;
use crate::cast_impl;

use super::AliasName;
use super::AliasTy;
use super::Const;
use super::Parameter;
use super::Parameters;
Expand All @@ -23,6 +25,9 @@ pub enum Predicate {
#[grammar(!$v0)]
NotImplemented(TraitRef),

#[cast]
AliasEq(AliasTy, Ty),

#[grammar(@WellFormedTraitRef($v0))]
WellFormedTraitRef(TraitRef),

Expand Down Expand Up @@ -80,6 +85,7 @@ impl Parameter {
pub enum Skeleton {
IsImplemented(TraitId),
NotImplemented(TraitId),
AliasEq(AliasName),
WellFormed,
WellFormedTraitRef(TraitId),
IsLocal(TraitId),
Expand Down Expand Up @@ -110,6 +116,15 @@ impl Predicate {
Skeleton::NotImplemented(trait_id.clone()),
parameters.clone(),
),
Predicate::AliasEq(AliasTy { name, parameters }, ty) => {
let mut params = parameters.clone();
params.push(ty.clone().upcast());
(
Skeleton::AliasEq(name.clone()),
params,
)

}
Predicate::WellFormedTraitRef(TraitRef {
trait_id,
parameters,
Expand Down
51 changes: 0 additions & 51 deletions fixme_tests/basic--where-clauses.rs

This file was deleted.

12 changes: 7 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@ pub fn test_program_ok(input: &str) -> anyhow::Result<()> {
}

pub fn test_where_clause(program: &str, assertion: &str) -> anyhow::Result<Set<Constraints>> {
let program: Program = try_term(program)?;
check_all_crates(&program)?;
let assertion: Arc<TestAssertion> = try_term(assertion)?;
let decls = program.to_prove_decls();
Ok(formality_prove::test_util::test_prove(decls, assertion))
formality_core::with_tracing_logs(|| {
let program: Program = try_term(program)?;
check_all_crates(&program)?;
let assertion: Arc<TestAssertion> = try_term(assertion)?;
let decls = program.to_prove_decls();
Ok(formality_prove::test_util::test_prove(decls, assertion))
})
}
Loading
Loading