aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorFlorian Diebold <[email protected]>2020-07-15 20:47:45 +0100
committerFlorian Diebold <[email protected]>2020-07-15 21:07:13 +0100
commit20770044631fd0c21caa12f9bc87489ea6c848ee (patch)
tree27ba12638469c763874fa094744ffe3f628a7164 /crates
parenta48843a16a2306399f2f6a78c69d9192a6480c88 (diff)
Remove TypeCtor interning
Our TypeCtor and Chalk's TypeName match now!
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_hir/src/db.rs6
-rw-r--r--crates/ra_hir_def/src/lib.rs8
-rw-r--r--crates/ra_hir_ty/src/db.rs4
-rw-r--r--crates/ra_hir_ty/src/lib.rs8
-rw-r--r--crates/ra_hir_ty/src/traits/chalk.rs12
-rw-r--r--crates/ra_hir_ty/src/traits/chalk/interner.rs14
-rw-r--r--crates/ra_hir_ty/src/traits/chalk/mapping.rs13
-rw-r--r--crates/ra_ide_db/src/change.rs1
8 files changed, 28 insertions, 38 deletions
diff --git a/crates/ra_hir/src/db.rs b/crates/ra_hir/src/db.rs
index 3a9973abf..1ad92a1f8 100644
--- a/crates/ra_hir/src/db.rs
+++ b/crates/ra_hir/src/db.rs
@@ -17,9 +17,9 @@ pub use hir_ty::db::{
17 AssociatedTyDataQuery, AssociatedTyValueQuery, CallableItemSignatureQuery, FieldTypesQuery, 17 AssociatedTyDataQuery, AssociatedTyValueQuery, CallableItemSignatureQuery, FieldTypesQuery,
18 GenericDefaultsQuery, GenericPredicatesForParamQuery, GenericPredicatesQuery, HirDatabase, 18 GenericDefaultsQuery, GenericPredicatesForParamQuery, GenericPredicatesQuery, HirDatabase,
19 HirDatabaseStorage, ImplDatumQuery, ImplSelfTyQuery, ImplTraitQuery, InferQueryQuery, 19 HirDatabaseStorage, ImplDatumQuery, ImplSelfTyQuery, ImplTraitQuery, InferQueryQuery,
20 InherentImplsInCrateQuery, InternTypeCtorQuery, InternTypeParamIdQuery, 20 InherentImplsInCrateQuery, InternTypeParamIdQuery, ReturnTypeImplTraitsQuery, StructDatumQuery,
21 ReturnTypeImplTraitsQuery, StructDatumQuery, TraitDatumQuery, TraitImplsInCrateQuery, 21 TraitDatumQuery, TraitImplsInCrateQuery, TraitImplsInDepsQuery, TraitSolveQuery, TyQuery,
22 TraitImplsInDepsQuery, TraitSolveQuery, TyQuery, ValueTyQuery, 22 ValueTyQuery,
23}; 23};
24 24
25#[test] 25#[test]
diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs
index b71d626c3..87000fe98 100644
--- a/crates/ra_hir_def/src/lib.rs
+++ b/crates/ra_hir_def/src/lib.rs
@@ -159,17 +159,17 @@ pub struct FunctionId(salsa::InternId);
159type FunctionLoc = AssocItemLoc<Function>; 159type FunctionLoc = AssocItemLoc<Function>;
160impl_intern!(FunctionId, FunctionLoc, intern_function, lookup_intern_function); 160impl_intern!(FunctionId, FunctionLoc, intern_function, lookup_intern_function);
161 161
162#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 162#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
163pub struct StructId(salsa::InternId); 163pub struct StructId(salsa::InternId);
164type StructLoc = ItemLoc<Struct>; 164type StructLoc = ItemLoc<Struct>;
165impl_intern!(StructId, StructLoc, intern_struct, lookup_intern_struct); 165impl_intern!(StructId, StructLoc, intern_struct, lookup_intern_struct);
166 166
167#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 167#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
168pub struct UnionId(salsa::InternId); 168pub struct UnionId(salsa::InternId);
169pub type UnionLoc = ItemLoc<Union>; 169pub type UnionLoc = ItemLoc<Union>;
170impl_intern!(UnionId, UnionLoc, intern_union, lookup_intern_union); 170impl_intern!(UnionId, UnionLoc, intern_union, lookup_intern_union);
171 171
172#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 172#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
173pub struct EnumId(salsa::InternId); 173pub struct EnumId(salsa::InternId);
174pub type EnumLoc = ItemLoc<Enum>; 174pub type EnumLoc = ItemLoc<Enum>;
175impl_intern!(EnumId, EnumLoc, intern_enum, lookup_intern_enum); 175impl_intern!(EnumId, EnumLoc, intern_enum, lookup_intern_enum);
@@ -239,7 +239,7 @@ pub enum AssocContainerId {
239impl_from!(ContainerId for AssocContainerId); 239impl_from!(ContainerId for AssocContainerId);
240 240
241/// A Data Type 241/// A Data Type
242#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] 242#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
243pub enum AdtId { 243pub enum AdtId {
244 StructId(StructId), 244 StructId(StructId),
245 UnionId(UnionId), 245 UnionId(UnionId),
diff --git a/crates/ra_hir_ty/src/db.rs b/crates/ra_hir_ty/src/db.rs
index d8a798771..608bab1b1 100644
--- a/crates/ra_hir_ty/src/db.rs
+++ b/crates/ra_hir_ty/src/db.rs
@@ -14,7 +14,7 @@ use crate::{
14 method_resolution::{InherentImpls, TraitImpls}, 14 method_resolution::{InherentImpls, TraitImpls},
15 traits::chalk, 15 traits::chalk,
16 Binders, CallableDef, GenericPredicate, InferenceResult, OpaqueTyId, PolyFnSig, 16 Binders, CallableDef, GenericPredicate, InferenceResult, OpaqueTyId, PolyFnSig,
17 ReturnTypeImplTraits, TraitRef, Ty, TyDefId, TypeCtor, ValueTyDefId, 17 ReturnTypeImplTraits, TraitRef, Ty, TyDefId, ValueTyDefId,
18}; 18};
19use hir_expand::name::Name; 19use hir_expand::name::Name;
20 20
@@ -77,8 +77,6 @@ pub trait HirDatabase: DefDatabase + Upcast<dyn DefDatabase> {
77 77
78 // Interned IDs for Chalk integration 78 // Interned IDs for Chalk integration
79 #[salsa::interned] 79 #[salsa::interned]
80 fn intern_type_ctor(&self, type_ctor: TypeCtor) -> crate::TypeCtorId;
81 #[salsa::interned]
82 fn intern_callable_def(&self, callable_def: CallableDef) -> crate::CallableDefId; 80 fn intern_callable_def(&self, callable_def: CallableDef) -> crate::CallableDefId;
83 #[salsa::interned] 81 #[salsa::interned]
84 fn intern_type_param_id(&self, param_id: TypeParamId) -> GlobalTypeParamId; 82 fn intern_type_param_id(&self, param_id: TypeParamId) -> GlobalTypeParamId;
diff --git a/crates/ra_hir_ty/src/lib.rs b/crates/ra_hir_ty/src/lib.rs
index c4c24a83b..9f034eca5 100644
--- a/crates/ra_hir_ty/src/lib.rs
+++ b/crates/ra_hir_ty/src/lib.rs
@@ -112,6 +112,7 @@ pub enum TypeCtor {
112 /// fn foo() -> i32 { 1 } 112 /// fn foo() -> i32 { 1 }
113 /// let bar: fn() -> i32 = foo; 113 /// let bar: fn() -> i32 = foo;
114 /// ``` 114 /// ```
115 // FIXME make this a Ty variant like in Chalk
115 FnPtr { num_args: u16, is_varargs: bool }, 116 FnPtr { num_args: u16, is_varargs: bool },
116 117
117 /// The never type `!`. 118 /// The never type `!`.
@@ -139,13 +140,6 @@ pub enum TypeCtor {
139 Closure { def: DefWithBodyId, expr: ExprId }, 140 Closure { def: DefWithBodyId, expr: ExprId },
140} 141}
141 142
142/// This exists just for Chalk, because Chalk just has a single `StructId` where
143/// we have different kinds of ADTs, primitive types and special type
144/// constructors like tuples and function pointers.
145#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Ord, PartialOrd)]
146pub struct TypeCtorId(salsa::InternId);
147impl_intern_key!(TypeCtorId);
148
149/// This exists just for Chalk, because Chalk just has a single `FnDefId` where 143/// This exists just for Chalk, because Chalk just has a single `FnDefId` where
150/// we have different IDs for struct and enum variant constructors. 144/// we have different IDs for struct and enum variant constructors.
151#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Ord, PartialOrd)] 145#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Ord, PartialOrd)]
diff --git a/crates/ra_hir_ty/src/traits/chalk.rs b/crates/ra_hir_ty/src/traits/chalk.rs
index 7f8ba2f12..1ef5baa05 100644
--- a/crates/ra_hir_ty/src/traits/chalk.rs
+++ b/crates/ra_hir_ty/src/traits/chalk.rs
@@ -552,18 +552,6 @@ pub(crate) fn fn_def_datum_query(
552 Arc::new(datum) 552 Arc::new(datum)
553} 553}
554 554
555impl From<AdtId> for crate::TypeCtorId {
556 fn from(struct_id: AdtId) -> Self {
557 struct_id.0
558 }
559}
560
561impl From<crate::TypeCtorId> for AdtId {
562 fn from(type_ctor_id: crate::TypeCtorId) -> Self {
563 chalk_ir::AdtId(type_ctor_id)
564 }
565}
566
567impl From<FnDefId> for crate::CallableDefId { 555impl From<FnDefId> for crate::CallableDefId {
568 fn from(fn_def_id: FnDefId) -> Self { 556 fn from(fn_def_id: FnDefId) -> Self {
569 InternKey::from_intern_id(fn_def_id.0) 557 InternKey::from_intern_id(fn_def_id.0)
diff --git a/crates/ra_hir_ty/src/traits/chalk/interner.rs b/crates/ra_hir_ty/src/traits/chalk/interner.rs
index 156b691b4..8d4c51a8f 100644
--- a/crates/ra_hir_ty/src/traits/chalk/interner.rs
+++ b/crates/ra_hir_ty/src/traits/chalk/interner.rs
@@ -41,7 +41,7 @@ impl chalk_ir::interner::Interner for Interner {
41 type InternedCanonicalVarKinds = Vec<chalk_ir::CanonicalVarKind<Self>>; 41 type InternedCanonicalVarKinds = Vec<chalk_ir::CanonicalVarKind<Self>>;
42 type InternedConstraints = Vec<chalk_ir::InEnvironment<chalk_ir::Constraint<Self>>>; 42 type InternedConstraints = Vec<chalk_ir::InEnvironment<chalk_ir::Constraint<Self>>>;
43 type DefId = InternId; 43 type DefId = InternId;
44 type InternedAdtId = crate::TypeCtorId; 44 type InternedAdtId = hir_def::AdtId;
45 type Identifier = TypeAliasId; 45 type Identifier = TypeAliasId;
46 type FnAbi = (); 46 type FnAbi = ();
47 47
@@ -364,6 +364,18 @@ impl chalk_ir::interner::Interner for Interner {
364 ) -> &'a [chalk_ir::InEnvironment<chalk_ir::Constraint<Self>>] { 364 ) -> &'a [chalk_ir::InEnvironment<chalk_ir::Constraint<Self>>] {
365 constraints 365 constraints
366 } 366 }
367 fn debug_closure_id(
368 _fn_def_id: chalk_ir::ClosureId<Self>,
369 _fmt: &mut fmt::Formatter<'_>,
370 ) -> Option<fmt::Result> {
371 None
372 }
373 fn debug_constraints(
374 _clauses: &chalk_ir::Constraints<Self>,
375 _fmt: &mut fmt::Formatter<'_>,
376 ) -> Option<fmt::Result> {
377 None
378 }
367} 379}
368 380
369impl chalk_ir::interner::HasInterner for Interner { 381impl chalk_ir::interner::HasInterner for Interner {
diff --git a/crates/ra_hir_ty/src/traits/chalk/mapping.rs b/crates/ra_hir_ty/src/traits/chalk/mapping.rs
index 796947e69..a852ce2ac 100644
--- a/crates/ra_hir_ty/src/traits/chalk/mapping.rs
+++ b/crates/ra_hir_ty/src/traits/chalk/mapping.rs
@@ -316,20 +316,19 @@ impl ToChalk for TypeCtor {
316 TypeName::Closure(closure_id.into()) 316 TypeName::Closure(closure_id.into())
317 } 317 }
318 318
319 TypeCtor::FnPtr { .. } => panic!("Trying to convert FnPtr to TypeName"), 319 TypeCtor::Adt(adt_id) => TypeName::Adt(chalk_ir::AdtId(adt_id)),
320 320
321 TypeCtor::Adt(_) => { 321 TypeCtor::FnPtr { .. } => {
322 // FIXME no interning needed anymore 322 // This should not be reached, since Chalk doesn't represent
323 // other TypeCtors get interned and turned into a chalk StructId 323 // function pointers with TypeName
324 let struct_id = db.intern_type_ctor(self).into(); 324 unreachable!()
325 TypeName::Adt(struct_id)
326 } 325 }
327 } 326 }
328 } 327 }
329 328
330 fn from_chalk(db: &dyn HirDatabase, type_name: TypeName<Interner>) -> TypeCtor { 329 fn from_chalk(db: &dyn HirDatabase, type_name: TypeName<Interner>) -> TypeCtor {
331 match type_name { 330 match type_name {
332 TypeName::Adt(struct_id) => db.lookup_intern_type_ctor(struct_id.into()), 331 TypeName::Adt(struct_id) => TypeCtor::Adt(struct_id.0),
333 TypeName::AssociatedType(type_id) => TypeCtor::AssociatedType(from_chalk(db, type_id)), 332 TypeName::AssociatedType(type_id) => TypeCtor::AssociatedType(from_chalk(db, type_id)),
334 TypeName::OpaqueType(opaque_type_id) => { 333 TypeName::OpaqueType(opaque_type_id) => {
335 TypeCtor::OpaqueType(from_chalk(db, opaque_type_id)) 334 TypeCtor::OpaqueType(from_chalk(db, opaque_type_id))
diff --git a/crates/ra_ide_db/src/change.rs b/crates/ra_ide_db/src/change.rs
index d40cfeb02..a1bb3043b 100644
--- a/crates/ra_ide_db/src/change.rs
+++ b/crates/ra_ide_db/src/change.rs
@@ -279,7 +279,6 @@ impl RootDatabase {
279 hir::db::InternImplQuery 279 hir::db::InternImplQuery
280 280
281 // HirDatabase 281 // HirDatabase
282 hir::db::InternTypeCtorQuery
283 hir::db::InternTypeParamIdQuery 282 hir::db::InternTypeParamIdQuery
284 ]; 283 ];
285 284