diff options
Diffstat (limited to 'crates/hir_ty/src/traits/chalk')
-rw-r--r-- | crates/hir_ty/src/traits/chalk/interner.rs | 2 | ||||
-rw-r--r-- | crates/hir_ty/src/traits/chalk/mapping.rs | 202 | ||||
-rw-r--r-- | crates/hir_ty/src/traits/chalk/tls.rs | 9 |
3 files changed, 67 insertions, 146 deletions
diff --git a/crates/hir_ty/src/traits/chalk/interner.rs b/crates/hir_ty/src/traits/chalk/interner.rs index 54bd1c724..1dc3f497d 100644 --- a/crates/hir_ty/src/traits/chalk/interner.rs +++ b/crates/hir_ty/src/traits/chalk/interner.rs | |||
@@ -12,7 +12,6 @@ pub struct Interner; | |||
12 | 12 | ||
13 | pub(crate) type AssocTypeId = chalk_ir::AssocTypeId<Interner>; | 13 | pub(crate) type AssocTypeId = chalk_ir::AssocTypeId<Interner>; |
14 | pub(crate) type AssociatedTyDatum = chalk_solve::rust_ir::AssociatedTyDatum<Interner>; | 14 | pub(crate) type AssociatedTyDatum = chalk_solve::rust_ir::AssociatedTyDatum<Interner>; |
15 | pub(crate) type ForeignDefId = chalk_ir::ForeignDefId<Interner>; | ||
16 | pub(crate) type TraitId = chalk_ir::TraitId<Interner>; | 15 | pub(crate) type TraitId = chalk_ir::TraitId<Interner>; |
17 | pub(crate) type TraitDatum = chalk_solve::rust_ir::TraitDatum<Interner>; | 16 | pub(crate) type TraitDatum = chalk_solve::rust_ir::TraitDatum<Interner>; |
18 | pub(crate) type AdtId = chalk_ir::AdtId<Interner>; | 17 | pub(crate) type AdtId = chalk_ir::AdtId<Interner>; |
@@ -21,7 +20,6 @@ pub(crate) type ImplId = chalk_ir::ImplId<Interner>; | |||
21 | pub(crate) type ImplDatum = chalk_solve::rust_ir::ImplDatum<Interner>; | 20 | pub(crate) type ImplDatum = chalk_solve::rust_ir::ImplDatum<Interner>; |
22 | pub(crate) type AssociatedTyValueId = chalk_solve::rust_ir::AssociatedTyValueId<Interner>; | 21 | pub(crate) type AssociatedTyValueId = chalk_solve::rust_ir::AssociatedTyValueId<Interner>; |
23 | pub(crate) type AssociatedTyValue = chalk_solve::rust_ir::AssociatedTyValue<Interner>; | 22 | pub(crate) type AssociatedTyValue = chalk_solve::rust_ir::AssociatedTyValue<Interner>; |
24 | pub(crate) type FnDefId = chalk_ir::FnDefId<Interner>; | ||
25 | pub(crate) type FnDefDatum = chalk_solve::rust_ir::FnDefDatum<Interner>; | 23 | pub(crate) type FnDefDatum = chalk_solve::rust_ir::FnDefDatum<Interner>; |
26 | pub(crate) type OpaqueTyId = chalk_ir::OpaqueTyId<Interner>; | 24 | pub(crate) type OpaqueTyId = chalk_ir::OpaqueTyId<Interner>; |
27 | pub(crate) type OpaqueTyDatum = chalk_solve::rust_ir::OpaqueTyDatum<Interner>; | 25 | pub(crate) type OpaqueTyDatum = chalk_solve::rust_ir::OpaqueTyDatum<Interner>; |
diff --git a/crates/hir_ty/src/traits/chalk/mapping.rs b/crates/hir_ty/src/traits/chalk/mapping.rs index b0415e8b0..2a66a2310 100644 --- a/crates/hir_ty/src/traits/chalk/mapping.rs +++ b/crates/hir_ty/src/traits/chalk/mapping.rs | |||
@@ -3,10 +3,7 @@ | |||
3 | //! Chalk (in both directions); plus some helper functions for more specialized | 3 | //! Chalk (in both directions); plus some helper functions for more specialized |
4 | //! conversions. | 4 | //! conversions. |
5 | 5 | ||
6 | use chalk_ir::{ | 6 | use chalk_ir::{cast::Cast, fold::shift::Shift, interner::HasInterner, LifetimeData}; |
7 | cast::Cast, fold::shift::Shift, interner::HasInterner, LifetimeData, PlaceholderIndex, | ||
8 | UniverseIndex, | ||
9 | }; | ||
10 | use chalk_solve::rust_ir; | 7 | use chalk_solve::rust_ir; |
11 | 8 | ||
12 | use base_db::salsa::InternKey; | 9 | use base_db::salsa::InternKey; |
@@ -14,10 +11,11 @@ use hir_def::{AssocContainerId, GenericDefId, Lookup, TypeAliasId}; | |||
14 | 11 | ||
15 | use crate::{ | 12 | use crate::{ |
16 | db::HirDatabase, | 13 | db::HirDatabase, |
14 | from_assoc_type_id, | ||
17 | primitive::UintTy, | 15 | primitive::UintTy, |
18 | traits::{Canonical, Obligation}, | 16 | traits::{Canonical, Obligation}, |
19 | AliasTy, CallableDefId, FnPointer, FnSig, GenericPredicate, InEnvironment, OpaqueTy, | 17 | AliasTy, CallableDefId, FnPointer, FnSig, GenericPredicate, InEnvironment, OpaqueTy, |
20 | OpaqueTyId, ProjectionPredicate, ProjectionTy, Scalar, Substs, TraitRef, Ty, | 18 | ProjectionPredicate, ProjectionTy, Scalar, Substs, TraitRef, Ty, |
21 | }; | 19 | }; |
22 | 20 | ||
23 | use super::interner::*; | 21 | use super::interner::*; |
@@ -26,10 +24,10 @@ use super::*; | |||
26 | impl ToChalk for Ty { | 24 | impl ToChalk for Ty { |
27 | type Chalk = chalk_ir::Ty<Interner>; | 25 | type Chalk = chalk_ir::Ty<Interner>; |
28 | fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::Ty<Interner> { | 26 | fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::Ty<Interner> { |
29 | match self { | 27 | match self.0 { |
30 | Ty::Ref(m, parameters) => ref_to_chalk(db, m, parameters), | 28 | TyKind::Ref(m, parameters) => ref_to_chalk(db, m, parameters), |
31 | Ty::Array(parameters) => array_to_chalk(db, parameters), | 29 | TyKind::Array(parameters) => array_to_chalk(db, parameters), |
32 | Ty::Function(FnPointer { sig: FnSig { variadic }, substs, .. }) => { | 30 | TyKind::Function(FnPointer { sig: FnSig { variadic }, substs, .. }) => { |
33 | let substitution = chalk_ir::FnSubst(substs.to_chalk(db).shifted_in(&Interner)); | 31 | let substitution = chalk_ir::FnSubst(substs.to_chalk(db).shifted_in(&Interner)); |
34 | chalk_ir::TyKind::Function(chalk_ir::FnPointer { | 32 | chalk_ir::TyKind::Function(chalk_ir::FnPointer { |
35 | num_binders: 0, | 33 | num_binders: 0, |
@@ -38,58 +36,49 @@ impl ToChalk for Ty { | |||
38 | }) | 36 | }) |
39 | .intern(&Interner) | 37 | .intern(&Interner) |
40 | } | 38 | } |
41 | Ty::AssociatedType(type_alias, substs) => { | 39 | TyKind::AssociatedType(assoc_type_id, substs) => { |
42 | let assoc_type = TypeAliasAsAssocType(type_alias); | ||
43 | let assoc_type_id = assoc_type.to_chalk(db); | ||
44 | let substitution = substs.to_chalk(db); | 40 | let substitution = substs.to_chalk(db); |
45 | chalk_ir::TyKind::AssociatedType(assoc_type_id, substitution).intern(&Interner) | 41 | chalk_ir::TyKind::AssociatedType(assoc_type_id, substitution).intern(&Interner) |
46 | } | 42 | } |
47 | 43 | ||
48 | Ty::OpaqueType(impl_trait_id, substs) => { | 44 | TyKind::OpaqueType(id, substs) => { |
49 | let id = impl_trait_id.to_chalk(db); | ||
50 | let substitution = substs.to_chalk(db); | 45 | let substitution = substs.to_chalk(db); |
51 | chalk_ir::TyKind::OpaqueType(id, substitution).intern(&Interner) | 46 | chalk_ir::TyKind::OpaqueType(id, substitution).intern(&Interner) |
52 | } | 47 | } |
53 | 48 | ||
54 | Ty::ForeignType(type_alias) => { | 49 | TyKind::ForeignType(id) => chalk_ir::TyKind::Foreign(id).intern(&Interner), |
55 | let foreign_type = TypeAliasAsForeignType(type_alias); | ||
56 | let foreign_type_id = foreign_type.to_chalk(db); | ||
57 | chalk_ir::TyKind::Foreign(foreign_type_id).intern(&Interner) | ||
58 | } | ||
59 | 50 | ||
60 | Ty::Scalar(scalar) => chalk_ir::TyKind::Scalar(scalar).intern(&Interner), | 51 | TyKind::Scalar(scalar) => chalk_ir::TyKind::Scalar(scalar).intern(&Interner), |
61 | 52 | ||
62 | Ty::Tuple(cardinality, substs) => { | 53 | TyKind::Tuple(cardinality, substs) => { |
63 | let substitution = substs.to_chalk(db); | 54 | let substitution = substs.to_chalk(db); |
64 | chalk_ir::TyKind::Tuple(cardinality.into(), substitution).intern(&Interner) | 55 | chalk_ir::TyKind::Tuple(cardinality.into(), substitution).intern(&Interner) |
65 | } | 56 | } |
66 | Ty::Raw(mutability, substs) => { | 57 | TyKind::Raw(mutability, substs) => { |
67 | let ty = substs[0].clone().to_chalk(db); | 58 | let ty = substs[0].clone().to_chalk(db); |
68 | chalk_ir::TyKind::Raw(mutability, ty).intern(&Interner) | 59 | chalk_ir::TyKind::Raw(mutability, ty).intern(&Interner) |
69 | } | 60 | } |
70 | Ty::Slice(substs) => { | 61 | TyKind::Slice(substs) => { |
71 | chalk_ir::TyKind::Slice(substs[0].clone().to_chalk(db)).intern(&Interner) | 62 | chalk_ir::TyKind::Slice(substs[0].clone().to_chalk(db)).intern(&Interner) |
72 | } | 63 | } |
73 | Ty::Str => chalk_ir::TyKind::Str.intern(&Interner), | 64 | TyKind::Str => chalk_ir::TyKind::Str.intern(&Interner), |
74 | Ty::FnDef(callable_def, substs) => { | 65 | TyKind::FnDef(id, substs) => { |
75 | let id = callable_def.to_chalk(db); | ||
76 | let substitution = substs.to_chalk(db); | 66 | let substitution = substs.to_chalk(db); |
77 | chalk_ir::TyKind::FnDef(id, substitution).intern(&Interner) | 67 | chalk_ir::TyKind::FnDef(id, substitution).intern(&Interner) |
78 | } | 68 | } |
79 | Ty::Never => chalk_ir::TyKind::Never.intern(&Interner), | 69 | TyKind::Never => chalk_ir::TyKind::Never.intern(&Interner), |
80 | 70 | ||
81 | Ty::Closure(def, expr, substs) => { | 71 | TyKind::Closure(closure_id, substs) => { |
82 | let closure_id = db.intern_closure((def, expr)); | ||
83 | let substitution = substs.to_chalk(db); | 72 | let substitution = substs.to_chalk(db); |
84 | chalk_ir::TyKind::Closure(closure_id.into(), substitution).intern(&Interner) | 73 | chalk_ir::TyKind::Closure(closure_id, substitution).intern(&Interner) |
85 | } | 74 | } |
86 | 75 | ||
87 | Ty::Adt(adt_id, substs) => { | 76 | TyKind::Adt(adt_id, substs) => { |
88 | let substitution = substs.to_chalk(db); | 77 | let substitution = substs.to_chalk(db); |
89 | chalk_ir::TyKind::Adt(adt_id, substitution).intern(&Interner) | 78 | chalk_ir::TyKind::Adt(adt_id, substitution).intern(&Interner) |
90 | } | 79 | } |
91 | Ty::Alias(AliasTy::Projection(proj_ty)) => { | 80 | TyKind::Alias(AliasTy::Projection(proj_ty)) => { |
92 | let associated_ty_id = TypeAliasAsAssocType(proj_ty.associated_ty).to_chalk(db); | 81 | let associated_ty_id = proj_ty.associated_ty; |
93 | let substitution = proj_ty.parameters.to_chalk(db); | 82 | let substitution = proj_ty.parameters.to_chalk(db); |
94 | chalk_ir::AliasTy::Projection(chalk_ir::ProjectionTy { | 83 | chalk_ir::AliasTy::Projection(chalk_ir::ProjectionTy { |
95 | associated_ty_id, | 84 | associated_ty_id, |
@@ -98,17 +87,10 @@ impl ToChalk for Ty { | |||
98 | .cast(&Interner) | 87 | .cast(&Interner) |
99 | .intern(&Interner) | 88 | .intern(&Interner) |
100 | } | 89 | } |
101 | Ty::Placeholder(id) => { | 90 | TyKind::Placeholder(idx) => idx.to_ty::<Interner>(&Interner), |
102 | let interned_id = db.intern_type_param_id(id); | 91 | TyKind::BoundVar(idx) => chalk_ir::TyKind::BoundVar(idx).intern(&Interner), |
103 | PlaceholderIndex { | 92 | TyKind::InferenceVar(..) => panic!("uncanonicalized infer ty"), |
104 | ui: UniverseIndex::ROOT, | 93 | TyKind::Dyn(predicates) => { |
105 | idx: interned_id.as_intern_id().as_usize(), | ||
106 | } | ||
107 | .to_ty::<Interner>(&Interner) | ||
108 | } | ||
109 | Ty::BoundVar(idx) => chalk_ir::TyKind::BoundVar(idx).intern(&Interner), | ||
110 | Ty::InferenceVar(..) => panic!("uncanonicalized infer ty"), | ||
111 | Ty::Dyn(predicates) => { | ||
112 | let where_clauses = chalk_ir::QuantifiedWhereClauses::from_iter( | 94 | let where_clauses = chalk_ir::QuantifiedWhereClauses::from_iter( |
113 | &Interner, | 95 | &Interner, |
114 | predicates.iter().filter(|p| !p.is_error()).cloned().map(|p| p.to_chalk(db)), | 96 | predicates.iter().filter(|p| !p.is_error()).cloned().map(|p| p.to_chalk(db)), |
@@ -119,8 +101,8 @@ impl ToChalk for Ty { | |||
119 | }; | 101 | }; |
120 | chalk_ir::TyKind::Dyn(bounded_ty).intern(&Interner) | 102 | chalk_ir::TyKind::Dyn(bounded_ty).intern(&Interner) |
121 | } | 103 | } |
122 | Ty::Alias(AliasTy::Opaque(opaque_ty)) => { | 104 | TyKind::Alias(AliasTy::Opaque(opaque_ty)) => { |
123 | let opaque_ty_id = opaque_ty.opaque_ty_id.to_chalk(db); | 105 | let opaque_ty_id = opaque_ty.opaque_ty_id; |
124 | let substitution = opaque_ty.parameters.to_chalk(db); | 106 | let substitution = opaque_ty.parameters.to_chalk(db); |
125 | chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Opaque(chalk_ir::OpaqueTy { | 107 | chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Opaque(chalk_ir::OpaqueTy { |
126 | opaque_ty_id, | 108 | opaque_ty_id, |
@@ -128,30 +110,23 @@ impl ToChalk for Ty { | |||
128 | })) | 110 | })) |
129 | .intern(&Interner) | 111 | .intern(&Interner) |
130 | } | 112 | } |
131 | Ty::Unknown => chalk_ir::TyKind::Error.intern(&Interner), | 113 | TyKind::Unknown => chalk_ir::TyKind::Error.intern(&Interner), |
132 | } | 114 | } |
133 | } | 115 | } |
134 | fn from_chalk(db: &dyn HirDatabase, chalk: chalk_ir::Ty<Interner>) -> Self { | 116 | fn from_chalk(db: &dyn HirDatabase, chalk: chalk_ir::Ty<Interner>) -> Self { |
135 | match chalk.data(&Interner).kind.clone() { | 117 | match chalk.data(&Interner).kind.clone() { |
136 | chalk_ir::TyKind::Error => Ty::Unknown, | 118 | chalk_ir::TyKind::Error => TyKind::Unknown, |
137 | chalk_ir::TyKind::Array(ty, _size) => Ty::Array(Substs::single(from_chalk(db, ty))), | 119 | chalk_ir::TyKind::Array(ty, _size) => TyKind::Array(Substs::single(from_chalk(db, ty))), |
138 | chalk_ir::TyKind::Placeholder(idx) => { | 120 | chalk_ir::TyKind::Placeholder(idx) => TyKind::Placeholder(idx), |
139 | assert_eq!(idx.ui, UniverseIndex::ROOT); | ||
140 | let interned_id = crate::db::GlobalTypeParamId::from_intern_id( | ||
141 | crate::salsa::InternId::from(idx.idx), | ||
142 | ); | ||
143 | Ty::Placeholder(db.lookup_intern_type_param_id(interned_id)) | ||
144 | } | ||
145 | chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Projection(proj)) => { | 121 | chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Projection(proj)) => { |
146 | let associated_ty = | 122 | let associated_ty = proj.associated_ty_id; |
147 | from_chalk::<TypeAliasAsAssocType, _>(db, proj.associated_ty_id).0; | ||
148 | let parameters = from_chalk(db, proj.substitution); | 123 | let parameters = from_chalk(db, proj.substitution); |
149 | Ty::Alias(AliasTy::Projection(ProjectionTy { associated_ty, parameters })) | 124 | TyKind::Alias(AliasTy::Projection(ProjectionTy { associated_ty, parameters })) |
150 | } | 125 | } |
151 | chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Opaque(opaque_ty)) => { | 126 | chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Opaque(opaque_ty)) => { |
152 | let impl_trait_id = from_chalk(db, opaque_ty.opaque_ty_id); | 127 | let opaque_ty_id = opaque_ty.opaque_ty_id; |
153 | let parameters = from_chalk(db, opaque_ty.substitution); | 128 | let parameters = from_chalk(db, opaque_ty.substitution); |
154 | Ty::Alias(AliasTy::Opaque(OpaqueTy { opaque_ty_id: impl_trait_id, parameters })) | 129 | TyKind::Alias(AliasTy::Opaque(OpaqueTy { opaque_ty_id, parameters })) |
155 | } | 130 | } |
156 | chalk_ir::TyKind::Function(chalk_ir::FnPointer { | 131 | chalk_ir::TyKind::Function(chalk_ir::FnPointer { |
157 | num_binders, | 132 | num_binders, |
@@ -164,14 +139,14 @@ impl ToChalk for Ty { | |||
164 | db, | 139 | db, |
165 | substitution.0.shifted_out(&Interner).expect("fn ptr should have no binders"), | 140 | substitution.0.shifted_out(&Interner).expect("fn ptr should have no binders"), |
166 | ); | 141 | ); |
167 | Ty::Function(FnPointer { | 142 | TyKind::Function(FnPointer { |
168 | num_args: (substs.len() - 1), | 143 | num_args: (substs.len() - 1), |
169 | sig: FnSig { variadic }, | 144 | sig: FnSig { variadic }, |
170 | substs, | 145 | substs, |
171 | }) | 146 | }) |
172 | } | 147 | } |
173 | chalk_ir::TyKind::BoundVar(idx) => Ty::BoundVar(idx), | 148 | chalk_ir::TyKind::BoundVar(idx) => TyKind::BoundVar(idx), |
174 | chalk_ir::TyKind::InferenceVar(_iv, _kind) => Ty::Unknown, | 149 | chalk_ir::TyKind::InferenceVar(_iv, _kind) => TyKind::Unknown, |
175 | chalk_ir::TyKind::Dyn(where_clauses) => { | 150 | chalk_ir::TyKind::Dyn(where_clauses) => { |
176 | assert_eq!(where_clauses.bounds.binders.len(&Interner), 1); | 151 | assert_eq!(where_clauses.bounds.binders.len(&Interner), 1); |
177 | let predicates = where_clauses | 152 | let predicates = where_clauses |
@@ -180,49 +155,43 @@ impl ToChalk for Ty { | |||
180 | .iter(&Interner) | 155 | .iter(&Interner) |
181 | .map(|c| from_chalk(db, c.clone())) | 156 | .map(|c| from_chalk(db, c.clone())) |
182 | .collect(); | 157 | .collect(); |
183 | Ty::Dyn(predicates) | 158 | TyKind::Dyn(predicates) |
184 | } | 159 | } |
185 | 160 | ||
186 | chalk_ir::TyKind::Adt(adt_id, subst) => Ty::Adt(adt_id, from_chalk(db, subst)), | 161 | chalk_ir::TyKind::Adt(adt_id, subst) => TyKind::Adt(adt_id, from_chalk(db, subst)), |
187 | chalk_ir::TyKind::AssociatedType(type_id, subst) => Ty::AssociatedType( | 162 | chalk_ir::TyKind::AssociatedType(type_id, subst) => { |
188 | from_chalk::<TypeAliasAsAssocType, _>(db, type_id).0, | 163 | TyKind::AssociatedType(type_id, from_chalk(db, subst)) |
189 | from_chalk(db, subst), | 164 | } |
190 | ), | ||
191 | 165 | ||
192 | chalk_ir::TyKind::OpaqueType(opaque_type_id, subst) => { | 166 | chalk_ir::TyKind::OpaqueType(opaque_type_id, subst) => { |
193 | Ty::OpaqueType(from_chalk(db, opaque_type_id), from_chalk(db, subst)) | 167 | TyKind::OpaqueType(opaque_type_id, from_chalk(db, subst)) |
194 | } | 168 | } |
195 | 169 | ||
196 | chalk_ir::TyKind::Scalar(scalar) => Ty::Scalar(scalar), | 170 | chalk_ir::TyKind::Scalar(scalar) => TyKind::Scalar(scalar), |
197 | chalk_ir::TyKind::Tuple(cardinality, subst) => { | 171 | chalk_ir::TyKind::Tuple(cardinality, subst) => { |
198 | Ty::Tuple(cardinality, from_chalk(db, subst)) | 172 | TyKind::Tuple(cardinality, from_chalk(db, subst)) |
199 | } | 173 | } |
200 | chalk_ir::TyKind::Raw(mutability, ty) => { | 174 | chalk_ir::TyKind::Raw(mutability, ty) => { |
201 | Ty::Raw(mutability, Substs::single(from_chalk(db, ty))) | 175 | TyKind::Raw(mutability, Substs::single(from_chalk(db, ty))) |
202 | } | 176 | } |
203 | chalk_ir::TyKind::Slice(ty) => Ty::Slice(Substs::single(from_chalk(db, ty))), | 177 | chalk_ir::TyKind::Slice(ty) => TyKind::Slice(Substs::single(from_chalk(db, ty))), |
204 | chalk_ir::TyKind::Ref(mutability, _lifetime, ty) => { | 178 | chalk_ir::TyKind::Ref(mutability, _lifetime, ty) => { |
205 | Ty::Ref(mutability, Substs::single(from_chalk(db, ty))) | 179 | TyKind::Ref(mutability, Substs::single(from_chalk(db, ty))) |
206 | } | 180 | } |
207 | chalk_ir::TyKind::Str => Ty::Str, | 181 | chalk_ir::TyKind::Str => TyKind::Str, |
208 | chalk_ir::TyKind::Never => Ty::Never, | 182 | chalk_ir::TyKind::Never => TyKind::Never, |
209 | 183 | ||
210 | chalk_ir::TyKind::FnDef(fn_def_id, subst) => { | 184 | chalk_ir::TyKind::FnDef(fn_def_id, subst) => { |
211 | Ty::FnDef(from_chalk(db, fn_def_id), from_chalk(db, subst)) | 185 | TyKind::FnDef(fn_def_id, from_chalk(db, subst)) |
212 | } | 186 | } |
213 | 187 | ||
214 | chalk_ir::TyKind::Closure(id, subst) => { | 188 | chalk_ir::TyKind::Closure(id, subst) => TyKind::Closure(id, from_chalk(db, subst)), |
215 | let id: crate::db::ClosureId = id.into(); | ||
216 | let (def, expr) = db.lookup_intern_closure(id); | ||
217 | Ty::Closure(def, expr, from_chalk(db, subst)) | ||
218 | } | ||
219 | 189 | ||
220 | chalk_ir::TyKind::Foreign(foreign_def_id) => { | 190 | chalk_ir::TyKind::Foreign(foreign_def_id) => TyKind::ForeignType(foreign_def_id), |
221 | Ty::ForeignType(from_chalk::<TypeAliasAsForeignType, _>(db, foreign_def_id).0) | ||
222 | } | ||
223 | chalk_ir::TyKind::Generator(_, _) => unimplemented!(), // FIXME | 191 | chalk_ir::TyKind::Generator(_, _) => unimplemented!(), // FIXME |
224 | chalk_ir::TyKind::GeneratorWitness(_, _) => unimplemented!(), // FIXME | 192 | chalk_ir::TyKind::GeneratorWitness(_, _) => unimplemented!(), // FIXME |
225 | } | 193 | } |
194 | .intern(&Interner) | ||
226 | } | 195 | } |
227 | } | 196 | } |
228 | 197 | ||
@@ -298,21 +267,6 @@ impl ToChalk for hir_def::TraitId { | |||
298 | } | 267 | } |
299 | } | 268 | } |
300 | 269 | ||
301 | impl ToChalk for OpaqueTyId { | ||
302 | type Chalk = chalk_ir::OpaqueTyId<Interner>; | ||
303 | |||
304 | fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::OpaqueTyId<Interner> { | ||
305 | db.intern_impl_trait_id(self).into() | ||
306 | } | ||
307 | |||
308 | fn from_chalk( | ||
309 | db: &dyn HirDatabase, | ||
310 | opaque_ty_id: chalk_ir::OpaqueTyId<Interner>, | ||
311 | ) -> OpaqueTyId { | ||
312 | db.lookup_intern_impl_trait_id(opaque_ty_id.into()) | ||
313 | } | ||
314 | } | ||
315 | |||
316 | impl ToChalk for hir_def::ImplId { | 270 | impl ToChalk for hir_def::ImplId { |
317 | type Chalk = ImplId; | 271 | type Chalk = ImplId; |
318 | 272 | ||
@@ -337,34 +291,6 @@ impl ToChalk for CallableDefId { | |||
337 | } | 291 | } |
338 | } | 292 | } |
339 | 293 | ||
340 | pub(crate) struct TypeAliasAsAssocType(pub(crate) TypeAliasId); | ||
341 | |||
342 | impl ToChalk for TypeAliasAsAssocType { | ||
343 | type Chalk = AssocTypeId; | ||
344 | |||
345 | fn to_chalk(self, _db: &dyn HirDatabase) -> AssocTypeId { | ||
346 | chalk_ir::AssocTypeId(self.0.as_intern_id()) | ||
347 | } | ||
348 | |||
349 | fn from_chalk(_db: &dyn HirDatabase, assoc_type_id: AssocTypeId) -> TypeAliasAsAssocType { | ||
350 | TypeAliasAsAssocType(InternKey::from_intern_id(assoc_type_id.0)) | ||
351 | } | ||
352 | } | ||
353 | |||
354 | pub(crate) struct TypeAliasAsForeignType(pub(crate) TypeAliasId); | ||
355 | |||
356 | impl ToChalk for TypeAliasAsForeignType { | ||
357 | type Chalk = ForeignDefId; | ||
358 | |||
359 | fn to_chalk(self, _db: &dyn HirDatabase) -> ForeignDefId { | ||
360 | chalk_ir::ForeignDefId(self.0.as_intern_id()) | ||
361 | } | ||
362 | |||
363 | fn from_chalk(_db: &dyn HirDatabase, foreign_def_id: ForeignDefId) -> TypeAliasAsForeignType { | ||
364 | TypeAliasAsForeignType(InternKey::from_intern_id(foreign_def_id.0)) | ||
365 | } | ||
366 | } | ||
367 | |||
368 | pub(crate) struct TypeAliasAsValue(pub(crate) TypeAliasId); | 294 | pub(crate) struct TypeAliasAsValue(pub(crate) TypeAliasId); |
369 | 295 | ||
370 | impl ToChalk for TypeAliasAsValue { | 296 | impl ToChalk for TypeAliasAsValue { |
@@ -446,7 +372,7 @@ impl ToChalk for ProjectionTy { | |||
446 | 372 | ||
447 | fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::ProjectionTy<Interner> { | 373 | fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::ProjectionTy<Interner> { |
448 | chalk_ir::ProjectionTy { | 374 | chalk_ir::ProjectionTy { |
449 | associated_ty_id: TypeAliasAsAssocType(self.associated_ty).to_chalk(db), | 375 | associated_ty_id: self.associated_ty, |
450 | substitution: self.parameters.to_chalk(db), | 376 | substitution: self.parameters.to_chalk(db), |
451 | } | 377 | } |
452 | } | 378 | } |
@@ -456,11 +382,7 @@ impl ToChalk for ProjectionTy { | |||
456 | projection_ty: chalk_ir::ProjectionTy<Interner>, | 382 | projection_ty: chalk_ir::ProjectionTy<Interner>, |
457 | ) -> ProjectionTy { | 383 | ) -> ProjectionTy { |
458 | ProjectionTy { | 384 | ProjectionTy { |
459 | associated_ty: from_chalk::<TypeAliasAsAssocType, _>( | 385 | associated_ty: projection_ty.associated_ty_id, |
460 | db, | ||
461 | projection_ty.associated_ty_id, | ||
462 | ) | ||
463 | .0, | ||
464 | parameters: from_chalk(db, projection_ty.substitution), | 386 | parameters: from_chalk(db, projection_ty.substitution), |
465 | } | 387 | } |
466 | } | 388 | } |
@@ -614,7 +536,10 @@ pub(super) fn generic_predicate_to_inline_bound( | |||
614 | if &proj.projection_ty.parameters[0] != self_ty { | 536 | if &proj.projection_ty.parameters[0] != self_ty { |
615 | return None; | 537 | return None; |
616 | } | 538 | } |
617 | let trait_ = match proj.projection_ty.associated_ty.lookup(db.upcast()).container { | 539 | let trait_ = match from_assoc_type_id(proj.projection_ty.associated_ty) |
540 | .lookup(db.upcast()) | ||
541 | .container | ||
542 | { | ||
618 | AssocContainerId::TraitId(t) => t, | 543 | AssocContainerId::TraitId(t) => t, |
619 | _ => panic!("associated type not in trait"), | 544 | _ => panic!("associated type not in trait"), |
620 | }; | 545 | }; |
@@ -625,8 +550,7 @@ pub(super) fn generic_predicate_to_inline_bound( | |||
625 | let alias_eq_bound = rust_ir::AliasEqBound { | 550 | let alias_eq_bound = rust_ir::AliasEqBound { |
626 | value: proj.ty.clone().to_chalk(db), | 551 | value: proj.ty.clone().to_chalk(db), |
627 | trait_bound: rust_ir::TraitBound { trait_id: trait_.to_chalk(db), args_no_self }, | 552 | trait_bound: rust_ir::TraitBound { trait_id: trait_.to_chalk(db), args_no_self }, |
628 | associated_ty_id: TypeAliasAsAssocType(proj.projection_ty.associated_ty) | 553 | associated_ty_id: proj.projection_ty.associated_ty, |
629 | .to_chalk(db), | ||
630 | parameters: Vec::new(), // FIXME we don't support generic associated types yet | 554 | parameters: Vec::new(), // FIXME we don't support generic associated types yet |
631 | }; | 555 | }; |
632 | Some(rust_ir::InlineBound::AliasEqBound(alias_eq_bound)) | 556 | 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 75b16172e..8892a63a9 100644 --- a/crates/hir_ty/src/traits/chalk/tls.rs +++ b/crates/hir_ty/src/traits/chalk/tls.rs | |||
@@ -4,8 +4,8 @@ use std::fmt; | |||
4 | use chalk_ir::{AliasTy, GenericArg, Goal, Goals, Lifetime, ProgramClauseImplication}; | 4 | use chalk_ir::{AliasTy, GenericArg, Goal, Goals, Lifetime, ProgramClauseImplication}; |
5 | use itertools::Itertools; | 5 | use itertools::Itertools; |
6 | 6 | ||
7 | use super::{from_chalk, Interner, TypeAliasAsAssocType}; | 7 | use super::{from_chalk, Interner}; |
8 | use crate::{db::HirDatabase, CallableDefId}; | 8 | use crate::{db::HirDatabase, from_assoc_type_id, CallableDefId}; |
9 | use hir_def::{AdtId, AssocContainerId, Lookup, TypeAliasId}; | 9 | use hir_def::{AdtId, AssocContainerId, Lookup, TypeAliasId}; |
10 | 10 | ||
11 | pub(crate) use unsafe_tls::{set_current_program, with_current_program}; | 11 | pub(crate) use unsafe_tls::{set_current_program, with_current_program}; |
@@ -41,7 +41,7 @@ impl DebugContext<'_> { | |||
41 | id: super::AssocTypeId, | 41 | id: super::AssocTypeId, |
42 | fmt: &mut fmt::Formatter<'_>, | 42 | fmt: &mut fmt::Formatter<'_>, |
43 | ) -> Result<(), fmt::Error> { | 43 | ) -> Result<(), fmt::Error> { |
44 | let type_alias: TypeAliasId = from_chalk::<TypeAliasAsAssocType, _>(self.0, id).0; | 44 | let type_alias: TypeAliasId = from_assoc_type_id(id); |
45 | let type_alias_data = self.0.type_alias_data(type_alias); | 45 | let type_alias_data = self.0.type_alias_data(type_alias); |
46 | let trait_ = match type_alias.lookup(self.0.upcast()).container { | 46 | let trait_ = match type_alias.lookup(self.0.upcast()).container { |
47 | AssocContainerId::TraitId(t) => t, | 47 | AssocContainerId::TraitId(t) => t, |
@@ -75,8 +75,7 @@ impl DebugContext<'_> { | |||
75 | projection_ty: &chalk_ir::ProjectionTy<Interner>, | 75 | projection_ty: &chalk_ir::ProjectionTy<Interner>, |
76 | fmt: &mut fmt::Formatter<'_>, | 76 | fmt: &mut fmt::Formatter<'_>, |
77 | ) -> Result<(), fmt::Error> { | 77 | ) -> Result<(), fmt::Error> { |
78 | let type_alias: TypeAliasId = | 78 | let type_alias = from_assoc_type_id(projection_ty.associated_ty_id); |
79 | from_chalk::<TypeAliasAsAssocType, _>(self.0, projection_ty.associated_ty_id).0; | ||
80 | let type_alias_data = self.0.type_alias_data(type_alias); | 79 | let type_alias_data = self.0.type_alias_data(type_alias); |
81 | let trait_ = match type_alias.lookup(self.0.upcast()).container { | 80 | let trait_ = match type_alias.lookup(self.0.upcast()).container { |
82 | AssocContainerId::TraitId(t) => t, | 81 | AssocContainerId::TraitId(t) => t, |