diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_hir/src/ids.rs | 32 | ||||
-rw-r--r-- | crates/ra_hir/src/lib.rs | 16 |
2 files changed, 34 insertions, 14 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 | } | ||
diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs index 1219b9fba..8d3a026d5 100644 --- a/crates/ra_hir/src/lib.rs +++ b/crates/ra_hir/src/lib.rs | |||
@@ -22,6 +22,7 @@ mod path; | |||
22 | mod arena; | 22 | mod arena; |
23 | pub mod source_binder; | 23 | pub mod source_binder; |
24 | 24 | ||
25 | mod ids; | ||
25 | mod macros; | 26 | mod macros; |
26 | mod name; | 27 | mod name; |
27 | mod krate; | 28 | mod krate; |
@@ -46,6 +47,7 @@ pub use self::{ | |||
46 | path::{Path, PathKind}, | 47 | path::{Path, PathKind}, |
47 | name::Name, | 48 | name::Name, |
48 | krate::Crate, | 49 | krate::Crate, |
50 | ids::MFileId, | ||
49 | macros::{MacroDef, MacroInput, MacroExpansion, MacroCallId, MacroCallLoc}, | 51 | macros::{MacroDef, MacroInput, MacroExpansion, MacroCallId, MacroCallLoc}, |
50 | module::{Module, ModuleId, Problem, nameres::{ItemMap, PerNs, Namespace}, ModuleScope, Resolution}, | 52 | module::{Module, ModuleId, Problem, nameres::{ItemMap, PerNs, Namespace}, ModuleScope, Resolution}, |
51 | function::{Function, FnScopes}, | 53 | function::{Function, FnScopes}, |
@@ -55,20 +57,6 @@ pub use self::{ | |||
55 | 57 | ||
56 | pub use self::function::FnSignatureInfo; | 58 | pub use self::function::FnSignatureInfo; |
57 | 59 | ||
58 | /// An `MFileId` is like a `FileId`, but it can also refer to code generated by | ||
59 | /// macros. | ||
60 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
61 | pub enum MFileId { | ||
62 | File(FileId), | ||
63 | Macro(MacroCallId), | ||
64 | } | ||
65 | |||
66 | impl From<FileId> for MFileId { | ||
67 | fn from(file_id: FileId) -> MFileId { | ||
68 | MFileId::File(file_id) | ||
69 | } | ||
70 | } | ||
71 | |||
72 | /// Def's are a core concept of hir. A `Def` is an Item (function, module, etc) | 60 | /// Def's are a core concept of hir. A `Def` is an Item (function, module, etc) |
73 | /// in a specific module. | 61 | /// in a specific module. |
74 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 62 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |