aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_hir/src/db.rs10
-rw-r--r--crates/ra_hir/src/ids.rs26
-rw-r--r--crates/ra_hir/src/lib.rs1
-rw-r--r--crates/ra_hir/src/ty.rs8
-rw-r--r--crates/ra_hir/src/ty/traits.rs11
-rw-r--r--crates/ra_hir/src/ty/traits/chalk.rs18
6 files changed, 33 insertions, 41 deletions
diff --git a/crates/ra_hir/src/db.rs b/crates/ra_hir/src/db.rs
index 3ae5df8d5..a9dab2d25 100644
--- a/crates/ra_hir/src/db.rs
+++ b/crates/ra_hir/src/db.rs
@@ -5,7 +5,6 @@ use std::sync::Arc;
5use ra_db::salsa; 5use ra_db::salsa;
6 6
7use crate::{ 7use crate::{
8 ids,
9 ty::{ 8 ty::{
10 method_resolution::CrateImplBlocks, 9 method_resolution::CrateImplBlocks,
11 traits::{AssocTyValue, Impl}, 10 traits::{AssocTyValue, Impl},
@@ -71,11 +70,14 @@ pub trait HirDatabase: DefDatabase {
71 70
72 // Interned IDs for Chalk integration 71 // Interned IDs for Chalk integration
73 #[salsa::interned] 72 #[salsa::interned]
74 fn intern_type_ctor(&self, type_ctor: TypeCtor) -> ids::TypeCtorId; 73 fn intern_type_ctor(&self, type_ctor: TypeCtor) -> crate::ty::TypeCtorId;
75 #[salsa::interned] 74 #[salsa::interned]
76 fn intern_chalk_impl(&self, impl_: Impl) -> ids::GlobalImplId; 75 fn intern_chalk_impl(&self, impl_: Impl) -> crate::ty::traits::GlobalImplId;
77 #[salsa::interned] 76 #[salsa::interned]
78 fn intern_assoc_ty_value(&self, assoc_ty_value: AssocTyValue) -> ids::AssocTyValueId; 77 fn intern_assoc_ty_value(
78 &self,
79 assoc_ty_value: AssocTyValue,
80 ) -> crate::ty::traits::AssocTyValueId;
79 81
80 #[salsa::invoke(crate::ty::traits::chalk::associated_ty_data_query)] 82 #[salsa::invoke(crate::ty::traits::chalk::associated_ty_data_query)]
81 fn associated_ty_data( 83 fn associated_ty_data(
diff --git a/crates/ra_hir/src/ids.rs b/crates/ra_hir/src/ids.rs
deleted file mode 100644
index 67de8b243..000000000
--- a/crates/ra_hir/src/ids.rs
+++ /dev/null
@@ -1,26 +0,0 @@
1//! hir makes heavy use of ids: integer (u32) handlers to various things. You
2//! can think of id as a pointer (but without a lifetime) or a file descriptor
3//! (but for hir objects).
4//!
5//! This module defines a bunch of ids we are using. The most important ones are
6//! probably `HirFileId` and `DefId`.
7
8use ra_db::{impl_intern_key, salsa};
9
10/// This exists just for Chalk, because Chalk just has a single `StructId` where
11/// we have different kinds of ADTs, primitive types and special type
12/// constructors like tuples and function pointers.
13#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
14pub struct TypeCtorId(salsa::InternId);
15impl_intern_key!(TypeCtorId);
16
17/// This exists just for Chalk, because our ImplIds are only unique per module.
18#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
19pub struct GlobalImplId(salsa::InternId);
20impl_intern_key!(GlobalImplId);
21
22/// This exists just for Chalk, because it needs a unique ID for each associated
23/// type value in an impl (even synthetic ones).
24#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
25pub struct AssocTyValueId(salsa::InternId);
26impl_intern_key!(AssocTyValueId);
diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs
index 239798bcc..8c589c728 100644
--- a/crates/ra_hir/src/lib.rs
+++ b/crates/ra_hir/src/lib.rs
@@ -31,7 +31,6 @@ pub mod debug;
31pub mod db; 31pub mod db;
32pub mod source_binder; 32pub mod source_binder;
33 33
34mod ids;
35mod ty; 34mod ty;
36mod impl_block; 35mod impl_block;
37mod expr; 36mod expr;
diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs
index 95b8df181..309bd2727 100644
--- a/crates/ra_hir/src/ty.rs
+++ b/crates/ra_hir/src/ty.rs
@@ -18,6 +18,7 @@ use std::sync::Arc;
18use std::{fmt, iter, mem}; 18use std::{fmt, iter, mem};
19 19
20use hir_def::{generics::GenericParams, AdtId}; 20use hir_def::{generics::GenericParams, AdtId};
21use ra_db::{impl_intern_key, salsa};
21 22
22use crate::{ 23use crate::{
23 db::HirDatabase, expr::ExprId, util::make_mut_slice, Adt, Crate, DefWithBody, FloatTy, 24 db::HirDatabase, expr::ExprId, util::make_mut_slice, Adt, Crate, DefWithBody, FloatTy,
@@ -114,6 +115,13 @@ pub enum TypeCtor {
114 Closure { def: DefWithBody, expr: ExprId }, 115 Closure { def: DefWithBody, expr: ExprId },
115} 116}
116 117
118/// This exists just for Chalk, because Chalk just has a single `StructId` where
119/// we have different kinds of ADTs, primitive types and special type
120/// constructors like tuples and function pointers.
121#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
122pub struct TypeCtorId(salsa::InternId);
123impl_intern_key!(TypeCtorId);
124
117impl TypeCtor { 125impl TypeCtor {
118 pub fn num_ty_params(self, db: &impl HirDatabase) -> usize { 126 pub fn num_ty_params(self, db: &impl HirDatabase) -> usize {
119 match self { 127 match self {
diff --git a/crates/ra_hir/src/ty/traits.rs b/crates/ra_hir/src/ty/traits.rs
index 45f725438..268fa09e4 100644
--- a/crates/ra_hir/src/ty/traits.rs
+++ b/crates/ra_hir/src/ty/traits.rs
@@ -3,7 +3,7 @@ use std::sync::{Arc, Mutex};
3 3
4use chalk_ir::{cast::Cast, family::ChalkIr}; 4use chalk_ir::{cast::Cast, family::ChalkIr};
5use log::debug; 5use log::debug;
6use ra_db::salsa; 6use ra_db::{impl_intern_key, salsa};
7use ra_prof::profile; 7use ra_prof::profile;
8use rustc_hash::FxHashSet; 8use rustc_hash::FxHashSet;
9 9
@@ -304,6 +304,10 @@ pub enum Impl {
304 /// Closure types implement the Fn traits synthetically. 304 /// Closure types implement the Fn traits synthetically.
305 ClosureFnTraitImpl(ClosureFnTraitImplData), 305 ClosureFnTraitImpl(ClosureFnTraitImplData),
306} 306}
307/// This exists just for Chalk, because our ImplIds are only unique per module.
308#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
309pub struct GlobalImplId(salsa::InternId);
310impl_intern_key!(GlobalImplId);
307 311
308/// An associated type value. Usually this comes from a `type` declaration 312/// An associated type value. Usually this comes from a `type` declaration
309/// inside an impl block, but for built-in impls we have to synthesize it. 313/// inside an impl block, but for built-in impls we have to synthesize it.
@@ -315,3 +319,8 @@ pub enum AssocTyValue {
315 /// The output type of the Fn trait implementation. 319 /// The output type of the Fn trait implementation.
316 ClosureFnTraitImplOutput(ClosureFnTraitImplData), 320 ClosureFnTraitImplOutput(ClosureFnTraitImplData),
317} 321}
322/// This exists just for Chalk, because it needs a unique ID for each associated
323/// type value in an impl (even synthetic ones).
324#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
325pub struct AssocTyValueId(salsa::InternId);
326impl_intern_key!(AssocTyValueId);
diff --git a/crates/ra_hir/src/ty/traits/chalk.rs b/crates/ra_hir/src/ty/traits/chalk.rs
index 53818a5e5..9efdc53c4 100644
--- a/crates/ra_hir/src/ty/traits/chalk.rs
+++ b/crates/ra_hir/src/ty/traits/chalk.rs
@@ -847,38 +847,38 @@ fn id_to_chalk<T: InternKey>(salsa_id: T) -> chalk_ir::RawId {
847 chalk_ir::RawId { index: salsa_id.as_intern_id().as_u32() } 847 chalk_ir::RawId { index: salsa_id.as_intern_id().as_u32() }
848} 848}
849 849
850impl From<chalk_ir::StructId> for crate::ids::TypeCtorId { 850impl From<chalk_ir::StructId> for crate::ty::TypeCtorId {
851 fn from(struct_id: chalk_ir::StructId) -> Self { 851 fn from(struct_id: chalk_ir::StructId) -> Self {
852 id_from_chalk(struct_id.0) 852 id_from_chalk(struct_id.0)
853 } 853 }
854} 854}
855 855
856impl From<crate::ids::TypeCtorId> for chalk_ir::StructId { 856impl From<crate::ty::TypeCtorId> for chalk_ir::StructId {
857 fn from(type_ctor_id: crate::ids::TypeCtorId) -> Self { 857 fn from(type_ctor_id: crate::ty::TypeCtorId) -> Self {
858 chalk_ir::StructId(id_to_chalk(type_ctor_id)) 858 chalk_ir::StructId(id_to_chalk(type_ctor_id))
859 } 859 }
860} 860}
861 861
862impl From<chalk_ir::ImplId> for crate::ids::GlobalImplId { 862impl From<chalk_ir::ImplId> for crate::ty::traits::GlobalImplId {
863 fn from(impl_id: chalk_ir::ImplId) -> Self { 863 fn from(impl_id: chalk_ir::ImplId) -> Self {
864 id_from_chalk(impl_id.0) 864 id_from_chalk(impl_id.0)
865 } 865 }
866} 866}
867 867
868impl From<crate::ids::GlobalImplId> for chalk_ir::ImplId { 868impl From<crate::ty::traits::GlobalImplId> for chalk_ir::ImplId {
869 fn from(impl_id: crate::ids::GlobalImplId) -> Self { 869 fn from(impl_id: crate::ty::traits::GlobalImplId) -> Self {
870 chalk_ir::ImplId(id_to_chalk(impl_id)) 870 chalk_ir::ImplId(id_to_chalk(impl_id))
871 } 871 }
872} 872}
873 873
874impl From<chalk_rust_ir::AssociatedTyValueId> for crate::ids::AssocTyValueId { 874impl From<chalk_rust_ir::AssociatedTyValueId> for crate::ty::traits::AssocTyValueId {
875 fn from(id: chalk_rust_ir::AssociatedTyValueId) -> Self { 875 fn from(id: chalk_rust_ir::AssociatedTyValueId) -> Self {
876 id_from_chalk(id.0) 876 id_from_chalk(id.0)
877 } 877 }
878} 878}
879 879
880impl From<crate::ids::AssocTyValueId> for chalk_rust_ir::AssociatedTyValueId { 880impl From<crate::ty::traits::AssocTyValueId> for chalk_rust_ir::AssociatedTyValueId {
881 fn from(assoc_ty_value_id: crate::ids::AssocTyValueId) -> Self { 881 fn from(assoc_ty_value_id: crate::ty::traits::AssocTyValueId) -> Self {
882 chalk_rust_ir::AssociatedTyValueId(id_to_chalk(assoc_ty_value_id)) 882 chalk_rust_ir::AssociatedTyValueId(id_to_chalk(assoc_ty_value_id))
883 } 883 }
884} 884}