aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_ty/src/traits/chalk.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir_ty/src/traits/chalk.rs')
-rw-r--r--crates/ra_hir_ty/src/traits/chalk.rs99
1 files changed, 35 insertions, 64 deletions
diff --git a/crates/ra_hir_ty/src/traits/chalk.rs b/crates/ra_hir_ty/src/traits/chalk.rs
index c448aea65..1ef5baa05 100644
--- a/crates/ra_hir_ty/src/traits/chalk.rs
+++ b/crates/ra_hir_ty/src/traits/chalk.rs
@@ -12,15 +12,17 @@ use hir_def::{
12}; 12};
13use ra_db::{salsa::InternKey, CrateId}; 13use ra_db::{salsa::InternKey, CrateId};
14 14
15use super::{builtin, AssocTyValue, ChalkContext, Impl}; 15use super::ChalkContext;
16use crate::{ 16use crate::{
17 db::HirDatabase, 17 db::HirDatabase,
18 display::HirDisplay, 18 display::HirDisplay,
19 method_resolution::{TyFingerprint, ALL_FLOAT_FPS, ALL_INT_FPS}, 19 method_resolution::{TyFingerprint, ALL_FLOAT_FPS, ALL_INT_FPS},
20 utils::generics, 20 utils::generics,
21 CallableDef, DebruijnIndex, GenericPredicate, Substs, Ty, TypeCtor, 21 CallableDef, DebruijnIndex, FnSig, GenericPredicate, Substs, Ty, TypeCtor,
22};
23use mapping::{
24 convert_where_clauses, generic_predicate_to_inline_bound, make_binders, TypeAliasAsValue,
22}; 25};
23use mapping::{convert_where_clauses, generic_predicate_to_inline_bound, make_binders};
24 26
25pub use self::interner::*; 27pub use self::interner::*;
26 28
@@ -102,9 +104,9 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> {
102 let in_self = self.db.trait_impls_in_crate(self.krate); 104 let in_self = self.db.trait_impls_in_crate(self.krate);
103 let impl_maps = [in_deps, in_self]; 105 let impl_maps = [in_deps, in_self];
104 106
105 let id_to_chalk = |id: hir_def::ImplId| Impl::ImplDef(id).to_chalk(self.db); 107 let id_to_chalk = |id: hir_def::ImplId| id.to_chalk(self.db);
106 108
107 let mut result: Vec<_> = if fps.is_empty() { 109 let result: Vec<_> = if fps.is_empty() {
108 debug!("Unrestricted search for {:?} impls...", trait_); 110 debug!("Unrestricted search for {:?} impls...", trait_);
109 impl_maps 111 impl_maps
110 .iter() 112 .iter()
@@ -121,13 +123,6 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> {
121 .collect() 123 .collect()
122 }; 124 };
123 125
124 let arg: Option<Ty> =
125 parameters.get(1).map(|p| from_chalk(self.db, p.assert_ty_ref(&Interner).clone()));
126
127 builtin::get_builtin_impls(self.db, self.krate, &ty, &arg, trait_, |i| {
128 result.push(i.to_chalk(self.db))
129 });
130
131 debug!("impls_for_trait returned {} impls", result.len()); 126 debug!("impls_for_trait returned {} impls", result.len());
132 result 127 result
133 } 128 }
@@ -217,32 +212,40 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> {
217 _closure_id: chalk_ir::ClosureId<Interner>, 212 _closure_id: chalk_ir::ClosureId<Interner>,
218 _substs: &chalk_ir::Substitution<Interner>, 213 _substs: &chalk_ir::Substitution<Interner>,
219 ) -> rust_ir::ClosureKind { 214 ) -> rust_ir::ClosureKind {
220 // FIXME: implement closure support 215 // Fn is the closure kind that implements all three traits
221 unimplemented!() 216 rust_ir::ClosureKind::Fn
222 } 217 }
223 fn closure_inputs_and_output( 218 fn closure_inputs_and_output(
224 &self, 219 &self,
225 _closure_id: chalk_ir::ClosureId<Interner>, 220 _closure_id: chalk_ir::ClosureId<Interner>,
226 _substs: &chalk_ir::Substitution<Interner>, 221 substs: &chalk_ir::Substitution<Interner>,
227 ) -> chalk_ir::Binders<rust_ir::FnDefInputsAndOutputDatum<Interner>> { 222 ) -> chalk_ir::Binders<rust_ir::FnDefInputsAndOutputDatum<Interner>> {
228 // FIXME: implement closure support 223 let sig_ty: Ty =
229 unimplemented!() 224 from_chalk(self.db, substs.at(&Interner, 0).assert_ty_ref(&Interner).clone());
225 let sig = FnSig::from_fn_ptr_substs(
226 &sig_ty.substs().expect("first closure param should be fn ptr"),
227 false,
228 );
229 let io = rust_ir::FnDefInputsAndOutputDatum {
230 argument_types: sig.params().iter().map(|ty| ty.clone().to_chalk(self.db)).collect(),
231 return_type: sig.ret().clone().to_chalk(self.db),
232 };
233 make_binders(io.shifted_in(&Interner), 0)
230 } 234 }
231 fn closure_upvars( 235 fn closure_upvars(
232 &self, 236 &self,
233 _closure_id: chalk_ir::ClosureId<Interner>, 237 _closure_id: chalk_ir::ClosureId<Interner>,
234 _substs: &chalk_ir::Substitution<Interner>, 238 _substs: &chalk_ir::Substitution<Interner>,
235 ) -> chalk_ir::Binders<chalk_ir::Ty<Interner>> { 239 ) -> chalk_ir::Binders<chalk_ir::Ty<Interner>> {
236 // FIXME: implement closure support 240 let ty = Ty::unit().to_chalk(self.db);
237 unimplemented!() 241 make_binders(ty, 0)
238 } 242 }
239 fn closure_fn_substitution( 243 fn closure_fn_substitution(
240 &self, 244 &self,
241 _closure_id: chalk_ir::ClosureId<Interner>, 245 _closure_id: chalk_ir::ClosureId<Interner>,
242 _substs: &chalk_ir::Substitution<Interner>, 246 _substs: &chalk_ir::Substitution<Interner>,
243 ) -> chalk_ir::Substitution<Interner> { 247 ) -> chalk_ir::Substitution<Interner> {
244 // FIXME: implement closure support 248 Substs::empty().to_chalk(self.db)
245 unimplemented!()
246 } 249 }
247 250
248 fn trait_name(&self, _trait_id: chalk_ir::TraitId<Interner>) -> String { 251 fn trait_name(&self, _trait_id: chalk_ir::TraitId<Interner>) -> String {
@@ -417,11 +420,8 @@ pub(crate) fn impl_datum_query(
417) -> Arc<ImplDatum> { 420) -> Arc<ImplDatum> {
418 let _p = ra_prof::profile("impl_datum"); 421 let _p = ra_prof::profile("impl_datum");
419 debug!("impl_datum {:?}", impl_id); 422 debug!("impl_datum {:?}", impl_id);
420 let impl_: Impl = from_chalk(db, impl_id); 423 let impl_: hir_def::ImplId = from_chalk(db, impl_id);
421 match impl_ { 424 impl_def_datum(db, krate, impl_id, impl_)
422 Impl::ImplDef(impl_def) => impl_def_datum(db, krate, impl_id, impl_def),
423 _ => Arc::new(builtin::impl_datum(db, krate, impl_).to_chalk(db)),
424 }
425} 425}
426 426
427fn impl_def_datum( 427fn impl_def_datum(
@@ -472,7 +472,7 @@ fn impl_def_datum(
472 let name = &db.type_alias_data(type_alias).name; 472 let name = &db.type_alias_data(type_alias).name;
473 trait_data.associated_type_by_name(name).is_some() 473 trait_data.associated_type_by_name(name).is_some()
474 }) 474 })
475 .map(|type_alias| AssocTyValue::TypeAlias(type_alias).to_chalk(db)) 475 .map(|type_alias| TypeAliasAsValue(type_alias).to_chalk(db))
476 .collect(); 476 .collect();
477 debug!("impl_datum: {:?}", impl_datum_bound); 477 debug!("impl_datum: {:?}", impl_datum_bound);
478 let impl_datum = ImplDatum { 478 let impl_datum = ImplDatum {
@@ -489,13 +489,8 @@ pub(crate) fn associated_ty_value_query(
489 krate: CrateId, 489 krate: CrateId,
490 id: AssociatedTyValueId, 490 id: AssociatedTyValueId,
491) -> Arc<AssociatedTyValue> { 491) -> Arc<AssociatedTyValue> {
492 let data: AssocTyValue = from_chalk(db, id); 492 let type_alias: TypeAliasAsValue = from_chalk(db, id);
493 match data { 493 type_alias_associated_ty_value(db, krate, type_alias.0)
494 AssocTyValue::TypeAlias(type_alias) => {
495 type_alias_associated_ty_value(db, krate, type_alias)
496 }
497 _ => Arc::new(builtin::associated_ty_value(db, krate, data).to_chalk(db)),
498 }
499} 494}
500 495
501fn type_alias_associated_ty_value( 496fn type_alias_associated_ty_value(
@@ -518,7 +513,7 @@ fn type_alias_associated_ty_value(
518 let ty = db.ty(type_alias.into()); 513 let ty = db.ty(type_alias.into());
519 let value_bound = rust_ir::AssociatedTyValueBound { ty: ty.value.to_chalk(db) }; 514 let value_bound = rust_ir::AssociatedTyValueBound { ty: ty.value.to_chalk(db) };
520 let value = rust_ir::AssociatedTyValue { 515 let value = rust_ir::AssociatedTyValue {
521 impl_id: Impl::ImplDef(impl_id).to_chalk(db), 516 impl_id: impl_id.to_chalk(db),
522 associated_ty_id: assoc_ty.to_chalk(db), 517 associated_ty_id: assoc_ty.to_chalk(db),
523 value: make_binders(value_bound, ty.num_binders), 518 value: make_binders(value_bound, ty.num_binders),
524 }; 519 };
@@ -557,18 +552,6 @@ pub(crate) fn fn_def_datum_query(
557 Arc::new(datum) 552 Arc::new(datum)
558} 553}
559 554
560impl From<AdtId> for crate::TypeCtorId {
561 fn from(struct_id: AdtId) -> Self {
562 struct_id.0
563 }
564}
565
566impl From<crate::TypeCtorId> for AdtId {
567 fn from(type_ctor_id: crate::TypeCtorId) -> Self {
568 chalk_ir::AdtId(type_ctor_id)
569 }
570}
571
572impl From<FnDefId> for crate::CallableDefId { 555impl From<FnDefId> for crate::CallableDefId {
573 fn from(fn_def_id: FnDefId) -> Self { 556 fn from(fn_def_id: FnDefId) -> Self {
574 InternKey::from_intern_id(fn_def_id.0) 557 InternKey::from_intern_id(fn_def_id.0)
@@ -581,18 +564,6 @@ impl From<crate::CallableDefId> for FnDefId {
581 } 564 }
582} 565}
583 566
584impl From<ImplId> for crate::traits::GlobalImplId {
585 fn from(impl_id: ImplId) -> Self {
586 InternKey::from_intern_id(impl_id.0)
587 }
588}
589
590impl From<crate::traits::GlobalImplId> for ImplId {
591 fn from(impl_id: crate::traits::GlobalImplId) -> Self {
592 chalk_ir::ImplId(impl_id.as_intern_id())
593 }
594}
595
596impl From<OpaqueTyId> for crate::db::InternedOpaqueTyId { 567impl From<OpaqueTyId> for crate::db::InternedOpaqueTyId {
597 fn from(id: OpaqueTyId) -> Self { 568 fn from(id: OpaqueTyId) -> Self {
598 InternKey::from_intern_id(id.0) 569 InternKey::from_intern_id(id.0)
@@ -605,14 +576,14 @@ impl From<crate::db::InternedOpaqueTyId> for OpaqueTyId {
605 } 576 }
606} 577}
607 578
608impl From<rust_ir::AssociatedTyValueId<Interner>> for crate::traits::AssocTyValueId { 579impl From<chalk_ir::ClosureId<Interner>> for crate::db::ClosureId {
609 fn from(id: rust_ir::AssociatedTyValueId<Interner>) -> Self { 580 fn from(id: chalk_ir::ClosureId<Interner>) -> Self {
610 Self::from_intern_id(id.0) 581 Self::from_intern_id(id.0)
611 } 582 }
612} 583}
613 584
614impl From<crate::traits::AssocTyValueId> for rust_ir::AssociatedTyValueId<Interner> { 585impl From<crate::db::ClosureId> for chalk_ir::ClosureId<Interner> {
615 fn from(assoc_ty_value_id: crate::traits::AssocTyValueId) -> Self { 586 fn from(id: crate::db::ClosureId) -> Self {
616 rust_ir::AssociatedTyValueId(assoc_ty_value_id.as_intern_id()) 587 chalk_ir::ClosureId(id.as_intern_id())
617 } 588 }
618} 589}