diff options
Diffstat (limited to 'crates/ra_hir_ty/src')
-rw-r--r-- | crates/ra_hir_ty/src/traits/chalk.rs | 39 |
1 files changed, 18 insertions, 21 deletions
diff --git a/crates/ra_hir_ty/src/traits/chalk.rs b/crates/ra_hir_ty/src/traits/chalk.rs index 4001aa941..7f7fe93b7 100644 --- a/crates/ra_hir_ty/src/traits/chalk.rs +++ b/crates/ra_hir_ty/src/traits/chalk.rs | |||
@@ -18,7 +18,7 @@ use crate::{ | |||
18 | }; | 18 | }; |
19 | 19 | ||
20 | #[derive(Debug, Copy, Clone, Hash, PartialOrd, Ord, PartialEq, Eq)] | 20 | #[derive(Debug, Copy, Clone, Hash, PartialOrd, Ord, PartialEq, Eq)] |
21 | pub struct Interner {} | 21 | pub struct Interner; |
22 | 22 | ||
23 | impl chalk_ir::interner::Interner for Interner { | 23 | impl chalk_ir::interner::Interner for Interner { |
24 | type InternedType = Box<chalk_ir::TyData<Self>>; | 24 | type InternedType = Box<chalk_ir::TyData<Self>>; |
@@ -27,6 +27,7 @@ impl chalk_ir::interner::Interner for Interner { | |||
27 | type InternedGoal = Arc<GoalData<Self>>; | 27 | type InternedGoal = Arc<GoalData<Self>>; |
28 | type InternedGoals = Vec<Goal<Self>>; | 28 | type InternedGoals = Vec<Goal<Self>>; |
29 | type InternedSubstitution = Vec<Parameter<Self>>; | 29 | type InternedSubstitution = Vec<Parameter<Self>>; |
30 | type Identifier = lalrpop_intern::InternedString; | ||
30 | type DefId = InternId; | 31 | type DefId = InternId; |
31 | 32 | ||
32 | // FIXME: implement these | 33 | // FIXME: implement these |
@@ -58,7 +59,7 @@ impl chalk_ir::interner::Interner for Interner { | |||
58 | None | 59 | None |
59 | } | 60 | } |
60 | 61 | ||
61 | fn intern_ty(ty: chalk_ir::TyData<Self>) -> Box<chalk_ir::TyData<Self>> { | 62 | fn intern_ty(&self, ty: chalk_ir::TyData<Self>) -> Box<chalk_ir::TyData<Self>> { |
62 | Box::new(ty) | 63 | Box::new(ty) |
63 | } | 64 | } |
64 | 65 | ||
@@ -121,7 +122,7 @@ pub type StructId = chalk_ir::StructId<Interner>; | |||
121 | pub type StructDatum = chalk_rust_ir::StructDatum<Interner>; | 122 | pub type StructDatum = chalk_rust_ir::StructDatum<Interner>; |
122 | pub type ImplId = chalk_ir::ImplId<Interner>; | 123 | pub type ImplId = chalk_ir::ImplId<Interner>; |
123 | pub type ImplDatum = chalk_rust_ir::ImplDatum<Interner>; | 124 | pub type ImplDatum = chalk_rust_ir::ImplDatum<Interner>; |
124 | pub type AssociatedTyValueId = chalk_rust_ir::AssociatedTyValueId; | 125 | pub type AssociatedTyValueId = chalk_rust_ir::AssociatedTyValueId<Interner>; |
125 | pub type AssociatedTyValue = chalk_rust_ir::AssociatedTyValue<Interner>; | 126 | pub type AssociatedTyValue = chalk_rust_ir::AssociatedTyValue<Interner>; |
126 | 127 | ||
127 | pub(super) trait ToChalk { | 128 | pub(super) trait ToChalk { |
@@ -144,12 +145,12 @@ impl ToChalk for Ty { | |||
144 | Ty::Apply(apply_ty) => { | 145 | Ty::Apply(apply_ty) => { |
145 | let name = apply_ty.ctor.to_chalk(db); | 146 | let name = apply_ty.ctor.to_chalk(db); |
146 | let substitution = apply_ty.parameters.to_chalk(db); | 147 | let substitution = apply_ty.parameters.to_chalk(db); |
147 | chalk_ir::ApplicationTy { name, substitution }.cast().intern() | 148 | chalk_ir::ApplicationTy { name, substitution }.cast().intern(&Interner) |
148 | } | 149 | } |
149 | Ty::Projection(proj_ty) => { | 150 | Ty::Projection(proj_ty) => { |
150 | let associated_ty_id = proj_ty.associated_ty.to_chalk(db); | 151 | let associated_ty_id = proj_ty.associated_ty.to_chalk(db); |
151 | let substitution = proj_ty.parameters.to_chalk(db); | 152 | let substitution = proj_ty.parameters.to_chalk(db); |
152 | chalk_ir::AliasTy { associated_ty_id, substitution }.cast().intern() | 153 | chalk_ir::AliasTy { associated_ty_id, substitution }.cast().intern(&Interner) |
153 | } | 154 | } |
154 | Ty::Placeholder(id) => { | 155 | Ty::Placeholder(id) => { |
155 | let interned_id = db.intern_type_param_id(id); | 156 | let interned_id = db.intern_type_param_id(id); |
@@ -157,9 +158,9 @@ impl ToChalk for Ty { | |||
157 | ui: UniverseIndex::ROOT, | 158 | ui: UniverseIndex::ROOT, |
158 | idx: interned_id.as_intern_id().as_usize(), | 159 | idx: interned_id.as_intern_id().as_usize(), |
159 | } | 160 | } |
160 | .to_ty::<Interner>() | 161 | .to_ty::<Interner>(&Interner) |
161 | } | 162 | } |
162 | Ty::Bound(idx) => chalk_ir::TyData::BoundVar(idx as usize).intern(), | 163 | Ty::Bound(idx) => chalk_ir::TyData::BoundVar(idx as usize).intern(&Interner), |
163 | Ty::Infer(_infer_ty) => panic!("uncanonicalized infer ty"), | 164 | Ty::Infer(_infer_ty) => panic!("uncanonicalized infer ty"), |
164 | Ty::Dyn(predicates) => { | 165 | Ty::Dyn(predicates) => { |
165 | let where_clauses = predicates | 166 | let where_clauses = predicates |
@@ -169,12 +170,12 @@ impl ToChalk for Ty { | |||
169 | .map(|p| p.to_chalk(db)) | 170 | .map(|p| p.to_chalk(db)) |
170 | .collect(); | 171 | .collect(); |
171 | let bounded_ty = chalk_ir::DynTy { bounds: make_binders(where_clauses, 1) }; | 172 | let bounded_ty = chalk_ir::DynTy { bounds: make_binders(where_clauses, 1) }; |
172 | chalk_ir::TyData::Dyn(bounded_ty).intern() | 173 | chalk_ir::TyData::Dyn(bounded_ty).intern(&Interner) |
173 | } | 174 | } |
174 | Ty::Opaque(_) | Ty::Unknown => { | 175 | Ty::Opaque(_) | Ty::Unknown => { |
175 | let substitution = chalk_ir::Substitution::empty(); | 176 | let substitution = chalk_ir::Substitution::empty(); |
176 | let name = TypeName::Error; | 177 | let name = TypeName::Error; |
177 | chalk_ir::ApplicationTy { name, substitution }.cast().intern() | 178 | chalk_ir::ApplicationTy { name, substitution }.cast().intern(&Interner) |
178 | } | 179 | } |
179 | } | 180 | } |
180 | } | 181 | } |
@@ -611,6 +612,9 @@ where | |||
611 | _ => None, | 612 | _ => None, |
612 | } | 613 | } |
613 | } | 614 | } |
615 | fn interner(&self) -> &Interner { | ||
616 | &Interner | ||
617 | } | ||
614 | } | 618 | } |
615 | 619 | ||
616 | pub(crate) fn associated_ty_data_query( | 620 | pub(crate) fn associated_ty_data_query( |
@@ -822,13 +826,6 @@ fn type_alias_associated_ty_value( | |||
822 | Arc::new(value) | 826 | Arc::new(value) |
823 | } | 827 | } |
824 | 828 | ||
825 | fn id_from_chalk<T: InternKey>(chalk_id: chalk_ir::RawId) -> T { | ||
826 | T::from_intern_id(InternId::from(chalk_id.index)) | ||
827 | } | ||
828 | fn id_to_chalk<T: InternKey>(salsa_id: T) -> chalk_ir::RawId { | ||
829 | chalk_ir::RawId { index: salsa_id.as_intern_id().as_u32() } | ||
830 | } | ||
831 | |||
832 | impl From<StructId> for crate::TypeCtorId { | 829 | impl From<StructId> for crate::TypeCtorId { |
833 | fn from(struct_id: StructId) -> Self { | 830 | fn from(struct_id: StructId) -> Self { |
834 | InternKey::from_intern_id(struct_id.0) | 831 | InternKey::from_intern_id(struct_id.0) |
@@ -853,14 +850,14 @@ impl From<crate::traits::GlobalImplId> for ImplId { | |||
853 | } | 850 | } |
854 | } | 851 | } |
855 | 852 | ||
856 | impl From<chalk_rust_ir::AssociatedTyValueId> for crate::traits::AssocTyValueId { | 853 | impl From<chalk_rust_ir::AssociatedTyValueId<Interner>> for crate::traits::AssocTyValueId { |
857 | fn from(id: chalk_rust_ir::AssociatedTyValueId) -> Self { | 854 | fn from(id: chalk_rust_ir::AssociatedTyValueId<Interner>) -> Self { |
858 | id_from_chalk(id.0) | 855 | Self::from_intern_id(id.0) |
859 | } | 856 | } |
860 | } | 857 | } |
861 | 858 | ||
862 | impl From<crate::traits::AssocTyValueId> for chalk_rust_ir::AssociatedTyValueId { | 859 | impl From<crate::traits::AssocTyValueId> for chalk_rust_ir::AssociatedTyValueId<Interner> { |
863 | fn from(assoc_ty_value_id: crate::traits::AssocTyValueId) -> Self { | 860 | fn from(assoc_ty_value_id: crate::traits::AssocTyValueId) -> Self { |
864 | chalk_rust_ir::AssociatedTyValueId(id_to_chalk(assoc_ty_value_id)) | 861 | chalk_rust_ir::AssociatedTyValueId(assoc_ty_value_id.as_intern_id()) |
865 | } | 862 | } |
866 | } | 863 | } |