aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_ty/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir_ty/src')
-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
5 files changed, 21 insertions, 30 deletions
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))