diff options
Diffstat (limited to 'crates/hir_ty/src/traits/chalk')
-rw-r--r-- | crates/hir_ty/src/traits/chalk/interner.rs | 1 | ||||
-rw-r--r-- | crates/hir_ty/src/traits/chalk/mapping.rs | 69 | ||||
-rw-r--r-- | crates/hir_ty/src/traits/chalk/tls.rs | 11 |
3 files changed, 62 insertions, 19 deletions
diff --git a/crates/hir_ty/src/traits/chalk/interner.rs b/crates/hir_ty/src/traits/chalk/interner.rs index eb35db3ff..f9304b7d0 100644 --- a/crates/hir_ty/src/traits/chalk/interner.rs +++ b/crates/hir_ty/src/traits/chalk/interner.rs | |||
@@ -12,6 +12,7 @@ pub struct Interner; | |||
12 | 12 | ||
13 | pub type AssocTypeId = chalk_ir::AssocTypeId<Interner>; | 13 | pub type AssocTypeId = chalk_ir::AssocTypeId<Interner>; |
14 | pub type AssociatedTyDatum = chalk_solve::rust_ir::AssociatedTyDatum<Interner>; | 14 | pub type AssociatedTyDatum = chalk_solve::rust_ir::AssociatedTyDatum<Interner>; |
15 | pub type ForeignDefId = chalk_ir::ForeignDefId<Interner>; | ||
15 | pub type TraitId = chalk_ir::TraitId<Interner>; | 16 | pub type TraitId = chalk_ir::TraitId<Interner>; |
16 | pub type TraitDatum = chalk_solve::rust_ir::TraitDatum<Interner>; | 17 | pub type TraitDatum = chalk_solve::rust_ir::TraitDatum<Interner>; |
17 | pub type AdtId = chalk_ir::AdtId<Interner>; | 18 | pub type AdtId = chalk_ir::AdtId<Interner>; |
diff --git a/crates/hir_ty/src/traits/chalk/mapping.rs b/crates/hir_ty/src/traits/chalk/mapping.rs index d6bacba1d..d42f4bba9 100644 --- a/crates/hir_ty/src/traits/chalk/mapping.rs +++ b/crates/hir_ty/src/traits/chalk/mapping.rs | |||
@@ -34,9 +34,11 @@ impl ToChalk for Ty { | |||
34 | let substitution = apply_ty.parameters.to_chalk(db).shifted_in(&Interner); | 34 | let substitution = apply_ty.parameters.to_chalk(db).shifted_in(&Interner); |
35 | chalk_ir::TyData::Function(chalk_ir::FnPointer { | 35 | chalk_ir::TyData::Function(chalk_ir::FnPointer { |
36 | num_binders: 0, | 36 | num_binders: 0, |
37 | abi: (), | 37 | sig: chalk_ir::FnSig { |
38 | safety: chalk_ir::Safety::Safe, | 38 | abi: (), |
39 | variadic: is_varargs, | 39 | safety: chalk_ir::Safety::Safe, |
40 | variadic: is_varargs, | ||
41 | }, | ||
40 | substitution, | 42 | substitution, |
41 | }) | 43 | }) |
42 | .intern(&Interner) | 44 | .intern(&Interner) |
@@ -48,7 +50,7 @@ impl ToChalk for Ty { | |||
48 | } | 50 | } |
49 | }, | 51 | }, |
50 | Ty::Projection(proj_ty) => { | 52 | Ty::Projection(proj_ty) => { |
51 | let associated_ty_id = proj_ty.associated_ty.to_chalk(db); | 53 | let associated_ty_id = TypeAliasAsAssocType(proj_ty.associated_ty).to_chalk(db); |
52 | let substitution = proj_ty.parameters.to_chalk(db); | 54 | let substitution = proj_ty.parameters.to_chalk(db); |
53 | chalk_ir::AliasTy::Projection(chalk_ir::ProjectionTy { | 55 | chalk_ir::AliasTy::Projection(chalk_ir::ProjectionTy { |
54 | associated_ty_id, | 56 | associated_ty_id, |
@@ -114,7 +116,8 @@ impl ToChalk for Ty { | |||
114 | Ty::Placeholder(db.lookup_intern_type_param_id(interned_id)) | 116 | Ty::Placeholder(db.lookup_intern_type_param_id(interned_id)) |
115 | } | 117 | } |
116 | chalk_ir::TyData::Alias(chalk_ir::AliasTy::Projection(proj)) => { | 118 | chalk_ir::TyData::Alias(chalk_ir::AliasTy::Projection(proj)) => { |
117 | let associated_ty = from_chalk(db, proj.associated_ty_id); | 119 | let associated_ty = |
120 | from_chalk::<TypeAliasAsAssocType, _>(db, proj.associated_ty_id).0; | ||
118 | let parameters = from_chalk(db, proj.substitution); | 121 | let parameters = from_chalk(db, proj.substitution); |
119 | Ty::Projection(ProjectionTy { associated_ty, parameters }) | 122 | Ty::Projection(ProjectionTy { associated_ty, parameters }) |
120 | } | 123 | } |
@@ -125,7 +128,7 @@ impl ToChalk for Ty { | |||
125 | } | 128 | } |
126 | chalk_ir::TyData::Function(chalk_ir::FnPointer { | 129 | chalk_ir::TyData::Function(chalk_ir::FnPointer { |
127 | num_binders, | 130 | num_binders, |
128 | variadic, | 131 | sig: chalk_ir::FnSig { variadic, .. }, |
129 | substitution, | 132 | substitution, |
130 | .. | 133 | .. |
131 | }) => { | 134 | }) => { |
@@ -290,8 +293,9 @@ impl ToChalk for TypeCtor { | |||
290 | fn to_chalk(self, db: &dyn HirDatabase) -> TypeName<Interner> { | 293 | fn to_chalk(self, db: &dyn HirDatabase) -> TypeName<Interner> { |
291 | match self { | 294 | match self { |
292 | TypeCtor::AssociatedType(type_alias) => { | 295 | TypeCtor::AssociatedType(type_alias) => { |
293 | let type_id = type_alias.to_chalk(db); | 296 | let assoc_type = TypeAliasAsAssocType(type_alias); |
294 | TypeName::AssociatedType(type_id) | 297 | let assoc_type_id = assoc_type.to_chalk(db); |
298 | TypeName::AssociatedType(assoc_type_id) | ||
295 | } | 299 | } |
296 | 300 | ||
297 | TypeCtor::OpaqueType(impl_trait_id) => { | 301 | TypeCtor::OpaqueType(impl_trait_id) => { |
@@ -299,6 +303,12 @@ impl ToChalk for TypeCtor { | |||
299 | TypeName::OpaqueType(id) | 303 | TypeName::OpaqueType(id) |
300 | } | 304 | } |
301 | 305 | ||
306 | TypeCtor::ForeignType(type_alias) => { | ||
307 | let foreign_type = TypeAliasAsForeignType(type_alias); | ||
308 | let foreign_type_id = foreign_type.to_chalk(db); | ||
309 | TypeName::Foreign(foreign_type_id) | ||
310 | } | ||
311 | |||
302 | TypeCtor::Bool => TypeName::Scalar(Scalar::Bool), | 312 | TypeCtor::Bool => TypeName::Scalar(Scalar::Bool), |
303 | TypeCtor::Char => TypeName::Scalar(Scalar::Char), | 313 | TypeCtor::Char => TypeName::Scalar(Scalar::Char), |
304 | TypeCtor::Int(int_ty) => TypeName::Scalar(int_ty_to_chalk(int_ty)), | 314 | TypeCtor::Int(int_ty) => TypeName::Scalar(int_ty_to_chalk(int_ty)), |
@@ -339,7 +349,9 @@ impl ToChalk for TypeCtor { | |||
339 | fn from_chalk(db: &dyn HirDatabase, type_name: TypeName<Interner>) -> TypeCtor { | 349 | fn from_chalk(db: &dyn HirDatabase, type_name: TypeName<Interner>) -> TypeCtor { |
340 | match type_name { | 350 | match type_name { |
341 | TypeName::Adt(struct_id) => TypeCtor::Adt(struct_id.0), | 351 | TypeName::Adt(struct_id) => TypeCtor::Adt(struct_id.0), |
342 | TypeName::AssociatedType(type_id) => TypeCtor::AssociatedType(from_chalk(db, type_id)), | 352 | TypeName::AssociatedType(type_id) => { |
353 | TypeCtor::AssociatedType(from_chalk::<TypeAliasAsAssocType, _>(db, type_id).0) | ||
354 | } | ||
343 | TypeName::OpaqueType(opaque_type_id) => { | 355 | TypeName::OpaqueType(opaque_type_id) => { |
344 | TypeCtor::OpaqueType(from_chalk(db, opaque_type_id)) | 356 | TypeCtor::OpaqueType(from_chalk(db, opaque_type_id)) |
345 | } | 357 | } |
@@ -379,6 +391,10 @@ impl ToChalk for TypeCtor { | |||
379 | TypeCtor::Closure { def, expr } | 391 | TypeCtor::Closure { def, expr } |
380 | } | 392 | } |
381 | 393 | ||
394 | TypeName::Foreign(foreign_def_id) => { | ||
395 | TypeCtor::ForeignType(from_chalk::<TypeAliasAsForeignType, _>(db, foreign_def_id).0) | ||
396 | } | ||
397 | |||
382 | TypeName::Error => { | 398 | TypeName::Error => { |
383 | // this should not be reached, since we don't represent TypeName::Error with TypeCtor | 399 | // this should not be reached, since we don't represent TypeName::Error with TypeCtor |
384 | unreachable!() | 400 | unreachable!() |
@@ -488,15 +504,31 @@ impl ToChalk for CallableDefId { | |||
488 | } | 504 | } |
489 | } | 505 | } |
490 | 506 | ||
491 | impl ToChalk for TypeAliasId { | 507 | pub struct TypeAliasAsAssocType(pub TypeAliasId); |
508 | |||
509 | impl ToChalk for TypeAliasAsAssocType { | ||
492 | type Chalk = AssocTypeId; | 510 | type Chalk = AssocTypeId; |
493 | 511 | ||
494 | fn to_chalk(self, _db: &dyn HirDatabase) -> AssocTypeId { | 512 | fn to_chalk(self, _db: &dyn HirDatabase) -> AssocTypeId { |
495 | chalk_ir::AssocTypeId(self.as_intern_id()) | 513 | chalk_ir::AssocTypeId(self.0.as_intern_id()) |
514 | } | ||
515 | |||
516 | fn from_chalk(_db: &dyn HirDatabase, assoc_type_id: AssocTypeId) -> TypeAliasAsAssocType { | ||
517 | TypeAliasAsAssocType(InternKey::from_intern_id(assoc_type_id.0)) | ||
518 | } | ||
519 | } | ||
520 | |||
521 | pub struct TypeAliasAsForeignType(pub TypeAliasId); | ||
522 | |||
523 | impl ToChalk for TypeAliasAsForeignType { | ||
524 | type Chalk = ForeignDefId; | ||
525 | |||
526 | fn to_chalk(self, _db: &dyn HirDatabase) -> ForeignDefId { | ||
527 | chalk_ir::ForeignDefId(self.0.as_intern_id()) | ||
496 | } | 528 | } |
497 | 529 | ||
498 | fn from_chalk(_db: &dyn HirDatabase, type_alias_id: AssocTypeId) -> TypeAliasId { | 530 | fn from_chalk(_db: &dyn HirDatabase, foreign_def_id: ForeignDefId) -> TypeAliasAsForeignType { |
499 | InternKey::from_intern_id(type_alias_id.0) | 531 | TypeAliasAsForeignType(InternKey::from_intern_id(foreign_def_id.0)) |
500 | } | 532 | } |
501 | } | 533 | } |
502 | 534 | ||
@@ -580,7 +612,7 @@ impl ToChalk for ProjectionTy { | |||
580 | 612 | ||
581 | fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::ProjectionTy<Interner> { | 613 | fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::ProjectionTy<Interner> { |
582 | chalk_ir::ProjectionTy { | 614 | chalk_ir::ProjectionTy { |
583 | associated_ty_id: self.associated_ty.to_chalk(db), | 615 | associated_ty_id: TypeAliasAsAssocType(self.associated_ty).to_chalk(db), |
584 | substitution: self.parameters.to_chalk(db), | 616 | substitution: self.parameters.to_chalk(db), |
585 | } | 617 | } |
586 | } | 618 | } |
@@ -590,7 +622,11 @@ impl ToChalk for ProjectionTy { | |||
590 | projection_ty: chalk_ir::ProjectionTy<Interner>, | 622 | projection_ty: chalk_ir::ProjectionTy<Interner>, |
591 | ) -> ProjectionTy { | 623 | ) -> ProjectionTy { |
592 | ProjectionTy { | 624 | ProjectionTy { |
593 | associated_ty: from_chalk(db, projection_ty.associated_ty_id), | 625 | associated_ty: from_chalk::<TypeAliasAsAssocType, _>( |
626 | db, | ||
627 | projection_ty.associated_ty_id, | ||
628 | ) | ||
629 | .0, | ||
594 | parameters: from_chalk(db, projection_ty.substitution), | 630 | parameters: from_chalk(db, projection_ty.substitution), |
595 | } | 631 | } |
596 | } | 632 | } |
@@ -789,7 +825,8 @@ pub(super) fn generic_predicate_to_inline_bound( | |||
789 | let alias_eq_bound = rust_ir::AliasEqBound { | 825 | let alias_eq_bound = rust_ir::AliasEqBound { |
790 | value: proj.ty.clone().to_chalk(db), | 826 | value: proj.ty.clone().to_chalk(db), |
791 | trait_bound: rust_ir::TraitBound { trait_id: trait_.to_chalk(db), args_no_self }, | 827 | trait_bound: rust_ir::TraitBound { trait_id: trait_.to_chalk(db), args_no_self }, |
792 | associated_ty_id: proj.projection_ty.associated_ty.to_chalk(db), | 828 | associated_ty_id: TypeAliasAsAssocType(proj.projection_ty.associated_ty) |
829 | .to_chalk(db), | ||
793 | parameters: Vec::new(), // FIXME we don't support generic associated types yet | 830 | parameters: Vec::new(), // FIXME we don't support generic associated types yet |
794 | }; | 831 | }; |
795 | Some(rust_ir::InlineBound::AliasEqBound(alias_eq_bound)) | 832 | Some(rust_ir::InlineBound::AliasEqBound(alias_eq_bound)) |
diff --git a/crates/hir_ty/src/traits/chalk/tls.rs b/crates/hir_ty/src/traits/chalk/tls.rs index cb6b0fe81..b4568cff6 100644 --- a/crates/hir_ty/src/traits/chalk/tls.rs +++ b/crates/hir_ty/src/traits/chalk/tls.rs | |||
@@ -4,7 +4,7 @@ use std::fmt; | |||
4 | use chalk_ir::{AliasTy, GenericArg, Goal, Goals, Lifetime, ProgramClauseImplication, TypeName}; | 4 | use chalk_ir::{AliasTy, GenericArg, Goal, Goals, Lifetime, ProgramClauseImplication, TypeName}; |
5 | use itertools::Itertools; | 5 | use itertools::Itertools; |
6 | 6 | ||
7 | use super::{from_chalk, Interner}; | 7 | use super::{from_chalk, Interner, TypeAliasAsAssocType}; |
8 | use crate::{db::HirDatabase, CallableDefId, TypeCtor}; | 8 | use crate::{db::HirDatabase, CallableDefId, TypeCtor}; |
9 | use hir_def::{AdtId, AssocContainerId, DefWithBodyId, Lookup, TypeAliasId}; | 9 | use hir_def::{AdtId, AssocContainerId, DefWithBodyId, Lookup, TypeAliasId}; |
10 | 10 | ||
@@ -77,6 +77,10 @@ impl DebugContext<'_> { | |||
77 | write!(f, "{{impl trait of async block {} of {:?}}}", idx.into_raw(), def)?; | 77 | write!(f, "{{impl trait of async block {} of {:?}}}", idx.into_raw(), def)?; |
78 | } | 78 | } |
79 | }, | 79 | }, |
80 | TypeCtor::ForeignType(type_alias) => { | ||
81 | let name = self.0.type_alias_data(type_alias).name.clone(); | ||
82 | write!(f, "{}", name)?; | ||
83 | } | ||
80 | TypeCtor::Closure { def, expr } => { | 84 | TypeCtor::Closure { def, expr } => { |
81 | write!(f, "{{closure {:?} in ", expr.into_raw())?; | 85 | write!(f, "{{closure {:?} in ", expr.into_raw())?; |
82 | match def { | 86 | match def { |
@@ -119,7 +123,7 @@ impl DebugContext<'_> { | |||
119 | id: super::AssocTypeId, | 123 | id: super::AssocTypeId, |
120 | fmt: &mut fmt::Formatter<'_>, | 124 | fmt: &mut fmt::Formatter<'_>, |
121 | ) -> Result<(), fmt::Error> { | 125 | ) -> Result<(), fmt::Error> { |
122 | let type_alias: TypeAliasId = from_chalk(self.0, id); | 126 | let type_alias: TypeAliasId = from_chalk::<TypeAliasAsAssocType, _>(self.0, id).0; |
123 | let type_alias_data = self.0.type_alias_data(type_alias); | 127 | let type_alias_data = self.0.type_alias_data(type_alias); |
124 | let trait_ = match type_alias.lookup(self.0.upcast()).container { | 128 | let trait_ = match type_alias.lookup(self.0.upcast()).container { |
125 | AssocContainerId::TraitId(t) => t, | 129 | AssocContainerId::TraitId(t) => t, |
@@ -153,7 +157,8 @@ impl DebugContext<'_> { | |||
153 | projection_ty: &chalk_ir::ProjectionTy<Interner>, | 157 | projection_ty: &chalk_ir::ProjectionTy<Interner>, |
154 | fmt: &mut fmt::Formatter<'_>, | 158 | fmt: &mut fmt::Formatter<'_>, |
155 | ) -> Result<(), fmt::Error> { | 159 | ) -> Result<(), fmt::Error> { |
156 | let type_alias: TypeAliasId = from_chalk(self.0, projection_ty.associated_ty_id); | 160 | let type_alias: TypeAliasId = |
161 | from_chalk::<TypeAliasAsAssocType, _>(self.0, projection_ty.associated_ty_id).0; | ||
157 | let type_alias_data = self.0.type_alias_data(type_alias); | 162 | let type_alias_data = self.0.type_alias_data(type_alias); |
158 | let trait_ = match type_alias.lookup(self.0.upcast()).container { | 163 | let trait_ = match type_alias.lookup(self.0.upcast()).container { |
159 | AssocContainerId::TraitId(t) => t, | 164 | AssocContainerId::TraitId(t) => t, |