diff options
author | Florian Diebold <[email protected]> | 2020-07-11 14:22:46 +0100 |
---|---|---|
committer | Florian Diebold <[email protected]> | 2020-07-12 18:58:34 +0100 |
commit | 209c492432c15b017f99dba06d5937389c1f9546 (patch) | |
tree | 45d30a421ff534c72ae850cd4ff108b74ef81f9d /crates/ra_hir_ty | |
parent | ab1ad19f552e1b11055ed60f87cc420871d902eb (diff) |
Upgrade Chalk
Diffstat (limited to 'crates/ra_hir_ty')
-rw-r--r-- | crates/ra_hir_ty/src/traits.rs | 8 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/traits/chalk.rs | 36 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/traits/chalk/interner.rs | 15 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/traits/chalk/mapping.rs | 15 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/traits/chalk/tls.rs | 2 |
5 files changed, 63 insertions, 13 deletions
diff --git a/crates/ra_hir_ty/src/traits.rs b/crates/ra_hir_ty/src/traits.rs index 2a6d7faef..786f758e9 100644 --- a/crates/ra_hir_ty/src/traits.rs +++ b/crates/ra_hir_ty/src/traits.rs | |||
@@ -2,6 +2,7 @@ | |||
2 | use std::sync::Arc; | 2 | use std::sync::Arc; |
3 | 3 | ||
4 | use chalk_ir::cast::Cast; | 4 | use chalk_ir::cast::Cast; |
5 | use chalk_solve::Solver; | ||
5 | use hir_def::{ | 6 | use hir_def::{ |
6 | expr::ExprId, lang_item::LangItemTarget, DefWithBodyId, ImplId, TraitId, TypeAliasId, | 7 | expr::ExprId, lang_item::LangItemTarget, DefWithBodyId, ImplId, TraitId, TypeAliasId, |
7 | }; | 8 | }; |
@@ -32,9 +33,10 @@ struct ChalkContext<'a> { | |||
32 | krate: CrateId, | 33 | krate: CrateId, |
33 | } | 34 | } |
34 | 35 | ||
35 | fn create_chalk_solver() -> chalk_solve::Solver<Interner> { | 36 | fn create_chalk_solver() -> chalk_recursive::RecursiveSolver<Interner> { |
36 | let solver_choice = chalk_solve::SolverChoice::recursive(); | 37 | let overflow_depth = 100; |
37 | solver_choice.into_solver() | 38 | let caching_enabled = true; |
39 | chalk_recursive::RecursiveSolver::new(overflow_depth, caching_enabled) | ||
38 | } | 40 | } |
39 | 41 | ||
40 | /// A set of clauses that we assume to be true. E.g. if we are inside this function: | 42 | /// A set of clauses that we assume to be true. E.g. if we are inside this function: |
diff --git a/crates/ra_hir_ty/src/traits/chalk.rs b/crates/ra_hir_ty/src/traits/chalk.rs index c97b81d57..a9b39474a 100644 --- a/crates/ra_hir_ty/src/traits/chalk.rs +++ b/crates/ra_hir_ty/src/traits/chalk.rs | |||
@@ -3,7 +3,7 @@ use std::sync::Arc; | |||
3 | 3 | ||
4 | use log::debug; | 4 | use log::debug; |
5 | 5 | ||
6 | use chalk_ir::{fold::shift::Shift, GenericArg, TypeName}; | 6 | use chalk_ir::{fold::shift::Shift, GenericArg, TypeName, CanonicalVarKinds}; |
7 | use chalk_solve::rust_ir::{self, OpaqueTyDatumBound, WellKnownTrait}; | 7 | use chalk_solve::rust_ir::{self, OpaqueTyDatumBound, WellKnownTrait}; |
8 | 8 | ||
9 | use hir_def::{ | 9 | use hir_def::{ |
@@ -66,10 +66,13 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> { | |||
66 | &self, | 66 | &self, |
67 | trait_id: TraitId, | 67 | trait_id: TraitId, |
68 | parameters: &[GenericArg<Interner>], | 68 | parameters: &[GenericArg<Interner>], |
69 | _binders: &CanonicalVarKinds<Interner>, | ||
69 | ) -> Vec<ImplId> { | 70 | ) -> Vec<ImplId> { |
70 | debug!("impls_for_trait {:?}", trait_id); | 71 | debug!("impls_for_trait {:?}", trait_id); |
71 | let trait_: hir_def::TraitId = from_chalk(self.db, trait_id); | 72 | let trait_: hir_def::TraitId = from_chalk(self.db, trait_id); |
72 | 73 | ||
74 | // FIXME use binders to look for int/float impls when necessary | ||
75 | |||
73 | let ty: Ty = from_chalk(self.db, parameters[0].assert_ty_ref(&Interner).clone()); | 76 | let ty: Ty = from_chalk(self.db, parameters[0].assert_ty_ref(&Interner).clone()); |
74 | 77 | ||
75 | let self_ty_fp = TyFingerprint::for_impl(&ty); | 78 | let self_ty_fp = TyFingerprint::for_impl(&ty); |
@@ -219,6 +222,22 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> { | |||
219 | // FIXME: implement closure support | 222 | // FIXME: implement closure support |
220 | unimplemented!() | 223 | unimplemented!() |
221 | } | 224 | } |
225 | |||
226 | fn trait_name(&self, _trait_id: chalk_ir::TraitId<Interner>) -> String { | ||
227 | unimplemented!() | ||
228 | } | ||
229 | fn adt_name(&self, _struct_id: chalk_ir::AdtId<Interner>) -> String { | ||
230 | unimplemented!() | ||
231 | } | ||
232 | fn assoc_type_name(&self, _assoc_ty_id: chalk_ir::AssocTypeId<Interner>) -> String { | ||
233 | unimplemented!() | ||
234 | } | ||
235 | fn opaque_type_name(&self, _opaque_ty_id: chalk_ir::OpaqueTyId<Interner>) -> String { | ||
236 | unimplemented!() | ||
237 | } | ||
238 | fn fn_def_name(&self, _fn_def_id: chalk_ir::FnDefId<Interner>) -> String { | ||
239 | unimplemented!() | ||
240 | } | ||
222 | } | 241 | } |
223 | 242 | ||
224 | pub(crate) fn program_clauses_for_chalk_env_query( | 243 | pub(crate) fn program_clauses_for_chalk_env_query( |
@@ -354,12 +373,21 @@ pub(crate) fn struct_datum_query( | |||
354 | fundamental: false, | 373 | fundamental: false, |
355 | phantom_data: false, | 374 | phantom_data: false, |
356 | }; | 375 | }; |
376 | // FIXME provide enum variants properly (for auto traits) | ||
377 | let variant = rust_ir::AdtVariantDatum { | ||
378 | fields: Vec::new(), // FIXME add fields (only relevant for auto traits), | ||
379 | }; | ||
357 | let struct_datum_bound = rust_ir::AdtDatumBound { | 380 | let struct_datum_bound = rust_ir::AdtDatumBound { |
358 | fields: Vec::new(), // FIXME add fields (only relevant for auto traits) | 381 | variants: vec![variant], |
359 | where_clauses, | 382 | where_clauses, |
360 | }; | 383 | }; |
361 | let struct_datum = | 384 | let struct_datum = StructDatum { |
362 | StructDatum { id: struct_id, binders: make_binders(struct_datum_bound, num_params), flags }; | 385 | // FIXME set ADT kind |
386 | kind: rust_ir::AdtKind::Struct, | ||
387 | id: struct_id, | ||
388 | binders: make_binders(struct_datum_bound, num_params), | ||
389 | flags | ||
390 | }; | ||
363 | Arc::new(struct_datum) | 391 | Arc::new(struct_datum) |
364 | } | 392 | } |
365 | 393 | ||
diff --git a/crates/ra_hir_ty/src/traits/chalk/interner.rs b/crates/ra_hir_ty/src/traits/chalk/interner.rs index 15426b022..156b691b4 100644 --- a/crates/ra_hir_ty/src/traits/chalk/interner.rs +++ b/crates/ra_hir_ty/src/traits/chalk/interner.rs | |||
@@ -39,6 +39,7 @@ impl chalk_ir::interner::Interner for Interner { | |||
39 | type InternedQuantifiedWhereClauses = Vec<chalk_ir::QuantifiedWhereClause<Self>>; | 39 | type InternedQuantifiedWhereClauses = Vec<chalk_ir::QuantifiedWhereClause<Self>>; |
40 | type InternedVariableKinds = Vec<chalk_ir::VariableKind<Self>>; | 40 | type InternedVariableKinds = Vec<chalk_ir::VariableKind<Self>>; |
41 | type InternedCanonicalVarKinds = Vec<chalk_ir::CanonicalVarKind<Self>>; | 41 | type InternedCanonicalVarKinds = Vec<chalk_ir::CanonicalVarKind<Self>>; |
42 | type InternedConstraints = Vec<chalk_ir::InEnvironment<chalk_ir::Constraint<Self>>>; | ||
42 | type DefId = InternId; | 43 | type DefId = InternId; |
43 | type InternedAdtId = crate::TypeCtorId; | 44 | type InternedAdtId = crate::TypeCtorId; |
44 | type Identifier = TypeAliasId; | 45 | type Identifier = TypeAliasId; |
@@ -349,6 +350,20 @@ impl chalk_ir::interner::Interner for Interner { | |||
349 | ) -> &'a [chalk_ir::CanonicalVarKind<Self>] { | 350 | ) -> &'a [chalk_ir::CanonicalVarKind<Self>] { |
350 | &canonical_var_kinds | 351 | &canonical_var_kinds |
351 | } | 352 | } |
353 | |||
354 | fn intern_constraints<E>( | ||
355 | &self, | ||
356 | data: impl IntoIterator<Item = Result<chalk_ir::InEnvironment<chalk_ir::Constraint<Self>>, E>>, | ||
357 | ) -> Result<Self::InternedConstraints, E> { | ||
358 | data.into_iter().collect() | ||
359 | } | ||
360 | |||
361 | fn constraints_data<'a>( | ||
362 | &self, | ||
363 | constraints: &'a Self::InternedConstraints, | ||
364 | ) -> &'a [chalk_ir::InEnvironment<chalk_ir::Constraint<Self>>] { | ||
365 | constraints | ||
366 | } | ||
352 | } | 367 | } |
353 | 368 | ||
354 | impl chalk_ir::interner::HasInterner for Interner { | 369 | impl chalk_ir::interner::HasInterner for Interner { |
diff --git a/crates/ra_hir_ty/src/traits/chalk/mapping.rs b/crates/ra_hir_ty/src/traits/chalk/mapping.rs index 433d6aa03..bc0c6de17 100644 --- a/crates/ra_hir_ty/src/traits/chalk/mapping.rs +++ b/crates/ra_hir_ty/src/traits/chalk/mapping.rs | |||
@@ -61,7 +61,7 @@ impl ToChalk for Ty { | |||
61 | Ty::Bound(idx) => chalk_ir::TyData::BoundVar(idx).intern(&Interner), | 61 | Ty::Bound(idx) => chalk_ir::TyData::BoundVar(idx).intern(&Interner), |
62 | Ty::Infer(_infer_ty) => panic!("uncanonicalized infer ty"), | 62 | Ty::Infer(_infer_ty) => panic!("uncanonicalized infer ty"), |
63 | Ty::Dyn(predicates) => { | 63 | Ty::Dyn(predicates) => { |
64 | let where_clauses = chalk_ir::QuantifiedWhereClauses::from( | 64 | let where_clauses = chalk_ir::QuantifiedWhereClauses::from_iter( |
65 | &Interner, | 65 | &Interner, |
66 | predicates.iter().filter(|p| !p.is_error()).cloned().map(|p| p.to_chalk(db)), | 66 | predicates.iter().filter(|p| !p.is_error()).cloned().map(|p| p.to_chalk(db)), |
67 | ); | 67 | ); |
@@ -152,7 +152,7 @@ fn ref_to_chalk( | |||
152 | let lifetime = LIFETIME_PLACEHOLDER.to_lifetime(&Interner); | 152 | let lifetime = LIFETIME_PLACEHOLDER.to_lifetime(&Interner); |
153 | chalk_ir::ApplicationTy { | 153 | chalk_ir::ApplicationTy { |
154 | name: TypeName::Ref(mutability.to_chalk(db)), | 154 | name: TypeName::Ref(mutability.to_chalk(db)), |
155 | substitution: chalk_ir::Substitution::from( | 155 | substitution: chalk_ir::Substitution::from_iter( |
156 | &Interner, | 156 | &Interner, |
157 | vec![lifetime.cast(&Interner), arg.cast(&Interner)], | 157 | vec![lifetime.cast(&Interner), arg.cast(&Interner)], |
158 | ), | 158 | ), |
@@ -177,7 +177,7 @@ impl ToChalk for Substs { | |||
177 | type Chalk = chalk_ir::Substitution<Interner>; | 177 | type Chalk = chalk_ir::Substitution<Interner>; |
178 | 178 | ||
179 | fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::Substitution<Interner> { | 179 | fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::Substitution<Interner> { |
180 | chalk_ir::Substitution::from(&Interner, self.iter().map(|ty| ty.clone().to_chalk(db))) | 180 | chalk_ir::Substitution::from_iter(&Interner, self.iter().map(|ty| ty.clone().to_chalk(db))) |
181 | } | 181 | } |
182 | 182 | ||
183 | fn from_chalk(db: &dyn HirDatabase, parameters: chalk_ir::Substitution<Interner>) -> Substs { | 183 | fn from_chalk(db: &dyn HirDatabase, parameters: chalk_ir::Substitution<Interner>) -> Substs { |
@@ -492,6 +492,11 @@ impl ToChalk for GenericPredicate { | |||
492 | // we shouldn't get these from Chalk | 492 | // we shouldn't get these from Chalk |
493 | panic!("encountered LifetimeOutlives from Chalk") | 493 | panic!("encountered LifetimeOutlives from Chalk") |
494 | } | 494 | } |
495 | |||
496 | chalk_ir::WhereClause::TypeOutlives(_) => { | ||
497 | // we shouldn't get these from Chalk | ||
498 | panic!("encountered TypeOutlives from Chalk") | ||
499 | } | ||
495 | } | 500 | } |
496 | } | 501 | } |
497 | } | 502 | } |
@@ -570,7 +575,7 @@ where | |||
570 | ) | 575 | ) |
571 | }); | 576 | }); |
572 | let value = self.value.to_chalk(db); | 577 | let value = self.value.to_chalk(db); |
573 | chalk_ir::Canonical { value, binders: chalk_ir::CanonicalVarKinds::from(&Interner, kinds) } | 578 | chalk_ir::Canonical { value, binders: chalk_ir::CanonicalVarKinds::from_iter(&Interner, kinds) } |
574 | } | 579 | } |
575 | 580 | ||
576 | fn from_chalk(db: &dyn HirDatabase, canonical: chalk_ir::Canonical<T::Chalk>) -> Canonical<T> { | 581 | fn from_chalk(db: &dyn HirDatabase, canonical: chalk_ir::Canonical<T::Chalk>) -> Canonical<T> { |
@@ -691,7 +696,7 @@ where | |||
691 | T: HasInterner<Interner = Interner>, | 696 | T: HasInterner<Interner = Interner>, |
692 | { | 697 | { |
693 | chalk_ir::Binders::new( | 698 | chalk_ir::Binders::new( |
694 | chalk_ir::VariableKinds::from( | 699 | chalk_ir::VariableKinds::from_iter( |
695 | &Interner, | 700 | &Interner, |
696 | std::iter::repeat(chalk_ir::VariableKind::Ty(chalk_ir::TyKind::General)).take(num_vars), | 701 | std::iter::repeat(chalk_ir::VariableKind::Ty(chalk_ir::TyKind::General)).take(num_vars), |
697 | ), | 702 | ), |
diff --git a/crates/ra_hir_ty/src/traits/chalk/tls.rs b/crates/ra_hir_ty/src/traits/chalk/tls.rs index e6a9d3211..1e226baea 100644 --- a/crates/ra_hir_ty/src/traits/chalk/tls.rs +++ b/crates/ra_hir_ty/src/traits/chalk/tls.rs | |||
@@ -157,7 +157,7 @@ impl DebugContext<'_> { | |||
157 | _ => panic!("associated type not in trait"), | 157 | _ => panic!("associated type not in trait"), |
158 | }; | 158 | }; |
159 | let trait_data = self.0.trait_data(trait_); | 159 | let trait_data = self.0.trait_data(trait_); |
160 | let params = projection_ty.substitution.parameters(&Interner); | 160 | let params = projection_ty.substitution.as_slice(&Interner); |
161 | write!(fmt, "<{:?} as {}", ¶ms[0], trait_data.name,)?; | 161 | write!(fmt, "<{:?} as {}", ¶ms[0], trait_data.name,)?; |
162 | if params.len() > 1 { | 162 | if params.len() > 1 { |
163 | write!( | 163 | write!( |