From 78dd5482438b1ba13b4aa2eaa9a7c443a3342ce4 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Fri, 20 Nov 2020 18:00:34 +0100 Subject: Upgrade Chalk Also make overflow depth and max type size configurable through env variables. This can be helpful at least for debugging. Fixes #6628. --- crates/hir_ty/src/traits/chalk/interner.rs | 16 ++++++++++++++++ crates/hir_ty/src/traits/chalk/mapping.rs | 13 ++++++++++--- 2 files changed, 26 insertions(+), 3 deletions(-) (limited to 'crates/hir_ty/src/traits/chalk') diff --git a/crates/hir_ty/src/traits/chalk/interner.rs b/crates/hir_ty/src/traits/chalk/interner.rs index 39569e690..6a4aa8333 100644 --- a/crates/hir_ty/src/traits/chalk/interner.rs +++ b/crates/hir_ty/src/traits/chalk/interner.rs @@ -25,6 +25,7 @@ pub(crate) type FnDefId = chalk_ir::FnDefId; pub(crate) type FnDefDatum = chalk_solve::rust_ir::FnDefDatum; pub(crate) type OpaqueTyId = chalk_ir::OpaqueTyId; pub(crate) type OpaqueTyDatum = chalk_solve::rust_ir::OpaqueTyDatum; +pub(crate) type Variances = chalk_ir::Variances; impl chalk_ir::interner::Interner for Interner { type InternedType = Arc>; @@ -41,6 +42,7 @@ impl chalk_ir::interner::Interner for Interner { type InternedVariableKinds = Vec>; type InternedCanonicalVarKinds = Vec>; type InternedConstraints = Vec>>; + type InternedVariances = Arc<[chalk_ir::Variance]>; type DefId = InternId; type InternedAdtId = hir_def::AdtId; type Identifier = TypeAliasId; @@ -370,6 +372,20 @@ impl chalk_ir::interner::Interner for Interner { ) -> Option { None } + + fn intern_variances( + &self, + data: impl IntoIterator>, + ) -> Result { + data.into_iter().collect() + } + + fn variances_data<'a>( + &self, + variances: &'a Self::InternedVariances, + ) -> &'a [chalk_ir::Variance] { + &variances + } } impl chalk_ir::interner::HasInterner for Interner { diff --git a/crates/hir_ty/src/traits/chalk/mapping.rs b/crates/hir_ty/src/traits/chalk/mapping.rs index 86cbc4c7e..8700d664e 100644 --- a/crates/hir_ty/src/traits/chalk/mapping.rs +++ b/crates/hir_ty/src/traits/chalk/mapping.rs @@ -31,7 +31,8 @@ impl ToChalk for Ty { TypeCtor::Ref(m) => ref_to_chalk(db, m, apply_ty.parameters), TypeCtor::Array => array_to_chalk(db, apply_ty.parameters), TypeCtor::FnPtr { num_args: _, is_varargs } => { - let substitution = apply_ty.parameters.to_chalk(db).shifted_in(&Interner); + let substitution = + chalk_ir::FnSubst(apply_ty.parameters.to_chalk(db).shifted_in(&Interner)); chalk_ir::TyKind::Function(chalk_ir::FnPointer { num_binders: 0, sig: chalk_ir::FnSig { @@ -183,7 +184,7 @@ impl ToChalk for Ty { assert_eq!(num_binders, 0); let parameters: Substs = from_chalk( db, - substitution.shifted_out(&Interner).expect("fn ptr should have no binders"), + substitution.0.shifted_out(&Interner).expect("fn ptr should have no binders"), ); Ty::Apply(ApplicationTy { ctor: TypeCtor::FnPtr { @@ -536,6 +537,7 @@ impl ToChalk for GenericPredicate { // we don't produce any where clauses with binders and can't currently deal with them match where_clause .skip_binders() + .clone() .shifted_out(&Interner) .expect("unexpected bound vars in where clause") { @@ -661,7 +663,12 @@ where chalk_ir::TyVariableKind::Integer => TyKind::Integer, chalk_ir::TyVariableKind::Float => TyKind::Float, }, - chalk_ir::VariableKind::Lifetime => panic!("unexpected lifetime from Chalk"), + // HACK: Chalk can sometimes return new lifetime variables. We + // want to just skip them, but to not mess up the indices of + // other variables, we'll just create a new type variable in + // their place instead. This should not matter (we never see the + // actual *uses* of the lifetime variable). + chalk_ir::VariableKind::Lifetime => TyKind::General, chalk_ir::VariableKind::Const(_) => panic!("unexpected const from Chalk"), }) .collect(); -- cgit v1.2.3