diff options
Diffstat (limited to 'crates/ra_hir_ty/src/traits/chalk/mapping.rs')
-rw-r--r-- | crates/ra_hir_ty/src/traits/chalk/mapping.rs | 53 |
1 files changed, 41 insertions, 12 deletions
diff --git a/crates/ra_hir_ty/src/traits/chalk/mapping.rs b/crates/ra_hir_ty/src/traits/chalk/mapping.rs index a83d82fd8..7082cb095 100644 --- a/crates/ra_hir_ty/src/traits/chalk/mapping.rs +++ b/crates/ra_hir_ty/src/traits/chalk/mapping.rs | |||
@@ -15,8 +15,8 @@ use crate::{ | |||
15 | db::HirDatabase, | 15 | db::HirDatabase, |
16 | primitive::{FloatBitness, FloatTy, IntBitness, IntTy, Signedness, Uncertain}, | 16 | primitive::{FloatBitness, FloatTy, IntBitness, IntTy, Signedness, Uncertain}, |
17 | traits::{builtin, AssocTyValue, Canonical, Impl, Obligation}, | 17 | traits::{builtin, AssocTyValue, Canonical, Impl, Obligation}, |
18 | ApplicationTy, GenericPredicate, InEnvironment, ProjectionPredicate, ProjectionTy, Substs, | 18 | ApplicationTy, CallableDef, GenericPredicate, InEnvironment, ProjectionPredicate, ProjectionTy, |
19 | TraitEnvironment, TraitRef, Ty, TypeCtor, | 19 | Substs, TraitEnvironment, TraitRef, Ty, TypeCtor, |
20 | }; | 20 | }; |
21 | 21 | ||
22 | use super::interner::*; | 22 | use super::interner::*; |
@@ -26,14 +26,19 @@ impl ToChalk for Ty { | |||
26 | type Chalk = chalk_ir::Ty<Interner>; | 26 | type Chalk = chalk_ir::Ty<Interner>; |
27 | fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::Ty<Interner> { | 27 | fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::Ty<Interner> { |
28 | match self { | 28 | match self { |
29 | Ty::Apply(apply_ty) => { | 29 | Ty::Apply(apply_ty) => match apply_ty.ctor { |
30 | if let TypeCtor::Ref(m) = apply_ty.ctor { | 30 | TypeCtor::Ref(m) => ref_to_chalk(db, m, apply_ty.parameters), |
31 | return ref_to_chalk(db, m, apply_ty.parameters); | 31 | TypeCtor::FnPtr { num_args: _ } => { |
32 | let substitution = apply_ty.parameters.to_chalk(db).shifted_in(&Interner); | ||
33 | chalk_ir::TyData::Function(chalk_ir::Fn { num_binders: 0, substitution }) | ||
34 | .intern(&Interner) | ||
32 | } | 35 | } |
33 | let name = apply_ty.ctor.to_chalk(db); | 36 | _ => { |
34 | let substitution = apply_ty.parameters.to_chalk(db); | 37 | let name = apply_ty.ctor.to_chalk(db); |
35 | chalk_ir::ApplicationTy { name, substitution }.cast(&Interner).intern(&Interner) | 38 | let substitution = apply_ty.parameters.to_chalk(db); |
36 | } | 39 | chalk_ir::ApplicationTy { name, substitution }.cast(&Interner).intern(&Interner) |
40 | } | ||
41 | }, | ||
37 | Ty::Projection(proj_ty) => { | 42 | Ty::Projection(proj_ty) => { |
38 | let associated_ty_id = proj_ty.associated_ty.to_chalk(db); | 43 | let associated_ty_id = proj_ty.associated_ty.to_chalk(db); |
39 | let substitution = proj_ty.parameters.to_chalk(db); | 44 | let substitution = proj_ty.parameters.to_chalk(db); |
@@ -93,7 +98,13 @@ impl ToChalk for Ty { | |||
93 | Ty::Projection(ProjectionTy { associated_ty, parameters }) | 98 | Ty::Projection(ProjectionTy { associated_ty, parameters }) |
94 | } | 99 | } |
95 | chalk_ir::TyData::Alias(chalk_ir::AliasTy::Opaque(_)) => unimplemented!(), | 100 | chalk_ir::TyData::Alias(chalk_ir::AliasTy::Opaque(_)) => unimplemented!(), |
96 | chalk_ir::TyData::Function(_) => unimplemented!(), | 101 | chalk_ir::TyData::Function(chalk_ir::Fn { num_binders: _, substitution }) => { |
102 | let parameters: Substs = from_chalk(db, substitution); | ||
103 | Ty::Apply(ApplicationTy { | ||
104 | ctor: TypeCtor::FnPtr { num_args: (parameters.len() - 1) as u16 }, | ||
105 | parameters, | ||
106 | }) | ||
107 | } | ||
97 | chalk_ir::TyData::BoundVar(idx) => Ty::Bound(idx), | 108 | chalk_ir::TyData::BoundVar(idx) => Ty::Bound(idx), |
98 | chalk_ir::TyData::InferenceVar(_iv) => Ty::Unknown, | 109 | chalk_ir::TyData::InferenceVar(_iv) => Ty::Unknown, |
99 | chalk_ir::TyData::Dyn(where_clauses) => { | 110 | chalk_ir::TyData::Dyn(where_clauses) => { |
@@ -217,11 +228,14 @@ impl ToChalk for TypeCtor { | |||
217 | TypeCtor::Slice => TypeName::Slice, | 228 | TypeCtor::Slice => TypeName::Slice, |
218 | TypeCtor::Ref(mutability) => TypeName::Ref(mutability.to_chalk(db)), | 229 | TypeCtor::Ref(mutability) => TypeName::Ref(mutability.to_chalk(db)), |
219 | TypeCtor::Str => TypeName::Str, | 230 | TypeCtor::Str => TypeName::Str, |
231 | TypeCtor::FnDef(callable_def) => { | ||
232 | let id = callable_def.to_chalk(db); | ||
233 | TypeName::FnDef(id) | ||
234 | } | ||
220 | TypeCtor::Int(Uncertain::Unknown) | 235 | TypeCtor::Int(Uncertain::Unknown) |
221 | | TypeCtor::Float(Uncertain::Unknown) | 236 | | TypeCtor::Float(Uncertain::Unknown) |
222 | | TypeCtor::Adt(_) | 237 | | TypeCtor::Adt(_) |
223 | | TypeCtor::Array | 238 | | TypeCtor::Array |
224 | | TypeCtor::FnDef(_) | ||
225 | | TypeCtor::FnPtr { .. } | 239 | | TypeCtor::FnPtr { .. } |
226 | | TypeCtor::Never | 240 | | TypeCtor::Never |
227 | | TypeCtor::Closure { .. } => { | 241 | | TypeCtor::Closure { .. } => { |
@@ -260,7 +274,10 @@ impl ToChalk for TypeCtor { | |||
260 | TypeName::Ref(mutability) => TypeCtor::Ref(from_chalk(db, mutability)), | 274 | TypeName::Ref(mutability) => TypeCtor::Ref(from_chalk(db, mutability)), |
261 | TypeName::Str => TypeCtor::Str, | 275 | TypeName::Str => TypeCtor::Str, |
262 | 276 | ||
263 | TypeName::FnDef(_) => unreachable!(), | 277 | TypeName::FnDef(fn_def_id) => { |
278 | let callable_def = from_chalk(db, fn_def_id); | ||
279 | TypeCtor::FnDef(callable_def) | ||
280 | } | ||
264 | 281 | ||
265 | TypeName::Error => { | 282 | TypeName::Error => { |
266 | // this should not be reached, since we don't represent TypeName::Error with TypeCtor | 283 | // this should not be reached, since we don't represent TypeName::Error with TypeCtor |
@@ -347,6 +364,18 @@ impl ToChalk for Impl { | |||
347 | } | 364 | } |
348 | } | 365 | } |
349 | 366 | ||
367 | impl ToChalk for CallableDef { | ||
368 | type Chalk = FnDefId; | ||
369 | |||
370 | fn to_chalk(self, db: &dyn HirDatabase) -> FnDefId { | ||
371 | db.intern_callable_def(self).into() | ||
372 | } | ||
373 | |||
374 | fn from_chalk(db: &dyn HirDatabase, fn_def_id: FnDefId) -> CallableDef { | ||
375 | db.lookup_intern_callable_def(fn_def_id.into()) | ||
376 | } | ||
377 | } | ||
378 | |||
350 | impl ToChalk for TypeAliasId { | 379 | impl ToChalk for TypeAliasId { |
351 | type Chalk = AssocTypeId; | 380 | type Chalk = AssocTypeId; |
352 | 381 | ||