diff options
Diffstat (limited to 'crates/ra_hir/src/ids.rs')
-rw-r--r-- | crates/ra_hir/src/ids.rs | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/crates/ra_hir/src/ids.rs b/crates/ra_hir/src/ids.rs new file mode 100644 index 000000000..881303861 --- /dev/null +++ b/crates/ra_hir/src/ids.rs | |||
@@ -0,0 +1,32 @@ | |||
1 | use crate::{FileId, MacroCallId}; | ||
2 | |||
3 | /// hir makes a heavy use of ids: integer (u32) handlers to various things. You | ||
4 | /// can think of id as a pointer (but without a lifetime) or a file descriptor | ||
5 | /// (but for hir objects). | ||
6 | /// | ||
7 | /// This module defines a bunch of ids we are using. The most important ones are | ||
8 | /// probably `HirFileId` and `DefId`. | ||
9 | |||
10 | /// Input to the analyzer is a set of file, where each file is indetified by | ||
11 | /// `FileId` and contains source code. However, another source of source code in | ||
12 | /// Rust are macros: each macro can be thought of as producing a "temporary | ||
13 | /// file". To assign id to such file, we use the id of a macro call that | ||
14 | /// produced the file. So, a `HirFileId` is either a `FileId` (source code | ||
15 | /// written by user), or a `MacroCallId` (source code produced by macro). | ||
16 | /// | ||
17 | /// What is a `MacroCallId`? Simplifying, it's a `HirFileId` of a file containin | ||
18 | /// the call plus the offset of the macro call in the file. Note that this is a | ||
19 | /// recursive definition! Nethetheless, size_of of `HirFileId` is finite | ||
20 | /// (because everything bottoms out at the real `FileId`) and small | ||
21 | /// (`MacroCallId` uses location interner). | ||
22 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
23 | pub enum MFileId { | ||
24 | File(FileId), | ||
25 | Macro(MacroCallId), | ||
26 | } | ||
27 | |||
28 | impl From<FileId> for MFileId { | ||
29 | fn from(file_id: FileId) -> MFileId { | ||
30 | MFileId::File(file_id) | ||
31 | } | ||
32 | } | ||