diff options
Diffstat (limited to 'crates/ra_hir_ty/src/traits/chalk')
-rw-r--r-- | crates/ra_hir_ty/src/traits/chalk/interner.rs | 14 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/traits/chalk/mapping.rs | 104 |
2 files changed, 49 insertions, 69 deletions
diff --git a/crates/ra_hir_ty/src/traits/chalk/interner.rs b/crates/ra_hir_ty/src/traits/chalk/interner.rs index 156b691b4..8d4c51a8f 100644 --- a/crates/ra_hir_ty/src/traits/chalk/interner.rs +++ b/crates/ra_hir_ty/src/traits/chalk/interner.rs | |||
@@ -41,7 +41,7 @@ impl chalk_ir::interner::Interner for Interner { | |||
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 InternedConstraints = Vec<chalk_ir::InEnvironment<chalk_ir::Constraint<Self>>>; |
43 | type DefId = InternId; | 43 | type DefId = InternId; |
44 | type InternedAdtId = crate::TypeCtorId; | 44 | type InternedAdtId = hir_def::AdtId; |
45 | type Identifier = TypeAliasId; | 45 | type Identifier = TypeAliasId; |
46 | type FnAbi = (); | 46 | type FnAbi = (); |
47 | 47 | ||
@@ -364,6 +364,18 @@ impl chalk_ir::interner::Interner for Interner { | |||
364 | ) -> &'a [chalk_ir::InEnvironment<chalk_ir::Constraint<Self>>] { | 364 | ) -> &'a [chalk_ir::InEnvironment<chalk_ir::Constraint<Self>>] { |
365 | constraints | 365 | constraints |
366 | } | 366 | } |
367 | fn debug_closure_id( | ||
368 | _fn_def_id: chalk_ir::ClosureId<Self>, | ||
369 | _fmt: &mut fmt::Formatter<'_>, | ||
370 | ) -> Option<fmt::Result> { | ||
371 | None | ||
372 | } | ||
373 | fn debug_constraints( | ||
374 | _clauses: &chalk_ir::Constraints<Self>, | ||
375 | _fmt: &mut fmt::Formatter<'_>, | ||
376 | ) -> Option<fmt::Result> { | ||
377 | None | ||
378 | } | ||
367 | } | 379 | } |
368 | 380 | ||
369 | impl chalk_ir::interner::HasInterner for Interner { | 381 | 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 3ebb55f77..a852ce2ac 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,18 +311,24 @@ 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 | // other TypeCtors get interned and turned into a chalk StructId | 316 | TypeName::Closure(closure_id.into()) |
317 | let struct_id = db.intern_type_ctor(self).into(); | 317 | } |
318 | TypeName::Adt(struct_id) | 318 | |
319 | TypeCtor::Adt(adt_id) => TypeName::Adt(chalk_ir::AdtId(adt_id)), | ||
320 | |||
321 | TypeCtor::FnPtr { .. } => { | ||
322 | // This should not be reached, since Chalk doesn't represent | ||
323 | // function pointers with TypeName | ||
324 | unreachable!() | ||
319 | } | 325 | } |
320 | } | 326 | } |
321 | } | 327 | } |
322 | 328 | ||
323 | fn from_chalk(db: &dyn HirDatabase, type_name: TypeName<Interner>) -> TypeCtor { | 329 | fn from_chalk(db: &dyn HirDatabase, type_name: TypeName<Interner>) -> TypeCtor { |
324 | match type_name { | 330 | match type_name { |
325 | TypeName::Adt(struct_id) => db.lookup_intern_type_ctor(struct_id.into()), | 331 | TypeName::Adt(struct_id) => TypeCtor::Adt(struct_id.0), |
326 | TypeName::AssociatedType(type_id) => TypeCtor::AssociatedType(from_chalk(db, type_id)), | 332 | TypeName::AssociatedType(type_id) => TypeCtor::AssociatedType(from_chalk(db, type_id)), |
327 | TypeName::OpaqueType(opaque_type_id) => { | 333 | TypeName::OpaqueType(opaque_type_id) => { |
328 | TypeCtor::OpaqueType(from_chalk(db, opaque_type_id)) | 334 | TypeCtor::OpaqueType(from_chalk(db, opaque_type_id)) |
@@ -355,13 +361,16 @@ impl ToChalk for TypeCtor { | |||
355 | let callable_def = from_chalk(db, fn_def_id); | 361 | let callable_def = from_chalk(db, fn_def_id); |
356 | TypeCtor::FnDef(callable_def) | 362 | TypeCtor::FnDef(callable_def) |
357 | } | 363 | } |
364 | TypeName::Array => TypeCtor::Array, | ||
358 | 365 | ||
359 | TypeName::Array | TypeName::Error => { | 366 | TypeName::Closure(id) => { |
360 | // this should not be reached, since we don't represent TypeName::Error with TypeCtor | 367 | let id: crate::db::ClosureId = id.into(); |
361 | unreachable!() | 368 | let (def, expr) = db.lookup_intern_closure(id); |
369 | TypeCtor::Closure { def, expr } | ||
362 | } | 370 | } |
363 | TypeName::Closure(_) => { | 371 | |
364 | // FIXME: implement closure support | 372 | TypeName::Error => { |
373 | // this should not be reached, since we don't represent TypeName::Error with TypeCtor | ||
365 | unreachable!() | 374 | unreachable!() |
366 | } | 375 | } |
367 | } | 376 | } |
@@ -433,15 +442,15 @@ impl ToChalk for Mutability { | |||
433 | } | 442 | } |
434 | } | 443 | } |
435 | 444 | ||
436 | impl ToChalk for Impl { | 445 | impl ToChalk for hir_def::ImplId { |
437 | type Chalk = ImplId; | 446 | type Chalk = ImplId; |
438 | 447 | ||
439 | fn to_chalk(self, db: &dyn HirDatabase) -> ImplId { | 448 | fn to_chalk(self, _db: &dyn HirDatabase) -> ImplId { |
440 | db.intern_chalk_impl(self).into() | 449 | chalk_ir::ImplId(self.as_intern_id()) |
441 | } | 450 | } |
442 | 451 | ||
443 | fn from_chalk(db: &dyn HirDatabase, impl_id: ImplId) -> Impl { | 452 | fn from_chalk(_db: &dyn HirDatabase, impl_id: ImplId) -> hir_def::ImplId { |
444 | db.lookup_intern_chalk_impl(impl_id.into()) | 453 | InternKey::from_intern_id(impl_id.0) |
445 | } | 454 | } |
446 | } | 455 | } |
447 | 456 | ||
@@ -469,15 +478,20 @@ impl ToChalk for TypeAliasId { | |||
469 | } | 478 | } |
470 | } | 479 | } |
471 | 480 | ||
472 | impl ToChalk for AssocTyValue { | 481 | pub struct TypeAliasAsValue(pub TypeAliasId); |
482 | |||
483 | impl ToChalk for TypeAliasAsValue { | ||
473 | type Chalk = AssociatedTyValueId; | 484 | type Chalk = AssociatedTyValueId; |
474 | 485 | ||
475 | fn to_chalk(self, db: &dyn HirDatabase) -> AssociatedTyValueId { | 486 | fn to_chalk(self, _db: &dyn HirDatabase) -> AssociatedTyValueId { |
476 | db.intern_assoc_ty_value(self).into() | 487 | rust_ir::AssociatedTyValueId(self.0.as_intern_id()) |
477 | } | 488 | } |
478 | 489 | ||
479 | fn from_chalk(db: &dyn HirDatabase, assoc_ty_value_id: AssociatedTyValueId) -> AssocTyValue { | 490 | fn from_chalk( |
480 | db.lookup_intern_assoc_ty_value(assoc_ty_value_id.into()) | 491 | _db: &dyn HirDatabase, |
492 | assoc_ty_value_id: AssociatedTyValueId, | ||
493 | ) -> TypeAliasAsValue { | ||
494 | TypeAliasAsValue(TypeAliasId::from_intern_id(assoc_ty_value_id.0)) | ||
481 | } | 495 | } |
482 | } | 496 | } |
483 | 497 | ||
@@ -686,52 +700,6 @@ where | |||
686 | } | 700 | } |
687 | } | 701 | } |
688 | 702 | ||
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> | 703 | pub(super) fn make_binders<T>(value: T, num_vars: usize) -> chalk_ir::Binders<T> |
736 | where | 704 | where |
737 | T: HasInterner<Interner = Interner>, | 705 | T: HasInterner<Interner = Interner>, |