aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/hir_ty/src/lower.rs5
-rw-r--r--crates/hir_ty/src/traits.rs2
-rw-r--r--crates/hir_ty/src/traits/chalk.rs38
-rw-r--r--crates/hir_ty/src/traits/chalk/mapping.rs191
4 files changed, 21 insertions, 215 deletions
diff --git a/crates/hir_ty/src/lower.rs b/crates/hir_ty/src/lower.rs
index 109157a5e..6584bcf34 100644
--- a/crates/hir_ty/src/lower.rs
+++ b/crates/hir_ty/src/lower.rs
@@ -950,8 +950,7 @@ pub(crate) fn trait_environment_query(
950 traits_in_scope 950 traits_in_scope
951 .push((tr.self_type_parameter(&Interner).clone(), tr.hir_trait_id())); 951 .push((tr.self_type_parameter(&Interner).clone(), tr.hir_trait_id()));
952 } 952 }
953 let program_clause: chalk_ir::ProgramClause<Interner> = 953 let program_clause: chalk_ir::ProgramClause<Interner> = pred.clone().cast(&Interner);
954 pred.clone().to_chalk(db).cast(&Interner);
955 clauses.push(program_clause.into_from_env_clause(&Interner)); 954 clauses.push(program_clause.into_from_env_clause(&Interner));
956 } 955 }
957 } 956 }
@@ -974,7 +973,7 @@ pub(crate) fn trait_environment_query(
974 let substs = TyBuilder::type_params_subst(db, trait_id); 973 let substs = TyBuilder::type_params_subst(db, trait_id);
975 let trait_ref = TraitRef { trait_id: to_chalk_trait_id(trait_id), substitution: substs }; 974 let trait_ref = TraitRef { trait_id: to_chalk_trait_id(trait_id), substitution: substs };
976 let pred = WhereClause::Implemented(trait_ref); 975 let pred = WhereClause::Implemented(trait_ref);
977 let program_clause: chalk_ir::ProgramClause<Interner> = pred.to_chalk(db).cast(&Interner); 976 let program_clause: chalk_ir::ProgramClause<Interner> = pred.cast(&Interner);
978 clauses.push(program_clause.into_from_env_clause(&Interner)); 977 clauses.push(program_clause.into_from_env_clause(&Interner));
979 } 978 }
980 979
diff --git a/crates/hir_ty/src/traits.rs b/crates/hir_ty/src/traits.rs
index de1d37e17..63d87fe61 100644
--- a/crates/hir_ty/src/traits.rs
+++ b/crates/hir_ty/src/traits.rs
@@ -96,7 +96,7 @@ pub(crate) fn trait_solve_query(
96 } 96 }
97 } 97 }
98 98
99 let canonical = goal.to_chalk(db).cast(&Interner); 99 let canonical = goal.cast(&Interner);
100 100
101 // We currently don't deal with universes (I think / hope they're not yet 101 // We currently don't deal with universes (I think / hope they're not yet
102 // relevant for our use cases?) 102 // relevant for our use cases?)
diff --git a/crates/hir_ty/src/traits/chalk.rs b/crates/hir_ty/src/traits/chalk.rs
index a5aa40c10..fcdcc2b4d 100644
--- a/crates/hir_ty/src/traits/chalk.rs
+++ b/crates/hir_ty/src/traits/chalk.rs
@@ -86,7 +86,7 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> {
86 debug!("impls_for_trait {:?}", trait_id); 86 debug!("impls_for_trait {:?}", trait_id);
87 let trait_: hir_def::TraitId = from_chalk(self.db, trait_id); 87 let trait_: hir_def::TraitId = from_chalk(self.db, trait_id);
88 88
89 let ty: Ty = from_chalk(self.db, parameters[0].assert_ty_ref(&Interner).clone()); 89 let ty: Ty = parameters[0].assert_ty_ref(&Interner).clone();
90 90
91 fn binder_kind( 91 fn binder_kind(
92 ty: &Ty, 92 ty: &Ty,
@@ -187,15 +187,7 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> {
187 let (datas, binders) = (*datas).as_ref().into_value_and_skipped_binders(); 187 let (datas, binders) = (*datas).as_ref().into_value_and_skipped_binders();
188 let data = &datas.impl_traits[idx as usize]; 188 let data = &datas.impl_traits[idx as usize];
189 let bound = OpaqueTyDatumBound { 189 let bound = OpaqueTyDatumBound {
190 bounds: make_binders( 190 bounds: make_binders(data.bounds.skip_binders().iter().cloned().collect(), 1),
191 data.bounds
192 .skip_binders()
193 .iter()
194 .cloned()
195 .map(|b| b.to_chalk(self.db))
196 .collect(),
197 1,
198 ),
199 where_clauses: make_binders(vec![], 0), 191 where_clauses: make_binders(vec![], 0),
200 }; 192 };
201 chalk_ir::Binders::new(binders, bound) 193 chalk_ir::Binders::new(binders, bound)
@@ -246,8 +238,8 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> {
246 let bound = OpaqueTyDatumBound { 238 let bound = OpaqueTyDatumBound {
247 bounds: make_binders( 239 bounds: make_binders(
248 vec![ 240 vec![
249 crate::wrap_empty_binders(impl_bound).to_chalk(self.db), 241 crate::wrap_empty_binders(impl_bound),
250 crate::wrap_empty_binders(proj_bound).to_chalk(self.db), 242 crate::wrap_empty_binders(proj_bound),
251 ], 243 ],
252 1, 244 1,
253 ), 245 ),
@@ -272,7 +264,7 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> {
272 264
273 fn hidden_opaque_type(&self, _id: chalk_ir::OpaqueTyId<Interner>) -> chalk_ir::Ty<Interner> { 265 fn hidden_opaque_type(&self, _id: chalk_ir::OpaqueTyId<Interner>) -> chalk_ir::Ty<Interner> {
274 // FIXME: actually provide the hidden type; it is relevant for auto traits 266 // FIXME: actually provide the hidden type; it is relevant for auto traits
275 TyKind::Error.intern(&Interner).to_chalk(self.db) 267 TyKind::Error.intern(&Interner)
276 } 268 }
277 269
278 fn is_object_safe(&self, _trait_id: chalk_ir::TraitId<Interner>) -> bool { 270 fn is_object_safe(&self, _trait_id: chalk_ir::TraitId<Interner>) -> bool {
@@ -293,12 +285,11 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> {
293 _closure_id: chalk_ir::ClosureId<Interner>, 285 _closure_id: chalk_ir::ClosureId<Interner>,
294 substs: &chalk_ir::Substitution<Interner>, 286 substs: &chalk_ir::Substitution<Interner>,
295 ) -> chalk_ir::Binders<rust_ir::FnDefInputsAndOutputDatum<Interner>> { 287 ) -> chalk_ir::Binders<rust_ir::FnDefInputsAndOutputDatum<Interner>> {
296 let sig_ty: Ty = 288 let sig_ty = substs.at(&Interner, 0).assert_ty_ref(&Interner).clone();
297 from_chalk(self.db, substs.at(&Interner, 0).assert_ty_ref(&Interner).clone());
298 let sig = &sig_ty.callable_sig(self.db).expect("first closure param should be fn ptr"); 289 let sig = &sig_ty.callable_sig(self.db).expect("first closure param should be fn ptr");
299 let io = rust_ir::FnDefInputsAndOutputDatum { 290 let io = rust_ir::FnDefInputsAndOutputDatum {
300 argument_types: sig.params().iter().map(|ty| ty.clone().to_chalk(self.db)).collect(), 291 argument_types: sig.params().iter().cloned().collect(),
301 return_type: sig.ret().clone().to_chalk(self.db), 292 return_type: sig.ret().clone(),
302 }; 293 };
303 make_binders(io.shifted_in(&Interner), 0) 294 make_binders(io.shifted_in(&Interner), 0)
304 } 295 }
@@ -307,7 +298,7 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> {
307 _closure_id: chalk_ir::ClosureId<Interner>, 298 _closure_id: chalk_ir::ClosureId<Interner>,
308 _substs: &chalk_ir::Substitution<Interner>, 299 _substs: &chalk_ir::Substitution<Interner>,
309 ) -> chalk_ir::Binders<chalk_ir::Ty<Interner>> { 300 ) -> chalk_ir::Binders<chalk_ir::Ty<Interner>> {
310 let ty = TyBuilder::unit().to_chalk(self.db); 301 let ty = TyBuilder::unit();
311 make_binders(ty, 0) 302 make_binders(ty, 0)
312 } 303 }
313 fn closure_fn_substitution( 304 fn closure_fn_substitution(
@@ -315,7 +306,7 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> {
315 _closure_id: chalk_ir::ClosureId<Interner>, 306 _closure_id: chalk_ir::ClosureId<Interner>,
316 _substs: &chalk_ir::Substitution<Interner>, 307 _substs: &chalk_ir::Substitution<Interner>,
317 ) -> chalk_ir::Substitution<Interner> { 308 ) -> chalk_ir::Substitution<Interner> {
318 Substitution::empty(&Interner).to_chalk(self.db) 309 Substitution::empty(&Interner)
319 } 310 }
320 311
321 fn trait_name(&self, trait_id: chalk_ir::TraitId<Interner>) -> String { 312 fn trait_name(&self, trait_id: chalk_ir::TraitId<Interner>) -> String {
@@ -410,7 +401,7 @@ pub(crate) fn associated_ty_data_query(
410 let where_clauses = convert_where_clauses(db, type_alias.into(), &bound_vars); 401 let where_clauses = convert_where_clauses(db, type_alias.into(), &bound_vars);
411 let bound_data = rust_ir::AssociatedTyDatumBound { bounds, where_clauses }; 402 let bound_data = rust_ir::AssociatedTyDatumBound { bounds, where_clauses };
412 let datum = AssociatedTyDatum { 403 let datum = AssociatedTyDatum {
413 trait_id: trait_.to_chalk(db), 404 trait_id: to_chalk_trait_id(trait_),
414 id, 405 id,
415 name: type_alias, 406 name: type_alias,
416 binders: make_binders(bound_data, generic_params.len()), 407 binders: make_binders(bound_data, generic_params.len()),
@@ -563,7 +554,6 @@ fn impl_def_datum(
563 trait_ref.display(db), 554 trait_ref.display(db),
564 where_clauses 555 where_clauses
565 ); 556 );
566 let trait_ref = trait_ref.to_chalk(db);
567 557
568 let polarity = if negative { rust_ir::Polarity::Negative } else { rust_ir::Polarity::Positive }; 558 let polarity = if negative { rust_ir::Polarity::Negative } else { rust_ir::Polarity::Positive };
569 559
@@ -624,7 +614,7 @@ fn type_alias_associated_ty_value(
624 .associated_type_by_name(&type_alias_data.name) 614 .associated_type_by_name(&type_alias_data.name)
625 .expect("assoc ty value should not exist"); // validated when building the impl data as well 615 .expect("assoc ty value should not exist"); // validated when building the impl data as well
626 let (ty, binders) = db.ty(type_alias.into()).into_value_and_skipped_binders(); 616 let (ty, binders) = db.ty(type_alias.into()).into_value_and_skipped_binders();
627 let value_bound = rust_ir::AssociatedTyValueBound { ty: ty.to_chalk(db) }; 617 let value_bound = rust_ir::AssociatedTyValueBound { ty };
628 let value = rust_ir::AssociatedTyValue { 618 let value = rust_ir::AssociatedTyValue {
629 impl_id: impl_id.to_chalk(db), 619 impl_id: impl_id.to_chalk(db),
630 associated_ty_id: to_assoc_type_id(assoc_ty), 620 associated_ty_id: to_assoc_type_id(assoc_ty),
@@ -647,8 +637,8 @@ pub(crate) fn fn_def_datum_query(
647 // Note: Chalk doesn't actually use this information yet as far as I am aware, but we provide it anyway 637 // Note: Chalk doesn't actually use this information yet as far as I am aware, but we provide it anyway
648 inputs_and_output: make_binders( 638 inputs_and_output: make_binders(
649 rust_ir::FnDefInputsAndOutputDatum { 639 rust_ir::FnDefInputsAndOutputDatum {
650 argument_types: sig.params().iter().map(|ty| ty.clone().to_chalk(db)).collect(), 640 argument_types: sig.params().iter().cloned().collect(),
651 return_type: sig.ret().clone().to_chalk(db), 641 return_type: sig.ret().clone(),
652 } 642 }
653 .shifted_in(&Interner), 643 .shifted_in(&Interner),
654 0, 644 0,
diff --git a/crates/hir_ty/src/traits/chalk/mapping.rs b/crates/hir_ty/src/traits/chalk/mapping.rs
index 62cf0fecf..54783b58c 100644
--- a/crates/hir_ty/src/traits/chalk/mapping.rs
+++ b/crates/hir_ty/src/traits/chalk/mapping.rs
@@ -18,55 +18,6 @@ use crate::{
18use super::interner::*; 18use super::interner::*;
19use super::*; 19use super::*;
20 20
21impl ToChalk for Ty {
22 type Chalk = chalk_ir::Ty<Interner>;
23 fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::Ty<Interner> {
24 self
25 }
26 fn from_chalk(db: &dyn HirDatabase, chalk: chalk_ir::Ty<Interner>) -> Self {
27 chalk
28 }
29}
30
31impl ToChalk for GenericArg {
32 type Chalk = chalk_ir::GenericArg<Interner>;
33
34 fn to_chalk(self, db: &dyn HirDatabase) -> Self::Chalk {
35 self
36 }
37
38 fn from_chalk(db: &dyn HirDatabase, chalk: Self::Chalk) -> Self {
39 chalk
40 }
41}
42
43impl ToChalk for Substitution {
44 type Chalk = chalk_ir::Substitution<Interner>;
45
46 fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::Substitution<Interner> {
47 self
48 }
49
50 fn from_chalk(
51 db: &dyn HirDatabase,
52 parameters: chalk_ir::Substitution<Interner>,
53 ) -> Substitution {
54 parameters
55 }
56}
57
58impl ToChalk for TraitRef {
59 type Chalk = chalk_ir::TraitRef<Interner>;
60
61 fn to_chalk(self: TraitRef, db: &dyn HirDatabase) -> chalk_ir::TraitRef<Interner> {
62 self
63 }
64
65 fn from_chalk(db: &dyn HirDatabase, trait_ref: chalk_ir::TraitRef<Interner>) -> Self {
66 trait_ref
67 }
68}
69
70impl ToChalk for hir_def::TraitId { 21impl ToChalk for hir_def::TraitId {
71 type Chalk = TraitId; 22 type Chalk = TraitId;
72 23
@@ -120,140 +71,6 @@ impl ToChalk for TypeAliasAsValue {
120 } 71 }
121} 72}
122 73
123impl ToChalk for WhereClause {
124 type Chalk = chalk_ir::WhereClause<Interner>;
125
126 fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::WhereClause<Interner> {
127 self
128 }
129
130 fn from_chalk(
131 db: &dyn HirDatabase,
132 where_clause: chalk_ir::WhereClause<Interner>,
133 ) -> WhereClause {
134 where_clause
135 }
136}
137
138impl ToChalk for ProjectionTy {
139 type Chalk = chalk_ir::ProjectionTy<Interner>;
140
141 fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::ProjectionTy<Interner> {
142 self
143 }
144
145 fn from_chalk(
146 db: &dyn HirDatabase,
147 projection_ty: chalk_ir::ProjectionTy<Interner>,
148 ) -> ProjectionTy {
149 projection_ty
150 }
151}
152impl ToChalk for OpaqueTy {
153 type Chalk = chalk_ir::OpaqueTy<Interner>;
154
155 fn to_chalk(self, db: &dyn HirDatabase) -> Self::Chalk {
156 self
157 }
158
159 fn from_chalk(db: &dyn HirDatabase, chalk: Self::Chalk) -> Self {
160 chalk
161 }
162}
163
164impl ToChalk for AliasTy {
165 type Chalk = chalk_ir::AliasTy<Interner>;
166
167 fn to_chalk(self, db: &dyn HirDatabase) -> Self::Chalk {
168 self
169 }
170
171 fn from_chalk(db: &dyn HirDatabase, chalk: Self::Chalk) -> Self {
172 chalk
173 }
174}
175
176impl ToChalk for AliasEq {
177 type Chalk = chalk_ir::AliasEq<Interner>;
178
179 fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::AliasEq<Interner> {
180 self
181 }
182
183 fn from_chalk(db: &dyn HirDatabase, alias_eq: chalk_ir::AliasEq<Interner>) -> Self {
184 alias_eq
185 }
186}
187
188impl ToChalk for DomainGoal {
189 type Chalk = chalk_ir::DomainGoal<Interner>;
190
191 fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::DomainGoal<Interner> {
192 self
193 }
194
195 fn from_chalk(_db: &dyn HirDatabase, goal: chalk_ir::DomainGoal<Interner>) -> Self {
196 goal
197 }
198}
199
200impl<T> ToChalk for Canonical<T>
201where
202 T: HasInterner<Interner = Interner>,
203{
204 type Chalk = chalk_ir::Canonical<T>;
205
206 fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::Canonical<T> {
207 self
208 }
209
210 fn from_chalk(db: &dyn HirDatabase, canonical: chalk_ir::Canonical<T>) -> Canonical<T> {
211 canonical
212 }
213}
214
215impl<T: ToChalk> ToChalk for InEnvironment<T>
216where
217 T: HasInterner<Interner = Interner>,
218{
219 type Chalk = chalk_ir::InEnvironment<T>;
220
221 fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::InEnvironment<T> {
222 self
223 }
224
225 fn from_chalk(_db: &dyn HirDatabase, in_env: chalk_ir::InEnvironment<T>) -> InEnvironment<T> {
226 in_env
227 }
228}
229
230impl<T: ToChalk> ToChalk for crate::Binders<T>
231where
232 T: HasInterner<Interner = Interner>,
233{
234 type Chalk = chalk_ir::Binders<T>;
235
236 fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::Binders<T> {
237 self
238 }
239
240 fn from_chalk(db: &dyn HirDatabase, binders: chalk_ir::Binders<T>) -> crate::Binders<T> {
241 binders
242 }
243}
244
245impl ToChalk for crate::ConstrainedSubst {
246 type Chalk = chalk_ir::ConstrainedSubst<Interner>;
247
248 fn to_chalk(self, _db: &dyn HirDatabase) -> Self::Chalk {
249 self
250 }
251
252 fn from_chalk(db: &dyn HirDatabase, chalk: Self::Chalk) -> Self {
253 chalk
254 }
255}
256
257pub(super) fn make_binders<T>(value: T, num_vars: usize) -> chalk_ir::Binders<T> 74pub(super) fn make_binders<T>(value: T, num_vars: usize) -> chalk_ir::Binders<T>
258where 75where
259 T: HasInterner<Interner = Interner>, 76 T: HasInterner<Interner = Interner>,
@@ -276,7 +93,7 @@ pub(super) fn convert_where_clauses(
276 let generic_predicates = db.generic_predicates(def); 93 let generic_predicates = db.generic_predicates(def);
277 let mut result = Vec::with_capacity(generic_predicates.len()); 94 let mut result = Vec::with_capacity(generic_predicates.len());
278 for pred in generic_predicates.iter() { 95 for pred in generic_predicates.iter() {
279 result.push(pred.clone().substitute(&Interner, substs).to_chalk(db)); 96 result.push(pred.clone().substitute(&Interner, substs));
280 } 97 }
281 result 98 result
282} 99}
@@ -299,7 +116,7 @@ pub(super) fn generic_predicate_to_inline_bound(
299 } 116 }
300 let args_no_self = trait_ref.substitution.interned()[1..] 117 let args_no_self = trait_ref.substitution.interned()[1..]
301 .iter() 118 .iter()
302 .map(|ty| ty.clone().to_chalk(db).cast(&Interner)) 119 .map(|ty| ty.clone().cast(&Interner))
303 .collect(); 120 .collect();
304 let trait_bound = rust_ir::TraitBound { trait_id: trait_ref.trait_id, args_no_self }; 121 let trait_bound = rust_ir::TraitBound { trait_id: trait_ref.trait_id, args_no_self };
305 Some(chalk_ir::Binders::new(binders, rust_ir::InlineBound::TraitBound(trait_bound))) 122 Some(chalk_ir::Binders::new(binders, rust_ir::InlineBound::TraitBound(trait_bound)))
@@ -311,10 +128,10 @@ pub(super) fn generic_predicate_to_inline_bound(
311 let trait_ = projection_ty.trait_(db); 128 let trait_ = projection_ty.trait_(db);
312 let args_no_self = projection_ty.substitution.interned()[1..] 129 let args_no_self = projection_ty.substitution.interned()[1..]
313 .iter() 130 .iter()
314 .map(|ty| ty.clone().to_chalk(db).cast(&Interner)) 131 .map(|ty| ty.clone().cast(&Interner))
315 .collect(); 132 .collect();
316 let alias_eq_bound = rust_ir::AliasEqBound { 133 let alias_eq_bound = rust_ir::AliasEqBound {
317 value: ty.clone().to_chalk(db), 134 value: ty.clone(),
318 trait_bound: rust_ir::TraitBound { trait_id: trait_.to_chalk(db), args_no_self }, 135 trait_bound: rust_ir::TraitBound { trait_id: trait_.to_chalk(db), args_no_self },
319 associated_ty_id: projection_ty.associated_ty_id, 136 associated_ty_id: projection_ty.associated_ty_id,
320 parameters: Vec::new(), // FIXME we don't support generic associated types yet 137 parameters: Vec::new(), // FIXME we don't support generic associated types yet