aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty/src/traits/chalk.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir_ty/src/traits/chalk.rs')
-rw-r--r--crates/hir_ty/src/traits/chalk.rs75
1 files changed, 33 insertions, 42 deletions
diff --git a/crates/hir_ty/src/traits/chalk.rs b/crates/hir_ty/src/traits/chalk.rs
index 090f6492b..b8c390b2e 100644
--- a/crates/hir_ty/src/traits/chalk.rs
+++ b/crates/hir_ty/src/traits/chalk.rs
@@ -17,16 +17,14 @@ use super::ChalkContext;
17use crate::{ 17use crate::{
18 db::HirDatabase, 18 db::HirDatabase,
19 display::HirDisplay, 19 display::HirDisplay,
20 from_assoc_type_id, 20 from_assoc_type_id, make_only_type_binders,
21 method_resolution::{TyFingerprint, ALL_FLOAT_FPS, ALL_INT_FPS}, 21 method_resolution::{TyFingerprint, ALL_FLOAT_FPS, ALL_INT_FPS},
22 to_assoc_type_id, to_chalk_trait_id, 22 to_assoc_type_id, to_chalk_trait_id,
23 utils::generics, 23 utils::generics,
24 AliasEq, AliasTy, BoundVar, CallableDefId, DebruijnIndex, FnDefId, ProjectionTy, Substitution, 24 AliasEq, AliasTy, BoundVar, CallableDefId, DebruijnIndex, FnDefId, ProjectionTy, Substitution,
25 TraitRef, TraitRefExt, Ty, TyBuilder, TyExt, TyKind, WhereClause, 25 TraitRef, TraitRefExt, Ty, TyBuilder, TyExt, TyKind, WhereClause,
26}; 26};
27use mapping::{ 27use mapping::{convert_where_clauses, generic_predicate_to_inline_bound, TypeAliasAsValue};
28 convert_where_clauses, generic_predicate_to_inline_bound, make_binders, TypeAliasAsValue,
29};
30 28
31pub use self::interner::Interner; 29pub use self::interner::Interner;
32pub(crate) use self::interner::*; 30pub(crate) use self::interner::*;
@@ -86,7 +84,7 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> {
86 debug!("impls_for_trait {:?}", trait_id); 84 debug!("impls_for_trait {:?}", trait_id);
87 let trait_: hir_def::TraitId = from_chalk(self.db, trait_id); 85 let trait_: hir_def::TraitId = from_chalk(self.db, trait_id);
88 86
89 let ty: Ty = from_chalk(self.db, parameters[0].assert_ty_ref(&Interner).clone()); 87 let ty: Ty = parameters[0].assert_ty_ref(&Interner).clone();
90 88
91 fn binder_kind( 89 fn binder_kind(
92 ty: &Ty, 90 ty: &Ty,
@@ -187,16 +185,11 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> {
187 let (datas, binders) = (*datas).as_ref().into_value_and_skipped_binders(); 185 let (datas, binders) = (*datas).as_ref().into_value_and_skipped_binders();
188 let data = &datas.impl_traits[idx as usize]; 186 let data = &datas.impl_traits[idx as usize];
189 let bound = OpaqueTyDatumBound { 187 let bound = OpaqueTyDatumBound {
190 bounds: make_binders( 188 bounds: make_only_type_binders(
191 data.bounds
192 .skip_binders()
193 .iter()
194 .cloned()
195 .map(|b| b.to_chalk(self.db))
196 .collect(),
197 1, 189 1,
190 data.bounds.skip_binders().iter().cloned().collect(),
198 ), 191 ),
199 where_clauses: make_binders(vec![], 0), 192 where_clauses: make_only_type_binders(0, vec![]),
200 }; 193 };
201 chalk_ir::Binders::new(binders, bound) 194 chalk_ir::Binders::new(binders, bound)
202 } 195 }
@@ -244,25 +237,25 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> {
244 .intern(&Interner), 237 .intern(&Interner),
245 }); 238 });
246 let bound = OpaqueTyDatumBound { 239 let bound = OpaqueTyDatumBound {
247 bounds: make_binders( 240 bounds: make_only_type_binders(
241 1,
248 vec![ 242 vec![
249 crate::wrap_empty_binders(impl_bound).to_chalk(self.db), 243 crate::wrap_empty_binders(impl_bound),
250 crate::wrap_empty_binders(proj_bound).to_chalk(self.db), 244 crate::wrap_empty_binders(proj_bound),
251 ], 245 ],
252 1,
253 ), 246 ),
254 where_clauses: make_binders(vec![], 0), 247 where_clauses: make_only_type_binders(0, vec![]),
255 }; 248 };
256 // The opaque type has 1 parameter. 249 // The opaque type has 1 parameter.
257 make_binders(bound, 1) 250 make_only_type_binders(1, bound)
258 } else { 251 } else {
259 // If failed to find Symbol’s value as variable is void: Future::Output, return empty bounds as fallback. 252 // If failed to find Symbol’s value as variable is void: Future::Output, return empty bounds as fallback.
260 let bound = OpaqueTyDatumBound { 253 let bound = OpaqueTyDatumBound {
261 bounds: make_binders(vec![], 0), 254 bounds: make_only_type_binders(0, vec![]),
262 where_clauses: make_binders(vec![], 0), 255 where_clauses: make_only_type_binders(0, vec![]),
263 }; 256 };
264 // The opaque type has 1 parameter. 257 // The opaque type has 1 parameter.
265 make_binders(bound, 1) 258 make_only_type_binders(1, bound)
266 } 259 }
267 } 260 }
268 }; 261 };
@@ -272,7 +265,7 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> {
272 265
273 fn hidden_opaque_type(&self, _id: chalk_ir::OpaqueTyId<Interner>) -> chalk_ir::Ty<Interner> { 266 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 267 // FIXME: actually provide the hidden type; it is relevant for auto traits
275 TyKind::Error.intern(&Interner).to_chalk(self.db) 268 TyKind::Error.intern(&Interner)
276 } 269 }
277 270
278 fn is_object_safe(&self, _trait_id: chalk_ir::TraitId<Interner>) -> bool { 271 fn is_object_safe(&self, _trait_id: chalk_ir::TraitId<Interner>) -> bool {
@@ -293,29 +286,28 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> {
293 _closure_id: chalk_ir::ClosureId<Interner>, 286 _closure_id: chalk_ir::ClosureId<Interner>,
294 substs: &chalk_ir::Substitution<Interner>, 287 substs: &chalk_ir::Substitution<Interner>,
295 ) -> chalk_ir::Binders<rust_ir::FnDefInputsAndOutputDatum<Interner>> { 288 ) -> chalk_ir::Binders<rust_ir::FnDefInputsAndOutputDatum<Interner>> {
296 let sig_ty: Ty = 289 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"); 290 let sig = &sig_ty.callable_sig(self.db).expect("first closure param should be fn ptr");
299 let io = rust_ir::FnDefInputsAndOutputDatum { 291 let io = rust_ir::FnDefInputsAndOutputDatum {
300 argument_types: sig.params().iter().map(|ty| ty.clone().to_chalk(self.db)).collect(), 292 argument_types: sig.params().iter().cloned().collect(),
301 return_type: sig.ret().clone().to_chalk(self.db), 293 return_type: sig.ret().clone(),
302 }; 294 };
303 make_binders(io.shifted_in(&Interner), 0) 295 make_only_type_binders(0, io.shifted_in(&Interner))
304 } 296 }
305 fn closure_upvars( 297 fn closure_upvars(
306 &self, 298 &self,
307 _closure_id: chalk_ir::ClosureId<Interner>, 299 _closure_id: chalk_ir::ClosureId<Interner>,
308 _substs: &chalk_ir::Substitution<Interner>, 300 _substs: &chalk_ir::Substitution<Interner>,
309 ) -> chalk_ir::Binders<chalk_ir::Ty<Interner>> { 301 ) -> chalk_ir::Binders<chalk_ir::Ty<Interner>> {
310 let ty = TyBuilder::unit().to_chalk(self.db); 302 let ty = TyBuilder::unit();
311 make_binders(ty, 0) 303 make_only_type_binders(0, ty)
312 } 304 }
313 fn closure_fn_substitution( 305 fn closure_fn_substitution(
314 &self, 306 &self,
315 _closure_id: chalk_ir::ClosureId<Interner>, 307 _closure_id: chalk_ir::ClosureId<Interner>,
316 _substs: &chalk_ir::Substitution<Interner>, 308 _substs: &chalk_ir::Substitution<Interner>,
317 ) -> chalk_ir::Substitution<Interner> { 309 ) -> chalk_ir::Substitution<Interner> {
318 Substitution::empty(&Interner).to_chalk(self.db) 310 Substitution::empty(&Interner)
319 } 311 }
320 312
321 fn trait_name(&self, trait_id: chalk_ir::TraitId<Interner>) -> String { 313 fn trait_name(&self, trait_id: chalk_ir::TraitId<Interner>) -> String {
@@ -410,10 +402,10 @@ pub(crate) fn associated_ty_data_query(
410 let where_clauses = convert_where_clauses(db, type_alias.into(), &bound_vars); 402 let where_clauses = convert_where_clauses(db, type_alias.into(), &bound_vars);
411 let bound_data = rust_ir::AssociatedTyDatumBound { bounds, where_clauses }; 403 let bound_data = rust_ir::AssociatedTyDatumBound { bounds, where_clauses };
412 let datum = AssociatedTyDatum { 404 let datum = AssociatedTyDatum {
413 trait_id: trait_.to_chalk(db), 405 trait_id: to_chalk_trait_id(trait_),
414 id, 406 id,
415 name: type_alias, 407 name: type_alias,
416 binders: make_binders(bound_data, generic_params.len()), 408 binders: make_only_type_binders(generic_params.len(), bound_data),
417 }; 409 };
418 Arc::new(datum) 410 Arc::new(datum)
419} 411}
@@ -446,7 +438,7 @@ pub(crate) fn trait_datum_query(
446 lang_attr(db.upcast(), trait_).and_then(|name| well_known_trait_from_lang_attr(&name)); 438 lang_attr(db.upcast(), trait_).and_then(|name| well_known_trait_from_lang_attr(&name));
447 let trait_datum = TraitDatum { 439 let trait_datum = TraitDatum {
448 id: trait_id, 440 id: trait_id,
449 binders: make_binders(trait_datum_bound, bound_vars.len(&Interner)), 441 binders: make_only_type_binders(bound_vars.len(&Interner), trait_datum_bound),
450 flags, 442 flags,
451 associated_ty_ids, 443 associated_ty_ids,
452 well_known, 444 well_known,
@@ -515,7 +507,7 @@ pub(crate) fn struct_datum_query(
515 // FIXME set ADT kind 507 // FIXME set ADT kind
516 kind: rust_ir::AdtKind::Struct, 508 kind: rust_ir::AdtKind::Struct,
517 id: struct_id, 509 id: struct_id,
518 binders: make_binders(struct_datum_bound, num_params), 510 binders: make_only_type_binders(num_params, struct_datum_bound),
519 flags, 511 flags,
520 }; 512 };
521 Arc::new(struct_datum) 513 Arc::new(struct_datum)
@@ -563,7 +555,6 @@ fn impl_def_datum(
563 trait_ref.display(db), 555 trait_ref.display(db),
564 where_clauses 556 where_clauses
565 ); 557 );
566 let trait_ref = trait_ref.to_chalk(db);
567 558
568 let polarity = if negative { rust_ir::Polarity::Negative } else { rust_ir::Polarity::Positive }; 559 let polarity = if negative { rust_ir::Polarity::Negative } else { rust_ir::Polarity::Positive };
569 560
@@ -585,7 +576,7 @@ fn impl_def_datum(
585 .collect(); 576 .collect();
586 debug!("impl_datum: {:?}", impl_datum_bound); 577 debug!("impl_datum: {:?}", impl_datum_bound);
587 let impl_datum = ImplDatum { 578 let impl_datum = ImplDatum {
588 binders: make_binders(impl_datum_bound, bound_vars.len(&Interner)), 579 binders: make_only_type_binders(bound_vars.len(&Interner), impl_datum_bound),
589 impl_type, 580 impl_type,
590 polarity, 581 polarity,
591 associated_ty_value_ids, 582 associated_ty_value_ids,
@@ -624,7 +615,7 @@ fn type_alias_associated_ty_value(
624 .associated_type_by_name(&type_alias_data.name) 615 .associated_type_by_name(&type_alias_data.name)
625 .expect("assoc ty value should not exist"); // validated when building the impl data as well 616 .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(); 617 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) }; 618 let value_bound = rust_ir::AssociatedTyValueBound { ty };
628 let value = rust_ir::AssociatedTyValue { 619 let value = rust_ir::AssociatedTyValue {
629 impl_id: impl_id.to_chalk(db), 620 impl_id: impl_id.to_chalk(db),
630 associated_ty_id: to_assoc_type_id(assoc_ty), 621 associated_ty_id: to_assoc_type_id(assoc_ty),
@@ -645,13 +636,13 @@ pub(crate) fn fn_def_datum_query(
645 let where_clauses = convert_where_clauses(db, callable_def.into(), &bound_vars); 636 let where_clauses = convert_where_clauses(db, callable_def.into(), &bound_vars);
646 let bound = rust_ir::FnDefDatumBound { 637 let bound = rust_ir::FnDefDatumBound {
647 // Note: Chalk doesn't actually use this information yet as far as I am aware, but we provide it anyway 638 // 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( 639 inputs_and_output: make_only_type_binders(
640 0,
649 rust_ir::FnDefInputsAndOutputDatum { 641 rust_ir::FnDefInputsAndOutputDatum {
650 argument_types: sig.params().iter().map(|ty| ty.clone().to_chalk(db)).collect(), 642 argument_types: sig.params().iter().cloned().collect(),
651 return_type: sig.ret().clone().to_chalk(db), 643 return_type: sig.ret().clone(),
652 } 644 }
653 .shifted_in(&Interner), 645 .shifted_in(&Interner),
654 0,
655 ), 646 ),
656 where_clauses, 647 where_clauses,
657 }; 648 };