Bump chalk to 0.86
Two breaking changes: - `TypeFolder` has been split into `TypeFolder` and `FallibleTypeFolder` - `ProjectionTy::self_type_parameter()` has been removed
This commit is contained in:
parent
a0ab61fb6c
commit
310a72bf47
17
Cargo.lock
generated
17
Cargo.lock
generated
@ -171,9 +171,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "chalk-derive"
|
name = "chalk-derive"
|
||||||
version = "0.84.0"
|
version = "0.86.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "cf29c109d57f8d57b0e7675391be37a9285d86dd93278bd5f14a0ad3c447a6c2"
|
checksum = "5499d415d855b5094366a824815341893ad3de0ecb6048c430118bdae6d27402"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
@ -183,9 +183,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "chalk-ir"
|
name = "chalk-ir"
|
||||||
version = "0.84.0"
|
version = "0.86.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "d391763027b5e50a5e15caf6d2857ec585fd68160367bbeac9e1804209620918"
|
checksum = "3800118c76a48507b0eece3a01f3a429b5c478d203c493096e6040c67ab960e1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags",
|
"bitflags",
|
||||||
"chalk-derive",
|
"chalk-derive",
|
||||||
@ -194,9 +194,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "chalk-recursive"
|
name = "chalk-recursive"
|
||||||
version = "0.84.0"
|
version = "0.86.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "afafd92dcdc7fe0ea940ee94bdd8cc5bd18f4a4a84c593d6d7025fe16c150478"
|
checksum = "1baf60628fd73104d1f8562586a52d48f37f1e84435aab2e62674b1fd935b8c8"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"chalk-derive",
|
"chalk-derive",
|
||||||
"chalk-ir",
|
"chalk-ir",
|
||||||
@ -207,9 +207,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "chalk-solve"
|
name = "chalk-solve"
|
||||||
version = "0.84.0"
|
version = "0.86.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "3af1d111f11c91c48ace02e93e470c5bae6d2631bd112e4545317da53660d7fc"
|
checksum = "0e9c3c068f9358786348e58a1b94ef0a5cf90a9810fc1f10fda896f0b5d80185"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"chalk-derive",
|
"chalk-derive",
|
||||||
"chalk-ir",
|
"chalk-ir",
|
||||||
@ -546,6 +546,7 @@ version = "0.0.0"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"arrayvec",
|
"arrayvec",
|
||||||
"base-db",
|
"base-db",
|
||||||
|
"chalk-derive",
|
||||||
"chalk-ir",
|
"chalk-ir",
|
||||||
"chalk-recursive",
|
"chalk-recursive",
|
||||||
"chalk-solve",
|
"chalk-solve",
|
||||||
|
@ -27,6 +27,7 @@ debug = 0
|
|||||||
# chalk-solve = { path = "../chalk/chalk-solve" }
|
# chalk-solve = { path = "../chalk/chalk-solve" }
|
||||||
# chalk-ir = { path = "../chalk/chalk-ir" }
|
# chalk-ir = { path = "../chalk/chalk-ir" }
|
||||||
# chalk-recursive = { path = "../chalk/chalk-recursive" }
|
# chalk-recursive = { path = "../chalk/chalk-recursive" }
|
||||||
|
# chalk-derive = { path = "../chalk/chalk-derive" }
|
||||||
|
|
||||||
# ungrammar = { path = "../ungrammar" }
|
# ungrammar = { path = "../ungrammar" }
|
||||||
|
|
||||||
|
@ -18,9 +18,10 @@ ena = "0.14.0"
|
|||||||
tracing = "0.1.35"
|
tracing = "0.1.35"
|
||||||
rustc-hash = "1.1.0"
|
rustc-hash = "1.1.0"
|
||||||
scoped-tls = "1.0.0"
|
scoped-tls = "1.0.0"
|
||||||
chalk-solve = { version = "0.84.0", default-features = false }
|
chalk-solve = { version = "0.86.0", default-features = false }
|
||||||
chalk-ir = "0.84.0"
|
chalk-ir = "0.86.0"
|
||||||
chalk-recursive = { version = "0.84.0", default-features = false }
|
chalk-recursive = { version = "0.86.0", default-features = false }
|
||||||
|
chalk-derive = "0.86.0"
|
||||||
la-arena = { version = "0.3.0", path = "../../lib/la-arena" }
|
la-arena = { version = "0.3.0", path = "../../lib/la-arena" }
|
||||||
once_cell = "1.12.0"
|
once_cell = "1.12.0"
|
||||||
typed-arena = "2.0.1"
|
typed-arena = "2.0.1"
|
||||||
|
@ -823,10 +823,10 @@ pub(super) fn generic_predicate_to_inline_bound(
|
|||||||
Some(chalk_ir::Binders::new(binders, rust_ir::InlineBound::TraitBound(trait_bound)))
|
Some(chalk_ir::Binders::new(binders, rust_ir::InlineBound::TraitBound(trait_bound)))
|
||||||
}
|
}
|
||||||
WhereClause::AliasEq(AliasEq { alias: AliasTy::Projection(projection_ty), ty }) => {
|
WhereClause::AliasEq(AliasEq { alias: AliasTy::Projection(projection_ty), ty }) => {
|
||||||
if projection_ty.self_type_parameter(Interner) != self_ty_shifted_in {
|
let trait_ = projection_ty.trait_(db);
|
||||||
|
if projection_ty.self_type_parameter(db) != self_ty_shifted_in {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
let trait_ = projection_ty.trait_(db);
|
|
||||||
let args_no_self = projection_ty.substitution.as_slice(Interner)[1..]
|
let args_no_self = projection_ty.substitution.as_slice(Interner)[1..]
|
||||||
.iter()
|
.iter()
|
||||||
.map(|ty| ty.clone().cast(Interner))
|
.map(|ty| ty.clone().cast(Interner))
|
||||||
|
@ -262,7 +262,7 @@ fn impl_trait_bounds(&self, db: &dyn HirDatabase) -> Option<Vec<QuantifiedWhereC
|
|||||||
WhereClause::AliasEq(AliasEq {
|
WhereClause::AliasEq(AliasEq {
|
||||||
alias: AliasTy::Projection(proj),
|
alias: AliasTy::Projection(proj),
|
||||||
ty: _,
|
ty: _,
|
||||||
}) => &proj.self_type_parameter(Interner) == self,
|
}) => &proj.self_type_parameter(db) == self,
|
||||||
_ => false,
|
_ => false,
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
@ -333,6 +333,7 @@ fn equals_ctor(&self, other: &Ty) -> bool {
|
|||||||
pub trait ProjectionTyExt {
|
pub trait ProjectionTyExt {
|
||||||
fn trait_ref(&self, db: &dyn HirDatabase) -> TraitRef;
|
fn trait_ref(&self, db: &dyn HirDatabase) -> TraitRef;
|
||||||
fn trait_(&self, db: &dyn HirDatabase) -> TraitId;
|
fn trait_(&self, db: &dyn HirDatabase) -> TraitId;
|
||||||
|
fn self_type_parameter(&self, db: &dyn HirDatabase) -> Ty;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ProjectionTyExt for ProjectionTy {
|
impl ProjectionTyExt for ProjectionTy {
|
||||||
@ -349,6 +350,10 @@ fn trait_(&self, db: &dyn HirDatabase) -> TraitId {
|
|||||||
_ => panic!("projection ty without parent trait"),
|
_ => panic!("projection ty without parent trait"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn self_type_parameter(&self, db: &dyn HirDatabase) -> Ty {
|
||||||
|
self.trait_ref(db).self_type_parameter(Interner)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait TraitRefExt {
|
pub trait TraitRefExt {
|
||||||
|
@ -291,7 +291,7 @@ fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> {
|
|||||||
|
|
||||||
let trait_ = f.db.trait_data(self.trait_(f.db));
|
let trait_ = f.db.trait_data(self.trait_(f.db));
|
||||||
write!(f, "<")?;
|
write!(f, "<")?;
|
||||||
self.self_type_parameter(Interner).hir_fmt(f)?;
|
self.self_type_parameter(f.db).hir_fmt(f)?;
|
||||||
write!(f, " as {}", trait_.name)?;
|
write!(f, " as {}", trait_.name)?;
|
||||||
if self.substitution.len(Interner) > 1 {
|
if self.substitution.len(Interner) > 1 {
|
||||||
write!(f, "<")?;
|
write!(f, "<")?;
|
||||||
@ -731,7 +731,7 @@ fn should_show(
|
|||||||
WhereClause::AliasEq(AliasEq {
|
WhereClause::AliasEq(AliasEq {
|
||||||
alias: AliasTy::Projection(proj),
|
alias: AliasTy::Projection(proj),
|
||||||
ty: _,
|
ty: _,
|
||||||
}) => &proj.self_type_parameter(Interner) == self,
|
}) => &proj.self_type_parameter(f.db) == self,
|
||||||
_ => false,
|
_ => false,
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
use chalk_ir::{
|
use chalk_ir::{
|
||||||
cast::Cast, fold::TypeFoldable, interner::HasInterner, zip::Zip, CanonicalVarKind, FloatTy,
|
cast::Cast, fold::TypeFoldable, interner::HasInterner, zip::Zip, CanonicalVarKind, FloatTy,
|
||||||
IntTy, NoSolution, TyVariableKind, UniverseIndex,
|
IntTy, TyVariableKind, UniverseIndex,
|
||||||
};
|
};
|
||||||
use chalk_solve::infer::ParameterEnaVariableExt;
|
use chalk_solve::infer::ParameterEnaVariableExt;
|
||||||
use ena::unify::UnifyKey;
|
use ena::unify::UnifyKey;
|
||||||
@ -331,7 +331,6 @@ fn resolve_with_fallback_inner<T>(
|
|||||||
&mut resolve::Resolver { table: self, var_stack, fallback },
|
&mut resolve::Resolver { table: self, var_stack, fallback },
|
||||||
DebruijnIndex::INNERMOST,
|
DebruijnIndex::INNERMOST,
|
||||||
)
|
)
|
||||||
.expect("fold failed unexpectedly")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn resolve_completely<T>(&mut self, t: T) -> T
|
pub(crate) fn resolve_completely<T>(&mut self, t: T) -> T
|
||||||
@ -452,13 +451,14 @@ pub(crate) fn fudge_inference<T: TypeFoldable<Interner>>(
|
|||||||
f: impl FnOnce(&mut Self) -> T,
|
f: impl FnOnce(&mut Self) -> T,
|
||||||
) -> T {
|
) -> T {
|
||||||
use chalk_ir::fold::TypeFolder;
|
use chalk_ir::fold::TypeFolder;
|
||||||
|
|
||||||
|
#[derive(chalk_derive::FallibleTypeFolder)]
|
||||||
|
#[has_interner(Interner)]
|
||||||
struct VarFudger<'a, 'b> {
|
struct VarFudger<'a, 'b> {
|
||||||
table: &'a mut InferenceTable<'b>,
|
table: &'a mut InferenceTable<'b>,
|
||||||
highest_known_var: InferenceVar,
|
highest_known_var: InferenceVar,
|
||||||
}
|
}
|
||||||
impl<'a, 'b> TypeFolder<Interner> for VarFudger<'a, 'b> {
|
impl<'a, 'b> TypeFolder<Interner> for VarFudger<'a, 'b> {
|
||||||
type Error = NoSolution;
|
|
||||||
|
|
||||||
fn as_dyn(&mut self) -> &mut dyn TypeFolder<Interner, Error = Self::Error> {
|
fn as_dyn(&mut self) -> &mut dyn TypeFolder<Interner, Error = Self::Error> {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
@ -472,24 +472,24 @@ fn fold_inference_ty(
|
|||||||
var: chalk_ir::InferenceVar,
|
var: chalk_ir::InferenceVar,
|
||||||
kind: TyVariableKind,
|
kind: TyVariableKind,
|
||||||
_outer_binder: chalk_ir::DebruijnIndex,
|
_outer_binder: chalk_ir::DebruijnIndex,
|
||||||
) -> chalk_ir::Fallible<chalk_ir::Ty<Interner>> {
|
) -> chalk_ir::Ty<Interner> {
|
||||||
Ok(if var < self.highest_known_var {
|
if var < self.highest_known_var {
|
||||||
var.to_ty(Interner, kind)
|
var.to_ty(Interner, kind)
|
||||||
} else {
|
} else {
|
||||||
self.table.new_type_var()
|
self.table.new_type_var()
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fold_inference_lifetime(
|
fn fold_inference_lifetime(
|
||||||
&mut self,
|
&mut self,
|
||||||
var: chalk_ir::InferenceVar,
|
var: chalk_ir::InferenceVar,
|
||||||
_outer_binder: chalk_ir::DebruijnIndex,
|
_outer_binder: chalk_ir::DebruijnIndex,
|
||||||
) -> chalk_ir::Fallible<chalk_ir::Lifetime<Interner>> {
|
) -> chalk_ir::Lifetime<Interner> {
|
||||||
Ok(if var < self.highest_known_var {
|
if var < self.highest_known_var {
|
||||||
var.to_lifetime(Interner)
|
var.to_lifetime(Interner)
|
||||||
} else {
|
} else {
|
||||||
self.table.new_lifetime_var()
|
self.table.new_lifetime_var()
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fold_inference_const(
|
fn fold_inference_const(
|
||||||
@ -497,12 +497,12 @@ fn fold_inference_const(
|
|||||||
ty: chalk_ir::Ty<Interner>,
|
ty: chalk_ir::Ty<Interner>,
|
||||||
var: chalk_ir::InferenceVar,
|
var: chalk_ir::InferenceVar,
|
||||||
_outer_binder: chalk_ir::DebruijnIndex,
|
_outer_binder: chalk_ir::DebruijnIndex,
|
||||||
) -> chalk_ir::Fallible<chalk_ir::Const<Interner>> {
|
) -> chalk_ir::Const<Interner> {
|
||||||
Ok(if var < self.highest_known_var {
|
if var < self.highest_known_var {
|
||||||
var.to_const(Interner, ty)
|
var.to_const(Interner, ty)
|
||||||
} else {
|
} else {
|
||||||
self.table.new_const_var(ty)
|
self.table.new_const_var(ty)
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -512,7 +512,6 @@ fn fold_inference_const(
|
|||||||
self.rollback_to(snapshot);
|
self.rollback_to(snapshot);
|
||||||
result
|
result
|
||||||
.fold_with(&mut VarFudger { table: self, highest_known_var }, DebruijnIndex::INNERMOST)
|
.fold_with(&mut VarFudger { table: self, highest_known_var }, DebruijnIndex::INNERMOST)
|
||||||
.expect("fold_with with VarFudger")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This checks whether any of the free variables in the `canonicalized`
|
/// This checks whether any of the free variables in the `canonicalized`
|
||||||
@ -639,21 +638,24 @@ mod resolve {
|
|||||||
use chalk_ir::{
|
use chalk_ir::{
|
||||||
cast::Cast,
|
cast::Cast,
|
||||||
fold::{TypeFoldable, TypeFolder},
|
fold::{TypeFoldable, TypeFolder},
|
||||||
Fallible, NoSolution,
|
|
||||||
};
|
};
|
||||||
use hir_def::type_ref::ConstScalar;
|
use hir_def::type_ref::ConstScalar;
|
||||||
|
|
||||||
pub(super) struct Resolver<'a, 'b, F> {
|
#[derive(chalk_derive::FallibleTypeFolder)]
|
||||||
|
#[has_interner(Interner)]
|
||||||
|
pub(super) struct Resolver<
|
||||||
|
'a,
|
||||||
|
'b,
|
||||||
|
F: Fn(InferenceVar, VariableKind, GenericArg, DebruijnIndex) -> GenericArg,
|
||||||
|
> {
|
||||||
pub(super) table: &'a mut InferenceTable<'b>,
|
pub(super) table: &'a mut InferenceTable<'b>,
|
||||||
pub(super) var_stack: &'a mut Vec<InferenceVar>,
|
pub(super) var_stack: &'a mut Vec<InferenceVar>,
|
||||||
pub(super) fallback: F,
|
pub(super) fallback: F,
|
||||||
}
|
}
|
||||||
impl<'a, 'b, 'i, F> TypeFolder<Interner> for Resolver<'a, 'b, F>
|
impl<'a, 'b, F> TypeFolder<Interner> for Resolver<'a, 'b, F>
|
||||||
where
|
where
|
||||||
F: Fn(InferenceVar, VariableKind, GenericArg, DebruijnIndex) -> GenericArg + 'i,
|
F: Fn(InferenceVar, VariableKind, GenericArg, DebruijnIndex) -> GenericArg,
|
||||||
{
|
{
|
||||||
type Error = NoSolution;
|
|
||||||
|
|
||||||
fn as_dyn(&mut self) -> &mut dyn TypeFolder<Interner, Error = Self::Error> {
|
fn as_dyn(&mut self) -> &mut dyn TypeFolder<Interner, Error = Self::Error> {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
@ -667,20 +669,19 @@ fn fold_inference_ty(
|
|||||||
var: InferenceVar,
|
var: InferenceVar,
|
||||||
kind: TyVariableKind,
|
kind: TyVariableKind,
|
||||||
outer_binder: DebruijnIndex,
|
outer_binder: DebruijnIndex,
|
||||||
) -> Fallible<Ty> {
|
) -> Ty {
|
||||||
let var = self.table.var_unification_table.inference_var_root(var);
|
let var = self.table.var_unification_table.inference_var_root(var);
|
||||||
if self.var_stack.contains(&var) {
|
if self.var_stack.contains(&var) {
|
||||||
// recursive type
|
// recursive type
|
||||||
let default = self.table.fallback_value(var, kind).cast(Interner);
|
let default = self.table.fallback_value(var, kind).cast(Interner);
|
||||||
return Ok((self.fallback)(var, VariableKind::Ty(kind), default, outer_binder)
|
return (self.fallback)(var, VariableKind::Ty(kind), default, outer_binder)
|
||||||
.assert_ty_ref(Interner)
|
.assert_ty_ref(Interner)
|
||||||
.clone());
|
.clone();
|
||||||
}
|
}
|
||||||
let result = if let Some(known_ty) = self.table.var_unification_table.probe_var(var) {
|
let result = if let Some(known_ty) = self.table.var_unification_table.probe_var(var) {
|
||||||
// known_ty may contain other variables that are known by now
|
// known_ty may contain other variables that are known by now
|
||||||
self.var_stack.push(var);
|
self.var_stack.push(var);
|
||||||
let result =
|
let result = known_ty.fold_with(self, outer_binder);
|
||||||
known_ty.fold_with(self, outer_binder).expect("fold failed unexpectedly");
|
|
||||||
self.var_stack.pop();
|
self.var_stack.pop();
|
||||||
result.assert_ty_ref(Interner).clone()
|
result.assert_ty_ref(Interner).clone()
|
||||||
} else {
|
} else {
|
||||||
@ -689,7 +690,7 @@ fn fold_inference_ty(
|
|||||||
.assert_ty_ref(Interner)
|
.assert_ty_ref(Interner)
|
||||||
.clone()
|
.clone()
|
||||||
};
|
};
|
||||||
Ok(result)
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fold_inference_const(
|
fn fold_inference_const(
|
||||||
@ -697,7 +698,7 @@ fn fold_inference_const(
|
|||||||
ty: Ty,
|
ty: Ty,
|
||||||
var: InferenceVar,
|
var: InferenceVar,
|
||||||
outer_binder: DebruijnIndex,
|
outer_binder: DebruijnIndex,
|
||||||
) -> Fallible<Const> {
|
) -> Const {
|
||||||
let var = self.table.var_unification_table.inference_var_root(var);
|
let var = self.table.var_unification_table.inference_var_root(var);
|
||||||
let default = ConstData {
|
let default = ConstData {
|
||||||
ty: ty.clone(),
|
ty: ty.clone(),
|
||||||
@ -707,35 +708,33 @@ fn fold_inference_const(
|
|||||||
.cast(Interner);
|
.cast(Interner);
|
||||||
if self.var_stack.contains(&var) {
|
if self.var_stack.contains(&var) {
|
||||||
// recursive
|
// recursive
|
||||||
return Ok((self.fallback)(var, VariableKind::Const(ty), default, outer_binder)
|
return (self.fallback)(var, VariableKind::Const(ty), default, outer_binder)
|
||||||
.assert_const_ref(Interner)
|
.assert_const_ref(Interner)
|
||||||
.clone());
|
.clone();
|
||||||
}
|
}
|
||||||
let result = if let Some(known_ty) = self.table.var_unification_table.probe_var(var) {
|
if let Some(known_ty) = self.table.var_unification_table.probe_var(var) {
|
||||||
// known_ty may contain other variables that are known by now
|
// known_ty may contain other variables that are known by now
|
||||||
self.var_stack.push(var);
|
self.var_stack.push(var);
|
||||||
let result =
|
let result = known_ty.fold_with(self, outer_binder);
|
||||||
known_ty.fold_with(self, outer_binder).expect("fold failed unexpectedly");
|
|
||||||
self.var_stack.pop();
|
self.var_stack.pop();
|
||||||
result.assert_const_ref(Interner).clone()
|
result.assert_const_ref(Interner).clone()
|
||||||
} else {
|
} else {
|
||||||
(self.fallback)(var, VariableKind::Const(ty), default, outer_binder)
|
(self.fallback)(var, VariableKind::Const(ty), default, outer_binder)
|
||||||
.assert_const_ref(Interner)
|
.assert_const_ref(Interner)
|
||||||
.clone()
|
.clone()
|
||||||
};
|
}
|
||||||
Ok(result)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fold_inference_lifetime(
|
fn fold_inference_lifetime(
|
||||||
&mut self,
|
&mut self,
|
||||||
_var: InferenceVar,
|
_var: InferenceVar,
|
||||||
_outer_binder: DebruijnIndex,
|
_outer_binder: DebruijnIndex,
|
||||||
) -> Fallible<Lifetime> {
|
) -> Lifetime {
|
||||||
// fall back all lifetimes to 'static -- currently we don't deal
|
// fall back all lifetimes to 'static -- currently we don't deal
|
||||||
// with any lifetimes, but we can sometimes get some lifetime
|
// with any lifetimes, but we can sometimes get some lifetime
|
||||||
// variables through Chalk's unification, and this at least makes
|
// variables through Chalk's unification, and this at least makes
|
||||||
// sure we don't leak them outside of inference
|
// sure we don't leak them outside of inference
|
||||||
Ok(crate::static_lifetime())
|
crate::static_lifetime()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -254,13 +254,13 @@ pub fn ret(&self) -> &Ty {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl TypeFoldable<Interner> for CallableSig {
|
impl TypeFoldable<Interner> for CallableSig {
|
||||||
fn fold_with<E>(
|
fn try_fold_with<E>(
|
||||||
self,
|
self,
|
||||||
folder: &mut dyn chalk_ir::fold::TypeFolder<Interner, Error = E>,
|
folder: &mut dyn chalk_ir::fold::FallibleTypeFolder<Interner, Error = E>,
|
||||||
outer_binder: DebruijnIndex,
|
outer_binder: DebruijnIndex,
|
||||||
) -> Result<Self, E> {
|
) -> Result<Self, E> {
|
||||||
let vec = self.params_and_return.to_vec();
|
let vec = self.params_and_return.to_vec();
|
||||||
let folded = vec.fold_with(folder, outer_binder)?;
|
let folded = vec.try_fold_with(folder, outer_binder)?;
|
||||||
Ok(CallableSig { params_and_return: folded.into(), is_varargs: self.is_varargs })
|
Ok(CallableSig { params_and_return: folded.into(), is_varargs: self.is_varargs })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -292,16 +292,19 @@ pub(crate) fn fold_free_vars<T: HasInterner<Interner = Interner> + TypeFoldable<
|
|||||||
for_ty: impl FnMut(BoundVar, DebruijnIndex) -> Ty,
|
for_ty: impl FnMut(BoundVar, DebruijnIndex) -> Ty,
|
||||||
for_const: impl FnMut(Ty, BoundVar, DebruijnIndex) -> Const,
|
for_const: impl FnMut(Ty, BoundVar, DebruijnIndex) -> Const,
|
||||||
) -> T {
|
) -> T {
|
||||||
use chalk_ir::{fold::TypeFolder, Fallible};
|
use chalk_ir::fold::TypeFolder;
|
||||||
struct FreeVarFolder<F1, F2>(F1, F2);
|
|
||||||
|
#[derive(chalk_derive::FallibleTypeFolder)]
|
||||||
|
#[has_interner(Interner)]
|
||||||
|
struct FreeVarFolder<
|
||||||
|
F1: FnMut(BoundVar, DebruijnIndex) -> Ty,
|
||||||
|
F2: FnMut(Ty, BoundVar, DebruijnIndex) -> Const,
|
||||||
|
>(F1, F2);
|
||||||
impl<
|
impl<
|
||||||
'i,
|
F1: FnMut(BoundVar, DebruijnIndex) -> Ty,
|
||||||
F1: FnMut(BoundVar, DebruijnIndex) -> Ty + 'i,
|
F2: FnMut(Ty, BoundVar, DebruijnIndex) -> Const,
|
||||||
F2: FnMut(Ty, BoundVar, DebruijnIndex) -> Const + 'i,
|
|
||||||
> TypeFolder<Interner> for FreeVarFolder<F1, F2>
|
> TypeFolder<Interner> for FreeVarFolder<F1, F2>
|
||||||
{
|
{
|
||||||
type Error = NoSolution;
|
|
||||||
|
|
||||||
fn as_dyn(&mut self) -> &mut dyn TypeFolder<Interner, Error = Self::Error> {
|
fn as_dyn(&mut self) -> &mut dyn TypeFolder<Interner, Error = Self::Error> {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
@ -310,12 +313,8 @@ fn interner(&self) -> Interner {
|
|||||||
Interner
|
Interner
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fold_free_var_ty(
|
fn fold_free_var_ty(&mut self, bound_var: BoundVar, outer_binder: DebruijnIndex) -> Ty {
|
||||||
&mut self,
|
self.0(bound_var, outer_binder)
|
||||||
bound_var: BoundVar,
|
|
||||||
outer_binder: DebruijnIndex,
|
|
||||||
) -> Fallible<Ty> {
|
|
||||||
Ok(self.0(bound_var, outer_binder))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fold_free_var_const(
|
fn fold_free_var_const(
|
||||||
@ -323,12 +322,11 @@ fn fold_free_var_const(
|
|||||||
ty: Ty,
|
ty: Ty,
|
||||||
bound_var: BoundVar,
|
bound_var: BoundVar,
|
||||||
outer_binder: DebruijnIndex,
|
outer_binder: DebruijnIndex,
|
||||||
) -> Fallible<Const> {
|
) -> Const {
|
||||||
Ok(self.1(ty, bound_var, outer_binder))
|
self.1(ty, bound_var, outer_binder)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
t.fold_with(&mut FreeVarFolder(for_ty, for_const), DebruijnIndex::INNERMOST)
|
t.fold_with(&mut FreeVarFolder(for_ty, for_const), DebruijnIndex::INNERMOST)
|
||||||
.expect("fold failed unexpectedly")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn fold_tys<T: HasInterner<Interner = Interner> + TypeFoldable<Interner>>(
|
pub(crate) fn fold_tys<T: HasInterner<Interner = Interner> + TypeFoldable<Interner>>(
|
||||||
@ -351,16 +349,13 @@ pub(crate) fn fold_tys_and_consts<T: HasInterner<Interner = Interner> + TypeFold
|
|||||||
f: impl FnMut(Either<Ty, Const>, DebruijnIndex) -> Either<Ty, Const>,
|
f: impl FnMut(Either<Ty, Const>, DebruijnIndex) -> Either<Ty, Const>,
|
||||||
binders: DebruijnIndex,
|
binders: DebruijnIndex,
|
||||||
) -> T {
|
) -> T {
|
||||||
use chalk_ir::{
|
use chalk_ir::fold::{TypeFolder, TypeSuperFoldable};
|
||||||
fold::{TypeFolder, TypeSuperFoldable},
|
#[derive(chalk_derive::FallibleTypeFolder)]
|
||||||
Fallible,
|
#[has_interner(Interner)]
|
||||||
};
|
struct TyFolder<F: FnMut(Either<Ty, Const>, DebruijnIndex) -> Either<Ty, Const>>(F);
|
||||||
struct TyFolder<F>(F);
|
impl<F: FnMut(Either<Ty, Const>, DebruijnIndex) -> Either<Ty, Const>> TypeFolder<Interner>
|
||||||
impl<'i, F: FnMut(Either<Ty, Const>, DebruijnIndex) -> Either<Ty, Const> + 'i>
|
for TyFolder<F>
|
||||||
TypeFolder<Interner> for TyFolder<F>
|
|
||||||
{
|
{
|
||||||
type Error = NoSolution;
|
|
||||||
|
|
||||||
fn as_dyn(&mut self) -> &mut dyn TypeFolder<Interner, Error = Self::Error> {
|
fn as_dyn(&mut self) -> &mut dyn TypeFolder<Interner, Error = Self::Error> {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
@ -369,16 +364,16 @@ fn interner(&self) -> Interner {
|
|||||||
Interner
|
Interner
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fold_ty(&mut self, ty: Ty, outer_binder: DebruijnIndex) -> Fallible<Ty> {
|
fn fold_ty(&mut self, ty: Ty, outer_binder: DebruijnIndex) -> Ty {
|
||||||
let ty = ty.super_fold_with(self.as_dyn(), outer_binder)?;
|
let ty = ty.super_fold_with(self.as_dyn(), outer_binder);
|
||||||
Ok(self.0(Either::Left(ty), outer_binder).left().unwrap())
|
self.0(Either::Left(ty), outer_binder).left().unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fold_const(&mut self, c: Const, outer_binder: DebruijnIndex) -> Fallible<Const> {
|
fn fold_const(&mut self, c: Const, outer_binder: DebruijnIndex) -> Const {
|
||||||
Ok(self.0(Either::Right(c), outer_binder).right().unwrap())
|
self.0(Either::Right(c), outer_binder).right().unwrap()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
t.fold_with(&mut TyFolder(f), binders).expect("fold failed unexpectedly")
|
t.fold_with(&mut TyFolder(f), binders)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 'Canonicalizes' the `t` by replacing any errors with new variables. Also
|
/// 'Canonicalizes' the `t` by replacing any errors with new variables. Also
|
||||||
@ -390,16 +385,16 @@ pub fn replace_errors_with_variables<T>(t: &T) -> Canonical<T>
|
|||||||
T: HasInterner<Interner = Interner>,
|
T: HasInterner<Interner = Interner>,
|
||||||
{
|
{
|
||||||
use chalk_ir::{
|
use chalk_ir::{
|
||||||
fold::{TypeFolder, TypeSuperFoldable},
|
fold::{FallibleTypeFolder, TypeSuperFoldable},
|
||||||
Fallible,
|
Fallible,
|
||||||
};
|
};
|
||||||
struct ErrorReplacer {
|
struct ErrorReplacer {
|
||||||
vars: usize,
|
vars: usize,
|
||||||
}
|
}
|
||||||
impl TypeFolder<Interner> for ErrorReplacer {
|
impl FallibleTypeFolder<Interner> for ErrorReplacer {
|
||||||
type Error = NoSolution;
|
type Error = NoSolution;
|
||||||
|
|
||||||
fn as_dyn(&mut self) -> &mut dyn TypeFolder<Interner, Error = Self::Error> {
|
fn as_dyn(&mut self) -> &mut dyn FallibleTypeFolder<Interner, Error = Self::Error> {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -407,18 +402,17 @@ fn interner(&self) -> Interner {
|
|||||||
Interner
|
Interner
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fold_ty(&mut self, ty: Ty, outer_binder: DebruijnIndex) -> Fallible<Ty> {
|
fn try_fold_ty(&mut self, ty: Ty, outer_binder: DebruijnIndex) -> Fallible<Ty> {
|
||||||
if let TyKind::Error = ty.kind(Interner) {
|
if let TyKind::Error = ty.kind(Interner) {
|
||||||
let index = self.vars;
|
let index = self.vars;
|
||||||
self.vars += 1;
|
self.vars += 1;
|
||||||
Ok(TyKind::BoundVar(BoundVar::new(outer_binder, index)).intern(Interner))
|
Ok(TyKind::BoundVar(BoundVar::new(outer_binder, index)).intern(Interner))
|
||||||
} else {
|
} else {
|
||||||
let ty = ty.super_fold_with(self.as_dyn(), outer_binder)?;
|
ty.try_super_fold_with(self.as_dyn(), outer_binder)
|
||||||
Ok(ty)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fold_inference_ty(
|
fn try_fold_inference_ty(
|
||||||
&mut self,
|
&mut self,
|
||||||
_var: InferenceVar,
|
_var: InferenceVar,
|
||||||
_kind: TyVariableKind,
|
_kind: TyVariableKind,
|
||||||
@ -433,7 +427,7 @@ fn fold_inference_ty(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fold_free_var_ty(
|
fn try_fold_free_var_ty(
|
||||||
&mut self,
|
&mut self,
|
||||||
_bound_var: BoundVar,
|
_bound_var: BoundVar,
|
||||||
_outer_binder: DebruijnIndex,
|
_outer_binder: DebruijnIndex,
|
||||||
@ -447,7 +441,7 @@ fn fold_free_var_ty(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fold_inference_const(
|
fn try_fold_inference_const(
|
||||||
&mut self,
|
&mut self,
|
||||||
ty: Ty,
|
ty: Ty,
|
||||||
_var: InferenceVar,
|
_var: InferenceVar,
|
||||||
@ -460,7 +454,7 @@ fn fold_inference_const(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fold_free_var_const(
|
fn try_fold_free_var_const(
|
||||||
&mut self,
|
&mut self,
|
||||||
ty: Ty,
|
ty: Ty,
|
||||||
_bound_var: BoundVar,
|
_bound_var: BoundVar,
|
||||||
@ -473,7 +467,7 @@ fn fold_free_var_const(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fold_inference_lifetime(
|
fn try_fold_inference_lifetime(
|
||||||
&mut self,
|
&mut self,
|
||||||
_var: InferenceVar,
|
_var: InferenceVar,
|
||||||
_outer_binder: DebruijnIndex,
|
_outer_binder: DebruijnIndex,
|
||||||
@ -485,7 +479,7 @@ fn fold_inference_lifetime(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fold_free_var_lifetime(
|
fn try_fold_free_var_lifetime(
|
||||||
&mut self,
|
&mut self,
|
||||||
_bound_var: BoundVar,
|
_bound_var: BoundVar,
|
||||||
_outer_binder: DebruijnIndex,
|
_outer_binder: DebruijnIndex,
|
||||||
@ -498,7 +492,7 @@ fn fold_free_var_lifetime(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
let mut error_replacer = ErrorReplacer { vars: 0 };
|
let mut error_replacer = ErrorReplacer { vars: 0 };
|
||||||
let value = match t.clone().fold_with(&mut error_replacer, DebruijnIndex::INNERMOST) {
|
let value = match t.clone().try_fold_with(&mut error_replacer, DebruijnIndex::INNERMOST) {
|
||||||
Ok(t) => t,
|
Ok(t) => t,
|
||||||
Err(_) => panic!("Encountered unbound or inference vars in {:?}", t),
|
Err(_) => panic!("Encountered unbound or inference vars in {:?}", t),
|
||||||
};
|
};
|
||||||
|
@ -13,8 +13,8 @@
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
db::HirDatabase, infer::unify::InferenceTable, AliasEq, AliasTy, Canonical, DomainGoal, Goal,
|
db::HirDatabase, infer::unify::InferenceTable, AliasEq, AliasTy, Canonical, DomainGoal, Goal,
|
||||||
Guidance, InEnvironment, Interner, ProjectionTy, Solution, TraitRefExt, Ty, TyKind,
|
Guidance, InEnvironment, Interner, ProjectionTy, ProjectionTyExt, Solution, TraitRefExt, Ty,
|
||||||
WhereClause,
|
TyKind, WhereClause,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// This controls how much 'time' we give the Chalk solver before giving up.
|
/// This controls how much 'time' we give the Chalk solver before giving up.
|
||||||
@ -95,7 +95,7 @@ pub(crate) fn trait_solve_query(
|
|||||||
..
|
..
|
||||||
}))) = &goal.value.goal.data(Interner)
|
}))) = &goal.value.goal.data(Interner)
|
||||||
{
|
{
|
||||||
if let TyKind::BoundVar(_) = projection_ty.self_type_parameter(Interner).kind(Interner) {
|
if let TyKind::BoundVar(_) = projection_ty.self_type_parameter(db).kind(Interner) {
|
||||||
// Hack: don't ask Chalk to normalize with an unknown self type, it'll say that's impossible
|
// Hack: don't ask Chalk to normalize with an unknown self type, it'll say that's impossible
|
||||||
return Some(Solution::Ambig(Guidance::Unknown));
|
return Some(Solution::Ambig(Guidance::Unknown));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user