diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-03-13 19:08:29 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2021-03-13 19:08:29 +0000 |
commit | 17eeb2a6d2ea81b302b6707c63bf8fba489c2bdd (patch) | |
tree | a2e152f5f16dd92f4c4be011be2399998dc7eb6f /crates/hir_ty/src/traits/chalk/mapping.rs | |
parent | be7a31fbd64943f71afe11b0413c99496526dddc (diff) | |
parent | b035c314b4b0ecd2477fde216dbe7e8801f94d0d (diff) |
Merge #8001
8001: More Chalk IDs r=flodiebold a=flodiebold
Co-authored-by: Florian Diebold <[email protected]>
Diffstat (limited to 'crates/hir_ty/src/traits/chalk/mapping.rs')
-rw-r--r-- | crates/hir_ty/src/traits/chalk/mapping.rs | 61 |
1 files changed, 12 insertions, 49 deletions
diff --git a/crates/hir_ty/src/traits/chalk/mapping.rs b/crates/hir_ty/src/traits/chalk/mapping.rs index 23ef07d77..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; |
@@ -18,7 +15,7 @@ use crate::{ | |||
18 | primitive::UintTy, | 15 | primitive::UintTy, |
19 | traits::{Canonical, Obligation}, | 16 | traits::{Canonical, Obligation}, |
20 | AliasTy, CallableDefId, FnPointer, FnSig, GenericPredicate, InEnvironment, OpaqueTy, | 17 | AliasTy, CallableDefId, FnPointer, FnSig, GenericPredicate, InEnvironment, OpaqueTy, |
21 | OpaqueTyId, ProjectionPredicate, ProjectionTy, Scalar, Substs, TraitRef, Ty, | 18 | ProjectionPredicate, ProjectionTy, Scalar, Substs, TraitRef, Ty, |
22 | }; | 19 | }; |
23 | 20 | ||
24 | use super::interner::*; | 21 | use super::interner::*; |
@@ -44,8 +41,7 @@ impl ToChalk for Ty { | |||
44 | chalk_ir::TyKind::AssociatedType(assoc_type_id, substitution).intern(&Interner) | 41 | chalk_ir::TyKind::AssociatedType(assoc_type_id, substitution).intern(&Interner) |
45 | } | 42 | } |
46 | 43 | ||
47 | TyKind::OpaqueType(impl_trait_id, substs) => { | 44 | TyKind::OpaqueType(id, substs) => { |
48 | let id = impl_trait_id.to_chalk(db); | ||
49 | let substitution = substs.to_chalk(db); | 45 | let substitution = substs.to_chalk(db); |
50 | chalk_ir::TyKind::OpaqueType(id, substitution).intern(&Interner) | 46 | chalk_ir::TyKind::OpaqueType(id, substitution).intern(&Interner) |
51 | } | 47 | } |
@@ -72,10 +68,9 @@ impl ToChalk for Ty { | |||
72 | } | 68 | } |
73 | TyKind::Never => chalk_ir::TyKind::Never.intern(&Interner), | 69 | TyKind::Never => chalk_ir::TyKind::Never.intern(&Interner), |
74 | 70 | ||
75 | TyKind::Closure(def, expr, substs) => { | 71 | TyKind::Closure(closure_id, substs) => { |
76 | let closure_id = db.intern_closure((def, expr)); | ||
77 | let substitution = substs.to_chalk(db); | 72 | let substitution = substs.to_chalk(db); |
78 | chalk_ir::TyKind::Closure(closure_id.into(), substitution).intern(&Interner) | 73 | chalk_ir::TyKind::Closure(closure_id, substitution).intern(&Interner) |
79 | } | 74 | } |
80 | 75 | ||
81 | TyKind::Adt(adt_id, substs) => { | 76 | TyKind::Adt(adt_id, substs) => { |
@@ -92,14 +87,7 @@ impl ToChalk for Ty { | |||
92 | .cast(&Interner) | 87 | .cast(&Interner) |
93 | .intern(&Interner) | 88 | .intern(&Interner) |
94 | } | 89 | } |
95 | TyKind::Placeholder(id) => { | 90 | TyKind::Placeholder(idx) => idx.to_ty::<Interner>(&Interner), |
96 | let interned_id = db.intern_type_param_id(id); | ||
97 | PlaceholderIndex { | ||
98 | ui: UniverseIndex::ROOT, | ||
99 | idx: interned_id.as_intern_id().as_usize(), | ||
100 | } | ||
101 | .to_ty::<Interner>(&Interner) | ||
102 | } | ||
103 | TyKind::BoundVar(idx) => chalk_ir::TyKind::BoundVar(idx).intern(&Interner), | 91 | TyKind::BoundVar(idx) => chalk_ir::TyKind::BoundVar(idx).intern(&Interner), |
104 | TyKind::InferenceVar(..) => panic!("uncanonicalized infer ty"), | 92 | TyKind::InferenceVar(..) => panic!("uncanonicalized infer ty"), |
105 | TyKind::Dyn(predicates) => { | 93 | TyKind::Dyn(predicates) => { |
@@ -114,7 +102,7 @@ impl ToChalk for Ty { | |||
114 | chalk_ir::TyKind::Dyn(bounded_ty).intern(&Interner) | 102 | chalk_ir::TyKind::Dyn(bounded_ty).intern(&Interner) |
115 | } | 103 | } |
116 | TyKind::Alias(AliasTy::Opaque(opaque_ty)) => { | 104 | TyKind::Alias(AliasTy::Opaque(opaque_ty)) => { |
117 | let opaque_ty_id = opaque_ty.opaque_ty_id.to_chalk(db); | 105 | let opaque_ty_id = opaque_ty.opaque_ty_id; |
118 | let substitution = opaque_ty.parameters.to_chalk(db); | 106 | let substitution = opaque_ty.parameters.to_chalk(db); |
119 | chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Opaque(chalk_ir::OpaqueTy { | 107 | chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Opaque(chalk_ir::OpaqueTy { |
120 | opaque_ty_id, | 108 | opaque_ty_id, |
@@ -129,22 +117,16 @@ impl ToChalk for Ty { | |||
129 | match chalk.data(&Interner).kind.clone() { | 117 | match chalk.data(&Interner).kind.clone() { |
130 | chalk_ir::TyKind::Error => TyKind::Unknown, | 118 | chalk_ir::TyKind::Error => TyKind::Unknown, |
131 | chalk_ir::TyKind::Array(ty, _size) => TyKind::Array(Substs::single(from_chalk(db, ty))), | 119 | chalk_ir::TyKind::Array(ty, _size) => TyKind::Array(Substs::single(from_chalk(db, ty))), |
132 | chalk_ir::TyKind::Placeholder(idx) => { | 120 | chalk_ir::TyKind::Placeholder(idx) => TyKind::Placeholder(idx), |
133 | assert_eq!(idx.ui, UniverseIndex::ROOT); | ||
134 | let interned_id = crate::db::GlobalTypeParamId::from_intern_id( | ||
135 | crate::salsa::InternId::from(idx.idx), | ||
136 | ); | ||
137 | TyKind::Placeholder(db.lookup_intern_type_param_id(interned_id)) | ||
138 | } | ||
139 | chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Projection(proj)) => { | 121 | chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Projection(proj)) => { |
140 | let associated_ty = proj.associated_ty_id; | 122 | let associated_ty = proj.associated_ty_id; |
141 | let parameters = from_chalk(db, proj.substitution); | 123 | let parameters = from_chalk(db, proj.substitution); |
142 | TyKind::Alias(AliasTy::Projection(ProjectionTy { associated_ty, parameters })) | 124 | TyKind::Alias(AliasTy::Projection(ProjectionTy { associated_ty, parameters })) |
143 | } | 125 | } |
144 | chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Opaque(opaque_ty)) => { | 126 | chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Opaque(opaque_ty)) => { |
145 | let impl_trait_id = from_chalk(db, opaque_ty.opaque_ty_id); | 127 | let opaque_ty_id = opaque_ty.opaque_ty_id; |
146 | let parameters = from_chalk(db, opaque_ty.substitution); | 128 | let parameters = from_chalk(db, opaque_ty.substitution); |
147 | TyKind::Alias(AliasTy::Opaque(OpaqueTy { opaque_ty_id: impl_trait_id, parameters })) | 129 | TyKind::Alias(AliasTy::Opaque(OpaqueTy { opaque_ty_id, parameters })) |
148 | } | 130 | } |
149 | chalk_ir::TyKind::Function(chalk_ir::FnPointer { | 131 | chalk_ir::TyKind::Function(chalk_ir::FnPointer { |
150 | num_binders, | 132 | num_binders, |
@@ -182,7 +164,7 @@ impl ToChalk for Ty { | |||
182 | } | 164 | } |
183 | 165 | ||
184 | chalk_ir::TyKind::OpaqueType(opaque_type_id, subst) => { | 166 | chalk_ir::TyKind::OpaqueType(opaque_type_id, subst) => { |
185 | TyKind::OpaqueType(from_chalk(db, opaque_type_id), from_chalk(db, subst)) | 167 | TyKind::OpaqueType(opaque_type_id, from_chalk(db, subst)) |
186 | } | 168 | } |
187 | 169 | ||
188 | chalk_ir::TyKind::Scalar(scalar) => TyKind::Scalar(scalar), | 170 | chalk_ir::TyKind::Scalar(scalar) => TyKind::Scalar(scalar), |
@@ -203,11 +185,7 @@ impl ToChalk for Ty { | |||
203 | TyKind::FnDef(fn_def_id, from_chalk(db, subst)) | 185 | TyKind::FnDef(fn_def_id, from_chalk(db, subst)) |
204 | } | 186 | } |
205 | 187 | ||
206 | chalk_ir::TyKind::Closure(id, subst) => { | 188 | chalk_ir::TyKind::Closure(id, subst) => TyKind::Closure(id, from_chalk(db, subst)), |
207 | let id: crate::db::ClosureId = id.into(); | ||
208 | let (def, expr) = db.lookup_intern_closure(id); | ||
209 | TyKind::Closure(def, expr, from_chalk(db, subst)) | ||
210 | } | ||
211 | 189 | ||
212 | chalk_ir::TyKind::Foreign(foreign_def_id) => TyKind::ForeignType(foreign_def_id), | 190 | chalk_ir::TyKind::Foreign(foreign_def_id) => TyKind::ForeignType(foreign_def_id), |
213 | chalk_ir::TyKind::Generator(_, _) => unimplemented!(), // FIXME | 191 | chalk_ir::TyKind::Generator(_, _) => unimplemented!(), // FIXME |
@@ -289,21 +267,6 @@ impl ToChalk for hir_def::TraitId { | |||
289 | } | 267 | } |
290 | } | 268 | } |
291 | 269 | ||
292 | impl ToChalk for OpaqueTyId { | ||
293 | type Chalk = chalk_ir::OpaqueTyId<Interner>; | ||
294 | |||
295 | fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::OpaqueTyId<Interner> { | ||
296 | db.intern_impl_trait_id(self).into() | ||
297 | } | ||
298 | |||
299 | fn from_chalk( | ||
300 | db: &dyn HirDatabase, | ||
301 | opaque_ty_id: chalk_ir::OpaqueTyId<Interner>, | ||
302 | ) -> OpaqueTyId { | ||
303 | db.lookup_intern_impl_trait_id(opaque_ty_id.into()) | ||
304 | } | ||
305 | } | ||
306 | |||
307 | impl ToChalk for hir_def::ImplId { | 270 | impl ToChalk for hir_def::ImplId { |
308 | type Chalk = ImplId; | 271 | type Chalk = ImplId; |
309 | 272 | ||