diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_hir_ty/Cargo.toml | 7 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/db.rs | 35 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/traits.rs | 6 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/traits/chalk.rs | 180 |
4 files changed, 103 insertions, 125 deletions
diff --git a/crates/ra_hir_ty/Cargo.toml b/crates/ra_hir_ty/Cargo.toml index d277bf2bc..60793db44 100644 --- a/crates/ra_hir_ty/Cargo.toml +++ b/crates/ra_hir_ty/Cargo.toml | |||
@@ -21,10 +21,9 @@ ra_prof = { path = "../ra_prof" } | |||
21 | ra_syntax = { path = "../ra_syntax" } | 21 | ra_syntax = { path = "../ra_syntax" } |
22 | test_utils = { path = "../test_utils" } | 22 | test_utils = { path = "../test_utils" } |
23 | 23 | ||
24 | # https://github.com/rust-lang/chalk/pull/294 | 24 | chalk-solve = { git = "https://github.com/rust-lang/chalk.git", rev = "ff65b5ac9860f3c36bd892c865ab23d5ff0bbae5" } |
25 | chalk-solve = { git = "https://github.com/rust-lang/chalk.git", rev = "151949dece8117d180b5d197a7afa968c3ba14bb" } | 25 | chalk-rust-ir = { git = "https://github.com/rust-lang/chalk.git", rev = "ff65b5ac9860f3c36bd892c865ab23d5ff0bbae5" } |
26 | chalk-rust-ir = { git = "https://github.com/rust-lang/chalk.git", rev = "151949dece8117d180b5d197a7afa968c3ba14bb" } | 26 | chalk-ir = { git = "https://github.com/rust-lang/chalk.git", rev = "ff65b5ac9860f3c36bd892c865ab23d5ff0bbae5" } |
27 | chalk-ir = { git = "https://github.com/rust-lang/chalk.git", rev = "151949dece8117d180b5d197a7afa968c3ba14bb" } | ||
28 | 27 | ||
29 | lalrpop-intern = "0.15.1" | 28 | lalrpop-intern = "0.15.1" |
30 | 29 | ||
diff --git a/crates/ra_hir_ty/src/db.rs b/crates/ra_hir_ty/src/db.rs index 222a36a9f..d52f65b83 100644 --- a/crates/ra_hir_ty/src/db.rs +++ b/crates/ra_hir_ty/src/db.rs | |||
@@ -10,7 +10,7 @@ use ra_db::{salsa, CrateId}; | |||
10 | 10 | ||
11 | use crate::{ | 11 | use crate::{ |
12 | method_resolution::CrateImplBlocks, | 12 | method_resolution::CrateImplBlocks, |
13 | traits::{AssocTyValue, Impl}, | 13 | traits::{chalk, AssocTyValue, Impl}, |
14 | CallableDef, FnSig, GenericPredicate, InferenceResult, Substs, TraitRef, Ty, TyDefId, TypeCtor, | 14 | CallableDef, FnSig, GenericPredicate, InferenceResult, Substs, TraitRef, Ty, TyDefId, TypeCtor, |
15 | ValueTyDefId, | 15 | ValueTyDefId, |
16 | }; | 16 | }; |
@@ -77,39 +77,24 @@ pub trait HirDatabase: DefDatabase { | |||
77 | #[salsa::interned] | 77 | #[salsa::interned] |
78 | fn intern_assoc_ty_value(&self, assoc_ty_value: AssocTyValue) -> crate::traits::AssocTyValueId; | 78 | fn intern_assoc_ty_value(&self, assoc_ty_value: AssocTyValue) -> crate::traits::AssocTyValueId; |
79 | 79 | ||
80 | #[salsa::invoke(crate::traits::chalk::associated_ty_data_query)] | 80 | #[salsa::invoke(chalk::associated_ty_data_query)] |
81 | fn associated_ty_data( | 81 | fn associated_ty_data(&self, id: chalk::AssocTypeId) -> Arc<chalk::AssociatedTyDatum>; |
82 | &self, | ||
83 | id: chalk_ir::TypeId, | ||
84 | ) -> Arc<chalk_rust_ir::AssociatedTyDatum<chalk_ir::family::ChalkIr>>; | ||
85 | 82 | ||
86 | #[salsa::invoke(crate::traits::chalk::trait_datum_query)] | 83 | #[salsa::invoke(chalk::trait_datum_query)] |
87 | fn trait_datum( | 84 | fn trait_datum(&self, krate: CrateId, trait_id: chalk::TraitId) -> Arc<chalk::TraitDatum>; |
88 | &self, | ||
89 | krate: CrateId, | ||
90 | trait_id: chalk_ir::TraitId, | ||
91 | ) -> Arc<chalk_rust_ir::TraitDatum<chalk_ir::family::ChalkIr>>; | ||
92 | 85 | ||
93 | #[salsa::invoke(crate::traits::chalk::struct_datum_query)] | 86 | #[salsa::invoke(chalk::struct_datum_query)] |
94 | fn struct_datum( | 87 | fn struct_datum(&self, krate: CrateId, struct_id: chalk::StructId) -> Arc<chalk::StructDatum>; |
95 | &self, | ||
96 | krate: CrateId, | ||
97 | struct_id: chalk_ir::StructId, | ||
98 | ) -> Arc<chalk_rust_ir::StructDatum<chalk_ir::family::ChalkIr>>; | ||
99 | 88 | ||
100 | #[salsa::invoke(crate::traits::chalk::impl_datum_query)] | 89 | #[salsa::invoke(crate::traits::chalk::impl_datum_query)] |
101 | fn impl_datum( | 90 | fn impl_datum(&self, krate: CrateId, impl_id: chalk::ImplId) -> Arc<chalk::ImplDatum>; |
102 | &self, | ||
103 | krate: CrateId, | ||
104 | impl_id: chalk_ir::ImplId, | ||
105 | ) -> Arc<chalk_rust_ir::ImplDatum<chalk_ir::family::ChalkIr>>; | ||
106 | 91 | ||
107 | #[salsa::invoke(crate::traits::chalk::associated_ty_value_query)] | 92 | #[salsa::invoke(crate::traits::chalk::associated_ty_value_query)] |
108 | fn associated_ty_value( | 93 | fn associated_ty_value( |
109 | &self, | 94 | &self, |
110 | krate: CrateId, | 95 | krate: CrateId, |
111 | id: chalk_rust_ir::AssociatedTyValueId, | 96 | id: chalk::AssociatedTyValueId, |
112 | ) -> Arc<chalk_rust_ir::AssociatedTyValue<chalk_ir::family::ChalkIr>>; | 97 | ) -> Arc<chalk::AssociatedTyValue>; |
113 | 98 | ||
114 | #[salsa::invoke(crate::traits::trait_solve_query)] | 99 | #[salsa::invoke(crate::traits::trait_solve_query)] |
115 | fn trait_solve( | 100 | fn trait_solve( |
diff --git a/crates/ra_hir_ty/src/traits.rs b/crates/ra_hir_ty/src/traits.rs index d49f8fb4b..46e17f0b8 100644 --- a/crates/ra_hir_ty/src/traits.rs +++ b/crates/ra_hir_ty/src/traits.rs | |||
@@ -209,9 +209,9 @@ fn solution_from_chalk( | |||
209 | .parameters | 209 | .parameters |
210 | .into_iter() | 210 | .into_iter() |
211 | .map(|p| { | 211 | .map(|p| { |
212 | let ty = match p { | 212 | let ty = match p.ty() { |
213 | chalk_ir::Parameter(chalk_ir::ParameterKind::Ty(ty)) => from_chalk(db, ty), | 213 | Some(ty) => from_chalk(db, ty.clone()), |
214 | chalk_ir::Parameter(chalk_ir::ParameterKind::Lifetime(_)) => unimplemented!(), | 214 | None => unimplemented!(), |
215 | }; | 215 | }; |
216 | ty | 216 | ty |
217 | }) | 217 | }) |
diff --git a/crates/ra_hir_ty/src/traits/chalk.rs b/crates/ra_hir_ty/src/traits/chalk.rs index 5eb032d86..3a91a374d 100644 --- a/crates/ra_hir_ty/src/traits/chalk.rs +++ b/crates/ra_hir_ty/src/traits/chalk.rs | |||
@@ -3,15 +3,9 @@ use std::sync::Arc; | |||
3 | 3 | ||
4 | use log::debug; | 4 | use log::debug; |
5 | 5 | ||
6 | use chalk_ir::{ | 6 | use chalk_ir::{cast::Cast, family::ChalkIr, Parameter, PlaceholderIndex, TypeName, UniverseIndex}; |
7 | cast::Cast, family::ChalkIr, Identifier, Parameter, PlaceholderIndex, TypeId, TypeKindId, | ||
8 | TypeName, UniverseIndex, | ||
9 | }; | ||
10 | use chalk_rust_ir::{AssociatedTyDatum, AssociatedTyValue, ImplDatum, StructDatum, TraitDatum}; | ||
11 | 7 | ||
12 | use hir_def::{ | 8 | use hir_def::{AssocContainerId, AssocItemId, GenericDefId, HasModule, Lookup, TypeAliasId}; |
13 | AssocContainerId, AssocItemId, GenericDefId, HasModule, ImplId, Lookup, TraitId, TypeAliasId, | ||
14 | }; | ||
15 | use ra_db::{ | 9 | use ra_db::{ |
16 | salsa::{InternId, InternKey}, | 10 | salsa::{InternId, InternKey}, |
17 | CrateId, | 11 | CrateId, |
@@ -23,9 +17,20 @@ use crate::{ | |||
23 | ProjectionTy, Substs, TraitRef, Ty, TypeCtor, TypeWalk, | 17 | ProjectionTy, Substs, TraitRef, Ty, TypeCtor, TypeWalk, |
24 | }; | 18 | }; |
25 | 19 | ||
20 | pub type TypeFamily = chalk_ir::family::ChalkIr; // TODO use everywhere | ||
21 | pub type AssocTypeId = chalk_ir::AssocTypeId<TypeFamily>; | ||
22 | pub type AssociatedTyDatum = chalk_rust_ir::AssociatedTyDatum<TypeFamily>; | ||
23 | pub type TraitId = chalk_ir::TraitId<TypeFamily>; | ||
24 | pub type TraitDatum = chalk_rust_ir::TraitDatum<TypeFamily>; | ||
25 | pub type StructId = chalk_ir::StructId<TypeFamily>; | ||
26 | pub type StructDatum = chalk_rust_ir::StructDatum<TypeFamily>; | ||
27 | pub type ImplId = chalk_ir::ImplId<TypeFamily>; | ||
28 | pub type ImplDatum = chalk_rust_ir::ImplDatum<TypeFamily>; | ||
29 | pub type AssociatedTyValueId = chalk_rust_ir::AssociatedTyValueId; | ||
30 | pub type AssociatedTyValue = chalk_rust_ir::AssociatedTyValue<TypeFamily>; | ||
31 | |||
26 | /// This represents a trait whose name we could not resolve. | 32 | /// This represents a trait whose name we could not resolve. |
27 | const UNKNOWN_TRAIT: chalk_ir::TraitId = | 33 | const UNKNOWN_TRAIT: TraitId = chalk_ir::TraitId(chalk_ir::RawId { index: u32::max_value() }); |
28 | chalk_ir::TraitId(chalk_ir::RawId { index: u32::max_value() }); | ||
29 | 34 | ||
30 | pub(super) trait ToChalk { | 35 | pub(super) trait ToChalk { |
31 | type Chalk; | 36 | type Chalk; |
@@ -53,7 +58,7 @@ impl ToChalk for Ty { | |||
53 | _ => { | 58 | _ => { |
54 | // other TypeCtors get interned and turned into a chalk StructId | 59 | // other TypeCtors get interned and turned into a chalk StructId |
55 | let struct_id = apply_ty.ctor.to_chalk(db); | 60 | let struct_id = apply_ty.ctor.to_chalk(db); |
56 | TypeName::TypeKindId(struct_id.into()) | 61 | TypeName::Struct(struct_id.into()) |
57 | } | 62 | } |
58 | }; | 63 | }; |
59 | let parameters = apply_ty.parameters.to_chalk(db); | 64 | let parameters = apply_ty.parameters.to_chalk(db); |
@@ -71,11 +76,13 @@ impl ToChalk for Ty { | |||
71 | Ty::Infer(_infer_ty) => panic!("uncanonicalized infer ty"), | 76 | Ty::Infer(_infer_ty) => panic!("uncanonicalized infer ty"), |
72 | Ty::Dyn(predicates) => { | 77 | Ty::Dyn(predicates) => { |
73 | let where_clauses = predicates.iter().cloned().map(|p| p.to_chalk(db)).collect(); | 78 | let where_clauses = predicates.iter().cloned().map(|p| p.to_chalk(db)).collect(); |
74 | chalk_ir::TyData::Dyn(make_binders(where_clauses, 1)).intern() | 79 | let bounded_ty = chalk_ir::BoundedTy { bounds: make_binders(where_clauses, 1) }; |
80 | chalk_ir::TyData::Dyn(bounded_ty).intern() | ||
75 | } | 81 | } |
76 | Ty::Opaque(predicates) => { | 82 | Ty::Opaque(predicates) => { |
77 | let where_clauses = predicates.iter().cloned().map(|p| p.to_chalk(db)).collect(); | 83 | let where_clauses = predicates.iter().cloned().map(|p| p.to_chalk(db)).collect(); |
78 | chalk_ir::TyData::Opaque(make_binders(where_clauses, 1)).intern() | 84 | let bounded_ty = chalk_ir::BoundedTy { bounds: make_binders(where_clauses, 1) }; |
85 | chalk_ir::TyData::Opaque(bounded_ty).intern() | ||
79 | } | 86 | } |
80 | Ty::Unknown => { | 87 | Ty::Unknown => { |
81 | let parameters = Vec::new(); | 88 | let parameters = Vec::new(); |
@@ -87,10 +94,9 @@ impl ToChalk for Ty { | |||
87 | fn from_chalk(db: &impl HirDatabase, chalk: chalk_ir::Ty<ChalkIr>) -> Self { | 94 | fn from_chalk(db: &impl HirDatabase, chalk: chalk_ir::Ty<ChalkIr>) -> Self { |
88 | match chalk.data().clone() { | 95 | match chalk.data().clone() { |
89 | chalk_ir::TyData::Apply(apply_ty) => { | 96 | chalk_ir::TyData::Apply(apply_ty) => { |
90 | // FIXME this is kind of hacky due to the fact that | 97 | // TODO clean this up now that Placeholder isn't in TypeName anymore |
91 | // TypeName::Placeholder is a Ty::Param on our side | ||
92 | match apply_ty.name { | 98 | match apply_ty.name { |
93 | TypeName::TypeKindId(TypeKindId::StructId(struct_id)) => { | 99 | TypeName::Struct(struct_id) => { |
94 | let ctor = from_chalk(db, struct_id); | 100 | let ctor = from_chalk(db, struct_id); |
95 | let parameters = from_chalk(db, apply_ty.parameters); | 101 | let parameters = from_chalk(db, apply_ty.parameters); |
96 | Ty::Apply(ApplicationTy { ctor, parameters }) | 102 | Ty::Apply(ApplicationTy { ctor, parameters }) |
@@ -101,14 +107,12 @@ impl ToChalk for Ty { | |||
101 | Ty::Apply(ApplicationTy { ctor, parameters }) | 107 | Ty::Apply(ApplicationTy { ctor, parameters }) |
102 | } | 108 | } |
103 | TypeName::Error => Ty::Unknown, | 109 | TypeName::Error => Ty::Unknown, |
104 | // FIXME handle TypeKindId::Trait/Type here | ||
105 | TypeName::TypeKindId(_) => unimplemented!(), | ||
106 | TypeName::Placeholder(idx) => { | ||
107 | assert_eq!(idx.ui, UniverseIndex::ROOT); | ||
108 | Ty::Param { idx: idx.idx as u32, name: crate::Name::missing() } | ||
109 | } | ||
110 | } | 110 | } |
111 | } | 111 | } |
112 | chalk_ir::TyData::Placeholder(idx) => { | ||
113 | assert_eq!(idx.ui, UniverseIndex::ROOT); | ||
114 | Ty::Param { idx: idx.idx as u32, name: crate::Name::missing() } | ||
115 | } | ||
112 | chalk_ir::TyData::Projection(proj) => { | 116 | chalk_ir::TyData::Projection(proj) => { |
113 | let associated_ty = from_chalk(db, proj.associated_ty_id); | 117 | let associated_ty = from_chalk(db, proj.associated_ty_id); |
114 | let parameters = from_chalk(db, proj.parameters); | 118 | let parameters = from_chalk(db, proj.parameters); |
@@ -118,15 +122,15 @@ impl ToChalk for Ty { | |||
118 | chalk_ir::TyData::BoundVar(idx) => Ty::Bound(idx as u32), | 122 | chalk_ir::TyData::BoundVar(idx) => Ty::Bound(idx as u32), |
119 | chalk_ir::TyData::InferenceVar(_iv) => Ty::Unknown, | 123 | chalk_ir::TyData::InferenceVar(_iv) => Ty::Unknown, |
120 | chalk_ir::TyData::Dyn(where_clauses) => { | 124 | chalk_ir::TyData::Dyn(where_clauses) => { |
121 | assert_eq!(where_clauses.binders.len(), 1); | 125 | assert_eq!(where_clauses.bounds.binders.len(), 1); |
122 | let predicates = | 126 | let predicates = |
123 | where_clauses.value.into_iter().map(|c| from_chalk(db, c)).collect(); | 127 | where_clauses.bounds.value.into_iter().map(|c| from_chalk(db, c)).collect(); |
124 | Ty::Dyn(predicates) | 128 | Ty::Dyn(predicates) |
125 | } | 129 | } |
126 | chalk_ir::TyData::Opaque(where_clauses) => { | 130 | chalk_ir::TyData::Opaque(where_clauses) => { |
127 | assert_eq!(where_clauses.binders.len(), 1); | 131 | assert_eq!(where_clauses.bounds.binders.len(), 1); |
128 | let predicates = | 132 | let predicates = |
129 | where_clauses.value.into_iter().map(|c| from_chalk(db, c)).collect(); | 133 | where_clauses.bounds.value.into_iter().map(|c| from_chalk(db, c)).collect(); |
130 | Ty::Opaque(predicates) | 134 | Ty::Opaque(predicates) |
131 | } | 135 | } |
132 | } | 136 | } |
@@ -143,9 +147,9 @@ impl ToChalk for Substs { | |||
143 | fn from_chalk(db: &impl HirDatabase, parameters: Vec<chalk_ir::Parameter<ChalkIr>>) -> Substs { | 147 | fn from_chalk(db: &impl HirDatabase, parameters: Vec<chalk_ir::Parameter<ChalkIr>>) -> Substs { |
144 | let tys = parameters | 148 | let tys = parameters |
145 | .into_iter() | 149 | .into_iter() |
146 | .map(|p| match p { | 150 | .map(|p| match p.ty() { |
147 | chalk_ir::Parameter(chalk_ir::ParameterKind::Ty(ty)) => from_chalk(db, ty), | 151 | Some(ty) => from_chalk(db, ty.clone()), |
148 | chalk_ir::Parameter(chalk_ir::ParameterKind::Lifetime(_)) => unimplemented!(), | 152 | None => unimplemented!(), |
149 | }) | 153 | }) |
150 | .collect(); | 154 | .collect(); |
151 | Substs(tys) | 155 | Substs(tys) |
@@ -168,65 +172,62 @@ impl ToChalk for TraitRef { | |||
168 | } | 172 | } |
169 | } | 173 | } |
170 | 174 | ||
171 | impl ToChalk for TraitId { | 175 | impl ToChalk for hir_def::TraitId { |
172 | type Chalk = chalk_ir::TraitId; | 176 | type Chalk = TraitId; |
173 | 177 | ||
174 | fn to_chalk(self, _db: &impl HirDatabase) -> chalk_ir::TraitId { | 178 | fn to_chalk(self, _db: &impl HirDatabase) -> TraitId { |
175 | chalk_ir::TraitId(id_to_chalk(self)) | 179 | chalk_ir::TraitId(id_to_chalk(self)) |
176 | } | 180 | } |
177 | 181 | ||
178 | fn from_chalk(_db: &impl HirDatabase, trait_id: chalk_ir::TraitId) -> TraitId { | 182 | fn from_chalk(_db: &impl HirDatabase, trait_id: TraitId) -> hir_def::TraitId { |
179 | id_from_chalk(trait_id.0) | 183 | id_from_chalk(trait_id.0) |
180 | } | 184 | } |
181 | } | 185 | } |
182 | 186 | ||
183 | impl ToChalk for TypeCtor { | 187 | impl ToChalk for TypeCtor { |
184 | type Chalk = chalk_ir::StructId; | 188 | type Chalk = StructId; |
185 | 189 | ||
186 | fn to_chalk(self, db: &impl HirDatabase) -> chalk_ir::StructId { | 190 | fn to_chalk(self, db: &impl HirDatabase) -> StructId { |
187 | db.intern_type_ctor(self).into() | 191 | db.intern_type_ctor(self).into() |
188 | } | 192 | } |
189 | 193 | ||
190 | fn from_chalk(db: &impl HirDatabase, struct_id: chalk_ir::StructId) -> TypeCtor { | 194 | fn from_chalk(db: &impl HirDatabase, struct_id: StructId) -> TypeCtor { |
191 | db.lookup_intern_type_ctor(struct_id.into()) | 195 | db.lookup_intern_type_ctor(struct_id.into()) |
192 | } | 196 | } |
193 | } | 197 | } |
194 | 198 | ||
195 | impl ToChalk for Impl { | 199 | impl ToChalk for Impl { |
196 | type Chalk = chalk_ir::ImplId; | 200 | type Chalk = ImplId; |
197 | 201 | ||
198 | fn to_chalk(self, db: &impl HirDatabase) -> chalk_ir::ImplId { | 202 | fn to_chalk(self, db: &impl HirDatabase) -> ImplId { |
199 | db.intern_chalk_impl(self).into() | 203 | db.intern_chalk_impl(self).into() |
200 | } | 204 | } |
201 | 205 | ||
202 | fn from_chalk(db: &impl HirDatabase, impl_id: chalk_ir::ImplId) -> Impl { | 206 | fn from_chalk(db: &impl HirDatabase, impl_id: ImplId) -> Impl { |
203 | db.lookup_intern_chalk_impl(impl_id.into()) | 207 | db.lookup_intern_chalk_impl(impl_id.into()) |
204 | } | 208 | } |
205 | } | 209 | } |
206 | 210 | ||
207 | impl ToChalk for TypeAliasId { | 211 | impl ToChalk for TypeAliasId { |
208 | type Chalk = chalk_ir::TypeId; | 212 | type Chalk = AssocTypeId; |
209 | 213 | ||
210 | fn to_chalk(self, _db: &impl HirDatabase) -> chalk_ir::TypeId { | 214 | fn to_chalk(self, _db: &impl HirDatabase) -> AssocTypeId { |
211 | chalk_ir::TypeId(id_to_chalk(self)) | 215 | chalk_ir::AssocTypeId(id_to_chalk(self)) |
212 | } | 216 | } |
213 | 217 | ||
214 | fn from_chalk(_db: &impl HirDatabase, type_alias_id: chalk_ir::TypeId) -> TypeAliasId { | 218 | fn from_chalk(_db: &impl HirDatabase, type_alias_id: AssocTypeId) -> TypeAliasId { |
215 | id_from_chalk(type_alias_id.0) | 219 | id_from_chalk(type_alias_id.0) |
216 | } | 220 | } |
217 | } | 221 | } |
218 | 222 | ||
219 | impl ToChalk for AssocTyValue { | 223 | impl ToChalk for AssocTyValue { |
220 | type Chalk = chalk_rust_ir::AssociatedTyValueId; | 224 | type Chalk = AssociatedTyValueId; |
221 | 225 | ||
222 | fn to_chalk(self, db: &impl HirDatabase) -> chalk_rust_ir::AssociatedTyValueId { | 226 | fn to_chalk(self, db: &impl HirDatabase) -> AssociatedTyValueId { |
223 | db.intern_assoc_ty_value(self).into() | 227 | db.intern_assoc_ty_value(self).into() |
224 | } | 228 | } |
225 | 229 | ||
226 | fn from_chalk( | 230 | fn from_chalk(db: &impl HirDatabase, assoc_ty_value_id: AssociatedTyValueId) -> AssocTyValue { |
227 | db: &impl HirDatabase, | ||
228 | assoc_ty_value_id: chalk_rust_ir::AssociatedTyValueId, | ||
229 | ) -> AssocTyValue { | ||
230 | db.lookup_intern_assoc_ty_value(assoc_ty_value_id.into()) | 231 | db.lookup_intern_assoc_ty_value(assoc_ty_value_id.into()) |
231 | } | 232 | } |
232 | } | 233 | } |
@@ -468,28 +469,28 @@ impl<'a, DB> chalk_solve::RustIrDatabase<ChalkIr> for ChalkContext<'a, DB> | |||
468 | where | 469 | where |
469 | DB: HirDatabase, | 470 | DB: HirDatabase, |
470 | { | 471 | { |
471 | fn associated_ty_data(&self, id: TypeId) -> Arc<AssociatedTyDatum<ChalkIr>> { | 472 | fn associated_ty_data(&self, id: AssocTypeId) -> Arc<AssociatedTyDatum> { |
472 | self.db.associated_ty_data(id) | 473 | self.db.associated_ty_data(id) |
473 | } | 474 | } |
474 | fn trait_datum(&self, trait_id: chalk_ir::TraitId) -> Arc<TraitDatum<ChalkIr>> { | 475 | fn trait_datum(&self, trait_id: TraitId) -> Arc<TraitDatum> { |
475 | self.db.trait_datum(self.krate, trait_id) | 476 | self.db.trait_datum(self.krate, trait_id) |
476 | } | 477 | } |
477 | fn struct_datum(&self, struct_id: chalk_ir::StructId) -> Arc<StructDatum<ChalkIr>> { | 478 | fn struct_datum(&self, struct_id: StructId) -> Arc<StructDatum> { |
478 | self.db.struct_datum(self.krate, struct_id) | 479 | self.db.struct_datum(self.krate, struct_id) |
479 | } | 480 | } |
480 | fn impl_datum(&self, impl_id: chalk_ir::ImplId) -> Arc<ImplDatum<ChalkIr>> { | 481 | fn impl_datum(&self, impl_id: ImplId) -> Arc<ImplDatum> { |
481 | self.db.impl_datum(self.krate, impl_id) | 482 | self.db.impl_datum(self.krate, impl_id) |
482 | } | 483 | } |
483 | fn impls_for_trait( | 484 | fn impls_for_trait( |
484 | &self, | 485 | &self, |
485 | trait_id: chalk_ir::TraitId, | 486 | trait_id: TraitId, |
486 | parameters: &[Parameter<ChalkIr>], | 487 | parameters: &[Parameter<TypeFamily>], |
487 | ) -> Vec<chalk_ir::ImplId> { | 488 | ) -> Vec<ImplId> { |
488 | debug!("impls_for_trait {:?}", trait_id); | 489 | debug!("impls_for_trait {:?}", trait_id); |
489 | if trait_id == UNKNOWN_TRAIT { | 490 | if trait_id == UNKNOWN_TRAIT { |
490 | return Vec::new(); | 491 | return Vec::new(); |
491 | } | 492 | } |
492 | let trait_: TraitId = from_chalk(self.db, trait_id); | 493 | let trait_: hir_def::TraitId = from_chalk(self.db, trait_id); |
493 | let mut result: Vec<_> = self | 494 | let mut result: Vec<_> = self |
494 | .db | 495 | .db |
495 | .impls_for_trait(self.krate, trait_.into()) | 496 | .impls_for_trait(self.krate, trait_.into()) |
@@ -508,39 +509,32 @@ where | |||
508 | debug!("impls_for_trait returned {} impls", result.len()); | 509 | debug!("impls_for_trait returned {} impls", result.len()); |
509 | result | 510 | result |
510 | } | 511 | } |
511 | fn impl_provided_for( | 512 | fn impl_provided_for(&self, auto_trait_id: TraitId, struct_id: StructId) -> bool { |
512 | &self, | ||
513 | auto_trait_id: chalk_ir::TraitId, | ||
514 | struct_id: chalk_ir::StructId, | ||
515 | ) -> bool { | ||
516 | debug!("impl_provided_for {:?}, {:?}", auto_trait_id, struct_id); | 513 | debug!("impl_provided_for {:?}, {:?}", auto_trait_id, struct_id); |
517 | false // FIXME | 514 | false // FIXME |
518 | } | 515 | } |
519 | fn type_name(&self, _id: TypeKindId) -> Identifier { | 516 | fn associated_ty_value(&self, id: AssociatedTyValueId) -> Arc<AssociatedTyValue> { |
520 | unimplemented!() | ||
521 | } | ||
522 | fn associated_ty_value( | ||
523 | &self, | ||
524 | id: chalk_rust_ir::AssociatedTyValueId, | ||
525 | ) -> Arc<AssociatedTyValue<ChalkIr>> { | ||
526 | self.db.associated_ty_value(self.krate.into(), id) | 517 | self.db.associated_ty_value(self.krate.into(), id) |
527 | } | 518 | } |
528 | fn custom_clauses(&self) -> Vec<chalk_ir::ProgramClause<ChalkIr>> { | 519 | fn custom_clauses(&self) -> Vec<chalk_ir::ProgramClause<ChalkIr>> { |
529 | vec![] | 520 | vec![] |
530 | } | 521 | } |
531 | fn local_impls_to_coherence_check( | 522 | fn local_impls_to_coherence_check(&self, _trait_id: TraitId) -> Vec<ImplId> { |
532 | &self, | ||
533 | _trait_id: chalk_ir::TraitId, | ||
534 | ) -> Vec<chalk_ir::ImplId> { | ||
535 | // We don't do coherence checking (yet) | 523 | // We don't do coherence checking (yet) |
536 | unimplemented!() | 524 | unimplemented!() |
537 | } | 525 | } |
526 | fn as_struct_id(&self, id: &TypeName<TypeFamily>) -> Option<StructId> { | ||
527 | match id { | ||
528 | TypeName::Struct(struct_id) => Some(*struct_id), | ||
529 | _ => None, | ||
530 | } | ||
531 | } | ||
538 | } | 532 | } |
539 | 533 | ||
540 | pub(crate) fn associated_ty_data_query( | 534 | pub(crate) fn associated_ty_data_query( |
541 | db: &impl HirDatabase, | 535 | db: &impl HirDatabase, |
542 | id: TypeId, | 536 | id: AssocTypeId, |
543 | ) -> Arc<AssociatedTyDatum<ChalkIr>> { | 537 | ) -> Arc<AssociatedTyDatum> { |
544 | debug!("associated_ty_data {:?}", id); | 538 | debug!("associated_ty_data {:?}", id); |
545 | let type_alias: TypeAliasId = from_chalk(db, id); | 539 | let type_alias: TypeAliasId = from_chalk(db, id); |
546 | let trait_ = match type_alias.lookup(db).container { | 540 | let trait_ = match type_alias.lookup(db).container { |
@@ -565,8 +559,8 @@ pub(crate) fn associated_ty_data_query( | |||
565 | pub(crate) fn trait_datum_query( | 559 | pub(crate) fn trait_datum_query( |
566 | db: &impl HirDatabase, | 560 | db: &impl HirDatabase, |
567 | krate: CrateId, | 561 | krate: CrateId, |
568 | trait_id: chalk_ir::TraitId, | 562 | trait_id: TraitId, |
569 | ) -> Arc<TraitDatum<ChalkIr>> { | 563 | ) -> Arc<TraitDatum> { |
570 | debug!("trait_datum {:?}", trait_id); | 564 | debug!("trait_datum {:?}", trait_id); |
571 | if trait_id == UNKNOWN_TRAIT { | 565 | if trait_id == UNKNOWN_TRAIT { |
572 | let trait_datum_bound = chalk_rust_ir::TraitDatumBound { where_clauses: Vec::new() }; | 566 | let trait_datum_bound = chalk_rust_ir::TraitDatumBound { where_clauses: Vec::new() }; |
@@ -586,7 +580,7 @@ pub(crate) fn trait_datum_query( | |||
586 | associated_ty_ids: vec![], | 580 | associated_ty_ids: vec![], |
587 | }); | 581 | }); |
588 | } | 582 | } |
589 | let trait_: TraitId = from_chalk(db, trait_id); | 583 | let trait_: hir_def::TraitId = from_chalk(db, trait_id); |
590 | let trait_data = db.trait_data(trait_); | 584 | let trait_data = db.trait_data(trait_); |
591 | debug!("trait {:?} = {:?}", trait_id, trait_data.name); | 585 | debug!("trait {:?} = {:?}", trait_id, trait_data.name); |
592 | let generic_params = generics(db, trait_.into()); | 586 | let generic_params = generics(db, trait_.into()); |
@@ -616,8 +610,8 @@ pub(crate) fn trait_datum_query( | |||
616 | pub(crate) fn struct_datum_query( | 610 | pub(crate) fn struct_datum_query( |
617 | db: &impl HirDatabase, | 611 | db: &impl HirDatabase, |
618 | krate: CrateId, | 612 | krate: CrateId, |
619 | struct_id: chalk_ir::StructId, | 613 | struct_id: StructId, |
620 | ) -> Arc<StructDatum<ChalkIr>> { | 614 | ) -> Arc<StructDatum> { |
621 | debug!("struct_datum {:?}", struct_id); | 615 | debug!("struct_datum {:?}", struct_id); |
622 | let type_ctor: TypeCtor = from_chalk(db, struct_id); | 616 | let type_ctor: TypeCtor = from_chalk(db, struct_id); |
623 | debug!("struct {:?} = {:?}", struct_id, type_ctor); | 617 | debug!("struct {:?} = {:?}", struct_id, type_ctor); |
@@ -648,8 +642,8 @@ pub(crate) fn struct_datum_query( | |||
648 | pub(crate) fn impl_datum_query( | 642 | pub(crate) fn impl_datum_query( |
649 | db: &impl HirDatabase, | 643 | db: &impl HirDatabase, |
650 | krate: CrateId, | 644 | krate: CrateId, |
651 | impl_id: chalk_ir::ImplId, | 645 | impl_id: ImplId, |
652 | ) -> Arc<ImplDatum<ChalkIr>> { | 646 | ) -> Arc<ImplDatum> { |
653 | let _p = ra_prof::profile("impl_datum"); | 647 | let _p = ra_prof::profile("impl_datum"); |
654 | debug!("impl_datum {:?}", impl_id); | 648 | debug!("impl_datum {:?}", impl_id); |
655 | let impl_: Impl = from_chalk(db, impl_id); | 649 | let impl_: Impl = from_chalk(db, impl_id); |
@@ -663,9 +657,9 @@ pub(crate) fn impl_datum_query( | |||
663 | fn impl_block_datum( | 657 | fn impl_block_datum( |
664 | db: &impl HirDatabase, | 658 | db: &impl HirDatabase, |
665 | krate: CrateId, | 659 | krate: CrateId, |
666 | chalk_id: chalk_ir::ImplId, | 660 | chalk_id: ImplId, |
667 | impl_id: ImplId, | 661 | impl_id: hir_def::ImplId, |
668 | ) -> Option<Arc<ImplDatum<ChalkIr>>> { | 662 | ) -> Option<Arc<ImplDatum>> { |
669 | let trait_ref = db.impl_trait(impl_id)?; | 663 | let trait_ref = db.impl_trait(impl_id)?; |
670 | let impl_data = db.impl_data(impl_id); | 664 | let impl_data = db.impl_data(impl_id); |
671 | 665 | ||
@@ -721,7 +715,7 @@ fn impl_block_datum( | |||
721 | Some(Arc::new(impl_datum)) | 715 | Some(Arc::new(impl_datum)) |
722 | } | 716 | } |
723 | 717 | ||
724 | fn invalid_impl_datum() -> Arc<ImplDatum<ChalkIr>> { | 718 | fn invalid_impl_datum() -> Arc<ImplDatum> { |
725 | let trait_ref = chalk_ir::TraitRef { | 719 | let trait_ref = chalk_ir::TraitRef { |
726 | trait_id: UNKNOWN_TRAIT, | 720 | trait_id: UNKNOWN_TRAIT, |
727 | parameters: vec![chalk_ir::TyData::BoundVar(0).cast().intern().cast()], | 721 | parameters: vec![chalk_ir::TyData::BoundVar(0).cast().intern().cast()], |
@@ -754,7 +748,7 @@ fn type_alias_associated_ty_value( | |||
754 | db: &impl HirDatabase, | 748 | db: &impl HirDatabase, |
755 | _krate: CrateId, | 749 | _krate: CrateId, |
756 | type_alias: TypeAliasId, | 750 | type_alias: TypeAliasId, |
757 | ) -> Arc<AssociatedTyValue<ChalkIr>> { | 751 | ) -> Arc<AssociatedTyValue> { |
758 | let type_alias_data = db.type_alias_data(type_alias); | 752 | let type_alias_data = db.type_alias_data(type_alias); |
759 | let impl_id = match type_alias.lookup(db).container { | 753 | let impl_id = match type_alias.lookup(db).container { |
760 | AssocContainerId::ImplId(it) => it, | 754 | AssocContainerId::ImplId(it) => it, |
@@ -786,25 +780,25 @@ fn id_to_chalk<T: InternKey>(salsa_id: T) -> chalk_ir::RawId { | |||
786 | chalk_ir::RawId { index: salsa_id.as_intern_id().as_u32() } | 780 | chalk_ir::RawId { index: salsa_id.as_intern_id().as_u32() } |
787 | } | 781 | } |
788 | 782 | ||
789 | impl From<chalk_ir::StructId> for crate::TypeCtorId { | 783 | impl From<StructId> for crate::TypeCtorId { |
790 | fn from(struct_id: chalk_ir::StructId) -> Self { | 784 | fn from(struct_id: StructId) -> Self { |
791 | id_from_chalk(struct_id.0) | 785 | id_from_chalk(struct_id.0) |
792 | } | 786 | } |
793 | } | 787 | } |
794 | 788 | ||
795 | impl From<crate::TypeCtorId> for chalk_ir::StructId { | 789 | impl From<crate::TypeCtorId> for StructId { |
796 | fn from(type_ctor_id: crate::TypeCtorId) -> Self { | 790 | fn from(type_ctor_id: crate::TypeCtorId) -> Self { |
797 | chalk_ir::StructId(id_to_chalk(type_ctor_id)) | 791 | chalk_ir::StructId(id_to_chalk(type_ctor_id)) |
798 | } | 792 | } |
799 | } | 793 | } |
800 | 794 | ||
801 | impl From<chalk_ir::ImplId> for crate::traits::GlobalImplId { | 795 | impl From<ImplId> for crate::traits::GlobalImplId { |
802 | fn from(impl_id: chalk_ir::ImplId) -> Self { | 796 | fn from(impl_id: ImplId) -> Self { |
803 | id_from_chalk(impl_id.0) | 797 | id_from_chalk(impl_id.0) |
804 | } | 798 | } |
805 | } | 799 | } |
806 | 800 | ||
807 | impl From<crate::traits::GlobalImplId> for chalk_ir::ImplId { | 801 | impl From<crate::traits::GlobalImplId> for ImplId { |
808 | fn from(impl_id: crate::traits::GlobalImplId) -> Self { | 802 | fn from(impl_id: crate::traits::GlobalImplId) -> Self { |
809 | chalk_ir::ImplId(id_to_chalk(impl_id)) | 803 | chalk_ir::ImplId(id_to_chalk(impl_id)) |
810 | } | 804 | } |