diff options
Diffstat (limited to 'crates/ra_hir/src/ids.rs')
-rw-r--r-- | crates/ra_hir/src/ids.rs | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/crates/ra_hir/src/ids.rs b/crates/ra_hir/src/ids.rs index b93b7f397..43f0e81f9 100644 --- a/crates/ra_hir/src/ids.rs +++ b/crates/ra_hir/src/ids.rs | |||
@@ -8,6 +8,18 @@ use crate::{ | |||
8 | module_tree::ModuleId, | 8 | module_tree::ModuleId, |
9 | }; | 9 | }; |
10 | 10 | ||
11 | #[derive(Debug, Default)] | ||
12 | pub struct HirInterner { | ||
13 | defs: LocationIntener<DefLoc, DefId>, | ||
14 | macros: LocationIntener<MacroCallLoc, MacroCallId>, | ||
15 | } | ||
16 | |||
17 | impl HirInterner { | ||
18 | pub fn len(&self) -> usize { | ||
19 | self.defs.len() + self.macros.len() | ||
20 | } | ||
21 | } | ||
22 | |||
11 | /// hir makes heavy use of ids: integer (u32) handlers to various things. You | 23 | /// hir makes heavy use of ids: integer (u32) handlers to various things. You |
12 | /// can think of id as a pointer (but without a lifetime) or a file descriptor | 24 | /// can think of id as a pointer (but without a lifetime) or a file descriptor |
13 | /// (but for hir objects). | 25 | /// (but for hir objects). |
@@ -106,21 +118,15 @@ pub struct MacroCallLoc { | |||
106 | } | 118 | } |
107 | 119 | ||
108 | impl MacroCallId { | 120 | impl MacroCallId { |
109 | pub(crate) fn loc( | 121 | pub(crate) fn loc(self, db: &impl AsRef<HirInterner>) -> MacroCallLoc { |
110 | self, | 122 | db.as_ref().macros.id2loc(self) |
111 | db: &impl AsRef<LocationIntener<MacroCallLoc, MacroCallId>>, | ||
112 | ) -> MacroCallLoc { | ||
113 | db.as_ref().id2loc(self) | ||
114 | } | 123 | } |
115 | } | 124 | } |
116 | 125 | ||
117 | impl MacroCallLoc { | 126 | impl MacroCallLoc { |
118 | #[allow(unused)] | 127 | #[allow(unused)] |
119 | pub(crate) fn id( | 128 | pub(crate) fn id(&self, db: &impl AsRef<HirInterner>) -> MacroCallId { |
120 | &self, | 129 | db.as_ref().macros.loc2id(&self) |
121 | db: &impl AsRef<LocationIntener<MacroCallLoc, MacroCallId>>, | ||
122 | ) -> MacroCallId { | ||
123 | db.as_ref().loc2id(&self) | ||
124 | } | 130 | } |
125 | } | 131 | } |
126 | 132 | ||
@@ -164,8 +170,8 @@ pub(crate) enum DefKind { | |||
164 | } | 170 | } |
165 | 171 | ||
166 | impl DefId { | 172 | impl DefId { |
167 | pub(crate) fn loc(self, db: &impl AsRef<LocationIntener<DefLoc, DefId>>) -> DefLoc { | 173 | pub(crate) fn loc(self, db: &impl AsRef<HirInterner>) -> DefLoc { |
168 | db.as_ref().id2loc(self) | 174 | db.as_ref().defs.id2loc(self) |
169 | } | 175 | } |
170 | 176 | ||
171 | pub fn resolve(self, db: &impl HirDatabase) -> Def { | 177 | pub fn resolve(self, db: &impl HirDatabase) -> Def { |
@@ -233,8 +239,8 @@ impl DefId { | |||
233 | } | 239 | } |
234 | 240 | ||
235 | impl DefLoc { | 241 | impl DefLoc { |
236 | pub(crate) fn id(&self, db: &impl AsRef<LocationIntener<DefLoc, DefId>>) -> DefId { | 242 | pub(crate) fn id(&self, db: &impl AsRef<HirInterner>) -> DefId { |
237 | db.as_ref().loc2id(&self) | 243 | db.as_ref().defs.loc2id(&self) |
238 | } | 244 | } |
239 | } | 245 | } |
240 | 246 | ||