aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty/src/traits/chalk
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir_ty/src/traits/chalk')
-rw-r--r--crates/hir_ty/src/traits/chalk/mapping.rs332
1 files changed, 102 insertions, 230 deletions
diff --git a/crates/hir_ty/src/traits/chalk/mapping.rs b/crates/hir_ty/src/traits/chalk/mapping.rs
index 8700d664e..db1760e6c 100644
--- a/crates/hir_ty/src/traits/chalk/mapping.rs
+++ b/crates/hir_ty/src/traits/chalk/mapping.rs
@@ -4,20 +4,20 @@
4//! conversions. 4//! conversions.
5 5
6use chalk_ir::{ 6use chalk_ir::{
7 cast::Cast, fold::shift::Shift, interner::HasInterner, LifetimeData, PlaceholderIndex, Scalar, 7 cast::Cast, fold::shift::Shift, interner::HasInterner, LifetimeData, PlaceholderIndex,
8 UniverseIndex, 8 UniverseIndex,
9}; 9};
10use chalk_solve::rust_ir; 10use chalk_solve::rust_ir;
11 11
12use base_db::salsa::InternKey; 12use base_db::salsa::InternKey;
13use hir_def::{type_ref::Mutability, AssocContainerId, GenericDefId, Lookup, TypeAliasId}; 13use hir_def::{AssocContainerId, GenericDefId, Lookup, TypeAliasId};
14 14
15use crate::{ 15use crate::{
16 db::HirDatabase, 16 db::HirDatabase,
17 primitive::{FloatBitness, FloatTy, IntBitness, IntTy, Signedness}, 17 primitive::UintTy,
18 traits::{Canonical, Obligation}, 18 traits::{Canonical, Obligation},
19 ApplicationTy, CallableDefId, GenericPredicate, InEnvironment, OpaqueTy, OpaqueTyId, 19 AliasTy, CallableDefId, FnPointer, FnSig, GenericPredicate, InEnvironment, OpaqueTy,
20 ProjectionPredicate, ProjectionTy, Substs, TraitEnvironment, TraitRef, Ty, TyKind, TypeCtor, 20 OpaqueTyId, ProjectionPredicate, ProjectionTy, Scalar, Substs, TraitEnvironment, TraitRef, Ty,
21}; 21};
22 22
23use super::interner::*; 23use super::interner::*;
@@ -27,88 +27,68 @@ impl ToChalk for Ty {
27 type Chalk = chalk_ir::Ty<Interner>; 27 type Chalk = chalk_ir::Ty<Interner>;
28 fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::Ty<Interner> { 28 fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::Ty<Interner> {
29 match self { 29 match self {
30 Ty::Apply(apply_ty) => match apply_ty.ctor { 30 Ty::Ref(m, parameters) => ref_to_chalk(db, m, parameters),
31 TypeCtor::Ref(m) => ref_to_chalk(db, m, apply_ty.parameters), 31 Ty::Array(parameters) => array_to_chalk(db, parameters),
32 TypeCtor::Array => array_to_chalk(db, apply_ty.parameters), 32 Ty::Function(FnPointer { sig: FnSig { variadic }, substs, .. }) => {
33 TypeCtor::FnPtr { num_args: _, is_varargs } => { 33 let substitution = chalk_ir::FnSubst(substs.to_chalk(db).shifted_in(&Interner));
34 let substitution = 34 chalk_ir::TyKind::Function(chalk_ir::FnPointer {
35 chalk_ir::FnSubst(apply_ty.parameters.to_chalk(db).shifted_in(&Interner)); 35 num_binders: 0,
36 chalk_ir::TyKind::Function(chalk_ir::FnPointer { 36 sig: chalk_ir::FnSig { abi: (), safety: chalk_ir::Safety::Safe, variadic },
37 num_binders: 0, 37 substitution,
38 sig: chalk_ir::FnSig { 38 })
39 abi: (), 39 .intern(&Interner)
40 safety: chalk_ir::Safety::Safe, 40 }
41 variadic: is_varargs, 41 Ty::AssociatedType(type_alias, substs) => {
42 }, 42 let assoc_type = TypeAliasAsAssocType(type_alias);
43 substitution, 43 let assoc_type_id = assoc_type.to_chalk(db);
44 }) 44 let substitution = substs.to_chalk(db);
45 .intern(&Interner) 45 chalk_ir::TyKind::AssociatedType(assoc_type_id, substitution).intern(&Interner)
46 } 46 }
47 TypeCtor::AssociatedType(type_alias) => {
48 let assoc_type = TypeAliasAsAssocType(type_alias);
49 let assoc_type_id = assoc_type.to_chalk(db);
50 let substitution = apply_ty.parameters.to_chalk(db);
51 chalk_ir::TyKind::AssociatedType(assoc_type_id, substitution).intern(&Interner)
52 }
53 47
54 TypeCtor::OpaqueType(impl_trait_id) => { 48 Ty::OpaqueType(impl_trait_id, substs) => {
55 let id = impl_trait_id.to_chalk(db); 49 let id = impl_trait_id.to_chalk(db);
56 let substitution = apply_ty.parameters.to_chalk(db); 50 let substitution = substs.to_chalk(db);
57 chalk_ir::TyKind::OpaqueType(id, substitution).intern(&Interner) 51 chalk_ir::TyKind::OpaqueType(id, substitution).intern(&Interner)
58 } 52 }
59 53
60 TypeCtor::ForeignType(type_alias) => { 54 Ty::ForeignType(type_alias) => {
61 let foreign_type = TypeAliasAsForeignType(type_alias); 55 let foreign_type = TypeAliasAsForeignType(type_alias);
62 let foreign_type_id = foreign_type.to_chalk(db); 56 let foreign_type_id = foreign_type.to_chalk(db);
63 chalk_ir::TyKind::Foreign(foreign_type_id).intern(&Interner) 57 chalk_ir::TyKind::Foreign(foreign_type_id).intern(&Interner)
64 } 58 }
65 59
66 TypeCtor::Bool => chalk_ir::TyKind::Scalar(Scalar::Bool).intern(&Interner), 60 Ty::Scalar(scalar) => chalk_ir::TyKind::Scalar(scalar).intern(&Interner),
67 TypeCtor::Char => chalk_ir::TyKind::Scalar(Scalar::Char).intern(&Interner),
68 TypeCtor::Int(int_ty) => {
69 chalk_ir::TyKind::Scalar(int_ty_to_chalk(int_ty)).intern(&Interner)
70 }
71 TypeCtor::Float(FloatTy { bitness: FloatBitness::X32 }) => {
72 chalk_ir::TyKind::Scalar(Scalar::Float(chalk_ir::FloatTy::F32))
73 .intern(&Interner)
74 }
75 TypeCtor::Float(FloatTy { bitness: FloatBitness::X64 }) => {
76 chalk_ir::TyKind::Scalar(Scalar::Float(chalk_ir::FloatTy::F64))
77 .intern(&Interner)
78 }
79 61
80 TypeCtor::Tuple { cardinality } => { 62 Ty::Tuple(cardinality, substs) => {
81 let substitution = apply_ty.parameters.to_chalk(db); 63 let substitution = substs.to_chalk(db);
82 chalk_ir::TyKind::Tuple(cardinality.into(), substitution).intern(&Interner) 64 chalk_ir::TyKind::Tuple(cardinality.into(), substitution).intern(&Interner)
83 } 65 }
84 TypeCtor::RawPtr(mutability) => { 66 Ty::Raw(mutability, substs) => {
85 let ty = apply_ty.parameters[0].clone().to_chalk(db); 67 let ty = substs[0].clone().to_chalk(db);
86 chalk_ir::TyKind::Raw(mutability.to_chalk(db), ty).intern(&Interner) 68 chalk_ir::TyKind::Raw(mutability, ty).intern(&Interner)
87 } 69 }
88 TypeCtor::Slice => { 70 Ty::Slice(substs) => {
89 chalk_ir::TyKind::Slice(apply_ty.parameters[0].clone().to_chalk(db)) 71 chalk_ir::TyKind::Slice(substs[0].clone().to_chalk(db)).intern(&Interner)
90 .intern(&Interner) 72 }
91 } 73 Ty::Str => chalk_ir::TyKind::Str.intern(&Interner),
92 TypeCtor::Str => chalk_ir::TyKind::Str.intern(&Interner), 74 Ty::FnDef(callable_def, substs) => {
93 TypeCtor::FnDef(callable_def) => { 75 let id = callable_def.to_chalk(db);
94 let id = callable_def.to_chalk(db); 76 let substitution = substs.to_chalk(db);
95 let substitution = apply_ty.parameters.to_chalk(db); 77 chalk_ir::TyKind::FnDef(id, substitution).intern(&Interner)
96 chalk_ir::TyKind::FnDef(id, substitution).intern(&Interner) 78 }
97 } 79 Ty::Never => chalk_ir::TyKind::Never.intern(&Interner),
98 TypeCtor::Never => chalk_ir::TyKind::Never.intern(&Interner),
99 80
100 TypeCtor::Closure { def, expr } => { 81 Ty::Closure(def, expr, substs) => {
101 let closure_id = db.intern_closure((def, expr)); 82 let closure_id = db.intern_closure((def, expr));
102 let substitution = apply_ty.parameters.to_chalk(db); 83 let substitution = substs.to_chalk(db);
103 chalk_ir::TyKind::Closure(closure_id.into(), substitution).intern(&Interner) 84 chalk_ir::TyKind::Closure(closure_id.into(), substitution).intern(&Interner)
104 } 85 }
105 86
106 TypeCtor::Adt(adt_id) => { 87 Ty::Adt(adt_id, substs) => {
107 let substitution = apply_ty.parameters.to_chalk(db); 88 let substitution = substs.to_chalk(db);
108 chalk_ir::TyKind::Adt(chalk_ir::AdtId(adt_id), substitution).intern(&Interner) 89 chalk_ir::TyKind::Adt(chalk_ir::AdtId(adt_id), substitution).intern(&Interner)
109 } 90 }
110 }, 91 Ty::Alias(AliasTy::Projection(proj_ty)) => {
111 Ty::Projection(proj_ty) => {
112 let associated_ty_id = TypeAliasAsAssocType(proj_ty.associated_ty).to_chalk(db); 92 let associated_ty_id = TypeAliasAsAssocType(proj_ty.associated_ty).to_chalk(db);
113 let substitution = proj_ty.parameters.to_chalk(db); 93 let substitution = proj_ty.parameters.to_chalk(db);
114 chalk_ir::AliasTy::Projection(chalk_ir::ProjectionTy { 94 chalk_ir::AliasTy::Projection(chalk_ir::ProjectionTy {
@@ -126,8 +106,8 @@ impl ToChalk for Ty {
126 } 106 }
127 .to_ty::<Interner>(&Interner) 107 .to_ty::<Interner>(&Interner)
128 } 108 }
129 Ty::Bound(idx) => chalk_ir::TyKind::BoundVar(idx).intern(&Interner), 109 Ty::BoundVar(idx) => chalk_ir::TyKind::BoundVar(idx).intern(&Interner),
130 Ty::Infer(_infer_ty) => panic!("uncanonicalized infer ty"), 110 Ty::InferenceVar(..) => panic!("uncanonicalized infer ty"),
131 Ty::Dyn(predicates) => { 111 Ty::Dyn(predicates) => {
132 let where_clauses = chalk_ir::QuantifiedWhereClauses::from_iter( 112 let where_clauses = chalk_ir::QuantifiedWhereClauses::from_iter(
133 &Interner, 113 &Interner,
@@ -139,7 +119,7 @@ impl ToChalk for Ty {
139 }; 119 };
140 chalk_ir::TyKind::Dyn(bounded_ty).intern(&Interner) 120 chalk_ir::TyKind::Dyn(bounded_ty).intern(&Interner)
141 } 121 }
142 Ty::Opaque(opaque_ty) => { 122 Ty::Alias(AliasTy::Opaque(opaque_ty)) => {
143 let opaque_ty_id = opaque_ty.opaque_ty_id.to_chalk(db); 123 let opaque_ty_id = opaque_ty.opaque_ty_id.to_chalk(db);
144 let substitution = opaque_ty.parameters.to_chalk(db); 124 let substitution = opaque_ty.parameters.to_chalk(db);
145 chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Opaque(chalk_ir::OpaqueTy { 125 chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Opaque(chalk_ir::OpaqueTy {
@@ -154,9 +134,7 @@ impl ToChalk for Ty {
154 fn from_chalk(db: &dyn HirDatabase, chalk: chalk_ir::Ty<Interner>) -> Self { 134 fn from_chalk(db: &dyn HirDatabase, chalk: chalk_ir::Ty<Interner>) -> Self {
155 match chalk.data(&Interner).kind.clone() { 135 match chalk.data(&Interner).kind.clone() {
156 chalk_ir::TyKind::Error => Ty::Unknown, 136 chalk_ir::TyKind::Error => Ty::Unknown,
157 chalk_ir::TyKind::Array(ty, _size) => { 137 chalk_ir::TyKind::Array(ty, _size) => Ty::Array(Substs::single(from_chalk(db, ty))),
158 Ty::apply(TypeCtor::Array, Substs::single(from_chalk(db, ty)))
159 }
160 chalk_ir::TyKind::Placeholder(idx) => { 138 chalk_ir::TyKind::Placeholder(idx) => {
161 assert_eq!(idx.ui, UniverseIndex::ROOT); 139 assert_eq!(idx.ui, UniverseIndex::ROOT);
162 let interned_id = crate::db::GlobalTypeParamId::from_intern_id( 140 let interned_id = crate::db::GlobalTypeParamId::from_intern_id(
@@ -168,12 +146,12 @@ impl ToChalk for Ty {
168 let associated_ty = 146 let associated_ty =
169 from_chalk::<TypeAliasAsAssocType, _>(db, proj.associated_ty_id).0; 147 from_chalk::<TypeAliasAsAssocType, _>(db, proj.associated_ty_id).0;
170 let parameters = from_chalk(db, proj.substitution); 148 let parameters = from_chalk(db, proj.substitution);
171 Ty::Projection(ProjectionTy { associated_ty, parameters }) 149 Ty::Alias(AliasTy::Projection(ProjectionTy { associated_ty, parameters }))
172 } 150 }
173 chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Opaque(opaque_ty)) => { 151 chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Opaque(opaque_ty)) => {
174 let impl_trait_id = from_chalk(db, opaque_ty.opaque_ty_id); 152 let impl_trait_id = from_chalk(db, opaque_ty.opaque_ty_id);
175 let parameters = from_chalk(db, opaque_ty.substitution); 153 let parameters = from_chalk(db, opaque_ty.substitution);
176 Ty::Opaque(OpaqueTy { opaque_ty_id: impl_trait_id, parameters }) 154 Ty::Alias(AliasTy::Opaque(OpaqueTy { opaque_ty_id: impl_trait_id, parameters }))
177 } 155 }
178 chalk_ir::TyKind::Function(chalk_ir::FnPointer { 156 chalk_ir::TyKind::Function(chalk_ir::FnPointer {
179 num_binders, 157 num_binders,
@@ -182,19 +160,17 @@ impl ToChalk for Ty {
182 .. 160 ..
183 }) => { 161 }) => {
184 assert_eq!(num_binders, 0); 162 assert_eq!(num_binders, 0);
185 let parameters: Substs = from_chalk( 163 let substs: Substs = from_chalk(
186 db, 164 db,
187 substitution.0.shifted_out(&Interner).expect("fn ptr should have no binders"), 165 substitution.0.shifted_out(&Interner).expect("fn ptr should have no binders"),
188 ); 166 );
189 Ty::Apply(ApplicationTy { 167 Ty::Function(FnPointer {
190 ctor: TypeCtor::FnPtr { 168 num_args: (substs.len() - 1),
191 num_args: (parameters.len() - 1) as u16, 169 sig: FnSig { variadic },
192 is_varargs: variadic, 170 substs,
193 },
194 parameters,
195 }) 171 })
196 } 172 }
197 chalk_ir::TyKind::BoundVar(idx) => Ty::Bound(idx), 173 chalk_ir::TyKind::BoundVar(idx) => Ty::BoundVar(idx),
198 chalk_ir::TyKind::InferenceVar(_iv, _kind) => Ty::Unknown, 174 chalk_ir::TyKind::InferenceVar(_iv, _kind) => Ty::Unknown,
199 chalk_ir::TyKind::Dyn(where_clauses) => { 175 chalk_ir::TyKind::Dyn(where_clauses) => {
200 assert_eq!(where_clauses.bounds.binders.len(&Interner), 1); 176 assert_eq!(where_clauses.bounds.binders.len(&Interner), 1);
@@ -207,93 +183,66 @@ impl ToChalk for Ty {
207 Ty::Dyn(predicates) 183 Ty::Dyn(predicates)
208 } 184 }
209 185
210 chalk_ir::TyKind::Adt(struct_id, subst) => { 186 chalk_ir::TyKind::Adt(struct_id, subst) => Ty::Adt(struct_id.0, from_chalk(db, subst)),
211 apply_ty_from_chalk(db, TypeCtor::Adt(struct_id.0), subst) 187 chalk_ir::TyKind::AssociatedType(type_id, subst) => Ty::AssociatedType(
212 } 188 from_chalk::<TypeAliasAsAssocType, _>(db, type_id).0,
213 chalk_ir::TyKind::AssociatedType(type_id, subst) => apply_ty_from_chalk( 189 from_chalk(db, subst),
214 db,
215 TypeCtor::AssociatedType(from_chalk::<TypeAliasAsAssocType, _>(db, type_id).0),
216 subst,
217 ), 190 ),
191
218 chalk_ir::TyKind::OpaqueType(opaque_type_id, subst) => { 192 chalk_ir::TyKind::OpaqueType(opaque_type_id, subst) => {
219 apply_ty_from_chalk(db, TypeCtor::OpaqueType(from_chalk(db, opaque_type_id)), subst) 193 Ty::OpaqueType(from_chalk(db, opaque_type_id), from_chalk(db, subst))
220 } 194 }
221 195
222 chalk_ir::TyKind::Scalar(Scalar::Bool) => Ty::simple(TypeCtor::Bool), 196 chalk_ir::TyKind::Scalar(scalar) => Ty::Scalar(scalar),
223 chalk_ir::TyKind::Scalar(Scalar::Char) => Ty::simple(TypeCtor::Char),
224 chalk_ir::TyKind::Scalar(Scalar::Int(int_ty)) => Ty::simple(TypeCtor::Int(IntTy {
225 signedness: Signedness::Signed,
226 bitness: bitness_from_chalk_int(int_ty),
227 })),
228 chalk_ir::TyKind::Scalar(Scalar::Uint(uint_ty)) => Ty::simple(TypeCtor::Int(IntTy {
229 signedness: Signedness::Unsigned,
230 bitness: bitness_from_chalk_uint(uint_ty),
231 })),
232 chalk_ir::TyKind::Scalar(Scalar::Float(chalk_ir::FloatTy::F32)) => {
233 Ty::simple(TypeCtor::Float(FloatTy { bitness: FloatBitness::X32 }))
234 }
235 chalk_ir::TyKind::Scalar(Scalar::Float(chalk_ir::FloatTy::F64)) => {
236 Ty::simple(TypeCtor::Float(FloatTy { bitness: FloatBitness::X64 }))
237 }
238 chalk_ir::TyKind::Tuple(cardinality, subst) => { 197 chalk_ir::TyKind::Tuple(cardinality, subst) => {
239 apply_ty_from_chalk(db, TypeCtor::Tuple { cardinality: cardinality as u16 }, subst) 198 Ty::Tuple(cardinality, from_chalk(db, subst))
240 } 199 }
241 chalk_ir::TyKind::Raw(mutability, ty) => { 200 chalk_ir::TyKind::Raw(mutability, ty) => {
242 Ty::apply_one(TypeCtor::RawPtr(from_chalk(db, mutability)), from_chalk(db, ty)) 201 Ty::Raw(mutability, Substs::single(from_chalk(db, ty)))
243 } 202 }
244 chalk_ir::TyKind::Slice(ty) => Ty::apply_one(TypeCtor::Slice, from_chalk(db, ty)), 203 chalk_ir::TyKind::Slice(ty) => Ty::Slice(Substs::single(from_chalk(db, ty))),
245 chalk_ir::TyKind::Ref(mutability, _lifetime, ty) => { 204 chalk_ir::TyKind::Ref(mutability, _lifetime, ty) => {
246 Ty::apply_one(TypeCtor::Ref(from_chalk(db, mutability)), from_chalk(db, ty)) 205 Ty::Ref(mutability, Substs::single(from_chalk(db, ty)))
247 } 206 }
248 chalk_ir::TyKind::Str => Ty::simple(TypeCtor::Str), 207 chalk_ir::TyKind::Str => Ty::Str,
249 chalk_ir::TyKind::Never => Ty::simple(TypeCtor::Never), 208 chalk_ir::TyKind::Never => Ty::Never,
250 209
251 chalk_ir::TyKind::FnDef(fn_def_id, subst) => { 210 chalk_ir::TyKind::FnDef(fn_def_id, subst) => {
252 let callable_def = from_chalk(db, fn_def_id); 211 Ty::FnDef(from_chalk(db, fn_def_id), from_chalk(db, subst))
253 apply_ty_from_chalk(db, TypeCtor::FnDef(callable_def), subst)
254 } 212 }
255 213
256 chalk_ir::TyKind::Closure(id, subst) => { 214 chalk_ir::TyKind::Closure(id, subst) => {
257 let id: crate::db::ClosureId = id.into(); 215 let id: crate::db::ClosureId = id.into();
258 let (def, expr) = db.lookup_intern_closure(id); 216 let (def, expr) = db.lookup_intern_closure(id);
259 apply_ty_from_chalk(db, TypeCtor::Closure { def, expr }, subst) 217 Ty::Closure(def, expr, from_chalk(db, subst))
260 } 218 }
261 219
262 chalk_ir::TyKind::Foreign(foreign_def_id) => Ty::simple(TypeCtor::ForeignType( 220 chalk_ir::TyKind::Foreign(foreign_def_id) => {
263 from_chalk::<TypeAliasAsForeignType, _>(db, foreign_def_id).0, 221 Ty::ForeignType(from_chalk::<TypeAliasAsForeignType, _>(db, foreign_def_id).0)
264 )), 222 }
265 chalk_ir::TyKind::Generator(_, _) => unimplemented!(), // FIXME 223 chalk_ir::TyKind::Generator(_, _) => unimplemented!(), // FIXME
266 chalk_ir::TyKind::GeneratorWitness(_, _) => unimplemented!(), // FIXME 224 chalk_ir::TyKind::GeneratorWitness(_, _) => unimplemented!(), // FIXME
267 } 225 }
268 } 226 }
269} 227}
270 228
271fn apply_ty_from_chalk(
272 db: &dyn HirDatabase,
273 ctor: TypeCtor,
274 subst: chalk_ir::Substitution<Interner>,
275) -> Ty {
276 Ty::Apply(ApplicationTy { ctor, parameters: from_chalk(db, subst) })
277}
278
279/// We currently don't model lifetimes, but Chalk does. So, we have to insert a 229/// We currently don't model lifetimes, but Chalk does. So, we have to insert a
280/// fake lifetime here, because Chalks built-in logic may expect it to be there. 230/// fake lifetime here, because Chalks built-in logic may expect it to be there.
281fn ref_to_chalk( 231fn ref_to_chalk(
282 db: &dyn HirDatabase, 232 db: &dyn HirDatabase,
283 mutability: Mutability, 233 mutability: chalk_ir::Mutability,
284 subst: Substs, 234 subst: Substs,
285) -> chalk_ir::Ty<Interner> { 235) -> chalk_ir::Ty<Interner> {
286 let arg = subst[0].clone().to_chalk(db); 236 let arg = subst[0].clone().to_chalk(db);
287 let lifetime = LifetimeData::Static.intern(&Interner); 237 let lifetime = LifetimeData::Static.intern(&Interner);
288 chalk_ir::TyKind::Ref(mutability.to_chalk(db), lifetime, arg).intern(&Interner) 238 chalk_ir::TyKind::Ref(mutability, lifetime, arg).intern(&Interner)
289} 239}
290 240
291/// We currently don't model constants, but Chalk does. So, we have to insert a 241/// We currently don't model constants, but Chalk does. So, we have to insert a
292/// fake constant here, because Chalks built-in logic may expect it to be there. 242/// fake constant here, because Chalks built-in logic may expect it to be there.
293fn array_to_chalk(db: &dyn HirDatabase, subst: Substs) -> chalk_ir::Ty<Interner> { 243fn array_to_chalk(db: &dyn HirDatabase, subst: Substs) -> chalk_ir::Ty<Interner> {
294 let arg = subst[0].clone().to_chalk(db); 244 let arg = subst[0].clone().to_chalk(db);
295 let usize_ty = 245 let usize_ty = chalk_ir::TyKind::Scalar(Scalar::Uint(UintTy::Usize)).intern(&Interner);
296 chalk_ir::TyKind::Scalar(Scalar::Uint(chalk_ir::UintTy::Usize)).intern(&Interner);
297 let const_ = chalk_ir::ConstData { 246 let const_ = chalk_ir::ConstData {
298 ty: usize_ty, 247 ty: usize_ty,
299 value: chalk_ir::ConstValue::Concrete(chalk_ir::ConcreteConst { interned: () }), 248 value: chalk_ir::ConstValue::Concrete(chalk_ir::ConcreteConst { interned: () }),
@@ -364,71 +313,6 @@ impl ToChalk for OpaqueTyId {
364 } 313 }
365} 314}
366 315
367fn bitness_from_chalk_uint(uint_ty: chalk_ir::UintTy) -> IntBitness {
368 use chalk_ir::UintTy;
369
370 match uint_ty {
371 UintTy::Usize => IntBitness::Xsize,
372 UintTy::U8 => IntBitness::X8,
373 UintTy::U16 => IntBitness::X16,
374 UintTy::U32 => IntBitness::X32,
375 UintTy::U64 => IntBitness::X64,
376 UintTy::U128 => IntBitness::X128,
377 }
378}
379
380fn bitness_from_chalk_int(int_ty: chalk_ir::IntTy) -> IntBitness {
381 use chalk_ir::IntTy;
382
383 match int_ty {
384 IntTy::Isize => IntBitness::Xsize,
385 IntTy::I8 => IntBitness::X8,
386 IntTy::I16 => IntBitness::X16,
387 IntTy::I32 => IntBitness::X32,
388 IntTy::I64 => IntBitness::X64,
389 IntTy::I128 => IntBitness::X128,
390 }
391}
392
393fn int_ty_to_chalk(int_ty: IntTy) -> Scalar {
394 use chalk_ir::{IntTy, UintTy};
395
396 match int_ty.signedness {
397 Signedness::Signed => Scalar::Int(match int_ty.bitness {
398 IntBitness::Xsize => IntTy::Isize,
399 IntBitness::X8 => IntTy::I8,
400 IntBitness::X16 => IntTy::I16,
401 IntBitness::X32 => IntTy::I32,
402 IntBitness::X64 => IntTy::I64,
403 IntBitness::X128 => IntTy::I128,
404 }),
405 Signedness::Unsigned => Scalar::Uint(match int_ty.bitness {
406 IntBitness::Xsize => UintTy::Usize,
407 IntBitness::X8 => UintTy::U8,
408 IntBitness::X16 => UintTy::U16,
409 IntBitness::X32 => UintTy::U32,
410 IntBitness::X64 => UintTy::U64,
411 IntBitness::X128 => UintTy::U128,
412 }),
413 }
414}
415
416impl ToChalk for Mutability {
417 type Chalk = chalk_ir::Mutability;
418 fn to_chalk(self, _db: &dyn HirDatabase) -> Self::Chalk {
419 match self {
420 Mutability::Shared => chalk_ir::Mutability::Not,
421 Mutability::Mut => chalk_ir::Mutability::Mut,
422 }
423 }
424 fn from_chalk(_db: &dyn HirDatabase, chalk: Self::Chalk) -> Self {
425 match chalk {
426 chalk_ir::Mutability::Mut => Mutability::Mut,
427 chalk_ir::Mutability::Not => Mutability::Shared,
428 }
429 }
430}
431
432impl ToChalk for hir_def::ImplId { 316impl ToChalk for hir_def::ImplId {
433 type Chalk = ImplId; 317 type Chalk = ImplId;
434 318
@@ -632,20 +516,12 @@ where
632 type Chalk = chalk_ir::Canonical<T::Chalk>; 516 type Chalk = chalk_ir::Canonical<T::Chalk>;
633 517
634 fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::Canonical<T::Chalk> { 518 fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::Canonical<T::Chalk> {
635 let kinds = self 519 let kinds = self.kinds.iter().map(|&tk| {
636 .kinds 520 chalk_ir::CanonicalVarKind::new(
637 .iter() 521 chalk_ir::VariableKind::Ty(tk),
638 .map(|k| match k { 522 chalk_ir::UniverseIndex::ROOT,
639 TyKind::General => chalk_ir::TyVariableKind::General, 523 )
640 TyKind::Integer => chalk_ir::TyVariableKind::Integer, 524 });
641 TyKind::Float => chalk_ir::TyVariableKind::Float,
642 })
643 .map(|tk| {
644 chalk_ir::CanonicalVarKind::new(
645 chalk_ir::VariableKind::Ty(tk),
646 chalk_ir::UniverseIndex::ROOT,
647 )
648 });
649 let value = self.value.to_chalk(db); 525 let value = self.value.to_chalk(db);
650 chalk_ir::Canonical { 526 chalk_ir::Canonical {
651 value, 527 value,
@@ -658,17 +534,13 @@ where
658 .binders 534 .binders
659 .iter(&Interner) 535 .iter(&Interner)
660 .map(|k| match k.kind { 536 .map(|k| match k.kind {
661 chalk_ir::VariableKind::Ty(tk) => match tk { 537 chalk_ir::VariableKind::Ty(tk) => tk,
662 chalk_ir::TyVariableKind::General => TyKind::General,
663 chalk_ir::TyVariableKind::Integer => TyKind::Integer,
664 chalk_ir::TyVariableKind::Float => TyKind::Float,
665 },
666 // HACK: Chalk can sometimes return new lifetime variables. We 538 // HACK: Chalk can sometimes return new lifetime variables. We
667 // want to just skip them, but to not mess up the indices of 539 // want to just skip them, but to not mess up the indices of
668 // other variables, we'll just create a new type variable in 540 // other variables, we'll just create a new type variable in
669 // their place instead. This should not matter (we never see the 541 // their place instead. This should not matter (we never see the
670 // actual *uses* of the lifetime variable). 542 // actual *uses* of the lifetime variable).
671 chalk_ir::VariableKind::Lifetime => TyKind::General, 543 chalk_ir::VariableKind::Lifetime => chalk_ir::TyVariableKind::General,
672 chalk_ir::VariableKind::Const(_) => panic!("unexpected const from Chalk"), 544 chalk_ir::VariableKind::Const(_) => panic!("unexpected const from Chalk"),
673 }) 545 })
674 .collect(); 546 .collect();