diff options
-rw-r--r-- | crates/hir_ty/src/chalk_db.rs | 15 | ||||
-rw-r--r-- | crates/hir_ty/src/lib.rs | 61 | ||||
-rw-r--r-- | crates/hir_ty/src/mapping.rs | 71 | ||||
-rw-r--r-- | crates/hir_ty/src/tls.rs | 5 |
4 files changed, 74 insertions, 78 deletions
diff --git a/crates/hir_ty/src/chalk_db.rs b/crates/hir_ty/src/chalk_db.rs index 9d07ad597..8f054d06b 100644 --- a/crates/hir_ty/src/chalk_db.rs +++ b/crates/hir_ty/src/chalk_db.rs | |||
@@ -17,7 +17,7 @@ use hir_expand::name::name; | |||
17 | use crate::{ | 17 | use crate::{ |
18 | db::HirDatabase, | 18 | db::HirDatabase, |
19 | display::HirDisplay, | 19 | display::HirDisplay, |
20 | from_assoc_type_id, make_only_type_binders, | 20 | from_assoc_type_id, from_chalk_trait_id, make_only_type_binders, |
21 | mapping::{from_chalk, ToChalk, TypeAliasAsValue}, | 21 | mapping::{from_chalk, ToChalk, TypeAliasAsValue}, |
22 | method_resolution::{TyFingerprint, ALL_FLOAT_FPS, ALL_INT_FPS}, | 22 | method_resolution::{TyFingerprint, ALL_FLOAT_FPS, ALL_INT_FPS}, |
23 | to_assoc_type_id, to_chalk_trait_id, | 23 | to_assoc_type_id, to_chalk_trait_id, |
@@ -79,7 +79,7 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> { | |||
79 | binders: &CanonicalVarKinds<Interner>, | 79 | binders: &CanonicalVarKinds<Interner>, |
80 | ) -> Vec<ImplId> { | 80 | ) -> Vec<ImplId> { |
81 | debug!("impls_for_trait {:?}", trait_id); | 81 | debug!("impls_for_trait {:?}", trait_id); |
82 | let trait_: hir_def::TraitId = from_chalk(self.db, trait_id); | 82 | let trait_: hir_def::TraitId = from_chalk_trait_id(trait_id); |
83 | 83 | ||
84 | let ty: Ty = parameters[0].assert_ty_ref(&Interner).clone(); | 84 | let ty: Ty = parameters[0].assert_ty_ref(&Interner).clone(); |
85 | 85 | ||
@@ -161,7 +161,7 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> { | |||
161 | Some(LangItemTarget::TraitId(trait_)) => trait_, | 161 | Some(LangItemTarget::TraitId(trait_)) => trait_, |
162 | _ => return None, | 162 | _ => return None, |
163 | }; | 163 | }; |
164 | Some(trait_.to_chalk(self.db)) | 164 | Some(to_chalk_trait_id(trait_)) |
165 | } | 165 | } |
166 | 166 | ||
167 | fn program_clauses_for_env( | 167 | fn program_clauses_for_env( |
@@ -308,7 +308,7 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> { | |||
308 | } | 308 | } |
309 | 309 | ||
310 | fn trait_name(&self, trait_id: chalk_ir::TraitId<Interner>) -> String { | 310 | fn trait_name(&self, trait_id: chalk_ir::TraitId<Interner>) -> String { |
311 | let id = from_chalk(self.db, trait_id); | 311 | let id = from_chalk_trait_id(trait_id); |
312 | self.db.trait_data(id).name.to_string() | 312 | self.db.trait_data(id).name.to_string() |
313 | } | 313 | } |
314 | fn adt_name(&self, chalk_ir::AdtId(adt_id): AdtId) -> String { | 314 | fn adt_name(&self, chalk_ir::AdtId(adt_id): AdtId) -> String { |
@@ -413,7 +413,7 @@ pub(crate) fn trait_datum_query( | |||
413 | trait_id: TraitId, | 413 | trait_id: TraitId, |
414 | ) -> Arc<TraitDatum> { | 414 | ) -> Arc<TraitDatum> { |
415 | debug!("trait_datum {:?}", trait_id); | 415 | debug!("trait_datum {:?}", trait_id); |
416 | let trait_: hir_def::TraitId = from_chalk(db, trait_id); | 416 | let trait_ = from_chalk_trait_id(trait_id); |
417 | let trait_data = db.trait_data(trait_); | 417 | let trait_data = db.trait_data(trait_); |
418 | debug!("trait {:?} = {:?}", trait_id, trait_data.name); | 418 | debug!("trait {:?} = {:?}", trait_id, trait_data.name); |
419 | let generic_params = generics(db.upcast(), trait_.into()); | 419 | let generic_params = generics(db.upcast(), trait_.into()); |
@@ -723,7 +723,10 @@ pub(super) fn generic_predicate_to_inline_bound( | |||
723 | .collect(); | 723 | .collect(); |
724 | let alias_eq_bound = rust_ir::AliasEqBound { | 724 | let alias_eq_bound = rust_ir::AliasEqBound { |
725 | value: ty.clone(), | 725 | value: ty.clone(), |
726 | trait_bound: rust_ir::TraitBound { trait_id: trait_.to_chalk(db), args_no_self }, | 726 | trait_bound: rust_ir::TraitBound { |
727 | trait_id: to_chalk_trait_id(trait_), | ||
728 | args_no_self, | ||
729 | }, | ||
727 | associated_ty_id: projection_ty.associated_ty_id, | 730 | associated_ty_id: projection_ty.associated_ty_id, |
728 | parameters: Vec::new(), // FIXME we don't support generic associated types yet | 731 | parameters: Vec::new(), // FIXME we don't support generic associated types yet |
729 | }; | 732 | }; |
diff --git a/crates/hir_ty/src/lib.rs b/crates/hir_ty/src/lib.rs index 434e2e533..6b5006f5d 100644 --- a/crates/hir_ty/src/lib.rs +++ b/crates/hir_ty/src/lib.rs | |||
@@ -34,16 +34,12 @@ mod test_db; | |||
34 | 34 | ||
35 | use std::sync::Arc; | 35 | use std::sync::Arc; |
36 | 36 | ||
37 | use base_db::salsa; | ||
38 | use chalk_ir::{ | 37 | use chalk_ir::{ |
39 | fold::{Fold, Shift}, | 38 | fold::{Fold, Shift}, |
40 | interner::HasInterner, | 39 | interner::HasInterner, |
41 | UintTy, | 40 | UintTy, |
42 | }; | 41 | }; |
43 | use hir_def::{ | 42 | use hir_def::{expr::ExprId, type_ref::Rawness, TypeParamId}; |
44 | expr::ExprId, type_ref::Rawness, ConstParamId, LifetimeParamId, TraitId, TypeAliasId, | ||
45 | TypeParamId, | ||
46 | }; | ||
47 | 43 | ||
48 | use crate::{db::HirDatabase, display::HirDisplay, utils::generics}; | 44 | use crate::{db::HirDatabase, display::HirDisplay, utils::generics}; |
49 | 45 | ||
@@ -56,6 +52,11 @@ pub use lower::{ | |||
56 | associated_type_shorthand_candidates, callable_item_sig, CallableDefId, ImplTraitLoweringMode, | 52 | associated_type_shorthand_candidates, callable_item_sig, CallableDefId, ImplTraitLoweringMode, |
57 | TyDefId, TyLoweringContext, ValueTyDefId, | 53 | TyDefId, TyLoweringContext, ValueTyDefId, |
58 | }; | 54 | }; |
55 | pub use mapping::{ | ||
56 | const_from_placeholder_idx, from_assoc_type_id, from_chalk_trait_id, from_foreign_def_id, | ||
57 | from_placeholder_idx, lt_from_placeholder_idx, to_assoc_type_id, to_chalk_trait_id, | ||
58 | to_foreign_def_id, to_placeholder_idx, | ||
59 | }; | ||
59 | pub use traits::TraitEnvironment; | 60 | pub use traits::TraitEnvironment; |
60 | pub use walk::TypeWalk; | 61 | pub use walk::TypeWalk; |
61 | 62 | ||
@@ -242,56 +243,6 @@ pub(crate) struct ReturnTypeImplTrait { | |||
242 | pub(crate) bounds: Binders<Vec<QuantifiedWhereClause>>, | 243 | pub(crate) bounds: Binders<Vec<QuantifiedWhereClause>>, |
243 | } | 244 | } |
244 | 245 | ||
245 | pub fn to_foreign_def_id(id: TypeAliasId) -> ForeignDefId { | ||
246 | chalk_ir::ForeignDefId(salsa::InternKey::as_intern_id(&id)) | ||
247 | } | ||
248 | |||
249 | pub fn from_foreign_def_id(id: ForeignDefId) -> TypeAliasId { | ||
250 | salsa::InternKey::from_intern_id(id.0) | ||
251 | } | ||
252 | |||
253 | pub fn to_assoc_type_id(id: TypeAliasId) -> AssocTypeId { | ||
254 | chalk_ir::AssocTypeId(salsa::InternKey::as_intern_id(&id)) | ||
255 | } | ||
256 | |||
257 | pub fn from_assoc_type_id(id: AssocTypeId) -> TypeAliasId { | ||
258 | salsa::InternKey::from_intern_id(id.0) | ||
259 | } | ||
260 | |||
261 | pub fn from_placeholder_idx(db: &dyn HirDatabase, idx: PlaceholderIndex) -> TypeParamId { | ||
262 | assert_eq!(idx.ui, chalk_ir::UniverseIndex::ROOT); | ||
263 | let interned_id = salsa::InternKey::from_intern_id(salsa::InternId::from(idx.idx)); | ||
264 | db.lookup_intern_type_param_id(interned_id) | ||
265 | } | ||
266 | |||
267 | pub fn to_placeholder_idx(db: &dyn HirDatabase, id: TypeParamId) -> PlaceholderIndex { | ||
268 | let interned_id = db.intern_type_param_id(id); | ||
269 | PlaceholderIndex { | ||
270 | ui: chalk_ir::UniverseIndex::ROOT, | ||
271 | idx: salsa::InternKey::as_intern_id(&interned_id).as_usize(), | ||
272 | } | ||
273 | } | ||
274 | |||
275 | pub fn lt_from_placeholder_idx(db: &dyn HirDatabase, idx: PlaceholderIndex) -> LifetimeParamId { | ||
276 | assert_eq!(idx.ui, chalk_ir::UniverseIndex::ROOT); | ||
277 | let interned_id = salsa::InternKey::from_intern_id(salsa::InternId::from(idx.idx)); | ||
278 | db.lookup_intern_lifetime_param_id(interned_id) | ||
279 | } | ||
280 | |||
281 | pub fn const_from_placeholder_idx(db: &dyn HirDatabase, idx: PlaceholderIndex) -> ConstParamId { | ||
282 | assert_eq!(idx.ui, chalk_ir::UniverseIndex::ROOT); | ||
283 | let interned_id = salsa::InternKey::from_intern_id(salsa::InternId::from(idx.idx)); | ||
284 | db.lookup_intern_const_param_id(interned_id) | ||
285 | } | ||
286 | |||
287 | pub fn to_chalk_trait_id(id: TraitId) -> ChalkTraitId { | ||
288 | chalk_ir::TraitId(salsa::InternKey::as_intern_id(&id)) | ||
289 | } | ||
290 | |||
291 | pub fn from_chalk_trait_id(id: ChalkTraitId) -> TraitId { | ||
292 | salsa::InternKey::from_intern_id(id.0) | ||
293 | } | ||
294 | |||
295 | pub fn static_lifetime() -> Lifetime { | 246 | pub fn static_lifetime() -> Lifetime { |
296 | LifetimeData::Static.intern(&Interner) | 247 | LifetimeData::Static.intern(&Interner) |
297 | } | 248 | } |
diff --git a/crates/hir_ty/src/mapping.rs b/crates/hir_ty/src/mapping.rs index 37c935194..5e86fafe5 100644 --- a/crates/hir_ty/src/mapping.rs +++ b/crates/hir_ty/src/mapping.rs | |||
@@ -5,10 +5,13 @@ | |||
5 | 5 | ||
6 | use chalk_solve::rust_ir; | 6 | use chalk_solve::rust_ir; |
7 | 7 | ||
8 | use base_db::salsa::InternKey; | 8 | use base_db::salsa::{self, InternKey}; |
9 | use hir_def::TypeAliasId; | 9 | use hir_def::{ConstParamId, LifetimeParamId, TraitId, TypeAliasId, TypeParamId}; |
10 | 10 | ||
11 | use crate::{chalk_db, db::HirDatabase, CallableDefId, FnDefId, Interner, OpaqueTyId}; | 11 | use crate::{ |
12 | chalk_db, db::HirDatabase, AssocTypeId, CallableDefId, ChalkTraitId, FnDefId, ForeignDefId, | ||
13 | Interner, OpaqueTyId, PlaceholderIndex, | ||
14 | }; | ||
12 | 15 | ||
13 | pub(crate) trait ToChalk { | 16 | pub(crate) trait ToChalk { |
14 | type Chalk; | 17 | type Chalk; |
@@ -23,18 +26,6 @@ where | |||
23 | T::from_chalk(db, chalk) | 26 | T::from_chalk(db, chalk) |
24 | } | 27 | } |
25 | 28 | ||
26 | impl ToChalk for hir_def::TraitId { | ||
27 | type Chalk = chalk_db::TraitId; | ||
28 | |||
29 | fn to_chalk(self, _db: &dyn HirDatabase) -> chalk_db::TraitId { | ||
30 | chalk_ir::TraitId(self.as_intern_id()) | ||
31 | } | ||
32 | |||
33 | fn from_chalk(_db: &dyn HirDatabase, trait_id: chalk_db::TraitId) -> hir_def::TraitId { | ||
34 | InternKey::from_intern_id(trait_id.0) | ||
35 | } | ||
36 | } | ||
37 | |||
38 | impl ToChalk for hir_def::ImplId { | 29 | impl ToChalk for hir_def::ImplId { |
39 | type Chalk = chalk_db::ImplId; | 30 | type Chalk = chalk_db::ImplId; |
40 | 31 | ||
@@ -111,3 +102,53 @@ impl From<crate::db::InternedClosureId> for chalk_ir::ClosureId<Interner> { | |||
111 | chalk_ir::ClosureId(id.as_intern_id()) | 102 | chalk_ir::ClosureId(id.as_intern_id()) |
112 | } | 103 | } |
113 | } | 104 | } |
105 | |||
106 | pub fn to_foreign_def_id(id: TypeAliasId) -> ForeignDefId { | ||
107 | chalk_ir::ForeignDefId(salsa::InternKey::as_intern_id(&id)) | ||
108 | } | ||
109 | |||
110 | pub fn from_foreign_def_id(id: ForeignDefId) -> TypeAliasId { | ||
111 | salsa::InternKey::from_intern_id(id.0) | ||
112 | } | ||
113 | |||
114 | pub fn to_assoc_type_id(id: TypeAliasId) -> AssocTypeId { | ||
115 | chalk_ir::AssocTypeId(salsa::InternKey::as_intern_id(&id)) | ||
116 | } | ||
117 | |||
118 | pub fn from_assoc_type_id(id: AssocTypeId) -> TypeAliasId { | ||
119 | salsa::InternKey::from_intern_id(id.0) | ||
120 | } | ||
121 | |||
122 | pub fn from_placeholder_idx(db: &dyn HirDatabase, idx: PlaceholderIndex) -> TypeParamId { | ||
123 | assert_eq!(idx.ui, chalk_ir::UniverseIndex::ROOT); | ||
124 | let interned_id = salsa::InternKey::from_intern_id(salsa::InternId::from(idx.idx)); | ||
125 | db.lookup_intern_type_param_id(interned_id) | ||
126 | } | ||
127 | |||
128 | pub fn to_placeholder_idx(db: &dyn HirDatabase, id: TypeParamId) -> PlaceholderIndex { | ||
129 | let interned_id = db.intern_type_param_id(id); | ||
130 | PlaceholderIndex { | ||
131 | ui: chalk_ir::UniverseIndex::ROOT, | ||
132 | idx: salsa::InternKey::as_intern_id(&interned_id).as_usize(), | ||
133 | } | ||
134 | } | ||
135 | |||
136 | pub fn lt_from_placeholder_idx(db: &dyn HirDatabase, idx: PlaceholderIndex) -> LifetimeParamId { | ||
137 | assert_eq!(idx.ui, chalk_ir::UniverseIndex::ROOT); | ||
138 | let interned_id = salsa::InternKey::from_intern_id(salsa::InternId::from(idx.idx)); | ||
139 | db.lookup_intern_lifetime_param_id(interned_id) | ||
140 | } | ||
141 | |||
142 | pub fn const_from_placeholder_idx(db: &dyn HirDatabase, idx: PlaceholderIndex) -> ConstParamId { | ||
143 | assert_eq!(idx.ui, chalk_ir::UniverseIndex::ROOT); | ||
144 | let interned_id = salsa::InternKey::from_intern_id(salsa::InternId::from(idx.idx)); | ||
145 | db.lookup_intern_const_param_id(interned_id) | ||
146 | } | ||
147 | |||
148 | pub fn to_chalk_trait_id(id: TraitId) -> ChalkTraitId { | ||
149 | chalk_ir::TraitId(salsa::InternKey::as_intern_id(&id)) | ||
150 | } | ||
151 | |||
152 | pub fn from_chalk_trait_id(id: ChalkTraitId) -> TraitId { | ||
153 | salsa::InternKey::from_intern_id(id.0) | ||
154 | } | ||
diff --git a/crates/hir_ty/src/tls.rs b/crates/hir_ty/src/tls.rs index 92989f11f..87c671a42 100644 --- a/crates/hir_ty/src/tls.rs +++ b/crates/hir_ty/src/tls.rs | |||
@@ -5,7 +5,8 @@ use chalk_ir::{AliasTy, GenericArg, Goal, Goals, Lifetime, ProgramClauseImplicat | |||
5 | use itertools::Itertools; | 5 | use itertools::Itertools; |
6 | 6 | ||
7 | use crate::{ | 7 | use crate::{ |
8 | chalk_db, db::HirDatabase, from_assoc_type_id, mapping::from_chalk, CallableDefId, Interner, | 8 | chalk_db, db::HirDatabase, from_assoc_type_id, from_chalk_trait_id, mapping::from_chalk, |
9 | CallableDefId, Interner, | ||
9 | }; | 10 | }; |
10 | use hir_def::{AdtId, AssocContainerId, Lookup, TypeAliasId}; | 11 | use hir_def::{AdtId, AssocContainerId, Lookup, TypeAliasId}; |
11 | 12 | ||
@@ -32,7 +33,7 @@ impl DebugContext<'_> { | |||
32 | id: chalk_db::TraitId, | 33 | id: chalk_db::TraitId, |
33 | fmt: &mut fmt::Formatter<'_>, | 34 | fmt: &mut fmt::Formatter<'_>, |
34 | ) -> Result<(), fmt::Error> { | 35 | ) -> Result<(), fmt::Error> { |
35 | let trait_: hir_def::TraitId = from_chalk(self.0, id); | 36 | let trait_: hir_def::TraitId = from_chalk_trait_id(id); |
36 | let trait_data = self.0.trait_data(trait_); | 37 | let trait_data = self.0.trait_data(trait_); |
37 | write!(fmt, "{}", trait_data.name) | 38 | write!(fmt, "{}", trait_data.name) |
38 | } | 39 | } |