Introduce PredicateKind::Clause

This commit is contained in:
Santiago Pastorino
2022-11-24 18:14:58 -03:00
parent 42cc8e8f4e
commit 974e2837bb
75 changed files with 568 additions and 407 deletions

View File

@@ -89,24 +89,32 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::InEnvironment<chalk_ir::Goal<RustInterner<'
ty::PredicateKind::TypeWellFormedFromEnv(ty) => {
chalk_ir::DomainGoal::FromEnv(chalk_ir::FromEnv::Ty(ty.lower_into(interner)))
}
ty::PredicateKind::Trait(predicate) => chalk_ir::DomainGoal::FromEnv(
chalk_ir::FromEnv::Trait(predicate.trait_ref.lower_into(interner)),
),
ty::PredicateKind::RegionOutlives(predicate) => chalk_ir::DomainGoal::Holds(
chalk_ir::WhereClause::LifetimeOutlives(chalk_ir::LifetimeOutlives {
a: predicate.0.lower_into(interner),
b: predicate.1.lower_into(interner),
}),
),
ty::PredicateKind::TypeOutlives(predicate) => chalk_ir::DomainGoal::Holds(
chalk_ir::WhereClause::TypeOutlives(chalk_ir::TypeOutlives {
ty: predicate.0.lower_into(interner),
lifetime: predicate.1.lower_into(interner),
}),
),
ty::PredicateKind::Projection(predicate) => chalk_ir::DomainGoal::Holds(
chalk_ir::WhereClause::AliasEq(predicate.lower_into(interner)),
),
ty::PredicateKind::Clause(ty::Clause::Trait(predicate)) => {
chalk_ir::DomainGoal::FromEnv(chalk_ir::FromEnv::Trait(
predicate.trait_ref.lower_into(interner),
))
}
ty::PredicateKind::Clause(ty::Clause::RegionOutlives(predicate)) => {
chalk_ir::DomainGoal::Holds(chalk_ir::WhereClause::LifetimeOutlives(
chalk_ir::LifetimeOutlives {
a: predicate.0.lower_into(interner),
b: predicate.1.lower_into(interner),
},
))
}
ty::PredicateKind::Clause(ty::Clause::TypeOutlives(predicate)) => {
chalk_ir::DomainGoal::Holds(chalk_ir::WhereClause::TypeOutlives(
chalk_ir::TypeOutlives {
ty: predicate.0.lower_into(interner),
lifetime: predicate.1.lower_into(interner),
},
))
}
ty::PredicateKind::Clause(ty::Clause::Projection(predicate)) => {
chalk_ir::DomainGoal::Holds(chalk_ir::WhereClause::AliasEq(
predicate.lower_into(interner),
))
}
ty::PredicateKind::WellFormed(arg) => match arg.unpack() {
ty::GenericArgKind::Type(ty) => chalk_ir::DomainGoal::WellFormed(
chalk_ir::WellFormed::Ty(ty.lower_into(interner)),
@@ -149,12 +157,12 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::GoalData<RustInterner<'tcx>>> for ty::Predi
collect_bound_vars(interner, interner.tcx, self.kind());
let value = match predicate {
ty::PredicateKind::Trait(predicate) => {
ty::PredicateKind::Clause(ty::Clause::Trait(predicate)) => {
chalk_ir::GoalData::DomainGoal(chalk_ir::DomainGoal::Holds(
chalk_ir::WhereClause::Implemented(predicate.trait_ref.lower_into(interner)),
))
}
ty::PredicateKind::RegionOutlives(predicate) => {
ty::PredicateKind::Clause(ty::Clause::RegionOutlives(predicate)) => {
chalk_ir::GoalData::DomainGoal(chalk_ir::DomainGoal::Holds(
chalk_ir::WhereClause::LifetimeOutlives(chalk_ir::LifetimeOutlives {
a: predicate.0.lower_into(interner),
@@ -162,7 +170,7 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::GoalData<RustInterner<'tcx>>> for ty::Predi
}),
))
}
ty::PredicateKind::TypeOutlives(predicate) => {
ty::PredicateKind::Clause(ty::Clause::TypeOutlives(predicate)) => {
chalk_ir::GoalData::DomainGoal(chalk_ir::DomainGoal::Holds(
chalk_ir::WhereClause::TypeOutlives(chalk_ir::TypeOutlives {
ty: predicate.0.lower_into(interner),
@@ -170,7 +178,7 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::GoalData<RustInterner<'tcx>>> for ty::Predi
}),
))
}
ty::PredicateKind::Projection(predicate) => {
ty::PredicateKind::Clause(ty::Clause::Projection(predicate)) => {
chalk_ir::GoalData::DomainGoal(chalk_ir::DomainGoal::Holds(
chalk_ir::WhereClause::AliasEq(predicate.lower_into(interner)),
))
@@ -605,22 +613,22 @@ impl<'tcx> LowerInto<'tcx, Option<chalk_ir::QuantifiedWhereClause<RustInterner<'
let (predicate, binders, _named_regions) =
collect_bound_vars(interner, interner.tcx, self.kind());
let value = match predicate {
ty::PredicateKind::Trait(predicate) => {
ty::PredicateKind::Clause(ty::Clause::Trait(predicate)) => {
Some(chalk_ir::WhereClause::Implemented(predicate.trait_ref.lower_into(interner)))
}
ty::PredicateKind::RegionOutlives(predicate) => {
ty::PredicateKind::Clause(ty::Clause::RegionOutlives(predicate)) => {
Some(chalk_ir::WhereClause::LifetimeOutlives(chalk_ir::LifetimeOutlives {
a: predicate.0.lower_into(interner),
b: predicate.1.lower_into(interner),
}))
}
ty::PredicateKind::TypeOutlives(predicate) => {
ty::PredicateKind::Clause(ty::Clause::TypeOutlives(predicate)) => {
Some(chalk_ir::WhereClause::TypeOutlives(chalk_ir::TypeOutlives {
ty: predicate.0.lower_into(interner),
lifetime: predicate.1.lower_into(interner),
}))
}
ty::PredicateKind::Projection(predicate) => {
ty::PredicateKind::Clause(ty::Clause::Projection(predicate)) => {
Some(chalk_ir::WhereClause::AliasEq(predicate.lower_into(interner)))
}
ty::PredicateKind::WellFormed(_ty) => None,
@@ -741,20 +749,24 @@ impl<'tcx> LowerInto<'tcx, Option<chalk_solve::rust_ir::QuantifiedInlineBound<Ru
let (predicate, binders, _named_regions) =
collect_bound_vars(interner, interner.tcx, self.kind());
match predicate {
ty::PredicateKind::Trait(predicate) => Some(chalk_ir::Binders::new(
binders,
chalk_solve::rust_ir::InlineBound::TraitBound(
predicate.trait_ref.lower_into(interner),
),
)),
ty::PredicateKind::Projection(predicate) => Some(chalk_ir::Binders::new(
binders,
chalk_solve::rust_ir::InlineBound::AliasEqBound(predicate.lower_into(interner)),
)),
ty::PredicateKind::TypeOutlives(_predicate) => None,
ty::PredicateKind::Clause(ty::Clause::Trait(predicate)) => {
Some(chalk_ir::Binders::new(
binders,
chalk_solve::rust_ir::InlineBound::TraitBound(
predicate.trait_ref.lower_into(interner),
),
))
}
ty::PredicateKind::Clause(ty::Clause::Projection(predicate)) => {
Some(chalk_ir::Binders::new(
binders,
chalk_solve::rust_ir::InlineBound::AliasEqBound(predicate.lower_into(interner)),
))
}
ty::PredicateKind::Clause(ty::Clause::TypeOutlives(_predicate)) => None,
ty::PredicateKind::WellFormed(_ty) => None,
ty::PredicateKind::RegionOutlives(..)
ty::PredicateKind::Clause(ty::Clause::RegionOutlives(..))
| ty::PredicateKind::ObjectSafe(..)
| ty::PredicateKind::ClosureKind(..)
| ty::PredicateKind::Subtype(..)