Update to chalk 0.31. Implement some unimplemented. Ignore some tests in compare mode chalk don't finish.
This commit is contained in:
parent
08e2d46166
commit
23491084bc
44 changed files with 143 additions and 99 deletions
|
@ -22,7 +22,6 @@ use rustc_ast::ast;
|
|||
|
||||
pub struct RustIrDatabase<'tcx> {
|
||||
pub(crate) interner: RustInterner<'tcx>,
|
||||
pub(crate) restatic_placeholder: ty::Region<'tcx>,
|
||||
pub(crate) reempty_placeholder: ty::Region<'tcx>,
|
||||
}
|
||||
|
||||
|
@ -39,11 +38,8 @@ impl<'tcx> RustIrDatabase<'tcx> {
|
|||
bound_vars: SubstsRef<'tcx>,
|
||||
) -> Vec<chalk_ir::QuantifiedWhereClause<RustInterner<'tcx>>> {
|
||||
let predicates = self.interner.tcx.predicates_of(def_id).predicates;
|
||||
let mut regions_substitutor = lowering::RegionsSubstitutor::new(
|
||||
self.interner.tcx,
|
||||
self.restatic_placeholder,
|
||||
self.reempty_placeholder,
|
||||
);
|
||||
let mut regions_substitutor =
|
||||
lowering::RegionsSubstitutor::new(self.interner.tcx, self.reempty_placeholder);
|
||||
predicates
|
||||
.iter()
|
||||
.map(|(wc, _)| wc.subst(self.interner.tcx, bound_vars))
|
||||
|
@ -274,11 +270,8 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
|
|||
|
||||
let trait_ref = self.interner.tcx.impl_trait_ref(def_id).expect("not an impl");
|
||||
let trait_ref = trait_ref.subst(self.interner.tcx, bound_vars);
|
||||
let mut regions_substitutor = lowering::RegionsSubstitutor::new(
|
||||
self.interner.tcx,
|
||||
self.restatic_placeholder,
|
||||
self.reempty_placeholder,
|
||||
);
|
||||
let mut regions_substitutor =
|
||||
lowering::RegionsSubstitutor::new(self.interner.tcx, self.reempty_placeholder);
|
||||
let trait_ref = trait_ref.fold_with(&mut regions_substitutor);
|
||||
|
||||
let where_clauses = self.where_clauses_for(def_id, bound_vars);
|
||||
|
@ -316,11 +309,8 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
|
|||
|
||||
let self_ty = trait_ref.self_ty();
|
||||
let self_ty = self_ty.subst(self.interner.tcx, bound_vars);
|
||||
let mut regions_substitutor = lowering::RegionsSubstitutor::new(
|
||||
self.interner.tcx,
|
||||
self.restatic_placeholder,
|
||||
self.reempty_placeholder,
|
||||
);
|
||||
let mut regions_substitutor =
|
||||
lowering::RegionsSubstitutor::new(self.interner.tcx, self.reempty_placeholder);
|
||||
let self_ty = self_ty.fold_with(&mut regions_substitutor);
|
||||
let lowered_ty = self_ty.lower_into(&self.interner);
|
||||
|
||||
|
@ -590,6 +580,20 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
|
|||
let substitution = &substs.as_slice(&self.interner)[0..substs.len(&self.interner) - 3];
|
||||
chalk_ir::Substitution::from_iter(&self.interner, substitution)
|
||||
}
|
||||
|
||||
fn generator_datum(
|
||||
&self,
|
||||
_generator_id: chalk_ir::GeneratorId<RustInterner<'tcx>>,
|
||||
) -> Arc<chalk_solve::rust_ir::GeneratorDatum<RustInterner<'tcx>>> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
fn generator_witness_datum(
|
||||
&self,
|
||||
_generator_id: chalk_ir::GeneratorId<RustInterner<'tcx>>,
|
||||
) -> Arc<chalk_solve::rust_ir::GeneratorWitnessDatum<RustInterner<'tcx>>> {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
|
||||
/// Creates a `InternalSubsts` that maps each generic parameter to a higher-ranked
|
||||
|
|
|
@ -427,13 +427,20 @@ impl<'tcx> LowerInto<'tcx, Ty<'tcx>> for &chalk_ir::Ty<RustInterner<'tcx>> {
|
|||
chalk_ir::FloatTy::F64 => ty::Float(ast::FloatTy::F64),
|
||||
},
|
||||
},
|
||||
chalk_ir::TypeName::Array => unimplemented!(),
|
||||
chalk_ir::TypeName::Array => {
|
||||
let substs = application_ty.substitution.as_slice(interner);
|
||||
let ty = substs[0].assert_ty_ref(interner).lower_into(interner);
|
||||
let c = substs[1].assert_const_ref(interner).lower_into(interner);
|
||||
ty::Array(ty, interner.tcx.mk_const(c))
|
||||
}
|
||||
chalk_ir::TypeName::FnDef(id) => {
|
||||
ty::FnDef(id.0, application_ty.substitution.lower_into(interner))
|
||||
}
|
||||
chalk_ir::TypeName::Closure(closure) => {
|
||||
ty::Closure(closure.0, application_ty.substitution.lower_into(interner))
|
||||
}
|
||||
chalk_ir::TypeName::Generator(_) => unimplemented!(),
|
||||
chalk_ir::TypeName::GeneratorWitness(_) => unimplemented!(),
|
||||
chalk_ir::TypeName::Never => ty::Never,
|
||||
chalk_ir::TypeName::Tuple(_size) => {
|
||||
ty::Tuple(application_ty.substitution.lower_into(interner))
|
||||
|
@ -483,7 +490,15 @@ impl<'tcx> LowerInto<'tcx, Ty<'tcx>> for &chalk_ir::Ty<RustInterner<'tcx>> {
|
|||
universe: ty::UniverseIndex::from_usize(placeholder.ui.counter),
|
||||
name: ty::BoundVar::from_usize(placeholder.idx),
|
||||
}),
|
||||
TyData::Alias(_alias_ty) => unimplemented!(),
|
||||
chalk_ir::TyData::Alias(alias_ty) => match alias_ty {
|
||||
chalk_ir::AliasTy::Projection(projection) => ty::Projection(ty::ProjectionTy {
|
||||
item_def_id: projection.associated_ty_id.0,
|
||||
substs: projection.substitution.lower_into(interner),
|
||||
}),
|
||||
chalk_ir::AliasTy::Opaque(opaque) => {
|
||||
ty::Opaque(opaque.opaque_ty_id.0, opaque.substitution.lower_into(interner))
|
||||
}
|
||||
},
|
||||
TyData::Function(_quantified_ty) => unimplemented!(),
|
||||
TyData::BoundVar(_bound) => ty::Bound(
|
||||
ty::DebruijnIndex::from_usize(_bound.debruijn.depth() as usize),
|
||||
|
@ -519,8 +534,7 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::Lifetime<RustInterner<'tcx>>> for Region<'t
|
|||
ty::BrEnv => unimplemented!(),
|
||||
},
|
||||
ReFree(_) => unimplemented!(),
|
||||
// FIXME(chalk): need to handle ReStatic
|
||||
ReStatic => unimplemented!(),
|
||||
ReStatic => chalk_ir::LifetimeData::Static.intern(interner),
|
||||
ReVar(_) => unimplemented!(),
|
||||
RePlaceholder(placeholder_region) => {
|
||||
chalk_ir::LifetimeData::Placeholder(chalk_ir::PlaceholderIndex {
|
||||
|
@ -550,6 +564,7 @@ impl<'tcx> LowerInto<'tcx, Region<'tcx>> for &chalk_ir::Lifetime<RustInterner<'t
|
|||
name: ty::BoundRegion::BrAnon(p.idx as u32),
|
||||
})
|
||||
}
|
||||
chalk_ir::LifetimeData::Static => ty::RegionKind::ReStatic,
|
||||
chalk_ir::LifetimeData::Phantom(_, _) => unimplemented!(),
|
||||
};
|
||||
interner.tcx.mk_region(kind)
|
||||
|
@ -701,7 +716,16 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::Binders<chalk_ir::QuantifiedWhereClauses<Ru
|
|||
}),
|
||||
)
|
||||
}
|
||||
ty::ExistentialPredicate::Projection(_predicate) => unimplemented!(),
|
||||
ty::ExistentialPredicate::Projection(predicate) => chalk_ir::Binders::new(
|
||||
chalk_ir::VariableKinds::empty(interner),
|
||||
chalk_ir::WhereClause::AliasEq(chalk_ir::AliasEq {
|
||||
alias: chalk_ir::AliasTy::Projection(chalk_ir::ProjectionTy {
|
||||
associated_ty_id: chalk_ir::AssocTypeId(predicate.item_def_id),
|
||||
substitution: predicate.substs.lower_into(interner),
|
||||
}),
|
||||
ty: predicate.ty.lower_into(interner),
|
||||
}),
|
||||
),
|
||||
ty::ExistentialPredicate::AutoTrait(def_id) => chalk_ir::Binders::new(
|
||||
chalk_ir::VariableKinds::empty(interner),
|
||||
chalk_ir::WhereClause::Implemented(chalk_ir::TraitRef {
|
||||
|
@ -1116,17 +1140,12 @@ impl<'tcx> TypeVisitor<'tcx> for PlaceholdersCollector {
|
|||
/// Used to substitute specific `Regions`s with placeholders.
|
||||
crate struct RegionsSubstitutor<'tcx> {
|
||||
tcx: TyCtxt<'tcx>,
|
||||
restatic_placeholder: ty::Region<'tcx>,
|
||||
reempty_placeholder: ty::Region<'tcx>,
|
||||
}
|
||||
|
||||
impl<'tcx> RegionsSubstitutor<'tcx> {
|
||||
crate fn new(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
restatic_placeholder: ty::Region<'tcx>,
|
||||
reempty_placeholder: ty::Region<'tcx>,
|
||||
) -> Self {
|
||||
RegionsSubstitutor { tcx, restatic_placeholder, reempty_placeholder }
|
||||
crate fn new(tcx: TyCtxt<'tcx>, reempty_placeholder: ty::Region<'tcx>) -> Self {
|
||||
RegionsSubstitutor { tcx, reempty_placeholder }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1137,7 +1156,6 @@ impl<'tcx> TypeFolder<'tcx> for RegionsSubstitutor<'tcx> {
|
|||
|
||||
fn fold_region(&mut self, r: Region<'tcx>) -> Region<'tcx> {
|
||||
match r {
|
||||
ty::ReStatic => self.restatic_placeholder,
|
||||
ty::ReEmpty(ui) => {
|
||||
assert_eq!(ui.as_usize(), 0);
|
||||
self.reempty_placeholder
|
||||
|
|
|
@ -42,10 +42,6 @@ crate fn evaluate_goal<'tcx>(
|
|||
let mut placeholders_collector = PlaceholdersCollector::new();
|
||||
obligation.visit_with(&mut placeholders_collector);
|
||||
|
||||
let restatic_placeholder = tcx.mk_region(ty::RegionKind::RePlaceholder(ty::Placeholder {
|
||||
universe: ty::UniverseIndex::ROOT,
|
||||
name: ty::BoundRegion::BrAnon(placeholders_collector.next_anon_region_placeholder),
|
||||
}));
|
||||
let reempty_placeholder = tcx.mk_region(ty::RegionKind::RePlaceholder(ty::Placeholder {
|
||||
universe: ty::UniverseIndex::ROOT,
|
||||
name: ty::BoundRegion::BrAnon(placeholders_collector.next_anon_region_placeholder + 1),
|
||||
|
@ -57,8 +53,7 @@ crate fn evaluate_goal<'tcx>(
|
|||
// FIXME(chalk): we really should be substituting these back in the solution
|
||||
let _params: FxHashMap<usize, ParamTy> = params_substitutor.params;
|
||||
|
||||
let mut regions_substitutor =
|
||||
RegionsSubstitutor::new(tcx, restatic_placeholder, reempty_placeholder);
|
||||
let mut regions_substitutor = RegionsSubstitutor::new(tcx, reempty_placeholder);
|
||||
let obligation = obligation.fold_with(&mut regions_substitutor);
|
||||
|
||||
let max_universe = obligation.max_universe.index();
|
||||
|
@ -101,7 +96,7 @@ crate fn evaluate_goal<'tcx>(
|
|||
|
||||
use chalk_solve::Solver;
|
||||
let mut solver = chalk_engine::solve::SLGSolver::new(32, None);
|
||||
let db = ChalkRustIrDatabase { interner, restatic_placeholder, reempty_placeholder };
|
||||
let db = ChalkRustIrDatabase { interner, reempty_placeholder };
|
||||
let solution = chalk_solve::logging::with_tracing_logs(|| solver.solve(&db, &lowered_goal));
|
||||
|
||||
// Ideally, the code to convert *back* to rustc types would live close to
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue