aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_ty/src/traits
diff options
context:
space:
mode:
authorFlorian Diebold <[email protected]>2020-07-12 14:26:02 +0100
committerFlorian Diebold <[email protected]>2020-07-15 21:04:49 +0100
commita48843a16a2306399f2f6a78c69d9192a6480c88 (patch)
tree2fbaf1c22c631e9e2278e6a33940ccf6ea98037c /crates/ra_hir_ty/src/traits
parentb63e23e98e7dfbe57de93ebe256254825512e148 (diff)
Use Chalk closure support
Diffstat (limited to 'crates/ra_hir_ty/src/traits')
-rw-r--r--crates/ra_hir_ty/src/traits/builtin.rs178
-rw-r--r--crates/ra_hir_ty/src/traits/chalk.rs87
-rw-r--r--crates/ra_hir_ty/src/traits/chalk/mapping.rs97
3 files changed, 68 insertions, 294 deletions
diff --git a/crates/ra_hir_ty/src/traits/builtin.rs b/crates/ra_hir_ty/src/traits/builtin.rs
deleted file mode 100644
index 60cc9a9f5..000000000
--- a/crates/ra_hir_ty/src/traits/builtin.rs
+++ /dev/null
@@ -1,178 +0,0 @@
1//! This module provides the built-in trait implementations, e.g. to make
2//! closures implement `Fn`.
3use hir_def::{expr::Expr, TraitId, TypeAliasId};
4use hir_expand::name::name;
5use ra_db::CrateId;
6
7use super::{AssocTyValue, Impl};
8use crate::{
9 db::HirDatabase, ApplicationTy, BoundVar, DebruijnIndex, Substs, TraitRef, Ty, TypeCtor,
10};
11
12pub(super) struct BuiltinImplData {
13 pub num_vars: usize,
14 pub trait_ref: TraitRef,
15 pub where_clauses: Vec<super::GenericPredicate>,
16 pub assoc_ty_values: Vec<AssocTyValue>,
17}
18
19pub(super) struct BuiltinImplAssocTyValueData {
20 pub impl_: Impl,
21 pub assoc_ty_id: TypeAliasId,
22 pub num_vars: usize,
23 pub value: Ty,
24}
25
26pub(super) fn get_builtin_impls(
27 db: &dyn HirDatabase,
28 krate: CrateId,
29 ty: &Ty,
30 // The first argument for the trait, if present
31 _arg: &Option<Ty>,
32 trait_: TraitId,
33 mut callback: impl FnMut(Impl),
34) {
35 // Note: since impl_datum needs to be infallible, we need to make sure here
36 // that we have all prerequisites to build the respective impls.
37 if let Ty::Apply(ApplicationTy { ctor: TypeCtor::Closure { def, expr }, .. }) = ty {
38 for &fn_trait in [super::FnTrait::FnOnce, super::FnTrait::FnMut, super::FnTrait::Fn].iter()
39 {
40 if let Some(actual_trait) = fn_trait.get_id(db, krate) {
41 if trait_ == actual_trait {
42 let impl_ = super::ClosureFnTraitImplData { def: *def, expr: *expr, fn_trait };
43 if check_closure_fn_trait_impl_prerequisites(db, krate, impl_) {
44 callback(Impl::ClosureFnTraitImpl(impl_));
45 }
46 }
47 }
48 }
49 }
50}
51
52pub(super) fn impl_datum(db: &dyn HirDatabase, krate: CrateId, impl_: Impl) -> BuiltinImplData {
53 match impl_ {
54 Impl::ImplDef(_) => unreachable!(),
55 Impl::ClosureFnTraitImpl(data) => closure_fn_trait_impl_datum(db, krate, data),
56 }
57}
58
59pub(super) fn associated_ty_value(
60 db: &dyn HirDatabase,
61 krate: CrateId,
62 data: AssocTyValue,
63) -> BuiltinImplAssocTyValueData {
64 match data {
65 AssocTyValue::TypeAlias(_) => unreachable!(),
66 AssocTyValue::ClosureFnTraitImplOutput(data) => {
67 closure_fn_trait_output_assoc_ty_value(db, krate, data)
68 }
69 }
70}
71
72// Closure Fn trait impls
73
74fn check_closure_fn_trait_impl_prerequisites(
75 db: &dyn HirDatabase,
76 krate: CrateId,
77 data: super::ClosureFnTraitImplData,
78) -> bool {
79 // the respective Fn/FnOnce/FnMut trait needs to exist
80 if data.fn_trait.get_id(db, krate).is_none() {
81 return false;
82 }
83
84 // FIXME: there are more assumptions that we should probably check here:
85 // the traits having no type params, FnOnce being a supertrait
86
87 // the FnOnce trait needs to exist and have an assoc type named Output
88 let fn_once_trait = match (super::FnTrait::FnOnce).get_id(db, krate) {
89 Some(t) => t,
90 None => return false,
91 };
92 db.trait_data(fn_once_trait).associated_type_by_name(&name![Output]).is_some()
93}
94
95fn closure_fn_trait_impl_datum(
96 db: &dyn HirDatabase,
97 krate: CrateId,
98 data: super::ClosureFnTraitImplData,
99) -> BuiltinImplData {
100 // for some closure |X, Y| -> Z:
101 // impl<T, U, V> Fn<(T, U)> for closure<fn(T, U) -> V> { Output = V }
102
103 let trait_ = data
104 .fn_trait
105 .get_id(db, krate) // get corresponding fn trait
106 // the existence of the Fn trait has been checked before
107 .expect("fn trait for closure impl missing");
108
109 let num_args: u16 = match &db.body(data.def)[data.expr] {
110 Expr::Lambda { args, .. } => args.len() as u16,
111 _ => {
112 log::warn!("closure for closure type {:?} not found", data);
113 0
114 }
115 };
116
117 let arg_ty = Ty::apply(
118 TypeCtor::Tuple { cardinality: num_args },
119 Substs::builder(num_args as usize)
120 .fill_with_bound_vars(DebruijnIndex::INNERMOST, 0)
121 .build(),
122 );
123 let sig_ty = Ty::apply(
124 TypeCtor::FnPtr { num_args, is_varargs: false },
125 Substs::builder(num_args as usize + 1)
126 .fill_with_bound_vars(DebruijnIndex::INNERMOST, 0)
127 .build(),
128 );
129
130 let self_ty = Ty::apply_one(TypeCtor::Closure { def: data.def, expr: data.expr }, sig_ty);
131
132 let trait_ref = TraitRef {
133 trait_,
134 substs: Substs::build_for_def(db, trait_).push(self_ty).push(arg_ty).build(),
135 };
136
137 let output_ty_id = AssocTyValue::ClosureFnTraitImplOutput(data);
138
139 BuiltinImplData {
140 num_vars: num_args as usize + 1,
141 trait_ref,
142 where_clauses: Vec::new(),
143 assoc_ty_values: vec![output_ty_id],
144 }
145}
146
147fn closure_fn_trait_output_assoc_ty_value(
148 db: &dyn HirDatabase,
149 krate: CrateId,
150 data: super::ClosureFnTraitImplData,
151) -> BuiltinImplAssocTyValueData {
152 let impl_ = Impl::ClosureFnTraitImpl(data);
153
154 let num_args: u16 = match &db.body(data.def)[data.expr] {
155 Expr::Lambda { args, .. } => args.len() as u16,
156 _ => {
157 log::warn!("closure for closure type {:?} not found", data);
158 0
159 }
160 };
161
162 let output_ty = Ty::Bound(BoundVar::new(DebruijnIndex::INNERMOST, num_args.into()));
163
164 let fn_once_trait =
165 (super::FnTrait::FnOnce).get_id(db, krate).expect("assoc ty value should not exist");
166
167 let output_ty_id = db
168 .trait_data(fn_once_trait)
169 .associated_type_by_name(&name![Output])
170 .expect("assoc ty value should not exist");
171
172 BuiltinImplAssocTyValueData {
173 impl_,
174 assoc_ty_id: output_ty_id,
175 num_vars: num_args as usize + 1,
176 value: output_ty,
177 }
178}
diff --git a/crates/ra_hir_ty/src/traits/chalk.rs b/crates/ra_hir_ty/src/traits/chalk.rs
index c448aea65..7f8ba2f12 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 };
@@ -581,18 +576,6 @@ impl From<crate::CallableDefId> for FnDefId {
581 } 576 }
582} 577}
583 578
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 { 579impl From<OpaqueTyId> for crate::db::InternedOpaqueTyId {
597 fn from(id: OpaqueTyId) -> Self { 580 fn from(id: OpaqueTyId) -> Self {
598 InternKey::from_intern_id(id.0) 581 InternKey::from_intern_id(id.0)
@@ -605,14 +588,14 @@ impl From<crate::db::InternedOpaqueTyId> for OpaqueTyId {
605 } 588 }
606} 589}
607 590
608impl From<rust_ir::AssociatedTyValueId<Interner>> for crate::traits::AssocTyValueId { 591impl From<chalk_ir::ClosureId<Interner>> for crate::db::ClosureId {
609 fn from(id: rust_ir::AssociatedTyValueId<Interner>) -> Self { 592 fn from(id: chalk_ir::ClosureId<Interner>) -> Self {
610 Self::from_intern_id(id.0) 593 Self::from_intern_id(id.0)
611 } 594 }
612} 595}
613 596
614impl From<crate::traits::AssocTyValueId> for rust_ir::AssociatedTyValueId<Interner> { 597impl From<crate::db::ClosureId> for chalk_ir::ClosureId<Interner> {
615 fn from(assoc_ty_value_id: crate::traits::AssocTyValueId) -> Self { 598 fn from(id: crate::db::ClosureId) -> Self {
616 rust_ir::AssociatedTyValueId(assoc_ty_value_id.as_intern_id()) 599 chalk_ir::ClosureId(id.as_intern_id())
617 } 600 }
618} 601}
diff --git a/crates/ra_hir_ty/src/traits/chalk/mapping.rs b/crates/ra_hir_ty/src/traits/chalk/mapping.rs
index 3ebb55f77..796947e69 100644
--- a/crates/ra_hir_ty/src/traits/chalk/mapping.rs
+++ b/crates/ra_hir_ty/src/traits/chalk/mapping.rs
@@ -15,7 +15,7 @@ use ra_db::salsa::InternKey;
15use crate::{ 15use crate::{
16 db::HirDatabase, 16 db::HirDatabase,
17 primitive::{FloatBitness, FloatTy, IntBitness, IntTy, Signedness}, 17 primitive::{FloatBitness, FloatTy, IntBitness, IntTy, Signedness},
18 traits::{builtin, AssocTyValue, Canonical, Impl, Obligation}, 18 traits::{Canonical, Obligation},
19 ApplicationTy, CallableDef, GenericPredicate, InEnvironment, OpaqueTy, OpaqueTyId, 19 ApplicationTy, CallableDef, GenericPredicate, InEnvironment, OpaqueTy, OpaqueTyId,
20 ProjectionPredicate, ProjectionTy, Substs, TraitEnvironment, TraitRef, Ty, TyKind, TypeCtor, 20 ProjectionPredicate, ProjectionTy, Substs, TraitEnvironment, TraitRef, Ty, TyKind, TypeCtor,
21}; 21};
@@ -311,8 +311,15 @@ impl ToChalk for TypeCtor {
311 } 311 }
312 TypeCtor::Never => TypeName::Never, 312 TypeCtor::Never => TypeName::Never,
313 313
314 // FIXME convert these 314 TypeCtor::Closure { def, expr } => {
315 TypeCtor::Adt(_) | TypeCtor::FnPtr { .. } | TypeCtor::Closure { .. } => { 315 let closure_id = db.intern_closure((def, expr));
316 TypeName::Closure(closure_id.into())
317 }
318
319 TypeCtor::FnPtr { .. } => panic!("Trying to convert FnPtr to TypeName"),
320
321 TypeCtor::Adt(_) => {
322 // FIXME no interning needed anymore
316 // other TypeCtors get interned and turned into a chalk StructId 323 // other TypeCtors get interned and turned into a chalk StructId
317 let struct_id = db.intern_type_ctor(self).into(); 324 let struct_id = db.intern_type_ctor(self).into();
318 TypeName::Adt(struct_id) 325 TypeName::Adt(struct_id)
@@ -355,13 +362,16 @@ impl ToChalk for TypeCtor {
355 let callable_def = from_chalk(db, fn_def_id); 362 let callable_def = from_chalk(db, fn_def_id);
356 TypeCtor::FnDef(callable_def) 363 TypeCtor::FnDef(callable_def)
357 } 364 }
365 TypeName::Array => TypeCtor::Array,
358 366
359 TypeName::Array | TypeName::Error => { 367 TypeName::Closure(id) => {
360 // this should not be reached, since we don't represent TypeName::Error with TypeCtor 368 let id: crate::db::ClosureId = id.into();
361 unreachable!() 369 let (def, expr) = db.lookup_intern_closure(id);
370 TypeCtor::Closure { def, expr }
362 } 371 }
363 TypeName::Closure(_) => { 372
364 // FIXME: implement closure support 373 TypeName::Error => {
374 // this should not be reached, since we don't represent TypeName::Error with TypeCtor
365 unreachable!() 375 unreachable!()
366 } 376 }
367 } 377 }
@@ -433,15 +443,15 @@ impl ToChalk for Mutability {
433 } 443 }
434} 444}
435 445
436impl ToChalk for Impl { 446impl ToChalk for hir_def::ImplId {
437 type Chalk = ImplId; 447 type Chalk = ImplId;
438 448
439 fn to_chalk(self, db: &dyn HirDatabase) -> ImplId { 449 fn to_chalk(self, _db: &dyn HirDatabase) -> ImplId {
440 db.intern_chalk_impl(self).into() 450 chalk_ir::ImplId(self.as_intern_id())
441 } 451 }
442 452
443 fn from_chalk(db: &dyn HirDatabase, impl_id: ImplId) -> Impl { 453 fn from_chalk(_db: &dyn HirDatabase, impl_id: ImplId) -> hir_def::ImplId {
444 db.lookup_intern_chalk_impl(impl_id.into()) 454 InternKey::from_intern_id(impl_id.0)
445 } 455 }
446} 456}
447 457
@@ -469,15 +479,20 @@ impl ToChalk for TypeAliasId {
469 } 479 }
470} 480}
471 481
472impl ToChalk for AssocTyValue { 482pub struct TypeAliasAsValue(pub TypeAliasId);
483
484impl ToChalk for TypeAliasAsValue {
473 type Chalk = AssociatedTyValueId; 485 type Chalk = AssociatedTyValueId;
474 486
475 fn to_chalk(self, db: &dyn HirDatabase) -> AssociatedTyValueId { 487 fn to_chalk(self, _db: &dyn HirDatabase) -> AssociatedTyValueId {
476 db.intern_assoc_ty_value(self).into() 488 rust_ir::AssociatedTyValueId(self.0.as_intern_id())
477 } 489 }
478 490
479 fn from_chalk(db: &dyn HirDatabase, assoc_ty_value_id: AssociatedTyValueId) -> AssocTyValue { 491 fn from_chalk(
480 db.lookup_intern_assoc_ty_value(assoc_ty_value_id.into()) 492 _db: &dyn HirDatabase,
493 assoc_ty_value_id: AssociatedTyValueId,
494 ) -> TypeAliasAsValue {
495 TypeAliasAsValue(TypeAliasId::from_intern_id(assoc_ty_value_id.0))
481 } 496 }
482} 497}
483 498
@@ -686,52 +701,6 @@ where
686 } 701 }
687} 702}
688 703
689impl ToChalk for builtin::BuiltinImplData {
690 type Chalk = ImplDatum;
691
692 fn to_chalk(self, db: &dyn HirDatabase) -> ImplDatum {
693 let impl_type = rust_ir::ImplType::External;
694 let where_clauses = self.where_clauses.into_iter().map(|w| w.to_chalk(db)).collect();
695
696 let impl_datum_bound =
697 rust_ir::ImplDatumBound { trait_ref: self.trait_ref.to_chalk(db), where_clauses };
698 let associated_ty_value_ids =
699 self.assoc_ty_values.into_iter().map(|v| v.to_chalk(db)).collect();
700 rust_ir::ImplDatum {
701 binders: make_binders(impl_datum_bound, self.num_vars),
702 impl_type,
703 polarity: rust_ir::Polarity::Positive,
704 associated_ty_value_ids,
705 }
706 }
707
708 fn from_chalk(_db: &dyn HirDatabase, _data: ImplDatum) -> Self {
709 unimplemented!()
710 }
711}
712
713impl ToChalk for builtin::BuiltinImplAssocTyValueData {
714 type Chalk = AssociatedTyValue;
715
716 fn to_chalk(self, db: &dyn HirDatabase) -> AssociatedTyValue {
717 let ty = self.value.to_chalk(db);
718 let value_bound = rust_ir::AssociatedTyValueBound { ty };
719
720 rust_ir::AssociatedTyValue {
721 associated_ty_id: self.assoc_ty_id.to_chalk(db),
722 impl_id: self.impl_.to_chalk(db),
723 value: make_binders(value_bound, self.num_vars),
724 }
725 }
726
727 fn from_chalk(
728 _db: &dyn HirDatabase,
729 _data: AssociatedTyValue,
730 ) -> builtin::BuiltinImplAssocTyValueData {
731 unimplemented!()
732 }
733}
734
735pub(super) fn make_binders<T>(value: T, num_vars: usize) -> chalk_ir::Binders<T> 704pub(super) fn make_binders<T>(value: T, num_vars: usize) -> chalk_ir::Binders<T>
736where 705where
737 T: HasInterner<Interner = Interner>, 706 T: HasInterner<Interner = Interner>,