1
Fork 0

Migrate predicates_of and caller_bounds to Clause

This commit is contained in:
Michael Goulet 2023-06-22 18:17:13 +00:00
parent 36fb58e433
commit fbdef58414
77 changed files with 478 additions and 705 deletions

View file

@ -42,7 +42,7 @@ impl<'tcx> RustIrDatabase<'tcx> {
.tcx
.predicates_defined_on(def_id)
.instantiate_own(self.interner.tcx, bound_vars)
.filter_map(|(wc, _)| LowerInto::lower_into(wc, self.interner))
.filter_map(|(wc, _)| LowerInto::lower_into(wc.as_predicate(), self.interner))
.collect()
}

View file

@ -93,36 +93,29 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::InEnvironment<chalk_ir::Goal<RustInterner<'
let (predicate, binders, _named_regions) =
collect_bound_vars(interner, interner.tcx, predicate.kind());
let consequence = match predicate {
ty::PredicateKind::TypeWellFormedFromEnv(ty) => {
// TODO: FIXME
/*ty::PredicateKind::TypeWellFormedFromEnv(ty) => {
chalk_ir::DomainGoal::FromEnv(chalk_ir::FromEnv::Ty(ty.lower_into(interner)))
}
ty::PredicateKind::Clause(ty::ClauseKind::Trait(predicate)) => {
chalk_ir::DomainGoal::FromEnv(chalk_ir::FromEnv::Trait(
predicate.trait_ref.lower_into(interner),
))
}
ty::PredicateKind::Clause(ty::ClauseKind::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::ClauseKind::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::ClauseKind::Projection(predicate)) => {
chalk_ir::DomainGoal::Holds(chalk_ir::WhereClause::AliasEq(
predicate.lower_into(interner),
))
}
ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(arg)) => match arg.unpack() {
}*/
ty::ClauseKind::Trait(predicate) => chalk_ir::DomainGoal::FromEnv(
chalk_ir::FromEnv::Trait(predicate.trait_ref.lower_into(interner)),
),
ty::ClauseKind::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::ClauseKind::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::ClauseKind::Projection(predicate) => chalk_ir::DomainGoal::Holds(
chalk_ir::WhereClause::AliasEq(predicate.lower_into(interner)),
),
ty::ClauseKind::WellFormed(arg) => match arg.unpack() {
ty::GenericArgKind::Type(ty) => chalk_ir::DomainGoal::WellFormed(
chalk_ir::WellFormed::Ty(ty.lower_into(interner)),
),
@ -131,15 +124,9 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::InEnvironment<chalk_ir::Goal<RustInterner<'
interner.tcx.types.unit.lower_into(interner),
)),
},
ty::PredicateKind::ObjectSafe(..)
| ty::PredicateKind::Clause(ty::ClauseKind::ConstArgHasType(..))
| ty::PredicateKind::AliasRelate(..)
| ty::PredicateKind::ClosureKind(..)
| ty::PredicateKind::Subtype(..)
| ty::PredicateKind::Coerce(..)
| ty::PredicateKind::Clause(ty::ClauseKind::ConstEvaluatable(..))
| ty::PredicateKind::Ambiguous
| ty::PredicateKind::ConstEquate(..) => bug!("unexpected predicate {}", predicate),
ty::ClauseKind::ConstArgHasType(..) | ty::ClauseKind::ConstEvaluatable(_) => {
bug!("unexpected predicate {}", predicate)
}
};
let value = chalk_ir::ProgramClauseImplication {
consequence,

View file

@ -2,8 +2,8 @@ use rustc_infer::infer::canonical::{Canonical, QueryResponse};
use rustc_infer::infer::TyCtxtInferExt;
use rustc_middle::query::Providers;
use rustc_middle::traits::query::NoSolution;
use rustc_middle::ty::{Clause, ParamEnvAnd};
use rustc_middle::ty::{FnSig, Lift, PolyFnSig, Ty, TyCtxt, TypeFoldable};
use rustc_middle::ty::{ParamEnvAnd, Predicate};
use rustc_trait_selection::infer::InferCtxtBuilderExt;
use rustc_trait_selection::traits::query::normalize::QueryNormalizeExt;
use rustc_trait_selection::traits::query::type_op::ascribe_user_type::{
@ -23,7 +23,7 @@ pub(crate) fn provide(p: &mut Providers) {
type_op_prove_predicate,
type_op_subtype,
type_op_normalize_ty,
type_op_normalize_predicate,
type_op_normalize_clause,
type_op_normalize_fn_sig,
type_op_normalize_poly_fn_sig,
..*p
@ -70,10 +70,10 @@ fn type_op_normalize_ty<'tcx>(
tcx.infer_ctxt().enter_canonical_trait_query(&canonicalized, type_op_normalize)
}
fn type_op_normalize_predicate<'tcx>(
fn type_op_normalize_clause<'tcx>(
tcx: TyCtxt<'tcx>,
canonicalized: Canonical<'tcx, ParamEnvAnd<'tcx, Normalize<Predicate<'tcx>>>>,
) -> Result<&'tcx Canonical<'tcx, QueryResponse<'tcx, Predicate<'tcx>>>, NoSolution> {
canonicalized: Canonical<'tcx, ParamEnvAnd<'tcx, Normalize<Clause<'tcx>>>>,
) -> Result<&'tcx Canonical<'tcx, QueryResponse<'tcx, Clause<'tcx>>>, NoSolution> {
tcx.infer_ctxt().enter_canonical_trait_query(&canonicalized, type_op_normalize)
}