aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-01-01 19:47:10 +0000
committerAleksey Kladov <[email protected]>2019-01-01 19:47:10 +0000
commit9c65e618498596a5dc75efe0814a5542c54d54d8 (patch)
tree30d22a7d25c1baf9bada0da625dc60bc7572b079
parentfca1422ea34363b6f47da76914022bc60f7f66df (diff)
introduce ids module
-rw-r--r--crates/ra_hir/src/ids.rs32
-rw-r--r--crates/ra_hir/src/lib.rs16
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 @@
1use 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)]
23pub enum MFileId {
24 File(FileId),
25 Macro(MacroCallId),
26}
27
28impl 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;
22mod arena; 22mod arena;
23pub mod source_binder; 23pub mod source_binder;
24 24
25mod ids;
25mod macros; 26mod macros;
26mod name; 27mod name;
27mod krate; 28mod 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
56pub use self::function::FnSignatureInfo; 58pub 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)]
61pub enum MFileId {
62 File(FileId),
63 Macro(MacroCallId),
64}
65
66impl 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)]