diff options
author | Florian Diebold <[email protected]> | 2020-07-12 14:26:02 +0100 |
---|---|---|
committer | Florian Diebold <[email protected]> | 2020-07-15 21:04:49 +0100 |
commit | a48843a16a2306399f2f6a78c69d9192a6480c88 (patch) | |
tree | 2fbaf1c22c631e9e2278e6a33940ccf6ea98037c /crates/ra_hir_ty/src/traits/chalk | |
parent | b63e23e98e7dfbe57de93ebe256254825512e148 (diff) |
Use Chalk closure support
Diffstat (limited to 'crates/ra_hir_ty/src/traits/chalk')
-rw-r--r-- | crates/ra_hir_ty/src/traits/chalk/mapping.rs | 97 |
1 files changed, 33 insertions, 64 deletions
diff --git a/crates/ra_hir_ty/src/traits/chalk/mapping.rs b/crates/ra_hir_ty/src/traits/chalk/mapping.rs index 3ebb55f77..796947e69 100644 --- a/crates/ra_hir_ty/src/traits/chalk/mapping.rs +++ b/crates/ra_hir_ty/src/traits/chalk/mapping.rs | |||
@@ -15,7 +15,7 @@ use ra_db::salsa::InternKey; | |||
15 | use crate::{ | 15 | use crate::{ |
16 | db::HirDatabase, | 16 | db::HirDatabase, |
17 | primitive::{FloatBitness, FloatTy, IntBitness, IntTy, Signedness}, | 17 | primitive::{FloatBitness, FloatTy, IntBitness, IntTy, Signedness}, |
18 | traits::{builtin, AssocTyValue, Canonical, Impl, Obligation}, | 18 | traits::{Canonical, Obligation}, |
19 | ApplicationTy, CallableDef, GenericPredicate, InEnvironment, OpaqueTy, OpaqueTyId, | 19 | ApplicationTy, CallableDef, GenericPredicate, InEnvironment, OpaqueTy, OpaqueTyId, |
20 | ProjectionPredicate, ProjectionTy, Substs, TraitEnvironment, TraitRef, Ty, TyKind, TypeCtor, | 20 | ProjectionPredicate, ProjectionTy, Substs, TraitEnvironment, TraitRef, Ty, TyKind, TypeCtor, |
21 | }; | 21 | }; |
@@ -311,8 +311,15 @@ impl ToChalk for TypeCtor { | |||
311 | } | 311 | } |
312 | TypeCtor::Never => TypeName::Never, | 312 | TypeCtor::Never => TypeName::Never, |
313 | 313 | ||
314 | // FIXME convert these | 314 | TypeCtor::Closure { def, expr } => { |
315 | TypeCtor::Adt(_) | TypeCtor::FnPtr { .. } | TypeCtor::Closure { .. } => { | 315 | let closure_id = db.intern_closure((def, expr)); |
316 | TypeName::Closure(closure_id.into()) | ||
317 | } | ||
318 | |||
319 | TypeCtor::FnPtr { .. } => panic!("Trying to convert FnPtr to TypeName"), | ||
320 | |||
321 | TypeCtor::Adt(_) => { | ||
322 | // FIXME no interning needed anymore | ||
316 | // other TypeCtors get interned and turned into a chalk StructId | 323 | // other TypeCtors get interned and turned into a chalk StructId |
317 | let struct_id = db.intern_type_ctor(self).into(); | 324 | let struct_id = db.intern_type_ctor(self).into(); |
318 | TypeName::Adt(struct_id) | 325 | TypeName::Adt(struct_id) |
@@ -355,13 +362,16 @@ impl ToChalk for TypeCtor { | |||
355 | let callable_def = from_chalk(db, fn_def_id); | 362 | let callable_def = from_chalk(db, fn_def_id); |
356 | TypeCtor::FnDef(callable_def) | 363 | TypeCtor::FnDef(callable_def) |
357 | } | 364 | } |
365 | TypeName::Array => TypeCtor::Array, | ||
358 | 366 | ||
359 | TypeName::Array | TypeName::Error => { | 367 | TypeName::Closure(id) => { |
360 | // this should not be reached, since we don't represent TypeName::Error with TypeCtor | 368 | let id: crate::db::ClosureId = id.into(); |
361 | unreachable!() | 369 | let (def, expr) = db.lookup_intern_closure(id); |
370 | TypeCtor::Closure { def, expr } | ||
362 | } | 371 | } |
363 | TypeName::Closure(_) => { | 372 | |
364 | // FIXME: implement closure support | 373 | TypeName::Error => { |
374 | // this should not be reached, since we don't represent TypeName::Error with TypeCtor | ||
365 | unreachable!() | 375 | unreachable!() |
366 | } | 376 | } |
367 | } | 377 | } |
@@ -433,15 +443,15 @@ impl ToChalk for Mutability { | |||
433 | } | 443 | } |
434 | } | 444 | } |
435 | 445 | ||
436 | impl ToChalk for Impl { | 446 | impl ToChalk for hir_def::ImplId { |
437 | type Chalk = ImplId; | 447 | type Chalk = ImplId; |
438 | 448 | ||
439 | fn to_chalk(self, db: &dyn HirDatabase) -> ImplId { | 449 | fn to_chalk(self, _db: &dyn HirDatabase) -> ImplId { |
440 | db.intern_chalk_impl(self).into() | 450 | chalk_ir::ImplId(self.as_intern_id()) |
441 | } | 451 | } |
442 | 452 | ||
443 | fn from_chalk(db: &dyn HirDatabase, impl_id: ImplId) -> Impl { | 453 | fn from_chalk(_db: &dyn HirDatabase, impl_id: ImplId) -> hir_def::ImplId { |
444 | db.lookup_intern_chalk_impl(impl_id.into()) | 454 | InternKey::from_intern_id(impl_id.0) |
445 | } | 455 | } |
446 | } | 456 | } |
447 | 457 | ||
@@ -469,15 +479,20 @@ impl ToChalk for TypeAliasId { | |||
469 | } | 479 | } |
470 | } | 480 | } |
471 | 481 | ||
472 | impl ToChalk for AssocTyValue { | 482 | pub struct TypeAliasAsValue(pub TypeAliasId); |
483 | |||
484 | impl ToChalk for TypeAliasAsValue { | ||
473 | type Chalk = AssociatedTyValueId; | 485 | type Chalk = AssociatedTyValueId; |
474 | 486 | ||
475 | fn to_chalk(self, db: &dyn HirDatabase) -> AssociatedTyValueId { | 487 | fn to_chalk(self, _db: &dyn HirDatabase) -> AssociatedTyValueId { |
476 | db.intern_assoc_ty_value(self).into() | 488 | rust_ir::AssociatedTyValueId(self.0.as_intern_id()) |
477 | } | 489 | } |
478 | 490 | ||
479 | fn from_chalk(db: &dyn HirDatabase, assoc_ty_value_id: AssociatedTyValueId) -> AssocTyValue { | 491 | fn from_chalk( |
480 | db.lookup_intern_assoc_ty_value(assoc_ty_value_id.into()) | 492 | _db: &dyn HirDatabase, |
493 | assoc_ty_value_id: AssociatedTyValueId, | ||
494 | ) -> TypeAliasAsValue { | ||
495 | TypeAliasAsValue(TypeAliasId::from_intern_id(assoc_ty_value_id.0)) | ||
481 | } | 496 | } |
482 | } | 497 | } |
483 | 498 | ||
@@ -686,52 +701,6 @@ where | |||
686 | } | 701 | } |
687 | } | 702 | } |
688 | 703 | ||
689 | impl ToChalk for builtin::BuiltinImplData { | ||
690 | type Chalk = ImplDatum; | ||
691 | |||
692 | fn to_chalk(self, db: &dyn HirDatabase) -> ImplDatum { | ||
693 | let impl_type = rust_ir::ImplType::External; | ||
694 | let where_clauses = self.where_clauses.into_iter().map(|w| w.to_chalk(db)).collect(); | ||
695 | |||
696 | let impl_datum_bound = | ||
697 | rust_ir::ImplDatumBound { trait_ref: self.trait_ref.to_chalk(db), where_clauses }; | ||
698 | let associated_ty_value_ids = | ||
699 | self.assoc_ty_values.into_iter().map(|v| v.to_chalk(db)).collect(); | ||
700 | rust_ir::ImplDatum { | ||
701 | binders: make_binders(impl_datum_bound, self.num_vars), | ||
702 | impl_type, | ||
703 | polarity: rust_ir::Polarity::Positive, | ||
704 | associated_ty_value_ids, | ||
705 | } | ||
706 | } | ||
707 | |||
708 | fn from_chalk(_db: &dyn HirDatabase, _data: ImplDatum) -> Self { | ||
709 | unimplemented!() | ||
710 | } | ||
711 | } | ||
712 | |||
713 | impl ToChalk for builtin::BuiltinImplAssocTyValueData { | ||
714 | type Chalk = AssociatedTyValue; | ||
715 | |||
716 | fn to_chalk(self, db: &dyn HirDatabase) -> AssociatedTyValue { | ||
717 | let ty = self.value.to_chalk(db); | ||
718 | let value_bound = rust_ir::AssociatedTyValueBound { ty }; | ||
719 | |||
720 | rust_ir::AssociatedTyValue { | ||
721 | associated_ty_id: self.assoc_ty_id.to_chalk(db), | ||
722 | impl_id: self.impl_.to_chalk(db), | ||
723 | value: make_binders(value_bound, self.num_vars), | ||
724 | } | ||
725 | } | ||
726 | |||
727 | fn from_chalk( | ||
728 | _db: &dyn HirDatabase, | ||
729 | _data: AssociatedTyValue, | ||
730 | ) -> builtin::BuiltinImplAssocTyValueData { | ||
731 | unimplemented!() | ||
732 | } | ||
733 | } | ||
734 | |||
735 | pub(super) fn make_binders<T>(value: T, num_vars: usize) -> chalk_ir::Binders<T> | 704 | pub(super) fn make_binders<T>(value: T, num_vars: usize) -> chalk_ir::Binders<T> |
736 | where | 705 | where |
737 | T: HasInterner<Interner = Interner>, | 706 | T: HasInterner<Interner = Interner>, |