mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-27 05:23:24 +00:00
Upgrade Chalk
This commit is contained in:
parent
ab1ad19f55
commit
209c492432
5 changed files with 63 additions and 13 deletions
|
@ -2,6 +2,7 @@
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use chalk_ir::cast::Cast;
|
use chalk_ir::cast::Cast;
|
||||||
|
use chalk_solve::Solver;
|
||||||
use hir_def::{
|
use hir_def::{
|
||||||
expr::ExprId, lang_item::LangItemTarget, DefWithBodyId, ImplId, TraitId, TypeAliasId,
|
expr::ExprId, lang_item::LangItemTarget, DefWithBodyId, ImplId, TraitId, TypeAliasId,
|
||||||
};
|
};
|
||||||
|
@ -32,9 +33,10 @@ struct ChalkContext<'a> {
|
||||||
krate: CrateId,
|
krate: CrateId,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_chalk_solver() -> chalk_solve::Solver<Interner> {
|
fn create_chalk_solver() -> chalk_recursive::RecursiveSolver<Interner> {
|
||||||
let solver_choice = chalk_solve::SolverChoice::recursive();
|
let overflow_depth = 100;
|
||||||
solver_choice.into_solver()
|
let caching_enabled = true;
|
||||||
|
chalk_recursive::RecursiveSolver::new(overflow_depth, caching_enabled)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A set of clauses that we assume to be true. E.g. if we are inside this function:
|
/// A set of clauses that we assume to be true. E.g. if we are inside this function:
|
||||||
|
|
|
@ -3,7 +3,7 @@ use std::sync::Arc;
|
||||||
|
|
||||||
use log::debug;
|
use log::debug;
|
||||||
|
|
||||||
use chalk_ir::{fold::shift::Shift, GenericArg, TypeName};
|
use chalk_ir::{fold::shift::Shift, GenericArg, TypeName, CanonicalVarKinds};
|
||||||
use chalk_solve::rust_ir::{self, OpaqueTyDatumBound, WellKnownTrait};
|
use chalk_solve::rust_ir::{self, OpaqueTyDatumBound, WellKnownTrait};
|
||||||
|
|
||||||
use hir_def::{
|
use hir_def::{
|
||||||
|
@ -66,10 +66,13 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> {
|
||||||
&self,
|
&self,
|
||||||
trait_id: TraitId,
|
trait_id: TraitId,
|
||||||
parameters: &[GenericArg<Interner>],
|
parameters: &[GenericArg<Interner>],
|
||||||
|
_binders: &CanonicalVarKinds<Interner>,
|
||||||
) -> Vec<ImplId> {
|
) -> Vec<ImplId> {
|
||||||
debug!("impls_for_trait {:?}", trait_id);
|
debug!("impls_for_trait {:?}", trait_id);
|
||||||
let trait_: hir_def::TraitId = from_chalk(self.db, trait_id);
|
let trait_: hir_def::TraitId = from_chalk(self.db, trait_id);
|
||||||
|
|
||||||
|
// FIXME use binders to look for int/float impls when necessary
|
||||||
|
|
||||||
let ty: Ty = from_chalk(self.db, parameters[0].assert_ty_ref(&Interner).clone());
|
let ty: Ty = from_chalk(self.db, parameters[0].assert_ty_ref(&Interner).clone());
|
||||||
|
|
||||||
let self_ty_fp = TyFingerprint::for_impl(&ty);
|
let self_ty_fp = TyFingerprint::for_impl(&ty);
|
||||||
|
@ -219,6 +222,22 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> {
|
||||||
// FIXME: implement closure support
|
// FIXME: implement closure support
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn trait_name(&self, _trait_id: chalk_ir::TraitId<Interner>) -> String {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
fn adt_name(&self, _struct_id: chalk_ir::AdtId<Interner>) -> String {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
fn assoc_type_name(&self, _assoc_ty_id: chalk_ir::AssocTypeId<Interner>) -> String {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
fn opaque_type_name(&self, _opaque_ty_id: chalk_ir::OpaqueTyId<Interner>) -> String {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
fn fn_def_name(&self, _fn_def_id: chalk_ir::FnDefId<Interner>) -> String {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn program_clauses_for_chalk_env_query(
|
pub(crate) fn program_clauses_for_chalk_env_query(
|
||||||
|
@ -354,12 +373,21 @@ pub(crate) fn struct_datum_query(
|
||||||
fundamental: false,
|
fundamental: false,
|
||||||
phantom_data: false,
|
phantom_data: false,
|
||||||
};
|
};
|
||||||
|
// FIXME provide enum variants properly (for auto traits)
|
||||||
|
let variant = rust_ir::AdtVariantDatum {
|
||||||
|
fields: Vec::new(), // FIXME add fields (only relevant for auto traits),
|
||||||
|
};
|
||||||
let struct_datum_bound = rust_ir::AdtDatumBound {
|
let struct_datum_bound = rust_ir::AdtDatumBound {
|
||||||
fields: Vec::new(), // FIXME add fields (only relevant for auto traits)
|
variants: vec![variant],
|
||||||
where_clauses,
|
where_clauses,
|
||||||
};
|
};
|
||||||
let struct_datum =
|
let struct_datum = StructDatum {
|
||||||
StructDatum { id: struct_id, binders: make_binders(struct_datum_bound, num_params), flags };
|
// FIXME set ADT kind
|
||||||
|
kind: rust_ir::AdtKind::Struct,
|
||||||
|
id: struct_id,
|
||||||
|
binders: make_binders(struct_datum_bound, num_params),
|
||||||
|
flags
|
||||||
|
};
|
||||||
Arc::new(struct_datum)
|
Arc::new(struct_datum)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,6 +39,7 @@ impl chalk_ir::interner::Interner for Interner {
|
||||||
type InternedQuantifiedWhereClauses = Vec<chalk_ir::QuantifiedWhereClause<Self>>;
|
type InternedQuantifiedWhereClauses = Vec<chalk_ir::QuantifiedWhereClause<Self>>;
|
||||||
type InternedVariableKinds = Vec<chalk_ir::VariableKind<Self>>;
|
type InternedVariableKinds = Vec<chalk_ir::VariableKind<Self>>;
|
||||||
type InternedCanonicalVarKinds = Vec<chalk_ir::CanonicalVarKind<Self>>;
|
type InternedCanonicalVarKinds = Vec<chalk_ir::CanonicalVarKind<Self>>;
|
||||||
|
type InternedConstraints = Vec<chalk_ir::InEnvironment<chalk_ir::Constraint<Self>>>;
|
||||||
type DefId = InternId;
|
type DefId = InternId;
|
||||||
type InternedAdtId = crate::TypeCtorId;
|
type InternedAdtId = crate::TypeCtorId;
|
||||||
type Identifier = TypeAliasId;
|
type Identifier = TypeAliasId;
|
||||||
|
@ -349,6 +350,20 @@ impl chalk_ir::interner::Interner for Interner {
|
||||||
) -> &'a [chalk_ir::CanonicalVarKind<Self>] {
|
) -> &'a [chalk_ir::CanonicalVarKind<Self>] {
|
||||||
&canonical_var_kinds
|
&canonical_var_kinds
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn intern_constraints<E>(
|
||||||
|
&self,
|
||||||
|
data: impl IntoIterator<Item = Result<chalk_ir::InEnvironment<chalk_ir::Constraint<Self>>, E>>,
|
||||||
|
) -> Result<Self::InternedConstraints, E> {
|
||||||
|
data.into_iter().collect()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn constraints_data<'a>(
|
||||||
|
&self,
|
||||||
|
constraints: &'a Self::InternedConstraints,
|
||||||
|
) -> &'a [chalk_ir::InEnvironment<chalk_ir::Constraint<Self>>] {
|
||||||
|
constraints
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl chalk_ir::interner::HasInterner for Interner {
|
impl chalk_ir::interner::HasInterner for Interner {
|
||||||
|
|
|
@ -61,7 +61,7 @@ impl ToChalk for Ty {
|
||||||
Ty::Bound(idx) => chalk_ir::TyData::BoundVar(idx).intern(&Interner),
|
Ty::Bound(idx) => chalk_ir::TyData::BoundVar(idx).intern(&Interner),
|
||||||
Ty::Infer(_infer_ty) => panic!("uncanonicalized infer ty"),
|
Ty::Infer(_infer_ty) => panic!("uncanonicalized infer ty"),
|
||||||
Ty::Dyn(predicates) => {
|
Ty::Dyn(predicates) => {
|
||||||
let where_clauses = chalk_ir::QuantifiedWhereClauses::from(
|
let where_clauses = chalk_ir::QuantifiedWhereClauses::from_iter(
|
||||||
&Interner,
|
&Interner,
|
||||||
predicates.iter().filter(|p| !p.is_error()).cloned().map(|p| p.to_chalk(db)),
|
predicates.iter().filter(|p| !p.is_error()).cloned().map(|p| p.to_chalk(db)),
|
||||||
);
|
);
|
||||||
|
@ -152,7 +152,7 @@ fn ref_to_chalk(
|
||||||
let lifetime = LIFETIME_PLACEHOLDER.to_lifetime(&Interner);
|
let lifetime = LIFETIME_PLACEHOLDER.to_lifetime(&Interner);
|
||||||
chalk_ir::ApplicationTy {
|
chalk_ir::ApplicationTy {
|
||||||
name: TypeName::Ref(mutability.to_chalk(db)),
|
name: TypeName::Ref(mutability.to_chalk(db)),
|
||||||
substitution: chalk_ir::Substitution::from(
|
substitution: chalk_ir::Substitution::from_iter(
|
||||||
&Interner,
|
&Interner,
|
||||||
vec![lifetime.cast(&Interner), arg.cast(&Interner)],
|
vec![lifetime.cast(&Interner), arg.cast(&Interner)],
|
||||||
),
|
),
|
||||||
|
@ -177,7 +177,7 @@ impl ToChalk for Substs {
|
||||||
type Chalk = chalk_ir::Substitution<Interner>;
|
type Chalk = chalk_ir::Substitution<Interner>;
|
||||||
|
|
||||||
fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::Substitution<Interner> {
|
fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::Substitution<Interner> {
|
||||||
chalk_ir::Substitution::from(&Interner, self.iter().map(|ty| ty.clone().to_chalk(db)))
|
chalk_ir::Substitution::from_iter(&Interner, self.iter().map(|ty| ty.clone().to_chalk(db)))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_chalk(db: &dyn HirDatabase, parameters: chalk_ir::Substitution<Interner>) -> Substs {
|
fn from_chalk(db: &dyn HirDatabase, parameters: chalk_ir::Substitution<Interner>) -> Substs {
|
||||||
|
@ -492,6 +492,11 @@ impl ToChalk for GenericPredicate {
|
||||||
// we shouldn't get these from Chalk
|
// we shouldn't get these from Chalk
|
||||||
panic!("encountered LifetimeOutlives from Chalk")
|
panic!("encountered LifetimeOutlives from Chalk")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
chalk_ir::WhereClause::TypeOutlives(_) => {
|
||||||
|
// we shouldn't get these from Chalk
|
||||||
|
panic!("encountered TypeOutlives from Chalk")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -570,7 +575,7 @@ where
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
let value = self.value.to_chalk(db);
|
let value = self.value.to_chalk(db);
|
||||||
chalk_ir::Canonical { value, binders: chalk_ir::CanonicalVarKinds::from(&Interner, kinds) }
|
chalk_ir::Canonical { value, binders: chalk_ir::CanonicalVarKinds::from_iter(&Interner, kinds) }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_chalk(db: &dyn HirDatabase, canonical: chalk_ir::Canonical<T::Chalk>) -> Canonical<T> {
|
fn from_chalk(db: &dyn HirDatabase, canonical: chalk_ir::Canonical<T::Chalk>) -> Canonical<T> {
|
||||||
|
@ -691,7 +696,7 @@ where
|
||||||
T: HasInterner<Interner = Interner>,
|
T: HasInterner<Interner = Interner>,
|
||||||
{
|
{
|
||||||
chalk_ir::Binders::new(
|
chalk_ir::Binders::new(
|
||||||
chalk_ir::VariableKinds::from(
|
chalk_ir::VariableKinds::from_iter(
|
||||||
&Interner,
|
&Interner,
|
||||||
std::iter::repeat(chalk_ir::VariableKind::Ty(chalk_ir::TyKind::General)).take(num_vars),
|
std::iter::repeat(chalk_ir::VariableKind::Ty(chalk_ir::TyKind::General)).take(num_vars),
|
||||||
),
|
),
|
||||||
|
|
|
@ -157,7 +157,7 @@ impl DebugContext<'_> {
|
||||||
_ => panic!("associated type not in trait"),
|
_ => panic!("associated type not in trait"),
|
||||||
};
|
};
|
||||||
let trait_data = self.0.trait_data(trait_);
|
let trait_data = self.0.trait_data(trait_);
|
||||||
let params = projection_ty.substitution.parameters(&Interner);
|
let params = projection_ty.substitution.as_slice(&Interner);
|
||||||
write!(fmt, "<{:?} as {}", ¶ms[0], trait_data.name,)?;
|
write!(fmt, "<{:?} as {}", ¶ms[0], trait_data.name,)?;
|
||||||
if params.len() > 1 {
|
if params.len() > 1 {
|
||||||
write!(
|
write!(
|
||||||
|
|
Loading…
Reference in a new issue